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

Can copy a literal word to a word table.

This commit is contained in:
Chris Pressey 2017-12-12 16:04:59 +00:00
parent 63f75a26b4
commit 50390b0787
5 changed files with 54 additions and 1 deletions

View File

@ -8,6 +8,7 @@ History of SixtyPical
* The `forward` modifier can also be used to indicate that the symbol being copied
in a `copy` to a vector is a routine that is defined further down in the source.
* Initialized `word` memory locations.
* Can `copy` a literal word to a word table.
* Fixed bug which was preventing `if` branches to diverge in what they initialized,
if it was already initialized when going into the `if`.
* Fixed a bug which was making it crash when trying to analyze `repeat forever` loops.

View File

@ -352,7 +352,7 @@ class Analyzer(object):
else:
raise TypeMismatchError((src, dest))
elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef):
elif isinstance(src, (LocationRef, ConstantRef)) and isinstance(dest, IndexedRef):
if src.type == TYPE_WORD and dest.ref.type == TYPE_WORD_TABLE:
pass
else:
@ -391,6 +391,9 @@ class Analyzer(object):
context.assert_meaningful(src, dest.ref, dest.index)
context.set_touched(src) # TODO and dest.index?
context.set_written(dest.ref)
elif isinstance(src, ConstantRef) and isinstance(dest, IndexedRef):
context.assert_meaningful(src, dest.ref, dest.index)
context.set_written(dest.ref)
elif isinstance(src, IndexedRef) and isinstance(dest, LocationRef):
context.assert_meaningful(src.ref, src.index, dest)
context.set_touched(dest) # TODO and src.index?

View File

@ -383,6 +383,22 @@ class Compiler(object):
self.emitter.emit(STA(addressing_mode(Offset(dest_label, 256))))
else:
raise NotImplementedError
elif isinstance(src, ConstantRef) and isinstance(dest, IndexedRef):
if src.type == TYPE_WORD and dest.ref.type == TYPE_WORD_TABLE:
dest_label = self.labels[dest.ref.name]
addressing_mode = None
if dest.index == REG_X:
addressing_mode = AbsoluteX
elif dest.index == REG_Y:
addressing_mode = AbsoluteY
else:
raise NotImplementedError(dest)
self.emitter.emit(LDA(Immediate(Byte(src.low_byte()))))
self.emitter.emit(STA(addressing_mode(dest_label)))
self.emitter.emit(LDA(Immediate(Byte(src.high_byte()))))
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]

View File

@ -388,6 +388,20 @@ Copying to and from a word table.
| }
? TypeMismatchError
You can also copy a literal word to a word table.
| word table many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
= ok
### add ###
Can't `add` from or to a memory location that isn't initialized.

View File

@ -434,6 +434,25 @@ Copy literal word to word.
= $0814 STA $0819
= $0817 RTS
You can also copy a literal word to a word table.
| word table many
|
| routine main
| inputs many
| outputs many
| trashes a, x, n, z
| {
| ld x, 0
| copy 9999, many + x
| }
= $080D LDX #$00
= $080F LDA #$0F
= $0811 STA $081A,X
= $0814 LDA #$27
= $0816 STA $091A,X
= $0819 RTS
Copy vector to vector.
| vector bar