commit 65c4799

Devine Lu Linvega  ·  2025-01-19 03:36:19 +0000 UTC
parent 214e51b
(console) Return false on EOF
3 files changed,  +11, -17
+6, -5
 1@@ -22,7 +22,7 @@
 2 #include "console.h"
 3 
 4 /*
 5-Copyright (c) 2022-2024 Devine Lu Linvega, Andrew Alderwick
 6+Copyright (c) 2022-2025 Devine Lu Linvega, Andrew Alderwick
 7 
 8 Permission to use, copy, modify, and distribute this software for any
 9 purpose with or without fee is hereby granted, provided that the above
10@@ -192,11 +192,12 @@ close_console(void)
11 }
12 
13 int
14-console_input(Uint8 c, int type)
15+console_input(int c, int type)
16 {
17-	uxn.dev[0x12] = c;
18-	uxn.dev[0x17] = type;
19-	return uxn_eval(PEEK2(&uxn.dev[0x10]));
20+	if(c == EOF) c = 0, type = 4;
21+	uxn.dev[0x12] = c, uxn.dev[0x17] = type;
22+	uxn_eval(uxn.dev[0x10] << 8 | uxn.dev[0x11]);
23+	return type != 4;
24 }
25 
26 void
+2, -2
 1@@ -1,5 +1,5 @@
 2 /*
 3-Copyright (c) 2021 Devine Lu Linvega, Andrew Alderwick
 4+Copyright (c) 2021-2025 Devine Lu Linvega, Andrew Alderwick
 5 
 6 Permission to use, copy, modify, and distribute this software for any
 7 purpose with or without fee is hereby granted, provided that the above
 8@@ -14,7 +14,7 @@ WITH REGARD TO THIS SOFTWARE.
 9 #define CONSOLE_EOA 0x3
10 #define CONSOLE_END 0x4
11 
12-int console_input(Uint8 c, int type);
13+int console_input(int c, int type);
14 void console_listen(int i, int argc, char **argv);
15 Uint8 console_dei(Uint8 addr);
16 void console_deo(Uint8 addr);
+3, -10
 1@@ -8,7 +8,7 @@
 2 #include "devices/datetime.h"
 3 
 4 /*
 5-Copyright (c) 2021-2024 Devine Lu Linvega, Andrew Alderwick
 6+Copyright (c) 2021-2025 Devine Lu Linvega, Andrew Alderwick
 7 
 8 Permission to use, copy, modify, and distribute this software for any
 9 purpose with or without fee is hereby granted, provided that the above
10@@ -47,7 +47,7 @@ main(int argc, char **argv)
11 {
12 	int i = 1;
13 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
14-		return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 1 Jan 2025.\n");
15+		return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 18 Jan 2025.\n");
16 	else if(argc == 1)
17 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
18 	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
19@@ -61,14 +61,7 @@ main(int argc, char **argv)
20 			console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
21 		}
22 		/* console input */
23-		while(!uxn.dev[0x0f]) {
24-			int c = fgetc(stdin);
25-			if(c == EOF) {
26-				console_input(0x00, CONSOLE_END);
27-				break;
28-			}
29-			console_input(c, CONSOLE_STD);
30-		}
31+		while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
32 	}
33 	return uxn.dev[0x0f] & 0x7f;
34 }