| ... | ... |
@@ -20,6 +20,8 @@ then |
| 20 | 20 |
clang-format -i src/devices/apu.c |
| 21 | 21 |
clang-format -i src/devices/file.h |
| 22 | 22 |
clang-format -i src/devices/file.c |
| 23 |
+ clang-format -i src/devices/mouse.h |
|
| 24 |
+ clang-format -i src/devices/mouse.c |
|
| 23 | 25 |
clang-format -i src/uxnasm.c |
| 24 | 26 |
clang-format -i src/uxnemu.c |
| 25 | 27 |
clang-format -i src/uxncli.c |
| ... | ... |
@@ -62,7 +64,7 @@ fi |
| 62 | 64 |
|
| 63 | 65 |
echo "Building.." |
| 64 | 66 |
${CC} ${CFLAGS} src/uxnasm.c -o bin/uxnasm
|
| 65 |
-${CC} ${CFLAGS} ${CORE} src/devices/file.c src/devices/ppu.c src/devices/apu.c src/uxnemu.c ${EXTRA} ${UXNEMU_LDFLAGS} -o bin/uxnemu
|
|
| 67 |
+${CC} ${CFLAGS} ${CORE} src/devices/file.c src/devices/mouse.c src/devices/ppu.c src/devices/apu.c src/uxnemu.c ${EXTRA} ${UXNEMU_LDFLAGS} -o bin/uxnemu
|
|
| 66 | 68 |
${CC} ${CFLAGS} ${CORE} src/devices/file.c src/uxncli.c -o bin/uxncli
|
| 67 | 69 |
|
| 68 | 70 |
if [ -d "$HOME/bin" ] |
| 69 | 71 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,44 @@ |
| 1 |
+#include "../uxn.h" |
|
| 2 |
+#include "mouse.h" |
|
| 3 |
+ |
|
| 4 |
+/* |
|
| 5 |
+Copyright (c) 2021 Devine Lu Linvega |
|
| 6 |
+Copyright (c) 2021 Andrew Alderwick |
|
| 7 |
+ |
|
| 8 |
+Permission to use, copy, modify, and distribute this software for any |
|
| 9 |
+purpose with or without fee is hereby granted, provided that the above |
|
| 10 |
+copyright notice and this permission notice appear in all copies. |
|
| 11 |
+ |
|
| 12 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
| 13 |
+WITH REGARD TO THIS SOFTWARE. |
|
| 14 |
+*/ |
|
| 15 |
+ |
|
| 16 |
+void |
|
| 17 |
+mouse_xy(Device *d, Uint16 x, Uint16 y) |
|
| 18 |
+{
|
|
| 19 |
+ poke16(d->dat, 0x2, x); |
|
| 20 |
+ poke16(d->dat, 0x4, y); |
|
| 21 |
+ uxn_eval(d->u, d->vector); |
|
| 22 |
+} |
|
| 23 |
+ |
|
| 24 |
+void |
|
| 25 |
+mouse_z(Device *d, Uint8 z) |
|
| 26 |
+{
|
|
| 27 |
+ d->dat[7] = z; |
|
| 28 |
+ uxn_eval(d->u, d->vector); |
|
| 29 |
+ d->dat[7] = 0x00; |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+void |
|
| 33 |
+mouse_down(Device *d, Uint8 mask) |
|
| 34 |
+{
|
|
| 35 |
+ d->dat[6] |= mask; |
|
| 36 |
+ uxn_eval(d->u, d->vector); |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+void |
|
| 40 |
+mouse_up(Device *d, Uint8 mask) |
|
| 41 |
+{
|
|
| 42 |
+ d->dat[6] &= (~mask); |
|
| 43 |
+ uxn_eval(d->u, d->vector); |
|
| 44 |
+} |
|
| 0 | 45 |
\ No newline at end of file |
| 1 | 46 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,16 @@ |
| 1 |
+/* |
|
| 2 |
+Copyright (c) 2021 Devine Lu Linvega |
|
| 3 |
+Copyright (c) 2021 Andrew Alderwick |
|
| 4 |
+ |
|
| 5 |
+Permission to use, copy, modify, and distribute this software for any |
|
| 6 |
+purpose with or without fee is hereby granted, provided that the above |
|
| 7 |
+copyright notice and this permission notice appear in all copies. |
|
| 8 |
+ |
|
| 9 |
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
| 10 |
+WITH REGARD TO THIS SOFTWARE. |
|
| 11 |
+*/ |
|
| 12 |
+ |
|
| 13 |
+void mouse_xy(Device *d, Uint16 x, Uint16 y); |
|
| 14 |
+void mouse_z(Device *d, Uint8 z); |
|
| 15 |
+void mouse_down(Device *d, Uint8 mask); |
|
| 16 |
+void mouse_up(Device *d, Uint8 mask); |
| ... | ... |
@@ -11,6 +11,7 @@ |
| 11 | 11 |
#include "devices/ppu.h" |
| 12 | 12 |
#include "devices/apu.h" |
| 13 | 13 |
#include "devices/file.h" |
| 14 |
+#include "devices/mouse.h" |
|
| 14 | 15 |
#pragma GCC diagnostic pop |
| 15 | 16 |
#pragma clang diagnostic pop |
| 16 | 17 |
|
| ... | ... |
@@ -196,33 +197,6 @@ init(void) |
| 196 | 197 |
return 1; |
| 197 | 198 |
} |
| 198 | 199 |
|
| 199 |
-static void |
|
| 200 |
-domouse(SDL_Event *event) |
|
| 201 |
-{
|
|
| 202 |
- Uint8 flag = 0x00; |
|
| 203 |
- Uint16 x = clamp(event->motion.x - PAD, 0, ppu.width - 1); |
|
| 204 |
- Uint16 y = clamp(event->motion.y - PAD, 0, ppu.height - 1); |
|
| 205 |
- if(event->type == SDL_MOUSEWHEEL) {
|
|
| 206 |
- devmouse->dat[7] = event->wheel.y; |
|
| 207 |
- return; |
|
| 208 |
- } |
|
| 209 |
- poke16(devmouse->dat, 0x2, x); |
|
| 210 |
- poke16(devmouse->dat, 0x4, y); |
|
| 211 |
- devmouse->dat[7] = 0x00; |
|
| 212 |
- switch(event->button.button) {
|
|
| 213 |
- case SDL_BUTTON_LEFT: flag = 0x01; break; |
|
| 214 |
- case SDL_BUTTON_RIGHT: flag = 0x10; break; |
|
| 215 |
- } |
|
| 216 |
- switch(event->type) {
|
|
| 217 |
- case SDL_MOUSEBUTTONDOWN: |
|
| 218 |
- devmouse->dat[6] |= flag; |
|
| 219 |
- break; |
|
| 220 |
- case SDL_MOUSEBUTTONUP: |
|
| 221 |
- devmouse->dat[6] &= (~flag); |
|
| 222 |
- break; |
|
| 223 |
- } |
|
| 224 |
-} |
|
| 225 |
- |
|
| 226 | 200 |
#pragma mark - Devices |
| 227 | 201 |
|
| 228 | 202 |
static Uint8 |
| ... | ... |
@@ -494,7 +468,6 @@ run(Uxn *u) |
| 494 | 468 |
doctrl(u, &event, event.type == SDL_KEYDOWN); |
| 495 | 469 |
uxn_eval(u, devctrl->vector); |
| 496 | 470 |
devctrl->dat[3] = 0; |
| 497 |
- |
|
| 498 | 471 |
if(event.type == SDL_KEYDOWN) {
|
| 499 | 472 |
ksym = event.key.keysym.sym; |
| 500 | 473 |
if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym) |
| ... | ... |
@@ -502,11 +475,18 @@ run(Uxn *u) |
| 502 | 475 |
} |
| 503 | 476 |
break; |
| 504 | 477 |
case SDL_MOUSEWHEEL: |
| 478 |
+ mouse_z(devmouse, event.wheel.y); |
|
| 479 |
+ break; |
|
| 505 | 480 |
case SDL_MOUSEBUTTONUP: |
| 481 |
+ mouse_up(devmouse, 0x1 << (event.button.button - 1)); |
|
| 482 |
+ break; |
|
| 506 | 483 |
case SDL_MOUSEBUTTONDOWN: |
| 484 |
+ mouse_down(devmouse, 0x1 << (event.button.button - 1)); |
|
| 485 |
+ break; |
|
| 507 | 486 |
case SDL_MOUSEMOTION: |
| 508 |
- domouse(&event); |
|
| 509 |
- uxn_eval(u, devmouse->vector); |
|
| 487 |
+ mouse_xy(devmouse, |
|
| 488 |
+ clamp(event.motion.x - PAD, 0, ppu.width - 1), |
|
| 489 |
+ clamp(event.motion.y - PAD, 0, ppu.height - 1)); |
|
| 510 | 490 |
break; |
| 511 | 491 |
case SDL_WINDOWEVENT: |
| 512 | 492 |
if(event.window.event == SDL_WINDOWEVENT_EXPOSED) |