From 8d73001e86f8ec3e37debc13a78e62a070f36465 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sun, 30 Jun 2024 21:21:01 -0800 Subject: [PATCH] Do not pass memory in mouse device --- src/devices/mouse.c | 32 ++++++++++++++++---------------- src/devices/mouse.h | 8 ++++---- src/uxn11.c | 14 +++++++------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/devices/mouse.c b/src/devices/mouse.c index b01d5d6..27f725f 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -13,33 +13,33 @@ WITH REGARD TO THIS SOFTWARE. */ void -mouse_down(Uint8 *d, Uint8 mask) +mouse_down(Uint8 mask) { - d[6] |= mask; - uxn_eval(PEEK2(d)); + uxn.dev[0x96] |= mask; + uxn_eval(PEEK2(&uxn.dev[0x90])); } void -mouse_up(Uint8 *d, Uint8 mask) +mouse_up(Uint8 mask) { - d[6] &= (~mask); - uxn_eval(PEEK2(d)); + uxn.dev[0x96] &= (~mask); + uxn_eval(PEEK2(&uxn.dev[0x90])); } void -mouse_pos(Uint8 *d, Uint16 x, Uint16 y) +mouse_pos(Uint16 x, Uint16 y) { - *(d + 2) = x >> 8, *(d + 3) = x; - *(d + 4) = y >> 8, *(d + 5) = y; - uxn_eval(PEEK2(d)); + uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x; + uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y; + uxn_eval(PEEK2(&uxn.dev[0x90])); } void -mouse_scroll(Uint8 *d, Uint16 x, Uint16 y) +mouse_scroll(Uint16 x, Uint16 y) { - *(d + 0xa) = x >> 8, *(d + 0xb) = x; - *(d + 0xc) = -y >> 8, *(d + 0xd) = -y; - uxn_eval(PEEK2(d)); - *(d + 0xa) = 0, *(d + 0xb) = 0; - *(d + 0xc) = 0, *(d + 0xd) = 0; + uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x; + uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y; + uxn_eval(PEEK2(&uxn.dev[0x90])); + uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0; + uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0; } diff --git a/src/devices/mouse.h b/src/devices/mouse.h index 3f13070..7d8ece5 100644 --- a/src/devices/mouse.h +++ b/src/devices/mouse.h @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -void mouse_down(Uint8 *d, Uint8 mask); -void mouse_up(Uint8 *d, Uint8 mask); -void mouse_pos(Uint8 *d, Uint16 x, Uint16 y); -void mouse_scroll(Uint8 *d, Uint16 x, Uint16 y); +void mouse_down(Uint8 mask); +void mouse_up(Uint8 mask); +void mouse_pos(Uint16 x, Uint16 y); +void mouse_scroll(Uint16 x, Uint16 y); diff --git a/src/uxn11.c b/src/uxn11.c index 1ad9a89..37710f1 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -170,25 +170,25 @@ emu_event(void) case ButtonPress: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; if(e->button == 4) - mouse_scroll(&uxn.dev[0x90], 0, 1); + mouse_scroll(0, 1); else if(e->button == 5) - mouse_scroll(&uxn.dev[0x90], 0, -1); + mouse_scroll( 0, -1); else if(e->button == 6) - mouse_scroll(&uxn.dev[0x90], 1, 0); + mouse_scroll(1, 0); else if(e->button == 7) - mouse_scroll(&uxn.dev[0x90], -1, 0); + mouse_scroll(-1, 0); else - mouse_down(&uxn.dev[0x90], 0x1 << (e->button - 1)); + mouse_down(0x1 << (e->button - 1)); } break; case ButtonRelease: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; - mouse_up(&uxn.dev[0x90], 0x1 << (e->button - 1)); + mouse_up(0x1 << (e->button - 1)); } break; case MotionNotify: { XMotionEvent *e = (XMotionEvent *)&ev; int x = clamp((e->x - PAD) / uxn_screen.scale, 0, uxn_screen.width - 1); int y = clamp((e->y - PAD) / uxn_screen.scale, 0, uxn_screen.height - 1); - mouse_pos(&uxn.dev[0x90], x, y); + mouse_pos(x, y); } break; } }