uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

controller.tal (4494B)


      1 ( Controller: Buttons should highlight on press and display the button and key bytes. )
      2 
      3 |00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
      4 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
      5 |80 @Controller &vector $2 &button $1 &key $1
      6 
      7 |0000
      8 
      9 	@center &x $2 &y $2
     10 	@frame &w $2 &h $2 &x0 $2 &y0 $2 &x1 $2 &y1 $2
     11 
     12 |0100
     13 
     14 @on-reset ( -> )
     15 	( | theme )
     16 	#0fff .System/r DEO2
     17 	#0f0f .System/g DEO2
     18 	#0f0f .System/b DEO2
     19 	( | find center )
     20 	.Screen/width DEI2 #01 SFT2 .center/x STZ2
     21 	.Screen/height DEI2 #01 SFT2 .center/y STZ2
     22 	( | place controller )
     23 	#0068 .frame/w STZ2
     24 	#0030 .frame/h STZ2
     25 	.center/x LDZ2 .frame/w LDZ2 #01 SFT2 SUB2 .frame/x0 STZ2
     26 	.center/y LDZ2 .frame/h LDZ2 #01 SFT2 SUB2 .frame/y0 STZ2
     27 	.frame/x0 LDZ2 .frame/w LDZ2 ADD2 .frame/x1 STZ2
     28 	.frame/y0 LDZ2 .frame/h LDZ2 ADD2 .frame/y1 STZ2
     29 	( | vectors )
     30 	;on-button .Controller/vector DEO2
     31 	( | frame )
     32 	.frame/x0 LDZ2 .frame/y0 LDZ2 .frame/x1 LDZ2 .frame/y1 LDZ2 #03 <line-rect>
     33 	<draw-controller>
     34 	BRK
     35 
     36 @on-button ( -> )
     37 	<draw-controller>
     38 	( | print stack on start button )
     39 	[ LIT2 08 -Controller/button ] DEI NEQ ?{ #010e DEO }
     40 	BRK
     41 
     42 (
     43 @|drawing )
     44 
     45 @<draw-controller> ( -- )
     46 	.Controller/button DEI STH
     47 	( | d-pad )
     48 	.frame/x0 LDZ2 #0010 ADD2 .Screen/x DEO2
     49 	.frame/y0 LDZ2 #0010 ADD2 .Screen/y DEO2
     50 	;dpad-up-icn .Screen/addr DEO2
     51 	#03 STHkr #04 SFT #01 AND SUB .Screen/sprite DEO
     52 	.Screen/y DEI2 #0010 ADD2 .Screen/y DEO2
     53 	;dpad-down-icn .Screen/addr DEO2
     54 	#03 STHkr #05 SFT #01 AND SUB .Screen/sprite DEO
     55 	.Screen/y DEI2 #0008 SUB2 .Screen/y DEO2
     56 	.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
     57 	;dpad-left-icn .Screen/addr DEO2
     58 	#03 STHkr #06 SFT #01 AND SUB .Screen/sprite DEO
     59 	.Screen/x DEI2 #0010 ADD2 .Screen/x DEO2
     60 	;dpad-right-icn .Screen/addr DEO2
     61 	#03 STHkr #07 SFT #01 AND SUB .Screen/sprite DEO
     62 	.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
     63 	;fill-icn .Screen/addr DEO2
     64 	[ LIT2 03 -Screen/sprite ] DEO
     65 	( | options )
     66 	.center/y LDZ2 #0009 ADD2 .Screen/y DEO2
     67 	.center/x LDZ2 #0009 SUB2 .Screen/x DEO2
     68 	;option-icn .Screen/addr DEO2
     69 	#03 STHkr #03 SFT #01 AND SUB .Screen/sprite DEO
     70 	.center/x LDZ2 #0004 ADD2 .Screen/x DEO2
     71 	;option-icn .Screen/addr DEO2
     72 	#03 STHkr #02 SFT #01 AND SUB .Screen/sprite DEO
     73 	( | buttons )
     74 	.center/y LDZ2 .Screen/y DEO2
     75 	.center/x LDZ2 #0018 ADD2 .Screen/x DEO2
     76 	;button-icn .Screen/addr DEO2
     77 	#03 STHkr #01 SFT #01 AND SUB .Screen/sprite DEO
     78 	.Screen/y DEI2 #000a ADD2 .Screen/y DEO2
     79 	;font-hex/b .Screen/addr DEO2
     80 	[ LIT2 03 -Screen/sprite ] DEO
     81 	.center/y LDZ2 .Screen/y DEO2
     82 	.center/x LDZ2 #0024 ADD2 .Screen/x DEO2
     83 	;button-icn .Screen/addr DEO2
     84 	#03 STHr #01 AND SUB .Screen/sprite DEO
     85 	.Screen/y DEI2 #000a ADD2 .Screen/y DEO2
     86 	;font-hex/a .Screen/addr DEO2
     87 	[ LIT2 03 -Screen/sprite ] DEO
     88 	.center/x LDZ2 #0010 SUB2 .Screen/x DEO2
     89 	.center/y LDZ2 #0010 SUB2 .Screen/y DEO2
     90 	[ LIT2 01 -Screen/auto ] DEO
     91 	.Controller/button DEI2 <draw-short>
     92 	[ LIT2 00 -Screen/auto ] DEO
     93 	JMP2r
     94 
     95 @<draw-short> ( short* -- )
     96 	SWP <draw-byte>
     97 
     98 @<draw-byte> ( byte -- )
     99 	DUP #04 SFT <draw-hex>
    100 
    101 @<draw-hex> ( char -- )
    102 	#00 SWP #0f AND #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
    103 	[ LIT2 03 -Screen/sprite ] DEO
    104 	JMP2r
    105 
    106 @<line-rect> ( x1* y1* x2* y2* color -- )
    107 	STH
    108 	DUP2 ,&ver-y2 STR2
    109 	,&hor-y2 STR2
    110 	DUP2 ,&ver-x2 STR2
    111 	,&hor-x2 STR2
    112 	DUP2 ,&ver-y1 STR2
    113 	,&hor-y1 STR2
    114 	DUP2 ,&ver-x1 STR2
    115 	,&hor-x1 STR2
    116 	( | horizontal )
    117 	[ LIT2 &hor-x2 $2 ] INC2 [ LIT2 &hor-x1 $2 ]
    118 	&hor ( -- )
    119 		DUP2 .Screen/x DEO2
    120 		[ LIT2 &hor-y1 $2 ] .Screen/y DEO2
    121 		STHkr .Screen/pixel DEOk [ LIT2 &hor-y2 $2 ] .Screen/y DEO2
    122 		DEO
    123 		INC2 GTH2k ?&hor
    124 	POP2 POP2
    125 	( | vertical )
    126 	[ LIT2 &ver-y2 $2 ] [ LIT2 &ver-y1 $2 ]
    127 	&ver ( -- )
    128 		DUP2 .Screen/y DEO2
    129 		[ LIT2 &ver-x1 $2 ] .Screen/x DEO2
    130 		STHkr .Screen/pixel DEOk [ LIT2 &ver-x2 $2 ] .Screen/x DEO2
    131 		DEO
    132 		INC2 GTH2k ?&ver
    133 	POP2 POP2 POPr JMP2r
    134 
    135 (
    136 @|assets )
    137 
    138 @fill-icn [ ffff ffff ffff ffff ]
    139 
    140 @dpad-up-icn [ 7eff e7c3 ffff ffff ]
    141 
    142 @dpad-down-icn [ ffff ffff c3e7 ff7e ]
    143 
    144 @dpad-left-icn [ 7fff efcf cfef ff7f ]
    145 
    146 @dpad-right-icn [ feff f7f3 f3f7 fffe ]
    147 
    148 @option-icn [ 0000 7eff ff7e 0000 ]
    149 
    150 @button-icn [ 3c7e ffff ffff 7e3c ]
    151 
    152 @font-hex [
    153 	007c 8282 8282 827c 0030 1010 1010 1010
    154 	007c 8202 7c80 80fe 007c 8202 1c02 827c
    155 	000c 1424 4484 fe04 00fe 8080 7c02 827c
    156 	007c 8280 fc82 827c 00fe 0202 0408 1010
    157 	007c 8282 7c82 827c 007c 8282 7e02 827c
    158 	&a 007c 8202 7e82 827e &b 00fc 8282
    159 	fc82 82fc 007c 8280 8080 827c 00fc 8282
    160 	8282 82fc 00fe 8080 fe80 80fe 00fe 8080
    161 	f080 8080 ]
    162