0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-24 06:45: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
console_talk(Device *d, Uint8 b0, Uint8 w)
{
if(b0 == 0x1)
d->vector = peek16(d->dat, 0x0);
if(w && b0 > 0x7)
write(b0 - 0x7, (char *)&d->dat[b0], 1);
return 1;
@ -134,11 +136,17 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
return 0;
}
static int
console_input(Uxn *u, char c)
{
devconsole->dat[0x2] = c;
return uxn_eval(u, devconsole->vector);
}
static void
run(Uxn *u)
{
Uint16 vec = PAGE_PROGRAM;
uxn_eval(u, vec);
Uint16 vec;
while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) {
vec = peek16(devconsole->dat, 0);
if(!vec) vec = u->ram.ptr; /* continue after last BRK */
@ -161,13 +169,10 @@ int
main(int argc, char **argv)
{
Uxn u;
int i, loaded = 0;
if(argc < 2)
return error("Input", "Missing");
if(!uxn_boot(&u))
return error("Boot", "Failed");
if(!load(&u, argv[1]))
return error("Load", "Failed");
/* system */ devsystem = uxn_port(&u, 0x0, system_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, 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);
return 0;

View file

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