0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-24 14:55:11 +00:00

Feed extra command line arguments to Console/vector

Each argument is followed by a newline character.
This commit is contained in:
Andrew Alderwick 2021-10-13 22:56:38 +01:00
parent 557584819f
commit e82acc875b
2 changed files with 53 additions and 22 deletions

View file

@ -69,6 +69,8 @@ system_talk(Device *d, Uint8 b0, Uint8 w)
static int static int
console_talk(Device *d, Uint8 b0, Uint8 w) console_talk(Device *d, Uint8 b0, Uint8 w)
{ {
if(b0 == 0x1)
d->vector = peek16(d->dat, 0x0);
if(w && b0 > 0x7) if(w && b0 > 0x7)
write(b0 - 0x7, (char *)&d->dat[b0], 1); write(b0 - 0x7, (char *)&d->dat[b0], 1);
return 1; return 1;
@ -134,11 +136,17 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
return 0; return 0;
} }
static int
console_input(Uxn *u, char c)
{
devconsole->dat[0x2] = c;
return uxn_eval(u, devconsole->vector);
}
static void static void
run(Uxn *u) run(Uxn *u)
{ {
Uint16 vec = PAGE_PROGRAM; Uint16 vec;
uxn_eval(u, vec);
while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) { while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) {
vec = peek16(devconsole->dat, 0); vec = peek16(devconsole->dat, 0);
if(!vec) vec = u->ram.ptr; /* continue after last BRK */ if(!vec) vec = u->ram.ptr; /* continue after last BRK */
@ -161,13 +169,10 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
Uxn u; Uxn u;
int i, loaded = 0;
if(argc < 2)
return error("Input", "Missing");
if(!uxn_boot(&u)) if(!uxn_boot(&u))
return error("Boot", "Failed"); return error("Boot", "Failed");
if(!load(&u, argv[1]))
return error("Load", "Failed");
/* system */ devsystem = uxn_port(&u, 0x0, system_talk); /* system */ devsystem = uxn_port(&u, 0x0, system_talk);
/* console */ devconsole = uxn_port(&u, 0x1, console_talk); /* console */ devconsole = uxn_port(&u, 0x1, console_talk);
@ -186,6 +191,21 @@ main(int argc, char **argv)
/* empty */ uxn_port(&u, 0xe, nil_talk); /* empty */ uxn_port(&u, 0xe, nil_talk);
/* empty */ uxn_port(&u, 0xf, nil_talk); /* empty */ uxn_port(&u, 0xf, nil_talk);
for(i = 1; i < argc; ++i) {
if(!loaded++) {
if(!load(&u, argv[i]))
return error("Load", "Failed");
if(!uxn_eval(&u, PAGE_PROGRAM))
return error("Init", "Failed");
} else {
char *p = argv[i];
while(*p) console_input(&u, *p++);
console_input(&u, '\n');
}
}
if(!loaded)
return error("Input", "Missing");
run(&u); run(&u);
return 0; return 0;

View file

@ -493,10 +493,16 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
return 0; return 0;
} }
static int
console_input(Uxn *u, char c)
{
devconsole->dat[0x2] = c;
return uxn_eval(u, devconsole->vector);
}
static int static int
run(Uxn *u) run(Uxn *u)
{ {
uxn_eval(u, PAGE_PROGRAM);
redraw(u); redraw(u);
while(!devsystem->dat[0xf]) { while(!devsystem->dat[0xf]) {
SDL_Event event; SDL_Event event;
@ -528,8 +534,7 @@ run(Uxn *u)
break; break;
default: default:
if(event.type == stdin_event) { if(event.type == stdin_event) {
devconsole->dat[0x2] = event.cbutton.button; console_input(u, event.cbutton.button);
uxn_eval(u, devconsole->vector);
} else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) } else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY)
uxn_eval(u, peek16((devaudio0 + (event.type - audio0_event))->dat, 0)); uxn_eval(u, peek16((devaudio0 + (event.type - audio0_event))->dat, 0));
} }
@ -560,14 +565,10 @@ main(int argc, char **argv)
{ {
SDL_DisplayMode DM; SDL_DisplayMode DM;
Uxn u; Uxn u;
int i; int i, loaded = 0;
if(argc < 2)
return error("usage", "uxnemu file.rom");
if(!uxn_boot(&u)) if(!uxn_boot(&u))
return error("Boot", "Failed to start uxn."); return error("Boot", "Failed to start uxn.");
if(!load(&u, argv[argc - 1]))
return error("Load", "Failed to open rom.");
/* system */ devsystem = uxn_port(&u, 0x0, system_talk); /* system */ devsystem = uxn_port(&u, 0x0, system_talk);
/* console */ devconsole = uxn_port(&u, 0x1, console_talk); /* console */ devconsole = uxn_port(&u, 0x1, console_talk);
@ -589,20 +590,30 @@ main(int argc, char **argv)
/* set default zoom */ /* set default zoom */
SDL_GetCurrentDisplayMode(0, &DM); SDL_GetCurrentDisplayMode(0, &DM);
set_zoom(DM.w / 1280); set_zoom(DM.w / 1280);
/* get default zoom from flags */ for(i = 1; i < argc; ++i) {
for(i = 1; i < argc - 1; i++) { /* get default zoom from flags */
if(strcmp(argv[i], "-s") == 0) { if(strcmp(argv[i], "-s") == 0) {
if((i + 1) < argc - 1) if(i < argc - 1)
set_zoom(atoi(argv[++i])); set_zoom(atoi(argv[++i]));
else else
return error("Opt", "-s No scale provided."); return error("Opt", "-s No scale provided.");
} else if(!loaded++) {
if(!load(&u, argv[i]))
return error("Load", "Failed to open rom.");
if(!init())
return error("Init", "Failed to initialize emulator.");
if(!set_size(WIDTH, HEIGHT, 0))
return error("Window", "Failed to set window size.");
if(!uxn_eval(&u, PAGE_PROGRAM))
return error("Init", "Failed");
} else {
char *p = argv[i];
while(*p) console_input(&u, *p++);
console_input(&u, '\n');
} }
} }
if(!loaded)
if(!init()) return error("usage", "uxnemu file.rom");
return error("Init", "Failed to initialize emulator.");
if(!set_size(WIDTH, HEIGHT, 0))
return error("Window", "Failed to set window size.");
run(&u); run(&u);
quit(); quit();