commit b00cafe0f269c1841357e21fd7dec06c1579a881 parent 0dffbf6c0e42882e2dbeb77e24fdd46ea88d8468 Author: Devine Lu Linvega <aliceffekt@gmail.com> Date: Sun, 25 Feb 2024 13:09:38 -0800 (timer.tal) Added OOP example Diffstat:
A | projects/examples/gui/timer.tal | | | 73 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 73 insertions(+), 0 deletions(-)
diff --git a/projects/examples/gui/timer.tal b/projects/examples/gui/timer.tal @@ -0,0 +1,73 @@ +( 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 ?{ Timer/end } + ,&time STR + Timer/<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 + ( ) DUP ,&paused STR + ( ) INC ;<draw-num>/color STA + !&<draw> + &end ( -- ) + #0000 .Screen/vector DEO2 + #06 ;<draw-num>/color STA + !&<draw> + &<draw> ( -- ) + #0010 DUP2 .Screen/x DEO2 + .Screen/y DEO2 + [ LIT2 01 -Screen/auto ] DEO + ,&time LDR DUP + ( x0 ) #0a DIV <draw-num> + ( 0x ) #0a DIVk MUL SUB <draw-num> + JMP2r + +@<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 ] +