Wednesday, August 15, 2018

--> 6502

The ubiquitous 6502.  It was meant to compete with the 6800 as an embedded controller.  If personal computers had already existed, they might have opted to include a few more features.


The Plus/4 & C64 code hasn't been tested yet, so this may have some bugs yet.
The font address is calculated by loading via the address of a table for all first bytes, 2nd bytes, etc...
This significantly reduces the amount of work the 6502 has to do, however, it's at the price of additional clock cycles used for that addressing mode.  The screen writes use an even slower addressing mode.
The row addresses are in a lookup table to further reduce the amount of work the 6502 has to do, but the 6502 version is over 500 bytes larger than other versions as a result, and changing the code so it could switch between fonts would require changing all the hard coded addresses of the font tables.

While the first section of the code is faster than the 6800 version, the 6800 appears to be quite competitive when writing to the screen.



;**************************************************
; write two characters at once
;**************************************************
print_642:
 ; register A contains left character
 ; calculate offset to left character font data
 sec
 sbc  #28     ; printable character set data starts at space, ASCII 32
 sta  firstchar   ; save as character table offset

 ; calculate screen address
 ldx  row     ; put row in x
 lda  col     ; get column
 and  #%11111110   ; convert 80 to 40 columns * 2, drop odd addresses (2 chars/byte)
 lsl       ; * 4
 lsl       ; * 8 bytes per character between columns
 adc  scrtableLSB,X  ; get LSB offset from table, carry should be clear
 sta  fscreen    ; store LSB
 lda  #0     ; add carry
 adc  scrtableMSB,X  ; get MSB offset from table
 sta  fscreen+1   ; store MSB

 ; calculate offset to right character font data
 iny
 lda  (string),y
 sec
 sbc  #28     ; 28?  This may be a bug
 sta  secondchar
 tax       ; load offset to first byte of 2nd character

 ; print characters to screen
 ldy  #0     ; clear the screen pointer offset 2
 lda  FCol20,X   ; load the first byte of the 2nd character 4
 ldx  firstchar   ; offset to 1st character 3
 lda  FCol0,X    ; load the first byte of the 1st character 4
 sta  (fscreen),y   ; write it to the screen 6

 iny       ; point to next screen byte 2
 lda  FCol1,X    ; load the next byte of the 1st character 4
 ldx  secondchar   ; offset to 2nd character 3
 eor  FCol21,X   ; add the next byte of the 2nd character 3
 sta  (fscreen),y   ; write it to the screen 6

 iny       ; point to next screen byte
 lda  FCol22,X   ; add the next byte of the 2nd character
 ldx  firstchar   ; offset to 1st character
 eor  FCol2,X    ; load the next byte of the 1st character
 sta  (fscreen),y   ; write it to the screen
 
 iny       ; point to next screen byte
 lda  FCol3,X    ; load the next byte of the 1st character
 ldx  secondchar   ; offset to 2nd character
 eor  FCol23,X   ; add the next byte of the 2nd character
 sta  (fscreen),y   ; write it to the screen
 
 iny       ; point to next screen byte
 lda  FCol24,X   ; add the next byte of the 2nd character
 ldx  firstchar   ; offset to 1st character
 eor  FCol4,X    ; load the next byte of the 1st character
 sta  (fscreen),y   ; write it to the screen

 iny       ; point to next screen byte
 lda  FCol5,X    ; load the next byte of the 1st character
 ldx  secondchar   ; offset to 2nd character
 eor  FCol25,X   ; add the next byte of the 2nd character
 sta  (fscreen),y   ; write it to the screen
 
 iny       ; point to next screen byte
 lda  FCol26,X   ; add the next byte of the 2nd character
 ldx  firstchar   ; offset to 1st character
 eor  FCol6,X    ; load the next byte of the 1st character
 sta  (fscreen),y   ; write it to the screen
 
 iny       ; point to next screen byte
 lda  FCol7,X    ; load the next byte of the 1st character
 ldx  secondchar   ; offset to 2nd character
 eor  FCol27,X   ; add the next byte of the 2nd character
 sta  (fscreen),y   ; write it to the screen
 
 rts

1 comment:

  1. The address calculation appears to need a little more work here

    ReplyDelete