diff --git a/src/devices/console.c b/src/devices/console.c index db0dd20..a699f2d 100644 --- a/src/devices/console.c +++ b/src/devices/console.c @@ -24,6 +24,16 @@ console_input(Uxn *u, char c, int type) return uxn_eval(u, PEEK2(d)); } +void +console_listen(Uxn *u, 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); + } +} + void console_deo(Uint8 *d, Uint8 port) { diff --git a/src/devices/console.h b/src/devices/console.h index aaaef23..eaa64f5 100644 --- a/src/devices/console.h +++ b/src/devices/console.h @@ -19,4 +19,5 @@ WITH REGARD TO THIS SOFTWARE. #define CONSOLE_END 0x4 int console_input(Uxn *u, char c, int type); +void console_listen(Uxn *u, int i, int argc, char **argv); void console_deo(Uint8 *d, Uint8 port); diff --git a/src/uxncli.c b/src/uxncli.c index 0615299..31e46db 100644 --- a/src/uxncli.c +++ b/src/uxncli.c @@ -62,11 +62,7 @@ main(int argc, char **argv) /* Game Loop */ u.dev[0x17] = argc - i; if(uxn_eval(&u, PAGE_PROGRAM)) { - 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); - } + console_listen(&u, i, argc, argv); while(!u.dev[0x0f]) { int c = fgetc(stdin); if(c == EOF) break; diff --git a/src/uxnemu.c b/src/uxnemu.c index c20b853..71de702 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -549,11 +549,7 @@ main(int argc, char **argv) if(!emu_start(&u, rom_path)) return system_error("Start", "Failed"); /* read arguments */ - 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); - } + console_listen(&u, i, argc, argv); /* start rom */ run(&u, rom_path); /* finished */