changeset 24:9586c547fcfa

Initialize the memory bookkeeping stuff at startup
author William Astle <lost@l-w.ca>
date Thu, 10 Nov 2022 21:29:47 -0700
parents 4b4806a32701
children 9593401d23cf
files src/lwbasic.s
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwbasic.s	Wed Nov 09 23:07:33 2022 -0700
+++ b/src/lwbasic.s	Thu Nov 10 21:29:47 2022 -0700
@@ -195,6 +195,15 @@
                 org 0
 dpstart         equ *                           ; start of direct page
 memtop          rmb 2                           ; absolute top of memory in 64K memory map
+memsize         rmb 2                           ; top of memory not reserved
+freetop         rmb 2                           ; top of free memory (bottom of string space)
+stringtab       rmb 2                           ; bottom of used string space
+progtext        rmb 2                           ; pointer to start of program text
+vartabint       rmb 2                           ; pointer to start of integer scalars
+vartabfloat     rmb 2                           ; pointer to start of floating point scalars
+vartabstring    rmb 2                           ; pointer to start of string scalars
+objecttab       rmb 2                           ; pointer to start of arrays and other variable sized objects
+freestart       rmb 2                           ; pointer to start of unallocated memory
 readlinenoecho  rmb 1                           ; if nonzero, the readline routine won't echo its input
                 rmb 0x71-*                      ; align RSTFLG/RSTVEC for stock ROM compatibility
 RSTFLG          rmb 1                           ; 0x55 if RSTVEC is valid
@@ -436,7 +445,20 @@
                 ldx #ROMSTART-1                 ; point to top of memory
                 endc
 coldstart2      stx memtop                      ; save absolute top of memory
+                stx memsize                     ; save top of unreserved memory
+                stx stringtab                   ; mark string space as empty
+                leax -200,x                     ; allocate 200 bytes of string space
+                stx freetop                     ; save top of free memory
                 leas ,x                         ; put the stack there
+                ldx #heapstart                  ; point to start of free memory
+                stx progtext                    ; put the start of the program there
+                clr ,x+                         ; put a NULL pointer to mark end of program
+                clr ,x+
+                stx vartabint                   ; put start of integer variables at end of program
+                stx vartabfloat                 ; put start of floating point variables after that
+                stx vartabstring                ; put start of string variables after that
+                stx objecttab                   ; also put the start of large objects there
+                stx freestart                   ; mark the start of free memory
                 ldx #warmstart                  ; set up warm start handler
                 stx RSTVEC
                 lda #0x55                       ; activate warm start handler