commit 5ea3a80

Devine Lu Linvega  ·  2025-05-16 16:27:44 +0000 UTC
parent e20f3ff
(uxncli) Catch all cycles limits
1 files changed,  +6, -9
+6, -9
 1@@ -2,8 +2,6 @@
 2 #include <stdlib.h>
 3 #include <unistd.h>
 4 
 5-#define STEP_MAX 0x80000000
 6-#define PAGE_PROGRAM 0x100
 7 #define RAM_PAGES 0x10
 8 
 9 /*
10@@ -75,9 +73,9 @@ static Stack wst, rst;
11 int
12 uxn_eval(Uint16 pc)
13 {
14-	Uint32 a, b, c, x[2], y[2], z[2], step;
15+	Uint32 a, b, c, x[2], y[2], z[2], step = 0x80000000;
16 	if(dev[0x0f]) return 0;
17-	for(step = STEP_MAX; step; step--) {
18+	while(step--) {
19 		switch(ram[pc++]) {
20 		/* BRK */ case 0x00: return 1;
21 		/* JCI */ case 0x20: if(DEC(wst)) { JMI pc += c; break; } pc += 2; break;
22@@ -120,6 +118,7 @@ uxn_eval(Uint16 pc)
23 		/* SFT */ OPC(0x1f,PO1(a) POx(b),PUx(b >> (a & 0xf) << (a >> 4)))
24 		}
25 	}
26+	fprintf(stdout, "Exhausted cycles limit.\n");
27 	return 0;
28 }
29 
30@@ -145,9 +144,9 @@ system_load(char *rom_path)
31 {
32 	FILE *f = fopen(rom_path, "rb");
33 	if(f) {
34-		int i = 0, l = fread(ram + PAGE_PROGRAM, 0x10000 - PAGE_PROGRAM, 1, f);
35+		int i = 0, l = fread(ram + 0x100, 0x10000 - 0x100, 1, f);
36 		while(l && ++i < RAM_PAGES)
37-			l = fread(ram + PAGE_PROGRAM + 0x10000 * i - PAGE_PROGRAM, 0x10000, 1, f);
38+			l = fread(ram + 0x100 + 0x10000 * i - 0x100, 0x10000, 1, f);
39 		fclose(f);
40 	}
41 	return !!f;
42@@ -704,9 +703,7 @@ main(int argc, char **argv)
43 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
44 	else if(!system_boot(argv[i++], argc > 2))
45 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
46-	if(!uxn_eval(PAGE_PROGRAM))
47-		return !fprintf(stdout, "Exhausted cycles.\n");
48-	if(console_vector) {
49+	if(uxn_eval(0x100) && console_vector) {
50 		for(; i < argc; i++) {
51 			char *p = argv[i];
52 			while(*p)