mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 22:30:46 +00:00
fixed array lookup and cube3d c64 example
This commit is contained in:
parent
9ee1628901
commit
b69697c3dd
@ -7,33 +7,25 @@
|
||||
const uword height = 25
|
||||
|
||||
; vertices
|
||||
float[8] xcoor = [ -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 2.0 ]
|
||||
float[8] ycoor = [ -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 3.0 ]
|
||||
float[8] zcoor = [ -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 4.0 ]
|
||||
float[8] xcoor = [ -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0 ]
|
||||
float[8] ycoor = [ -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0 ]
|
||||
float[8] zcoor = [ -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ]
|
||||
|
||||
; edges (msb=from vertex, lsb=to vertex)
|
||||
uword[12] edges = [$0001, $0103, $0302, $0200, $0405, $0507, $0706, $0604, $0004, $0105, $0206, $0307]
|
||||
|
||||
; storage for rotated coordinates
|
||||
float[len(xcoor)] rotatedx
|
||||
float[len(ycoor)] rotatedy
|
||||
float[len(zcoor)] rotatedz
|
||||
float[len(xcoor)] rotatedx=0.0
|
||||
float[len(ycoor)] rotatedy=0.0
|
||||
float[len(zcoor)] rotatedz=-1.0
|
||||
|
||||
sub start() {
|
||||
float time=0.0
|
||||
while true {
|
||||
c64scr.print("stack1 ")
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
rotate_vertices(time)
|
||||
; c64scr.print("stack2 ")
|
||||
; c64scr.print_ub(X)
|
||||
; c64.CHROUT('\n')
|
||||
; draw_edges()
|
||||
c64scr.print("stack3 ")
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
time += 0.1
|
||||
c64.CLEARSCR()
|
||||
draw_edges()
|
||||
time += 0.2
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,62 +33,30 @@
|
||||
; rotate around origin (0,0,0)
|
||||
|
||||
; set up the 3d rotation matrix values
|
||||
; float cosa = cos(t)
|
||||
; float sina = sin(t)
|
||||
; float cosb = cos(t*0.33)
|
||||
; float sinb = sin(t*0.33)
|
||||
; float cosc = cos(t*0.78)
|
||||
; float sinc = sin(t*0.78)
|
||||
;
|
||||
; float Axx = cosa*cosb
|
||||
; float Axy = cosa*sinb*sinc - sina*cosc
|
||||
; float Axz = cosa*sinb*cosc + sina*sinc
|
||||
; float Ayx = sina*cosb
|
||||
; float Ayy = sina*sinb*sinc + cosa*cosc
|
||||
; float Ayz = sina*sinb*cosc - cosa*sinc
|
||||
; float Azx = -sinb
|
||||
; float Azy = cosb*sinc
|
||||
; float Azz = cosb*cosc
|
||||
float cosa = cos(t)
|
||||
float sina = sin(t)
|
||||
float cosb = cos(t*0.33)
|
||||
float sinb = sin(t*0.33)
|
||||
float cosc = cos(t*0.78)
|
||||
float sinc = sin(t*0.78)
|
||||
|
||||
float Axx = cosa*cosb
|
||||
float Axy = cosa*sinb*sinc - sina*cosc
|
||||
float Axz = cosa*sinb*cosc + sina*sinc
|
||||
float Ayx = sina*cosb
|
||||
float Ayy = sina*sinb*sinc + cosa*cosc
|
||||
float Ayz = sina*sinb*cosc - cosa*sinc
|
||||
float Azx = -sinb
|
||||
float Azy = cosb*sinc
|
||||
float Azz = cosb*cosc
|
||||
|
||||
for ubyte i in 0 to len(xcoor)-1 {
|
||||
float xc = xcoor[i]
|
||||
c64scr.print("i=")
|
||||
c64scr.print_ub(i)
|
||||
c64scr.print(" xc=")
|
||||
c64flt.print_f(xc)
|
||||
c64.CHROUT('\n')
|
||||
float yc = ycoor[i]
|
||||
c64scr.print("i=")
|
||||
c64scr.print_ub(i)
|
||||
c64scr.print(" yc=")
|
||||
c64flt.print_f(yc)
|
||||
c64.CHROUT('\n')
|
||||
float zc = zcoor[i]
|
||||
c64scr.print("i=")
|
||||
c64scr.print_ub(i)
|
||||
c64scr.print(" zc=")
|
||||
c64flt.print_f(zc)
|
||||
c64.CHROUT('\n')
|
||||
%breakpoint
|
||||
|
||||
; @todo the calculations below destroy the contents of the coor[] arrays???
|
||||
; float rx=Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
|
||||
; float ry=Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]
|
||||
; float rz=Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i]
|
||||
; c64scr.print(" rx=")
|
||||
; c64flt.print_f(rx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print(" ry=")
|
||||
; c64flt.print_f(rx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print(" rz=")
|
||||
; c64flt.print_f(rx)
|
||||
; c64.CHROUT('\n')
|
||||
|
||||
|
||||
;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]
|
||||
rotatedx[i] = Axx*xc + Axy*yc + Axz*zc
|
||||
rotatedy[i] = Ayx*xc + Ayy*yc + Ayz*zc
|
||||
rotatedz[i] = Azx*xc + Azy*yc + Azz*zc
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,27 +64,22 @@
|
||||
sub draw_edges() {
|
||||
|
||||
sub toscreenx(float x, float z) -> byte {
|
||||
;return x/(4.2+z) * (height as float) as byte + width // 2
|
||||
c64flt.print_f(x)
|
||||
c64.CHROUT('\n')
|
||||
float fx = (x*8.0 + 20.0)
|
||||
return fx as byte
|
||||
|
||||
return x/(5.0+z) * (height as float) as byte + width // 2
|
||||
}
|
||||
|
||||
sub toscreeny(float y, float z) -> byte {
|
||||
;return y/(4.2+z) * (height as float) as byte + height // 2
|
||||
c64flt.print_f(y)
|
||||
c64.CHROUT('\n')
|
||||
float fy = (y*8.0 + 12.0)
|
||||
return fy as byte
|
||||
return y/(5.0+z) * (height as float) as byte + height // 2
|
||||
}
|
||||
|
||||
; plot the points of the 3d cube
|
||||
for ubyte i in 0 to len(xcoor)-1 {
|
||||
ubyte sx = toscreenx(rotatedx[i], rotatedz[i]) as ubyte
|
||||
ubyte sy = toscreeny(rotatedy[i], rotatedz[i]) as ubyte
|
||||
c64scr.setchrclr(sx, sy, 81, i+2)
|
||||
float rz = rotatedz[i]
|
||||
ubyte sx = toscreenx(rotatedx[i], rz) as ubyte
|
||||
ubyte sy = toscreeny(rotatedy[i], rz) as ubyte
|
||||
if rz < 0.1
|
||||
c64scr.setchrclr(sx, sy, 81, i+2)
|
||||
else
|
||||
c64scr.setchrclr(sx, sy, 46, i+2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,70 +3,34 @@
|
||||
|
||||
~ main {
|
||||
|
||||
; @todo fix floating point number corruption
|
||||
|
||||
byte[10] xbyte = [1,2,3,4,5,6,7,8,9,-110]
|
||||
byte[10] ybyte = [11,22,33,44,55,-66,-77,-88,-99,-110 ]
|
||||
byte[10] zbyte = [1,2,3,4,5,6,7,8,9,-99]
|
||||
|
||||
ubyte[10] xubyte = [1,2,3,4,5,6,77,88,99,111]
|
||||
ubyte[10] yubyte = [11,22,33,44,55,66,77,88,99,111]
|
||||
ubyte[10] zubyte = [1,2,3,4,5,66,7,88,99,111]
|
||||
|
||||
word[10] xword = [1,2,3,4,5,6,7,8,9,-1111]
|
||||
word[10] yword = [11,22,33,44,55,66,77,88,99,-1111 ]
|
||||
word[10] zword = [1,2,3,4,5,6,7,8,9,-9999]
|
||||
|
||||
uword[10] xuword = [1,2,3,4,5,6,7,88,99,1111]
|
||||
uword[10] yuword = [11,22,33,44,55,66,77,88,99,1111 ]
|
||||
uword[10] zuword = [1,2,3,4,5,6,77,88,99,9999]
|
||||
|
||||
float[10] xcoor = [1,2,3,4,5,6,7,8,9.9,11.11 ]
|
||||
float[10] ycoor = [11,22,33,44,55,66,77,88,99.9,111.11 ]
|
||||
float[10] zcoor = [111,222,333,444,555,666,777,888,999.9,1001.11 ]
|
||||
|
||||
sub start() {
|
||||
; c64scr.print("\nxword:\n")
|
||||
; for word w1 in xword {
|
||||
; c64scr.print_w(w1)
|
||||
; c64.CHROUT(',')
|
||||
; }
|
||||
c64scr.print("\nxcoor:\n")
|
||||
for float f1 in xcoor {
|
||||
c64flt.print_f(f1)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
|
||||
; c64scr.print("\nxcoor:\n")
|
||||
; for float f1 in xcoor {
|
||||
; c64flt.print_f(f1)
|
||||
; c64.CHROUT(',')
|
||||
; }
|
||||
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("ycoor:\n")
|
||||
; for float f2 in ycoor {
|
||||
; c64flt.print_f(f2)
|
||||
; c64.CHROUT(',')
|
||||
; }
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("zcoor:\n")
|
||||
; for float f3 in zcoor {
|
||||
; c64flt.print_f(f3)
|
||||
; c64.CHROUT(',')
|
||||
; }
|
||||
; c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("ycoor:\n")
|
||||
for float f2 in ycoor {
|
||||
c64flt.print_f(f2)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("zcoor:\n")
|
||||
for float f3 in zcoor {
|
||||
c64flt.print_f(f3)
|
||||
c64.CHROUT(',')
|
||||
}
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64.CHROUT('X')
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
float avgbx = avg(xbyte)
|
||||
float avgby = avg(ybyte)
|
||||
float avgbz = avg(zbyte)
|
||||
float avgubx = avg(xubyte)
|
||||
float avguby = avg(yubyte)
|
||||
float avgubz = avg(zubyte)
|
||||
float avgwx = avg(xword)
|
||||
float avgwy = avg(yword)
|
||||
float avgwz = avg(zword)
|
||||
float avguwx = avg(xuword)
|
||||
float avguwy = avg(yuword)
|
||||
float avguwz = avg(zuword)
|
||||
float avgfx = avg(xcoor)
|
||||
float avgfy = avg(ycoor)
|
||||
float avgfz = avg(zcoor)
|
||||
@ -74,46 +38,6 @@
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("avgbx=")
|
||||
c64flt.print_f(avgbx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgby=")
|
||||
c64flt.print_f(avgby)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgbz=")
|
||||
c64flt.print_f(avgbz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("avgubx=")
|
||||
c64flt.print_f(avgubx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avguby=")
|
||||
c64flt.print_f(avguby)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgubz=")
|
||||
c64flt.print_f(avgubz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("avgwx=")
|
||||
c64flt.print_f(avgwx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgwy=")
|
||||
c64flt.print_f(avgwy)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgwz=")
|
||||
c64flt.print_f(avgwz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("avguwx=")
|
||||
c64flt.print_f(avguwx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avguwy=")
|
||||
c64flt.print_f(avguwy)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avguwz=")
|
||||
c64flt.print_f(avguwz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("avgfx=")
|
||||
c64flt.print_f(avgfx)
|
||||
c64.CHROUT('\n')
|
||||
@ -124,23 +48,48 @@
|
||||
c64flt.print_f(avgfz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
return
|
||||
|
||||
|
||||
separated2:
|
||||
c64scr.print("\nseparated i=2\n")
|
||||
c64scr.print(" x[2]=")
|
||||
c64flt.print_f(xcoor[2]) ; @todo wrong value printed
|
||||
ubyte ii=2
|
||||
c64flt.print_f(xcoor[ii])
|
||||
|
||||
c64scr.print(" y[2]=")
|
||||
c64flt.print_f(ycoor[2])
|
||||
c64flt.print_f(ycoor[ii])
|
||||
c64scr.print(" z[2]=")
|
||||
c64flt.print_f(zcoor[2])
|
||||
c64flt.print_f(zcoor[ii])
|
||||
|
||||
separated3:
|
||||
c64scr.print("\nseparated i=3\n")
|
||||
ii=3
|
||||
c64scr.print(" x[3]=")
|
||||
c64flt.print_f(xcoor[3])
|
||||
c64flt.print_f(xcoor[ii])
|
||||
c64scr.print(" y[3]=")
|
||||
c64flt.print_f(ycoor[3])
|
||||
c64flt.print_f(ycoor[ii])
|
||||
c64scr.print(" z[3]=")
|
||||
c64flt.print_f(zcoor[3])
|
||||
c64flt.print_f(zcoor[ii])
|
||||
|
||||
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('X')
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
avgfx = avg(xcoor)
|
||||
avgfy = avg(ycoor)
|
||||
avgfz = avg(zcoor)
|
||||
c64.CHROUT('X')
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("avgfx=")
|
||||
c64flt.print_f(avgfx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgfy=")
|
||||
c64flt.print_f(avgfy)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("avgfz=")
|
||||
c64flt.print_f(avgfz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2412,8 +2412,8 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.POP_VAR_FLOAT)) { segment ->
|
||||
val index = intVal(segment[0]) * Mflpt5.MemorySize
|
||||
"""
|
||||
lda ${segment[1].callLabel}+$index
|
||||
ldy ${segment[1].callLabel}+${index+1}
|
||||
lda #<${segment[1].callLabel}+$index
|
||||
ldy #>${segment[1].callLabel}+$index
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
lda #<${segment[2].callLabel}
|
||||
@ -2611,8 +2611,8 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.POP_MEM_FLOAT)) { segment ->
|
||||
val index = intVal(segment[0]) * Mflpt5.MemorySize
|
||||
"""
|
||||
lda ${segment[1].callLabel}+$index
|
||||
ldy ${segment[1].callLabel}+${index+1}
|
||||
lda #<${segment[1].callLabel}+$index
|
||||
ldy #>${segment[1].callLabel}+$index
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
lda #<${hexVal(segment[2])}
|
||||
|
@ -182,7 +182,7 @@ add_a_to_zpword .proc
|
||||
clc
|
||||
adc SCRATCH_ZPWORD1
|
||||
sta SCRATCH_ZPWORD1
|
||||
bvc +
|
||||
bcc +
|
||||
inc SCRATCH_ZPWORD1+1
|
||||
+ rts
|
||||
.pend
|
||||
|
Loading…
x
Reference in New Issue
Block a user