commit 6007c24

Devine Lu Linvega  ·  2025-05-16 16:40:58 +0000 UTC
parent 23c0383
(uxn11) Cleanup
2 files changed,  +18, -26
+18, -23
  1@@ -2,19 +2,12 @@
  2 #include <stdlib.h>
  3 #include <unistd.h>
  4 #include <string.h>
  5-
  6 #include <X11/Xlib.h>
  7 #include <X11/Xutil.h>
  8 #include <X11/keysymdef.h>
  9 #include <sys/timerfd.h>
 10 #include <poll.h>
 11 
 12-#define STEP_MAX 0x80000000
 13-#define PAGE_PROGRAM 0x100
 14-#define RAM_PAGES 0x10
 15-#define WIDTH (64 * 8)
 16-#define HEIGHT (40 * 8)
 17-
 18 /*
 19 Copyright (c) 2021-2025 Devine Lu Linvega, Andrew Alderwick, 
 20 Andrew Richards, Eiríkr Åsheim, Sigrid Solveig Haflínudóttir
 21@@ -29,13 +22,6 @@ WITH REGARD TO THIS SOFTWARE.
 22 cc -DNDEBUG -O2 -g0 -s src/uxn11.c -lX11 -lutil -o bin/uxn11
 23 */
 24 
 25-static XImage *ximage;
 26-static Display *display;
 27-static Window window;
 28-
 29-/*
 30-@|Uxn --------------------------------------------------------------- */
 31-
 32 typedef unsigned char Uint8;
 33 typedef unsigned short Uint16;
 34 typedef unsigned int Uint32;
 35@@ -49,12 +35,19 @@ typedef struct Uxn {
 36 	Stack wst, rst;
 37 } Uxn;
 38 
 39+static XImage *ximage;
 40+static Display *display;
 41+static Window window;
 42+
 43 Uint8 emu_dei(Uint8 addr);
 44 void emu_deo(Uint8 addr, Uint8 value);
 45 static Uxn uxn;
 46 
 47 /* clang-format off */
 48 
 49+#define RAM_PAGES 0x10
 50+#define WIDTH (64 * 8)
 51+#define HEIGHT (40 * 8)
 52 #define PEEK2(d) (*(d) << 8 | (d)[1])
 53 #define POKE2(d, v) { *(d) = (v) >> 8; (d)[1] = (v); }
 54 #define clamp(v,a,b) { if(v < a) v = a; else if(v >= b) v = b; }
 55@@ -96,7 +89,7 @@ uxn_eval(Uint16 pc)
 56 {
 57 	Uint32 a, b, c, x[2], y[2], z[2], step;
 58 	if(uxn.dev[0x0f]) return 0;
 59-	for(step = STEP_MAX; step; step--) {
 60+	for(step = 0x80000000; step; step--) {
 61 		switch(uxn.ram[pc++]) {
 62 		/* BRK */ case 0x00: return 1;
 63 		/* JCI */ case 0x20: if(DEC(wst)) { JMI pc += c; break; } pc += 2; break;
 64@@ -164,22 +157,22 @@ system_load(Uint8 *ram, char *rom_path)
 65 {
 66 	FILE *f = fopen(rom_path, "rb");
 67 	if(f) {
 68-		int i = 0, l = fread(ram, 0x10000 - PAGE_PROGRAM, 1, f);
 69+		int i = 0, l = fread(ram, 0x10000 - 0x100, 1, f);
 70 		while(l && ++i < RAM_PAGES)
 71-			l = fread(ram + 0x10000 * i - PAGE_PROGRAM, 0x10000, 1, f);
 72+			l = fread(ram + 0x10000 * i - 0x100, 0x10000, 1, f);
 73 		fclose(f);
 74 	}
 75 	return !!f;
 76 }
 77 
 78 static int
 79-system_boot(Uint8 *ram, char *rom_path, int has_args)
 80+system_boot(char *rom_path, int has_args)
 81 {
 82-	uxn.ram = ram;
 83+	uxn.ram = (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8));
 84 	system_boot_path = rom_path;
 85 	uxn.dev[0x17] = has_args;
 86-	if(ram && system_load(uxn.ram + PAGE_PROGRAM, rom_path))
 87-		return uxn_eval(PAGE_PROGRAM);
 88+	if(uxn.ram && system_load(uxn.ram + 0x100, rom_path))
 89+		return uxn_eval(0x100);
 90 	return 0;
 91 }
 92 
 93@@ -190,7 +183,9 @@ system_reboot(int soft)
 94 	for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0;
 95 	for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0;
 96 	uxn.wst.ptr = uxn.rst.ptr = 0;
 97-	return system_boot(uxn.ram, system_boot_path, 0);
 98+	if(system_load(uxn.ram + 0x100, system_boot_path))
 99+		return uxn_eval(0x100);
100+	return 0;
101 }
102 
103 static void
104@@ -1238,7 +1233,7 @@ main(int argc, char **argv)
105 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
106 	else if(!display_init())
107 		return !fprintf(stdout, "Could not open display.\n");
108-	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
109+	else if(!system_boot(argv[i++], argc > 2))
110 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
111 	for(; i < argc; i++) {
112 		char *p = argv[i];
+0, -3
 1@@ -16,9 +16,6 @@ WITH REGARD TO THIS SOFTWARE.
 2 cc -DNDEBUG -O2 -g0 -s src/uxncli.c -lutil -o bin/uxncli
 3 */
 4 
 5-/*
 6-@|Uxn --------------------------------------------------------------- */
 7-
 8 typedef unsigned char Uint8;
 9 typedef unsigned short Uint16;
10 typedef unsigned int Uint32;