changeset 136:e49bd0493baf

Checkpoint updates to immediate mode program editing and some memory handling
author William Astle <lost@l-w.ca>
date Fri, 12 Jul 2024 23:29:45 -0600
parents 3a4cb89a419c
children 18940aa42dcf
files src/init.s src/interp.s src/memory.s src/progctrl.s src/vars.s
diffstat 5 files changed, 196 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/src/init.s	Tue Jul 09 22:18:30 2024 -0600
+++ b/src/init.s	Fri Jul 12 23:29:45 2024 -0600
@@ -218,7 +218,7 @@
                 leas ,x                         ; put the actual stack below the above
                 ldx #heapstart                  ; point to start of free memory
                 clr ,x+                         ; put a NUL before the start of the program
-                stx progtext                    ; put the start of the program there
+                stx prog_text                   ; put the start of the program there
                 clr ,x+                         ; put a NULL pointer to mark end of program
                 clr ,x+
                 stx vartab                      ; put start of integer variables at end of program
--- a/src/interp.s	Tue Jul 09 22:18:30 2024 -0600
+++ b/src/interp.s	Fri Jul 12 23:29:45 2024 -0600
@@ -14,7 +14,7 @@
 ; fact that it is called with an extended JSR instead of a direct JSR which causes one extra cycle to be used there
 ; and one extra byte for each call to nextchar or curchar.
 ;
-; On 6309, native move saves an extra cycle in the LDA sequence using the LDA extended followed by JMP extended
+; On 6309, native mode saves an extra cycle in the LDA sequence using the LDA extended followed by JMP extended
 ; sequence.
 ;
 ; This whole thing could be sped up by keeping the input pointer in a register. However, retaining the ability to
@@ -62,47 +62,81 @@
                 suba #-'0
 setcifdigit0    rts
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; Immediate mode handler
-immediatee      jsr ERRORstr                    ; get error string
-                jsr writestrconduc              ; display it
-                ldx #atmsg                      ; output " at "
-                jsr writestrconduc
-                leax ,u                         ; point to error location
-                jsr console_outstr              ; display remaining line part (but preserve case this time)
+; Immediate mode handler. This operates as follows:
+; 1. Write a newline if needed
+; 2. Output the prompt if needed
+; 3. Read an input line
+; 4. If the line is terminated by BREAK/ESC, go back to 3
+; 5. Find the first non-space character. If it is numeric, go on to 7
+; 6. Tokenize the input line, interpret it, and go back to 1
+; 7. Parse the line number. If it is invalid, do a syntax error
+; 8. Find the line number in the program and remove it if present
+; 9. If there is no non-space character after the number, go back to 3
+; 10. Tokenize the line and insert it into the program
+; 11. Go back to 3
 immediate       jsr writecondnl                 ; do newline if required
                 ldx #prompt                     ; point to prompt string
                 jsr console_outstrn
 immediate0      jsr readline                    ; read input line
                 bcs immediate0                  ; brif ended with BREAK
                 ldx #linebuff                   ; point to start of line input buffer
-immediate0a     lda ,x                          ; do we have anything at all?
+immediate0a     lda ,x+                         ; do we have anything at all?
                 beq immediate0                  ; brif not - just read another line
                 cmpa #0x20                      ; space?
-                bne immediate0c                 ; brif not
-immediate0b     leax 1,x                        ; move past the space
-                bra immediate0a                 ; keep looking for the start of input
-immediate0c     bsr setcifdigit                 ; do we have a line number?
+                beq immediate0a                 ; brif so
+                leax -1,x                       ; compensate for extra increment above
+                bsr setcifdigit                 ; do we have a line number?
                 bcs immediate1                  ; brif so - go handle program editing
-                clrb                            ; flag to do actual parsing
-                jsr parse                       ; go parse the line
+                jsr parse                       ; parse the line into tokens
                 bcs immediatee                  ; brif there was a parse error
-                bra *
                 jsr interpretline               ; go interpret the tokenized line
                 bra immediate                   ; go handle another line
