CoCo Cross Development, part 2

Previously, I demonstrated a simple way to write a BASIC program on a modern computer and then load that program in to a CoCo emulator. This time, I will discuss doing the same thing with 6809 assembly code.

Tool Time

When it comes to compiling CoCo-compatible 6809 assembly files on a PC, Mac or Linux machine, there are several options. While many generic 6809 assemblers exist, there are certain requirements of the Microsoft Color BASIC binary format or OS-9/NitrOS-9 module format that they typically do not handle.

His lwasm assembler can build code for Color BASIC and OS-9/NitrOS-9. lwasm is the compiler used to build the NitrOS-9 project (including kernel, file managers, device drivers, utilities, etc.) so it is well tested.

And, it’s cross platform so you can run it from a command line on Windows, Mac OS X or Linux. Instructions are given on the LWTOOLS website, but for Mac users, I wrote a tutorial on building NitrOS-9 which included the steps to build the LWTOOLS (and the Toolshed* tools) as part of this process:

* Toolshed is a set of tools for reading and writing Color DISK BASIC and OS-9/NitrOS-9 disk image files used by emulators. It will be discussed in a future installment.

My First 6809 Assembly

As mentioned in the first installment, the Radio Shack 6809 assembler for the CoCo was Microsoft’s EDTASM+. It was available as a ROM-Pak cartridge that could load/save to tape, or as Disk EDTASM+ which could load/save to disk:

EDTASM+ 6809 assembler by Microsoft. A ROM-Pak (cartridge) sold by Radio Shack.

It was never updated to take advantage of the enhanced hardware of the 1986 Color Computer 3, but folks came up with patches to make it use the CoCo 3’s 40 or 80 column screen and double speed mode. Enhancements were also made to enable compiling Hitachi 6309 code once that processor became a popular upgrade for CoCo owners. I think I even recall patches made to the original cartridge EDTASM+ to give it disk support, for some reason.

Here are the steps you would have taken to write a simple “Hello World” program using EDTASM+ on a CoCo. If you would like to play along, you may do so via JS Mocha, a CoCo 1/2 emulator written in HTML5, that runs in a modern web browser:

Make My Mocha Grande

From the JS Mocha web page, select “EDTASM” from the second column, then click the “Load Bin” button below it.

The emulator will reset and you will be greeted with the EDTASM+ title screen.

EDTASM+ operates in three modes: Editor, Assembler, and ZBUG debugger.

Initially, you are at the Assembler screen, with an asterisk (“*”) as the prompt.

Type “I” then ENTER to switch to the Editor. The prompt will now change to line numbers (“00100”).

Let’s type in a very simple program that makes use of the ROM character output routine (CHROUT) to print some text on the screen. Use tab (right arrow) to tab to each column. When done, press break (Esc key) to return to the assembler.

If we typed everything in correctly, we can compile it using the following command:

* A/IM/WE

This means Assemble, In Memory, and Wait for Errors. If there are any issues, you can use the Editor to make changes (“E 180” to edit line 180, then it has a similar syntax to the line editor in Extended Color BASIC. If you just wanted to retype a line, you could select “H” for hack, then retype the line and press ENTER). Consult the EDTASM+ manual for full details on how the Editor works.

If the program compiled properly, EDTASM+ should have printed out some memory locations, op codes, and assembly source, followed by the list of errors and the memory locations for the named functions:

0000 TOTAL ERRORS
DONE 08B0
LOOP 08A6
MSG 08A3
START 08A3

Since we did not specify where in memory to compile this code, EDTASM+ chose a location for us. Now we can try to run the program in the ZBUG debugger.

From the “*” prompt type “Z” then ENTER. The prompt will now turn to a number/hash symbol (“#”). This is the ZBUG prompt.

Type “GSTART” to run it:

EDTASM+ in the JS Mocha emulator running a Hello World program.

And that’s how we rolled back in 1982.

Do the same thing, only different.

Now let’s look at building this on a modern computer, and creating something we can then load on our virtual CoCo.

Using a text editor, create a file such as “helloworld.asm” and enter in the original program with two small changes. Unlike with EDTASM+, lwasm will allow op codes to be in lowercase, so you can save your SHIFT key if you prefer:

Notice we now specify an origin memory location (where the program will compile), and that the SWI (software interrupt) instruction has been changed to an RTS (return from subroutine). SWI is used when running in the ZBUG debugger, but for running standalone, RTS is how we will exit back to BASIC.

From the command line/shell (probably the MSYS shell on Windows, or Terminal on Mac OS X), you can build this source in to a .BIN binary file that you could CLOADM or LOADM in a CoCo:

We could use the Toolshed tools to copy this file over to a .DSK image and then try it out in an emulator, but lwasm has another output option that is handy for quick tests: BASIC!

By specifying the -f basic option, lwasm will generate an ASCII BASIC program that has the assembly converted to DATA statements. It will also have a few lines of BASIC code that will READ that data and POKE it in to memory so we can EXECute it.

Now that we have the assembly program turned in to a text file, we can load it the same way we loaded the BASIC example in the first part of this series.

From the XRoar emulator, select “File -> Load” then browse to “HELLO.BAS” and select it. Then, from the BASIC prompt in the emulator type “CLOAD” to load it in to memory:

6809 assembly as a BASIC program.

Now we can type “RUN” and the BASIC program will read the values in the DATA statements and POKE them in to memory starting at $3F00 (16128).

One the BASIC program has loaded the assembly code in to memory, we can EXECute it like this:

EXEC &H3F00

And hopefully see our “HELLO WORLD” message printed out:

HELLO WORLD in assembly.

Using this BASIC loader feature of lwasm, it is very quick and easy to build and test small assembly code programs in the XRoar emulator. I have been told that the MAME (formerly MESS) emulator allows copy/paste in to the emulator, which would give an easy way to do this in that emulator as well.

For other emulators without these features, we would use the Toolshed (or similar) tools to copy the .BIN file (or .BAS file, for that matter) to a virtual tape or disk image and then use that in the emulator. This would give us the ability to also move files back to the development computer, as well.

In 1982, I received my first computer: a $299.99 Commodore VIC-20. A year later, I moved on to a 64K Radio Shack Color Computer ("CoCo"). In 1990, I co-founded Sub-Etha Software "in Support of the CoCo and OS-9".
This later led me to a job at Microware, creator of OS-9. I am author of the CoCoFest Chronicles, a compilation of my fest reports covering the 1990s era. I also host the CoCopedia.com wiki. These days, I am enjoying excavating my original VIC-20 tapes and thousands of CoCo floppy disks...