git @ Cat's Eye Technologies SixtyPical / 2216fce
copy from word storage to word table and back, indexed by x or y. Chris Pressey 3 years ago
4 changed file(s) with 54 addition(s) and 16 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).
8 * Added `word table` type.
9 * Can `copy` from word storage location to word table and back.
910 * Implementation: `--debug` shows some extra info during analysis.
1011 * Fixed bug where `copy`ing literal word into word storage used wrong endianness.
1112 * Fixed bug where every memory location was allocated 2 bytes of storage, regardless of type.
33 routine main
44 inputs one, many
55 outputs one, many
6 trashes a, x, n, z
6 trashes a, x, y, n, z
77 {
88 ld x, 0
9 ld y, 0
910 copy 777, one
1011 copy one, many + x
11 //copy many + x, one
12 copy one, many + y
13 copy many + x, one
14 copy many + y, one
1215 }
370370 else:
371371 raise NotImplementedError(dest)
372372 self.emitter.emit(LDA(Absolute(src_label)))
373 self.emitter.emit(STA(AbsoluteX(dest_label)))
373 self.emitter.emit(STA(addressing_mode(dest_label)))
374374 self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
375 self.emitter.emit(STA(AbsoluteX(Offset(dest_label, 256))))
375 self.emitter.emit(STA(addressing_mode(Offset(dest_label, 256))))
376 else:
377 raise NotImplementedError
378 elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
379 if src.ref.type == TYPE_WORD_TABLE and dest.type == TYPE_WORD:
380 src_label = self.labels[src.ref.name]
381 dest_label = self.labels[dest.name]
382 addressing_mode = None
383 if src.index == REG_X:
384 addressing_mode = AbsoluteX
385 elif src.index == REG_Y:
386 addressing_mode = AbsoluteY
387 else:
388 raise NotImplementedError(src)
389 self.emitter.emit(LDA(addressing_mode(src_label)))
390 self.emitter.emit(STA(Absolute(dest_label)))
391 self.emitter.emit(LDA(addressing_mode(Offset(src_label, 256))))
392 self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
376393 else:
377394 raise NotImplementedError
378395
452452 = $081A INX
453453 = $081B RTS
454454
455 Copy word to word table.
455 Copy word to word table and back, with both `x` and `y` as indexes.
456456
457457 | word one
458458 | word table many
460460 | routine main
461461 | inputs one, many
462462 | outputs one, many
463 | trashes a, x, n, z
463 | trashes a, x, y, n, z
464464 | {
465465 | ld x, 0
466 | ld y, 0
466467 | copy 777, one
467468 | copy one, many + x
469 | copy one, many + y
470 | copy many + x, one
471 | copy many + y, one
468472 | }
469473 = $080D LDX #$00
470 = $080F LDA #$09
471 = $0811 STA $0826
472 = $0814 LDA #$03
473 = $0816 STA $0827
474 = $0819 LDA $0826
475 = $081C STA $0828,X
476 = $081F LDA $0827
477 = $0822 STA $0928,X
478 = $0825 RTS
474 = $080F LDY #$00
475 = $0811 LDA #$09
476 = $0813 STA $084C
477 = $0816 LDA #$03
478 = $0818 STA $084D
479 = $081B LDA $084C
480 = $081E STA $084E,X
481 = $0821 LDA $084D
482 = $0824 STA $094E,X
483 = $0827 LDA $084C
484 = $082A STA $084E,Y
485 = $082D LDA $084D
486 = $0830 STA $094E,Y
487 = $0833 LDA $084E,X
488 = $0836 STA $084C
489 = $0839 LDA $094E,X
490 = $083C STA $084D
491 = $083F LDA $084E,Y
492 = $0842 STA $084C
493 = $0845 LDA $094E,Y
494 = $0848 STA $084D
495 = $084B RTS
479496
480497 Indirect call.
481498