annotate src/interp.s @ 75:5f8f0b0781e8

Split some code into separate files for easier management (3) 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 three of the split. Includes a file missing from part one.
author William Astle <lost@l-w.ca>
date Sun, 06 Aug 2023 00:41:26 -0600
parents e74d00ac6b79
children eb2681108660
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 ; Immediate mode handler
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
47 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
48 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
49 jsr console_outstrn
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 sta ,y+ ; stash it
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
69 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
70 blo immediate2 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 std ,x++
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
91 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
92 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
93 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
94 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
95 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
96 stx objecttab
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
97 stx freestart
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
98 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
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
100 ; 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
101 ; 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
102 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
103 ; 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
104 ; 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
105 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
106 ; 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
107 ; 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
108 prog_fixlineptrs
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
109 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
110 prog_fixlineptrsx
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
111 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
112 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
113 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
114 prog_fixlineptrs1
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
115 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
116 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
117 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
118 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
119 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
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
121 ; 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
122 ; 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
123 ; 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
124 ; 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
125 ; 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 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
135 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
136 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
137 bls prog_findline2
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
138 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
139 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
140 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
141 prog_findline2 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
143 ; 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
144 ; 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
145 ; 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
146 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
147 std binval
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
148 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
149 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
150 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
151 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
152 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
153 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
154 rola ; times 2
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
155 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
156 lslb
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
157 rola ; times 4
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
158 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
159 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
160 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
161 lslb
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
162 rola ; times 10
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
163 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
164 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
165 adca #0
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
166 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
167 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
168 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
169 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
170 parse_lineno1 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 ; Main interpretation loop
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
173 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
174 ; 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
175 ; 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
176 ; 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
177 ; 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
178 ; 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
179 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
180 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
181 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
182 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
183 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
184 beq interpret0 ; brif so
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
185 cmpa #': ; end of statement?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
186 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
187 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
188 jmp ERROR
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
189 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
190 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
191 bne interpret1 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
192 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
193 rts ; return to caller
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
194 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
195 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
196 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
197 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
198 interpret2 stx inputptr
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 clr curline+1
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
213 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
214 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
215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
216 ; 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
217 ; next input character.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
218 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
219 bne SNERROR ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
220 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
221 *pragmapop list