From 214b100f9645d35f4424953d4ed8a98664cc9c59 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 6 Jan 2019 15:53:01 +0100 Subject: [PATCH] fix array assignment stack error --- compiler/examples/cube3d-c64-float.p8 | 15 ++++--- compiler/examples/cube3d-c64.p8 | 45 +++++++++++-------- .../src/prog8/compiler/target/c64/AsmGen.kt | 5 ++- prog8lib/c64utils.p8 | 10 +++++ 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/compiler/examples/cube3d-c64-float.p8 b/compiler/examples/cube3d-c64-float.p8 index 4f378bb9c..d4acc1199 100644 --- a/compiler/examples/cube3d-c64-float.p8 +++ b/compiler/examples/cube3d-c64-float.p8 @@ -21,9 +21,13 @@ while(true) { rotate_vertices(time) c64scr.clear_screenchars(32) - c64scr.print("\uf1203d cube! (using floating point)") draw_edges() time+=0.2 + c64.PLOT(0,0,0) + c64scr.print("3d cube! (float) ") + c64scr.print_ub(c64.TIME_LO) + c64scr.print(" jiffies/frame") + c64.TIME_LO=0 } } @@ -51,12 +55,9 @@ float Azz = cosb*cosc for ubyte i in 0 to len(xcoor)-1 { - float xc = xcoor[i] - float yc = ycoor[i] - float zc = zcoor[i] - rotatedx[i] = Axx*xc + Axy*yc + Axz*zc - rotatedy[i] = Ayx*xc + Ayy*yc + Ayz*zc - rotatedz[i] = Azx*xc + Azy*yc + Azz*zc + rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i] + rotatedy[i] = Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i] + rotatedz[i] = Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i] } } diff --git a/compiler/examples/cube3d-c64.p8 b/compiler/examples/cube3d-c64.p8 index a6e0ac521..765a0bad6 100644 --- a/compiler/examples/cube3d-c64.p8 +++ b/compiler/examples/cube3d-c64.p8 @@ -5,7 +5,6 @@ const uword width = 40 const uword height = 25 - const float height_f = height ; vertices byte[8] xcoor = [ -40, -40, -40, -40, 40, 40, 40, 40 ] @@ -24,11 +23,15 @@ while(true) { rotate_vertices(msb(anglex), msb(angley), msb(anglez)) c64scr.clear_screenchars(32) - c64scr.print("\uf1203d cube!") draw_edges() anglex+=1000 angley+=433 anglez+=907 + c64.PLOT(0,0,0) + c64scr.print("3d cube! (integer) ") + c64scr.print_ub(c64.TIME_LO) + c64scr.print(" jiffies/frame") + c64.TIME_LO=0 } } @@ -46,26 +49,20 @@ word wcosa_sinb = wcosa*wsinb // 128 word wsina_sinb = wsina*wsinb // 128 - word Axx = (wcosa*wcosb as float / 128.0) as word - word Axy = ((wcosa_sinb*wsinc - wsina*wcosc) as float / 128.0) as word - word Axz = ((wcosa_sinb*wcosc + wsina*wsinc) as float / 128.0) as word - word Ayx = (wsina*wcosb as float / 128.0) as word - word Ayy = ((wsina_sinb*wsinc + wcosa*wcosc) as float / 128.0) as word - word Ayz = ((wsina_sinb*wcosc - wcosa*wsinc) as float / 128.0) as word + word Axx = wcosa*wcosb // 128 + word Axy = (wcosa_sinb*wsinc - wsina*wcosc) // 128 + word Axz = (wcosa_sinb*wcosc + wsina*wsinc) // 128 + word Ayx = wsina*wcosb // 128 + word Ayy = (wsina_sinb*wsinc + wcosa*wcosc) // 128 + word Ayz = (wsina_sinb*wcosc - wcosa*wsinc) // 128 word Azx = -wsinb - word Azy = (wcosb*wsinc as float / 128.0) as word - word Azz = (wcosb*wcosc as float / 128.0) as word + word Azy = wcosb*wsinc // 128 + word Azz = wcosb*wcosc // 128 for ubyte i in 0 to len(xcoor)-1 { - word xc = xcoor[i] as word - word yc = ycoor[i] as word - word zc = zcoor[i] as word - word zz = (Axx*xc + Axy*yc + Axz*zc) // 128 ; @todo bugs when not using 'zz' temporary var!? - rotatedx[i] = zz - zz=(Ayx*xc + Ayy*yc + Ayz*zc) // 128 - rotatedy[i] = zz - zz = (Azx*xc + Azy*yc + Azz*zc) // 128 - rotatedz[i] = zz + rotatedx[i] = (Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]) // 128 + rotatedy[i] =(Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]) // 128 + rotatedz[i] = (Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i]) // 128 } } @@ -77,9 +74,14 @@ for ubyte i in 0 to len(xcoor)-1 { word rz = rotatedz[i] if rz >= 10 { + const float height_f = height float persp = (rz as float + 180.0)/height_f byte sx = rotatedx[i] as float / persp as byte + width//2 byte sy = rotatedy[i] as float / persp as byte + height//2 + ; @todo switch to this once idiv_w is implemented: (and remove c64flt import) + ;word persp = (rz+180) // height + ;byte sx = rotatedx[i] // persp as byte + width//2 + ;byte sy = rotatedy[i] // persp as byte + height//2 c64scr.setchrclr(sx as ubyte, sy as ubyte, 46, i+2) } } @@ -87,9 +89,14 @@ for ubyte i in 0 to len(xcoor)-1 { word rz = rotatedz[i] if rz < 10 { + const float height_f = height float persp = (rz as float + 180.0)/height_f byte sx = rotatedx[i] as float / persp as byte + width//2 byte sy = rotatedy[i] as float / persp as byte + height//2 + ; @todo switch to this once idiv_w is implemented: (and remove c64flt import) + ;word persp = (rz+180) // height + ;byte sx = rotatedx[i] // persp as byte + width//2 + ;byte sy = rotatedy[i] // persp as byte + height//2 c64scr.setchrclr(sx as ubyte, sy as ubyte, 81, i+2) } } diff --git a/compiler/src/prog8/compiler/target/c64/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/AsmGen.kt index d918eea4d..9dfd7faeb 100644 --- a/compiler/src/prog8/compiler/target/c64/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/AsmGen.kt @@ -582,9 +582,10 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram, lda ${ESTACK_LO.toHex()},x asl a tay - lda ${(ESTACK_LO-1).toHex()},x + inx + lda ${ESTACK_LO.toHex()},x sta ${ins.callLabel},y - lda ${(ESTACK_HI-1).toHex()},x + lda ${ESTACK_HI.toHex()},x sta ${ins.callLabel}+1,y """ } diff --git a/prog8lib/c64utils.p8 b/prog8lib/c64utils.p8 index 01969abe5..25a139b99 100644 --- a/prog8lib/c64utils.p8 +++ b/prog8lib/c64utils.p8 @@ -560,9 +560,14 @@ asmsub clear_screenchars (ubyte char @ A) -> clobbers(Y) -> () { %asm {{ ldy #0 _loop sta c64.Screen,y + sta c64.Screen+1,y sta c64.Screen+$0100,y + sta c64.Screen+$0101,y sta c64.Screen+$0200,y + sta c64.Screen+$0201,y sta c64.Screen+$02e8,y + sta c64.Screen+$02e9,y + iny iny bne _loop rts @@ -575,9 +580,14 @@ asmsub clear_screencolors (ubyte color @ A) -> clobbers(Y) -> () { %asm {{ ldy #0 _loop sta c64.Colors,y + sta c64.Colors+1,y sta c64.Colors+$0100,y + sta c64.Colors+$0101,y sta c64.Colors+$0200,y + sta c64.Colors+$0201,y sta c64.Colors+$02e8,y + sta c64.Colors+$02e9,y + iny iny bne _loop rts