diff --git a/compiler/res/prog8lib/prog8lib.asm b/compiler/res/prog8lib/prog8lib.asm index bbe67c02b..06c194880 100644 --- a/compiler/res/prog8lib/prog8lib.asm +++ b/compiler/res/prog8lib/prog8lib.asm @@ -1772,6 +1772,7 @@ _loop_hi ldy _index_first ror2_mem_ub .proc ; -- in-place 8-bit ror of byte at memory location on stack + ; TODO use self modifying code here inx lda c64.ESTACK_LO,x sta c64.SCRATCH_ZPWORD1 @@ -1788,7 +1789,7 @@ ror2_mem_ub .proc rol2_mem_ub .proc ; -- in-place 8-bit rol of byte at memory location on stack - ;" lda ${number.toHex()} | cmp #\$80 | rol a | sta ${number.toHex()}" + ; TODO use self modifying code here inx lda c64.ESTACK_LO,x sta c64.SCRATCH_ZPWORD1 diff --git a/compiler/src/prog8/compiler/Main.kt b/compiler/src/prog8/compiler/Main.kt index 164904429..f558f578f 100644 --- a/compiler/src/prog8/compiler/Main.kt +++ b/compiler/src/prog8/compiler/Main.kt @@ -40,6 +40,9 @@ fun compileProgram(filepath: Path, if (optimize) optimizeAst(programAst, errors) postprocessAst(programAst, errors, compilationOptions) + + printAst(programAst) // TODO + if(writeAssembly) programName = writeAssembly(programAst, errors, outputDir, optimize, compilationOptions) } diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt index b447d4373..917e4a2bd 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt @@ -127,8 +127,16 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge asmgen.out(" lda ${address.toHex()} | sta $ESTACK_LO_HEX,x | dex") } is IdentifierReference -> { + // the identifier is a pointer variable, so read the value from the address in it val sourceName = asmgen.asmIdentifierName(expr.addressExpression as IdentifierReference) - asmgen.out(" lda $sourceName | sta $ESTACK_LO_HEX,x | dex") + asmgen.out(""" + lda $sourceName + sta (+) +1 + lda $sourceName+1 + sta (+) +2 ++ lda ${'$'}ffff ; modified + sta $ESTACK_LO_HEX,x + dex""") } else -> { translateExpression(expr.addressExpression) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt index c17f47584..4b17b4790 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt @@ -66,20 +66,11 @@ internal class PostIncrDecrAsmGen(private val program: Program, private val asmg } is IdentifierReference -> { val what = asmgen.asmIdentifierName(addressExpr) - asmgen.out(""" - ldy $what - sty ${C64Zeropage.SCRATCH_W1} - ldy $what+1 - sty ${C64Zeropage.SCRATCH_W1 + 1} - ldy #0 - lda (${C64Zeropage.SCRATCH_W1}),y -""") + asmgen.out(" lda $what | sta (+) +1 | lda $what+1 | sta (+) +2") if(incr) - asmgen.out(" clc | adc #1") + asmgen.out("+\tinc ${'$'}ffff\t; modified") else - asmgen.out(" sec | sbc #1") - - asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") + asmgen.out("+\tdec ${'$'}ffff\t; modified") } else -> throw AssemblyError("weird target type $targetMemory") }