(console) Implemented 0x17 port with stream type based on design by zzo38

This commit is contained in:
Devine Lu Linvega 2023-04-16 21:13:50 -07:00
parent 5e927cdfde
commit fbba9b304d
4 changed files with 40 additions and 56 deletions

View File

@ -35,7 +35,7 @@ system_print(Stack *s, char *name)
static void static void
system_cmd(Uint8 *ram, Uint16 addr) system_cmd(Uint8 *ram, Uint16 addr)
{ {
if(ram[addr] == 0x01) { if(ram[addr] == 0x1) {
Uint16 i, length = PEEK2(ram + addr + 1); Uint16 i, length = PEEK2(ram + addr + 1);
Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4); Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4);
Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8); Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8);
@ -86,7 +86,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
int int
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
{ {
Uint8 *d = &u->dev[0x00]; Uint8 *d = &u->dev[0];
Uint16 handler = PEEK2(d); Uint16 handler = PEEK2(d);
if(handler) { if(handler) {
u->wst.ptr = 4; u->wst.ptr = 4;
@ -101,3 +101,27 @@ uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
} }
return 0; return 0;
} }
int
console_input(Uxn *u, char c, int type)
{
Uint8 *d = &u->dev[0x10];
d[0x2] = c;
d[0x7] = type;
return uxn_eval(u, PEEK2(d));
}
void
console_deo(Uint8 *d, Uint8 port)
{
switch(port) {
case 0x8:
fputc(d[port], stdout);
fflush(stdout);
return;
case 0x9:
fputc(d[port], stderr);
fflush(stderr);
return;
}
}

View File

@ -11,6 +11,13 @@ WITH REGARD TO THIS SOFTWARE.
#define RAM_PAGES 0x10 #define RAM_PAGES 0x10
#define CONSOLE_STD 0x0
#define CONSOLE_ARG 0x2
#define CONSOLE_EOA 0x3
#define CONSOLE_END 0x4
int system_load(Uxn *u, char *filename); int system_load(Uxn *u, char *filename);
void system_deo(Uxn *u, Uint8 *d, Uint8 port);
void system_inspect(Uxn *u); void system_inspect(Uxn *u);
void system_deo(Uxn *u, Uint8 *d, Uint8 port);
int console_input(Uxn *u, char c, int type);
void console_deo(Uint8 *d, Uint8 port);

View File

@ -27,29 +27,6 @@ emu_error(char *msg, const char *err)
return 1; return 1;
} }
static int
console_input(Uxn *u, char c)
{
Uint8 *d = &u->dev[0x10];
d[0x02] = c;
return uxn_eval(u, PEEK2(d));
}
static void
console_deo(Uint8 *d, Uint8 port)
{
switch(port) {
case 0x8:
fputc(d[port], stdout);
fflush(stdout);
return;
case 0x9:
fputc(d[port], stderr);
fflush(stderr);
return;
}
}
Uint8 Uint8
uxn_dei(Uxn *u, Uint8 addr) uxn_dei(Uxn *u, Uint8 addr)
{ {
@ -86,13 +63,12 @@ main(int argc, char **argv)
return u.dev[0x0f] & 0x7f; return u.dev[0x0f] & 0x7f;
for(i = 2; i < argc; i++) { for(i = 2; i < argc; i++) {
char *p = argv[i]; char *p = argv[i];
while(*p) console_input(&u, *p++); while(*p) console_input(&u, *p++, CONSOLE_ARG);
console_input(&u, '\n'); console_input(&u, '\n', CONSOLE_EOA);
} }
while(!u.dev[0x0f]) { while(!u.dev[0x0f]) {
int c = fgetc(stdin); int c = fgetc(stdin);
if(c != EOF) if(c != EOF) console_input(&u, (Uint8)c, CONSOLE_STD);
console_input(&u, (Uint8)c);
} }
return u.dev[0x0f] & 0x7f; return u.dev[0x0f] & 0x7f;
} }

View File

@ -71,35 +71,12 @@ error(char *msg, const char *err)
return 0; return 0;
} }
static int
console_input(Uxn *u, char c)
{
Uint8 *d = &u->dev[0x10];
d[0x02] = c;
return uxn_eval(u, PEEK2(d));
}
static int static int
clamp(int val, int min, int max) clamp(int val, int min, int max)
{ {
return (val >= min) ? (val <= max) ? val : max : min; return (val >= min) ? (val <= max) ? val : max : min;
} }
static void
console_deo(Uint8 *d, Uint8 port)
{
switch(port) {
case 0x8:
fputc(d[port], stdout);
fflush(stdout);
return;
case 0x9:
fputc(d[port], stderr);
fflush(stderr);
return;
}
}
static Uint8 static Uint8
audio_dei(int instance, Uint8 *d, Uint8 port) audio_dei(int instance, Uint8 *d, Uint8 port)
{ {
@ -475,7 +452,7 @@ handle_events(Uxn *u)
} }
/* Console */ /* Console */
else if(event.type == stdin_event) else if(event.type == stdin_event)
console_input(u, event.cbutton.button); console_input(u, event.cbutton.button, CONSOLE_STD);
} }
return 1; return 1;
} }
@ -533,8 +510,8 @@ main(int argc, char **argv)
rom_path = argv[i]; rom_path = argv[i];
} else { } else {
char *p = argv[i]; char *p = argv[i];
while(*p) console_input(&u, *p++); while(*p) console_input(&u, *p++, CONSOLE_ARG);
console_input(&u, '\n'); console_input(&u, '\n', i == argc ? CONSOLE_END : CONSOLE_EOA);
} }
} }
if(!loaded && !start(&u, "launcher.rom")) if(!loaded && !start(&u, "launcher.rom"))