The sbc09 package contains an emulator of a 6809-based single board computer that runs under UNIX. It contains all the programs needed to work with the emulator, such as the emulator itself, an assembler, a monitor program, a BASIC interpreter, a Forth interpreter, several example programs and several tools needed to build the programs. The program should work under most more-or-less POSIX-compliant versions of UNIX and they were developed under Linux. Of course I believe that the programs that currently run on the emulator would also run on a real 6809 machine.
In the seventies you could buy single board microcomputers that had a hexadecimal keypad and 7-segment displays. These computers typically had less than 1 kilobyte of RAM and a simple monitor program in ROM. An interface to a cassette recorder (or paper tape reader/writer) and a terminal was possible, but not standard. The typical way to program the machine was entering hexadecimal machine codes on the keypad. Machine code was the only language in which you could program them, especially if you only had a hexadecimal keypad and 7-segment led displays. You typically used these machines to experiment with hardware interfacing, as games and calculations were a bit limited with only six 7-sengment digits.
Next came simple home computers, like the TRS80, the Apple ][ and the Commodore PET. These machines had BASIC in ROM and they used a simple cassette recorder to store data. These computers had a TV or a low quality monitor as display and a QWERTY keyboard. These machines could be upgraded with a floppy disk drive and a printer and then they could be used for professional work. These machines had 4 to 64 kilobyts of memory. Apart from assembly language you could use BASIC, Forth and sometimes Pascal to program these machines. Most useful programs (and the best games) were programmed in assembly language. Many of these machines had BASIC in ROM and no machine code monitor. You had to load that separately.
Today we have personal computers that run DOS, Windows, UNIX or something else. New computers have 4 to 16 megabytes of RAM and hard disks of more than 500 Megabytes. Apart from having in the order of 1000 times more storage, they are also 1000 times faster than the old 8-bit home computers. Programming? You can use Visual BASIC, C++ and about every other programming language on the planet. But programs have become bigger and bigger. Programming is not the same as it was before.
I guess there is some demand for small 8-bit computer systems that are simple to build, easy to interface to all kinds of hobby projects, fun to program and small enough to integrate into a home-built project. Do we want to use hexadecimal keyboards and 7-segment displays? I guess not many people want to use them. Do we want to use a cassette recorder for data storage and a TV as a display? Not me. And if you build your own 8-bit microprocessor, do you want to waste your time and money on a hexadecimal keypad or a cassette interface that you do not like to use and that you do not need anyway? PCs of five years ago are more than adequate to run an editor, a terminal program and a cross assembler for your favourite 8-bit processor. The terminal program can then be used to send the programs to the 8-bit micro. If you equip an 8-bit system with some static CMOS RAM, a serial interface and a monitor in ROM, you can use the keyboard, hard disk and monitor of your PC for program development and the 8-bit micro can be disconnected from the PC and do its task, once it is programmed.
Cross development is nothing special. How do you think the microprocessor in you microwave was programmed? But it is not practical for a hobbyist to program an EPROM for each program change. Professional developers of embedded processors have expensive tools, like ROM emulators, processor emulators etc. to see what the processor is doing on its way to the next crash. For a hobbyist it is much more practical to have a slightly more expensive embedded computer that you can run an interactive debugger on. And you are not even limited to assembly language. If you have 32k ROM you can have both the monitor program and a BASIC interpreter and some aplication code in ROM. Nothing prevents you from having Forth as well.
The program sbc09 emulates the abovementioned single board computer plus the terminal program that communicates with it.
The assembler is a09. Run it with
Source is a mandatory argument. The -l listing and -o or -s object arguments are optional. By default there is no listing and the object file is the sourcefile name without an extension and if the source file name has no extension it is the source file name with .b extension.
A09 recognizes standard 6809 mnemonics. Labels should start in the first column and may or may not be terminated by a colon. Every line starting with a non-alphanumeric is taken to be a comment line. Everything after the operand field is taken to be comment. There is a full expression evaluator with C-style operators (and Motorola style number bases).
There are the usual pseudo-ops such as ORG EQU SET SETDP RMB FCB FDB FCC etc. Strings within double quotes may be mixed with numbers on FCB lines. There is conditional assembly with IF/ELSE/ENDIF and there is INCLUDE. The assembler is case-insensitive.
The object file is either a binary image file (-o) or Motorola S-records (-s). In the former case it contains a binary image of the assembled data starting at the first address where something is assembled. In the following case
the RMB statements generate no data so the object file contains the memory image from address $100.
The list file contains no pretty lay-out and no pagination. It is assumed that utilities (Unix pr or enscript) are available for that.
There are no macros and no linkable modules yet. Some provisions are taken for it in the code.
After the assembler has finished, it prints the number of pass 2 errors. This should be zero. So if you see
then you are lucky.
The simulator is v09. Run it with
tracelo and tracehi are addresses. They can be entered in decimal, octal or hex using the C conventions for number input.
If a tracefile is specified, all instructions at addresses between tracelo and tracehi are traced. Tracing information such as program location, register contents and opcodes are written to the trace file.
escchar is the escape character. It must be entered as a number. This is the character that you must type to get the v09 prompt. This is control-] by default. (0x1d)
The program loads its ROM image from the file v09.rom, which is a 32 kiliobyte binary file. This file should have been generated by the Makefile. The program starts executing at the address found at $FFFE in the ROM, just like a real 6809 would do on reset.
The address map is as follows.
At addresses $E000 and $E001 there is an emulated serial port (ACIA). All bytes sent to it (or read from it) are send to (read from) the terminal and sometimes to/from a file. Terminal I/O is in raw mode.
If you press the escape char, you get the v09 prompt. At the prompt you can enter the following things.
All of these commands, except the R command, can be seen as commands of the communication program that is used to access the single board computer. The R command is a subsitute for pushing the RESET button on the emulated computer.
The program monitor.asm is a program that is intended to be included in the ROM of a 6809 based single board computer. The program allows a user to communicate with the single board computer through a serial port. It allows a user to enter machine code, examine memory and registers, to set breakpoints, to trace a program and more. Furthermore, data can be sent to and be received from the single board computer through the X-MODEM protocol.
If you start v09 with the standard ROM, then you will run the monitor program. If all goes well you see something like
and you can type text. Excellent, you are now running 6809 code.
The following example programs you can run from the 6809 monitor. All of them start at address $400. For example to run the program bin2dec you type.
Then press your escape character (default is control-] ).
Then at the v09 prompt type
Now you see some lines displaying the progress of the X-modem session. If that is finished, you type
Now it runs and exits to the monitor with SWI, so that the registers are displayed.
Then press your escape char. At the v09 prompt type: sexampl.bas
Now a BASIC program is input. Type RUN to run it.
Leave BASIC by pressing the escape char and entering x at the prompt.
Dump 256 bytes starting at $E400
Dump the next 64 bytes.
Enter the bytes 86 44 9D 03 3F at address $400.
Enter the ASCII codes of ”Welcome” at address $400.
Find the specified string in memory, starting at the specified address. The I/O addresses $E000-$E0FF are skipped. The addresses of the first 16 occurrences are shown.
Search for the word ”SEX” starting in the monitor.
Move 128 bytes from address $400 to $500.
You are in the assembler until you make an error or until you enter an empty line.
Diassemble first 32 bytes of monitor program.
Disassemble next 21 bytes.
Four breakpoints can be active simultaneously.
Set the breakpoints at the addresses $403 and $408.
Show the breakpoints.
Remove the breakpoint at $403.
The registers are loaded from where they are saved (on the stack) and at the breakpoints SWI instructions are entered. Next the code is executed at the indicated address. The SWI instruction (or RTS for the J command) returns to the monitor, saving the registers.
P is similar to T, because it usually executes one instruction and returns to the monitor after it. That does not work for jumps though. Normally you use P only with JSR instructions if you want to execute the whole subroutine without single-stepping through it.
The R command uses the saved register values (on the stack). There are some restrictions on changing the S register.
Display all registers.
Load the B register with $03 and the program counter with $4444.
Show the ACIA status.
S records are usually entered from a file, either ASCII transfer (S command from the v09 prompt) or X-MODEM transfer (XX command in monitor, U command from v09 prompt). Most Motorola cross assemblers generate S records.
These S records can be loaded later by the monitor program.
Usually you capture the S records into a file (use L command at v09 prompt) or use XSS instead. The XSS command is the same as SS, except that it outputs the S records through the X-modem protocol (use D command at v09 prompt).
Before entering S records, it sets the first memory address where S records will be loaded, regardless of the address contained in the S records.
Before the SS command, it sets the first address that will go into the S records.
Load the S records at address $800 even though the address in the S records is $400
Save the memory region of 256 bytes starting at $400 as S records. The S records contain addresses starting at $8000.
Type your escape character and at the v09 prompt type
to load the binary file ”basic” at address $400.
to save the memory region of 128 bytes starting at $400 Type your escape character and at the v09 prompt type:
Now the bytes are saved into the file ”foo”.
See SS command for more details.
Now press the escape character and at the v09 prompt type
where sfile is a file with S-records.
Example: Under a UNIX system you want X-modem’s text output with just LF and a filler byte of 0. Type:
Of all the 8-bit home computers only a few had the Motorola 6809 CPU, the most famous of which was the Tandy Color Computer. Then there was its clone (from Wales) the Dragon and there was an old obscure SuperPet that I have never seen. The 6809 was the 8-bit processor finally done right, but it came a bit too late to have a real influence on the market.
The book that raised my enthousiasm for the Motorola 6809 processor was: Lance A. Leventhal, “6809 Assembly Language Programming”, 1981 Osborne/McGrawhill. ISBN 0-07-931035-4. I borrowed it several times from the university library and finally I bought my own copy.
The first sentence on the back of that book reads:
While everyone’s been talking about new 16-bit microprocessors, the 6809 has emerged as the important new device.
Though it was not the processor that changed the world, it certainly was the processor that changed my idea of what a good instruction set should look like. Before that I thought that the Z80 was superior to everything else on the planet, at least superior to every other 8-bit processor.
It was in April 1987. I borrowed the book for the first time and I had just written a Forth interpreter for my Z80 machine. It struck me that the following 7-instruction sequence on a Z80
could be replaced by just one instruction on the 6809.
BTW the above instructions are the heart of a Forth interpreter and making them more efficient has a tremendous effect on efficiency.
The years went by and I had bought an XT compatible computer in 1988. I didn’t buy a 6809 system though I could have done so. But it would either be too expensive or I would have to build it myself (I wasn’t too handy with soldering) or it would be a primitive machine like the Tandy Color Computer without expansions and I didn’t like to use cassettes and a 32-column display.
In 1989 I saw a 6502 simulator at a meeting of our Forth club. One could interactively enter hex codes, page through memory, modify registers, trace intructions etc. I just got to have this, but for a 6809 instead.
Around Christmas of that year I wrote a 6809 Forth assembler and an interactive simulator, like the one I had seen on the club meeting. Everything was written in F-PC, a very comprehensive Forth system for the PC.
I even made a start with writing an implementation of Forth for it, but the obvious lack of speed (among other things) witheld me from finishing it. I had a fairly complete set of assembly routines though. The estimated speed was around one thousand instructions per second, good for an equivalent processor speed of around 4kHz.
In May 1992 I changed my trusted 8MHz Turbo XT for a blistering fast 25MHz 80386 and it could run the simulator more than 5 times as fast. But then I wasn’t really working on it. In the summer of 1992 I changed to Linux, which I have been using ever since.
Around the summer of 1993 I was working with pfe, a brand new Forth system for Unix written by Dirk Zoller. It had reached such state of completeness and usability that porting the 6809 simulator to it would be feasible. I ported it and by doing so I regained interest in the 6809 processor. PFE is written in C instead of assembler and at least on the 80386 it is considerably slower than a Forth written in Assembler, like FPC. My simulated processor speed was around 5kHz, nothing to write home about. It was faster than on the XT, but not much.
The switch from Forth to C was caused by the fact that I wanted a traditional 6809 assembler, instead of the ’Forth’ assembler, in which the syntax is slightly tweaked to make the thing easy to implement in Forth and easy to use within Forth. In the fall of 1993 I wrote a traditional two pass assembler in a few days. It worked more or less, but only recently it has become bug-free in that it assembles all the instructions and all the addressing modes (even PC relative) without error.
Now that I had a real assembler, I could write real 6809 assembly programs, such as a BASIC interpreter (maybe kidding) or a monitor program or god knows what. If I would ever run real code on that 6809 simulator, I had to increase its speed considerably. So I wrote a very straightforward 6809 simulator in C using tables of function pointers. It did really well in terms of speed, I could reach an equivalent processor clock speed of around 200kHz. The C simulator didn’t have any fancy display, memory edit or single step functions. Its only I/O was through the SWI2 instruction for character output and SWI3 for character input, something I had added to the Forth-based simulator quite some time ago.
One afternoon in optimized hack mode brought me a crude port of E-Forth, a tiny and very slow (most was interpreted, very few assembler words) implementation of Forth. The original was written in MASM for the 8086 and other ports (like the 8051) wre already around. That was the first time I had Forth on an emulated 6809. BTW this Forth would also run, or should I say crawl, on the Forth-based simulator.
I released the assembler, simulator and EForth on alt.sources in November 1993.
Of course I also wrote some test and toy programs (what about a program to convert binary numbers to decimal using that oddball DAA instruction?).
In the spring of 1994 I picked up that old TINY BASIC interpreter written by John Byrns. And tiny it was. Not even arrays were supported. I ported it to my simulator and found some bugs, both in my simulator and in TINY BASIC itself.
I made some improvements to the 6809 simulator. Now I could send ASCII files to it and log the output to another ASCII file. That way I could ’load’ and ’save’ BASIC programs for one thing. Further I had a trace facility to write a trace of all the instructions in a certain address range to a file. Last I cleaned up the I/O and signal handling somewhat, making it portable across several Unix versions.
That version of the software, along with some example programs, was also released on alt.sources. The assembler implemented includes and conditional assembly in that version.
That blistering fast 80386 that I bought back in 1992 has become slow as molasses. It has actually become slower since the memory upgrade with slow memory (it was cheap) that necessitated an extra wait state. Fortunately I recently pruchased a Pentium.
At the moment I actually have plans to build (or have somebody build for me) a single board computer containing a 6809. I would like to have 32k RAM plus 32k EPROM. I definitely like to have a monitor program with the features I want. Hence another project was born, the virtual SBC that I could prototype my monitor ROM and some other software on.
The virtual SBC emulates a single board computer that communicates with a PC through an ACIA. On that PC there runs a simple terminal program that supports XMODEM file transfer. Things I recently did.
Finally I wrote a real 6809 Forth, based on some other Forth I wrote for an imaginary stack machine. Those old dusty primitives that I had written back in 1990 proved very useful now. This Forth can load programs through XMODEM too. It can recompile (metacompile) itself and, very importantly, it runs tetris! (crawls on the 386) This is the tetris implementation written in ANSI Forth by Dirk Zoller and it is used as a test program. Next I have to make this Forth ROM-able.
What else will go into that 32k ROM area? The monitor will be around 7k, 1k is reserved for the I/O space. Forth (with its own Forth assembler) will take about 12k, 8k without. A few additional k could be used for a ’real’ assemler, but I doubt I will ever use that. A cross assembler is much more convenient. BASIC no doubt. But I’m afraid I’ll have to write it myself, more so as I want to have source code of all my 6809 stuff. I already have the floating point routines for it.