Sunday, February 19, 2012

Translating 6502 to 6809

As I mentioned in a previous post, the AtariAge.com forum is filled with helpful people who readily took an interest in the project.  One particularly helpful fellow posted 6502 code which when run, would give audio and visual cues on the Atari XEGS that the computer was alive.  I downloaded a 6502 cross-assembler called atasm that compiled on my Mac, then used that to build the object file from the test source.  I then loaded the object into the Ostrich II which had its pod plugged into the 28 pin ROM socket on the XEGS.  The code ran fine.  Thanks to the following code, the screen went to a specific purple color, and a nice long sound emitted from the speaker of the TV.


*= $FFFE
  .word reset
  *= $FF00
reset
  sei
  cld
  ldx #$FF
;  txs  ; initialize 6502 mode and stack ptr
  inx
  txa
cleario
  sta $d000,x
  sta $d200,x
  sta $d300,x
  sta $d400,x
  dex
  bne cleario
  lda #3
  sta $d20f ; set Pokey to active
  ldx #$10
delay
  dex
  bne delay ; short delay for Pokey to start, probably not needed
  lda #$a-
  sta $d01a  ; set screen color
  lda #$a0
  sta $d200
  lda #$a1
  sta $d202  ; set audf1 and audf2
  lda #$a8
  sta $d201
  sta $d203 ; set audc1 and audc2
wait
  jmp wait  ; loop forever



Cool.  Now I had a way to cross verify the Liber809 design with known working 6502 code.  Next it was time to rewrite the code in 6809 assembly.  Wasn't too bad, and I got the chance to learn a little 6502.  Then I took out my trusty mamou cross-assembler and created the object code.  Double checked and triple checked, and it looked good...



 org $FF00
reset
 orcc #$50
 lds #$2000
 clrb
cleario
 ldx   #$D000
 clr   b,x
 ldx   #$D200
 clr   b,x
 ldx   #$D300
 clr   b,x
 ldx   #$D400
 clr   b,x
 decb
 bne   cleario
 lda   #3
 sta   $D20F ; set Pokey to active


delay
 lda   #$A0
 sta   $D01A  ; set screen color
 lda   #$A0
 sta   $D200
 lda   #$A1
 sta   $D202  ; set audf1 and audf2
 lda   #$A8
 sta   $D201
 sta   $D203  ; set audc1 and audc2
wait
 jmp   wait


 fill  $FF,$FFF0-*
 fdb   reset
 fdb   reset
 fdb   reset
 fdb   reset
 fdb   reset
 fdb   reset
 fdb   reset
 fdb   reset





With that done, I was ready to plug in the Liber809 prototype into the 6502 socket on the Atari XEGS, load up the ROM emulator with the 6809 object code, and press the power button.

No comments:

Post a Comment