Mercurial > hg > index.cgi
annotate src/interp.s @ 126:ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
Add ability to turn a token code into a keyword string. Also correct some
details related to token table generation with some additiona adjustments
for token symbols.
Also rework token symbol definitions and creation of some parsing tables as
well as the main statement parsing loop.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 08 Jan 2024 22:58:08 -0700 |
parents | eb2681108660 |
children | 9d57279c900e |
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 |
126
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
72 immediate0a lda ,x ; do we have anything at all? |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
73 beq immediate0 ; brif not - just read another line |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
74 cmpa #0x20 ; space? |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
75 bne immediate0c ; brif not |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
76 immediate0b leax 1,x ; move past the |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
77 bra immediate0a ; keep looking for the start of input |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
78 immediate0c bsr setcifdigit ; do we have a line number? |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
79 bcs immediate1 ; brif so - go handle program editing |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
80 clrb ; flag to do actual parsing |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
81 jsr parse ; go parse the line |
ac183a519439
Update parsing scheme with a keyword lookup by token value and other framework
William Astle <lost@l-w.ca>
parents:
76
diff
changeset
|
82 bra * |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 sta ,y+ ; stash it |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
92 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
|
93 blo immediate2 ; brif not |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 std ,x++ |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 stx objecttab |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
120 stx freestart |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
121 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
|
122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
123 ; 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
|
124 ; 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
|
125 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
126 ; 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
|
127 ; 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
|
128 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
129 ; 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
|
130 ; 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
|
131 prog_fixlineptrs |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
132 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_fixlineptrsx |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 prog_fixlineptrs1 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
144 ; 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
|
145 ; 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
|
146 ; 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
|
147 ; 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
|
148 ; 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 bls prog_findline2 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 prog_findline2 rts |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
166 ; 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
|
167 ; 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
|
168 ; 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
|
169 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
|
170 std binval |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 rola ; times 2 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
178 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
179 lslb |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
180 rola ; times 4 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
181 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
182 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
|
183 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
184 lslb |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
185 rola ; times 10 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
186 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
187 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
|
188 adca #0 |
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 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
|
191 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
|
192 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
|
193 parse_lineno1 rts |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
195 ; Main interpretation loop |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
196 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
197 ; 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
|
198 ; 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
|
199 ; 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
|
200 ; 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
|
201 ; 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 beq interpret0 ; brif so |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
208 cmpa #': ; end of statement? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
209 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
|
210 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
|
211 jmp ERROR |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
212 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
|
213 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
|
214 bne interpret1 ; brif not |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
215 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
|
216 rts ; return to caller |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 interpret2 stx inputptr |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 clr curline+1 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
236 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
|
237 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
|
238 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
239 ; 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
|
240 ; next input character. |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
241 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
|
242 bne SNERROR ; brif not |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
243 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
|
244 *pragmapop list |