On Linux, when uxnemu enters an infinite loop, the only way to stop
it is to send SIGKILL to it. This makes debugging infinite loops very
annoying. This patch adds a step limit per execution, which should be
well out of the realm of a plausible use, and helps stop infinite
loops.
---
src/uxn.c | 5 +++--src/uxn.h | 2 ++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/uxn.c b/src/uxn.c
index a56fdc0..55a12c1 100644
--- a/src/uxn.c+++ b/src/uxn.c
@@ -45,9 +45,9 @@ WITH REGARD TO THIS SOFTWARE.
int
uxn_eval(Uint16 pc)
{
- int a, b, c, x[2], y[2], z[2];+ int step, a, b, c, x[2], y[2], z[2]; if(!pc || uxn.dev[0x0f]) return 0;
- for(;;) {+ for(step = 0; step < STEP_LIMIT; step++) { switch(uxn.ram[pc++]) {
/* BRK */ case 0x00: return 1;
/* JCI */ case 0x20: if(DEC(wst)) { JMI break; } pc += 2; break;
@@ -90,4 +90,5 @@ uxn_eval(Uint16 pc)
/* SFT */ OPC(0x1f, PO1(a) POx(b),PUx(b >> (a & 0xf) << (a >> 4)))
}
}
+ return 0;}
diff --git a/src/uxn.h b/src/uxn.h
index c63e6bf..ab1d337 100644
--- a/src/uxn.h+++ b/src/uxn.h
@@ -18,6 +18,8 @@ WITH REGARD TO THIS SOFTWARE.
#define PAGE_PROGRAM 0x0100
+#define STEP_LIMIT 0x100000+typedef unsigned char Uint8;
typedef signed char Sint8;
typedef unsigned short Uint16;
--
2.47.0