Apple-6502-Scaffold/include/print

52 lines
1.8 KiB
Plaintext
Raw Normal View History

2019-04-12 07:50:47 +00:00
; ****************************************
; print
; ****************************************
;
; A zero-terminated string should immediately follow "jsr print"
;
; Example:
; jsr print
; byte "HELLO WORLD",0
; [program resumes here]
;
; Destroys A, X, Y
2019-04-12 06:34:51 +00:00
print subroutine
2019-04-12 07:50:47 +00:00
zp$ equ $06 ; Use some of that sweet, sweet zero page memory (non-destructive)
ldx zp$ ; Save zero page values to X and temp$
lda zp$+1
sta temp$
pla ; Copy jsr return address from stack to zero page
sta zp$
2019-04-12 06:34:51 +00:00
pla
2019-04-12 07:50:47 +00:00
sta zp$+1
ldy #0 ; Y always 0 since we're incrementing the addr itself
2019-04-12 06:34:51 +00:00
.loop
2019-04-12 07:50:47 +00:00
inc zp$ ; Increment zero page addr
2019-04-12 06:34:51 +00:00
bne .next
2019-04-12 07:50:47 +00:00
inc zp$+1
2019-04-12 06:34:51 +00:00
.next
2019-04-12 07:50:47 +00:00
lda (zp$),y ; Read the next character
beq .done ; Done if 0 (string terminator)
ora #$80 ; Else make printable
jsr COUT ; Output the character to the screen
bne .loop ; Repeat
2019-04-12 06:34:51 +00:00
.done
2019-04-12 07:50:47 +00:00
jsr CROUT ; Print carriage return at end of string
lda zp$+1 ; Copy zero page addr to stack for rts
pha
lda zp$
pha
stx zp$ ; Restore zero page values from X and temp$
lda #00 ; temp$ points to the immediate value here (self-modifying)
temp$ equ .-1
sta zp$+1
rts ; All done printing... that was kind of a pain