From b3fcbe9874b54fe85fc6f7e81a23545b019316f4 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 1 Jul 2024 07:11:07 -0800 Subject: [PATCH] Let the console_input do the cast --- src/devices/console.c | 9 ++++----- src/devices/console.h | 2 +- src/uxn11.c | 2 +- src/uxncli.c | 36 ++++++++++++------------------------ 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/devices/console.c b/src/devices/console.c index f6eb773..59add90 100644 --- a/src/devices/console.c +++ b/src/devices/console.c @@ -82,12 +82,11 @@ clean_after_child(void) } int -console_input(char c, int type) +console_input(Uint8 c, int type) { - Uint8 *d = &uxn.dev[0x10]; - d[0x2] = c; - d[0x7] = type; - return uxn_eval(PEEK2(d)); + uxn.dev[0x12] = c; + uxn.dev[0x17] = type; + return uxn_eval(PEEK2(&uxn.dev[0x10])); } void diff --git a/src/devices/console.h b/src/devices/console.h index 36d7c5e..890eded 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(char c, int type); +int console_input(Uint8 c, int type); void console_listen(int i, int argc, char **argv); Uint8 console_dei(Uint8 addr); void console_deo(Uint8 port); diff --git a/src/uxn11.c b/src/uxn11.c index 056824e..07bf294 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -172,7 +172,7 @@ emu_event(void) if(e->button == 4) mouse_scroll(0, 1); else if(e->button == 5) - mouse_scroll( 0, -1); + mouse_scroll(0, -1); else if(e->button == 6) mouse_scroll(1, 0); else if(e->button == 7) diff --git a/src/uxncli.c b/src/uxncli.c index d950c9e..dae60b2 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -34,9 +34,9 @@ emu_dei(Uint8 addr) void emu_deo(Uint8 addr, Uint8 value) { - Uint8 p = addr & 0x0f, d = addr & 0xf0; + Uint8 p = addr & 0x0f; uxn.dev[addr] = value; - switch(d) { + switch(addr & 0xf0) { case 0x00: system_deo(p); break; case 0x10: console_deo(p); break; case 0xa0: file_deo(0, p); break; @@ -44,26 +44,6 @@ emu_deo(Uint8 addr, Uint8 value) } } -static void -emu_run(void) -{ - while(!uxn.dev[0x0f]) { - int c = fgetc(stdin); - if(c == EOF) { - console_input(0x00, CONSOLE_END); - break; - } - console_input((Uint8)c, CONSOLE_STD); - } -} - -static int -emu_end(void) -{ - free(uxn.ram); - return uxn.dev[0x0f] & 0x7f; -} - int main(int argc, char **argv) { @@ -79,7 +59,15 @@ main(int argc, char **argv) uxn.dev[0x17] = argc - i; if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { console_listen(i, argc, argv); - emu_run(); + while(!uxn.dev[0x0f]) { + int c = fgetc(stdin); + if(c == EOF) { + console_input(0x00, CONSOLE_END); + break; + } + console_input(c, CONSOLE_STD); + } } - return emu_end(); + free(uxn.ram); + return uxn.dev[0x0f] & 0x7f; }