mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
fix assignment of register into byte array
This commit is contained in:
parent
4a8ee6815a
commit
c5219dfb3f
@ -2489,9 +2489,20 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
TODO("assign register as word into Array not yet supported")
|
TODO("assign register as word into Array not yet supported")
|
||||||
if (target.constArrayIndexValue!=null) {
|
if (target.constArrayIndexValue!=null) {
|
||||||
when (register) {
|
when (register) {
|
||||||
CpuRegister.A -> asmgen.out(" sta ${target.asmVarname}+${target.constArrayIndexValue}")
|
CpuRegister.A -> {}
|
||||||
CpuRegister.X -> asmgen.out(" stx ${target.asmVarname}+${target.constArrayIndexValue}")
|
CpuRegister.X -> asmgen.out(" txa")
|
||||||
CpuRegister.Y -> asmgen.out(" sty ${target.asmVarname}+${target.constArrayIndexValue}")
|
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 {
|
else {
|
||||||
@ -2501,7 +2512,17 @@ internal class AssignmentAsmGen(private val program: PtProgram,
|
|||||||
CpuRegister.Y -> asmgen.out(" tya")
|
CpuRegister.Y -> asmgen.out(" tya")
|
||||||
}
|
}
|
||||||
val indexVar = target.array!!.index as PtIdentifier
|
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 -> {
|
TargetStorageKind.REGISTER -> {
|
||||||
|
@ -1,47 +1,18 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import floats
|
%zeropage dontuse
|
||||||
%zeropage basicsafe
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
const uword width = 60
|
sub start() {
|
||||||
const uword height = 50
|
uword pointer = $4000
|
||||||
const ubyte max_iter = 16
|
ubyte index = $e3
|
||||||
|
@($40e2) = 69
|
||||||
|
; cx16.r0L = pointer[index-1]
|
||||||
|
|
||||||
sub start() {
|
;cx16.r0L=69
|
||||||
txt.print("calculating mandelbrot fractal...\n\n")
|
;pointer[16] = cx16.r0L
|
||||||
cbm.SETTIM(0,0,0)
|
ubyte targetindex=16
|
||||||
|
pointer[targetindex] = pointer[index-1]
|
||||||
ubyte pixelx
|
pointer[16] = pointer[index-1]
|
||||||
ubyte pixely
|
txt.print_ub(@($4010)) ; expected: 69
|
||||||
|
}
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user