diff --git a/HISTORY.markdown b/HISTORY.markdown index fee3cf2..e15ca92 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -6,6 +6,7 @@ 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). * Implementation: `--debug` shows some extra info during analysis. * Fixed bug where `copy`ing literal word into word storage used wrong endianness. diff --git a/README.markdown b/README.markdown index 4081ba8..7ab3fb5 100644 --- a/README.markdown +++ b/README.markdown @@ -47,7 +47,7 @@ Compare word (constant or memory location) with memory location or pointer. (Ma And then write a little demo "game" where you can move a block around the screen with the joystick. -### `word table` and `vector table` types +### `vector table` type ### `low` and `high` address operators @@ -55,7 +55,7 @@ To turn `word` type into `byte`. ### save registers on stack -This preserves them, so semantically, they can be used even though they +This preserves them, so that, semantically, they can be used later even though they are trashed inside the block. ### And at some point... diff --git a/eg/word-table.60p b/eg/word-table.60p new file mode 100644 index 0000000..2de788d --- /dev/null +++ b/eg/word-table.60p @@ -0,0 +1,13 @@ +word one +word table many + +routine main + inputs one, many + outputs one, many + trashes a, x, n, z +{ + ld x, 0 + copy 777, one + copy one, many + x + copy many + x, one +} diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index b3bb354..fa633fc 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -2,8 +2,8 @@ from sixtypical.ast import Program, Routine, Block, Instr from sixtypical.model import ( - ConstantRef, LocationRef, IndirectRef, AddressRef, - TYPE_BIT, TYPE_BYTE, TYPE_WORD, BufferType, PointerType, RoutineType, VectorType, + ConstantRef, LocationRef, IndexedRef, IndirectRef, AddressRef, + TYPE_BIT, TYPE_BYTE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType, REG_A, REG_X, REG_Y, FLAG_C ) from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte @@ -169,7 +169,7 @@ class Compiler(object): raise UnsupportedOpcodeError(instr) elif isinstance(dest, LocationRef) and src.type == TYPE_WORD and isinstance(dest.type, PointerType): if isinstance(src, ConstantRef): - dest_label = self.labels[dest.name] # this. is. zero-page. + dest_label = self.labels[dest.name] self.emitter.emit(LDA(ZeroPage(dest_label))) self.emitter.emit(ADC(Immediate(Byte(src.low_byte())))) self.emitter.emit(STA(ZeroPage(dest_label))) @@ -178,7 +178,7 @@ class Compiler(object): self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1)))) elif isinstance(src, LocationRef): src_label = self.labels[src.name] - dest_label = self.labels[dest.name] # this. is. zero-page. + dest_label = self.labels[dest.name] self.emitter.emit(LDA(ZeroPage(dest_label))) self.emitter.emit(ADC(Absolute(src_label))) self.emitter.emit(STA(ZeroPage(dest_label))) @@ -345,6 +345,17 @@ class Compiler(object): self.emitter.emit(STA(ZeroPage(dest_label))) self.emitter.emit(LDA(Immediate(LowAddressByte(src_label)))) self.emitter.emit(STA(ZeroPage(Offset(dest_label, 1)))) + elif isinstance(src, LocationRef) and isinstance(dest, IndexedRef): + if src.type == TYPE_WORD and dest.ref.type == TYPE_WORD_TABLE: + src_label = self.labels[src.name] + dest_label = self.labels[dest.ref.name] + raise NotImplementedError("""\ +What we will need to do here, is to have TWO 'labels' per name, one for the high byte table, +and one for the low byte table. Then select AbsoluteX() or AbsoluteY() addressing on those +tables. And use that in the STA() part.""") + else: + raise NotImplementedError + elif not isinstance(src, (ConstantRef, LocationRef)) or not isinstance(dest, LocationRef): raise NotImplementedError((src, dest)) elif src.type == TYPE_BYTE and dest.type == TYPE_BYTE: diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index b9956d6..0a74c82 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -316,6 +316,23 @@ Copy routine to vector, inside an `interrupts off` block. | } = 00c078a90d8d0fc0a9c08d10c05860e860 +Copy word to word table and back. + + | word one + | word table many + | + | routine main + | inputs one, many + | outputs one, many + | trashes a, x, n, z + | { + | ld x, 0 + | copy 777, one + | copy one, many + x + | copy many + x, one + | } + = 00c0a200a9009d0dc0bd0dc060.... + Indirect call. | vector foo outputs x trashes z, n