git @ Cat's Eye Technologies SixtyPical / f87bcf5
Initial work on initialized byte tables. Chris Pressey 3 years ago
5 changed file(s) with 304 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
55 TYPE_BIT, TYPE_BYTE, TYPE_BYTE_TABLE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType,
66 REG_A, REG_X, REG_Y, FLAG_C
77 )
8 from sixtypical.emitter import Byte, Word, Label, Offset, LowAddressByte, HighAddressByte
8 from sixtypical.emitter import Byte, Word, Table, Label, Offset, LowAddressByte, HighAddressByte
99 from sixtypical.gen6502 import (
1010 Immediate, Absolute, AbsoluteX, AbsoluteY, ZeroPage, Indirect, IndirectY, Relative,
1111 LDA, LDX, LDY, STA, STX, STY,
7777 initial_data = Byte(defn.initial)
7878 elif type_ == TYPE_WORD:
7979 initial_data = Word(defn.initial)
80 elif type_ == TYPE_BYTE_TABLE:
81 initial_data = Table(defn.initial)
8082 else:
8183 raise NotImplementedError(type_)
8284 label.set_length(initial_data.size())
4747
4848
4949 class Table(Emittable):
50 def __init__(self, value):
51 # TODO: range-checking
52 self.value = value
53
5054 def size(self):
5155 return 256
5256
5357 def serialize(self, addr=None):
54 return chr(0) * self.size()
58 bytes = []
59 for b in self.value:
60 bytes.append(chr(ord(b)))
61 while len(bytes) < self.size():
62 bytes.append(chr(0))
63 return ''.join(bytes)
5564
5665 def __repr__(self):
5766 return "%s()" % (self.__class__.__name__)
8888
8989 initial = None
9090 if self.scanner.consume(':'):
91 self.scanner.check_type('integer literal')
92 initial = int(self.scanner.token)
91 if type_ == TYPE_BYTE_TABLE and self.scanner.on_type('string literal'):
92 initial = self.scanner.token
93 else:
94 self.scanner.check_type('integer literal')
95 initial = int(self.scanner.token)
9396 self.scanner.scan()
9497
9598 addr = None
135135 = $0819 RTS
136136 = $081A .byte $BB
137137 = $081B .byte $0B
138
139 Initialized byte table.
140
141 | byte table message : "WHAT?"
142 |
143 | routine main
144 | inputs message
145 | outputs x, a, z, n
146 | {
147 | ld x, 0
148 | ld a, message + x
149 | }
150 = $080D LDX #$00
151 = $080F LDA $0813,X
152 = $0812 RTS
153 = $0813 .byte $57
154 = $0814 PHA
155 = $0815 EOR ($54,X)
156 = $0817 .byte $3F
157 = $0818 BRK
158 = $0819 BRK
159 = $081A BRK
160 = $081B BRK
161 = $081C BRK
162 = $081D BRK
163 = $081E BRK
164 = $081F BRK
165 = $0820 BRK
166 = $0821 BRK
167 = $0822 BRK
168 = $0823 BRK
169 = $0824 BRK
170 = $0825 BRK
171 = $0826 BRK
172 = $0827 BRK
173 = $0828 BRK
174 = $0829 BRK
175 = $082A BRK
176 = $082B BRK
177 = $082C BRK
178 = $082D BRK
179 = $082E BRK
180 = $082F BRK
181 = $0830 BRK
182 = $0831 BRK
183 = $0832 BRK
184 = $0833 BRK
185 = $0834 BRK
186 = $0835 BRK
187 = $0836 BRK
188 = $0837 BRK
189 = $0838 BRK
190 = $0839 BRK
191 = $083A BRK
192 = $083B BRK
193 = $083C BRK
194 = $083D BRK
195 = $083E BRK
196 = $083F BRK
197 = $0840 BRK
198 = $0841 BRK
199 = $0842 BRK
200 = $0843 BRK
201 = $0844 BRK
202 = $0845 BRK
203 = $0846 BRK
204 = $0847 BRK
205 = $0848 BRK
206 = $0849 BRK
207 = $084A BRK
208 = $084B BRK
209 = $084C BRK
210 = $084D BRK
211 = $084E BRK
212 = $084F BRK
213 = $0850 BRK
214 = $0851 BRK
215 = $0852 BRK
216 = $0853 BRK
217 = $0854 BRK
218 = $0855 BRK
219 = $0856 BRK
220 = $0857 BRK
221 = $0858 BRK
222 = $0859 BRK
223 = $085A BRK
224 = $085B BRK
225 = $085C BRK
226 = $085D BRK
227 = $085E BRK
228 = $085F BRK
229 = $0860 BRK
230 = $0861 BRK
231 = $0862 BRK
232 = $0863 BRK
233 = $0864 BRK
234 = $0865 BRK
235 = $0866 BRK
236 = $0867 BRK
237 = $0868 BRK
238 = $0869 BRK
239 = $086A BRK
240 = $086B BRK
241 = $086C BRK
242 = $086D BRK
243 = $086E BRK
244 = $086F BRK
245 = $0870 BRK
246 = $0871 BRK
247 = $0872 BRK
248 = $0873 BRK
249 = $0874 BRK
250 = $0875 BRK
251 = $0876 BRK
252 = $0877 BRK
253 = $0878 BRK
254 = $0879 BRK
255 = $087A BRK
256 = $087B BRK
257 = $087C BRK
258 = $087D BRK
259 = $087E BRK
260 = $087F BRK
261 = $0880 BRK
262 = $0881 BRK
263 = $0882 BRK
264 = $0883 BRK
265 = $0884 BRK
266 = $0885 BRK
267 = $0886 BRK
268 = $0887 BRK
269 = $0888 BRK
270 = $0889 BRK
271 = $088A BRK
272 = $088B BRK
273 = $088C BRK
274 = $088D BRK
275 = $088E BRK
276 = $088F BRK
277 = $0890 BRK
278 = $0891 BRK
279 = $0892 BRK
280 = $0893 BRK
281 = $0894 BRK
282 = $0895 BRK
283 = $0896 BRK
284 = $0897 BRK
285 = $0898 BRK
286 = $0899 BRK
287 = $089A BRK
288 = $089B BRK
289 = $089C BRK
290 = $089D BRK
291 = $089E BRK
292 = $089F BRK
293 = $08A0 BRK
294 = $08A1 BRK
295 = $08A2 BRK
296 = $08A3 BRK
297 = $08A4 BRK
298 = $08A5 BRK
299 = $08A6 BRK
300 = $08A7 BRK
301 = $08A8 BRK
302 = $08A9 BRK
303 = $08AA BRK
304 = $08AB BRK
305 = $08AC BRK
306 = $08AD BRK
307 = $08AE BRK
308 = $08AF BRK
309 = $08B0 BRK
310 = $08B1 BRK
311 = $08B2 BRK
312 = $08B3 BRK
313 = $08B4 BRK
314 = $08B5 BRK
315 = $08B6 BRK
316 = $08B7 BRK
317 = $08B8 BRK
318 = $08B9 BRK
319 = $08BA BRK
320 = $08BB BRK
321 = $08BC BRK
322 = $08BD BRK
323 = $08BE BRK
324 = $08BF BRK
325 = $08C0 BRK
326 = $08C1 BRK
327 = $08C2 BRK
328 = $08C3 BRK
329 = $08C4 BRK
330 = $08C5 BRK
331 = $08C6 BRK
332 = $08C7 BRK
333 = $08C8 BRK
334 = $08C9 BRK
335 = $08CA BRK
336 = $08CB BRK
337 = $08CC BRK
338 = $08CD BRK
339 = $08CE BRK
340 = $08CF BRK
341 = $08D0 BRK
342 = $08D1 BRK
343 = $08D2 BRK
344 = $08D3 BRK
345 = $08D4 BRK
346 = $08D5 BRK
347 = $08D6 BRK
348 = $08D7 BRK
349 = $08D8 BRK
350 = $08D9 BRK
351 = $08DA BRK
352 = $08DB BRK
353 = $08DC BRK
354 = $08DD BRK
355 = $08DE BRK
356 = $08DF BRK
357 = $08E0 BRK
358 = $08E1 BRK
359 = $08E2 BRK
360 = $08E3 BRK
361 = $08E4 BRK
362 = $08E5 BRK
363 = $08E6 BRK
364 = $08E7 BRK
365 = $08E8 BRK
366 = $08E9 BRK
367 = $08EA BRK
368 = $08EB BRK
369 = $08EC BRK
370 = $08ED BRK
371 = $08EE BRK
372 = $08EF BRK
373 = $08F0 BRK
374 = $08F1 BRK
375 = $08F2 BRK
376 = $08F3 BRK
377 = $08F4 BRK
378 = $08F5 BRK
379 = $08F6 BRK
380 = $08F7 BRK
381 = $08F8 BRK
382 = $08F9 BRK
383 = $08FA BRK
384 = $08FB BRK
385 = $08FC BRK
386 = $08FD BRK
387 = $08FE BRK
388 = $08FF BRK
389 = $0900 BRK
390 = $0901 BRK
391 = $0902 BRK
392 = $0903 BRK
393 = $0904 BRK
394 = $0905 BRK
395 = $0906 BRK
396 = $0907 BRK
397 = $0908 BRK
398 = $0909 BRK
399 = $090A BRK
400 = $090B BRK
401 = $090C BRK
402 = $090D BRK
403 = $090E BRK
404 = $090F BRK
405 = $0910 BRK
406 = $0911 BRK
407 = $0912 BRK
138408
139409 Some instructions.
140410
177177 | }
178178 = ok
179179
180 Initialized byte table.
181
182 | byte table message : "WHAT DO YOU WANT TO DO NEXT?"
183 |
184 | routine main {
185 | }
186 = ok
187
188 Can't initialize anything but a byte table with a string.
189
190 | word message : "WHAT DO YOU WANT TO DO NEXT?"
191 |
192 | routine main {
193 | }
194 ? SyntaxError
195
180196 Can't access an undeclared memory location.
181197
182198 | routine main {