Generalized font engine entry points

This commit is contained in:
blondie7575 2023-07-13 14:33:34 -07:00
parent 61efb73959
commit 36474e22dd
2 changed files with 34 additions and 4 deletions

View File

@ -10,28 +10,46 @@ FIRST_CHAR = 32
; ;
; Draws a Pascal string ; Draws a Pascal string
; ;
; PARAM0L = Pointer to string ; PARAML0 = Pointer to string
; PARAML1 = Width of one character in pixels (you can tweak kerning if you like)
; X = Font index
; Y = VRAM position of lower right corner of string at which to draw ; Y = VRAM position of lower right corner of string at which to draw
; ;
; Trashes SCRATCHL, X, Y, A ; Trashes SCRATCHL, X, Y, A
; ;
renderString: renderString:
NATIVE NATIVE
sty SCRATCHL SAVE_DBR
sty SCRATCHL ; Cache VRAM position
txa ; Cache font character table
asl
tay
lda fontJumpTable,y
sta renderCharBounce+1
lda PARAML1 ; Convert pixel width to bytes
lsr
sta PARAML1
plb ; Temporarily revert to caller's DBR to access their pointer
BITS8 BITS8
lda (PARAML0) lda (PARAML0)
tax tax
BITS16 BITS16
phb
renderStringLoop: renderStringLoop:
; Fetch and render next character in string ; Fetch and render next character in string
txy txy
lda #0 lda #0
plb ; Temporarily revert to caller's DBR to access their pointer
BITS8A BITS8A
lda (PARAML0),y lda (PARAML0),y
BITS16 BITS16
phb
ldy SCRATCHL ldy SCRATCHL
jsr renderChar jsr renderChar
@ -41,11 +59,12 @@ renderStringLoop:
; Calculate VRAM pointer for position of next character ; Calculate VRAM pointer for position of next character
lda SCRATCHL lda SCRATCHL
sec sec
sbc #8 sbc PARAML1
sta SCRATCHL sta SCRATCHL
bra renderStringLoop bra renderStringLoop
renderStringDone: renderStringDone:
RESTORE_DBR
rtl rtl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -64,13 +83,21 @@ renderChar:
asl asl
tax tax
FASTGRAPHICS FASTGRAPHICS
renderCharBounce: ; Self modifying code. Don't panic
jmp (font16characterJumpTable,x) jmp (font16characterJumpTable,x)
renderCharJumpReturn: ; Compiled glyphs jump back here. Can't rts because stack is turboborked renderCharJumpReturn: ; Compiled glyphs jump back here. Can't rts because stack is turboborked
SLOWGRAPHICS SLOWGRAPHICS
RESTORE_AXY
RESTORE_AXY
rts rts
fontJumpTable:
.addr font8characterJumpTable
.addr font16characterJumpTable
.include "font8x8.s" .include "font8x8.s"
.include "font16x16.s" .include "font16x16.s"

View File

@ -71,7 +71,10 @@ beginGameplay:
; Test font renderer ; Test font renderer
lda #testString lda #testString
sta PARAML0 sta PARAML0
lda #8
sta PARAML1
ldy #$4430 ; Correct start of line address for 16 wide: $4bc7 ldy #$4430 ; Correct start of line address for 16 wide: $4bc7
ldx #0
jsl $050000 jsl $050000
bra gameplayLoop bra gameplayLoop
testString: testString: