Do not pass memory in mouse device

This commit is contained in:
Devine Lu Linvega 2024-06-30 21:21:01 -08:00
parent 776b355ee3
commit 8d73001e86
3 changed files with 27 additions and 27 deletions

View File

@ -13,33 +13,33 @@ WITH REGARD TO THIS SOFTWARE.
*/ */
void void
mouse_down(Uint8 *d, Uint8 mask) mouse_down(Uint8 mask)
{ {
d[6] |= mask; uxn.dev[0x96] |= mask;
uxn_eval(PEEK2(d)); uxn_eval(PEEK2(&uxn.dev[0x90]));
} }
void void
mouse_up(Uint8 *d, Uint8 mask) mouse_up(Uint8 mask)
{ {
d[6] &= (~mask); uxn.dev[0x96] &= (~mask);
uxn_eval(PEEK2(d)); uxn_eval(PEEK2(&uxn.dev[0x90]));
} }
void void
mouse_pos(Uint8 *d, Uint16 x, Uint16 y) mouse_pos(Uint16 x, Uint16 y)
{ {
*(d + 2) = x >> 8, *(d + 3) = x; uxn.dev[0x92] = x >> 8, uxn.dev[0x93] = x;
*(d + 4) = y >> 8, *(d + 5) = y; uxn.dev[0x94] = y >> 8, uxn.dev[0x95] = y;
uxn_eval(PEEK2(d)); uxn_eval(PEEK2(&uxn.dev[0x90]));
} }
void void
mouse_scroll(Uint8 *d, Uint16 x, Uint16 y) mouse_scroll(Uint16 x, Uint16 y)
{ {
*(d + 0xa) = x >> 8, *(d + 0xb) = x; uxn.dev[0x9a] = x >> 8, uxn.dev[0x9b] = x;
*(d + 0xc) = -y >> 8, *(d + 0xd) = -y; uxn.dev[0x9c] = -y >> 8, uxn.dev[0x9d] = -y;
uxn_eval(PEEK2(d)); uxn_eval(PEEK2(&uxn.dev[0x90]));
*(d + 0xa) = 0, *(d + 0xb) = 0; uxn.dev[0x9a] = 0, uxn.dev[0x9b] = 0;
*(d + 0xc) = 0, *(d + 0xd) = 0; uxn.dev[0x9c] = 0, uxn.dev[0x9d] = 0;
} }

View File

@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE. WITH REGARD TO THIS SOFTWARE.
*/ */
void mouse_down(Uint8 *d, Uint8 mask); void mouse_down(Uint8 mask);
void mouse_up(Uint8 *d, Uint8 mask); void mouse_up(Uint8 mask);
void mouse_pos(Uint8 *d, Uint16 x, Uint16 y); void mouse_pos(Uint16 x, Uint16 y);
void mouse_scroll(Uint8 *d, Uint16 x, Uint16 y); void mouse_scroll(Uint16 x, Uint16 y);

View File

@ -170,25 +170,25 @@ emu_event(void)
case ButtonPress: { case ButtonPress: {
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
if(e->button == 4) if(e->button == 4)
mouse_scroll(&uxn.dev[0x90], 0, 1); mouse_scroll(0, 1);
else if(e->button == 5) else if(e->button == 5)
mouse_scroll(&uxn.dev[0x90], 0, -1); mouse_scroll( 0, -1);
else if(e->button == 6) else if(e->button == 6)
mouse_scroll(&uxn.dev[0x90], 1, 0); mouse_scroll(1, 0);
else if(e->button == 7) else if(e->button == 7)
mouse_scroll(&uxn.dev[0x90], -1, 0); mouse_scroll(-1, 0);
else else
mouse_down(&uxn.dev[0x90], 0x1 << (e->button - 1)); mouse_down(0x1 << (e->button - 1));
} break; } break;
case ButtonRelease: { case ButtonRelease: {
XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; XButtonPressedEvent *e = (XButtonPressedEvent *)&ev;
mouse_up(&uxn.dev[0x90], 0x1 << (e->button - 1)); mouse_up(0x1 << (e->button - 1));
} break; } break;
case MotionNotify: { case MotionNotify: {
XMotionEvent *e = (XMotionEvent *)&ev; XMotionEvent *e = (XMotionEvent *)&ev;
int x = clamp((e->x - PAD) / uxn_screen.scale, 0, uxn_screen.width - 1); 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); 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; } break;
} }
} }