Let the console_input do the cast

This commit is contained in:
Devine Lu Linvega 2024-07-01 07:11:07 -08:00
parent 9b9aae555e
commit b3fcbe9874
4 changed files with 18 additions and 31 deletions

View File

@ -82,12 +82,11 @@ clean_after_child(void)
} }
int int
console_input(char c, int type) console_input(Uint8 c, int type)
{ {
Uint8 *d = &uxn.dev[0x10]; uxn.dev[0x12] = c;
d[0x2] = c; uxn.dev[0x17] = type;
d[0x7] = type; return uxn_eval(PEEK2(&uxn.dev[0x10]));
return uxn_eval(PEEK2(d));
} }
void void

View File

@ -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(char c, int type); int console_input(Uint8 c, int type);
void console_listen(int i, int argc, char **argv); void console_listen(int i, int argc, char **argv);
Uint8 console_dei(Uint8 addr); Uint8 console_dei(Uint8 addr);
void console_deo(Uint8 port); void console_deo(Uint8 port);

View File

@ -172,7 +172,7 @@ emu_event(void)
if(e->button == 4) if(e->button == 4)
mouse_scroll(0, 1); mouse_scroll(0, 1);
else if(e->button == 5) else if(e->button == 5)
mouse_scroll( 0, -1); mouse_scroll(0, -1);
else if(e->button == 6) else if(e->button == 6)
mouse_scroll(1, 0); mouse_scroll(1, 0);
else if(e->button == 7) else if(e->button == 7)

View File

@ -34,9 +34,9 @@ emu_dei(Uint8 addr)
void void
emu_deo(Uint8 addr, Uint8 value) emu_deo(Uint8 addr, Uint8 value)
{ {
Uint8 p = addr & 0x0f, d = addr & 0xf0; Uint8 p = addr & 0x0f;
uxn.dev[addr] = value; uxn.dev[addr] = value;
switch(d) { switch(addr & 0xf0) {
case 0x00: system_deo(p); break; case 0x00: system_deo(p); break;
case 0x10: console_deo(p); break; case 0x10: console_deo(p); break;
case 0xa0: file_deo(0, p); break; case 0xa0: file_deo(0, p); break;
@ -44,26 +44,6 @@ emu_deo(Uint8 addr, Uint8 value)
} }
} }
static void
emu_run(void)
{
while(!uxn.dev[0x0f]) {
int c = fgetc(stdin);
if(c == EOF) {
console_input(0x00, CONSOLE_END);
break;
}
console_input((Uint8)c, CONSOLE_STD);
}
}
static int
emu_end(void)
{
free(uxn.ram);
return uxn.dev[0x0f] & 0x7f;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -79,7 +59,15 @@ main(int argc, char **argv)
uxn.dev[0x17] = argc - i; uxn.dev[0x17] = argc - i;
if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) { if(uxn_eval(PAGE_PROGRAM) && PEEK2(uxn.dev + 0x10)) {
console_listen(i, argc, argv); console_listen(i, argc, argv);
emu_run(); while(!uxn.dev[0x0f]) {
int c = fgetc(stdin);
if(c == EOF) {
console_input(0x00, CONSOLE_END);
break;
}
console_input(c, CONSOLE_STD);
}
} }
return emu_end(); free(uxn.ram);
return uxn.dev[0x0f] & 0x7f;
} }