annotate src/interp.s @ 74:e74d00ac6b79

Split some code into separate files for easier management (2) Because the source for lwbasic is so large, split it into several different files to make it easier to navigate and modify. This is part two of the split. Also includes fix for dependency tracking related to the split in the make file.
author William Astle <lost@l-w.ca>
date Sun, 06 Aug 2023 00:36:48 -0600
parents
children 5f8f0b0781e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
1 *pragmapush list
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
2 *pragma list
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
4 ; Fetch next input character, skip spaces. This is structured the way it is to avoid burning any register except A
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
5 ; which is used for the returned value. Z will be set if the input character is NUL or a colon. C will be set if the
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
6 ; input character is an ASCII digit. This allows testing Z to identify the end of a command due to either a colon or
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
7 ; the end of a line.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
8 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
9 ; Compared to Color Basic, the instruction sequence only varies in the handling of the LDA. In Color Basic, the sequence
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
10 ; is an LDA extended followed by a JMP extended. This totals to 9 cycles (5 for LDA, 4 for JMP). In LWBasic, an LDA
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
11 ; with extended indirect addressing is used. This also totals 9 cycles. The only other difference is when a space is
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
12 ; detected where the branch can be direct to the nextchar code instead of having to branch around a direct page JUMP
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
13 ; which saves 3 cycles for the case where a space is detected. In other words, this is only slower by virtue of the
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ; fact that it is called with an extended JSR instead of a direct JSR which causes one extra cycle to be used there
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
15 ; and one extra byte for each call to nextchar or curchar.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
16 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
17 ; On 6309, native move saves an extra cycle in the LDA sequence using the LDA extended followed by JMP extended
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
18 ; sequence.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
19 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
20 ; This whole thing could be sped up by keeping the input pointer in a register. However, retaining the ability to
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
21 ; use Y without having to save it first is likely more beneficial.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
22 nextchar inc inputptr+1 ; bump LSB of input pointer
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
23 bne curchar ; brif no carry
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
24 inc inputptr ; bump MSB
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
25 curchar lda [inputptr] ; read the byte
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
26 cmpa #'9+1 ; clear C if above ASCII digits, Z if colon
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
27 bhs curchar0 ; brif above the ASCII digits
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
28 cmpa #0x20 ; is it a space?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
29 beq nextchar ; brif so - skip over it
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
30 suba #'0 ; clever way to set C if >= ASCII 0, Z if zero
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
31 suba #-'0
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
32 curchar0 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
33 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
34 ; This is exactly the same as nextchar except it doesn't skip spaces. Unfortunately, for efficiency purposes, we need
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
35 ; to actually duplicate code here.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
36 nextcharraw inc inputptr+1 ; bump LSB of input pointer
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
37 bne curchar ; brif no carry
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
38 inc inputptr ; bump MSB
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
39 curcharraw lda [inputptr] ; fetch the byte
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
40 cmpa #'9+1 ; clear C if above digits, set Z if colon
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
41 bhs curcharraw0 ; brif above digits
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
42 suba #'0 ; clever way to set C if >= ASCII 0, Z if zero
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
43 suba #-'0
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
44 curcharraw0 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
46 ; The error handler
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
47 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
48 ; Enter with the error number in B. This routine will do some cleanup and handle any ON ERROR GOTO handler that
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
49 ; may be active.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
50 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
51 ; Note the error message lookup does not need to be efficient which is why the lookup just runs through the list
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
52 ; of error messages in sequence looking for NUL terminators. The specific handling of B (error number) below avoids
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
53 ; issues if there happen to be error codes above 128.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
54 ERROR clr filenum ; reset display device to console
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
55 jsr writecondnl ; do a newline if needed (will preserve B)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
56 ldx #errormsg ; point to error message list
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
57 incb ; account for decb below
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
58 bra ERROR1 ; go search for correct message
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
59 ERROR0 lda ,x+ ; end of message?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
60 bne ERROR0 ; brif not end of message
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
61 ERROR1 decb ; at the correct one?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
62 bne ERROR0 ; brif not - skip to next one
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
63 ERROR2 jsr writestrconduc ; output error message
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
64 ldu curline ; are we in immediate mode?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
65 beq ERROR3 ; brif so
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
66 ldx #inmsg ; point to " in "
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
67 jsr writestrconduc ; output " in "
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
68 ldd 2,u ; get line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
69 jsr print_uint16d ; display the line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
70 ERROR3 lds freetop ; reset the stack pointer (error routine could be called anywhere)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
71 clr ,-s ; reset the call stack
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
72 sts stackptr
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
73 ; fall through to immediate mode intentional
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
75 ; Immediate mode handler
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
76 immediate jsr writecondnl ; do newline if required
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
77 ldx #prompt ; point to prompt string
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
78 jsr console_outstrn
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
79 immediate0 jsr readline ; read input line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
80 bcs immediate0 ; brif ended with BREAK
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
81 ldx #linebuff ; point to start of line input buffer
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
82 stx inputptr ; set input pointer
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
83 jsr curchar ; skip spaces and set flags
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
84 bcs immediate1 ; brif there's a line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
85 tsta ; is there anything there at all (end of line)?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
86 beq immediate0 ; brif not - read another line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
87 ldx inputptr ; get the modified input pointer processing above
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
88 jsr tokenize ; tokenize the line at inputptr, return with result at tokebuff and X
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
89 jsr interpretline ; go interpret the tokenized line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
90 bra immediate ; go handle another line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
91 immediate1 bsr parse_lineno ; parse the line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
92 bsr prog_findline ; go see if the line is in the program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
93 bne immediate3 ; brif not - no need to delete it
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
94 ldu ,x ; get next line pointer which is where we start the copy from
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
95 leay ,x ; use temp pointer for copying
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
96 immediate2 lda ,u+ ; get source byte
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
97 sta ,y+ ; stash it
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
98 cmpu vartab ; did we reach the end of the program text?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
99 blo immediate2 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
100 sty vartab ; save new end of program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
101 immediate3 jsr curchar ; skip any spaces after line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
102 tsta ; is it the end of input (don't test for colon)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
103 beq immediate6 ; brif so - we don't need to insert a line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
104 pshs x ; save program insert location and line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
105 ldx inputptr ; point to line text
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
106 jsr tokenize ; tokenize line, get length to D
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
107 leay ,x ; save tokenized line pointer
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
108 addd #4 ; account for next line pointer and line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
109 ldx vartab ; get start of copy location
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
110 leau d,x ; set destination copy location D bytes further up
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
111 stu vartab ; save new end of program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
112 immediate4 lda ,-x ; get byte from program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
113 sta ,-u ; stash it above the empty space
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
114 cmpx ,s ; did we reach the insertion point?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
115 bne immediate4 ; brif not - keep going
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
116 leas 2,s ; clear insertion location
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
117 stu ,x++ ; set next line pointer to not null
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
118 ldd binval ; set the line number for the program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
119 std ,x++
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
120 immediate5 lda ,y+ ; get byte from tokenized line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
121 sta ,x+ ; stash it in the program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
122 bne immediate5 ; brif not at end of tokenized line (see note for fixlineptrs)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
123 immediate6 bsr prog_fixlineptrs ; fix up line pointers (all of them)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
124 ldx vartab ; clear out variables
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
125 stx objecttab
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
126 stx freestart
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
127 bra immediate0 ; go handle more input
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
129 ; Fix up next line pointers. Enter at prog_fixlineptrs to do the entire program. Enter at prog_fixlineptrsx to start
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
130 ; at the line pointered to by X, which MUST NOT point to the end of the program.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
131 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
132 ; Works by simply scanning for a NUL in the program text after a line header (pointer to next line and line number)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
133 ; and uses that as the new next line pointer. A NULL next line pointer flags the end of the program.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
134 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
135 ; Observation: if the program text format is changed such that it can include NULs embedded within a line, this routine
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
136 ; will need to be updated to grok that.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
137 prog_fixlineptrs
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
138 ldx progtext ; point to start of program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
139 prog_fixlineptrsx
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
140 ldu ,x ; are we at the end of the program?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
141 beq prog_findline2 ; brif not (borrow RTS from findline)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
142 leau 4,x ; point to line text (past pointer and line number)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
143 prog_fixlineptrs1
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
144 lda ,u+ ; are we at the end of this line?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
145 bne prog_fixlineptrs1 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
146 stu ,x ; set the next pointer for the previous line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
147 leax ,u ; move to the next line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
148 bra prog_fixlineptrsx ; go handle the next line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
150 ; Find a line in the program. Returns with C set and Z clear if no match and C clear and Z set if a match is found. X
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
151 ; will point to either the exact matched line *or* the line that would be immediately after the desired line number if
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
152 ; the line had been present, which could be the end of the program. D and U are clobbered. Enter at prog_findlinex to
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
153 ; start searching at the line pointed to by X. Enter at prog_findline to start at the beginning of the program. Enter
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
154 ; with the desired line number in binval.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
155 prog_findlinecl ldx curline ; get current line pointer
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
156 beq prog_findline ; brif immediate mode
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
157 ldd binval ; get desired line number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
158 cmpd 2,x ; is the desired line number >= current line?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
159 beq prog_findline2 ; brif this is the right line (optimizes goto self)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
160 bhi prog_findlinex ; brif desired line higher: start here instead of program start
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
161 prog_findline ldx progtext ; point to start of program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
162 prog_findlinex ldu binval ; get line number to search for
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
163 prog_findline0 ldd ,x ; end of program?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
164 beq prog_findline1 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
165 cmpu 2,x ; does line number match? Z set if so, clear if not; C set not found
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
166 bls prog_findline2
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
167 ldx ,x ; move to next line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
168 bra prog_findline0 ; see if we found the line yet
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
169 prog_findline1 coma ; set carry for not found; also clears Z because D is zero from above
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
170 prog_findline2 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
172 ; Parse a line number and return it in binval; raise syntax error if the line number overflows 16 bits unsigned.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
173 ; Preserves; registers except D. This will accept the entire 16 bit unsigned number range which is why there is
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
174 ; a BCS after every shift or add. Enter with the input pointer pointing to the number to parse.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
175 parse_lineno ldd zero ; clear out accumlator but preserve carry flag
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
176 std binval
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
177 jsr curchar ; set flags on current character; skip spaces
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
178 bcc parse_lineno1 ; brif first character wasn't a digit - default to zero
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
179 parse_lineno0 suba #0x30 ; adjust to binary digit
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
180 pshs a ; save digit so we can add it later
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
181 ldd binval ; get accumulated number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
182 lslb ; multiply accumulator by 10
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
183 rola ; times 2
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
184 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
185 lslb
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
186 rola ; times 4
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
187 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
188 addd binval ; times 5 (add orignal value to times 4)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
189 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
190 lslb
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
191 rola ; times 10
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
192 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
193 addb ,s+ ; add in accumulated digit
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
194 adca #0
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
195 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
196 std binval ; save accumulated number
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
197 jsr nextcharraw ; get next input character; DO NOT skip spaces
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
198 bcs parse_lineno0 ; brif it's also a digit
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
199 parse_lineno1 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
201 ; Main interpretation loop
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
202 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
203 ; Enter at interpret with inputptr pointing to the code stream to interpret.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
204 ; Enter at interpretline with X pointing to the command stream to interpret which will return to the caller one the
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
205 ; command stream has completed. STOP or BREAK will return with carry set while END or falling off the end of the
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
206 ; code will return with carry clear. In the event of an error, the usual error processing will be done and control
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
207 ; will return to immediate mode with the stack reset.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
208 interpret jsr breakcheck ; check for BREAK
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
209 bcs cmd_stop0 ; brif BREAK detected - go stop the program
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
210 ldx inputptr ; get interpration address
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
211 stx curstmt ; save address of the current statement (needed for some stuff)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
212 lda ,x+ ; are we at the end of the line?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
213 beq interpret0 ; brif so
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
214 cmpa #': ; end of statement?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
215 beq interpret3 ; brif so - do a statement
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
216 SNERROR ldb #err_sn ; raise a syntax error
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
217 jmp ERROR
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
218 interpret0 sta endflag ; flag the program exit state as "END" (will be zero)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
219 ldd curline ; were we in immediate mode?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
220 bne interpret1 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
221 clra ; clear carry to indicate normal exit
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
222 rts ; return to caller
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
223 interpret1 ldd ,x ; are we at the end of the program?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
224 beq interpret4 ; brif so - bail out
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
225 stx curline ; save pointer to current line
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
226 leax 3,x ; set input pointer one before the start of the line text
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
227 interpret2 stx inputptr
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
228 interpret3 jsr nextchar ; fetch first character of next statement
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
229 beq interpret ; brif end of statement - do the next statement dance
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
230 tsta ; set flags properly for token
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
231 lbpl cmd_let ; brif no command - do assignment (LET command is optional)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
232 ldx #primaryjump ; point to jump table
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
233 anda #0x7f ; lose bit 7
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
234 leax a,x ; get half way to the correct offset
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
235 ldx a,x ; get the address the other half of the way from here
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
236 jsr nextchar ; skip past token and set flags
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
237 jsr ,x ; call the routine
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
238 bra interpret ; go handle the next statement dance
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
239 interpret4 bsr cmd_stop1 ; make sure stack is aligned correctly (will not return)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
240 interpretline clr curline ; blank out current line pointer (for immediate mode)
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
241 clr curline+1
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
242 leax -1,x ; move back before start of code stream
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
243 bra interpret2 ; go interpret this statement and then continue with stuff
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
245 ; Check for character in B and raise a syntax error if not found at current input pointer. If it is found, fetch the
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
246 ; next input character.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
247 syncheckb cmpb [inputptr] ; do we have a syntax match?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
248 bne SNERROR ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
249 jmp nextchar ; return next input character
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
250 *pragmapop list