Apple-6502-Scaffold/include/print

52 lines
1.8 KiB
Plaintext

; ****************************************
; print
; ****************************************
;
; A zero-terminated string should immediately follow "jsr print"
;
; Example:
; jsr print
; byte "HELLO WORLD",0
; [program resumes here]
;
; Destroys A, X, Y
print subroutine
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$
pla
sta zp$+1
ldy #0 ; Y always 0 since we're incrementing the addr itself
.loop
inc zp$ ; Increment zero page addr
bne .next
inc zp$+1
.next
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
.done
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