From 3135f61e02f7ac3f3f87b7b14161dc0fe49855db Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 29 Jun 2024 10:55:57 -0800 Subject: [PATCH] Removing uxn core indirection in mouse, datetime --- src/devices/console.h | 2 -- src/devices/controller.c | 12 ++++++------ src/devices/controller.h | 6 +++--- src/devices/datetime.c | 4 ++-- src/devices/datetime.h | 2 +- src/devices/mouse.c | 16 ++++++++-------- src/devices/mouse.h | 10 ++++------ src/uxn11.c | 22 +++++++++++----------- src/uxncli.c | 2 +- 9 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/devices/console.h b/src/devices/console.h index 679b4e0..bb57577 100644 --- a/src/devices/console.h +++ b/src/devices/console.h @@ -9,8 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -#define CONSOLE_VERSION 1 - #define CONSOLE_STD 0x1 #define CONSOLE_ARG 0x2 #define CONSOLE_EOA 0x3 diff --git a/src/devices/controller.c b/src/devices/controller.c index 38fd3bb..d7f8f4b 100644 --- a/src/devices/controller.c +++ b/src/devices/controller.c @@ -13,29 +13,29 @@ WITH REGARD TO THIS SOFTWARE. */ void -controller_down(Uxn *u, Uint8 *d, Uint8 mask) +controller_down(Uint8 *d, Uint8 mask) { if(mask) { d[2] |= mask; - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); } } void -controller_up(Uxn *u, Uint8 *d, Uint8 mask) +controller_up(Uint8 *d, Uint8 mask) { if(mask) { d[2] &= (~mask); - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); } } void -controller_key(Uxn *u, Uint8 *d, Uint8 key) +controller_key(Uint8 *d, Uint8 key) { if(key) { d[3] = key; - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); d[3] = 0x00; } } diff --git a/src/devices/controller.h b/src/devices/controller.h index d4d835e..8b408fc 100644 --- a/src/devices/controller.h +++ b/src/devices/controller.h @@ -11,6 +11,6 @@ WITH REGARD TO THIS SOFTWARE. #define CONTROL_VERSION 1 -void controller_down(Uxn *u, Uint8 *d, Uint8 mask); -void controller_up(Uxn *u, Uint8 *d, Uint8 mask); -void controller_key(Uxn *u, Uint8 *d, Uint8 key); +void controller_down(Uint8 *d, Uint8 mask); +void controller_up(Uint8 *d, Uint8 mask); +void controller_key(Uint8 *d, Uint8 key); diff --git a/src/devices/datetime.c b/src/devices/datetime.c index 685f8e3..ec1d415 100644 --- a/src/devices/datetime.c +++ b/src/devices/datetime.c @@ -15,7 +15,7 @@ WITH REGARD TO THIS SOFTWARE. */ Uint8 -datetime_dei(Uxn *u, Uint8 addr) +datetime_dei(Uint8 addr) { time_t seconds = time(NULL); struct tm zt = {0}; @@ -34,6 +34,6 @@ datetime_dei(Uxn *u, Uint8 addr) case 0xc8: return t->tm_yday >> 8; case 0xc9: return t->tm_yday; case 0xca: return t->tm_isdst; - default: return u->dev[addr]; + default: return uxn.dev[addr]; } } diff --git a/src/devices/datetime.h b/src/devices/datetime.h index 4ae7a6c..cc56e66 100644 --- a/src/devices/datetime.h +++ b/src/devices/datetime.h @@ -11,4 +11,4 @@ WITH REGARD TO THIS SOFTWARE. #define DATETIME_VERSION 1 -Uint8 datetime_dei(Uxn *u, Uint8 addr); +Uint8 datetime_dei(Uint8 addr); diff --git a/src/devices/mouse.c b/src/devices/mouse.c index e7f1002..814bb6e 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -13,33 +13,33 @@ WITH REGARD TO THIS SOFTWARE. */ void -mouse_down(Uxn *u, Uint8 *d, Uint8 mask) +mouse_down(Uint8 *d, Uint8 mask) { d[6] |= mask; - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); } void -mouse_up(Uxn *u, Uint8 *d, Uint8 mask) +mouse_up(Uint8 *d, Uint8 mask) { d[6] &= (~mask); - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); } void -mouse_pos(Uxn *u, Uint8 *d, Uint16 x, Uint16 y) +mouse_pos(Uint8 *d, Uint16 x, Uint16 y) { *(d + 2) = x >> 8, *(d + 3) = x; *(d + 4) = y >> 8, *(d + 5) = y; - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); } void -mouse_scroll(Uxn *u, Uint8 *d, Uint16 x, Uint16 y) +mouse_scroll(Uint8 *d, Uint16 x, Uint16 y) { *(d + 0xa) = x >> 8, *(d + 0xb) = x; *(d + 0xc) = -y >> 8, *(d + 0xd) = -y; - uxn_eval(u, PEEK2(d)); + uxn_eval(&uxn, PEEK2(d)); *(d + 0xa) = 0, *(d + 0xb) = 0; *(d + 0xc) = 0, *(d + 0xd) = 0; } diff --git a/src/devices/mouse.h b/src/devices/mouse.h index 3af21f0..3f13070 100644 --- a/src/devices/mouse.h +++ b/src/devices/mouse.h @@ -9,9 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -#define MOUSE_VERSION 1 - -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); +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); diff --git a/src/uxn11.c b/src/uxn11.c index 750e222..a594fed 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -51,7 +51,7 @@ emu_dei(Uint8 addr) case 0x00: return system_dei(&uxn, addr); case 0x10: return console_dei(&uxn, addr); case 0x20: return screen_dei(&uxn, addr); - case 0xc0: return datetime_dei(&uxn, addr); + case 0xc0: return datetime_dei(addr); } return uxn.dev[addr]; } @@ -158,37 +158,37 @@ emu_event(Uxn *u) case XK_F4: emu_restart(u, boot_rom, 0); break; case XK_F5: emu_restart(u, boot_rom, 1); break; } - controller_down(u, &u->dev[0x80], get_button(sym)); - controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]); + controller_down(&u->dev[0x80], get_button(sym)); + controller_key(&u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]); } break; case KeyRelease: { KeySym sym; char buf[7]; XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); - controller_up(u, &u->dev[0x80], get_button(sym)); + controller_up(&u->dev[0x80], get_button(sym)); } break; case ButtonPress: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; if(e->button == 4) - mouse_scroll(u, &u->dev[0x90], 0, 1); + mouse_scroll(&u->dev[0x90], 0, 1); else if(e->button == 5) - mouse_scroll(u, &u->dev[0x90], 0, -1); + mouse_scroll(&u->dev[0x90], 0, -1); else if(e->button == 6) - mouse_scroll(u, &u->dev[0x90], 1, 0); + mouse_scroll(&u->dev[0x90], 1, 0); else if(e->button == 7) - mouse_scroll(u, &u->dev[0x90], -1, 0); + mouse_scroll(&u->dev[0x90], -1, 0); else - mouse_down(u, &u->dev[0x90], 0x1 << (e->button - 1)); + mouse_down(&u->dev[0x90], 0x1 << (e->button - 1)); } break; case ButtonRelease: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; - mouse_up(u, &u->dev[0x90], 0x1 << (e->button - 1)); + mouse_up(&u->dev[0x90], 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(u, &u->dev[0x90], x, y); + mouse_pos(&u->dev[0x90], x, y); } break; } } diff --git a/src/uxncli.c b/src/uxncli.c index 0b0d686..dc73541 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -26,7 +26,7 @@ emu_dei(Uint8 addr) switch(addr & 0xf0) { case 0x00: return system_dei(&uxn, addr); case 0x10: return console_dei(&uxn, addr); - case 0xc0: return datetime_dei(&uxn, addr); + case 0xc0: return datetime_dei(addr); } return uxn.dev[addr]; }