commit 20cc034

Devine Lu Linvega  ·  2025-01-20 23:29:36 +0000 UTC
parent e8c1fe1
Use console prefab for reading arguments
6 files changed,  +15, -21
+1, -1
1@@ -201,7 +201,7 @@ console_input(int c, int type)
2 }
3 
4 void
5-console_listen(int i, int argc, char **argv)
6+console_arguments(int i, int argc, char **argv)
7 {
8 	for(; i < argc; i++) {
9 		char *p = argv[i];
+2, -2
 1@@ -14,8 +14,8 @@ WITH REGARD TO THIS SOFTWARE.
 2 #define CONSOLE_EOA 0x3
 3 #define CONSOLE_END 0x4
 4 
 5+void close_console(void);
 6 int console_input(int c, int type);
 7-void console_listen(int i, int argc, char **argv);
 8+void console_arguments(int i, int argc, char **argv);
 9 Uint8 console_dei(Uint8 addr);
10 void console_deo(Uint8 addr);
11-void close_console(void);
+5, -3
 1@@ -48,9 +48,11 @@ system_error(char *msg, const char *err)
 2 }
 3 
 4 int
 5-system_boot(Uint8 *ram, char *rom_path)
 6+system_boot(Uint8 *ram, char *rom_path, int has_args)
 7 {
 8-	uxn.ram = ram, boot_path = rom_path;
 9+	uxn.ram = ram;
10+	boot_path = rom_path;
11+	uxn.dev[0x17] = has_args;
12 	return system_load(uxn.ram + PAGE_PROGRAM, rom_path);
13 }
14 
15@@ -61,7 +63,7 @@ system_reboot(int soft)
16 	for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0;
17 	for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0;
18 	uxn.wst.ptr = uxn.rst.ptr = 0;
19-	if(system_load(&uxn.ram[PAGE_PROGRAM], boot_path))
20+	if(system_load(uxn.ram + PAGE_PROGRAM, boot_path))
21 		uxn_eval(PAGE_PROGRAM);
22 }
23 
+1, -1
1@@ -12,7 +12,7 @@ WITH REGARD TO THIS SOFTWARE.
2 #define RAM_PAGES 0x10
3 
4 int system_error(char *msg, const char *err);
5-int system_boot(Uint8 *ram, char *rom_path);
6+int system_boot(Uint8 *ram, char *rom_path, int has_args);
7 void system_reboot(int soft);
8 
9 Uint8 system_dei(Uint8 addr);
+3, -4
 1@@ -255,16 +255,15 @@ main(int argc, char **argv)
 2 {
 3 	int i = 1;
 4 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
 5-		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 19 Jan 2025.\n");
 6+		return !fprintf(stdout, "Uxn11 - Varvara Emulator, 20 Jan 2025.\n");
 7 	else if(argc == 1)
 8 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
 9 	else if(!display_init())
10 		return !fprintf(stdout, "Could not open display.\n");
11-	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
12+	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
13 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
14-	uxn.dev[0x17] = argc > 2;
15 	if(uxn_eval(PAGE_PROGRAM))
16-		console_listen(i, argc, argv), emu_run();
17+		console_arguments(i, argc, argv), emu_run();
18 	close_console();
19 	XDestroyImage(ximage), XDestroyWindow(display, window), XCloseDisplay(display);
20 	return uxn.dev[0x0f] & 0x7f;
+3, -10
 1@@ -47,20 +47,13 @@ main(int argc, char **argv)
 2 {
 3 	int i = 1;
 4 	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
 5-		return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 18 Jan 2025.\n");
 6+		return !fprintf(stdout, "Uxn(cli) - Varvara Emulator, 20 Jan 2025.\n");
 7 	else if(argc == 1)
 8 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
 9-	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
10+	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
11 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
12-	uxn.dev[0x17] = argc > 2;
13 	if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) {
14-		/* arguments input */
15-		for(; i < argc; i++) {
16-			char *p = argv[i];
17-			while(*p) console_input(*p++, CONSOLE_ARG);
18-			console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
19-		}
20-		/* console input */
21+		console_arguments(i, argc, argv);
22 		while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
23 	}
24 	return uxn.dev[0x0f] & 0x7f;