summaryrefslogtreecommitdiff
path: root/programs/sub-suite/declare.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/declare.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/declare.s')
-rw-r--r--programs/sub-suite/declare.s88
1 files changed, 67 insertions, 21 deletions
diff --git a/programs/sub-suite/declare.s b/programs/sub-suite/declare.s
index 183d09d..6a8c90f 100644
--- a/programs/sub-suite/declare.s
+++ b/programs/sub-suite/declare.s
@@ -68,6 +68,19 @@
op .byte ; Base value used to get the actual opcode.
.endstruct
+; Free memory block struct, used by malloc.
+.struct fblk
+ size .qword ; Size of free memory block.
+ next .qword ; Pointer to next free block.
+ prev .qword ; Pointer to previous free block.
+.endstruct
+
+; Used memory block struct, used by malloc.
+.struct ublk
+ size .qword ; Size of used memory block.
+ start .qword ; Starting address of memory block.
+.endstruct
+
; Enums.
@@ -81,8 +94,17 @@ step = $110 ; Enables clock stepping, when set.
maxrow = 23 ; Screen's row count.
maxcol = 79 ; Screen's column count.
-MAX_SYM = $800 ; Max symbol size.
-OPNUM = 74 ; Instruction count.
+; Table sizes.
+SCRSIZE = $2000 ; Screen buffer size, in bytes.
+CMDSIZE = $400 ; Command buffer size, in bytes.
+LWSIZE = $1000 ; Linewrap table size, in bytes.
+
+; Magic number used by findramend.
+MAGIC = $AA
+
+; Heap related values.
+HEAPORG = $30000 ; Starting point of the heap.
+
; Directives.
DIR_ORG = 0 ; Origin.
@@ -164,23 +186,10 @@ IMPL = 1 << 10 ; Implied.
INDX2 = 1 << 11 ; Special case of INDX that uses the indirect table.
ZM2 = 1 << 12 ; Special case of Zero Matrix used by JMP, and JSR.
-
+OPNUM = 74 ; Instruction count.
; RAM declarations.
-; Linewrap table.
-.org $30000
-bitabl:
- .res $1000
-
-; Screen buffer.
-buffer:
- .res $2000
-
-; Command buffer.
-cmd_buf:
- .res $400
-
; Screen variables.
.org 0
scr_row:
@@ -238,10 +247,7 @@ ptr3:
.res 8
-; Token table.
.org $20000
-tokline:
- .res $400
; Program Counter.
prg_cnt:
@@ -327,14 +333,54 @@ lex_type:
lexeme:
.res $100
+; Size of the heap.
+heapsize:
+ .res 8
+
+; Start of the heap.
+heapstr:
+ .res 8
+
+; End of the heap.
+heapend:
+ .res 8
+
+; Current top of the heap.
+heapptr:
+ .res 8
+
+; First heap entry.
+heapf:
+ .res 8
+
+; Last heap entry.
+heapl:
+ .res 8
+
+; Linewrap table.
+bitabl:
+ .res 8
+
+; Screen buffer.
+buffer:
+ .res 8
+
+; Command buffer.
+cmd_buf:
+ .res 8
+
+; Token table.
+tokline:
+ .res 8
+
; Symbol table.
symbol:
- .res $8000
+ .res 8
; Fixup table.
; Fixups are unresolved symbols.
fixup:
- .res $2000
+ .res 8
; ROM data declarations.