From f5278f3a13f04c003a935f7c9a99994bf376cecd Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 7 Jan 2022 16:46:50 -0800 Subject: [PATCH] Removed device vector variable --- src/devices/controller.c | 8 ++++---- src/devices/file.c | 3 --- src/devices/mouse.c | 8 ++++---- src/devices/screen.c | 1 - src/devices/system.c | 9 +++++---- src/uxn.h | 2 +- src/uxncli.c | 7 +++---- src/uxnemu.c | 11 +++++------ 8 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/devices/controller.c b/src/devices/controller.c index cfc19e7..261b05f 100644 --- a/src/devices/controller.c +++ b/src/devices/controller.c @@ -18,7 +18,7 @@ controller_down(Device *d, Uint8 mask) { if(mask) { d->dat[2] |= mask; - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); } } @@ -27,7 +27,7 @@ controller_up(Device *d, Uint8 mask) { if(mask) { d->dat[2] &= (~mask); - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); } } @@ -36,7 +36,7 @@ controller_key(Device *d, Uint8 key) { if(key) { d->dat[3] = key; - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); d->dat[3] = 0x00; } } @@ -46,7 +46,7 @@ controller_special(Device *d, Uint8 key) { if(key) { d->dat[4] = key; - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); d->dat[4] = 0x00; } } \ No newline at end of file diff --git a/src/devices/file.c b/src/devices/file.c index b3b76f2..f5b8b8f 100644 --- a/src/devices/file.c +++ b/src/devices/file.c @@ -146,9 +146,6 @@ file_deo(Device *d, Uint8 port) { Uint16 a, b, res; switch(port) { - case 0x1: - DEVPEEK16(d->vector, 0x0); - break; case 0x5: DEVPEEK16(a, 0x4); DEVPEEK16(b, 0xa); diff --git a/src/devices/mouse.c b/src/devices/mouse.c index dacd2ab..d96a367 100644 --- a/src/devices/mouse.c +++ b/src/devices/mouse.c @@ -17,14 +17,14 @@ void mouse_down(Device *d, Uint8 mask) { d->dat[6] |= mask; - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); } void mouse_up(Device *d, Uint8 mask) { d->dat[6] &= (~mask); - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); } void @@ -32,7 +32,7 @@ mouse_pos(Device *d, Uint16 x, Uint16 y) { DEVPOKE16(0x2, x); DEVPOKE16(0x4, y); - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); } void @@ -40,7 +40,7 @@ mouse_scroll(Device *d, Uint16 x, Uint16 y) { DEVPOKE16(0xa, x); DEVPOKE16(0xc, -y); - uxn_eval(d->u, d->vector); + uxn_eval(d->u, GETVECTOR(d)); DEVPOKE16(0xa, 0); DEVPOKE16(0xc, 0); } diff --git a/src/devices/screen.c b/src/devices/screen.c index 0d733ec..3f8df56 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -127,7 +127,6 @@ void screen_deo(Device *d, Uint8 port) { switch(port) { - case 0x1: DEVPEEK16(d->vector, 0x0); break; case 0x5: if(!FIXED_SIZE) { Uint16 w, h; diff --git a/src/devices/system.c b/src/devices/system.c index aaf198c..be7af1f 100644 --- a/src/devices/system.c +++ b/src/devices/system.c @@ -28,12 +28,14 @@ int uxn_halt(Uxn *u, Uint8 error, Uint16 addr) { Device *d = &u->dev[0]; - Uint16 vec = d->vector; + Uint16 vec = GETVECTOR(d); DEVPOKE16(0x4, addr); d->dat[0x6] = error; - uxn_eval(&supervisor, supervisor.dev[0].vector); + uxn_eval(&supervisor, GETVECTOR(&supervisor.dev[0])); if(vec) { - d->vector = 0; /* need to rearm to run System/vector again */ + /* need to rearm to run System/vector again */ + d->dat[0] = 0; + d->dat[1] = 0; if(error != 2) /* working stack overflow has special treatment */ vec += 0x0004; return uxn_eval(u, vec); @@ -58,7 +60,6 @@ void system_deo(Device *d, Uint8 port) { switch(port) { - case 0x1: DEVPEEK16(d->vector, 0x0); break; case 0x2: d->u->wst->ptr = d->dat[port]; break; case 0x3: d->u->rst->ptr = d->dat[port]; break; default: system_deo_special(d, port); diff --git a/src/uxn.h b/src/uxn.h index 797b414..722abd6 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -27,6 +27,7 @@ typedef unsigned int Uint32; #define DEVPEEK16(o, x) { (o) = (d->dat[(x)] << 8) + d->dat[(x) + 1]; } #define DEVPOKE16(x, y) { d->dat[(x)] = (y) >> 8; d->dat[(x) + 1] = (y); } +#define GETVECTOR(d) ((d)->dat[0] << 8 | (d)->dat[1]) /* clang-format on */ @@ -37,7 +38,6 @@ typedef struct { typedef struct Device { struct Uxn *u; Uint8 *dat, *mem; - Uint16 vector; Uint8 (*dei)(struct Device *d, Uint8); void (*deo)(struct Device *d, Uint8); } Device; diff --git a/src/uxncli.c b/src/uxncli.c index c2fc1eb..c4ff951 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -60,8 +60,6 @@ system_deo_special(Device *d, Uint8 port) static void console_deo(Device *d, Uint8 port) { - if(port == 0x1) - DEVPEEK16(d->vector, 0x0); if(port > 0x7) write(port - 0x7, (char *)&d->dat[port], 1); } @@ -75,7 +73,8 @@ nil_dei(Device *d, Uint8 port) static void nil_deo(Device *d, Uint8 port) { - if(port == 0x1) DEVPEEK16(d->vector, 0x0); + (void)d; + (void)port; } #pragma mark - Generics @@ -84,7 +83,7 @@ static int console_input(Uxn *u, char c) { devconsole->dat[0x2] = c; - return uxn_eval(u, devconsole->vector); + return uxn_eval(u, GETVECTOR(devconsole)); } static void diff --git a/src/uxnemu.c b/src/uxnemu.c index 00442de..c877130 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -180,8 +180,6 @@ system_deo_special(Device *d, Uint8 port) static void console_deo(Device *d, Uint8 port) { - if(port == 0x1) - DEVPEEK16(d->vector, 0x0); if(port > 0x7) write(port - 0x7, (char *)&d->dat[port], 1); } @@ -228,7 +226,8 @@ nil_dei(Device *d, Uint8 port) static void nil_deo(Device *d, Uint8 port) { - if(port == 0x1) DEVPEEK16(d->vector, 0x0); + (void)d; + (void)port; } /* Boot */ @@ -409,7 +408,7 @@ static int console_input(Uxn *u, char c) { devconsole->dat[0x2] = c; - return uxn_eval(u, devconsole->vector); + return uxn_eval(u, GETVECTOR(devconsole)); } static int @@ -483,8 +482,8 @@ run(Uxn *u) console_input(u, event.cbutton.button); } if(devsystem->dat[0xe]) - uxn_eval(&supervisor, supervisor.dev[2].vector); - uxn_eval(u, devscreen->vector); + uxn_eval(&supervisor, GETVECTOR(&supervisor.dev[2])); + uxn_eval(u, GETVECTOR(devscreen)); if(uxn_screen.fg.changed || uxn_screen.bg.changed || devsystem->dat[0xe]) redraw(); if(!BENCH) {