From 19a196f765d3dcd4603cfb83cffc1d6abc1c3f39 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Fri, 24 Nov 2017 16:56:55 +0000 Subject: [PATCH] Compile copy[]+y. --- eg/buffer.60p | 2 +- src/sixtypical/compiler.py | 10 ++++++++++ src/sixtypical/gen6502.py | 12 ++---------- tests/SixtyPical Compilation.md | 17 ++++++++++++++++- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/eg/buffer.60p b/eg/buffer.60p index 84cb784..5b63103 100644 --- a/eg/buffer.60p +++ b/eg/buffer.60p @@ -8,5 +8,5 @@ routine main { ld y, 0 copy buf, ptr - // copy 123, [ptr] + y + copy 123, [ptr] + y } diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index a649b29..192f81f 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -322,5 +322,15 @@ class Compiler(object): self.emitter.emit(STA(Absolute(Offset(dest_label, 1)))) else: raise NotImplementedError(src.type) + elif opcode == 'copy[]+y': + if src.type == TYPE_BYTE and isinstance(dest.type, PointerType): + if isinstance(src, ConstantRef): + dest_label = self.labels[dest.name] + self.emitter.emit(LDA(Immediate(Byte(src.value)))) + self.emitter.emit(STA(IndirectY(dest_label))) + else: + raise NotImplementedError((src.type, dest.type)) + else: + raise NotImplementedError((src.type, dest.type)) else: raise NotImplementedError(opcode) diff --git a/src/sixtypical/gen6502.py b/src/sixtypical/gen6502.py index b72471e..8659ab6 100644 --- a/src/sixtypical/gen6502.py +++ b/src/sixtypical/gen6502.py @@ -82,16 +82,8 @@ class Indirect(AddressingMode): return self.value.serialize() -class IndirectY(AddressingMode): - def __init__(self, value): - assert isinstance(value, Label) - self.value = value - - def size(self): - return 1 - - def serialize(self, addr=None): - return self.value.serialize() +class IndirectY(ZeroPage): + pass class Relative(AddressingMode): diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index b001f53..5e2df28 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -354,6 +354,21 @@ Buffers and pointers. | { | ld y, 0 | copy buf, ptr - | // copy 123, [ptr] + y | } = 00c0a000a90b85fea9c085ff60 + +Writing through a pointer. + + | buffer[2048] buf + | pointer ptr @ 254 + | + | routine main + | inputs buf + | outputs buf, y + | trashes a, z, n, ptr + | { + | ld y, 0 + | copy buf, ptr + | copy 123, [ptr] + y + | } + = 00c0a000a90f85fea9c085ffa97b91fe60