Removed unistd from uxncli

This commit is contained in:
neauoire 2022-01-11 15:13:12 -08:00
parent 06b694d406
commit 5e2bb92e4c
1 changed files with 44 additions and 42 deletions

View File

@ -1,6 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include "uxn.h" #include "uxn.h"
@ -89,8 +88,11 @@ static void
run(Uxn *u) run(Uxn *u)
{ {
Device *d = &u->dev[0]; Device *d = &u->dev[0];
while((!d->dat[0xf]) && (read(0, &d->dat[0x2], 1) > 0)) while(!d->dat[0xf]) {
uxn_eval(u, GETVECTOR(d)); int c = fgetc(stdin);
if(c != EOF)
console_input(u, (Uint8)c);
}
} }
static int static int
@ -106,50 +108,50 @@ load(Uxn *u, char *filepath)
return 1; return 1;
} }
static int
start(Uxn *u)
{
bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8));
bank1 = (Uint8 *)calloc(0x10000, sizeof(Uint8));
if(!uxn_boot(u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST)))
return error("Boot", "Failed");
/* system */ uxn_port(u, 0x0, system_dei, system_deo);
/* console */ uxn_port(u, 0x1, nil_dei, console_deo);
/* empty */ uxn_port(u, 0x2, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x3, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x4, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x5, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x6, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x7, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x8, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0x9, nil_dei, nil_deo);
/* file */ uxn_port(u, 0xa, nil_dei, file_deo);
/* datetime */ uxn_port(u, 0xb, datetime_dei, nil_deo);
/* empty */ uxn_port(u, 0xc, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0xd, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0xe, nil_dei, nil_deo);
/* empty */ uxn_port(u, 0xf, nil_dei, nil_deo);
return 1;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
Uxn u; Uxn u;
int i, loaded = 0; int i;
if(argc < 2)
bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); return error("Usage", "uxncli game.rom args");
bank1 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); if(!start(&u))
if(!uxn_boot(&u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) return error("Start", "Failed");
return error("Boot", "Failed"); if(!load(&u, argv[1]))
return error("Load", "Failed");
/* system */ uxn_port(&u, 0x0, system_dei, system_deo); if(!uxn_eval(&u, PAGE_PROGRAM))
/* console */ uxn_port(&u, 0x1, nil_dei, console_deo); return error("Init", "Failed");
/* empty */ uxn_port(&u, 0x2, nil_dei, nil_deo); for(i = 2; i < argc; i++) {
/* empty */ uxn_port(&u, 0x3, nil_dei, nil_deo); char *p = argv[i];
/* empty */ uxn_port(&u, 0x4, nil_dei, nil_deo); while(*p) console_input(&u, *p++);
/* empty */ uxn_port(&u, 0x5, nil_dei, nil_deo); console_input(&u, '\n');
/* empty */ uxn_port(&u, 0x6, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0x7, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0x8, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0x9, nil_dei, nil_deo);
/* file */ uxn_port(&u, 0xa, nil_dei, file_deo);
/* datetime */ uxn_port(&u, 0xb, datetime_dei, nil_deo);
/* empty */ uxn_port(&u, 0xc, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0xd, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0xe, nil_dei, nil_deo);
/* empty */ uxn_port(&u, 0xf, nil_dei, nil_deo);
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;
} }