Compile copy byte to byte and word to word.
Chris Pressey
9 years ago
4 | 4 | ------- |
5 | 5 | |
6 | 6 | * User-defined `byte` locations can be given an initial value. |
7 | * `word` type locations which can be defined and `copy`ed between. | |
8 | * Can `copy` directly from one user-defined `byte` location to another. | |
7 | 9 | |
8 | 10 | 0.6 |
9 | 11 | --- |
43 | 43 | |
44 | 44 | For 0.7: |
45 | 45 | |
46 | * `word` type. | |
46 | * `low` and `high` address operators (turn `word` type into `byte`.) | |
47 | 47 | * `word table` type. |
48 | 48 | |
49 | 49 | For 0.8: |
2 | 2 | from sixtypical.ast import Program, Routine, Block, Instr |
3 | 3 | from sixtypical.model import ( |
4 | 4 | ConstantRef, |
5 | TYPE_BIT, | |
5 | TYPE_BIT, TYPE_BYTE, TYPE_WORD, | |
6 | 6 | RoutineType, VectorType, |
7 | 7 | REG_A, REG_X, REG_Y, FLAG_C |
8 | 8 | ) |
274 | 274 | self.compile_block(instr.block) |
275 | 275 | self.emitter.emit(CLI()) |
276 | 276 | elif opcode == 'copy': |
277 | if isinstance(src.type, VectorType) and isinstance(dest.type, VectorType): | |
277 | if src.type == TYPE_BYTE and dest.type == TYPE_BYTE: | |
278 | src_label = self.labels[src.name] | |
279 | dest_label = self.labels[dest.name] | |
280 | self.emitter.emit(LDA(Absolute(src_label))) | |
281 | self.emitter.emit(STA(Absolute(dest_label))) | |
282 | elif src.type == TYPE_WORD and dest.type == TYPE_WORD: | |
283 | src_label = self.labels[src.name] | |
284 | dest_label = self.labels[dest.name] | |
285 | self.emitter.emit(LDA(Absolute(src_label))) | |
286 | self.emitter.emit(STA(Absolute(dest_label))) | |
287 | self.emitter.emit(LDA(Absolute(Offset(src_label, 1)))) | |
288 | self.emitter.emit(STA(Absolute(Offset(dest_label, 1)))) | |
289 | elif isinstance(src.type, VectorType) and isinstance(dest.type, VectorType): | |
278 | 290 | src_label = self.labels[src.name] |
279 | 291 | dest_label = self.labels[dest.name] |
280 | 292 | self.emitter.emit(LDA(Absolute(src_label))) |
238 | 238 | | } |
239 | 239 | = 00c0a200a9009d0dc0bd0dc060 |
240 | 240 | |
241 | Copy instruction.. | |
241 | Copy byte to byte. | |
242 | ||
243 | | byte bar | |
244 | | byte baz | |
245 | | | |
246 | | routine main | |
247 | | inputs baz | |
248 | | outputs bar | |
249 | | trashes a, n, z | |
250 | | { | |
251 | | copy baz, bar | |
252 | | } | |
253 | = 00c0ad09c08d07c060 | |
254 | ||
255 | Copy word to word. | |
256 | ||
257 | | word bar | |
258 | | word baz | |
259 | | | |
260 | | routine main | |
261 | | inputs baz | |
262 | | outputs bar | |
263 | | trashes a, n, z | |
264 | | { | |
265 | | copy baz, bar | |
266 | | } | |
267 | = 00c0ad0fc08d0dc0ad10c08d0ec060 | |
268 | ||
269 | Copy vector to vector. | |
242 | 270 | |
243 | 271 | | vector bar |
244 | 272 | | vector baz |