changeset 50:aecea4c62324

Add LIST command Add the LIST command along with a placeholder - token and some adjustments to maintain buildability.
author William Astle <lost@l-w.ca>
date Sat, 10 Dec 2022 00:22:52 -0700
parents f5966048a796
children e0c0ed649269
files src/lwbasic.s
diffstat 1 files changed, 79 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwbasic.s	Sat Dec 10 00:22:05 2022 -0700
+++ b/src/lwbasic.s	Sat Dec 10 00:22:52 2022 -0700
@@ -1390,6 +1390,80 @@
                 suba #-'0
 setcifdigit0    rts
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; The LIST command.
+;
+; Syntax:
+; LIST
+; LIST <line>
+; LIST <line>-
+; LIST -<line>
+; LIST <start>-<end>
+cmd_list        bne cmd_list1                   ; brif we have arguments
+                ldx progtext                    ; point to start of program
+cmd_list0       ldd #65535                      ; set last line to list to max line number
+                std binval
+                bra cmd_list2                   ; go do the listing
+cmd_list1       jsr parse_lineno                ; parse starting line number (will default to 0)
+                jsr prog_findline               ; find the line or the one after where it would be
+                jsr curchar                     ; are we at the end of the command?
+                beq cmd_list2                   ; brif so - we have a single line (binval will have the start line #)
+                ldb #tok_minus                  ; insist on a - for a range if more than one line number
+                jsr syncheckb
+                beq cmd_list0                   ; brif open ended ending - set to max line number
+                jsr parse_lineno                ; parse ending of range
+cmd_list2       ldd ,x                          ; are we at the end of the program?
+                bne cmd_list4                   ; brif not
+cmd_list3       rts
+cmd_list4       ldd 2,x                         ; get line number
+                cmpd binval                     ; have we reached the end of the range?
+                bhi cmd_list3                   ; brif so - we're done
+                jsr print_uint16d               ; print out line number
+                lda #0x20                       ; and a space
+                jsr writechr
+                pshs x                          ; save start of this line (in case detokenizing exits early)
+                leax 4,x                        ; move past line header
+                bsr detokenize                  ; detokenize line to current output stream
+                ldx [,s++]                      ; point to next line using saved pointer and clear it from the stack
+                ; need to add a break check here
+                bra cmd_list2                   ; go handle another line
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Detokenize a line to the current output stream
+detokenize      lda ,x+                         ; get character from tokenized line
+                bmi detokenize1                 ; brif it's a keyword token
+                lbeq writecondnl                ; do a newline if needed and return
+                cmpa #':                        ; is it a colon?
+                bne detokenize0                 ; brif not
+                ldb ,x                          ; fetch subsequent character
+                cmpb #tok_apos                  ; apostrophe version of REM?
+                beq detokenize                  ; brif so - skip the colon
+                cmpb #tok_else                  ; ELSE?
+                beq detokenize                  ; brif so - skip the colon
+detokenize0     jsr writechr                    ; output it unmolested
+                bra detokenize                  ; go handle another character
+detokenize1     ldu #primarydict                ; point to primary dictionary table
+                cmpa #0xff                      ; is it a secondary token?
+                bne detokenize3                 ; brif not
+                ldu #secondarydict              ; point to secondary dictionary table
+                lda ,x+                         ; get secondary token value
+                bne detokenize3                 ; brif not end of line
+                leax -1,x                       ; don't consume the NUL
+detokenize2     lda #'!                         ; invalid token flag
+                bra detokenize0                 ; output it and continue
+detokenize3     anda #0x7f                      ; lose the high bit
+                beq detokenize6                 ; brif already at the right place
+detokenize4     ldb ,u                          ; end of dictionary table?
+                beq detokenize2                 ; brif so - show invalid tokenf lag
+detokenize5     ldb ,u+                         ; fetch character in this keyboard
+                bpl detokenize5                 ; brif not end of keyword (high bit set)
+                deca                            ; at the right token?
+                bne detokenize4                 ; brif not - skip another
+detokenize6     lda ,u+                         ; get keyword character
+                bmi detokenize7                 ; brif end of keyword
+                jsr writechr                    ; output it
+                bra detokenize6                 ; go fetch another
+detokenize7     anda #0x7f                      ; lose the high bit
+                bra detokenize0                 ; write it and move on with the input
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Tokenize line to tokebuff
 ;
 ; Enter with X pointing to the text to tokenize.
@@ -1407,9 +1481,9 @@
                 puls x,pc                       ; set return pointer and return
 tokenize1       tst ,s                          ; are we in the middle of a "not token"?
                 beq tokenize3a                  ; brif not
-                bsr setcifalpha                 ; is it alpha
+                jsr setcifalpha                 ; is it alpha
                 bcs tokenize2                   ; brif so - store it and continue
-                bsr setcifdigit                 ; is it numeric?
+                jsr setcifdigit                 ; is it numeric?
                 bcc tokenize3                   ; brif not
 tokenize2       sta ,y+                         ; save output character
                 bra tokenize0                   ; check for another
@@ -1443,7 +1517,7 @@
                 sta ,y+                         ; stash in output
                 bne tokenize8                   ; brif not end of input
                 bra tokenize0b                  ; go finish up
-tokenize9       bsr setcifdigit                 ; is it a digit?
+tokenize9       jsr setcifdigit                 ; is it a digit?
                 bcs tokenize2                   ; brif so - pass it through
                 tsta                            ; is the high bit set?
                 bmi tokenize0                   ; ignore it if so
@@ -1576,6 +1650,8 @@
                 defcmd 'LET',let
                 defcmd 'NEW',new
                 defcmd 'PRINT',print
+                defcmd 'LIST',list
+                defcmd '-',minus,SNERROR
 primarydict     cmdtab
 secondarydict   functab
 primaryjump     cmdjump