[Coco] Any reason to put a 6309 in a Coco2?

William Astle lost at l-w.net
Thu Jan 1 17:27:13 EST 2004


On Thu, 1 Jan 2004, Neil Morrison wrote:

>
> No. in fact they often jumped into the middle of an opcode to save a
> byte. Everyone had to learn that if they used the rom code.

Disclaimer: I may have misremembered some of the opcode details.

There are a couple of really neat things they did. For example, if there
are two processes that are essentially identical except for an initial
value, you might write the code to behave one way with a value of $00 and
another if the value is not $00. So you might see the following
instruction:

LDA #$4F (machine code: 864F)

Suppose that is at $3F00. Now if you jump to $3F01, you actually start at
the byte with $4F in it. $4F just happens to be CLRA. The processor has no
idea that it's really part of the LDA instruction, nor does it care. And
no illegal opcodes are executed.

Another trick is say you have code that looks like:

LDB #2
JMP ERROR
LDB #4
JMP ERROR
LDB #6
JMP ERROR

(You might have that as destinations for the various branch instructions.)
The above uses 15 bytes. You might rewrite that as:

LDB #2
CMPX #$C604
CMPX #$C606
JMP ERROR

The above uses 11 bytes. It runs a bit slower but that may not be a
problem in many circumstances. You might write that more clear as:

LDB #2
FCB $8C
LDB #4
FCB $8C
LDB #6
JMP ERROR

Again, jumping to any of the LDB instructions is perfectly valid and will
provide a valid instruction stream to the processor with the unused LDBs
simply ignored.

BRN provides an interesting way of skipping the following byte as well.
For example if you simply need to skip a CLRB:

LDB #2
FCB $21   (opcode of BRN)
CLRB
JMP ERROR

Obviously since BRN never branches, the destination of the branch is
rather immaterial so you can skip any single byte that way. And it's one
byte less than a BRA.

There are, of course, other cute things that can be done that are also
perfectly legal as far as the official documentation of the CPU is
concerned.

All three of the above tricks are used in the coco ROMs along with a few
others.

Now as far as the illegal opcodes in the 6809, most of them do something
because of sloppy decoding of the opcodes (to save chip realestate
probably). So, for example, while the opcode for LBRA is $16, $1020
apparently also works on the 6809. However, it doesn't on the 6309. There
is one that does a reset of the chip ($3E I believe) which actually works
on a 6809 (but not on the 6309).

So, how's that for something on-topic?

-- 
William Astle
finger lost at l-w.net for further information

Geek Code V3.12: GCS/M/S d- s+:+ !a C++ UL++++$ P++ L+++ !E W++ !N w--- !O
!M PS PE V-- Y+ PGP t+@ 5++ X !R tv+@ b+++@ !DI D? G e++ h+ y?



More information about the Coco mailing list