fix direcetmemoryread invalid asm

This commit is contained in:
Irmen de Jong 2020-03-26 22:46:05 +01:00
parent 22f8f4f359
commit 152888ee93
4 changed files with 17 additions and 14 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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")
}