Browse code

Removed Device struct from mouse device

Devine Lu Linvega authored on 01/01/2023 19:31:14
Showing 4 changed files
... ...
@@ -2,8 +2,7 @@
2 2
 #include "mouse.h"
3 3
 
4 4
 /*
5
-Copyright (c) 2021 Devine Lu Linvega
6
-Copyright (c) 2021 Andrew Alderwick
5
+Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
7 6
 
8 7
 Permission to use, copy, modify, and distribute this software for any
9 8
 purpose with or without fee is hereby granted, provided that the above
... ...
@@ -14,33 +13,33 @@ WITH REGARD TO THIS SOFTWARE.
14 13
 */
15 14
 
16 15
 void
17
-mouse_down(Device *d, Uint8 mask)
16
+mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
18 17
 {
19
-	d->dat[6] |= mask;
20
-	uxn_eval(d->u, GETVECTOR(d));
18
+	d[6] |= mask;
19
+	uxn_eval(u, GETVEC(d));
21 20
 }
22 21
 
23 22
 void
24
-mouse_up(Device *d, Uint8 mask)
23
+mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
25 24
 {
26
-	d->dat[6] &= (~mask);
27
-	uxn_eval(d->u, GETVECTOR(d));
25
+	d[6] &= (~mask);
26
+	uxn_eval(u, GETVEC(d));
28 27
 }
29 28
 
30 29
 void
31
-mouse_pos(Device *d, Uint16 x, Uint16 y)
30
+mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
32 31
 {
33
-	DEVPOKE16(0x2, x);
34
-	DEVPOKE16(0x4, y);
35
-	uxn_eval(d->u, GETVECTOR(d));
32
+	POKDEV(0x2, x);
33
+	POKDEV(0x4, y);
34
+	uxn_eval(u, GETVEC(d));
36 35
 }
37 36
 
38 37
 void
39
-mouse_scroll(Device *d, Uint16 x, Uint16 y)
38
+mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
40 39
 {
41
-	DEVPOKE16(0xa, x);
42
-	DEVPOKE16(0xc, -y);
43
-	uxn_eval(d->u, GETVECTOR(d));
44
-	DEVPOKE16(0xa, 0);
45
-	DEVPOKE16(0xc, 0);
40
+	POKDEV(0xa, x);
41
+	POKDEV(0xc, -y);
42
+	uxn_eval(u, GETVEC(d));
43
+	POKDEV(0xa, 0);
44
+	POKDEV(0xc, 0);
46 45
 }
... ...
@@ -1,6 +1,5 @@
1 1
 /*
2
-Copyright (c) 2021 Devine Lu Linvega
3
-Copyright (c) 2021 Andrew Alderwick
2
+Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
4 3
 
5 4
 Permission to use, copy, modify, and distribute this software for any
6 5
 purpose with or without fee is hereby granted, provided that the above
... ...
@@ -10,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 9
 WITH REGARD TO THIS SOFTWARE.
11 10
 */
12 11
 
13
-void mouse_down(Device *d, Uint8 mask);
14
-void mouse_up(Device *d, Uint8 mask);
15
-void mouse_pos(Device *d, Uint16 x, Uint16 y);
16
-void mouse_scroll(Device *d, Uint16 x, Uint16 y);
12
+void mouse_down(Uxn *u, Uint8 *d, Uint8 mask);
13
+void mouse_up(Uxn *u, Uint8 *d, Uint8 mask);
14
+void mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);
15
+void mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);
... ...
@@ -26,6 +26,12 @@ typedef unsigned int Uint32;
26 26
 #define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
27 27
 #define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
28 28
 
29
+/* new macros */
30
+
31
+#define GETVEC(d) ((d)[0] << 8 | (d)[1])
32
+#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
33
+#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
34
+
29 35
 /* clang-format on */
30 36
 
31 37
 typedef struct {
... ...
@@ -402,15 +402,13 @@ handle_events(Uxn *u)
402 402
 		}
403 403
 		/* Mouse */
404 404
 		else if(event.type == SDL_MOUSEMOTION)
405
-			mouse_pos(devmouse,
406
-				clamp(event.motion.x - PAD, 0, uxn_screen.width - 1),
407
-				clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
405
+			mouse_pos(u, devmouse->dat, clamp(event.motion.x - PAD, 0, uxn_screen.width - 1), clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
408 406
 		else if(event.type == SDL_MOUSEBUTTONUP)
409
-			mouse_up(devmouse, SDL_BUTTON(event.button.button));
407
+			mouse_up(u, devmouse->dat, SDL_BUTTON(event.button.button));
410 408
 		else if(event.type == SDL_MOUSEBUTTONDOWN)
411
-			mouse_down(devmouse, SDL_BUTTON(event.button.button));
409
+			mouse_down(u, devmouse->dat, SDL_BUTTON(event.button.button));
412 410
 		else if(event.type == SDL_MOUSEWHEEL)
413
-			mouse_scroll(devmouse, event.wheel.x, event.wheel.y);
411
+			mouse_scroll(u, devmouse->dat, event.wheel.x, event.wheel.y);
414 412
 		/* Controller */
415 413
 		else if(event.type == SDL_TEXTINPUT)
416 414
 			controller_key(devctrl, event.text.text[0]);