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
console_input(char c, int type)
console_input(Uint8 c, int type)
{
Uint8 *d = &uxn.dev[0x10];
d[0x2] = c;
d[0x7] = type;
return uxn_eval(PEEK2(d));
uxn.dev[0x12] = c;
uxn.dev[0x17] = type;
return uxn_eval(PEEK2(&uxn.dev[0x10]));
}
void

View File

@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE.
#define CONSOLE_EOA 0x3
#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);
Uint8 console_dei(Uint8 addr);
void console_deo(Uint8 port);

View File

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