From 2216fcec17b847cec006e6656652a648a52494c5 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Mon, 11 Dec 2017 12:02:48 +0000 Subject: [PATCH] copy from word storage to word table and back, indexed by x or y. --- HISTORY.markdown | 3 ++- eg/word-table.60p | 7 ++++-- src/sixtypical/compiler.py | 21 ++++++++++++++++-- tests/SixtyPical Compilation.md | 39 +++++++++++++++++++++++---------- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/HISTORY.markdown b/HISTORY.markdown index 43faac7..81dd7c0 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -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. diff --git a/eg/word-table.60p b/eg/word-table.60p index 3b22900..a0dc978 100644 --- a/eg/word-table.60p +++ b/eg/word-table.60p @@ -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 } diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 01727b6..8ac674a 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -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 diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 32e86d6..c84b1b3 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -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.