2019-10-09 17:04:39 +00:00
|
|
|
;license:MIT
|
2021-10-18 01:12:04 +00:00
|
|
|
;(c) 2018-2021 by 4am
|
2019-10-09 17:04:39 +00:00
|
|
|
;
|
|
|
|
; hi-res font drawing routines
|
|
|
|
;
|
|
|
|
; /!\ These live in LC RAM 2 and rely on the font data which is also in LC RAM 2. /!\
|
2019-10-09 17:05:08 +00:00
|
|
|
; Code in LC RAM 1 (which is most program code) should call the functions in ui.font
|
2019-10-09 17:04:39 +00:00
|
|
|
; which handle bank switching for you.
|
|
|
|
;
|
|
|
|
|
|
|
|
DrawPageInternal
|
2021-10-18 01:12:04 +00:00
|
|
|
; A/Y contains address of array of length-prefixed strings
|
|
|
|
; length #$FF terminates
|
2019-12-20 15:25:30 +00:00
|
|
|
; X contains 0-indexed left margin (HTAB)
|
2019-10-09 17:04:39 +00:00
|
|
|
; carry bit clear -> draw on page 1
|
|
|
|
; carry bit set -> draw on page 2
|
2019-12-20 15:25:30 +00:00
|
|
|
; drawing starts at VTAB 0
|
|
|
|
; each line starts at column X which was passed in (0-indexed)
|
2019-10-09 17:04:39 +00:00
|
|
|
; clobbers PTR
|
2020-08-11 18:55:38 +00:00
|
|
|
; clobbers $FF
|
2019-10-09 17:04:39 +00:00
|
|
|
; clobbers A/X/Y
|
2021-10-18 01:12:04 +00:00
|
|
|
; preserves all flags
|
2019-10-09 17:04:39 +00:00
|
|
|
php
|
2020-08-11 18:55:38 +00:00
|
|
|
stx $FF
|
2019-10-09 17:04:39 +00:00
|
|
|
ldx #0
|
|
|
|
stx VTAB
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 PTR
|
2019-10-09 17:04:39 +00:00
|
|
|
@drawLine
|
2020-08-11 18:55:38 +00:00
|
|
|
lda $FF
|
2019-12-20 15:25:30 +00:00
|
|
|
sta HTAB
|
2019-10-09 17:04:39 +00:00
|
|
|
ldy #0
|
2021-10-18 01:12:04 +00:00
|
|
|
lda (PTR), y ; A = length of line, or #$FF
|
|
|
|
bmi PLP_AND_RTS ; if #$FF then we're done
|
2019-10-09 17:04:39 +00:00
|
|
|
plp
|
2021-10-18 01:12:04 +00:00
|
|
|
php ; C = whatever was passed in
|
|
|
|
pha ; save length
|
|
|
|
jsr DrawStringSuperInternal
|
|
|
|
pla ; A = length of line
|
|
|
|
clc ; advance PTR to start of next line
|
2019-10-09 17:04:39 +00:00
|
|
|
adc PTR
|
|
|
|
sta PTR
|
|
|
|
bcc +
|
|
|
|
inc PTR+1
|
2021-10-18 01:12:04 +00:00
|
|
|
+ inc VTAB ; this will print 255 lines if you give
|
|
|
|
bne @drawLine ; it 255 lines, because this is assembly
|
|
|
|
PLP_AND_RTS
|
2019-10-09 17:04:39 +00:00
|
|
|
plp
|
|
|
|
rts
|
|
|
|
|
|
|
|
Draw40CharsInternal
|
|
|
|
; A/Y contains address of character buffer
|
|
|
|
; carry bit clear -> draw on page 1
|
2020-08-11 18:55:38 +00:00
|
|
|
;v carry bit set -> draw on page 2
|
2019-10-09 17:04:39 +00:00
|
|
|
; $25 contains textpage line (0..23) (this is the standard VTAB address)
|
|
|
|
; drawing starts at HTAB 0
|
|
|
|
; increments VTAB
|
|
|
|
; sets HTAB to 0 on exit
|
|
|
|
; clobbers A/X/Y
|
|
|
|
jsr +
|
|
|
|
ldx #40
|
|
|
|
jsr DrawBufferInternal
|
|
|
|
inc VTAB
|
|
|
|
+ ldx #0
|
|
|
|
stx HTAB
|
|
|
|
rts
|
|
|
|
|
|
|
|
DrawCenteredStringInternal
|
|
|
|
; 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
|
|
|
|
; clobbers PTR/PTR+1
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 PTR
|
2019-10-09 17:04:39 +00:00
|
|
|
ldy #0
|
2020-01-28 19:19:10 +00:00
|
|
|
php
|
2019-10-09 17:04:39 +00:00
|
|
|
lda #40
|
|
|
|
sec
|
2020-01-28 19:19:10 +00:00
|
|
|
sbc (PTR),y
|
2019-10-09 17:04:39 +00:00
|
|
|
lsr
|
|
|
|
sta HTAB
|
|
|
|
plp
|
2020-01-28 19:19:10 +00:00
|
|
|
beq +
|
2019-10-09 17:04:39 +00:00
|
|
|
|
|
|
|
DrawStringInternal
|
|
|
|
; A/Y contains address of length-prefixed string
|
|
|
|
; 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
|
|
|
|
; clobbers PTR/PTR+1
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 PTR
|
2019-10-09 17:04:39 +00:00
|
|
|
ldy #0
|
|
|
|
+ lda (PTR),y
|
2021-10-18 01:12:04 +00:00
|
|
|
DrawStringSuperInternal
|
2021-10-18 01:17:34 +00:00
|
|
|
tax
|
2019-10-09 17:04:39 +00:00
|
|
|
inc PTR
|
|
|
|
bne +
|
|
|
|
inc PTR+1
|
|
|
|
+
|
2020-03-24 20:30:14 +00:00
|
|
|
+LD16 PTR
|
2019-10-09 17:04:39 +00:00
|
|
|
; /!\ execution falls through here to DrawBufferInternal
|
|
|
|
|
|
|
|
DrawBufferInternal
|
|
|
|
; A/Y contains address of character buffer
|
2021-10-18 01:12:04 +00:00
|
|
|
; X contains buffer length (0..40)
|
2019-10-09 17:04:39 +00:00
|
|
|
; 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
|
|
|
|
; VTAB is NOT incremented
|
|
|
|
; clobbers A/X/Y
|
2020-03-24 20:30:14 +00:00
|
|
|
+ST16 DBISrc+1
|
2020-01-28 19:19:10 +00:00
|
|
|
php
|
2019-10-09 17:04:39 +00:00
|
|
|
dex
|
2021-10-18 01:12:04 +00:00
|
|
|
bmi PLP_AND_RTS ; empty string
|
2019-10-09 17:04:39 +00:00
|
|
|
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
|
2020-01-28 19:19:10 +00:00
|
|
|
plp
|
|
|
|
bcc +
|
|
|
|
eor #$60
|
2019-10-09 17:04:39 +00:00
|
|
|
clc
|
2020-01-28 19:19:10 +00:00
|
|
|
+
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow0+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow1+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow2+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow3+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow4+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow5+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow6+2
|
2019-10-09 17:04:39 +00:00
|
|
|
adc #$04
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow7+2
|
2019-10-09 17:04:39 +00:00
|
|
|
@hgrlo lda #$FD
|
|
|
|
clc
|
|
|
|
adc HTAB
|
2020-03-08 02:06:49 +00:00
|
|
|
sta DBIRow0+1
|
|
|
|
sta DBIRow1+1
|
|
|
|
sta DBIRow2+1
|
|
|
|
sta DBIRow3+1
|
|
|
|
sta DBIRow4+1
|
|
|
|
sta DBIRow5+1
|
|
|
|
sta DBIRow6+1
|
|
|
|
sta DBIRow7+1
|
|
|
|
DBILoop
|
|
|
|
DBISrc ldy $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow0,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow0 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow1,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow1 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow2,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow2 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow3,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow3 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow4,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow4 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow5,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow5 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow6,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow6 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
lda FontDataRow7,y
|
2020-03-08 02:06:49 +00:00
|
|
|
DBIRow7 sta $FDFD,x
|
2019-10-09 17:04:39 +00:00
|
|
|
inc HTAB
|
|
|
|
dex
|
2020-03-08 02:06:49 +00:00
|
|
|
bpl DBILoop
|
2019-10-09 17:04:39 +00:00
|
|
|
rts
|