Mercurial > hg > index.cgi
annotate src/interp.s @ 132:917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 24 Jun 2024 23:44:39 -0600 |
parents | 95f174bf459b |
children | e49bd0493baf |
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 |
131
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
66 immediatee jsr ERRORstr ; get error string |
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
67 jsr writestrconduc ; display it |
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
68 ldx #atmsg ; output " at " |
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
69 jsr writestrconduc |
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
70 leax ,u ; point to error location |
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
71 jsr console_outstr ; display remaining line part (but preserve case this time) |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
72 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
|
73 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
|
74 jsr console_outstrn |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 bne immediate0c ; brif not |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
82 immediate0b leax 1,x ; move past the space |
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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 jsr parse ; go parse the line |
131
95f174bf459b
Add error handling for immediate mode loop
William Astle <lost@l-w.ca>
parents:
128
diff
changeset
|
88 bcs immediatee ; brif there was a parse error |
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
|
89 bra * |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
90 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
|
91 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
|
92 immediate1 bsr parse_lineno ; parse the line number |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
93 jsr prog_remove ; remove the line from the program if it exists |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 ldx inputptr ; point to line text |
128
9d57279c900e
Remove old style keyword lists and jump tables
William Astle <lost@l-w.ca>
parents:
126
diff
changeset
|
98 jsr parse ; tokenize line, get length to D |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
99 ldy binval ; get the line number |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
100 jsr prog_insert ; insert the encoded line at X into program as line Y |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
101 immediate6 ldx vartab ; clear out variables |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
102 stx objecttab |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
103 stx freestart |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
104 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
|
105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
106 ; Find line number table entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
107 ; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
108 ; Entry: |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
109 ; D: the desired line number |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
110 ; |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
111 ; Exit: |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
112 ; U: pointer to line number table entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
113 ; CC.C: clear |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
114 ; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
115 ; Error: |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
116 ; CC.C: set |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
117 ; |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
118 ; This works by doing a binary search through the line number table. |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
119 prog_findline ldu prog_linetab ; point to program line table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
120 ldx prog_linetabp ; get end of table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
121 leax -prog_lineentl,u ; move back to the start of the last entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
122 pshs x,u ; save "high" at 0,s and "low" at 2,s |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
123 tfr d,x ; save line number for later comparisons |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
124 prog_findline1 ldd ,s ; get high pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
125 subd 2,s ; get different with low pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
126 bcs prog_findline2 ; brif high is below low - we didn't find it |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
127 lsra ; find half way |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
128 rorb |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
129 andb #0b11111100 ; round down for 4 bytes per entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
130 addd prog_linetab ; offset into line table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
131 tfr d,u ; move to a pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
132 cmpx linetabent_num,u ; is the desired number less, equal, or greater? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
133 beq prog_findline2 ; brif match |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
134 blo prog_findline3 ; brif desired line is lower |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
135 leau prog_lineentl,u ; skip past this non-matching item |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
136 stu 2,s ; save new low pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
137 bra prog_findline1 ; go do another iteration |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
138 prog_findline2 leas 4,s ; clean up the temporaries (C clear from compare above) |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
139 rts |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
140 prog_findline3 leau -prog_lineentl,u ; move before this non-matching entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
141 stu ,s ; save new top entry pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
142 bra prog_findline1 ; go do another iteration |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
144 ; Delete a line from the program: |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
145 ; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
146 ; Entry: |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
147 ; D: the line number to delete |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
148 ; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
149 ; This routine removes a line from the program. This works by deallocating the line data and moving all subsequent |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
150 ; line data forward to close the gap. The line table pointer will also be removed and the subsequent line table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
151 ; entries will also be brought forward to fill the gap. While closing the gap in the line table, the line data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
152 ; pointers will be adjusted to account for the relocation of the line data following the deleted line. The line number |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
153 ; table size allocation will not be adjusted. |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
154 prog_delline bsr prog_findline ; get a pointer to the desired line table entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
155 bcs prog_delline3 ; brif the line wasn't in the program - we have nothing to do |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
156 ldd linetabent_size+linetabent_ptr,u ; get pointer to next line data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
157 subd linetabent_ptr,u ; now D is the length of the line data to collapse out |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
158 pshs d ; save the calculated length - we need it for later |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
159 ldy linetabent_ptr,u ; get pointer to the line data to delete |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
160 leax d,y ; point to data to move |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
161 bra prog_delline1 ; go handle the loop, including the case where we copy nothing |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
162 prog_delline0 lda ,x+ ; copy a byte down |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
163 sta ,y+ |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
164 prog_delline1 cmpx vartab ; at the end of the program? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
165 blo prog_delline0 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
166 sty vartab ; save new variable table location |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
167 prog_delline2 ldx linetabent_size+linetabent_num,u ; get number of next line |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
168 ldd linetabent_size+linetabent_ptr,u ; get pointer for next line |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
169 subd ,s ; adjust for length removed in the line data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
170 std ,u++ ; save in the vacated entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
171 stx ,u++ |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
172 cmpu prog_linetabp ; at the end of allocated table entries? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
173 blo prog_delline2 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
174 leau -linetabent_size,u ; move back to the last actual entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
175 stu prog_linetabp ; update the line table pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
176 leas 2,s ; clear out the temp we no longer need |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
177 jsr cmd_newvars ; clear the variables out |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
178 prog_delline3 rts |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
132
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
180 ; prog_shrinklt: shrink the line table to its minimum possible size, but keep it a multiple of linetab_stride entries |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
181 prog_shrinklt ldd prog_linetabp ; get the end of the table entries |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
182 subd prog_linetab ; now we have the length of the table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
183 andb #(linetabent_size*linetab_stride)-1 ; is there a remainder? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
184 beq prog_shrinklt0 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
185 addd #linetabent_size*linetab_strider |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
186 prog_shrinklt0 tfr d,u ; put in a pointer register |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
187 leau linetabent_size,x ; move to the end of the phantom entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
188 cmpu prog_text ; anything to do? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
189 beq prog_shrinklt2 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
190 ldx prog_text ; point to source copy point |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
191 prog_shrinklt1 lda ,x+ ; copy a byte down |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
192 sta ,u+ |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
193 cmpx vartab ; end of program? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
194 blo prog_shrinklt1 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
195 stu vartab ; save new end of program |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
196 jmp cmd_newvars ; clear variables |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
197 prog_shrinklt2 rts |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
198 |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
199 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
200 ; Insert a line into the program |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
201 ; |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
202 ; Entry: |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
203 ; D: length of line to insert |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
204 ; X: pointer to line data to insert |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
205 ; U: the line number we're adding |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
206 prog_addline pshs d,x,u ; save length and pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
207 ldx prog_linetabp ; get line table pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
208 leax linetabent_size,x ; add in space for new entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
209 cmpx prog_text ; did we run into the program? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
210 blo prog_addline0 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
211 addd #linetabent_size*linetab_stride ; add in space for expanded line table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
212 prog_addline0 addd vartab ; calculate the new end of program data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
213 jsr checkmem_addr ; verify there is enough memory |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
214 cmpx prog_text ; do we need to expand the line number table? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
215 blo prog_addline3 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
216 ldx vartab ; point to byte past end of program |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
217 leau linetab_stride*linetabent_size,x ; set up destination pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
218 stu vartab ; set up new end of program text |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
219 prog_addline1 lda ,-x ; copy a byte up |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
220 sta ,-u |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
221 cmpx prog_text ; did we hit the start of the program? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
222 bne prog_addline1 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
223 ldx prog_linetab ; point to start of line table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
224 prog_addline2 ldd linetabent_ptr,x ; get pointer to this line |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
225 addd #linetab_stride*linetabent_size ; adjust offset for the expanded table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
226 std linetabent_ptr,x |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
227 leax linetabent_size,x ; move to next entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
228 cmpx prog_linetabp ; at end of table? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
229 bls prog_addline2 ; brif we're at the end of the table |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
230 prog_addline3 ldx prog_linetabp ; repoint to first "free" table entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
231 ldd linetabent_ptr,x ; get pointer for the end of the program |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
232 std linetabent_ptr+linetabent_size,x ; move it a slot forward |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
233 ldd 4,s ; get desired line number |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
234 std linetabent_num,x ; put line number in |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
235 bra prog_addline5 ; brif so - this is where we add it |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
236 prog_linetab4 cmpd -linetabent_size+linetabent_num,x ; is our line number less than previous entry? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
237 bhs prog_addline6 ; brif not - we're at the right place |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
238 leax -linetabent_size,x ; move back an entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
239 ldu linetabent_num,x ; move line number to next entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
240 stu linetabent_num+linetabent_size,x |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
241 ldu linetabent_ptr,x ; and move the pointer |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
242 stu linetabent_ptr+linetabent_size,x |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
243 prog_linetab5 cmpx prog_linetab ; at the start of the table? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
244 bhi prog_addline4 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
245 prog_linetab6 ldu vartab ; point to end of program data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
246 ldd ,s ; get length of line |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
247 leay d,u ; Y points to the destination of the move |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
248 sty vartab ; save new end of program text |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
249 bra prog_linetab8 ; jump into loop in case nothing to copy |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
250 prog_linetab7 lda ,-u ; copy a byte up |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
251 sta ,-y |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
252 prog_linetab8 cmpu linetabent_ptr,x ; finished the copy? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
253 bne prog_linetab7 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
254 prog_linetab9 leax linetabent_size,x ; move to next entry |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
255 ldd linetabent_ptr,x ; adjust the pointer for the newly inserted line |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
256 addd ,s |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
257 std linetabent_ptr,x |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
258 cmpx prog_linetabp ; run through the whole table? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
259 blo prog_linetab9 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
260 puls y ; get copy length to counter |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
261 puls x ; get pointer to line data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
262 prog_linetab10 lda ,x+ ; copy a byte into the program data |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
263 sta ,u+ |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
264 leay -1,y ; done all of it? |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
265 bne prog_linetab10 ; brif not |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
266 leas 2,s ; lose line number |
917b4893bb3d
Checkpoint before redoing a bunch of code for clarity
William Astle <lost@l-w.ca>
parents:
131
diff
changeset
|
267 jmp cmd_newvar ; erase variables |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
269 ; 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
|
270 ; 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
|
271 ; 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
|
272 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
|
273 std binval |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 rola ; times 2 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
281 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
282 lslb |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
283 rola ; times 4 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
284 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
285 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
|
286 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
287 lslb |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
288 rola ; times 10 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
289 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
290 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
|
291 adca #0 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
292 bcs SNERROR ; brif overflow |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 parse_lineno1 rts |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
298 ; Main interpretation loop |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
299 ; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
300 ; 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
|
301 ; 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
|
302 ; 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
|
303 ; 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
|
304 ; 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 beq interpret0 ; brif so |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
311 cmpa #': ; end of statement? |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
312 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
|
313 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
|
314 jmp ERROR |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
315 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
|
316 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
|
317 bne interpret1 ; brif not |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
318 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
|
319 rts ; return to caller |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 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
|
324 interpret2 stx inputptr |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 lbpl cmd_let ; brif no command - do assignment (LET command is optional) |
128
9d57279c900e
Remove old style keyword lists and jump tables
William Astle <lost@l-w.ca>
parents:
126
diff
changeset
|
329 ldx #exectab_cmd ; point to jump table |
74
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 clr curline+1 |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
338 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
|
339 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
|
340 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
341 ; 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
|
342 ; next input character. |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
343 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
|
344 bne SNERROR ; brif not |
e74d00ac6b79
Split some code into separate files for easier management (2)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
345 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
|
346 *pragmapop list |