              A 6809 ASSEMBLER IN MICROSOFT BASIC

                by Clarence Felong and Ken Brown


When the Radio Shack Color Computer was first announced, it
appeared to be a break-through in price/performance.  It was
based on the Motorola 6809 CPU, had color graphics, Basic in
ROM and cost under $500!  At about this same time we became
very interested in graphics and animation (i.e. games).  The
Basic was good, faster then the TRS-80's, but not fast enough
to handle real-time animation.  Assembly language programming
seemed the way to go.

                           BACKGROUND

A problem arose very quickly.  Where do you get a 6809
assembler to run on the Color Computer when the Advanced Basic
and add-on RAM was not even available?  What could the 6809 DO,
anyway?  After many phone calls to Radio Shack, Motorola part
distributers and local book stores, we obtained a book
entitled, "MC6809 PRELIMINARY PROGRAMMING MANUAL" from
Motorola.  Preliminary, indeed!  The listings in the book came
from a 6809 cross-assembler running on a 6800 based machine and
many of the comments were hand written.  This was interesting
but did not solve our problem.

Our pleas to Radio Shack for information on availability of an
assembler went unanswered.  South West Technical Products had a
6809 based computer running on the SS-50 bus but we were
unwilling to spend several thousand dollars for a computer to
write code for another computer.  Spectral Associates had
advertised an assembler but were "weeks" away from delivery at
that time.  It appeared that our options were to wait or write
our own.  We decided to write our own.

The Color Computer did not then have the memory capacity to run
a 6809 assembler written in Basic for itself on itself. We both
owned disk-based TRS-80 Model I systems and this seemed the
natural system to write code on.  We could take the generated
object code and input the data to the Color Computer through
DATA statements which could be POKEd into the Color Computer's
memory and then CSAVEd to cassette in machine executable form.
Once we could execute 6809 code on the Color Computer, we could
write a serial transfer program on it and the TRS-80 Model I
and send data through the RS232 ports.  We decided to write the
assembler in Basic for ease and speed of implementation.  The
following Basic program is the result.

One of the primary requirements for an assembler is an editor
which can be used to write and modify source code.  Rather than
writing our own, we decided to use Apparat's EDTASM editor
(Miosys' EDAS can also be used).  6809 source code can be
input, edited and saved to disk.  The "built-in" Z80 assembler
is not used.  The format of files saved by EDAS or EDTASM is as
follows:

line 1      characters  1-7      filename (NOT USED)
line 1      characters  8-12     line number - high bit set
line 1      characters  13-      source code line text

line 2      characters  1-5      line number - high bit set
line 2      characters  6-       source code line text

line 3..n   character   1-5      line number - high bit set
...         character   6-       source code line text

End Of File (EOF) is decimal 26 (HEX 1A or control-Z)

                     RUNNING THE ASSEMBLER

When the 6809 assembler Basic program is run, it prompts the
user for a filename.  The filename must contain any extension
needed - i.e "PONG/ASM".  This file must have been generated by
EDTASM or EDAS or be in the same format as described above.
The source code file is opened and source lines are displayed
on the CRT as read.  After the program is read into memory, the
program asks if output should be directed to the printer.  If a
"Y" is input, the compiled object code and associated source
line is output to the printer.  NOTE - the input of source code
and compilation takes a substantial amount of time for long
source code files.  After compilation, the user can opt for
DATA statement output to the printer.  This allows one to copy
the generated code to the Color Computer as DATA statements.

Extrememly long source code files should be broken into parts
as the assembler may run out of RAM on source line input or
compilation.  The two sample 6809 assembler listings are meant
to be linked together for execution.  This may be done by first
POKEing the PONG program into the Color Computer and then
POKEing the SETRES program.  The combined programs then can be
CSAVEd to tape.  Later a Basic program can be RUN on the Color
Computer saving RAM for the assembled code by use of the CLEAR
command.  The binary code tape can be CLOADed by the Basic
program and CALLed by it.

           LIMITATIONS AND CHANGES FROM STANDARD 6809

Programming a 6809 assembler on the TRS-80 has forced some
limitations and changes.  Indirect addressing in the standard
Motorola format is indicated by left and right square brackets.
In this version, the exclamation point, "!" is used in place of
either bracket.  Also note that the standard 6809 assembler
differs from a Z80 assambler in that comment fields after
opcodes or labels need no ";" for delineation.  An "*" in
column 1 makes the entire line a comment.  To assign a label to
the current PC, the "*" is used - i.e. "START  EQU  *".   Hex
values begin with "$" - i.e. "  ORG  $E000".  The Z80 psuedo
op-code, DEFB (DB) corresponds to either FDB for byte
definitions or FCC for string definitions - i.e. "STEP  FDB
$A1" and "MSG  FCC  /THIS IS A MESSAGE/".  Generally speaking,
6809 code is PC relative.  This means that generated code can
be run anywhere in RAM whithout recompilation - no ORG
statement is needed in assembler as presented.  The two 6809
assembler source code files given as examples contain most of
the different op-codes and pseudo op-codes used by our
assembler.

Both source code and object code are kept in RAM memory.
Because of this constraint, source code is limited to 270 lines
and object code is limited to 1000 bytes.  These constants may
be adjusted in line 130 of the Basic program.  Microsoft Basic
is VERY slow in "string garbage collection" and makes the
assembler run correspondingly slow.  Five minutes for a long
source code file assembly is not unrealistic (have patience!).

               POSSIBLE CHANGES AND ENHANCEMENTS

The assembler as written is designed for the TRS-80 Models I &
III.  It should port with very minor changes to other systems
running Microsoft Basic (such as CP/M based machines).  To
handle larger programs, the program could be easily modified so
that source code lines are not kept in RAM.  The program can
(and has!) been slightly changed to work under the Microsoft
Basic Compiler.  All DIMmensioned statements should be changed
to include numeric constants in the declaration rather than
variables as in line 140.  The CLEAR statement in lines 110 and
3780 should be deleted.  The passing of variable values using
POKE and PEEK in line 3780 is not necessary under a compiler.
With the inclusion of more logic, macros could be supported.

                       CONCLUDING REMARKS

The assembler as listed here is freely given to the Public
Domain.  We ask only acknowledgement of the authors in any
distribution of the program.  The program has undergone much
testing and use.  We are not aware of any bugs, but some may
exist.  Included with this article are a couple of sample
programs and listings used in the construction of a Pong-type
game,  these also may be used and reproduced freely.  We are no
longer using this program in any form and no modifications or
enhancements will be forthcoming.
 