From ad8e0647a43ba5310237015b0d56db184f0eb545 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Thu, 7 Dec 2017 16:49:43 +0000 Subject: [PATCH] Use right endianness when `copy`ing literal word into storage. --- HISTORY.markdown | 1 + eg/proto-game.60p | 3 ++- loadngo.sh | 6 +++++- src/sixtypical/compiler.py | 4 ++-- tests/SixtyPical Compilation.md | 6 +++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/HISTORY.markdown b/HISTORY.markdown index 1b7104d..fee3cf2 100644 --- a/HISTORY.markdown +++ b/HISTORY.markdown @@ -7,6 +7,7 @@ History of SixtyPical * Add word (constant or memory location) to word memory location. * Add word to pointer (unchecked for now). * Implementation: `--debug` shows some extra info during analysis. +* Fixed bug where `copy`ing literal word into word storage used wrong endianness. 0.8 --- diff --git a/eg/proto-game.60p b/eg/proto-game.60p index 20202c9..228f926 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -83,9 +83,10 @@ routine our_cinv routine main inputs cinv - outputs cinv, save_cinv + outputs cinv, save_cinv, pos trashes a, n, z { + copy word 0, pos with interrupts off { copy cinv, save_cinv copy our_cinv, cinv diff --git a/loadngo.sh b/loadngo.sh index ed2a1bb..65413e2 100755 --- a/loadngo.sh +++ b/loadngo.sh @@ -3,5 +3,9 @@ SRC=$1 OUT=/tmp/a-out.prg bin/sixtypical --analyze --compile --basic-prelude $SRC > $OUT || exit 1 -x64 $OUT +if [ -e vicerc ]; then + x64 -config vicerc $OUT +else + x64 $OUT +fi rm -f $OUT diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index ecb1f5b..b3bb354 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -358,9 +358,9 @@ class Compiler(object): elif src.type == TYPE_WORD and dest.type == TYPE_WORD: if isinstance(src, ConstantRef): dest_label = self.labels[dest.name] - self.emitter.emit(LDA(Immediate(Byte(src.high_byte())))) - self.emitter.emit(STA(Absolute(dest_label))) self.emitter.emit(LDA(Immediate(Byte(src.low_byte())))) + self.emitter.emit(STA(Absolute(dest_label))) + self.emitter.emit(LDA(Immediate(Byte(src.high_byte())))) self.emitter.emit(STA(Absolute(Offset(dest_label, 1)))) else: src_label = self.labels[src.name] diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 936fd4f..b9956d6 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -275,9 +275,9 @@ Copy literal word to word. | outputs bar | trashes a, n, z | { - | copy 65535, bar + | copy 2000, bar | } - = 00c0a9ff8d0bc0a9ff8d0cc060 + = 00c0a9d08d0bc0a9078d0cc060 Copy vector to vector. @@ -458,4 +458,4 @@ Note that this is *not* range-checked. (Yet.) | add ptr, word 1 | copy [ptr] + y, foo | } - = 00c0a9028d38c0a96b8d39c0a000a93485fea9c085ffa5fe6d38c085fea5ff6d39c085ffa5fe690185fea5ff690085ffb1fe8d36c060 + = 00c0a96b8d38c0a9028d39c0a000a93485fea9c085ffa5fe6d38c085fea5ff6d39c085ffa5fe690185fea5ff690085ffb1fe8d36c060