Mercurial > hg > index.cgi
changeset 41:090db8c5d509
Add NEW command and string stack
Add the new command and the various useful bits it brings along. Also add
the string stack for later since NEW has to reset it anyway.
author | William Astle <lost@l-w.ca> |
---|---|
date | Wed, 23 Nov 2022 22:26:20 -0700 |
parents | 68253ccbb9dc |
children | 1f74c2df443f |
files | src/lwbasic.s |
diffstat | 1 files changed, 38 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lwbasic.s Wed Nov 23 21:34:21 2022 -0700 +++ b/src/lwbasic.s Wed Nov 23 22:26:20 2022 -0700 @@ -40,6 +40,7 @@ keyb_ctrl equ 0x02 ; ctrl pressed keyb_shift equ 0x01 ; shift pressed linebuffsize equ 0x100 ; the line input buffer (256 bytes) +stringstacknum equ 20 ; number of entries on the anonymous string descriptor stack ifdef COCO3 ; GIME INIT0 GIME_COCO equ 0x80 ; Set for coco2 compatible mode (video display) @@ -221,6 +222,7 @@ contstmt rmb 2 ; interpretation pointer for CONT curstmt rmb 2 ; start of statement currently being interpreted endflag rmb 1 ; 00 = END, FF = STOP +stringstackptr rmb 2 ; anonymous string descriptor stack pointer 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) @@ -236,6 +238,8 @@ keyb_buff rmb keyb_bufflen ; the keyboard ring buffer linebuff rmb linebuffsize ; the line input buffer tokebuff rmb linebuffsize+50 ; make it as long as line buffer plus a margin +stringstack rmb 5*stringstacknum ; reserve space for the anonymous string descriptor stack +stringstackend equ * ; end of string stack buffer ifne *&0x1ff rmb 0x200-(*&0x1ff) endc @@ -457,7 +461,9 @@ leax -200,x ; allocate 200 bytes of string space stx freetop ; save top of free memory leas ,x ; put the stack there + clr ,-s ; put a flag to stop NEXT/RETURN searches 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 clr ,x+ ; put a NULL pointer to mark end of program clr ,x+ @@ -1157,6 +1163,37 @@ bcs parse_lineno0 ; brif it's also a digit parse_lineno1 rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; The NEW command. +; +; This also includes several useful entry points: +; +; cmd_newraw: does the whole NEW but without any syntax checks +; cmd_newinptr: skips clearing the program text +; cmd_newvars: clears variables and resets the stack and other misc state +; cmd_newstack: just reset the stack and other misc state +cmd_new bne parse_lineno1 ; brif there was an argument - don't wipe things out on syntax error +cmd_newraw ldx progtext ; point to start of program + clr -1,x ; make sure there's a NUL before the start of the program + clr ,x+ ; put a NULL pointer at the start of the program + clr ,x+ + stx vartab ; set start of variables after that +cmd_newinptr ldx progtext ;* set input pointer to the NUL before the program; this will cause the + leax -1,x ;* the interpreter to drop to immediate mode no matter what it was + stx inputptr ;* executing before this call if called from the main loop +cmd_newvars ldx memsize ; get top of memory + stx stringtab ; clear out string space + ldx vartab ; get start of variables + stx objecttab ; set start of large objects (arrays) there too (clear vars) + stx freestart ; set start of free memory (end of large objects) (clear arrays) +cmd_newstack ldx #stringstackend ; reset string stack (string stack counts down) + stx stringstackptr + ldx ,s ; get return address + lda freetop ; reset stack to top of memory + clr ,-s ; but a flag to stop stack searches (NEXT, RETURN) + clr contstmt ; clear "CONT" destination + clr contstmt+1 + jmp ,x ; return to caller +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Main interpretation loop ; ; Enter at interpret with inputptr pointing to the code stream to interpret. @@ -1472,6 +1509,7 @@ defcmd 'END',end defcmd 'STOP',stop defcmd 'LET',let + defcmd 'NEW',new primarydict cmdtab secondarydict functab primaryjump cmdjump