... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
( devices ) |
2 | 2 |
|
3 | 3 |
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 ] |
4 |
-|10 @Console [ &pad $8 &char $1 &byte $1 &short $2 &string $2 ] |
|
4 |
+|10 @Console [ &pad $8 &write $1 ] |
|
5 | 5 |
|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ] |
6 | 6 |
|
7 | 7 |
( vectors ) |
... | ... |
@@ -20,6 +20,15 @@ |
20 | 20 |
) |
21 | 21 |
|
22 | 22 |
|0100 @reset |
23 |
+ ( |
|
24 |
+ Set the log level for helping to debug stuff. |
|
25 |
+ Its value is the bitwise OR of all the following output types: |
|
26 |
+ #01 prints the number of lines in the source code, |
|
27 |
+ #04 dumps all defined labels at end, and |
|
28 |
+ #08 prints the heap usage. |
|
29 |
+ ) |
|
30 |
+ #09 ;asma/log-level STA |
|
31 |
+ |
|
23 | 32 |
( |
24 | 33 |
Assemble the source code into an output ROM file. |
25 | 34 |
|
... | ... |
@@ -70,17 +79,6 @@ |
70 | 79 |
) |
71 | 80 |
|
72 | 81 |
%asma-IF-ERROR { ;asma/error LDA2 ORA } |
73 |
-%asma-LOG { #09 } |
|
74 |
-( |
|
75 |
- asma-LOG is a log-level parameter for helping to debug stuff. |
|
76 |
- Its value is the bitwise OR of all the following output types: |
|
77 |
- #01 prints the number of lines in the source code, |
|
78 |
- #02 prints tokens as they are processed, |
|
79 |
- #04 dumps all defined labels at end, and |
|
80 |
- #08 prints the heap usage. |
|
81 |
-) |
|
82 |
-%asma-DEO2 { asma-LOG AND #00 EQU JMP DEO2k POP POP2 } |
|
83 |
-%asma-DEO { asma-LOG AND #00 EQU JMP DEOk POP2 } |
|
84 | 82 |
|
85 | 83 |
( |
86 | 84 |
Asma's public interface. |
... | ... |
@@ -119,30 +117,34 @@ |
119 | 117 |
) |
120 | 118 |
|
121 | 119 |
@asma-print-error ( -- ) |
122 |
- ;asma/error LDA2 .Console/string DEO2 |
|
123 |
- #3a .Console/char DEO |
|
124 |
- #20 .Console/char DEO |
|
125 |
- ;asma/orig-token LDA2 .Console/string DEO2 |
|
126 |
- ;&line .Console/string DEO2 |
|
127 |
- ;asma/line LDA2 .Console/short DEO2 |
|
128 |
- #2e .Console/char DEO |
|
129 |
- #0a .Console/char DEO |
|
120 |
+ ;asma/error LDA2 ;asma-print-string JSR2 |
|
121 |
+ #3a .Console/write DEO |
|
122 |
+ #20 .Console/write DEO |
|
123 |
+ ;asma/orig-token LDA2 ;asma-print-string JSR2 |
|
124 |
+ ;&line ;asma-print-string JSR2 |
|
125 |
+ ;asma/line LDA2 ;asma-print-short JSR2 |
|
126 |
+ #2e .Console/write DEO |
|
127 |
+ #0a .Console/write DEO |
|
130 | 128 |
JMP2r |
131 | 129 |
|
132 | 130 |
&line 20 "on 20 "line 20 00 |
133 | 131 |
|
134 | 132 |
@asma-print-line-count ( -- ) |
135 |
- ;asma/line LDA2 .Console/short #01 asma-DEO2 |
|
136 |
- ;&lines .Console/string #01 asma-DEO2 |
|
133 |
+ ;asma/log-level LDA #01 AND #00 EQU ,&skip JCN |
|
134 |
+ ;asma/line LDA2 ;asma-print-short JSR2 |
|
135 |
+ ;&lines ;asma-print-string JSR2 |
|
136 |
+ &skip |
|
137 | 137 |
JMP2r |
138 | 138 |
|
139 | 139 |
&lines [ 20 "lines 20 "of 20 "source 20 "code. 0a 00 ] |
140 | 140 |
|
141 | 141 |
@asma-print-heap-usage ( -- ) |
142 |
- ;asma/heap LDA2 ;asma-heap SUB2 .Console/short #08 asma-DEO2 |
|
143 |
- ;&str1 .Console/string #08 asma-DEO2 |
|
144 |
- ;asma-heap/end ;asma/heap LDA2 SUB2 .Console/short #08 asma-DEO2 |
|
145 |
- ;&str2 .Console/string #08 asma-DEO2 |
|
142 |
+ ;asma/log-level LDA #08 AND #00 EQU ,&skip JCN |
|
143 |
+ ;asma/heap LDA2 ;asma-heap SUB2 ;asma-print-short JSR2 |
|
144 |
+ ;&str1 ;asma-print-string JSR2 |
|
145 |
+ ;asma-heap/end ;asma/heap LDA2 SUB2 ;asma-print-short JSR2 |
|
146 |
+ ;&str2 ;asma-print-string JSR2 |
|
147 |
+ &skip |
|
146 | 148 |
JMP2r |
147 | 149 |
|
148 | 150 |
&str1 [ 20 "bytes 20 "of 20 "heap 20 "used, 20 00 ] |
... | ... |
@@ -157,26 +159,28 @@ |
157 | 159 |
( left node ) |
158 | 160 |
DUP2 ,asma-print-sublabels JSR |
159 | 161 |
( here ) |
160 |
- #09 .Console/char #04 asma-DEO |
|
162 |
+ #09 .Console/write DEO |
|
161 | 163 |
DUP2 #0004 ADD2 |
162 | 164 |
&loop |
163 | 165 |
DUP2 #0001 ADD2 SWP2 LDA |
164 | 166 |
DUP #00 EQU ,&end JCN |
165 |
- .Console/char #04 asma-DEO |
|
167 |
+ .Console/write DEO |
|
166 | 168 |
,&loop JMP |
167 | 169 |
&end |
168 | 170 |
POP |
169 |
- #09 .Console/char #04 asma-DEO |
|
170 |
- LDA2 .Console/short #04 asma-DEO2 |
|
171 |
- #0a .Console/char #04 asma-DEO |
|
171 |
+ #09 .Console/write DEO |
|
172 |
+ LDA2 ;asma-print-short JSR2 |
|
173 |
+ #0a .Console/write DEO |
|
172 | 174 |
|
173 | 175 |
( right node ) |
174 | 176 |
#0002 ADD2 ,asma-print-sublabels JSR |
175 | 177 |
JMP2r |
176 | 178 |
|
177 | 179 |
@asma-print-labels ( incoming-ptr* -- ) |
180 |
+ ;asma/log-level LDA #04 AND #00 EQU ,&skip JCN |
|
178 | 181 |
LDA2 |
179 | 182 |
ORAk ,&valid-incoming-ptr JCN |
183 |
+ &skip |
|
180 | 184 |
POP2 JMP2r |
181 | 185 |
|
182 | 186 |
&valid-incoming-ptr |
... | ... |
@@ -187,13 +191,13 @@ |
187 | 191 |
&loop |
188 | 192 |
DUP2 #0001 ADD2 SWP2 LDA |
189 | 193 |
DUP #00 EQU ,&end JCN |
190 |
- .Console/char #04 asma-DEO |
|
194 |
+ .Console/write DEO |
|
191 | 195 |
,&loop JMP |
192 | 196 |
&end |
193 | 197 |
POP |
194 |
- #09 .Console/char #04 asma-DEO |
|
195 |
- LDA2k .Console/short #04 asma-DEO2 |
|
196 |
- #0a .Console/char #04 asma-DEO |
|
198 |
+ #09 .Console/write DEO |
|
199 |
+ LDA2k ;asma-print-short JSR2 |
|
200 |
+ #0a .Console/write DEO |
|
197 | 201 |
( subtree ) |
198 | 202 |
#0002 ADD2 ;asma-print-sublabels JSR2 |
199 | 203 |
|
... | ... |
@@ -201,6 +205,27 @@ |
201 | 205 |
#0002 ADD2 ,asma-print-labels JSR |
202 | 206 |
JMP2r |
203 | 207 |
|
208 |
+@asma-print-string ( ptr* -- ) |
|
209 |
+ LDAk DUP ,&keep-going JCN |
|
210 |
+ POP POP2 JMP2r |
|
211 |
+ |
|
212 |
+ &keep-going |
|
213 |
+ .Console/write DEO |
|
214 |
+ #0001 ADD2 |
|
215 |
+ ,asma-print-string JMP |
|
216 |
+ |
|
217 |
+@asma-print-short ( short* -- ) |
|
218 |
+ LIT '0 .Console/write DEO |
|
219 |
+ LIT 'x .Console/write DEO |
|
220 |
+ OVR #04 SFT ,&hex JSR |
|
221 |
+ SWP #0f AND ,&hex JSR |
|
222 |
+ DUP #04 SFT ,&hex JSR |
|
223 |
+ #0f AND ,&hex JMP |
|
224 |
+ |
|
225 |
+ &hex |
|
226 |
+ #30 ADD DUP #39 GTH #27 MUL ADD .Console/write DEO |
|
227 |
+ JMP2r |
|
228 |
+ |
|
204 | 229 |
( |
205 | 230 |
Initialise the assembler state before loading a file or chunk. |
206 | 231 |
) |
... | ... |
@@ -298,7 +323,13 @@ |
298 | 323 |
POP POP2 POP2 |
299 | 324 |
JMP2r |
300 | 325 |
|
301 |
-@asma [ &pass $1 &state $1 &line $2 &token $2 &orig-token $2 &heap $2 &addr $2 &written-addr $2 &flush-fn $2 &src-filename $2 &dest-filename $2 &error $2 ] |
|
326 |
+@asma [ |
|
327 |
+ &pass $1 &state $1 &line $2 |
|
328 |
+ &token $2 &orig-token $2 |
|
329 |
+ &heap $2 &addr $2 &written-addr $2 &flush-fn $2 |
|
330 |
+ &src-filename $2 &dest-filename $2 |
|
331 |
+ &error $2 &log-level $1 |
|
332 |
+] |
|
302 | 333 |
@asma-trees [ &labels $2 ¯os $2 &opcodes $2 &scope $2 ] |
303 | 334 |
|
304 | 335 |
( |
... | ... |
@@ -314,8 +345,6 @@ |
314 | 345 |
) |
315 | 346 |
|
316 | 347 |
@asma-assemble-token ( string-ptr* -- ) |
317 |
- DUP2 .Console/string #02 asma-DEO2 |
|
318 |
- #0a .Console/char #02 asma-DEO |
|
319 | 348 |
DUP2 ;asma/token STA2 |
320 | 349 |
DUP2 ;asma/orig-token STA2 |
321 | 350 |
LDAk ,¬-empty JCN |
... | ... |
@@ -489,11 +518,6 @@ |
489 | 518 |
&after-flush |
490 | 519 |
STH2k STA |
491 | 520 |
STH2r #0001 ADD2 ,asma-output/ptr STR2 |
492 |
- |
|
493 |
- ( #3e .Console/char ;asma/pass LDA asma-DEO |
|
494 |
- #20 .Console/char ;asma/pass LDA asma-DEO |
|
495 |
- #00 .Console/byte ;asma/pass LDA asma-DEO |
|
496 |
- #0a .Console/char ;asma/pass LDA asma-DEO ) |
|
497 | 521 |
JMP2r |
498 | 522 |
|
499 | 523 |
&flush ( ptr* -- start-of-buffer* ) |