fix assignment of register into byte array

This commit is contained in:
Irmen de Jong 2023-07-28 22:08:33 +02:00
parent 4a8ee6815a
commit c5219dfb3f
2 changed files with 38 additions and 46 deletions

View File

@ -2489,9 +2489,20 @@ internal class AssignmentAsmGen(private val program: PtProgram,
TODO("assign register as word into Array not yet supported")
if (target.constArrayIndexValue!=null) {
when (register) {
CpuRegister.A -> asmgen.out(" sta ${target.asmVarname}+${target.constArrayIndexValue}")
CpuRegister.X -> asmgen.out(" stx ${target.asmVarname}+${target.constArrayIndexValue}")
CpuRegister.Y -> asmgen.out(" sty ${target.asmVarname}+${target.constArrayIndexValue}")
CpuRegister.A -> {}
CpuRegister.X -> asmgen.out(" txa")
CpuRegister.Y -> asmgen.out(" tya")
}
if(asmgen.isZpVar(target.origAstTarget!!.array!!.variable)) {
asmgen.out(" ldy #${target.constArrayIndexValue} | sta (${target.asmVarname}),y")
} else {
asmgen.out("""
ldy ${target.asmVarname}
sty P8ZP_SCRATCH_W1
ldy ${target.asmVarname}+1
sty P8ZP_SCRATCH_W1+1
ldy #${target.constArrayIndexValue}
sta (P8ZP_SCRATCH_W1),y""")
}
}
else {
@ -2501,7 +2512,17 @@ internal class AssignmentAsmGen(private val program: PtProgram,
CpuRegister.Y -> asmgen.out(" tya")
}
val indexVar = target.array!!.index as PtIdentifier
asmgen.out(" ldy ${asmgen.asmVariableName(indexVar)} | sta ${target.asmVarname},y")
if(asmgen.isZpVar(target.origAstTarget!!.array!!.variable)) {
asmgen.out(" ldy ${asmgen.asmVariableName(indexVar)} | sta (${target.asmVarname}),y")
} else {
asmgen.out("""
ldy ${target.asmVarname}
sty P8ZP_SCRATCH_W1
ldy ${target.asmVarname}+1
sty P8ZP_SCRATCH_W1+1
ldy ${asmgen.asmVariableName(indexVar)}
sta (P8ZP_SCRATCH_W1),y""")
}
}
}
TargetStorageKind.REGISTER -> {

View File

@ -1,47 +1,18 @@
%import textio
%import floats
%zeropage basicsafe
%zeropage dontuse
main {
const uword width = 60
const uword height = 50
const ubyte max_iter = 16
sub start() {
uword pointer = $4000
ubyte index = $e3
@($40e2) = 69
; cx16.r0L = pointer[index-1]
sub start() {
txt.print("calculating mandelbrot fractal...\n\n")
cbm.SETTIM(0,0,0)
ubyte pixelx
ubyte pixely
for pixely in 0 to height-1 {
float yy = (pixely as float)/0.40/height - 1.3
for pixelx in 0 to width-1 {
float xx = (pixelx as float)/0.32/width - 2.2
float xsquared = 0.0
float ysquared = 0.0
float x = 0.0
float y = 0.0
ubyte iter = 0
while iter<max_iter and xsquared+ysquared<4.0 {
y = x*y*2.0 + yy
x = xsquared - ysquared + xx
xsquared = x*x
ysquared = y*y
iter++
}
txt.color2(1, max_iter-iter)
txt.spc()
}
txt.nl()
}
float duration = (cbm.RDTIM16() as float) / 60
txt.print("\nfinished in ")
floats.print_f(duration)
txt.print(" seconds!\n")
}
;cx16.r0L=69
;pointer[16] = cx16.r0L
ubyte targetindex=16
pointer[targetindex] = pointer[index-1]
pointer[16] = pointer[index-1]
txt.print_ub(@($4010)) ; expected: 69
}
}