mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 01:29:28 +00:00
added cx16/rotating-stars example
This commit is contained in:
parent
c13168b60c
commit
2bd4326ff6
@ -22,7 +22,34 @@ gfx_lores {
|
||||
|
||||
sub clear_screen(ubyte color) {
|
||||
if verafx.available() {
|
||||
verafx.clear(0, 0, color, 320*240/4)
|
||||
; use verafx cache writes to quicly clear the screen
|
||||
const ubyte vbank = 0
|
||||
const uword vaddr = 0
|
||||
cx16.VERA_CTRL = 0
|
||||
cx16.VERA_ADDR_H = vbank | %00110000 ; 4-byte increment
|
||||
cx16.VERA_ADDR_M = msb(vaddr)
|
||||
cx16.VERA_ADDR_L = lsb(vaddr)
|
||||
cx16.VERA_CTRL = 6<<1 ; dcsel = 6, fill the 32 bits cache
|
||||
cx16.VERA_FX_CACHE_L = color
|
||||
cx16.VERA_FX_CACHE_M = color
|
||||
cx16.VERA_FX_CACHE_H = color
|
||||
cx16.VERA_FX_CACHE_U = color
|
||||
cx16.VERA_CTRL = 2<<1 ; dcsel = 2
|
||||
cx16.VERA_FX_MULT = 0
|
||||
cx16.VERA_FX_CTRL = %01000000 ; cache write enable
|
||||
repeat 320/4/4 {
|
||||
%asm {{
|
||||
ldy #240
|
||||
- stz cx16.VERA_DATA0
|
||||
stz cx16.VERA_DATA0
|
||||
stz cx16.VERA_DATA0
|
||||
stz cx16.VERA_DATA0
|
||||
dey
|
||||
bne -
|
||||
}}
|
||||
}
|
||||
cx16.VERA_FX_CTRL = 0 ; cache write disable
|
||||
cx16.VERA_CTRL = 0
|
||||
return
|
||||
}
|
||||
; fallback to cpu clear
|
||||
|
@ -136,6 +136,7 @@ class TestCompilerOnExamplesCx16: FunSpec({
|
||||
"multi-irq-new",
|
||||
"plasma",
|
||||
"rasterbars",
|
||||
"rotating-stars",
|
||||
"showbmx",
|
||||
"snow",
|
||||
"spotlight",
|
||||
|
@ -4,6 +4,7 @@ TODO
|
||||
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.
|
||||
|
||||
|
57
examples/cx16/rotating-stars.p8
Normal file
57
examples/cx16/rotating-stars.p8
Normal file
@ -0,0 +1,57 @@
|
||||
; 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user