1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 03:41:28 +00:00

copy from word storage to word table and back, indexed by x or y.

This commit is contained in:
Chris Pressey 2017-12-11 12:02:48 +00:00
parent b86e7491d5
commit 2216fcec17
4 changed files with 54 additions and 16 deletions

View File

@ -6,7 +6,8 @@ History of SixtyPical
* Add word (constant or memory location) to word memory location.
* Add word to pointer (unchecked for now).
* Adding `word table` type (in progress).
* Added `word table` type.
* Can `copy` from word storage location to word table and back.
* Implementation: `--debug` shows some extra info during analysis.
* Fixed bug where `copy`ing literal word into word storage used wrong endianness.
* Fixed bug where every memory location was allocated 2 bytes of storage, regardless of type.

View File

@ -4,10 +4,13 @@ word table many
routine main
inputs one, many
outputs one, many
trashes a, x, n, z
trashes a, x, y, n, z
{
ld x, 0
ld y, 0
copy 777, one
copy one, many + x
//copy many + x, one
copy one, many + y
copy many + x, one
copy many + y, one
}

View File

@ -371,9 +371,26 @@ class Compiler(object):
else:
raise NotImplementedError(dest)
self.emitter.emit(LDA(Absolute(src_label)))
self.emitter.emit(STA(AbsoluteX(dest_label)))
self.emitter.emit(STA(addressing_mode(dest_label)))
self.emitter.emit(LDA(Absolute(Offset(src_label, 1))))
self.emitter.emit(STA(AbsoluteX(Offset(dest_label, 256))))
self.emitter.emit(STA(addressing_mode(Offset(dest_label, 256))))
else:
raise NotImplementedError
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
if src.ref.type == TYPE_WORD_TABLE and dest.type == TYPE_WORD:
src_label = self.labels[src.ref.name]
dest_label = self.labels[dest.name]
addressing_mode = None
if src.index == REG_X:
addressing_mode = AbsoluteX
elif src.index == REG_Y:
addressing_mode = AbsoluteY
else:
raise NotImplementedError(src)
self.emitter.emit(LDA(addressing_mode(src_label)))
self.emitter.emit(STA(Absolute(dest_label)))
self.emitter.emit(LDA(addressing_mode(Offset(src_label, 256))))
self.emitter.emit(STA(Absolute(Offset(dest_label, 1))))
else:
raise NotImplementedError

View File

@ -453,7 +453,7 @@ Copy routine to vector, inside an `interrupts off` block.
= $081A INX
= $081B RTS
Copy word to word table.
Copy word to word table and back, with both `x` and `y` as indexes.
| word one
| word table many
@ -461,22 +461,39 @@ Copy word to word table.
| routine main
| inputs one, many
| outputs one, many
| trashes a, x, n, z
| trashes a, x, y, n, z
| {
| ld x, 0
| ld y, 0
| copy 777, one
| copy one, many + x
| copy one, many + y
| copy many + x, one
| copy many + y, one
| }
= $080D LDX #$00
= $080F LDA #$09
= $0811 STA $0826
= $0814 LDA #$03
= $0816 STA $0827
= $0819 LDA $0826
= $081C STA $0828,X
= $081F LDA $0827
= $0822 STA $0928,X
= $0825 RTS
= $080F LDY #$00
= $0811 LDA #$09
= $0813 STA $084C
= $0816 LDA #$03
= $0818 STA $084D
= $081B LDA $084C
= $081E STA $084E,X
= $0821 LDA $084D
= $0824 STA $094E,X
= $0827 LDA $084C
= $082A STA $084E,Y
= $082D LDA $084D
= $0830 STA $094E,Y
= $0833 LDA $084E,X
= $0836 STA $084C
= $0839 LDA $094E,X
= $083C STA $084D
= $083F LDA $084E,Y
= $0842 STA $084C
= $0845 LDA $094E,Y
= $0848 STA $084D
= $084B RTS
Indirect call.