Removed indirections in console
This commit is contained in:
parent
d49514e257
commit
f4f05d0419
|
@ -43,11 +43,11 @@ static pid_t child_pid;
|
||||||
struct winsize ws = {24, 80, 8, 12};
|
struct winsize ws = {24, 80, 8, 12};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_args(Uxn *u, Uint8 *d)
|
parse_args(Uint8 *d)
|
||||||
{
|
{
|
||||||
Uint8 *port_addr = d + 0x3;
|
Uint8 *port_addr = d + 0x3;
|
||||||
int addr = PEEK2(port_addr);
|
int addr = PEEK2(port_addr);
|
||||||
char *pos = (char *)&u->ram[addr];
|
char *pos = (char *)&uxn.ram[addr];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
do {
|
do {
|
||||||
fork_args[i++] = pos;
|
fork_args[i++] = pos;
|
||||||
|
@ -82,21 +82,21 @@ clean_after_child(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
console_input(Uxn *u, char c, int type)
|
console_input(char c, int type)
|
||||||
{
|
{
|
||||||
Uint8 *d = &u->dev[0x10];
|
Uint8 *d = &uxn.dev[0x10];
|
||||||
d[0x2] = c;
|
d[0x2] = c;
|
||||||
d[0x7] = type;
|
d[0x7] = type;
|
||||||
return uxn_eval(u, PEEK2(d));
|
return uxn_eval(&uxn, PEEK2(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
console_listen(Uxn *u, int i, int argc, char **argv)
|
console_listen(int i, int argc, char **argv)
|
||||||
{
|
{
|
||||||
for(; i < argc; i++) {
|
for(; i < argc; i++) {
|
||||||
char *p = argv[i];
|
char *p = argv[i];
|
||||||
while(*p) console_input(u, *p++, CONSOLE_ARG);
|
while(*p) console_input(*p++, CONSOLE_ARG);
|
||||||
console_input(u, '\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
|
console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +191,12 @@ kill_child(Uint8 *d, int options)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
start_fork(Uxn *u, Uint8 *d)
|
start_fork(Uint8 *d)
|
||||||
{
|
{
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
kill_child(d, 0);
|
kill_child(d, 0);
|
||||||
child_mode = d[0x5];
|
child_mode = d[0x5];
|
||||||
parse_args(u, d);
|
parse_args(d);
|
||||||
if(child_mode >= 0x80)
|
if(child_mode >= 0x80)
|
||||||
start_fork_pty(d);
|
start_fork_pty(d);
|
||||||
else
|
else
|
||||||
|
@ -204,9 +204,9 @@ start_fork(Uxn *u, Uint8 *d)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
console_dei(Uxn *u, Uint8 addr)
|
console_dei(Uint8 addr)
|
||||||
{
|
{
|
||||||
Uint8 port = addr & 0x0f, *d = &u->dev[addr & 0xf0];
|
Uint8 port = addr & 0x0f, *d = &uxn.dev[addr & 0xf0];
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x6:
|
case 0x6:
|
||||||
case 0x7: kill_child(d, WNOHANG);
|
case 0x7: kill_child(d, WNOHANG);
|
||||||
|
@ -215,11 +215,11 @@ console_dei(Uxn *u, Uint8 addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
console_deo(Uxn *u, Uint8 *d, Uint8 port)
|
console_deo(Uint8 *d, Uint8 port)
|
||||||
{
|
{
|
||||||
FILE *fd = NULL;
|
FILE *fd = NULL;
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x5: /* Console/dead */ start_fork(u, d); break;
|
case 0x5: /* Console/dead */ start_fork(d); break;
|
||||||
case 0x6: /* Console/exit*/ kill_child(d, 0); break;
|
case 0x6: /* Console/exit*/ kill_child(d, 0); break;
|
||||||
case 0x8: fd = stdout; break;
|
case 0x8: fd = stdout; break;
|
||||||
case 0x9: fd = stderr; break;
|
case 0x9: fd = stderr; break;
|
||||||
|
|
|
@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
#define CONSOLE_EOA 0x3
|
#define CONSOLE_EOA 0x3
|
||||||
#define CONSOLE_END 0x4
|
#define CONSOLE_END 0x4
|
||||||
|
|
||||||
int console_input(Uxn *u, char c, int type);
|
int console_input(char c, int type);
|
||||||
void console_listen(Uxn *u, int i, int argc, char **argv);
|
void console_listen(int i, int argc, char **argv);
|
||||||
Uint8 console_dei(Uxn *u, Uint8 addr);
|
Uint8 console_dei(Uint8 addr);
|
||||||
void console_deo(Uxn *u, Uint8 *d, Uint8 port);
|
void console_deo(Uint8 *d, Uint8 port);
|
||||||
|
|
|
@ -49,7 +49,7 @@ emu_dei(Uint8 addr)
|
||||||
{
|
{
|
||||||
switch(addr & 0xf0) {
|
switch(addr & 0xf0) {
|
||||||
case 0x00: return system_dei(addr);
|
case 0x00: return system_dei(addr);
|
||||||
case 0x10: return console_dei(&uxn, addr);
|
case 0x10: return console_dei(addr);
|
||||||
case 0x20: return screen_dei(addr);
|
case 0x20: return screen_dei(addr);
|
||||||
case 0xc0: return datetime_dei(addr);
|
case 0xc0: return datetime_dei(addr);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ emu_deo(Uint8 addr, Uint8 value)
|
||||||
if(p > 0x7 && p < 0xe)
|
if(p > 0x7 && p < 0xe)
|
||||||
screen_palette(&uxn.dev[0x8]);
|
screen_palette(&uxn.dev[0x8]);
|
||||||
break;
|
break;
|
||||||
case 0x10: console_deo(&uxn, &uxn.dev[d], p); break;
|
case 0x10: console_deo(&uxn.dev[d], p); break;
|
||||||
case 0x20: screen_deo(&uxn.dev[d], p); break;
|
case 0x20: screen_deo(&uxn.dev[d], p); break;
|
||||||
case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break;
|
case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break;
|
||||||
case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break;
|
case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break;
|
||||||
|
@ -260,7 +260,7 @@ emu_run(void)
|
||||||
n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
|
n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
|
||||||
coninp[n] = 0;
|
coninp[n] = 0;
|
||||||
for(i = 0; i < n; i++)
|
for(i = 0; i < n; i++)
|
||||||
console_input(&uxn, coninp[i], CONSOLE_STD);
|
console_input(coninp[i], CONSOLE_STD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -287,7 +287,7 @@ main(int argc, char **argv)
|
||||||
/* Game Loop */
|
/* Game Loop */
|
||||||
uxn.dev[0x17] = argc - i;
|
uxn.dev[0x17] = argc - i;
|
||||||
if(uxn_eval(&uxn, PAGE_PROGRAM)) {
|
if(uxn_eval(&uxn, PAGE_PROGRAM)) {
|
||||||
console_listen(&uxn, i, argc, argv);
|
console_listen(i, argc, argv);
|
||||||
emu_run();
|
emu_run();
|
||||||
}
|
}
|
||||||
return emu_end();
|
return emu_end();
|
||||||
|
|
24
src/uxncli.c
24
src/uxncli.c
|
@ -25,7 +25,7 @@ emu_dei(Uint8 addr)
|
||||||
{
|
{
|
||||||
switch(addr & 0xf0) {
|
switch(addr & 0xf0) {
|
||||||
case 0x00: return system_dei(addr);
|
case 0x00: return system_dei(addr);
|
||||||
case 0x10: return console_dei(&uxn, addr);
|
case 0x10: return console_dei(addr);
|
||||||
case 0xc0: return datetime_dei(addr);
|
case 0xc0: return datetime_dei(addr);
|
||||||
}
|
}
|
||||||
return uxn.dev[addr];
|
return uxn.dev[addr];
|
||||||
|
@ -38,30 +38,30 @@ emu_deo(Uint8 addr, Uint8 value)
|
||||||
uxn.dev[addr] = value;
|
uxn.dev[addr] = value;
|
||||||
switch(d) {
|
switch(d) {
|
||||||
case 0x00: system_deo(&uxn.dev[d], p); break;
|
case 0x00: system_deo(&uxn.dev[d], p); break;
|
||||||
case 0x10: console_deo(&uxn, &uxn.dev[d], p); break;
|
case 0x10: console_deo(&uxn.dev[d], p); break;
|
||||||
case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break;
|
case 0xa0: file_deo(0, uxn.ram, &uxn.dev[d], p); break;
|
||||||
case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break;
|
case 0xb0: file_deo(1, uxn.ram, &uxn.dev[d], p); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
emu_run(Uxn *u)
|
emu_run(void)
|
||||||
{
|
{
|
||||||
while(!u->dev[0x0f]) {
|
while(!uxn.dev[0x0f]) {
|
||||||
int c = fgetc(stdin);
|
int c = fgetc(stdin);
|
||||||
if(c == EOF) {
|
if(c == EOF) {
|
||||||
console_input(u, 0x00, CONSOLE_END);
|
console_input(0x00, CONSOLE_END);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
console_input(u, (Uint8)c, CONSOLE_STD);
|
console_input((Uint8)c, CONSOLE_STD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
emu_end(Uxn *u)
|
emu_end(void)
|
||||||
{
|
{
|
||||||
free(u->ram);
|
free(uxn.ram);
|
||||||
return u->dev[0x0f] & 0x7f;
|
return uxn.dev[0x0f] & 0x7f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -78,8 +78,8 @@ main(int argc, char **argv)
|
||||||
/* Game Loop */
|
/* Game Loop */
|
||||||
uxn.dev[0x17] = argc - i;
|
uxn.dev[0x17] = argc - i;
|
||||||
if(uxn_eval(&uxn, PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) {
|
if(uxn_eval(&uxn, PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) {
|
||||||
console_listen(&uxn, i, argc, argv);
|
console_listen(i, argc, argv);
|
||||||
emu_run(&uxn);
|
emu_run();
|
||||||
}
|
}
|
||||||
return emu_end(&uxn);
|
return emu_end();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue