commit fbba9b304dc48b98537cac5500e2c47680613051
parent 5e927cdfdec4f451467f1439814538232e47d29d
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 16 Apr 2023 21:13:50 -0700
(console) Implemented 0x17 port with stream type based on design by zzo38
Diffstat:
4 files changed, 41 insertions(+), 56 deletions(-)
diff --git a/src/devices/system.c b/src/devices/system.c
@@ -35,7 +35,7 @@ system_print(Stack *s, char *name)
static void
system_cmd(Uint8 *ram, Uint16 addr)
{
- if(ram[addr] == 0x01) {
+ if(ram[addr] == 0x1) {
Uint16 i, length = PEEK2(ram + addr + 1);
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);
@@ -86,7 +86,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port)
int
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
{
- Uint8 *d = &u->dev[0x00];
+ Uint8 *d = &u->dev[0];
Uint16 handler = PEEK2(d);
if(handler) {
u->wst.ptr = 4;
@@ -101,3 +101,27 @@ uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr)
}
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;
+ }
+}
diff --git a/src/devices/system.h b/src/devices/system.h
@@ -11,6 +11,13 @@ WITH REGARD TO THIS SOFTWARE.
#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);
-void system_deo(Uxn *u, Uint8 *d, Uint8 port);
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);
+\ No newline at end of file
diff --git a/src/uxncli.c b/src/uxncli.c
@@ -27,29 +27,6 @@ emu_error(char *msg, const char *err)
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
uxn_dei(Uxn *u, Uint8 addr)
{
@@ -86,13 +63,12 @@ main(int argc, char **argv)
return u.dev[0x0f] & 0x7f;
for(i = 2; i < argc; i++) {
char *p = argv[i];
- while(*p) console_input(&u, *p++);
- console_input(&u, '\n');
+ while(*p) console_input(&u, *p++, CONSOLE_ARG);
+ console_input(&u, '\n', CONSOLE_EOA);
}
while(!u.dev[0x0f]) {
int c = fgetc(stdin);
- if(c != EOF)
- console_input(&u, (Uint8)c);
+ if(c != EOF) console_input(&u, (Uint8)c, CONSOLE_STD);
}
return u.dev[0x0f] & 0x7f;
}
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -72,34 +72,11 @@ error(char *msg, const char *err)
}
static int
-console_input(Uxn *u, char c)
-{
- Uint8 *d = &u->dev[0x10];
- d[0x02] = c;
- return uxn_eval(u, PEEK2(d));
-}
-
-static int
clamp(int val, int min, int max)
{
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
audio_dei(int instance, Uint8 *d, Uint8 port)
{
@@ -475,7 +452,7 @@ handle_events(Uxn *u)
}
/* Console */
else if(event.type == stdin_event)
- console_input(u, event.cbutton.button);
+ console_input(u, event.cbutton.button, CONSOLE_STD);
}
return 1;
}
@@ -533,8 +510,8 @@ main(int argc, char **argv)
rom_path = argv[i];
} else {
char *p = argv[i];
- while(*p) console_input(&u, *p++);
- console_input(&u, '\n');
+ while(*p) console_input(&u, *p++, CONSOLE_ARG);
+ console_input(&u, '\n', i == argc ? CONSOLE_END : CONSOLE_EOA);
}
}
if(!loaded && !start(&u, "launcher.rom"))