Refactoring and cleanup
This commit is contained in:
parent
14bf02cf3d
commit
e74753c583
|
@ -1,23 +1,51 @@
|
||||||
|
; ****************************************
|
||||||
|
; 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
|
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
|
pla
|
||||||
sta $06
|
sta zp$+1
|
||||||
pla
|
|
||||||
sta $07
|
ldy #0 ; Y always 0 since we're incrementing the addr itself
|
||||||
ldy #0
|
|
||||||
.loop
|
.loop
|
||||||
inc $06
|
inc zp$ ; Increment zero page addr
|
||||||
bne .next
|
bne .next
|
||||||
inc $07
|
inc zp$+1
|
||||||
.next
|
.next
|
||||||
lda ($06),y
|
lda (zp$),y ; Read the next character
|
||||||
beq .done
|
beq .done ; Done if 0 (string terminator)
|
||||||
ora #$80
|
ora #$80 ; Else make printable
|
||||||
jsr COUT
|
jsr COUT ; Output the character to the screen
|
||||||
bne .loop
|
bne .loop ; Repeat
|
||||||
.done
|
.done
|
||||||
jsr CROUT
|
jsr CROUT ; Print carriage return at end of string
|
||||||
inc $06
|
|
||||||
bne .end
|
lda zp$+1 ; Copy zero page addr to stack for rts
|
||||||
inc $07
|
pha
|
||||||
.end
|
lda zp$
|
||||||
jmp ($06)
|
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
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
|
; ****************************************
|
||||||
|
; stdio
|
||||||
|
; ****************************************
|
||||||
|
;
|
||||||
; Source:
|
; Source:
|
||||||
; Assembly Cookbook for the Apple II/IIe part two by Don Lancaster
|
; Assembly Cookbook for the Apple II/IIe part two by Don Lancaster
|
||||||
; https://www.americanradiohistory.com/Archive-Don-Lancaster/aacb2.pdf
|
; https://www.americanradiohistory.com/Archive-Don-Lancaster/aacb2.pdf
|
||||||
|
;
|
||||||
|
; NOTE: This was copied from the above PDF and required some gentle
|
||||||
|
; massaging due to OCR errors. Not guaranteed to be typo-free.
|
||||||
|
|
||||||
WNDLFT EQU $20 ; SCROLL WINDOW LEFT
|
WNDLFT EQU $20 ; SCROLL WINDOW LEFT
|
||||||
WNDWDTH EQU $21 ; SCROLL WINDOW WIDTH
|
WNDWDTH EQU $21 ; SCROLL WINDOW WIDTH
|
||||||
|
|
16
src/main.asm
16
src/main.asm
|
@ -1,11 +1,21 @@
|
||||||
|
; ****************************************
|
||||||
|
; main.asm
|
||||||
|
; Copyright (C) 20XX [your_name_here]
|
||||||
|
; ****************************************
|
||||||
|
|
||||||
processor 6502
|
processor 6502
|
||||||
incdir "include"
|
incdir "include"
|
||||||
|
|
||||||
seg main
|
; ****************************************
|
||||||
|
; main
|
||||||
|
; ****************************************
|
||||||
|
|
||||||
|
seg
|
||||||
org $c00
|
org $c00
|
||||||
|
|
||||||
main subroutine
|
main subroutine
|
||||||
jsr HOME
|
|
||||||
|
jsr HOME ; Clear the screen
|
||||||
|
|
||||||
jsr print
|
jsr print
|
||||||
byte "YOUR PROGRAM WORKED!",0
|
byte "YOUR PROGRAM WORKED!",0
|
||||||
|
@ -13,7 +23,7 @@ main subroutine
|
||||||
jsr print
|
jsr print
|
||||||
byte '","CALL ",[main]d,'"," TO RUN AGAIN.",0
|
byte '","CALL ",[main]d,'"," TO RUN AGAIN.",0
|
||||||
|
|
||||||
jmp DOSWRM
|
jmp DOSWRM ; Return to Applesoft
|
||||||
|
|
||||||
; ****************************************
|
; ****************************************
|
||||||
; includes
|
; includes
|
||||||
|
|
Loading…
Reference in New Issue