6809 ASSEMBLY LANGUAGE – PART 2

If you are following along from part 1, you should have a Color Computer emulator, LWTOOLS, and TOOLSHED installed on your development system. By development system, I’m not talking about using a real 6809 based Color Computer from Tandy, but rather a laptop or desktop running Windows or even Linux.

My recommendations for a development environment are:

  • Microsoft VSCODE with the 6809 Assembly extension by Blair Leduc
  • Toolshed – For DECB copy, DECB dskini tools to create emulator DSK files.
  • LWTOOLS for MC6809 Assembler

All of these are available for Windows and Linux so no specific operating system is required.

To continue the commentary from part 1, I wanted to touch upon some added features of the MC6809 which were pretty novel for the time… like the movable direct page register. Direct Page normally referred to the lowest 8 bits of the address bus, or the first 256 bytes. Because these addresses do not require any of the upper 8 bits for addressing, you would only require 8 bits not 16 bits to acquire them but they were still a specific location in memory.

The 6809’s Direct Page Register enhancement allowed the ‘zero page’ to be relocated to any position within the 16-bit address space by defining a START block in the register, providing greater flexibility and optimization of memory utilization. As mentioned, direct page access uses only 1 byte versus 2 to define an address location, making access quicker.

While on the subject of adding features to a CPU, the design of the 6502 CPU took the opposite approach. The 6800 and 6809 were not cheap CPU’s in the 1970’s and they were rather complex 8-bit CPU designs. Motorola priced these accordingly, and in early days you might pay over $100 per CPU. On the other hand, the design of the 6502 was basically an attempt to take the 6800 design and strip it down to the bare essentials to get the cost to be 1/4 of the 6800 CPU. They managed to do this and thus the “very affordable” computers had arrived. By 1980, you might get a MC6809 for about $30, and it was clear that Motorola was getting less interested doing more development into the 8-bit general purpose CPU arena and ended up focusing more on the MC68000 as well as other simpler CPU’s that looked more like the 6502 in the end. This pretty much left the MC6809 at the end of its own branch on the 68 series tree. The MC68000, by comparison, became the future of the 68 series, offering 8,16 and 32 bit operations. It also introduced the idea of instruction suffixes, so you might see MOVE.B  #14, D0 with the .B indicating that this is an 8-bit Byte instruction. Ah, the problems of complexity make themselves known…

Rather than go into all sort of additional detail about the MC6809 CPU, I’l just refer you to this fine document from Motorola. https://archive.org/details/mc6809mc6809e8bitmicroprocessorprogrammingmanualmotorolainc.1981

In part one, the register layout of the 6809 and some of the mnemonics were mentioned but no real examples were shown. Its probably time to change that. Since the best example of the Color Computer is the Color Computer 3, this would be the best one to write some code for.

While the Instruction Set for the 6809 is big, most assemblers have a neat feature that allows one to create MACRO’s for certain tasks that can benefit from some shorthand. For example:

macro  DEX
    LEAX    -1,X
.endm

This macro definition would allow you to enter DEX instead of LEAX -1,X for a DECREMENT X instruction.

and if you have a DEX, why not an INX?

macro  INX
    LEAX    1,X
.endm

I leave it up to you to make your own macro sets based on your own experience. You might want to make a similar set of macros to Set Interrupts Enabled or Clear Interrupts Enabled (Disabled) or maybe a pushall and pullall.

Some general Color Computer Information to keep handy.

The Extended Memory Map of the Color Computer 3. Note: To access 512K, it requires 19 BITS of addressing.

Page19 bit addressPurposeDefault Logical 16 bit address
$00$0512k upgrade
$30$60000High Res Screen Ram
$34$68000High Res Buffer
$35$6A000Secontry Stack
$36$6C000High Res Text Screen
$37$6E000Unused
$38$70000Basic 32k0
$3C$78000Extended Color Basic$8000
$3D$7A000Color Basic$A000
$3E$7C000Cartridge$C000
$3F$7E000Super Extended Basic$E000
$7FF00Dedicated Addresses$FF00
$7FFFF$FFFF

In addition to the memory layout, here are some MMU Details.

