Mercurial > hg > index.cgi
annotate src/token.s @ 125:0607e4e20702
Correct offset error for keyword table lookup
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 07 Jan 2024 20:35:51 -0700 |
parents | eb2681108660 |
children |
rev | line source |
---|---|
76
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
1 *pragmapush list |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
2 *pragma list |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
4 ; The LIST command. |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
5 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
6 ; Syntax: |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
7 ; LIST |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
8 ; LIST <line> |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
9 ; LIST <line>- |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
10 ; LIST -<line> |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
11 ; LIST <start>-<end> |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
12 cmd_list bne cmd_list1 ; brif we have arguments |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ldx progtext ; point to start of program |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
14 cmd_list0 ldd #65535 ; set last line to list to max line number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
15 std binval |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 bra cmd_list2 ; go do the listing |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 cmd_list1 jsr parse_lineno ; parse starting line number (will default to 0) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
18 jsr prog_findline ; find the line or the one after where it would be |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
19 jsr curchar ; are we at the end of the command? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
20 beq cmd_list2 ; brif so - we have a single line (binval will have the start line #) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
21 ldb #tok_minus ; insist on a - for a range if more than one line number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
22 jsr syncheckb |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
23 beq cmd_list0 ; brif open ended ending - set to max line number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
24 jsr parse_lineno ; parse ending of range |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
25 cmd_list2 ldd ,x ; are we at the end of the program? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
26 bne cmd_list4 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
27 cmd_list3 rts |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 cmd_list4 ldd 2,x ; get line number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 cmpd binval ; have we reached the end of the range? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
30 bhi cmd_list3 ; brif so - we're done |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
31 jsr print_uint16d ; print out line number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
32 lda #0x20 ; and a space |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
33 jsr writechr |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
34 pshs x ; save start of this line (in case detokenizing exits early) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
35 leax 4,x ; move past line header |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
36 bsr detokenize ; detokenize line to current output stream |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
37 ldx [,s++] ; point to next line using saved pointer and clear it from the stack |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
38 ; need to add a break check here |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
39 bra cmd_list2 ; go handle another line |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
41 ; Detokenize a line to the current output stream |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
42 detokenize lda ,x+ ; get character from tokenized line |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
43 bmi detokenize1 ; brif it's a keyword token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
44 lbeq writecondnl ; do a newline if needed and return |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
45 cmpa #': ; is it a colon? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
46 bne detokenize0 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
47 ldb ,x ; fetch subsequent character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
48 cmpb #tok_apos ; apostrophe version of REM? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 beq detokenize ; brif so - skip the colon |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 cmpb #tok_else ; ELSE? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
51 beq detokenize ; brif so - skip the colon |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
52 detokenize0 jsr writechr ; output it unmolested |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
53 bra detokenize ; go handle another character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
54 detokenize1 ldu #primarydict ; point to primary dictionary table |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
55 cmpa #0xff ; is it a secondary token? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 bne detokenize3 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
57 ldu #secondarydict ; point to secondary dictionary table |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
58 lda ,x+ ; get secondary token value |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
59 bne detokenize3 ; brif not end of line |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
60 leax -1,x ; don't consume the NUL |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
61 detokenize2 lda #'! ; invalid token flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
62 bra detokenize0 ; output it and continue |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
63 detokenize3 anda #0x7f ; lose the high bit |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
64 beq detokenize6 ; brif already at the right place |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
65 detokenize4 ldb ,u ; end of dictionary table? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
66 beq detokenize2 ; brif so - show invalid tokenf lag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
67 detokenize5 ldb ,u+ ; fetch character in this keyboard |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
68 bpl detokenize5 ; brif not end of keyword (high bit set) |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
69 deca ; at the right token? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
70 bne detokenize4 ; brif not - skip another |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
71 detokenize6 lda ,u+ ; get keyword character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
72 bmi detokenize7 ; brif end of keyword |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
73 jsr writechr ; output it |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
74 bra detokenize6 ; go fetch another |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
75 detokenize7 anda #0x7f ; lose the high bit |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
76 bra detokenize0 ; write it and move on with the input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
78 ; Canonicalize certain sequences; ALL the rewrite sequences must make the result shorter or keep it the same size |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
79 makecanontab fcb tok_less,2 |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
80 fcb tok_greater,tok_notequal |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
81 fcb tok_equal,tok_lessequal |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
82 fcb tok_greater,2 |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
83 fcb tok_less,tok_notequal |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
84 fcb tok_equal,tok_greaterequal |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
85 fcb tok_equal,2 |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
86 fcb tok_greater,tok_greaterequal |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
87 fcb tok_less,tok_lessequal |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
88 fcb 0 |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
89 makecanon leay ,x ; point output to start of the buffer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
90 makecanon0 lda ,x+ ; get current byte |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
91 sta ,y+ ; save in output |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
92 bne makecanon1 ; brif not end of line |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
93 rts |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
94 makecanon1 bpl makecanon0 ; brif not a token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
95 cmpa #0xff ; is it secondary? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
96 bne makecanon2 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
97 leax 1,x ; move past second half |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
98 bra makecanon0 ; go handle next byte |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
99 makecanon2 ldu #makecanontab ; point to replacement table |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
100 makecanon3 cmpa ,u+ ; is it this entry? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
101 beq makecanon4 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
102 ldb ,u+ ; get number of entries |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
103 lslb ; 2 bytes per |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
104 leau b,u ; move past entry |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
105 ldb ,u ; end of table? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
106 bne makecanon3 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
107 bra makecanon0 ; no substitutions found |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
108 makecanon4 pshs x ; save original source pointer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
109 makecanon5 lda ,x+ ; get next character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
110 cmpa #0x20 ; is it space? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
111 beq makecanon5 ; brif so - skip it |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
112 ldb ,u+ ; get number of replacement candidates |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
113 makecanon6 cmpa ,u++ ; does it match? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
114 beq makecanon7 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
115 decb ; seen all of them? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
116 bne makecanon6 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
117 puls x ; restore input pointer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
118 bra makecanon0 ; go handle next input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
119 makecanon7 leas 2,s ; clear saved input pointer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
120 lda -1,u ; get replacement token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
121 sta -1,y ; put it in the output |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
122 bra makecanon0 ; go handle more input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
124 ; Tokenize line to tokebuff |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
125 ; |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
126 ; Enter with X pointing to the text to tokenize. |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
127 ; Exit with X pointing to the start of the tokenized line and D holding the length of the tokenized line. |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
128 tokenize clr tok_skipkw ; clear "not token" flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
129 clr tok_skipdt ; clear the "in data" flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
130 ldy #tokebuff ; point to destination buffer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
131 pshs y ; set return value |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
132 tokenize0 lda ,x+ ; get input character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
133 bne tokenize3 ; brif not end of input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
134 tokenize1 sta ,y+ ; blank out final byte in result |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
135 tokenize2 ldx #tokebuff ; point to start of tokenized line |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
136 bsr makecanon ; canonicalize certain sequences |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
137 tfr y,d ; get end address to accumulator |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
138 subd #tokebuff ; subtract out start; gives length of result |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
139 puls x,pc ; set return pointer and return |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
140 tokenize3 tst tok_skipkw ; are we in the middle of a "not token"? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
141 beq tokenize6 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
142 jsr setcifalpha ; is it alpha |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
143 bcs tokenize4 ; brif so - store it and continue |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
144 jsr setcifdigit ; is it numeric? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
145 bcc tokenize5 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
146 tokenize4 sta ,y+ ; save output character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
147 bra tokenize0 ; check for another |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
148 tokenize5 clr tok_skipkw ; clear the "not token" flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
149 tokenize6 cmpa #'" ; is it a string? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
150 bne tokenize8 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
151 sta ,y+ ; save string delimiter |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
152 tokenize7 lda ,x+ ; get input character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
153 beq tokenize1 ; brif end of input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
154 sta ,y+ ; save it in output |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
155 cmpa #'" ; end of string? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
156 bne tokenize7 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
157 bra tokenize0 ; brif |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
158 tokenize8 cmpa #': ; end of statement? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
159 bne tokenize9 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
160 clr tok_skipdt ; reset "in data" flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
161 bra tokenize4 ; stash it and continue |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
162 tokenize9 cmpa #0x20 ; is it a space? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
163 beq tokenize4 ; brif so - stash it unmodified |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
164 tst tok_skipdt ; are we "in data"? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
165 bne tokenize4 ; brif so - don't tokenize it |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
166 cmpa #'? ; PRINT shortcut? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
167 bne tokenize10 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
168 lda #tok_print ; load token for PRINT |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
169 bra tokenize4 ; move stash it and move on |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
170 tokenize10 cmpa #'' ; ' shortcut for remark? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
171 bne tokenize12 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
172 ldd #':*256+tok_apos ; put token for ' and an implied colon |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
173 std ,y++ ; stash it |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
174 tokenize11 lda ,x+ ; fetch byte from input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
175 sta ,y+ ; stash in output |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
176 bne tokenize11 ; brif not end of input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
177 bra tokenize2 ; go finish up |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
178 tokenize12 jsr setcifdigit ; is it a digit? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
179 bcs tokenize4 ; brif so - pass it through |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
180 tsta ; is the high bit set? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
181 bmi tokenize0 ; ignore it if so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
182 ldu #primarydict ; point to keyword table |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
183 leax -1,x ; back up input to start of potential token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
184 clr tok_kwtype ; set secondary table flag to primary table |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
185 clr tok_kwmatch ; clear the matched token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
186 clr tok_kwmatch+1 |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
187 clr tok_kwmatchl ; set length matched |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
188 pshs x ; save start of input token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
189 tokenize13 clr tok_kwnum ; clear keyword number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
190 tokenize14 ldb ,u ; are we at the end of the table? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
191 bne tokenize16 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
192 ldu #secondarydict ; point to secondary token dictionary |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
193 com tok_kwtype ; flip to secondary token flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
194 bne tokenize13 ; brif we haven't already done the secondaries |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
195 puls x ; get back input pointer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
196 ldb tok_kwmatchl ; get length of best match |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
197 beq tokenize15 ; brif we don't have a match |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
198 abx ; move input pointer past matched token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
199 ldd tok_kwmatch ; get matched token number |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
200 tsta ; is it a primary? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
201 beq tokenize24 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
202 bra tokenize23 ; go stash two byte token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
203 tokenize15 com tok_skipkw ; set "not token flag" |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
204 lda ,x+ ; get character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
205 bra tokenize4 ; stash it and continue |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
206 tokenize16 ldx ,s ; get back start of input token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
207 clra ; initalize match length counter |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
208 tokenize17 inca ; bump length counter |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
209 ldb ,x+ ; get input character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
210 cmpb #'z ; is it above lower case Z? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
211 bhi tokenize18 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
212 cmpb #'a ; is it below lower case A? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
213 blo tokenize18 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
214 subb #0x20 ; convert to upper case |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
215 tokenize18 subb ,u+ ; does it match? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
216 beq tokenize17 ; brif so - check another |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
217 cmpb #0x80 ; did it match with high bit set? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
218 beq tokenize21 ; brif so - exact match |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
219 leau -1,u ; back up to current test character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
220 tokenize19 ldb ,u+ ; end of token? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
221 bpl tokenize19 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
222 tokenize20 inc tok_kwnum ; bump token counter |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
223 bra tokenize14 ; go check another one |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
224 tokenize21 cmpa tok_kwmatchl ; is it a longer match? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
225 bls tokenize20 ; brif not, ignore it |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
226 sta tok_kwmatchl ; save new match length |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
227 ldd tok_kwtype ; get the matched token count |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
228 orb #0x80 ; set token flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
229 std tok_kwmatch ; save matched token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
230 bra tokenize20 ; keep looking through the tables |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
231 tokenize22 lda #': ; for putting implied colons in |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
232 tokenize23 std ,y++ ; put output into buffer |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
233 jmp tokenize0 ; go handle more input |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
234 tokenize24 cmpb #tok_else ; is it ELSE? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
235 beq tokenize22 ; brif so - stash it with colon |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
236 cmpb #tok_data ; is it DATA? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
237 bne tokenize26 ; brif not |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
238 stb tok_skipdt ; set "in data" flag |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
239 tokenize25 stb ,y+ ; stash token |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
240 jmp tokenize0 ; go handle more |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
241 tokenize26 cmpb #tok_rem ; is it REM? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
242 beq tokenize28 ; brif so |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
243 cmpb #tok_apos ; apostrophe REM? |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
244 bne tokenize25 ; brif not - stash token and continue |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
245 lda #': ; stash the implied colon |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
246 sta ,y+ |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
247 bra tokenize28 |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
248 tokenize27 ldb ,x+ ; fetch next input character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
249 tokenize28 stb ,y+ ; stash the character |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
250 bne tokenize27 ; brif not end of input - do another |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
251 jmp tokenize2 ; stash end of buffer and handle cleanup |
eb2681108660
Split some code into separate files for easier management (4)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
252 *pragmapop list |