4cade/src/ui.font.a
2021-10-28 00:40:20 -04:00

165 lines
4.0 KiB
Plaintext

;license:MIT
;(c) 2018-2020 by 4am
;
; hi-res font drawing routines
;
; Public functions
; - Draw40Chars
; - DrawCenteredString
; - DrawString
;
Draw40Chars
; A/Y contains address of character buffer
; carry bit clear -> draw on page 1
; carry bit set -> draw on page 2
; $25 contains textpage line (0..23) (this is the standard VTAB address)
; drawing starts at HTAB 0
; increments VTAB on exit
; sets HTAB to 0 on exit
; Z=1 on exit
; clobbers A/X/Y
jsr +
ldx #40
jsr .DrawBufferInternal
+ ldx #0
stx HTAB
rts
DrawCenteredString
; A/Y contains address of length-prefixed string
; carry bit clear -> draw on page 1
; carry bit set -> draw on page 2
; $25 contains textpage line (0..23) (this is the standard VTAB address)
; clobbers A/X/Y
+ST16 PTR
php
ldy #0
lda #40
sec
sbc (PTR),y
lsr
sta HTAB
plp
jmp DrawString_PTR_is_already_set
DrawString
; A/Y contains address of length-prefixed string
; length can be 0
; carry bit clear -> draw on page 1
; carry bit set -> draw on page 2
; $24 contains starting column (0..39) (this is the standard HTAB address)
; $25 contains textpage line (0..23) (this is the standard VTAB address)
; clobbers A/X/Y
+ST16 PTR
DrawString_PTR_is_already_set
ldy #0
lda (PTR),y
inc PTR
bne +
inc PTR+1
+ tax
bpl +
rts
+
+LD16 PTR
; /!\ execution falls through here to .DrawBufferInternal
.DrawBufferInternal
; [private]
; A/Y contains address of character buffer
; X contains buffer length (0..40)
; carry bit clear -> draw on page 1
; carry bit set -> draw on page 2
; characters MUST have high bit off (0x00..0x7F)
; special characters (0x00..0x1F) will be drawn
; $24 contains starting column (0..39) (this is the standard HTAB address)
; $25 contains textpage line (0..23) (this is the standard VTAB address)
; all characters are drawn on the same line
; HTAB is incremented for each character
; clobbers X,Y
; increments VTAB on exit
; A=buffer length on exit
; N=0,Z=0 on exit
+ST16 DBISrc+1
php
lda VTAB
asl
asl
asl
; routine to calculate memory address within HGR page
; and self-modify addresses within draw loop that follows
; (routine clobbers A and Y but preserves X)
asl
tay
and #$F0
bpl @calc1
ora #$05
@calc1 bcc @calc2
ora #$0A
@calc2 asl
asl
sta @hgrlo+1
tya
and #$0E
adc #$10
asl @hgrlo+1
rol
plp
bcc +
eor #$60
clc
+
sta DBIRow0+2
adc #$04
sta DBIRow1+2
adc #$04
sta DBIRow2+2
adc #$04
sta DBIRow3+2
adc #$04
sta DBIRow4+2
adc #$04
sta DBIRow5+2
adc #$04
sta DBIRow6+2
adc #$04
sta DBIRow7+2
@hgrlo lda #$FD
adc HTAB
sta DBIRow0+1
sta DBIRow1+1
sta DBIRow2+1
sta DBIRow3+1
sta DBIRow4+1
sta DBIRow5+1
sta DBIRow6+1
sta DBIRow7+1
txa
pha
bpl + ; always branches because X is 0..40
DBILoop
DBISrc ldy $FDFD,x
lda FontDataRow0,y
DBIRow0 sta $FDFD,x
lda FontDataRow1,y
DBIRow1 sta $FDFD,x
lda FontDataRow2,y
DBIRow2 sta $FDFD,x
lda FontDataRow3,y
DBIRow3 sta $FDFD,x
lda FontDataRow4,y
DBIRow4 sta $FDFD,x
lda FontDataRow5,y
DBIRow5 sta $FDFD,x
lda FontDataRow6,y
DBIRow6 sta $FDFD,x
lda FontDataRow7,y
DBIRow7 sta $FDFD,x
inc HTAB
+ dex
bpl DBILoop
pla ; A = buffer length (passed in in X)
inc VTAB
rts