commit 062bbac37df33f55924489fb72a212200ac57eca
parent 6317b5cf181e56253da10e0e5051ac75bbb5c4b2
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 1 Jan 2023 11:31:14 -0800
Removed Device struct from mouse device
Diffstat:
4 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/src/devices/mouse.c b/src/devices/mouse.c
@@ -2,8 +2,7 @@
#include "mouse.h"
/*
-Copyright (c) 2021 Devine Lu Linvega
-Copyright (c) 2021 Andrew Alderwick
+Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -14,33 +13,33 @@ WITH REGARD TO THIS SOFTWARE.
*/
void
-mouse_down(Device *d, Uint8 mask)
+mouse_down(Uxn *u, Uint8 *d, Uint8 mask)
{
- d->dat[6] |= mask;
- uxn_eval(d->u, GETVECTOR(d));
+ d[6] |= mask;
+ uxn_eval(u, GETVEC(d));
}
void
-mouse_up(Device *d, Uint8 mask)
+mouse_up(Uxn *u, Uint8 *d, Uint8 mask)
{
- d->dat[6] &= (~mask);
- uxn_eval(d->u, GETVECTOR(d));
+ d[6] &= (~mask);
+ uxn_eval(u, GETVEC(d));
}
void
-mouse_pos(Device *d, Uint16 x, Uint16 y)
+mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
- DEVPOKE16(0x2, x);
- DEVPOKE16(0x4, y);
- uxn_eval(d->u, GETVECTOR(d));
+ POKDEV(0x2, x);
+ POKDEV(0x4, y);
+ uxn_eval(u, GETVEC(d));
}
void
-mouse_scroll(Device *d, Uint16 x, Uint16 y)
+mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y)
{
- DEVPOKE16(0xa, x);
- DEVPOKE16(0xc, -y);
- uxn_eval(d->u, GETVECTOR(d));
- DEVPOKE16(0xa, 0);
- DEVPOKE16(0xc, 0);
+ POKDEV(0xa, x);
+ POKDEV(0xc, -y);
+ uxn_eval(u, GETVEC(d));
+ POKDEV(0xa, 0);
+ POKDEV(0xc, 0);
}
diff --git a/src/devices/mouse.h b/src/devices/mouse.h
@@ -1,6 +1,5 @@
/*
-Copyright (c) 2021 Devine Lu Linvega
-Copyright (c) 2021 Andrew Alderwick
+Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
Permission to use, copy, modify, and distribute this software for any
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
WITH REGARD TO THIS SOFTWARE.
*/
-void mouse_down(Device *d, Uint8 mask);
-void mouse_up(Device *d, Uint8 mask);
-void mouse_pos(Device *d, Uint16 x, Uint16 y);
-void mouse_scroll(Device *d, Uint16 x, Uint16 y);
+void mouse_down(Uxn *u, Uint8 *d, Uint8 mask);
+void mouse_up(Uxn *u, Uint8 *d, Uint8 mask);
+void mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);
+void mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y);
diff --git a/src/uxn.h b/src/uxn.h
@@ -26,6 +26,12 @@ typedef unsigned int Uint32;
#define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); }
#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1])
+/* new macros */
+
+#define GETVEC(d) ((d)[0] << 8 | (d)[1])
+#define POKDEV(x, y) { d[(x)] = (y) >> 8; d[(x) + 1] = (y); }
+#define PEKDEV(o, x) { (o) = (d[(x)] << 8) + d[(x) + 1]; }
+
/* clang-format on */
typedef struct {
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -402,15 +402,13 @@ handle_events(Uxn *u)
}
/* Mouse */
else if(event.type == SDL_MOUSEMOTION)
- mouse_pos(devmouse,
- clamp(event.motion.x - PAD, 0, uxn_screen.width - 1),
- clamp(event.motion.y - PAD, 0, uxn_screen.height - 1));
+ 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));
else if(event.type == SDL_MOUSEBUTTONUP)
- mouse_up(devmouse, SDL_BUTTON(event.button.button));
+ mouse_up(u, devmouse->dat, SDL_BUTTON(event.button.button));
else if(event.type == SDL_MOUSEBUTTONDOWN)
- mouse_down(devmouse, SDL_BUTTON(event.button.button));
+ mouse_down(u, devmouse->dat, SDL_BUTTON(event.button.button));
else if(event.type == SDL_MOUSEWHEEL)
- mouse_scroll(devmouse, event.wheel.x, event.wheel.y);
+ mouse_scroll(u, devmouse->dat, event.wheel.x, event.wheel.y);
/* Controller */
else if(event.type == SDL_TEXTINPUT)
controller_key(devctrl, event.text.text[0]);