diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index c60bc4eed..25b23c4ff 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -136,10 +136,10 @@ class TestCompilerOnExamplesCx16: FunSpec({ "multi-irq-new", "plasma", "rasterbars", - "rotating-stars", "showbmx", "snow", "spotlight", + "starszoom", "tehtriz", "testgfx2", "testmonogfx", diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 7ec4cf162..f404120b4 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,11 +1,13 @@ TODO ==== +fix the ubyte[] parser error. + +crash: speeds[star] = msb(r[star]) speeds and r are uword arrays + word starw for starw in 50 downto 0 -> compiler error word loop variable can only loop over bytes or words -fix the ubyte[] parser error. - Regenerate skeleton doc files. Improve register load order in subroutine call args assignments: diff --git a/examples/cx16/rotating-stars.p8 b/examples/cx16/rotating-stars.p8 deleted file mode 100644 index 1b981ad4c..000000000 --- a/examples/cx16/rotating-stars.p8 +++ /dev/null @@ -1,57 +0,0 @@ -; Animate a rotating and zooming sprite field. -; Rather than doing complicated 3d stuff, this simply uses polar coordinates. -; Every star lies along the circle and just has a radius R. - -%import math -%import palette -%import gfx_lores -%option no_sysinit - -main { - %option verafxmuls - - sub start() { - const ubyte NUM_STARS = 128 ; must be 128 to evenly distribute (angle goes from 0..255 in steps of 2) - - ubyte[NUM_STARS] r - ubyte[NUM_STARS] speeds - uword[NUM_STARS] prev_x - ubyte[NUM_STARS] prev_y - uword angle - - gfx_lores.set_screen_mode() - - ; init the star positions - ubyte star - for star in 0 to NUM_STARS-1 { - r[star] = 4 + math.rnd()/4 - speeds[star] = (math.rnd() & 3) + 1 - } - - repeat { - sys.waitvsync() - ;; palette.set_color(0, $400) - for star in NUM_STARS-1 downto 0 { - gfx_lores.plot(prev_x[star], prev_y[star], 0) - cx16.r2L = star*2 + msb(angle) - uword sx = (msb(math.sin8(cx16.r2L) as word * r[star]) + 128) as uword + 32 - ubyte sy = (msb(math.cos8(cx16.r2L) as word * r[star]) + 120) - prev_x[star] = sx - if sy<240 { - prev_y[star] = sy - gfx_lores.plot(sx, sy, star) - } else - prev_y[star] = 0 - - r[star] += speeds[star] - if r[star] >= 255-3 { - r[star] = 4 - speeds[star] = (math.rnd() & 3) + 1 - } - } - angle += $0040 - ;; palette.set_color(0, $000) - } - } -} - diff --git a/examples/cx16/starszoom.p8 b/examples/cx16/starszoom.p8 new file mode 100644 index 000000000..08ca09c46 --- /dev/null +++ b/examples/cx16/starszoom.p8 @@ -0,0 +1,75 @@ +; Animate a zooming star field. +; Rather than doing complicated 3d stuff, this simply uses polar coordinates. +; Every star lies along the circle and has a radius. +; Movement is dictated by a random accelleration, which increases the speed, which increases the radius. + +; TODO extend the radius to a larger maximum (0-319 or perhaps 0-511, instead of 0-255) so that we can fill the whole screen. +; TODO do something with the colors palette: make stars darker in the distance + +%import math +%import palette +%import gfx_lores +%option no_sysinit + +main { + %option verafxmuls + + sub start() { + const ubyte NUM_STARS = 128 ; maximum is 128. + const ubyte CIRCLE_SKIP = 256/NUM_STARS + + ubyte[NUM_STARS] color + uword[NUM_STARS] @split radius + uword[NUM_STARS] @split accel + uword[NUM_STARS] @split speed + uword[NUM_STARS] @split prev_x + ubyte[NUM_STARS] prev_y + + gfx_lores.set_screen_mode() + + ; init the star positions + ubyte star + for star in 0 to NUM_STARS-1 { + color[star] = star + accel[star] = (math.rnd() & 15) | 1 + radius[star] = mkword(math.rnd() & %11111000, 0) + speed[star] = 0 ; radius[star] >> 6 ; a slow buildup of movement at the start is kinda nice I think, so we start with speed zero + } + + const uword angle = 0 ; if you make this a variable and increase it, the stars rotate. + + repeat { + sys.waitvsync() + ;;palette.set_color(0, $400) + for star in NUM_STARS-1 downto 0 { + + gfx_lores.plot(prev_x[star], prev_y[star], 0) + + cx16.r2L = star*CIRCLE_SKIP + msb(angle) + uword sx = (msb(math.sin8(cx16.r2L) as word * msb(radius[star])) + 128) as uword + 32 + ubyte sy = (msb(math.cos8(cx16.r2L) as word * msb(radius[star])) + 120) + + prev_x[star] = sx + if sy<240 { + prev_y[star] = sy + gfx_lores.plot(sx, sy, color[star]) + } else + prev_y[star] = 0 + + if radius[star] > $fffe - speed[star] { + ; reset star to center + accel[star] = (math.rnd() & 15) | 1 + radius[star] = $0400 + accel[star] * 128 + speed[star] = 0 ; radius[star] >> 6 + color[star] = math.rnd() + } else { + ; can still move more. + radius[star] += speed[star] + speed[star] += accel[star] + } + } + ;; angle += $0040 + ;;palette.set_color(0, $000) + } + } +} diff --git a/examples/test.p8 b/examples/test.p8 index e973ba8a0..d5d3f5e2a 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,22 +1,15 @@ %import textio -%import floats %zeropage basicsafe %option no_sysinit main { sub start() { - word @shared x1 = -118 - floats.print(x1 as float) - txt.nl() - floats.print(x1 as float/1.9) - txt.nl() - xf1 = x1/1.9 - floats.print(xf1) - txt.nl() - - float @shared xf1 = -118 - floats.print(xf1/1.9) - txt.nl() + ubyte[] stuff1=[1,2,3] + ubyte [] stuff2=[1,2,3] + ubyte[ ] stuff3=[1,2,3] ; TODO fix parse error + stuff1[1]++ + stuff2[1]++ + stuff3[1]++ } }