0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-05 05:45:05 +00:00
uxn/projects/examples/gui/timer.tal
2024-02-25 16:06:54 -08:00

83 lines
1.8 KiB
Tal

( uxnemu timer.rom )
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|80 @Controller &vector $2 &button $1 &key $1
|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
|100
@on-reset ( -> )
;on-control .Controller/vector DEO2
#0080 DUP2 .Screen/width DEO2
.Screen/height DEO2
#f074 DUP2 .System/r DEO2
DUP2 .System/g DEO2
.System/b DEO2
Timer/start BRK
@on-control ( -> )
.Controller/button DEI
( A ) DUP #01 NEQ ?{ Timer/pause }
( B ) DUP #02 NEQ ?{ Timer/start }
POP BRK
(
@|Objects )
@Timer ( * )
&on-frame ( -> )
[ LIT &paused $1 ] ?{
[ LIT2 3c &frame 00 ] INCk ,&frame STR
EQU ?&on-second }
BRK
&on-second ( -> )
[ LIT2 00 _&frame ] STR
[ LIT2 ff &time $1 ] ADD DUP ?{ /end }
,&time STR
/<draw> BRK
&start ( -- )
[ LIT2 0f _&time ] STR
[ LIT2 00 _&paused ] STR
[ LIT2 0f _&frame ] STR
;&on-frame .Screen/vector DEO2
!&<draw>
&pause ( -- )
[ LIT2 00 _&paused ] LDR EQU
( ) INCk <set-dec-color>
,&paused STR
!&<draw>
&end ( -- )
#0000 .Screen/vector DEO2
#06 <set-dec-color>
!&<draw>
&<draw> ( -- )
,&time LDR !<draw-dec>
(
@|drawing )
@<set-dec-color> ( color -- )
;<draw-num>/color STA
JMP2r
@<draw-dec> ( dec -- )
#0010 DUP2 .Screen/x DEO2
.Screen/y DEO2
[ LIT2 01 -Screen/auto ] DEO
DUP
( x0 ) #0a DIV <draw-num>
( 0x ) #0a DIVk MUL SUB
( >> )
@<draw-num> ( num -- )
#00 SWP #30 SFT2 ;numbers-icns ADD2 .Screen/addr DEO2
[ LIT2 &color 01 -Screen/sprite ] DEO
JMP2r
@numbers-icns [
38c6 c6c6 c6c6 c638 8c78 1818 1818 187e
3c4e 860e 1c38 72fe 807e 0c10 7c0e 8e7c
0e1c 1c3c 6cff 0c1e c6f8 40c0 fc0e ce7c
3ac4 c0c0 fcce ce7c 807e 3e0c 1830 60c0
807c cece 7cce ce7c 807c cece 7c18 3060 ]