From c990a2a4073992a4b3492566bbeac6b105c614b3 Mon Sep 17 00:00:00 2001 From: neauoire Date: Tue, 5 Apr 2022 10:30:17 -0700 Subject: [PATCH] Removed a few indirections --- src/devices/file.c | 20 +++++++------------- src/devices/file.h | 4 ++-- src/devices/system.h | 5 ----- src/uxn.c | 1 + src/uxn.h | 2 +- src/uxn11.c | 36 ++++++++++++++++++------------------ 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/devices/file.c b/src/devices/file.c index c0ecc4e..350cca7 100644 --- a/src/devices/file.c +++ b/src/devices/file.c @@ -151,18 +151,12 @@ file_delete(UxnFile *c) return unlink(c->current_filename); } -static UxnFile * -file_instance(Device *d) -{ - return &uxn_file[d - &d->u->dev[DEV_FILE0]]; -} - /* IO */ void -file_deo(Device *d, Uint8 port) +file_deo(Uint8 id, Device *d, Uint8 port) { - UxnFile *c = file_instance(d); + UxnFile *c = &uxn_file[id]; Uint16 addr, len, res; switch(port) { case 0x5: @@ -202,18 +196,18 @@ file_deo(Device *d, Uint8 port) } Uint8 -file_dei(Device *d, Uint8 port) +file_dei(Uint8 id, Uint8 *d, Uint8 port) { - UxnFile *c = file_instance(d); + UxnFile *c = &uxn_file[id]; Uint16 res; switch(port) { case 0xc: case 0xd: - res = file_read(c, &d->dat[port], 1); - DEVPOKE16(0x2, res); + res = file_read(c, &d[port], 1); + POKDEV(0x2, res); break; } - return d->dat[port]; + return d[port]; } /* Boot */ diff --git a/src/devices/file.h b/src/devices/file.h index f6db406..72ace0a 100644 --- a/src/devices/file.h +++ b/src/devices/file.h @@ -13,6 +13,6 @@ WITH REGARD TO THIS SOFTWARE. #define POLYFILEY 2 #define DEV_FILE0 0xa -void file_deo(Device *d, Uint8 port); -Uint8 file_dei(Device *d, Uint8 port); +void file_deo(Uint8 id, Device *d, Uint8 port); +Uint8 file_dei(Uint8 id, Uint8 *d, Uint8 port); int load_rom(Uxn *u, char *filename); diff --git a/src/devices/system.h b/src/devices/system.h index d9f7602..3040224 100644 --- a/src/devices/system.h +++ b/src/devices/system.h @@ -9,11 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ -typedef struct SystemDevice { - Device device; - struct UxnScreen *screen; -} SystemDevice; - void system_inspect(Uxn *u); void system_deo(Uxn *u, Uint8 *d, Uint8 port); void system_deo_special(Uint8 *d, Uint8 port); diff --git a/src/uxn.c b/src/uxn.c index 5b2707d..561b165 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -110,6 +110,7 @@ uxn_boot(Uxn *u, Uint8 *ram) u->ram = ram; u->wst = (Stack*)(ram + 0x10000); u->rst = (Stack*)(ram + 0x10100); + u->dpg = (Uint8*)(ram + 0x10200); return 1; } diff --git a/src/uxn.h b/src/uxn.h index fab0d3b..0622fac 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -41,7 +41,7 @@ typedef struct Device { } Device; typedef struct Uxn { - Uint8 *ram; + Uint8 *ram, *dpg; Stack *wst, *rst; Uint8 (*dei)(struct Uxn *u, Uint8 address); void (*deo)(struct Uxn *u, Uint8 address, Uint8 value); diff --git a/src/uxn11.c b/src/uxn11.c index c80bbd1..1f54468 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -42,9 +42,9 @@ system_deo_special(Uint8 *d, Uint8 port) static int console_input(Uxn *u, char c) { - Device *d = &u->dev[1]; - d->dat[0x2] = c; - return uxn_eval(u, GETVEC(d->dat)); + Uint8 *d = u->dev[1].dat; + d[0x2] = c; + return uxn_eval(u, GETVEC(d)); } static void @@ -65,8 +65,8 @@ uxn11_dei(struct Uxn *u, Uint8 addr) Device *d = &u->dev[addr >> 4]; switch(addr & 0xf0) { case 0x20: return screen_dei(d->dat, p); break; - case 0xa0: return file_dei(d, p); break; - case 0xb0: return file_dei(d, p); break; + case 0xa0: return file_dei(0, d->dat, p); break; + case 0xb0: return file_dei(1, d->dat, p); break; case 0xc0: return datetime_dei(d->dat, p); break; } return d->dat[p]; @@ -82,8 +82,8 @@ uxn11_deo(Uxn *u, Uint8 addr, Uint8 v) case 0x00: system_deo(u, d->dat, p); break; case 0x10: console_deo(d->dat, p); break; case 0x20: screen_deo(u->ram, d->dat, p); break; - case 0xa0: file_deo(d, p); break; - case 0xb0: file_deo(d, p); break; + case 0xa0: file_deo(0, d, p); break; + case 0xb0: file_deo(1, d, p); break; } } @@ -126,7 +126,7 @@ get_button(KeySym sym) } static void -processEvent(void) +processEvent(Uxn *u) { XEvent ev; XNextEvent(display, &ev); @@ -144,26 +144,26 @@ processEvent(void) KeySym sym; char buf[7]; XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); - controller_down(devctrl->u, devctrl->dat, get_button(sym)); - controller_key(devctrl->u, devctrl->dat, sym < 0x80 ? sym : buf[0]); + controller_down(u, devctrl->dat, get_button(sym)); + controller_key(u, devctrl->dat, sym < 0x80 ? sym : buf[0]); } break; case KeyRelease: { KeySym sym; char buf[7]; XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); - controller_up(devctrl->u, devctrl->dat, get_button(sym)); + controller_up(u, devctrl->dat, get_button(sym)); } break; case ButtonPress: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; - mouse_down(devmouse->u, devmouse->dat, 0x1 << (e->button - 1)); + mouse_down(u, devmouse->dat, 0x1 << (e->button - 1)); } break; case ButtonRelease: { XButtonPressedEvent *e = (XButtonPressedEvent *)&ev; - mouse_up(devmouse->u, devmouse->dat, 0x1 << (e->button - 1)); + mouse_up(u, devmouse->dat, 0x1 << (e->button - 1)); } break; case MotionNotify: { XMotionEvent *e = (XMotionEvent *)&ev; - mouse_pos(devmouse->u, devmouse->dat, e->x, e->y); + mouse_pos(u, devmouse->dat, e->x, e->y); } break; } } @@ -184,7 +184,7 @@ nil_deo(Device *d, Uint8 port) static int start(Uxn *u, char *rom) { - if(!uxn_boot(u, (Uint8 *)calloc(0x10200, sizeof(Uint8)))) + if(!uxn_boot(u, (Uint8 *)calloc(0x10300, sizeof(Uint8)))) return error("Boot", "Failed"); if(!load_rom(u, rom)) return error("Load", "Failed"); @@ -202,8 +202,8 @@ start(Uxn *u, char *rom) /* empty */ uxn_port(u, 0x7, nil_dei, nil_deo); /* control */ devctrl = uxn_port(u, 0x8, nil_dei, nil_deo); /* mouse */ devmouse = uxn_port(u, 0x9, nil_dei, nil_deo); - /* file0 */ uxn_port(u, 0xa, file_dei, file_deo); - /* file1 */ uxn_port(u, 0xb, file_dei, file_deo); + /* file0 */ uxn_port(u, 0xa, nil_dei, nil_deo); + /* file1 */ uxn_port(u, 0xb, nil_dei, nil_deo); /* datetime */ uxn_port(u, 0xc, nil_dei, nil_deo); /* empty */ uxn_port(u, 0xd, nil_dei, nil_deo); /* reserved */ uxn_port(u, 0xe, nil_dei, nil_deo); @@ -262,7 +262,7 @@ main(int argc, char **argv) if(poll(fds, 2, 1000) <= 0) continue; while(XPending(display)) - processEvent(); + processEvent(&u); if(poll(&fds[1], 1, 0)) { read(fds[1].fd, expirations, 8); /* Indicate we handled the timer */ uxn_eval(&u, GETVECTOR(devscreen)); /* Call the vector once, even if the timer fired multiple times */