summaryrefslogtreecommitdiff
path: root/programs/sub-suite/utils.s
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-10-04 18:22:00 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-10-04 18:22:00 -0400
commitca8e2f93acc794b00464c5513956bd84de258913 (patch)
tree83153822fdea777bd11a8254c0e4bd87fe1d8350 /programs/sub-suite/utils.s
parent784ff59108b887e246b0f33ff696dfd981659ab2 (diff)
- Added support for reading, and writing outside the
emulator's memory. All reads outside of the emulator's memory give back $/0xFF bytes, while all writes outside of the emulator's memory are ignored. - Implemented malloc(), and free() in the SuB Suite. In order to do this, I had to add support for a heap, which I did by reserving the first 3 banks of the address space (the first 192K), and by adding a routine that finds the end of the RAM. In this case, I set the starting address for the routine at bank 3 (bank 4 with one indexing), but, the routine's starting address isn't hardcoded, and thus, any starting address can be passed as an argument. The routine uses the fact that we can now read/write outside the emulator's memory, and also uses the fact that writing outside the emulator's memory will be ignored, and that reading outside the emulator's memory will always read $/0xFF bytes, and uses that to signal that it's reached the end of the RAM. - Added a test program for getting the size of RAM starting at address $/0x20000.
Diffstat (limited to 'programs/sub-suite/utils.s')
-rw-r--r--programs/sub-suite/utils.s30
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.