0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-23 14:25:10 +00:00
uxn/projects/examples/devices/controller.keys.tal
2021-07-01 17:33:55 -07:00

148 lines
No EOL
3.4 KiB
Tal

( dev/controller/keys )
%+ { ADD } %- { SUB } %* { MUL } %/ { DIV }
%< { LTH } %> { GTH } %= { EQU } %! { NEQ }
%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 }
%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 }
%RTN { JMP2r }
%TOS { #00 SWP }
%DEBUG { ;print-hex JSR2 #0a .Console/write DEO }
%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 #0a .Console/write DEO }
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]
|a0 @File [ &vector $2 &success $2 &offset $2 &pad $2 &name $2 &length $2 &load $2 &save $2 ]
( variables )
|0000
@position
&x $2
&y $2
( init )
|0100 ( -> )
( theme )
#0f73 .System/r DEO2
#0fe3 .System/g DEO2
#0fc3 .System/b DEO2
( vectors )
;on-button .Controller/vector DEO2
( load font )
#1000 .File/length DEO2
;fontpath .File/name DEO2
;font-data .File/load DEO2
;draw-cursor JSR2
BRK
@on-button ( -> )
( skip ) .Controller/key DEI #01 JCN [ BRK ]
( print button-key code )
#0000 .Screen/x DEO2
.Screen/height DEI2 #0008 -- .Screen/y DEO2
.Controller/button DEI2 #21 ;draw-short JSR2
.position/x LDZ2 .Screen/x DEO2
.position/y LDZ2 .Screen/y DEO2
( linebreak )
.Controller/key DEI #0d NEQ ,&no-return JCN
( draw ) #20 .Screen/color DEO
( reset ) #0000 .position/x STZ2
( incr ) .position/y LDZ2 #0010 ++ .position/y STZ2
;draw-cursor JSR2
BRK
&no-return
.Controller/key DEI TOS #0020 ** DEBUG2
;font-data .Controller/key DEI TOS #0010 ** ++ .Screen/addr DEO2
.Controller/button DEI ;mod-color JSR2 .Screen/color DEO
.Screen/y DEI2 #0008 ++ .Screen/y DEO2
.Screen/addr DEI2 #0008 ++ .Screen/addr DEO2
.Controller/button DEI ;mod-color JSR2 .Screen/color DEO
( incr ) .position/x LDZ2 #0008 ++ .position/x STZ2
,draw-cursor JSR
BRK
@mod-color ( mod -- color )
( ctrl ) DUP #01 = #01 * STH
( alt ) DUP #02 = #03 * STH
( shift ) #04 = #05 * STH2r + +
#21 +
RTN
@draw-cursor ( -- )
.position/x LDZ2 .Screen/x DEO2
.position/y LDZ2 .Screen/y DEO2
;cursor .Screen/addr DEO2
#22 .Screen/color DEO
.position/y LDZ2 #0008 ++ .Screen/y DEO2
#22 .Screen/color DEO
RTN
@draw-short ( short* color -- )
STH SWP
DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
( draw ) STHkr .Screen/color DEO
#0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
.Screen/x DEI2 #0008 ++ .Screen/x DEO2
( draw ) STHkr .Screen/color DEO
DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
.Screen/x DEI2 #0008 ++ .Screen/x DEO2
( draw ) STHkr .Screen/color DEO
#0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2
.Screen/x DEI2 #0008 ++ .Screen/x DEO2
( draw ) STHr .Screen/color DEO
RTN
@print-hex ( value -- )
STHk #04 SFT ,&parse JSR .Console/write DEO
STHr #0f AND ,&parse JSR .Console/write DEO
RTN
&parse ( value -- char )
DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN
RTN
@cursor
ffff ffff ffff ffff
@font-hex
003c 464a 5262 3c00 0018 0808 0808 1c00
003c 4202 3c40 7e00 003c 421c 0242 3c00
000c 1424 447e 0400 007e 407c 0242 3c00
003c 407c 4242 3c00 007e 0204 0810 1000
003c 423c 4242 3c00 003c 4242 3e02 3c00
003c 4242 7e42 4200 007c 427c 4242 7c00
003c 4240 4042 3c00 007c 4242 4242 7c00
007e 4078 4040 7e00 007e 4078 4040 4000
@fontpath "projects/fonts/437dos8x16.bit
@font-data