fixed register clobbering at sub call and cube3d c64 example

This commit is contained in:
Irmen de Jong 2018-12-30 20:22:32 +01:00
parent b69697c3dd
commit 75a57da44d
3 changed files with 30 additions and 20 deletions

View File

@ -11,9 +11,6 @@
float[8] ycoor = [ -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 ] 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 ; storage for rotated coordinates
float[len(xcoor)] rotatedx=0.0 float[len(xcoor)] rotatedx=0.0
float[len(ycoor)] rotatedy=0.0 float[len(ycoor)] rotatedy=0.0
@ -21,11 +18,11 @@
sub start() { sub start() {
float time=0.0 float time=0.0
while true { while(true) {
rotate_vertices(time) rotate_vertices(time)
c64.CLEARSCR() c64.CLEARSCR()
draw_edges() draw_edges()
time += 0.2 time+=0.2
} }
} }
@ -40,12 +37,14 @@
float cosc = cos(t*0.78) float cosc = cos(t*0.78)
float sinc = sin(t*0.78) float sinc = sin(t*0.78)
float cosa_sinb = cosa*sinb
float sina_sinb = sina*sinb
float Axx = cosa*cosb float Axx = cosa*cosb
float Axy = cosa*sinb*sinc - sina*cosc float Axy = cosa_sinb*sinc - sina*cosc
float Axz = cosa*sinb*cosc + sina*sinc float Axz = cosa_sinb*cosc + sina*sinc
float Ayx = sina*cosb float Ayx = sina*cosb
float Ayy = sina*sinb*sinc + cosa*cosc float Ayy = sina_sinb*sinc + cosa*cosc
float Ayz = sina*sinb*cosc - cosa*sinc float Ayz = sina_sinb*cosc - cosa*sinc
float Azx = -sinb float Azx = -sinb
float Azy = cosb*sinc float Azy = cosb*sinc
float Azz = cosb*cosc float Azz = cosb*cosc
@ -60,7 +59,6 @@
} }
} }
sub draw_edges() { sub draw_edges() {
sub toscreenx(float x, float z) -> byte { sub toscreenx(float x, float z) -> byte {
@ -72,14 +70,24 @@
} }
; plot the points of the 3d cube ; plot the points of the 3d cube
; first the points on the back, then the points on the front (painter algorithm)
for ubyte i in 0 to len(xcoor)-1 { for ubyte i in 0 to len(xcoor)-1 {
float rz = rotatedz[i] float rz = rotatedz[i]
if rz >= 0.1 {
ubyte sx = toscreenx(rotatedx[i], rz) as ubyte ubyte sx = toscreenx(rotatedx[i], rz) as ubyte
ubyte sy = toscreeny(rotatedy[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) c64scr.setchrclr(sx, sy, 46, i+2)
} }
} }
for ubyte i in 0 to len(xcoor)-1 {
float rz = rotatedz[i]
if rz < 0.1 {
ubyte sx = toscreenx(rotatedx[i], rz) as ubyte
ubyte sy = toscreeny(rotatedy[i], rz) as ubyte
c64scr.setchrclr(sx, sy, 81, i+2)
}
}
}
} }

View File

@ -59,12 +59,14 @@
float cosc = cos(t*0.78) float cosc = cos(t*0.78)
float sinc = sin(t*0.78) float sinc = sin(t*0.78)
float cosa_sinb = cosa*sinb
float sina_sinb = sina*sinb
float Axx = cosa*cosb float Axx = cosa*cosb
float Axy = cosa*sinb*sinc - sina*cosc float Axy = cosa_sinb*sinc - sina*cosc
float Axz = cosa*sinb*cosc + sina*sinc float Axz = cosa_sinb*cosc + sina*sinc
float Ayx = sina*cosb float Ayx = sina*cosb
float Ayy = sina*sinb*sinc + cosa*cosc float Ayy = sina_sinb*sinc + cosa*cosc
float Ayz = sina*sinb*cosc - cosa*sinc float Ayz = sina_sinb*cosc - cosa*sinc
float Azx = -sinb float Azx = -sinb
float Azy = cosb*sinc float Azy = cosb*sinc
float Azz = cosb*cosc float Azz = cosb*cosc

View File

@ -858,7 +858,7 @@ private class StatementTranslator(private val prog: IntermediateProgram,
private fun translateSubroutineCall(subroutine: Subroutine, arguments: List<IExpression>, callPosition: Position) { private fun translateSubroutineCall(subroutine: Subroutine, arguments: List<IExpression>, callPosition: Position) {
// evaluate the arguments and assign them into the subroutine's argument variables. // evaluate the arguments and assign them into the subroutine's argument variables.
var restoreX = Register.X in subroutine.asmClobbers var restoreX = Register.X in subroutine.asmClobbers
if(subroutine.asmParameterRegisters.isNotEmpty()) { if(subroutine.isAsmSubroutine) {
if(subroutine.parameters.size!=subroutine.asmParameterRegisters.size) if(subroutine.parameters.size!=subroutine.asmParameterRegisters.size)
throw CompilerException("no support for mix of register and non-register subroutine arguments") throw CompilerException("no support for mix of register and non-register subroutine arguments")