Made a console_listen function

This commit is contained in:
neauoire 2023-08-15 16:24:40 -07:00
parent 8d4074b372
commit 4d7ce3e893
4 changed files with 13 additions and 10 deletions

View File

@ -24,6 +24,16 @@ console_input(Uxn *u, char c, int type)
return uxn_eval(u, PEEK2(d)); 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 void
console_deo(Uint8 *d, Uint8 port) console_deo(Uint8 *d, Uint8 port)
{ {

View File

@ -19,4 +19,5 @@ WITH REGARD TO THIS SOFTWARE.
#define CONSOLE_END 0x4 #define CONSOLE_END 0x4
int console_input(Uxn *u, char c, int type); 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); void console_deo(Uint8 *d, Uint8 port);

View File

@ -62,11 +62,7 @@ main(int argc, char **argv)
/* Game Loop */ /* Game Loop */
u.dev[0x17] = argc - i; u.dev[0x17] = argc - i;
if(uxn_eval(&u, PAGE_PROGRAM)) { if(uxn_eval(&u, PAGE_PROGRAM)) {
for(; i < argc; i++) { console_listen(&u, i, argc, argv);
char *p = argv[i];
while(*p) console_input(&u, *p++, CONSOLE_ARG);
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
}
while(!u.dev[0x0f]) { while(!u.dev[0x0f]) {
int c = fgetc(stdin); int c = fgetc(stdin);
if(c == EOF) break; if(c == EOF) break;

View File

@ -549,11 +549,7 @@ main(int argc, char **argv)
if(!emu_start(&u, rom_path)) if(!emu_start(&u, rom_path))
return system_error("Start", "Failed"); return system_error("Start", "Failed");
/* read arguments */ /* read arguments */
for(; i < argc; i++) { console_listen(&u, i, argc, argv);
char *p = argv[i];
while(*p) console_input(&u, *p++, CONSOLE_ARG);
console_input(&u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
}
/* start rom */ /* start rom */
run(&u, rom_path); run(&u, rom_path);
/* finished */ /* finished */