A couple of the finer points:
- the check for 'clearing' is made here instead of the attribute routine and simply plots the first character pattern, which I assume is always a space char (all blank anyway)
- I got took out indirect addressing because a sixteen bit index register is already large enough to cover the address range of the character ROM (is it a ROM? - the character patterns in memory, anyway). Attribute setup just stores the low 16 bits of base address of the charset in use. Absolute addressing takes care of the high 16 bits
- after a char row pattern is shifted to the high eight bits I set a bit to its 'immediate right' that acts as a sentinel (value also set by the attribute routine). No index register or memory location is needed to track when all the bits of the pattern are done; instead the Z-flag does that
Code: Select all
PLTCHR PHA ; Plot Character Subroutine variable (1-7) H and V size
TYA ; save all reg's
PHA
TXA
PHA
LDA #$2C ; Prepare TFT to Plot
STA DCOM
CACALC LDA PE ; clearing all pixels ?
BEQ pltspc ; b:yes, plot space character (first in every charset)
SEC
LDA CHR
CMP #127+1 ; an ascii char ?
BCS plotspc ; b: no (could be $0080 - $FFFF, don't know)
SBC #$20-1 ; first 32 ascii characters "undefined"
BCS nnull ; original char $20 - $7F now $00 - $5F (96 possible chars)
pltspc LDA #$00 ; make undefined char's a defined zero (space character)
nnull ASL A ; * 2
ASL A ; * 4
ASL A ; * 8
ADC CHRBASE ; add pointer to base either CA00 (C64) or CD00(3x5) (carry clear)
TAY
LDA PATHGT ; pattern rows either 8(c64) or 5(3x5)
STA PATROW
loop7 LDA PLTHGT ; plot row repeat count (1-7)
STA PIXROW
loop4 LDA $FFFF0000,y ; $FFFFCA00(c64) or $FFFFCD00(3x5)
ASL A ;
ASL A ;
ASL A ;
ASL A ;
ASL A ;
ASL A ;
ASL A ;
ASL A ; shift out upper 8 bits, don't care for 8-bit byte character font
ORA SENTINEL ; $0080 (C64) or $0800 (3x5)
ASL A ; get a pixel
loop5 PHA ; save remaining pixel row data
LDX PLTWID ; plot column repeat count (1-7) (same as PLTHGT?)
BCC xwnp ; b: clear ('blank')
xwp LDA PIXCOL1
STA DDAT ; plot RED pixel TFT data
LDA PIXCOL2
STA DDAT ; plot GREEN pixel TFT data
LDA PIXCOL3
STA DDAT ; plot BLUE pixel TFT data
DEX
BNE xwp
BEQ nxtpix ; b: forced
xwnp LDA SCRCOL1
STA DDAT ; plot RED "blank" pixel TFT data
LDA SCRCOL2
STA DDAT ; plot GREEN "blank" pixel TFT data
LDA SCRCOL3
STA DDAT ; plot BLUE "blank" pixel TFT data
DEX
BNE xwnp
nxtpix PLA ; get pixel row data back
ASL ; another pixel to plot ?
BNE loop5 ; b: yes (sentinel still hasn't shifted out)
DEC PIXROW ; repeat this row ?
BNE loop4 ; b: yes
INY
DEC PATROW ; another pattern row to plot ?
BNE loop7 ; b: yes
PLA
TAX
PLA
TAY
PLA ;reload all reg's
RTS