MMU Bank Switching
Bank switching is performed by addresses $FFA0-FFAF
There are two sets of options Task 0 (Executive Set) and Task 1 (Task Set)… which of these is active is selected by bit 0 of $FF91… this allows for quick switching between two options
$FF91 Bit0=0$FF91 Bit0=1
BankAddress RangeExecutive  SetTask SetDefault
0$0$FFA0$FFA8$38
1$2000$FFA1$FFA9$39
2$4000$FFA2$FFAA$3A
3$6000$FFA3$FFAB$3B
4$8000$FFA4$FFAC$3C
5$A000$FFA5$FFAD$3D
6$C000$FFA6$FFAE$3E
7$E000$FFA7$FFAF$3F

So how about some quick code to get us started? (Not my code, just stuff I collected and cobbled together)

;-------------------------------------------
; Use Color Computer 80 Column mode from ASM
;-------------------------------------------
; Defines color palette values for background and foreground colors
;-------------------------------------------
Black	equ	$00
Blue	equ	$08
Gray	equ	$38
Green	equ	$10
Orange	equ	$34
Red	    equ	$20
White	equ	$3F
Yellow	equ	$36
;--------------------------------------------
;  Palette information
;--------------------------------------------
;       Background 0-7
;       $FFB0 = $00 = Black
;       $FFB1 = $08 = Blue
;       $FFB2 = $07 = Gray
;       $FFB3 = $10 = Green
;       $FFB4 = $34 = Orange
;       $FFB5 = $20 = Red
;       $FFB6 = $3F = White
;       $FFB7 = $36 = Yellow
;
;       Foreground 8-F
;       $FFB8 = $00 = Black
;       $FFB9 = $08 = Blue
;       $FFBA = $38 = Gray
;       $FFBB = $10 = Green
;       $FFBC = $34 = Orange
;       $FFBD = $20 = Red
;       $FFBE = $3F = White
;       $FFBF = $36 = Yellow 
;--------------------------------------------
; MMU REGS
;--------------------------------------------
MM0	equ	$FFA0		; $0000 - $1FFF
MM1	equ	$FFA1		; $2000 - $3FFF
MM2	equ	$FFA2		; $4000 - $5FFF
MM3	equ	$FFA3		; $6000 - $7FFF
MM4	equ	$FFA4		; $8000 - $9FFF
MM5	equ	$FFA5		; $A000 - $BFFF
MM6	equ	$FFA6		; $C000 - $DFFF
MM7	equ	$FFA7		; $E000 - $FFFF
;--------------------------------------------
        org     $E00    ; start of PMODE screen code
start   clra            ; set a register to 0
        sta     $FFB0   ; set palette register 0 to 0 9 (black)
        lda     #White  ; Load the a register with 63
        sta     $FFB8   ; set the palette register 8 with 63 (white)
; Initialization complete, on to the screen
        lda     #$7E    ; Value for 80 column mode
        sta     $FF90   ; hi res
        lda     #$7B
        sta     $FF98   ; video mode
        lda     #$1F    ;
        sta     $FF99   ; video resolution
;--------------------------------------------
; Video display offset
        lda     #$36    ; MMU BLOCK ($6C000) 
        sta     MM2     ; ($4000 area)
; Set video offset to $D8
; Clear accumulator and store to video offset high byte
;--------------------------------------------
        lda     #$D8
        sta     $FF9D   ; Video Offset
        clra
        sta     $FF9E
;--------------------------------------------
; clear screen routine
;--------------------------------------------
        lda     #$20    ; 20 = space character
        ldb     #$00    ; Attribute
        ldx     #$4000  ; Start of video area
cls     std     ,x++    ; D register = A+B. Store D to X register
        cmpx    #$4F00  ; end of screen reached?
        bne     cls     ; Branch back to continue if "no"
;--------------------------------------------
        ldx     #TEXT   ; Get what we want to print
        ldy     #$4000  ; Start of video area
        ldb     #$20    ; length of TEXT string below
; TLOOP Transfers bytes from address in X to address in Y,
; decrementing B after each byte, repeating until B=0
tloop   lda     ,x+
        sta     ,y++
        decb
        bne     tloop
;--------------------------------------------
; infinite loop
;--------------------------------------------
loop    jmp     loop
;--------------------------------------------
; data
;---------------------------------------------
TEXT    fcc     'This is a test of 80 column mode'
        end     start

If you can get this to work… you are all well on your way to learning 6809 Assembly.

If you are interested in a helper script, I have one…

https://gist.github.com/pwillard/e0f0bc16d557a091a0c4dbe1bee8eefa

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.