diff --git a/HISTORY.markdown b/HISTORY.markdown index fefecd8..4675caa 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -1,6 +1,11 @@ History of SixtyPical ===================== +0.9 +--- + +* Add word (constant or memory location) to word memory location. + 0.8 --- diff --git a/README.markdown b/README.markdown index 175c5e1..6092815 100644 --- a/README.markdown +++ b/README.markdown @@ -40,11 +40,11 @@ Documentation TODO ---- -### Add 16 bit values. +### Operations on 16 bit values -I guess this means making `add` a bit more like `copy`. +Add word (constant or memory location) to pointer. (Not necessarily range-checked yet though.) -And then: add to pointer. (Not necessarily range-checked yet though.) +Compare word (constant or memory location) with memory location or pointer. (Maybe?) And then write a little demo "game" where you can move a block around the screen with the joystick. diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 3fd78e3..0f98d5a 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -147,14 +147,26 @@ class Compiler(object): self.emitter.emit(ADC(Immediate(Byte(src.value)))) else: self.emitter.emit(ADC(Absolute(self.labels[src.name]))) - elif isinstance(src, ConstantRef) and isinstance(dest, LocationRef) and dest.type == TYPE_WORD: - dest_label = self.labels[dest.name] - self.emitter.emit(LDA(Absolute(dest_label))) - self.emitter.emit(ADC(Immediate(Byte(src.low_byte())))) - self.emitter.emit(STA(Absolute(dest_label))) - self.emitter.emit(LDA(Absolute(Offset(dest_label, 1)))) - self.emitter.emit(ADC(Immediate(Byte(src.high_byte())))) - self.emitter.emit(STA(Absolute(Offset(dest_label, 1)))) + elif isinstance(dest, LocationRef) and dest.type == TYPE_WORD and src.type == TYPE_WORD: + if isinstance(src, ConstantRef): + dest_label = self.labels[dest.name] + self.emitter.emit(LDA(Absolute(dest_label))) + self.emitter.emit(ADC(Immediate(Byte(src.low_byte())))) + self.emitter.emit(STA(Absolute(dest_label))) + self.emitter.emit(LDA(Absolute(Offset(dest_label, 1)))) + self.emitter.emit(ADC(Immediate(Byte(src.high_byte())))) + self.emitter.emit(STA(Absolute(Offset(dest_label, 1)))) + elif isinstance(src, LocationRef): + src_label = self.labels[src.name] + dest_label = self.labels[dest.name] + self.emitter.emit(LDA(Absolute(dest_label))) + self.emitter.emit(ADC(Absolute(src_label))) + self.emitter.emit(STA(Absolute(dest_label))) + self.emitter.emit(LDA(Absolute(Offset(dest_label, 1)))) + self.emitter.emit(ADC(Absolute(Offset(src_label, 1)))) + self.emitter.emit(STA(Absolute(Offset(dest_label, 1)))) + else: + raise UnsupportedOpcodeError(instr) else: raise UnsupportedOpcodeError(instr) elif opcode == 'sub': diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index c1afc13..e6813b5 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -412,6 +412,34 @@ To be sure, `add`ing a word constant to a word memory location trashes `a`. | } ? ForbiddenWriteError: a in main +You can `add` a word memory location to another word memory location. + + | word score + | word delta + | routine main + | inputs score, delta + | outputs score + | trashes a, c, z, v, n + | { + | st off, c + | add score, delta + | } + = ok + +`add`ing a word memory location to a word memory location trashes `a`. + + | word score + | word delta + | routine main + | inputs score, delta + | outputs score + | trashes c, z, v, n + | { + | st off, c + | add score, delta + | } + ? ForbiddenWriteError: a in main + ### sub ### Can't `sub` from or to a memory location that isn't initialized. diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index a9405b0..87d7378 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -344,11 +344,11 @@ goto. ### word operations -Adding a constant word to a memory location. +Adding a constant word to a word memory location. | word score | routine main - | inputs a, score + | inputs score | outputs score | trashes a, c, z, v, n | { @@ -357,6 +357,20 @@ Adding a constant word to a memory location. | } = 00c018ad12c069cf8d12c0ad13c069078d13c060 +Adding a word memory location to another word memory location. + + | word score + | word delta + | routine main + | inputs score, delta + | outputs score + | trashes a, c, z, v, n + | { + | st off, c + | add score, delta + | } + = 00c018ad14c06d16c08d14c0ad15c06d17c08d15c060 + ### Buffers and Pointers Load address into pointer.