From f9dc730f88274bd54e3c7065005bfd6ba5c01ae4 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Wed, 13 Dec 2017 16:11:02 +0000 Subject: [PATCH] `copy []+y, a` to indirectly read byte into the `a` register. --- HISTORY.md | 1 + eg/proto-game.60p | 4 +++- src/sixtypical/compiler.py | 5 ++++- tests/SixtyPical Compilation.md | 10 ++++++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 0c66e7f..0259d3c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ History of SixtyPical * Can `copy` a literal word to a word table. * Subtract word (constant or memory location) from word memory location. * `trash` instruction explicitly indicates a value is no longer considered meaningful. +* `copy []+y, a` can indirectly read a byte value into the `a` register. * 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. diff --git a/eg/proto-game.60p b/eg/proto-game.60p index d53c111..7ffd61c 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -235,7 +235,9 @@ routine player_logic add ptr, new_pos ld y, 0 - // copy [ptr] + y, a + // check collision. + copy [ptr] + y, a + // cmp a, 32 // if z { // copy new_pos, pos diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 99eb5cc..1888cd7 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -385,7 +385,10 @@ class Compiler(object): else: raise NotImplementedError((src, dest)) elif isinstance(src, IndirectRef) and isinstance(dest, LocationRef): - if dest.type == TYPE_BYTE and isinstance(src.ref.type, PointerType): + if dest == REG_A and isinstance(src.ref.type, PointerType): + src_label = self.labels[src.ref.name] + self.emitter.emit(LDA(IndirectY(src_label))) + elif dest.type == TYPE_BYTE and isinstance(src.ref.type, PointerType): src_label = self.labels[src.ref.name] dest_label = self.labels[dest.name] self.emitter.emit(LDA(IndirectY(src_label))) diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 9382fb9..91fedfa 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -1005,7 +1005,7 @@ Write stored value through a pointer. = $081A STA ($FE),Y = $081C RTS -Read through a pointer. +Read through a pointer, into a byte storage location, or the `a` register. | buffer[2048] buf | pointer ptr @ 254 @@ -1019,15 +1019,17 @@ Read through a pointer. | ld y, 0 | copy ^buf, ptr | copy [ptr] + y, foo + | copy [ptr] + y, a | } = $080D LDY #$00 - = $080F LDA #$1D + = $080F LDA #$1F = $0811 STA $FE = $0813 LDA #$08 = $0815 STA $FF = $0817 LDA ($FE),Y - = $0819 STA $101D - = $081C RTS + = $0819 STA $101F + = $081C LDA ($FE),Y + = $081E RTS Add a word memory location, and a literal word, to a pointer, and then read through it. Note that this is *not* range-checked. (Yet.)