mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
34f3169dda
cbm: MEMTOP changed (now also returns nr of banks in A) STOP2 removed (just use STOP) RDTIM_safe() added TEST IRQ ENABLE RDTIM16 changed (internally) TEST IRQ ENABLE cx16: screen_mode changed (now also returns width and height in X,Y) kbdbuf_peek2 removed (just use kbdbuf_peek) joystick_get changed (presence now returned as bool in Y) joystick_get2 removed (just use joystick_get) mouse_pos changed (now properly returns x and y position in R0 and R1) set_led_brightness changed into set_led_state, with only a boolean on/off argument. There is no variable brightness. sys.set_leds_brightness() removed. Use cx16.set_led_brightness().
60 lines
1.7 KiB
Lua
60 lines
1.7 KiB
Lua
%import math
|
|
%import textio
|
|
%import palette
|
|
|
|
; use the mouse to move the cursor around the screen
|
|
; it uses the fast direction routine to spotlight your mouse position.
|
|
|
|
; you can use the atan2() routine as well for more precision laser beams,
|
|
; but it will use a lot more memory due to the required lookup tables.
|
|
|
|
main {
|
|
sub start() {
|
|
const uword WIDTH=320
|
|
const ubyte HEIGHT=240
|
|
|
|
uword xx
|
|
ubyte yy
|
|
void cx16.screen_mode(128, false)
|
|
cx16.mouse_config2(1)
|
|
txt.print("move the mouse for the spotlight.")
|
|
|
|
; prefill
|
|
for yy in 0 to HEIGHT-1 {
|
|
cx16.FB_cursor_position(0, yy)
|
|
for xx in 0 to WIDTH-1 {
|
|
cx16.FB_set_pixel(math.direction(128, HEIGHT/2, clampx(xx), yy) + 128)
|
|
}
|
|
}
|
|
|
|
|
|
ubyte previous_direction
|
|
ubyte new_direction
|
|
|
|
; dim the screen
|
|
for new_direction in 128 to 128+23
|
|
palette.set_color(new_direction, $024)
|
|
|
|
; spotlight
|
|
repeat {
|
|
void, cx16.r0s, cx16.r1s = cx16.mouse_pos()
|
|
new_direction = math.direction(128, HEIGHT/2, clampx(cx16.r0), cx16.r1L)
|
|
if new_direction != previous_direction {
|
|
sys.waitvsync()
|
|
palette.set_color(new_direction+128, math.rndw())
|
|
palette.set_color(previous_direction+128, $024)
|
|
previous_direction = new_direction
|
|
}
|
|
}
|
|
}
|
|
|
|
sub clampx(uword screenx) -> ubyte {
|
|
;; return clamp(screenx, 32, 255+32)-32 as ubyte
|
|
if screenx<32
|
|
return 0
|
|
else if screenx>255+32
|
|
return 255
|
|
return lsb(screenx)-32
|
|
}
|
|
}
|