From 75a57da44dedd93746084f672f9267891d5adfa8 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 30 Dec 2018 20:22:32 +0100 Subject: [PATCH] fixed register clobbering at sub call and cube3d c64 example --- compiler/examples/cube3d-c64.p8 | 38 +++++++++++++++---------- compiler/examples/cube3d.p8 | 10 ++++--- compiler/src/prog8/compiler/Compiler.kt | 2 +- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/compiler/examples/cube3d-c64.p8 b/compiler/examples/cube3d-c64.p8 index ddfa6fc55..a69b1d8c0 100644 --- a/compiler/examples/cube3d-c64.p8 +++ b/compiler/examples/cube3d-c64.p8 @@ -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] 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=0.0 float[len(ycoor)] rotatedy=0.0 @@ -21,11 +18,11 @@ sub start() { float time=0.0 - while true { + while(true) { rotate_vertices(time) c64.CLEARSCR() draw_edges() - time += 0.2 + time+=0.2 } } @@ -40,12 +37,14 @@ float cosc = cos(t*0.78) float sinc = sin(t*0.78) + float cosa_sinb = cosa*sinb + float sina_sinb = sina*sinb float Axx = cosa*cosb - float Axy = cosa*sinb*sinc - sina*cosc - float Axz = cosa*sinb*cosc + sina*sinc + 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 Ayy = sina_sinb*sinc + cosa*cosc + float Ayz = sina_sinb*cosc - cosa*sinc float Azx = -sinb float Azy = cosb*sinc float Azz = cosb*cosc @@ -60,7 +59,6 @@ } } - sub draw_edges() { sub toscreenx(float x, float z) -> byte { @@ -72,14 +70,24 @@ } ; 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 { 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 + if rz >= 0.1 { + ubyte sx = toscreenx(rotatedx[i], rz) as ubyte + ubyte sy = toscreeny(rotatedy[i], rz) as ubyte 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) + } } } } diff --git a/compiler/examples/cube3d.p8 b/compiler/examples/cube3d.p8 index f8e2308d2..6d1ad7a30 100644 --- a/compiler/examples/cube3d.p8 +++ b/compiler/examples/cube3d.p8 @@ -59,12 +59,14 @@ float cosc = cos(t*0.78) float sinc = sin(t*0.78) + float cosa_sinb = cosa*sinb + float sina_sinb = sina*sinb float Axx = cosa*cosb - float Axy = cosa*sinb*sinc - sina*cosc - float Axz = cosa*sinb*cosc + sina*sinc + 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 Ayy = sina_sinb*sinc + cosa*cosc + float Ayz = sina_sinb*cosc - cosa*sinc float Azx = -sinb float Azy = cosb*sinc float Azz = cosb*cosc diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index d3c393c0e..09a88bf5b 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -858,7 +858,7 @@ private class StatementTranslator(private val prog: IntermediateProgram, private fun translateSubroutineCall(subroutine: Subroutine, arguments: List, callPosition: Position) { // evaluate the arguments and assign them into the subroutine's argument variables. var restoreX = Register.X in subroutine.asmClobbers - if(subroutine.asmParameterRegisters.isNotEmpty()) { + if(subroutine.isAsmSubroutine) { if(subroutine.parameters.size!=subroutine.asmParameterRegisters.size) throw CompilerException("no support for mix of register and non-register subroutine arguments")