diff --git a/src/devices/console.c b/src/devices/console.c index 21804db..aaad677 100644 --- a/src/devices/console.c +++ b/src/devices/console.c @@ -43,11 +43,11 @@ static pid_t child_pid; struct winsize ws = {24, 80, 8, 12}; static void -parse_args(Uxn *u, Uint8 *d) +parse_args(Uint8 *d) { Uint8 *port_addr = d + 0x3; int addr = PEEK2(port_addr); - char *pos = (char *)&u->ram[addr]; + char *pos = (char *)&uxn.ram[addr]; int i = 0; do { fork_args[i++] = pos; @@ -82,21 +82,21 @@ clean_after_child(void) } int -console_input(Uxn *u, char c, int type) +console_input(char c, int type) { - Uint8 *d = &u->dev[0x10]; + Uint8 *d = &uxn.dev[0x10]; d[0x2] = c; d[0x7] = type; - return uxn_eval(u, PEEK2(d)); + return uxn_eval(&uxn, PEEK2(d)); } void -console_listen(Uxn *u, int i, int argc, char **argv) +console_listen(int i, int argc, char **argv) { for(; i < argc; i++) { char *p = argv[i]; - while(*p) console_input(u, *p++, CONSOLE_ARG); - console_input(u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); + while(*p) console_input(*p++, CONSOLE_ARG); + console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA); } } @@ -191,12 +191,12 @@ kill_child(Uint8 *d, int options) } static void -start_fork(Uxn *u, Uint8 *d) +start_fork(Uint8 *d) { fflush(stderr); kill_child(d, 0); child_mode = d[0x5]; - parse_args(u, d); + parse_args(d); if(child_mode >= 0x80) start_fork_pty(d); else @@ -204,9 +204,9 @@ start_fork(Uxn *u, Uint8 *d) } Uint8 -console_dei(Uxn *u, Uint8 addr) +console_dei(Uint8 addr) { - Uint8 port = addr & 0x0f, *d = &u->dev[addr & 0xf0]; + Uint8 port = addr & 0x0f, *d = &uxn.dev[addr & 0xf0]; switch(port) { case 0x6: case 0x7: kill_child(d, WNOHANG); @@ -215,11 +215,11 @@ console_dei(Uxn *u, Uint8 addr) } void -console_deo(Uxn *u, Uint8 *d, Uint8 port) +console_deo(Uint8 *d, Uint8 port) { FILE *fd = NULL; switch(port) { - case 0x5: /* Console/dead */ start_fork(u, d); break; + case 0x5: /* Console/dead */ start_fork(d); break; case 0x6: /* Console/exit*/ kill_child(d, 0); break; case 0x8: fd = stdout; break; case 0x9: fd = stderr; break; diff --git a/src/devices/console.h b/src/devices/console.h index bb57577..9c22617 100644 --- a/src/devices/console.h +++ b/src/devices/console.h @@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE. #define CONSOLE_EOA 0x3 #define CONSOLE_END 0x4 -int console_input(Uxn *u, char c, int type); -void console_listen(Uxn *u, int i, int argc, char **argv); -Uint8 console_dei(Uxn *u, Uint8 addr); -void console_deo(Uxn *u, Uint8 *d, Uint8 port); +int console_input(char c, int type); +void console_listen(int i, int argc, char **argv); +Uint8 console_dei(Uint8 addr); +void console_deo(Uint8 *d, Uint8 port); diff --git a/src/uxn11.c b/src/uxn11.c index 11e2db1..476116a 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -49,7 +49,7 @@ emu_dei(Uint8 addr) { switch(addr & 0xf0) { case 0x00: return system_dei(addr); - case 0x10: return console_dei(&uxn, addr); + case 0x10: return console_dei(addr); case 0x20: return screen_dei(addr); case 0xc0: return datetime_dei(addr); } @@ -67,7 +67,7 @@ emu_deo(Uint8 addr, Uint8 value) if(p > 0x7 && p < 0xe) screen_palette(&uxn.dev[0x8]); break; - case 0x10: console_deo(&uxn, &uxn.dev[d], p); break; + case 0x10: console_deo(&uxn.dev[d], p); break; case 0x20: screen_deo(&uxn.dev[d], p); break; case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break; case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break; @@ -260,7 +260,7 @@ emu_run(void) n = read(fds[2].fd, coninp, CONINBUFSIZE - 1); coninp[n] = 0; for(i = 0; i < n; i++) - console_input(&uxn, coninp[i], CONSOLE_STD); + console_input(coninp[i], CONSOLE_STD); } } return 1; @@ -287,7 +287,7 @@ main(int argc, char **argv) /* Game Loop */ uxn.dev[0x17] = argc - i; if(uxn_eval(&uxn, PAGE_PROGRAM)) { - console_listen(&uxn, i, argc, argv); + console_listen(i, argc, argv); emu_run(); } return emu_end(); diff --git a/src/uxncli.c b/src/uxncli.c index 0808490..bbeccf3 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -25,7 +25,7 @@ emu_dei(Uint8 addr) { switch(addr & 0xf0) { case 0x00: return system_dei(addr); - case 0x10: return console_dei(&uxn, addr); + case 0x10: return console_dei(addr); case 0xc0: return datetime_dei(addr); } return uxn.dev[addr]; @@ -38,30 +38,30 @@ emu_deo(Uint8 addr, Uint8 value) uxn.dev[addr] = value; switch(d) { case 0x00: system_deo(&uxn.dev[d], p); break; - case 0x10: console_deo(&uxn, &uxn.dev[d], p); break; + case 0x10: console_deo(&uxn.dev[d], p); break; case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break; case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break; } } static void -emu_run(Uxn *u) +emu_run(void) { - while(!u->dev[0x0f]) { + while(!uxn.dev[0x0f]) { int c = fgetc(stdin); if(c == EOF) { - console_input(u, 0x00, CONSOLE_END); + console_input(0x00, CONSOLE_END); break; } - console_input(u, (Uint8)c, CONSOLE_STD); + console_input((Uint8)c, CONSOLE_STD); } } static int -emu_end(Uxn *u) +emu_end(void) { - free(u->ram); - return u->dev[0x0f] & 0x7f; + free(uxn.ram); + return uxn.dev[0x0f] & 0x7f; } int @@ -78,8 +78,8 @@ main(int argc, char **argv) /* Game Loop */ uxn.dev[0x17] = argc - i; if(uxn_eval(&uxn, PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { - console_listen(&uxn, i, argc, argv); - emu_run(&uxn); + console_listen(i, argc, argv); + emu_run(); } - return emu_end(&uxn); + return emu_end(); }