diff options
Diffstat (limited to 'programs/sub-suite/utils.s')
-rw-r--r-- | programs/sub-suite/utils.s | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/programs/sub-suite/utils.s b/programs/sub-suite/utils.s index 7e7469c..21539eb 100644 --- a/programs/sub-suite/utils.s +++ b/programs/sub-suite/utils.s @@ -318,3 +318,33 @@ get_ctrlidx: @del: lda #2 ; Return 2. rts ; End of get_ctrlidx. + + +findramend: + pha.q ; Set the end of RAM pointer to the argument. + and #0 ; Reset A. + tab ; Reset B. + lda #MAGIC ; Set A to a magic number. +@loop: + ldx (sp+1) ; Preserve the value. + sta (sp+1) ; Write the magic number to the current end of RAM. + cmp (sp+1) ; Is the value in RAM, the same as the magic number we wrote? + bne @moveback ; No, so move back until we find the last writable memory location. + stx (sp+1) ; Yes, so restore the previous value. + pha.q ; Preserve the magic number. + lda.q sp+9 ; Get the end of RAM pointer. + clc ; Prepare for a non carrying add. + adc.w #$4000 ; Increment the end of RAM pointer by 16K. + sta.q sp+9 ; Save the new end of RAM pointer. + pla.q ; Restore the magic number. + bra @loop ; Keep looping. +@moveback: + dec.q sp+1 ; Decrement the end of RAM pointer. + ldx (sp+1) ; Preserve the value. + sta (sp+1) ; Write the magic number to the current end of RAM. + cmp (sp+1) ; Is the value in RAM, the same as the magic number we wrote? + bne @moveback ; No, so keep looping. + stx (sp+1) ; Yes, so restore the previous value. +@end: + pla.q ; Restore the argument. + rts ; End of findramend. |