From e74753c583d4e3fe095079c48bd66668233e3b10 Mon Sep 17 00:00:00 2001 From: Lee Fastenau Date: Fri, 12 Apr 2019 00:50:47 -0700 Subject: [PATCH] Refactoring and cleanup --- include/print | 62 +++++++++++++++++++++++++++++++++++++-------------- include/stdio | 7 ++++++ src/main.asm | 16 ++++++++++--- 3 files changed, 65 insertions(+), 20 deletions(-) diff --git a/include/print b/include/print index 52a9e7a..e1bc8da 100644 --- a/include/print +++ b/include/print @@ -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 + +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 $06 - pla - sta $07 - ldy #0 + sta zp$+1 + + ldy #0 ; Y always 0 since we're incrementing the addr itself .loop - inc $06 + inc zp$ ; Increment zero page addr bne .next - inc $07 + inc zp$+1 .next - lda ($06),y - beq .done - ora #$80 - jsr COUT - bne .loop + 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 - inc $06 - bne .end - inc $07 -.end - jmp ($06) \ No newline at end of file + 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 diff --git a/include/stdio b/include/stdio index b22dcf8..504af37 100644 --- a/include/stdio +++ b/include/stdio @@ -1,6 +1,13 @@ +; **************************************** +; stdio +; **************************************** +; ; Source: ; Assembly Cookbook for the Apple II/IIe part two by Don Lancaster ; 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 WNDWDTH EQU $21 ; SCROLL WINDOW WIDTH diff --git a/src/main.asm b/src/main.asm index c95e016..daa5bca 100644 --- a/src/main.asm +++ b/src/main.asm @@ -1,11 +1,21 @@ +; **************************************** +; main.asm +; Copyright (C) 20XX [your_name_here] +; **************************************** + processor 6502 incdir "include" - seg main +; **************************************** +; main +; **************************************** + + seg org $c00 main subroutine - jsr HOME + + jsr HOME ; Clear the screen jsr print byte "YOUR PROGRAM WORKED!",0 @@ -13,7 +23,7 @@ main subroutine jsr print byte '","CALL ",[main]d,'"," TO RUN AGAIN.",0 - jmp DOSWRM + jmp DOSWRM ; Return to Applesoft ; **************************************** ; includes