Removed device globals

This commit is contained in:
neauoire 2022-01-11 14:38:55 -08:00
parent cd30b48665
commit 61c7f9f0c1
2 changed files with 12 additions and 18 deletions

View File

@ -21,10 +21,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE. WITH REGARD TO THIS SOFTWARE.
*/ */
#pragma mark - Core
static Device *devsystem, *devconsole;
static int static int
error(char *msg, const char *err) error(char *msg, const char *err)
{ {
@ -48,8 +44,6 @@ inspect(Stack *s, char *name)
} }
} }
#pragma mark - Devices
void void
system_deo_special(Device *d, Uint8 port) system_deo_special(Device *d, Uint8 port)
{ {
@ -83,20 +77,19 @@ nil_deo(Device *d, Uint8 port)
(void)port; (void)port;
} }
#pragma mark - Generics
static int static int
console_input(Uxn *u, char c) console_input(Uxn *u, char c)
{ {
devconsole->dat[0x2] = c; Device *d = &u->dev[1];
return uxn_eval(u, GETVECTOR(devconsole)); d->dat[0x2] = c;
return uxn_eval(u, GETVECTOR(d));
} }
static void static void
run(Uxn *u) run(Uxn *u)
{ {
Device *d = devconsole; Device *d = &u->dev[0];
while((!u->dev[0].dat[0xf]) && (read(0, &d->dat[0x2], 1) > 0)) while((!d->dat[0xf]) && (read(0, &d->dat[0x2], 1) > 0))
uxn_eval(u, GETVECTOR(d)); uxn_eval(u, GETVECTOR(d));
} }
@ -124,8 +117,8 @@ main(int argc, char **argv)
if(!uxn_boot(&u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) if(!uxn_boot(&u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST)))
return error("Boot", "Failed"); return error("Boot", "Failed");
/* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo); /* system */ uxn_port(&u, 0x0, system_dei, system_deo);
/* console */ devconsole = uxn_port(&u, 0x1, nil_dei, console_deo); /* console */ uxn_port(&u, 0x1, nil_dei, console_deo);
/* empty */ uxn_port(&u, 0x2, nil_dei, nil_deo); /* empty */ uxn_port(&u, 0x2, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0x3, nil_dei, nil_deo); /* empty */ uxn_port(&u, 0x3, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0x4, nil_dei, nil_deo); /* empty */ uxn_port(&u, 0x4, nil_dei, nil_deo);

View File

@ -45,7 +45,7 @@ static SDL_Rect gRect;
/* devices */ /* devices */
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0;
static Uint8 zoom = 1; static Uint8 zoom = 1;
static Uint32 stdin_event, audio0_event; static Uint32 stdin_event, audio0_event;
@ -260,7 +260,7 @@ start(Uxn *u, char *rom)
if(!load(u, rom)) if(!load(u, rom))
return error("Boot", "Failed to load rom."); return error("Boot", "Failed to load rom.");
/* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo); /* system */ devsystem = uxn_port(u, 0x0, system_dei, system_deo);
/* console */ devconsole = uxn_port(u, 0x1, nil_dei, console_deo); /* console */ uxn_port(u, 0x1, nil_dei, console_deo);
/* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo); /* screen */ devscreen = uxn_port(u, 0x2, screen_dei, screen_deo);
/* audio0 */ devaudio0 = uxn_port(u, 0x3, audio_dei, audio_deo); /* audio0 */ devaudio0 = uxn_port(u, 0x3, audio_dei, audio_deo);
/* audio1 */ uxn_port(u, 0x4, audio_dei, audio_deo); /* audio1 */ uxn_port(u, 0x4, audio_dei, audio_deo);
@ -407,8 +407,9 @@ do_shortcut(Uxn *u, SDL_Event *event)
static int static int
console_input(Uxn *u, char c) console_input(Uxn *u, char c)
{ {
devconsole->dat[0x2] = c; Device *d = &u->dev[1];
return uxn_eval(u, GETVECTOR(devconsole)); d->dat[0x2] = c;
return uxn_eval(u, GETVECTOR(d));
} }
static int static int