summaryrefslogtreecommitdiff
path: root/programs/sub-suite/subeditor.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/subeditor.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/subeditor.s')
-rw-r--r--programs/sub-suite/subeditor.s62
1 files changed, 49 insertions, 13 deletions
diff --git a/programs/sub-suite/subeditor.s b/programs/sub-suite/subeditor.s
index fdf1e4b..7e124a2 100644
--- a/programs/sub-suite/subeditor.s
+++ b/programs/sub-suite/subeditor.s
@@ -10,10 +10,44 @@ reset:
txs ;
ldy #0 ; Reset Y.
tyx ; Reset X.
+ jsr init_heap ; Initialize the heap.
+ jsr init_tables ; Initialize the main tables.
jsr clr_scr ; Clear the screen.
jsr pnt_strt ; Print the starting message.
bra start ; Goto the start of the main program.
+
+init_heap:
+ and #0 ; Reset A.
+ lda.d #HEAPORG ; Get the heap's starting point.
+ sta.q heapptr ;
+ phb.q ; Preserve the value in B.
+ phx.q ; Preserve the value in X.
+ jsr findramend ; Find the end of the heap.
+ plb.q ; Restore the value in B.
+ plx.q ; Restore the value in X.
+ sta.q heapend ; Save the end of the heap.
+ and #0 ; Reset A.
+ rts ; End of init_heap.
+
+
+init_tables:
+ and #0 ; Reset A.
+ lda.w #SCRSIZE ; Allocate SCRSIZE bytes of RAM for the screen buffer.
+ jsr malloc ;
+ sta.q buffer ;
+ and #0 ; Reset A.
+ lda.w #CMDSIZE ; Allocate CMDSIZE bytes of RAM for the command buffer.
+ jsr malloc ;
+ sta.q cmd_buf ;
+ and #0 ; Reset A.
+ lda.w #LWSIZE ; Allocate LWSIZE bytes of RAM for the linewrap table.
+ jsr malloc ;
+ sta.q bitabl ;
+ and #0 ; Reset A.
+ rts ; End of init_tables.
+
+
clr_arr:
phb ; Preserve whatever was in B.
ldb #0 ; Clear B.
@@ -67,9 +101,9 @@ pnt_strt:
clr_cmd:
and #0 ; Reset A.
tay ; Reset Y.
- lda.w #$3FF ; Set the clear count to $3FF.
+ lda.w #CMDSIZE ; Set the clear count to CMDSIZE.
sta.w scr_ptr ;
- lda.d #cmd_buf ; Set the array to be cleared to the command buffer.
+ lda.q cmd_buf ; Set the array to be cleared to the command buffer.
jsr clr_arr ; Clear the command buffer.
rts ; End of clr_cmd.
@@ -152,7 +186,7 @@ getbt0:
getbt1:
pha ; Save the parameter.
ldb #1 ; Make sure that set_ptr sets the second pointer.
- lda.d #bitabl ; Set the second pointer to the linewrap table.
+ lda.q bitabl ; Set the second pointer to the linewrap table.
jsr set_ptr ;
lsr #$10 ; Clear the Accumulator.
pla ; Get the return byte back.
@@ -168,7 +202,7 @@ getbt1:
clrbit:
pha ; Save the parameter.
ldb #1 ; Make sure that set_ptr sets the second pointer.
- lda.d #bitabl ; Set the second pointer to the linewrap table.
+ lda.q bitabl ; Set the second pointer to the linewrap table.
jsr set_ptr ;
and #0 ; Clear the Accumulator.
pla ; Get the return byte back.
@@ -188,7 +222,7 @@ bitout:
setbit:
pha ; Save the parameter.
ldb #1 ; Make sure that set_ptr sets the second pointer.
- lda.d #bitabl ; Set the second pointer to the linewrap table.
+ lda.q bitabl ; Set the second pointer to the linewrap table.
jsr set_ptr ;
and #0 ; Clear the Accumulator.
pla ; Get the return byte back.
@@ -283,10 +317,10 @@ cmd_cpy:
tay ; Place it into the index.
ldx.w #0 ; Reset the X register.
ldb #0 ; Make sure that set_ptr sets the first pointer.
- lda.d #buffer ; Set the first pointer to the start of the screen buffer.
+ lda.q buffer ; Set the first pointer to the start of the screen buffer.
jsr set_ptr ;
inb ; Make sure that set_ptr sets the second pointer.
- lda.d #cmd_buf ; Set the second pointer to the start of the command buffer.
+ lda.q cmd_buf ; Set the second pointer to the start of the command buffer.
jsr set_ptr ;
deb ; Set B back to zero.
tba ; Set the accumulator to zero.
@@ -344,7 +378,7 @@ findst:
fndend:
phb ; Save the contents of the B register.
ldb #0 ; Make sure that set_ptr sets the first pointer.
- lda.d #buffer ; Set the first pointer to the start of the screen buffer.
+ lda.q buffer ; Set the first pointer to the start of the screen buffer.
jsr set_ptr ;
tba ; Set the Accumulator to zero.
plb ; Restore the contents of the B register.
@@ -369,7 +403,7 @@ findend:
print_char:
sta rega ; Preserve the character.
ldb #2 ; Make sure that set_ptr sets the third pointer.
- lda.d #buffer ; Set the third pointer to the start of the screen buffer.
+ lda.q buffer ; Set the third pointer to the start of the screen buffer.
jsr set_ptr ;
deb ; Set B to one.
tba ; Reset A.
@@ -504,12 +538,14 @@ clr_scr:
sta scr_end ;
lda #0 ;
sta scr_str ;
- sta.q bitabl ;
- sta.q bitabl+8 ;
tay ;
- lda.w #$1FFF ; Set the clear count to $1FFF.
+ lda.w #LWSIZE ; Set the clear count to LWSIZE.
+ sta.w scr_ptr ;
+ lda.q bitabl ; Set the array to be cleared to the linewrap table.
+ jsr clr_arr ; Clear the linewrap table.
+ lda.w #SCRSIZE ; Set the clear count to SCRSIZE.
sta.w scr_ptr ;
- lda.d #buffer ; Set the array to be cleared to the screen buffer.
+ lda.q buffer ; Set the array to be cleared to the screen buffer.
jsr clr_arr ; Clear the screen buffer.
; tay ;
; lda.w #$3FF ; Set the clear count to $3FF.