-immediate1      bsr parse_lineno                ; parse the line number
-                jsr prog_remove                 ; remove the line from the program if it exists
-immediate3      jsr curchar                     ; skip any spaces after line number
+immediatee      jmp SNERROR                     ; go do a syntax error
+immediate1      stx inputptr                    ; save input pointer for parsing purposes
+                bsr parse_lineno                ; parse the line number that was provided
+                bsr prog_delline                ; remove the line from the program if it exists
+                jsr curchar                     ; skip any spaces after line number
                 tsta                            ; is it the end of input (don't test for colon)
                 beq immediate6                  ; brif so - we don't need to insert a line
                 ldx inputptr                    ; point to line text
                 jsr parse                       ; tokenize line, get length to D
-                ldy binval                      ; get the line number
-                jsr prog_insert                 ; insert the encoded line at X into program as line Y
+                ldd binval                      ; get the line number
+                jsr prog_addline                ; insert the encoded line at X into program as line Y
 immediate6      ldx vartab                      ; clear out variables
                 stx objecttab
                 stx freestart
                 bra immediate0                  ; go handle more input
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Parse a line number and return it in binval; raise syntax error if the line number overflows 16 bits unsigned.
+; Preserves; registers except D. This will accept the entire 16 bit unsigned number range which is why there is
+; a BCS after every shift or add. Enter with the input pointer pointing to the number to parse.
+parse_lineno    ldd zero                        ; clear out accumlator but preserve carry flag
+                std binval
+                jsr curchar                     ; set flags on current character; skip spaces
+                bcc parse_lineno1               ; brif first character wasn't a digit - default to zero
+parse_lineno0   suba #0x30                      ; adjust to binary digit
+                pshs a                          ; save digit so we can add it later
+                ldd binval                      ; get accumulated number
+                lslb                            ; multiply accumulator by 10
+                rola                            ; times 2
+                bcs parse_lineno2               ; brif overflow
+                lslb
+                rola                            ; times 4
+                bcs parse_lineno2               ; brif overflow
+                addd binval                     ; times 5 (add orignal value to times 4)
+                bcs parse_lineno2               ; brif overflow
+                lslb
+                rola                            ; times 10
+                bcs parse_lineno2               ; brif overflow
+                addb ,s+                        ; add in accumulated digit
+                adca #0
+                bcs parse_lineno2               ; brif overflow
+                std binval                      ; save accumulated number
+                jsr nextcharraw                 ; get next input character; DO NOT skip spaces
+                bcs parse_lineno0               ; brif it's also a digit
+parse_lineno1   rts
+parse_lineno2   jmp SNERROR                     ; relay to syntax error
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Find line number table entry
 ;
 ; Entry:
@@ -118,7 +152,7 @@
 ; This works by doing a binary search through the line number table.
 prog_findline   ldu prog_linetab                ; point to program line table
                 ldx prog_linetabp               ; get end of table
-                leax -prog_lineentl,u           ; move back to the start of the last entry
+                leax -linetabent_size,u         ; move back to the start of the last entry
                 pshs x,u                        ; save "high" at 0,s and "low" at 2,s
                 tfr d,x                         ; save line number for later comparisons
 prog_findline1  ldd ,s                          ; get high pointer
@@ -132,12 +166,12 @@
                 cmpx linetabent_num,u           ; is the desired number less, equal, or greater?
                 beq prog_findline2              ; brif match
                 blo prog_findline3              ; brif desired line is lower
-                leau prog_lineentl,u            ; skip past this non-matching item
+                leau linetabent_size,u          ; skip past this non-matching item
                 stu 2,s                         ; save new low pointer
                 bra prog_findline1              ; go do another iteration
-prog_findline2  leas 4,s                        ; clean up the temporaries (C clear from compare above)
-                rts
-prog_findline3  leau -prog_lineentl,u           ; move before this non-matching entry
+prog_findline2  leas 4,s                        ;* clean up the temporaries (C clear from compare above or set from
+                rts                             ;* subtraction above
+prog_findline3  leau -linetabent_size,u         ; move before this non-matching entry
                 stu ,s                          ; save new top entry pointer
                 bra prog_findline1              ; go do another iteration
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -173,127 +207,105 @@
                 blo prog_delline2               ; brif not
                 leau -linetabent_size,u         ; move back to the last actual entry
                 stu prog_linetabp               ; update the line table pointer
-                leas 2,s                        ; clear out the temp we no longer need
-                jsr cmd_newvars                 ; clear the variables out
-prog_delline3   rts
+                bsr prog_shrinklt               ; shrink the line table if appropriate
+                jmp cmd_newvars                 ; clear out the variable table
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; prog_shrinklt: shrink the line table to its minimum possible size, but keep it a multiple of linetab_stride entries
+; prog_shrinklt: shrink the line table to its minimum possible size, but keep it a multiple of linetab_stride entries.
+; This will leave the state of the variable table undefined so it needs to be cleared out properly before doing anything
+; else after using this routine.
 prog_shrinklt   ldd prog_linetabp               ; get the end of the table entries
                 subd prog_linetab               ; now we have the length of the table
-                andb #(linetabent_size*linetab_stride)-1 ; is there a remainder?
+                pshs d                          ; save original size
+                bitb #(linetabent_size*linetab_stride)-1 ; is there a remainder?
                 beq prog_shrinklt0              ; brif not
-                addd #linetabent_size*linetab_strider
-prog_shrinklt0  tfr d,u                         ; put in a pointer register
-                leau linetabent_size,x          ; move to the end of the phantom entry
-                cmpu prog_text                  ; anything to do?
-                beq prog_shrinklt2              ; brif not
-                ldx prog_text                   ; point to source copy point
-prog_shrinklt1  lda ,x+                         ; copy a byte down
-                sta ,u+
-                cmpx vartab                     ; end of program?
-                blo prog_shrinklt1              ; brif not
-                stu vartab                      ; save new end of program
-                jmp cmd_newvars                 ; clear variables
-prog_shrinklt2  rts
-
+                andb #~((linetabent_size*linetab_stride)-1) ; actually round down now
+                addd #linetabent_size*linetab_stride ; and go up to the next stride
+prog_shrinklt0  subd ,s++                       ; now D is the difference in size; will be negative if shrinking
+                bne prog_resizelt               ; brif there is something to do - go resize the table
+prog_delline3   rts
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; prog_expandlt: expand the line table by one stride size.
+prog_expandlt   ldd #linetabent_size*linetab_stride ; get size of an expansion strider
+                ; fall through to the resize routine
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; Insert a line into the program
+; Adjust the size of the program line table, either larger or smaller.
+;
+; Enter:
+; D: the number of bytes to expand the table by; negative to shrink it; must be a multiple of the table entry size
+;
+; Exit:
+; D: the number of bytes the table was expanded (negative means shrinkage)
+; * prog_text: points to the new start of the program text
+; * vartab: points to the new start of the variable table
+; * all program line pointers are adjusted by D bytes
+;
+; Error:
+; * OM error if there isn't enough memory to expand the table by D bytes
+prog_resizelt   pshs d                          ; we're going to need the size number later
+                ldu prog_text                   ; point to start of program text
+                leax d,u                        ; point to the new address to copy to
+                addd vartab                     ; calculate the new start of the variable table
+                tfr d,y                         ; save it for later
+                jsr mem_checkptr                ; throw an error if it doesn't fit
+                ldd vartab                      ; get the end of the program text
+                subd prog_text                  ; now D is the number of bytes to copy
+                stx prog_text                   ; save new program text pointer
+                sty vartab                      ; save new variable table pointer
+                jsr mem_copy                    ; copy the program text up or down
+                ldx prog_linetab                ; point to first entry in the program line table
+prog_resizelt0  ldd linetabent_ptr,x            ; get the pointer for this entry
+                addd ,s                         ; add in the offset
+                std linetabent_ptr,x            ; save updated pointer
+                leax 4,x                        ; move to next entry
+                cmpx prog_text                  ; end of table?
+                blo prog_resizelt0              ; brif not
+                puls d,pc                       ; clean up stack and return
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Insert a line into the program.
+;
+; Note that we do a sequential walk back from the end of the line table looking for the insert location because we can
+; update all the line data pointers on the way through and that has to be done one by one anyway.
 ;
 ; Entry:
 ; D: length of line to insert
-; X: pointer to line data to insert
+; X: pointer to line data to insert *which MUST be within the prog_text...vartab area*
 ; U: the line number we're adding
 prog_addline    pshs d,x,u                      ; save length and pointer
                 ldx prog_linetabp               ; get line table pointer
                 leax linetabent_size,x          ; add in space for new entry
                 cmpx prog_text                  ; did we run into the program?
                 blo prog_addline0               ; brif not
-                addd #linetabent_size*linetab_stride ; add in space for expanded line table
-prog_addline0   addd vartab                     ; calculate the new end of program data
-                jsr checkmem_addr               ; verify there is enough memory
-                cmpx prog_text                  ; do we need to expand the line number table?
-                blo prog_addline3               ; brif not
-                ldx vartab                      ; point to byte past end of program
-                leau linetab_stride*linetabent_size,x ; set up destination pointer
-                stu vartab                      ; set up new end of program text
-prog_addline1   lda ,-x                         ; copy a byte up
-                sta ,-u
-                cmpx prog_text                  ; did we hit the start of the program?
-                bne prog_addline1               ; brif not
-                ldx prog_linetab                ; point to start of line table
-prog_addline2   ldd linetabent_ptr,x            ; get pointer to this line
-                addd #linetab_stride*linetabent_size ; adjust offset for the expanded table
+                bsr prog_expandlt               ; expand the program line table
+                ldx 2,s                         ; adjust the pointer for the line to insert
+                leax d,x
+                stx 2,s
+prog_addline0   ldu prog_linetabp               ; point to the end of the line table
+                leax linetabent_size,x          ; point to the new end of the table
+                stx prog_linetabp               ; save new end of table pointer
+                ldd linetabent_ptr,u            ; move the dummy end of table pointer up one slot
+                addd ,s                         ; (and adjust for the insert)
                 std linetabent_ptr,x
-                leax linetabent_size,x          ; move to next entry
-                cmpx prog_linetabp              ; at end of table?
-                bls prog_addline2               ; brif we're at the end of the table
-prog_addline3   ldx prog_linetabp               ; repoint to first "free" table entry
-                ldd linetabent_ptr,x            ; get pointer for the end of the program
-                std linetabent_ptr+linetabent_size,x ; move it a slot forward
-                ldd 4,s                         ; get desired line number
-                std linetabent_num,x            ; put line number in
-                bra prog_addline5               ; brif so - this is where we add it
-prog_linetab4   cmpd -linetabent_size+linetabent_num,x ; is our line number less than previous entry?
-                bhs prog_addline6               ; brif not - we're at the right place
-                leax -linetabent_size,x         ; move back an entry
-                ldu linetabent_num,x            ; move line number to next entry
-                stu linetabent_num+linetabent_size,x
-                ldu linetabent_ptr,x            ; and move the pointer
-                stu linetabent_ptr+linetabent_size,x
-prog_linetab5   cmpx prog_linetab               ; at the start of the table?
-                bhi prog_addline4               ; brif not
-prog_linetab6   ldu vartab                      ; point to end of program data
-                ldd ,s                          ; get length of line
-                leay d,u                        ; Y points to the destination of the move
-                sty vartab                      ; save new end of program text
-                bra prog_linetab8               ; jump into loop in case nothing to copy
-prog_linetab7   lda ,-u                         ; copy a byte up
-                sta ,-y
-prog_linetab8   cmpu linetabent_ptr,x           ; finished the copy?
-                bne prog_linetab7               ; brif not
-prog_linetab9   leax linetabent_size,x          ; move to next entry
-                ldd linetabent_ptr,x            ; adjust the pointer for the newly inserted line
-                addd ,s
-                std linetabent_ptr,x
-                cmpx prog_linetabp              ; run through the whole table?
-                blo prog_linetab9               ; brif not
-                puls y                          ; get copy length to counter
-                puls x                          ; get pointer to line data
-prog_linetab10  lda ,x+                         ; copy a byte into the program data
-                sta ,u+
-                leay -1,y                       ; done all of it?
-                bne prog_linetab10              ; brif not
-                leas 2,s                        ; lose line number
-                jmp cmd_newvar                  ; erase variables
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-; Parse a line number and return it in binval; raise syntax error if the line number overflows 16 bits unsigned.
-; Preserves; registers except D. This will accept the entire 16 bit unsigned number range which is why there is
-; a BCS after every shift or add. Enter with the input pointer pointing to the number to parse.
-parse_lineno    ldd zero                        ; clear out accumlator but preserve carry flag
-                std binval
-                jsr curchar                     ; set flags on current character; skip spaces
-                bcc parse_lineno1               ; brif first character wasn't a digit - default to zero
-parse_lineno0   suba #0x30                      ; adjust to binary digit
-                pshs a                          ; save digit so we can add it later
-                ldd binval                      ; get accumulated number
-                lslb                            ; multiply accumulator by 10
-                rola                            ; times 2
-                bcs SNERROR                     ; brif overflow
-                lslb
-                rola                            ; times 4
-                bcs SNERROR                     ; brif overflow
-                addd binval                     ; times 5 (add orignal value to times 4)
-                bcs SNERROR                     ; brif overflow
-                lslb
-                rola                            ; times 10
-                bcs SNERROR                     ; brif overflow
-                addb ,s+                        ; add in accumulated digit
-                adca #0
-                bcs SNERROR                     ; brif overflow
-                std binval                      ; save accumulated number
-                jsr nextcharraw                 ; get next input character; DO NOT skip spaces
-                bcs parse_lineno0               ; brif it's also a digit
-parse_lineno1   rts
+                ldx 4,s                         ; get the new line number
+prog_addline1   cmpu prog_linetab               ; are we at the start of the line table?
+                beq prog_addline2               ; brif so - we're inserting here
+                cmpx -linetabent_size+linetabent_num,u ; how does this line compare with the previous table entry?
+                bhs prog_addline2               ; brif our number is larger (or equal) to previous entry number
+                ldd -linetabent_size+linetabent_num,u ; copy line number up one slot
+                std linetabent_num,u
+                ldd -linetabent_size+linetabent_ptr,u ; get pointer of that entry
+                addd ,s                         ; add the size of the newly inserted line to adjust for after insert
+                std linetabent_ptr,u            ; save it in the new slot
+                leau -linetabent_size,u         ; move back a slot
+                bra prog_addline1               ; go check another slot
+prog_addline2   ldd linetabent_size+linetabent_ptr,u ; get pointer to the line to move out of the way
+                subd ,s                         ; unadjust for the insert size - get original location
+                std linetabent_ptr,u            ; set the data pointer for the new entry
+                stx linetabent_num,u            ; set the line number for this entry
+                tfr d,x                         ; set insertion point
+                ldu 2,s                         ; get the source data to insert
+                ldd ,s                          ; get length of source data
+                jsr mem_insert                  ; shift the block into place
+                jmp cmd_newvars                 ; erase variables and return
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Main interpretation loop
 ;
--- a/src/memory.s	Tue Jul 09 22:18:30 2024 -0600
+++ b/src/memory.s	Fri Jul 12 23:29:45 2024 -0600
@@ -52,4 +52,49 @@
                 leay -1,y                       ; done all source bytes?
                 bne mem_insert3                 ; brif not
                 puls d,x,pc                     ; clean up stack and return
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Block copy routines. There are two routines here. One for moving a block upward in memory and one for moving the block
+; downward in memory. Which one is used doesn't matter if the source and destination do not overlap. However, if the
+; source and destination do overlap, the direction that needs to be used depends on whether the source is after or
+; before the destination. There are three entry points below. One is a general block copy, one is for moving upward
+; and one is for moving downward. All entry points have the same input conditions.
+;
+; Entry:
+; X: Destination pointer
+; U: Source pointer
+; Y: Length of the block to copy
+;
+; General copy. This just dispatches either mem_copyup or mem_copydn based on whether the source is before or after
+; the destination.
+mem_copy        pshs u                          ; save source address for compare
+                cmpx ,s++                       ; is the destination below or above?
+                blo mem_copydn                  ; brif destination is below the source - we're copying downward
+                ; fall through                  ; we're copying upward here
+; Copy Y bytes from (U) to (X), working from the top down
+mem_copyup      tfr y,d                         ; need to move pointers to the end of the block
+                leax d,x
+                leau d,u
+mem_copyup0     lda ,-u                         ; copy a byte upward
+                sta ,-x
+                leay -1,y                       ; done yet?
+                bne mem_copyup0
+                rts
+; Copy Y bytes from (U) to (X), working from bottom up
+mem_copydn      lda ,u+                         ; copy a byte downward
+                sta ,x+
+                leay -1,y                       ; done yet?
+                bne mem_copydn                  ; brif not
+mem_checkptr0   rts
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Check for D bytes of free memory
+mem_checkd      addd freestart                  ; add to current start of free memory
+                ; fall through to test the resulting pointer
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Check if the address in D is within the free memory area allowing for a buffer for the system stack.
+mem_checkptr    addd #stackheadroom             ; add in the stack buffer space to the pointer
+                sts ,--s                        ; get the current stack pointer somewhere
+                cmpd ,s++                       ; did the pointer run into the stack pointer?
+                blo mem_checkptr0               ; brif not - no error
+OMERROR         ldb #err_om                     ; raise an OM error
+                jmp ERROR
                 *pragmapop list
--- a/src/progctrl.s	Tue Jul 09 22:18:30 2024 -0600
+++ b/src/progctrl.s	Fri Jul 12 23:29:45 2024 -0600
@@ -91,12 +91,12 @@
                 jsr curchar                     ; what do we have as an argument?
                 bcs cmd_goto                    ; brif a digit - it's a line number (RUN ###); do GOTO
                 lbne SNERROR                    ; brif anything else on the line - not legit command
-                ldx progtext                    ; point to start of program
+                ldx prog_text                   ; point to start of program
                 bra cmd_goto0                   ; go transfer control to the start of the program
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; GOTO command
 cmd_goto        jsr parse_lineno                ; parse the line number
-cmd_gosub0      jsr prog_findlinecl             ; go look up line number
+cmd_gosub0      jsr prog_findline               ; go look up line number
                 bcc cmd_goto0                   ; brif line found
 ULERROR         ldb #err_ul                     ; raise undefined line error
                 jmp ERROR
--- a/src/vars.s	Tue Jul 09 22:18:30 2024 -0600
+++ b/src/vars.s	Fri Jul 12 23:29:45 2024 -0600
@@ -45,6 +45,10 @@
 parse_tokenst   rmb 2                           ; pointer into input buffer of start of currently parsed token
 parse_curtok    rmb 1                           ; current token type code
 parse_stackptr  rmb 2                           ; saved stack pointer for bailing out from random parse points
+                rmb 0x71-*                      ; align RSTFLG/RSTVEC for stock ROM compatibility
+RSTFLG          rmb 1                           ; 0x55 if RSTVEC is valid
+RSTVEC          rmb 2                           ; points to warm start routine (must start with NOP)
+inputptr        rmb 2                           ; pointer to current program execution location
 ; General value accumulators used during expression evaluation. These are in the same format used for storing
 ; values in variables with the exception of having a type flag.
 val0            rmb val.size                    ; value accumulator 0 - current expression value
@@ -58,10 +62,6 @@
 fpa0            rmb fpa.size                    ; floating point accumulator 1
 fpa1            rmb fpa.size                    ; floating point accumulator 1
 fpaextra        rmb 12                          ; "extra" bytes for calculations
-                rmb 0x71-*                      ; align RSTFLG/RSTVEC for stock ROM compatibility
-RSTFLG          rmb 1                           ; 0x55 if RSTVEC is valid
-RSTVEC          rmb 2                           ; points to warm start routine (must start with NOP)
-inputptr        rmb 2                           ; pointer to current program execution location
                 rmb 0x100-*                     ; make sure the stuff that isn't direct page is outside of it
 SW3VEC          rmb 3                           ; SWI3 vector (for compatibility)
 SW2VEC          rmb 3                           ; SWI2 vector (for compatibility)