From 58f323c0877c28e686a7161d66001adfc771e748 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 20 Aug 2020 21:48:15 +0200 Subject: [PATCH] implemented missing memory postincrdecr codegen --- .../target/c64/codegen/PostIncrDecrAsmGen.kt | 17 ++++++++++++++++- examples/test.p8 | 19 ++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt index 915bc62a1..ddabe0d0b 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt @@ -7,6 +7,8 @@ import prog8.ast.expressions.NumericLiteralValue import prog8.ast.statements.PostIncrDecr import prog8.compiler.AssemblyError import prog8.compiler.target.c64.C64MachineDefinition.C64Zeropage +import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_HI_HEX +import prog8.compiler.target.c64.C64MachineDefinition.ESTACK_LO_HEX import prog8.compiler.toHex @@ -53,7 +55,20 @@ internal class PostIncrDecrAsmGen(private val program: Program, private val asmg else asmgen.out("+\tdec ${'$'}ffff\t; modified") } - else -> TODO("asmgen postincrdecr on memory expression") + else -> { + asmgen.translateExpression(addressExpr) + asmgen.out(""" + inx + lda $ESTACK_LO_HEX,x + sta (+) + 1 + lda $ESTACK_HI_HEX,x + sta (+) + 2 + """) + if(incr) + asmgen.out("+\tinc ${'$'}ffff\t; modified") + else + asmgen.out("+\tdec ${'$'}ffff\t; modified") + } } } targetArrayIdx!=null -> { diff --git a/examples/test.p8 b/examples/test.p8 index f44b7efc6..631dfd690 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -8,20 +8,17 @@ main { sub start() { ;@($d020) += @($d020) ; TODO fix compiler hang - ;@($c000+A) ++ ; TODO implement this - uword addr = $c000 - @(addr) = $f1 - c64scr.print_ubhex(@(addr), true) + ubyte A = 10 + @($c00a) = $4a + @($c000+A) ++ ; TODO implement this + + c64scr.print_ubhex(@($c00a), true) c64.CHROUT('\n') - @(addr) = - @(addr) - c64scr.print_ubhex(@(addr), true) - c64.CHROUT('\n') - @(addr) = - @(addr) - c64scr.print_ubhex(@(addr), true) + @($c000+A) -- ; TODO implement this + + c64scr.print_ubhex(@($c00a), true) c64.CHROUT('\n') - ;@($c000) = ! @($c000) - ;@($c000) = ~ @($c000) } }