changed cx16/rotating-stars example to starszoom instead.

This commit is contained in:
Irmen de Jong 2024-10-02 01:32:56 +02:00
parent 2bd4326ff6
commit 09f3eecf56
5 changed files with 86 additions and 73 deletions

View File

@ -136,10 +136,10 @@ class TestCompilerOnExamplesCx16: FunSpec({
"multi-irq-new",
"plasma",
"rasterbars",
"rotating-stars",
"showbmx",
"snow",
"spotlight",
"starszoom",
"tehtriz",
"testgfx2",
"testmonogfx",

View File

@ -1,11 +1,13 @@
TODO
====
fix the ubyte[<space>] 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[<space>] parser error.
Regenerate skeleton doc files.
Improve register load order in subroutine call args assignments:

View File

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

View File

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

View File

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