... | ... |
@@ -54,9 +54,9 @@ then |
54 | 54 |
fi |
55 | 55 |
|
56 | 56 |
echo "Assembling.." |
57 |
-./bin/uxnasm projects/examples/demos/theme.tal bin/theme.rom |
|
57 |
+./bin/uxnasm projects/examples/devices/controller.tal bin/controller.rom |
|
58 | 58 |
|
59 | 59 |
echo "Running.." |
60 |
-./bin/uxnemu bin/theme.rom |
|
60 |
+./bin/uxnemu bin/controller.rom |
|
61 | 61 |
|
62 | 62 |
echo "Done." |
66 | 66 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,202 @@ |
1 |
+( dev/controller/keys ) |
|
2 |
+ |
|
3 |
+%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } |
|
4 |
+%< { LTH } %> { GTH } %= { EQU } %! { NEQ } |
|
5 |
+%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } |
|
6 |
+%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } |
|
7 |
+ |
|
8 |
+%RTN { JMP2r } |
|
9 |
+%TOS { #00 SWP } |
|
10 |
+%LTS2 { #8000 ++ SWP2 #8000 ++ >> } %GTS2 { #8000 ++ SWP2 #8000 ++ << } |
|
11 |
+ |
|
12 |
+%DEBUG { ;print-hex JSR2 #0a .Console/write DEO } |
|
13 |
+%DEBUG2 { SWP ;print-hex JSR2 ;print-hex JSR2 #0a .Console/write DEO } |
|
14 |
+ |
|
15 |
+( devices ) |
|
16 |
+ |
|
17 |
+|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
18 |
+|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 ] |
|
19 |
+|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
|
20 |
+|80 @Controller [ &vector $2 &button $1 &key $1 ] |
|
21 |
+ |
|
22 |
+( variables ) |
|
23 |
+ |
|
24 |
+|0000 |
|
25 |
+ |
|
26 |
+@center |
|
27 |
+ &x $2 |
|
28 |
+ &y $2 |
|
29 |
+ |
|
30 |
+@position |
|
31 |
+ &x $2 |
|
32 |
+ &y $2 |
|
33 |
+@frame |
|
34 |
+ &w $2 &h $2 |
|
35 |
+ &x0 $2 &y0 $2 |
|
36 |
+ &x1 $2 &y1 $2 |
|
37 |
+ |
|
38 |
+@color $1 |
|
39 |
+@rect [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] |
|
40 |
+ |
|
41 |
+( init ) |
|
42 |
+ |
|
43 |
+|0100 ( -> ) |
|
44 |
+ |
|
45 |
+ ( theme ) |
|
46 |
+ #0ff7 .System/r DEO2 |
|
47 |
+ #0f07 .System/g DEO2 |
|
48 |
+ #0f07 .System/b DEO2 |
|
49 |
+ |
|
50 |
+ ( find center ) |
|
51 |
+ .Screen/width DEI2 #01 SFT2 .center/x STZ2 |
|
52 |
+ .Screen/height DEI2 #01 SFT2 .center/y STZ2 |
|
53 |
+ |
|
54 |
+ ( place controller ) |
|
55 |
+ #0068 .frame/w STZ2 |
|
56 |
+ #0030 .frame/h STZ2 |
|
57 |
+ .center/x LDZ2 .frame/w LDZ2 #0002 // -- .frame/x0 STZ2 |
|
58 |
+ .center/y LDZ2 .frame/h LDZ2 #0002 // -- .frame/y0 STZ2 |
|
59 |
+ .frame/x0 LDZ2 .frame/w LDZ2 ++ .frame/x1 STZ2 |
|
60 |
+ .frame/y0 LDZ2 .frame/h LDZ2 ++ .frame/y1 STZ2 |
|
61 |
+ |
|
62 |
+ ( vectors ) |
|
63 |
+ ;on-button .Controller/vector DEO2 |
|
64 |
+ |
|
65 |
+ ;draw-controller JSR2 |
|
66 |
+ |
|
67 |
+BRK |
|
68 |
+ |
|
69 |
+@on-button ( -> ) |
|
70 |
+ |
|
71 |
+ ;draw-controller JSR2 |
|
72 |
+ |
|
73 |
+BRK |
|
74 |
+ |
|
75 |
+@draw-controller ( -- ) |
|
76 |
+ |
|
77 |
+ .Controller/button DEI STH |
|
78 |
+ |
|
79 |
+ ( frame ) |
|
80 |
+ .frame/x0 LDZ2 .frame/y0 LDZ2 |
|
81 |
+ .frame/x1 LDZ2 .frame/y1 LDZ2 |
|
82 |
+ #01 ;line-rect JSR2 |
|
83 |
+ ( d-pad ) |
|
84 |
+ .frame/x0 LDZ2 #0010 ++ .Screen/x DEO2 |
|
85 |
+ .frame/y0 LDZ2 #0010 ++ .Screen/y DEO2 |
|
86 |
+ ;controller-icn/dpad-up .Screen/addr DEO2 |
|
87 |
+ #03 [ STHkr #04 SFT #01 AND #02 * - ] .Screen/sprite DEO |
|
88 |
+ .Screen/y DEI2 #0010 ++ .Screen/y DEO2 |
|
89 |
+ ;controller-icn/dpad-down .Screen/addr DEO2 |
|
90 |
+ #03 [ STHkr #05 SFT #01 AND #02 * - ] .Screen/sprite DEO |
|
91 |
+ .Screen/y DEI2 #0008 -- .Screen/y DEO2 |
|
92 |
+ .Screen/x DEI2 #0008 -- .Screen/x DEO2 |
|
93 |
+ ;controller-icn/dpad-left .Screen/addr DEO2 |
|
94 |
+ #03 [ STHkr #06 SFT #01 AND #02 * - ] .Screen/sprite DEO |
|
95 |
+ .Screen/x DEI2 #0010 ++ .Screen/x DEO2 |
|
96 |
+ ;controller-icn/dpad-right .Screen/addr DEO2 |
|
97 |
+ #03 [ STHkr #07 SFT #01 AND #02 * - ] .Screen/sprite DEO |
|
98 |
+ .Screen/x DEI2 #0008 -- .Screen/x DEO2 |
|
99 |
+ ;controller-icn/dpad .Screen/addr DEO2 |
|
100 |
+ #03 .Screen/sprite DEO |
|
101 |
+ |
|
102 |
+ ( options ) |
|
103 |
+ .center/y LDZ2 #0009 ++ .Screen/y DEO2 |
|
104 |
+ .center/x LDZ2 #0009 -- .Screen/x DEO2 |
|
105 |
+ ;controller-icn/option .Screen/addr DEO2 |
|
106 |
+ #03 [ STHkr #02 SFT #01 AND #02 * - ] .Screen/sprite DEO |
|
107 |
+ .center/x LDZ2 #0004 ++ .Screen/x DEO2 |
|
108 |
+ ;controller-icn/option .Screen/addr DEO2 |
|
109 |
+ #03 [ STHkr #03 SFT #01 AND #02 * - ] .Screen/sprite DEO |
|
110 |
+ |
|
111 |
+ ( buttons ) |
|
112 |
+ .center/y LDZ2 #0000 ++ .Screen/y DEO2 |
|
113 |
+ .center/x LDZ2 #0018 ++ .Screen/x DEO2 |
|
114 |
+ ;controller-icn/button .Screen/addr DEO2 |
|
115 |
+ #03 [ STHkr #01 SFT #01 AND - ] .Screen/sprite DEO |
|
116 |
+ .Screen/y DEI2 #000a ++ .Screen/y DEO2 |
|
117 |
+ ;font-hex #000b #0008 ** ++ .Screen/addr DEO2 |
|
118 |
+ #03 .Screen/sprite DEO |
|
119 |
+ |
|
120 |
+ .center/y LDZ2 #0000 ++ .Screen/y DEO2 |
|
121 |
+ .center/x LDZ2 #0024 ++ .Screen/x DEO2 |
|
122 |
+ ;controller-icn/button .Screen/addr DEO2 |
|
123 |
+ #03 [ STHr #01 AND - ] .Screen/sprite DEO |
|
124 |
+ .Screen/y DEI2 #000a ++ .Screen/y DEO2 |
|
125 |
+ ;font-hex #000a #0008 ** ++ .Screen/addr DEO2 |
|
126 |
+ #03 .Screen/sprite DEO |
|
127 |
+ |
|
128 |
+ .center/x LDZ2 #0010 -- .Screen/x DEO2 |
|
129 |
+ .center/y LDZ2 #0010 -- .Screen/y DEO2 |
|
130 |
+ .Controller/button DEI2 #03 ;draw-short JSR2 |
|
131 |
+ |
|
132 |
+RTN |
|
133 |
+ |
|
134 |
+( generics ) |
|
135 |
+ |
|
136 |
+@draw-short ( short* color -- ) |
|
137 |
+ |
|
138 |
+ STH SWP |
|
139 |
+ DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 |
|
140 |
+ ( draw ) STHkr .Screen/sprite DEO |
|
141 |
+ #0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 |
|
142 |
+ .Screen/x DEI2 #0008 ++ .Screen/x DEO2 |
|
143 |
+ ( draw ) STHkr .Screen/sprite DEO |
|
144 |
+ DUP #04 SFT TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 |
|
145 |
+ .Screen/x DEI2 #0008 ++ .Screen/x DEO2 |
|
146 |
+ ( draw ) STHkr .Screen/sprite DEO |
|
147 |
+ #0f AND TOS #0008 ** ;font-hex ++ .Screen/addr DEO2 |
|
148 |
+ .Screen/x DEI2 #0008 ++ .Screen/x DEO2 |
|
149 |
+ ( draw ) STHr .Screen/sprite DEO |
|
150 |
+ |
|
151 |
+RTN |
|
152 |
+ |
|
153 |
+@line-rect ( x1* y1* x2* y2* color -- ) |
|
154 |
+ |
|
155 |
+ ( load ) .color STZ DUP2 STH2 .rect/y2 STZ2 .rect/x2 STZ2 DUP2 STH2 .rect/y1 STZ2 .rect/x1 STZ2 |
|
156 |
+ STH2r #0001 ++ STH2r |
|
157 |
+ &ver |
|
158 |
+ ( save ) OVR2 .Screen/y DEO2 |
|
159 |
+ ( draw ) .rect/x1 LDZ2 .Screen/x DEO2 .color LDZ DUP .Screen/pixel DEO |
|
160 |
+ ( draw ) .rect/x2 LDZ2 .Screen/x DEO2 .Screen/pixel DEO |
|
161 |
+ ( incr ) SWP2 #0001 ++ SWP2 |
|
162 |
+ OVR2 OVR2 LTS2 ,&ver JCN |
|
163 |
+ POP2 POP2 |
|
164 |
+ .rect/x1 LDZ2 #0001 ++ .rect/x2 LDZ2 #0001 -- |
|
165 |
+ &hor |
|
166 |
+ ( save ) OVR2 .Screen/x DEO2 |
|
167 |
+ ( draw ) .rect/y1 LDZ2 .Screen/y DEO2 .color LDZ DUP .Screen/pixel DEO |
|
168 |
+ ( draw ) .rect/y2 LDZ2 .Screen/y DEO2 .Screen/pixel DEO |
|
169 |
+ ( incr ) SWP2 #0001 ++ SWP2 |
|
170 |
+ OVR2 OVR2 #0001 ++ LTS2 ,&hor JCN |
|
171 |
+ POP2 POP2 |
|
172 |
+ |
|
173 |
+RTN |
|
174 |
+ |
|
175 |
+@print-hex ( value -- ) |
|
176 |
+ |
|
177 |
+ STHk #04 SFT ,&parse JSR .Console/write DEO |
|
178 |
+ STHr #0f AND ,&parse JSR .Console/write DEO |
|
179 |
+ RTN |
|
180 |
+ &parse ( value -- char ) |
|
181 |
+ DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN |
|
182 |
+ |
|
183 |
+RTN |
|
184 |
+ |
|
185 |
+@controller-icn |
|
186 |
+ &dpad ffff ffff ffff ffff |
|
187 |
+ &dpad-up 7eff e7c3 ffff ffff |
|
188 |
+ &dpad-down ffff ffff c3e7 ff7e |
|
189 |
+ &dpad-left 7fff efcf cfef ff7f |
|
190 |
+ &dpad-right feff f7f3 f3f7 fffe |
|
191 |
+ &option 0000 7eff ff7e 0000 |
|
192 |
+ &button 3c7e ffff ffff 7e3c |
|
193 |
+ |
|
194 |
+@font-hex |
|
195 |
+ 003c 4242 4242 3c00 0018 0808 0808 1c00 |
|
196 |
+ 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
197 |
+ 000c 1424 447e 0400 007e 407c 0242 3c00 |
|
198 |
+ 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
199 |
+ 003c 423c 4242 3c00 003c 4242 3e02 3c00 |
|
200 |
+ 003c 4242 7e42 4200 007c 427c 4242 7c00 |
|
201 |
+ 003c 4240 4042 3c00 007c 4242 4242 7c00 |
|
202 |
+ 007e 4078 4040 7e00 007e 4078 4040 4000 |