annotate src/interp.s @ 125:0607e4e20702

Correct offset error for keyword table lookup
author William Astle <lost@l-w.ca>
date Sun, 07 Jan 2024 20:35:51 -0700
parents eb2681108660
children ac183a519439
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
46 ; Set carry if upper/lower case alpha
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
47 setcifalpha cmpa #'z+1 ; is it above lower case Z?
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
48 bhs setcifalpha0 ; brif so, C clear
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
49 suba #'a ; set C if >= lower case A
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
50 suba #-'a
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
51 bcs setcifalpha0 ; brif lower case alpha
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
52 setcifualpha cmpa #'Z+1 ; is it above upper case Z?
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
53 bhs setcifalpha0 ; brif so, C clear
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
54 suba #'A ; set C if >= upper case A
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
55 suba #-'A
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
56 setcifalpha0 rts
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
58 ; Set carry if digit
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
59 setcifdigit cmpa #'9+1 ; is it above digit 9?
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
60 bhs setcifdigit0 ; brif so, C clear
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
61 suba #'0 ; set C if >= digit 0
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
62 suba #-'0
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
63 setcifdigit0 rts
eb2681108660 Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents: 75
diff changeset
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
74
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
65 ; Immediate mode handler
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
66 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
67 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
68 jsr console_outstrn
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 sta ,y+ ; stash it
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
88 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
89 blo immediate2 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 std ,x++
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
110 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
111 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
112 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
113 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
114 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
115 stx objecttab
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
116 stx freestart
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
117 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
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
119 ; 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
120 ; 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
121 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
122 ; 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
123 ; 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
124 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
125 ; 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
126 ; 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
127 prog_fixlineptrs
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
128 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
129 prog_fixlineptrsx
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
130 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
131 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
132 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
133 prog_fixlineptrs1
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
134 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
135 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
136 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
137 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
138 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
139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
140 ; 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
141 ; 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
142 ; 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
143 ; 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
144 ; 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 bls prog_findline2
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
157 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
158 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
159 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
160 prog_findline2 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
162 ; 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
163 ; 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
164 ; 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
165 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
166 std binval
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
167 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
168 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
169 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
170 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
171 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
172 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
173 rola ; times 2
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
174 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
175 lslb
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
176 rola ; times 4
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
177 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
178 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
179 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
180 lslb
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
181 rola ; times 10
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
182 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
183 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
184 adca #0
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
185 bcs SNERROR ; brif overflow
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
186 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
187 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
188 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
189 parse_lineno1 rts
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
191 ; Main interpretation loop
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
192 ;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
193 ; 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
194 ; 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
195 ; 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
196 ; 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
197 ; 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
198 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
199 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
200 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
201 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
202 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
203 beq interpret0 ; brif so
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
204 cmpa #': ; end of statement?
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
205 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
206 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
207 jmp ERROR
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
208 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
209 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
210 bne interpret1 ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
211 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
212 rts ; return to caller
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
213 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
214 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
215 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
216 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
217 interpret2 stx inputptr
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 clr curline+1
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
232 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
233 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
234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
235 ; 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
236 ; next input character.
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
237 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
238 bne SNERROR ; brif not
e74d00ac6b79 Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff changeset
239 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
240 *pragmapop list