git @ Cat's Eye Technologies SixtyPical / 84ca6c4
Break the ground where we need to implement word table read/write. Chris Pressey 3 years ago
5 changed file(s) with 48 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
55
66 * Add word (constant or memory location) to word memory location.
77 * Add word to pointer (unchecked for now).
8 * Adding `word table` type (in progress).
89 * Implementation: `--debug` shows some extra info during analysis.
910 * Fixed bug where `copy`ing literal word into word storage used wrong endianness.
1011
4646 And then write a little demo "game" where you can move a block around the screen with
4747 the joystick.
4848
49 ### `word table` and `vector table` types
49 ### `vector table` type
5050
5151 ### `low` and `high` address operators
5252
5454
5555 ### save registers on stack
5656
57 This preserves them, so semantically, they can be used even though they
57 This preserves them, so that, semantically, they can be used later even though they
5858 are trashed inside the block.
5959
6060 ### And at some point...
0 word one
1 word table many
2
3 routine main
4 inputs one, many
5 outputs one, many
6 trashes a, x, n, z
7 {
8 ld x, 0
9 copy 777, one
10 copy one, many + x
11 copy many + x, one
12 }
11
22 from sixtypical.ast import Program, Routine, Block, Instr
33 from sixtypical.model import (
4 ConstantRef, LocationRef, IndirectRef, AddressRef,
5 TYPE_BIT, TYPE_BYTE, TYPE_WORD, BufferType, PointerType, RoutineType, VectorType,
4 ConstantRef, LocationRef, IndexedRef, IndirectRef, AddressRef,
5 TYPE_BIT, TYPE_BYTE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType,
66 REG_A, REG_X, REG_Y, FLAG_C
77 )
88 from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte
168168 raise UnsupportedOpcodeError(instr)
169169 elif isinstance(dest, LocationRef) and src.type == TYPE_WORD and isinstance(dest.type, PointerType):
170170 if isinstance(src, ConstantRef):
171 dest_label = self.labels[dest.name] # this. is. zero-page.
171 dest_label = self.labels[dest.name]
172172 self.emitter.emit(LDA(ZeroPage(dest_label)))
173173 self.emitter.emit(ADC(Immediate(Byte(src.low_byte()))))
174174 self.emitter.emit(STA(ZeroPage(dest_label)))
177177 self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
178178 elif isinstance(src, LocationRef):
179179 src_label = self.labels[src.name]
180 dest_label = self.labels[dest.name] # this. is. zero-page.
180 dest_label = self.labels[dest.name]
181181 self.emitter.emit(LDA(ZeroPage(dest_label)))
182182 self.emitter.emit(ADC(Absolute(src_label)))
183183 self.emitter.emit(STA(ZeroPage(dest_label)))
344344 self.emitter.emit(STA(ZeroPage(dest_label)))
345345 self.emitter.emit(LDA(Immediate(LowAddressByte(src_label))))
346346 self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1))))
347 elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
348 if src.type == TYPE_WORD and dest.ref.type == TYPE_WORD_TABLE:
349 src_label = self.labels[src.name]
350 dest_label = self.labels[dest.ref.name]
351 raise NotImplementedError("""\
352 What we will need to do here, is to have TWO 'labels' per name, one for the high byte table,
353 and one for the low byte table. Then select AbsoluteX() or AbsoluteY() addressing on those
354 tables. And use that in the STA() part.""")
355 else:
356 raise NotImplementedError
357
347358 elif not isinstance(src, (ConstantRef, LocationRef)) or not isinstance(dest, LocationRef):
348359 raise NotImplementedError((src, dest))
349360 elif src.type == TYPE_BYTE and dest.type == TYPE_BYTE:
315315 | }
316316 = 00c078a90d8d0fc0a9c08d10c05860e860
317317
318 Copy word to word table and back.
319
320 | word one
321 | word table many
322 |
323 | routine main
324 | inputs one, many
325 | outputs one, many
326 | trashes a, x, n, z
327 | {
328 | ld x, 0
329 | copy 777, one
330 | copy one, many + x
331 | copy many + x, one
332 | }
333 = 00c0a200a9009d0dc0bd0dc060....
334
318335 Indirect call.
319336
320337 | vector foo outputs x trashes z, n