draw_string

This commit is contained in:
Brooke Vibber 2025-02-01 10:02:01 -08:00
parent e0cc704d99
commit d182d33b35

141
mandel.s
View file

@ -34,7 +34,9 @@ count_frames = $be ; u8
; free space $bf
count_iters = $c0 ; u16
; free space c2-cb
text_col = $c2 ; u8
text_row = $c3 ; u8
; free space c4-cb
temp = $cc ; u16
temp2 = $ce ; u16
@ -140,16 +142,16 @@ KEY_0 = 50
strings:
str_self:
.byte "MANDEL-6502"
.byte "MANDEL-6502", 0
str_self_end:
str_speed:
.byte "us/iter: "
.byte "us/iter: ", 0
str_speed_end:
str_run:
.byte " RUN"
.byte " RUN", 0
str_run_end:
str_done:
.byte "DONE"
.byte "DONE", 0
str_done_end:
str_self_len = str_self_end - str_self
@ -1241,57 +1243,50 @@ done:
rts
.endproc
.macro draw_text_indirect col, len, strptr
; clobbers A, X
.local loop
.local done
.local padding
ldx #0
; in/out: column in text_col
; in: row in text_row @fixme implement
; in: pointer to string in INBUFF
; clobbers x/y/a/temp
.proc draw_string
drawptr = temp
strptr = INBUFF
clc
lda #.lobyte(textbuffer)
adc text_col
sta temp
lda #.hibyte(textbuffer)
adc #0
sta temp + 1
ldy #0
loop:
cpx #len
beq done
txa
tay
lda (strptr),y
pha ; save the char for terminator check
and #$7f ; strip the high bit (terminator)
tay
lda char_map,y
sta textbuffer + col,x
inx
; if char's null, terminate c-style
beq done
; save the char for terminator check
pha
; strip the high bit (terminator)
and #$7f
tax
lda char_map,x
sta (drawptr),y
iny
pla
bmi padding
; _last_ char has high bit set in atari rom routines
bmi done
jmp loop
padding:
ldy #32 ; space
lda char_map,y
cpx #len
beq done
sta textbuffer + col,x
inx
jmp padding
done:
.endmacro
; move the text column pointer
tya
clc
adc text_col
sta text_col
.macro draw_text col, len, cstr
; clobbers A, X
.local loop
.local done
ldx #0
loop:
cpx #len
beq done
ldy cstr,x
lda char_map,y
sta textbuffer + col,x
inx
jmp loop
done:
.endmacro
rts
.endproc
.proc vblank_handler
inc count_frames
@ -1506,8 +1501,24 @@ zero_byte_loop:
.proc status_bar
; Status bar
draw_text 0, str_self_len, str_self
draw_text 40 - str_run_len, str_run_len, str_run
lda #0
sta text_col
lda #0
sta text_row
lda #.lobyte(str_self)
sta INBUFF
lda #.hibyte(str_self)
sta INBUFF + 1
jsr draw_string
lda #(40 - str_run_len)
sta text_col
lda #.lobyte(str_run)
sta INBUFF
lda #.hibyte(str_run)
sta INBUFF + 1
jsr draw_string
rts
.endproc
@ -1758,13 +1769,19 @@ update_status:
clc
jsr IFP
; convert to ASCII in INBUFF
lda #speed_start
sta text_col
lda #0
sta text_row
lda #.lobyte(str_speed)
sta INBUFF
lda #.hibyte(str_speed)
sta INBUFF + 1
jsr draw_string
; convert to ASCII in INBUFF and print
jsr FASC
; print the first 6 digits
draw_text speed_start, str_speed_len, str_speed
draw_text_indirect speed_start + str_speed_len, speed_precision, INBUFF
jsr draw_string
skipped:
; sx += fill_level[fill_masks] + 1
@ -1812,7 +1829,17 @@ fill_loop_done:
loop:
; finished
draw_text 40 - str_done_len, str_done_len, str_done
lda #(40 - str_done_len)
sta text_col
lda #0
sta text_row
lda #.lobyte(str_done)
sta INBUFF
lda #.hibyte(str_done)
sta INBUFF + 1
jsr draw_string
jsr keycheck
beq loop
jmp main_loop