Code: Select all
JMPCode: Select all
JSRCode: Select all
JMPCode: Select all
JSRCode: Select all
JSR DISP_QUOTE
BYTE 25, "Press CONTINUE when ready"Code: Select all
DISP_IM "Press CONTINUE when ready"Code: Select all
JMP DISP_QUOTE
BYTE 19, "This is a tail call"
Code: Select all
org $0
ds 254
pString ds 2 ; Zero page location holds return address
; which is a pointer to the string to display
org $0200 ; Beginning of RAM
Start: jsr Disp_Quote
db 25, "Press CONTINUE when ready"
Next: brk
align 8
; On entry all registers preserved on stack
;
; Stack lays out as follows
;
; S+1 A
; S+2 X
; S+3 Y
; S+4 P
; S+5 Return Lo
; S+6 Return Hi
;
; Assume S = $80 and that its value is captured in X using tsx, then the
; address $105,x will yield $0185, which is S+5 in the stack page
;
; At completion of this routine, return address on stack should point to Next
Disp_Quote: php ; Save all registers
phy
phx
pha
tsx ; Capture current stack pointer in X
lda $105,x ; Read return address low from the stack
sta pString ; Store in low byte of zp pointer
lda $106,x ; Read return address high from the stack
sta pString+1 ; Store in high byte of zp pointer
lda (pString) ; load count into X
tax
ldy #$01 ; load index to first character in string
Disp_Lp: lda (pString),y ; load character into address
jsr put_ch ; output character
iny ; increment character index
dex ; decrement character counter
bne Disp_Lp ; loop until all characters sent to output
tsx ; capture S in X
clc ; prepare to offset the return address
lda (pString) ; load string length into A
adc $105,x ; add offset to low byte of return address
sta $105,x ; store adjusted low byte of return address
lda #0 ; prepare to adjust high byte of return address
adc $106,x ; add carry out of low byte adjustment
sta $106,x ; store adjuste high byte of return address
pla ; restore registers
plx
ply
plp
rts ; return from Disp_Quote routine
; Example output routine
put_ch: sta $F400 ;
rts