commit c0d36c3c4c2c81848fa95d56f78ef588a86f10eb
parent 43453d7a7c11971e8bae75a4033e82a22ae14306
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Thu, 3 Jul 2025 10:28:06 -0700
New controller example
Diffstat:
1 file changed, 156 insertions(+), 127 deletions(-)
diff --git a/projects/examples/devices/controller.tal b/projects/examples/devices/controller.tal
@@ -1,15 +1,14 @@
( Controller: Buttons should highlight on press and display the button and key bytes. )
-|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $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
+|00 @System/vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $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
-|0000
+|000
- @center &x $2 &y $2
- @frame &w $2 &h $2 &x0 $2 &y0 $2 &x1 $2 &y1 $2
+ @center/x $2 &y $2
-|0100
+|100
@on-reset ( -> )
( | theme )
@@ -19,144 +18,174 @@
( | find center )
.Screen/width DEI2 #01 SFT2 .center/x STZ2
.Screen/height DEI2 #01 SFT2 .center/y STZ2
- ( | place controller )
- #0068 .frame/w STZ2
- #0030 .frame/h STZ2
- .center/x LDZ2 .frame/w LDZ2 #01 SFT2 SUB2 .frame/x0 STZ2
- .center/y LDZ2 .frame/h LDZ2 #01 SFT2 SUB2 .frame/y0 STZ2
- .frame/x0 LDZ2 .frame/w LDZ2 ADD2 .frame/x1 STZ2
- .frame/y0 LDZ2 .frame/h LDZ2 ADD2 .frame/y1 STZ2
- ( | vectors )
+ controller/<draw>
;on-button .Controller/vector DEO2
- ( | frame )
- .frame/x0 LDZ2 .frame/y0 LDZ2 .frame/x1 LDZ2 .frame/y1 LDZ2 #03 <line-rect>
- <draw-controller>
BRK
@on-button ( -> )
- <draw-controller>
+ controller/<draw>
( | print stack on start button )
[ LIT2 08 -Controller/button ] DEI NEQ ?{ #010e DEO }
BRK
(
+@|Controller )
+
+@controller/<draw> ( -- )
+ .Controller/button DEI2
+ ( | background )
+ .center/x LDZ2 #0040 SUB2 .Screen/x DEO2
+ .center/y LDZ2 #0020 SUB2 .Screen/y DEO2
+ #01f9 ;&icns #f6 <draw-times>
+ ( | output )
+ .Screen/x DEI2 #0010 ADD2 .Screen/x DEO2
+ .Screen/y DEI2 #0050 SUB2 .Screen/y DEO2
+ DUP2 hex/<draw-short>
+ ( | A button )
+ OVR #01 AND #00 EQU ?{
+ .center/x LDZ2 #0028 ADD2 .Screen/x DEO2
+ .center/y LDZ2 .Screen/y DEO2
+ #01fe ;large/icns #16 <draw-times> }
+ ( | B button )
+ OVR #02 AND #00 EQU ?{
+ .center/x LDZ2 #0010 ADD2 .Screen/x DEO2
+ .center/y LDZ2 .Screen/y DEO2
+ #01fe ;large/icns #16 <draw-times> }
+ ( | C button )
+ OVR #04 AND #00 EQU ?{
+ .center/x LDZ2 #0008 SUB2 .Screen/x DEO2
+ .center/y LDZ2 #0008 ADD2 .Screen/y DEO2
+ #01ff ;small/icn #16 <draw-times> }
+ ( | S button )
+ OVR #08 AND #00 EQU ?{
+ .center/x LDZ2 #0018 SUB2 .Screen/x DEO2
+ .center/y LDZ2 #0008 ADD2 .Screen/y DEO2
+ #01ff ;small/icn #16 <draw-times> }
+ ( | Up arrow )
+ OVR #10 AND #00 EQU ?{
+ .center/x LDZ2 #0030 SUB2 .Screen/x DEO2
+ .center/y LDZ2 #0008 SUB2 .Screen/y DEO2
+ #05ff ;arrow/icn #00 <draw-times> }
+ ( | Down arrow )
+ OVR #20 AND #00 EQU ?{
+ .center/x LDZ2 #0030 SUB2 .Screen/x DEO2
+ .center/y LDZ2 #0008 ADD2 .Screen/y DEO2
+ #05ff ;arrow/icn #00 <draw-times> }
+ ( | Left arrow )
+ OVR #40 AND #00 EQU ?{
+ .center/x LDZ2 #0038 SUB2 .Screen/x DEO2
+ .center/y LDZ2 .Screen/y DEO2
+ #05ff ;arrow/icn #00 <draw-times> }
+ ( | Right arrow )
+ OVR #80 AND #00 EQU ?{
+ .center/x LDZ2 #0028 SUB2 .Screen/x DEO2
+ .center/y LDZ2 .Screen/y DEO2
+ #05ff ;arrow/icn #00 <draw-times> }
+ POP2 JMP2r
+
+@<draw-times> ( color times addr* auto -- )
+ .Screen/auto DEO
+ .Screen/addr DEO2
+ SWP STH
+ [ LITr -Screen/sprite ]
+ &>l
+ DEOkr
+ INC DUP ?&>l
+ POP POP2r JMP2r
+
+(
@|drawing )
-@<draw-controller> ( -- )
- .Controller/button DEI STH
- ( | d-pad )
- .frame/x0 LDZ2 #0010 ADD2 .Screen/x DEO2
- .frame/y0 LDZ2 #0010 ADD2 .Screen/y DEO2
- ;dpad-up-icn .Screen/addr DEO2
- #03 STHkr #04 SFT #01 AND SUB .Screen/sprite DEO
- .Screen/y DEI2 #0010 ADD2 .Screen/y DEO2
- ;dpad-down-icn .Screen/addr DEO2
- #03 STHkr #05 SFT #01 AND SUB .Screen/sprite DEO
- .Screen/y DEI2 #0008 SUB2 .Screen/y DEO2
- .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
- ;dpad-left-icn .Screen/addr DEO2
- #03 STHkr #06 SFT #01 AND SUB .Screen/sprite DEO
- .Screen/x DEI2 #0010 ADD2 .Screen/x DEO2
- ;dpad-right-icn .Screen/addr DEO2
- #03 STHkr #07 SFT #01 AND SUB .Screen/sprite DEO
- .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
- ;fill-icn .Screen/addr DEO2
- [ LIT2 03 -Screen/sprite ] DEO
- ( | options )
- .center/y LDZ2 #0009 ADD2 .Screen/y DEO2
- .center/x LDZ2 #0009 SUB2 .Screen/x DEO2
- ;option-icn .Screen/addr DEO2
- #03 STHkr #03 SFT #01 AND SUB .Screen/sprite DEO
- .center/x LDZ2 #0004 ADD2 .Screen/x DEO2
- ;option-icn .Screen/addr DEO2
- #03 STHkr #02 SFT #01 AND SUB .Screen/sprite DEO
- ( | buttons )
- .center/y LDZ2 .Screen/y DEO2
- .center/x LDZ2 #0018 ADD2 .Screen/x DEO2
- ;button-icn .Screen/addr DEO2
- #03 STHkr #01 SFT #01 AND SUB .Screen/sprite DEO
- .Screen/y DEI2 #000a ADD2 .Screen/y DEO2
- ;font-hex/b .Screen/addr DEO2
- [ LIT2 03 -Screen/sprite ] DEO
- .center/y LDZ2 .Screen/y DEO2
- .center/x LDZ2 #0024 ADD2 .Screen/x DEO2
- ;button-icn .Screen/addr DEO2
- #03 STHr #01 AND SUB .Screen/sprite DEO
- .Screen/y DEI2 #000a ADD2 .Screen/y DEO2
- ;font-hex/a .Screen/addr DEO2
- [ LIT2 03 -Screen/sprite ] DEO
- .center/x LDZ2 #0010 SUB2 .Screen/x DEO2
- .center/y LDZ2 #0010 SUB2 .Screen/y DEO2
+@hex/<draw-short> ( short* -- )
[ LIT2 01 -Screen/auto ] DEO
- .Controller/button DEI2 <draw-short>
- [ LIT2 00 -Screen/auto ] DEO
- JMP2r
-
-@<draw-short> ( short* -- )
- SWP <draw-byte>
+ SWP /<draw-byte>
+ ( >> )
-@<draw-byte> ( byte -- )
- DUP #04 SFT <draw-hex>
+@hex/<draw-byte> ( byte -- )
+ DUP #04 SFT /<draw-char>
+ ( >> )
-@<draw-hex> ( char -- )
- #00 SWP #0f AND #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
+@hex/<draw-char> ( char -- )
+ #00 SWP #0f AND #30 SFT2 ;&icns ADD2 .Screen/addr DEO2
[ LIT2 03 -Screen/sprite ] DEO
JMP2r
-@<line-rect> ( x1* y1* x2* y2* color -- )
- STH
- DUP2 ,&ver-y2 STR2
- ,&hor-y2 STR2
- DUP2 ,&ver-x2 STR2
- ,&hor-x2 STR2
- DUP2 ,&ver-y1 STR2
- ,&hor-y1 STR2
- DUP2 ,&ver-x1 STR2
- ,&hor-x1 STR2
- ( | horizontal )
- [ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
- &hor ( -- )
- DUP2 .Screen/x DEO2
- [ LIT2 &hor-y1 $2 ] .Screen/y DEO2
- STHkr .Screen/pixel DEOk [ LIT2 &hor-y2 $2 ] .Screen/y DEO2
- DEO
- INC2 GTH2k ?&hor
- POP2 POP2
- ( | vertical )
- [ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
- &ver ( -- )
- DUP2 .Screen/y DEO2
- [ LIT2 &ver-x1 $2 ] .Screen/x DEO2
- STHkr .Screen/pixel DEOk [ LIT2 &ver-x2 $2 ] .Screen/x DEO2
- DEO
- INC2 GTH2k ?&ver
- POP2 POP2 POPr JMP2r
-
(
@|assets )
-@fill-icn [ ffff ffff ffff ffff ]
-
-@dpad-up-icn [ 7eff e7c3 ffff ffff ]
-
-@dpad-down-icn [ ffff ffff c3e7 ff7e ]
-
-@dpad-left-icn [ 7fff efcf cfef ff7f ]
-
-@dpad-right-icn [ feff f7f3 f3f7 fffe ]
-
-@option-icn [ 0000 7eff ff7e 0000 ]
-
-@button-icn [ 3c7e ffff ffff 7e3c ]
-
-@font-hex [
- 007c 8282 8282 827c 0030 1010 1010 1010
- 007c 8202 7c80 80fe 007c 8202 1c02 827c
- 000c 1424 4484 fe04 00fe 8080 7c02 827c
- 007c 8280 fc82 827c 00fe 0202 0408 1010
- 007c 8282 7c82 827c 007c 8282 7e02 827c
- &a 007c 8202 7e82 827e &b 00fc 8282
- fc82 82fc 007c 8280 8080 827c 00fc 8282
- 8282 82fc 00fe 8080 fe80 80fe 00fe 8080
- f080 8080 ]
+@large/icns [
+ 071f 3f7f 7fff ffff e0f8 fcfe feff ffff
+ ffff ff7f 7f3f 1f07 ffff fffe fefc f8e0 ]
+
+@small/icn [ 0000 001f 3f3f 3f1f 0000 00f8 fcfc fcf8 ]
+
+@arrow/icn [ 187e 7eff ff7e 7e18 ]
+
+@controller/icns [
+ 0000 0f30 4040 8080 0000 ff00 0000 0000
+ 0042 8100 0000 0000 0000 ff00 0000 0000
+ 0000 ff00 0000 0000 0000 ff00 0000 0000
+ 0000 ff00 0000 0000 0000 ff00 0000 0000
+ 0000 ff00 0000 0000 0000 ff00 0000 0000
+ 0000 ff00 0000 0000 0000 ff00 0000 0000
+ 0000 ff00 0000 0000 0000 ff00 0000 0000
+ 0000 ff00 0000 0000 0000 f00c 0202 0101
+ 8080 8080 8080 8080 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0101 0101 0101 0101
+ 8080 8080 8080 8080 0000 0000 0000 0000
+ 0000 0000 0000 0018 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0302 0000 0000 0000 8040
+ 0000 0000 0000 0000 0000 0000 0000 0102
+ 0000 0000 0000 8040 0101 0101 0101 0101
+ 8080 8080 8080 8080 0000 0001 0101 011f
+ 6681 8100 0000 0000 0000 0080 8080 80f8
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0000 0000 0000 0000 0000 0000 0000 0000
+ 0203 0202 0300 0000 4080 4040 8000 0000
+ 0000 0000 0000 0000 0203 0202 0200 0000
+ 40c0 4040 4000 0000 0101 0101 0101 0101
+ 8080 8081 8180 8080 6080 8000 0080 8060
+ 0000 0000 0000 0000 0601 0100 0001 0106
+ 0000 0080 8000 0000 0001 0202 0100 0201
+ 0080 4000 8040 4080 0001 0202 0202 0201
+ 0080 4000 0000 4080 0000 0000 0000 0000
+ 0718 2040 4080 8080 e018 0402 0201 0101
+ 0000 0000 0000 0000 0718 2040 4080 8080
+ e018 0402 0201 0101 0101 0101 0101 0101
+ 8080 8080 8080 8080 1f01 0101 0100 0000
+ 0000 0000 0081 8166 f880 8080 8000 0000
+ 0000 0000 0000 0000 0000 001f 2020 201f
+ 0000 00f8 0404 04f8 0000 001f 2020 201f
+ 0000 00f8 0404 04f8 0000 0000 0000 0000
+ 8080 8040 4020 1807 0101 0102 0204 18e0
+ 0000 0000 0000 0000 8080 8040 4020 1807
+ 0101 0102 0204 18e0 0101 0101 0101 0101
+ 8080 8080 4040 300f 0000 0000 0000 00ff
+ 1800 0000 0000 00ff 0000 0000 0000 00ff
+ 0000 0000 0000 00ff 0000 0000 0000 00ff
+ 0000 0000 0000 00ff 0000 0000 0000 00ff
+ 0000 0000 0000 00ff 0000 0000 0000 00ff
+ 0000 0000 0000 00ff 0000 0000 0000 00ff
+ 0000 0000 0000 00ff 0000 0000 0000 00ff
+ 0000 0000 0000 00ff 0101 0101 0202 0cf0 ]
+
+@hex/icns [
+ 0018 2424 2424 2418 0008 1808 0808 0808
+ 0018 2404 1820 203c 0018 2404 1804 2418
+ 0024 2424 1c04 0404 003c 2020 1804 2418
+ 0018 2420 3824 2418 003c 0408 1010 1010
+ 0018 2424 1824 2418 0018 2424 1c04 2418
+ 0018 2424 3c24 2424 0038 2424 3824 2438
+ 0018 2420 2020 2418 0038 2424 2424 2438
+ 001c 2020 3820 201c 001c 2020 3820 2020 ]