fix array assignment stack error

This commit is contained in:
Irmen de Jong 2019-01-06 15:53:01 +01:00
parent c2c1b43714
commit 214b100f96
4 changed files with 47 additions and 28 deletions

View File

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

View File

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

View File

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

View File

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