... | ... |
@@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr |
20 | 20 |
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator |
21 | 21 |
|
22 | 22 |
# run |
23 |
-./bin/assembler examples/devmouse.usm bin/boot.rom |
|
23 |
+./bin/assembler examples/devchord.usm bin/boot.rom |
|
24 | 24 |
./bin/emulator bin/boot.rom |
... | ... |
@@ -258,22 +258,27 @@ init(void) |
258 | 258 |
void |
259 | 259 |
domouse(SDL_Event *event) |
260 | 260 |
{ |
261 |
+ Uint8 flag = 0x00; |
|
261 | 262 |
int x = clamp((event->motion.x - PAD * 8 * ZOOM) / ZOOM, 0, WIDTH - 1); |
262 | 263 |
int y = clamp((event->motion.y - PAD * 8 * ZOOM) / ZOOM, 0, HEIGHT - 1); |
263 |
- devmouse->mem[0] = (x >> 8) & 0xff; |
|
264 | 264 |
devmouse->mem[1] = x & 0xff; |
265 | 265 |
devmouse->mem[2] = (y >> 8) & 0xff; |
266 | 266 |
devmouse->mem[3] = y & 0xff; |
267 |
- devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT; |
|
268 | 267 |
devmouse->mem[5] = 0x00; |
268 |
+ switch(event->button.button) { |
|
269 |
+ case SDL_BUTTON_LEFT: flag = 0x01; break; |
|
270 |
+ case SDL_BUTTON_RIGHT: flag = 0x10; break; |
|
271 |
+ } |
|
269 | 272 |
switch(event->type) { |
270 | 273 |
case SDL_MOUSEBUTTONUP: |
271 |
- devmouse->mem[4] = 0; |
|
272 |
- devmouse->mem[5] = 0x10; |
|
274 |
+ setflag(&devmouse->mem[4], flag, 0); |
|
273 | 275 |
break; |
274 | 276 |
case SDL_MOUSEBUTTONDOWN: |
275 |
- devmouse->mem[4] = event->button.button == SDL_BUTTON_LEFT; |
|
276 |
- devmouse->mem[5] = 0x01; |
|
277 |
+ setflag(&devmouse->mem[4], flag, 1); |
|
278 |
+ if(flag == 0x01 && getflag(&devmouse->mem[4], 0x10)) |
|
279 |
+ devmouse->mem[5] = 0x01; |
|
280 |
+ if(flag == 0x10 && getflag(&devmouse->mem[4], 0x01)) |
|
281 |
+ devmouse->mem[5] = 0x10; |
|
277 | 282 |
break; |
278 | 283 |
} |
279 | 284 |
} |
280 | 285 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,234 @@ |
1 |
+( mouse ) |
|
2 |
+ |
|
3 |
+:dev/r fff8 ( std read port ) |
|
4 |
+:dev/w fff9 ( std write port ) |
|
5 |
+ |
|
6 |
+&Point2d { x 2 y 2 } |
|
7 |
+ |
|
8 |
+;pos Point2d |
|
9 |
+;mouse Point2d |
|
10 |
+;scenter Point2d |
|
11 |
+ |
|
12 |
+( drawing ) ;color 1 ;x1 2 ;x2 2 ;y1 2 ;y2 2 ;i 2 |
|
13 |
+( window ) ;wx1 2 ;wy1 2 ;wx2 2 ;wy2 2 |
|
14 |
+;state 1 |
|
15 |
+ |
|
16 |
+|0100 @RESET |
|
17 |
+ |
|
18 |
+ #01 =color |
|
19 |
+ |
|
20 |
+ #01 =dev/r ( read screen for size ) |
|
21 |
+ |
|
22 |
+ #02 =dev/w ( write to screen ) |
|
23 |
+ |
|
24 |
+ ,paint-pattern JSR |
|
25 |
+ |
|
26 |
+ #01 =dev/w ( write to screen ) |
|
27 |
+ |
|
28 |
+ #00 IOR2 #0002 DIV2 =scenter.x |
|
29 |
+ #02 IOR2 #0002 DIV2 =scenter.y |
|
30 |
+ |
|
31 |
+ ~scenter.x #0060 SUB2 |
|
32 |
+ ~scenter.y #0018 SUB2 |
|
33 |
+ ~scenter.x #0060 ADD2 |
|
34 |
+ ~scenter.y #0018 ADD2 ,paint-window JSR |
|
35 |
+ |
|
36 |
+ #05 =dev/r ( set dev/read mouse ) |
|
37 |
+ #02 =dev/w ( set dev/write to sprite ) |
|
38 |
+ |
|
39 |
+ #09 =color |
|
40 |
+ |
|
41 |
+ ,window_name ~scenter.x #0058 SUB2 ~scenter.y #0018 SUB2 ,draw-label JSR |
|
42 |
+ |
|
43 |
+BRK |
|
44 |
+ |
|
45 |
+|c000 @FRAME |
|
46 |
+ |
|
47 |
+ ( clear last cursor ) |
|
48 |
+ #10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
49 |
+ ( record mouse positions ) |
|
50 |
+ #00 IOR2 =mouse.x |
|
51 |
+ #02 IOR2 =mouse.y |
|
52 |
+ #11 =state |
|
53 |
+ |
|
54 |
+ ( detect click ) |
|
55 |
+ #04 IOR #11 NEQ ,no-click12 ROT JMP? POP2 |
|
56 |
+ #10 =state |
|
57 |
+ ,mouse12_text #0040 ~scenter.y ,draw-label JSR |
|
58 |
+ ~color ,mouse12_icn #0030 ~scenter.y ,draw-sprite JSR |
|
59 |
+ ,end-click JSR |
|
60 |
+ @no-click12 |
|
61 |
+ #04 IOR #01 NEQ ,no-click1 ROT JMP? POP2 |
|
62 |
+ #12 =state |
|
63 |
+ ,mouse1_text #0040 ~scenter.y ,draw-label JSR |
|
64 |
+ ~color ,mouse1_icn #0030 ~scenter.y ,draw-sprite JSR |
|
65 |
+ ,end-click JSR |
|
66 |
+ @no-click1 |
|
67 |
+ #04 IOR #10 NEQ ,no-click2 ROT JMP? POP2 |
|
68 |
+ #13 =state |
|
69 |
+ ,mouse2_text #0040 ~scenter.y ,draw-label JSR |
|
70 |
+ ~color ,mouse2_icn #0030 ~scenter.y ,draw-sprite JSR |
|
71 |
+ ,end-click JSR |
|
72 |
+ @no-click2 |
|
73 |
+ ( default ) |
|
74 |
+ ,mouse0_text #0040 ~scenter.y ,draw-label JSR |
|
75 |
+ ~color ,mouse0_icn #0030 ~scenter.y ,draw-sprite JSR |
|
76 |
+ @end-click |
|
77 |
+ |
|
78 |
+ ( detect chord ) |
|
79 |
+ #05 IOR #01 NEQ ,no-chord1 ROT JMP? POP2 |
|
80 |
+ ,chord1_text #0040 ~scenter.y #0008 ADD2 ,draw-label JSR |
|
81 |
+ ,end-chord JSR |
|
82 |
+ @no-chord1 |
|
83 |
+ #05 IOR #10 NEQ ,no-chord2 ROT JMP? POP2 |
|
84 |
+ ,chord2_text #0040 ~scenter.y #0008 ADD2 ,draw-label JSR |
|
85 |
+ ,end-chord JSR |
|
86 |
+ @no-chord2 |
|
87 |
+ ( default ) |
|
88 |
+ ,chord0_text #0040 ~scenter.y #0008 ADD2 ,draw-label JSR |
|
89 |
+ @end-chord |
|
90 |
+ |
|
91 |
+ ( draw mouse ) |
|
92 |
+ ~state ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR |
|
93 |
+ |
|
94 |
+BRK |
|
95 |
+ |
|
96 |
+@paint-pattern ( nil ) |
|
97 |
+ |
|
98 |
+ #01 =dev/r ( read screen for size ) |
|
99 |
+ #02 =dev/w ( write to sprite ) |
|
100 |
+ |
|
101 |
+ #0000 |
|
102 |
+ @paint-pattern-loop-hor |
|
103 |
+ #0000 |
|
104 |
+ @paint-pattern-loop |
|
105 |
+ ( draw ) OVR2 IOW2 DUP2 IOW2 ,pattern IOW2 #01 IOW |
|
106 |
+ ( incr ) #0008 ADD2 DUP2 |
|
107 |
+ #00 IOR2 LTH2 ,paint-pattern-loop ROT JMP? POP2 |
|
108 |
+ POP2 |
|
109 |
+ ( incr ) #0008 ADD2 DUP2 |
|
110 |
+ #02 IOR2 LTH2 ,paint-pattern-loop-hor ROT JMP? POP2 |
|
111 |
+ POP2 |
|
112 |
+ |
|
113 |
+RTS |
|
114 |
+ |
|
115 |
+@paint-window ( name wx1 wy1 wx2 wy2 ) |
|
116 |
+ |
|
117 |
+ =wy2 =wx2 =wy1 =wx1 |
|
118 |
+ |
|
119 |
+ ( Draw background ) |
|
120 |
+ #00 =color |
|
121 |
+ ~wx1 #0003 ADD2 ~wy1 #0003 ADD2 ~wx2 #0003 ADD2 ~wy2 #0003 ADD2 ,fill-rect JSR |
|
122 |
+ #02 =color |
|
123 |
+ ~wx1 ~wy1 ~wx2 ~wy2 ,fill-rect JSR |
|
124 |
+ ( draw outline ) |
|
125 |
+ #01 =color |
|
126 |
+ ~wx1 ~wy1 ~wx2 ~wy2 ,line-rect JSR |
|
127 |
+ #01 =color |
|
128 |
+ ~wx1 #0002 ADD2 ~wy1 #0002 ADD2 ~wx2 #0002 SUB2 ~wy2 #0002 SUB2 ,line-rect JSR |
|
129 |
+ |
|
130 |
+RTS |
|
131 |
+ |
|
132 |
+@draw-label ( text x1 y1 ) |
|
133 |
+ =pos.y =pos.x |
|
134 |
+ @draw-label-loop |
|
135 |
+ ( draw ) ~pos.x ~pos.y IOW2 IOW2 DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 IOW2 ~color IOW |
|
136 |
+ ( incr ) #0001 ADD2 |
|
137 |
+ ( incr ) ~pos.x #0008 ADD2 =pos.x |
|
138 |
+ DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2 |
|
139 |
+ POP2 |
|
140 |
+RTS |
|
141 |
+ |
|
142 |
+@fill-rect ( x1 y1 x2 y2 ) |
|
143 |
+ =y2 =x2 ( stash x1 y1 ) =y1 DUP2 WSR2 =x1 |
|
144 |
+ @fill-rect-ver |
|
145 |
+ RSW2 DUP2 =x1 WSR2 |
|
146 |
+ @fill-rect-hor |
|
147 |
+ ( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW |
|
148 |
+ ( incr ) ~x1 #0001 ADD2 DUP2 =x1 |
|
149 |
+ ~x2 LTH2 ,fill-rect-hor ROT JMP? POP2 |
|
150 |
+ ~y1 #0001 ADD2 DUP2 =y1 |
|
151 |
+ ~y2 LTH2 ,fill-rect-ver ROT JMP? POP2 |
|
152 |
+ RSW2 POP2 |
|
153 |
+RTS |
|
154 |
+ |
|
155 |
+@line-rect ( x1 y1 x2 y2 ) |
|
156 |
+ =y2 =x2 ( stash x1 y1 ) DUP2 WSR2 =y1 DUP2 WSR2 =x1 |
|
157 |
+ @line-rect-hor |
|
158 |
+ ( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW |
|
159 |
+ ( draw ) ~x1 ~y2 IOW2 IOW2 ~color IOW |
|
160 |
+ ( incr ) ~x1 #0001 ADD2 DUP2 =x1 |
|
161 |
+ ~x2 #0001 ADD2 LTH2 ,line-rect-hor ROT JMP? POP2 |
|
162 |
+ ( restore x1 y1 ) RSW2 =x1 RSW2 =y1 |
|
163 |
+ @line-rect-ver |
|
164 |
+ ( incr ) ~y1 #0001 ADD2 DUP2 =y1 |
|
165 |
+ ( draw ) ~x1 ~y1 IOW2 IOW2 ~color IOW |
|
166 |
+ ( draw ) ~x2 ~y1 IOW2 IOW2 ~color IOW |
|
167 |
+ ~y2 #0001 SUB2 LTH2 ,line-rect-ver ROT JMP? POP2 |
|
168 |
+RTS |
|
169 |
+ |
|
170 |
+@draw-sprite |
|
171 |
+ IOW2 ( y byte ) |
|
172 |
+ IOW2 ( x byte ) |
|
173 |
+ IOW2 ( sprite address ) |
|
174 |
+ IOW ( layer-color ) |
|
175 |
+ RTS |
|
176 |
+ |
|
177 |
+@pattern [ 0814 2241 8041 2214 ] |
|
178 |
+ |
|
179 |
+@clear_icn [ 0000 0000 0000 0000 ] |
|
180 |
+@cursor_icn [ 80c0 e0f0 f8e0 1000 ] |
|
181 |
+ |
|
182 |
+@mouse0_icn [ 7c82 92ee 8282 4438 ] |
|
183 |
+@mouse1_icn [ 7cf2 f2ee 8282 4438 ] |
|
184 |
+@mouse2_icn [ 7c9e 9eee 8282 4438 ] |
|
185 |
+@mouse12_icn [ 7cfe feee 8282 4438 ] |
|
186 |
+ |
|
187 |
+@font ( spectrum-zx font ) |
|
188 |
+[ |
|
189 |
+ 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 |
|
190 |
+ 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 |
|
191 |
+ 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 |
|
192 |
+ 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 |
|
193 |
+ 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 |
|
194 |
+ 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 |
|
195 |
+ 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 |
|
196 |
+ 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 |
|
197 |
+ 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 |
|
198 |
+ 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 |
|
199 |
+ 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 |
|
200 |
+ 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 |
|
201 |
+ 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
202 |
+ 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
203 |
+ 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 |
|
204 |
+ 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 |
|
205 |
+ 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 |
|
206 |
+ 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 |
|
207 |
+ 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 |
|
208 |
+ 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 |
|
209 |
+ 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 |
|
210 |
+ 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 |
|
211 |
+ 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 |
|
212 |
+ 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 |
|
213 |
+ 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 |
|
214 |
+ 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c |
|
215 |
+ 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 |
|
216 |
+ 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 |
|
217 |
+ 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 |
|
218 |
+ 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 |
|
219 |
+ 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 |
|
220 |
+ 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c |
|
221 |
+] |
|
222 |
+ |
|
223 |
+@chord0_text [ no chord ] <1 .00 |
|
224 |
+@chord1_text [ chord 1_ ] <1 .00 |
|
225 |
+@chord2_text [ chord _2 ] <1 .00 |
|
226 |
+@mouse0_text [ no click ] <1 .00 |
|
227 |
+@mouse1_text [ mouse 1_ ] <1 .00 |
|
228 |
+@mouse2_text [ mouse _2 ] <1 .00 |
|
229 |
+@mouse12_text [ mouse 12 ] <1 .00 |
|
230 |
+@window_name [ mouse test ] <1 .00 |
|
231 |
+ |
|
232 |
+|d000 @ERROR BRK |
|
233 |
+|FFF0 [ 25fd c3d2 a7bf ] ( palette ) |
|
234 |
+|FFFA .RESET .FRAME .ERROR |
... | ... |
@@ -77,7 +77,7 @@ RTS |
77 | 77 |
|
78 | 78 |
RTS |
79 | 79 |
|
80 |
-@paint-window ( wx1 wy1 wx2 wy2 ) |
|
80 |
+@paint-window ( name wx1 wy1 wx2 wy2 ) |
|
81 | 81 |
|
82 | 82 |
=wy2 =wx2 =wy1 =wx1 =wname |
83 | 83 |
|
... | ... |
@@ -167,6 +167,7 @@ RTS |
167 | 167 |
( incr ) #0001 ADD2 |
168 | 168 |
( incr ) ~x1 #0008 ADD2 =x1 |
169 | 169 |
DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2 |
170 |
+ POP2 |
|
170 | 171 |
RTS |
171 | 172 |
|
172 | 173 |
@texture [ aa55 aa55 aa55 aa55 ] |