commit 32fa0f95c3e2f43471c3d8e273e40400cabe6a36
parent 14b704fd0125b6fd575c7186d2a20be1b1ecbf44
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sat, 15 Apr 2023 09:52:08 -0700
(uxn.c) Catch div-by-zero errors
Diffstat:
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/projects/examples/devices/system.tal b/projects/examples/devices/system.tal
@@ -4,10 +4,10 @@
;on-halt .System/vector DEO2
+ ( divzero ) #02 #00 DIV
( underflow ) POP
( overflow ) #00 &l #ffff ROT INC DUP ?&l POP
- ( divzero ) #02 #00 DIV
-
+
#80 .System/halt DEO
BRK
diff --git a/src/uxn.c b/src/uxn.c
@@ -111,8 +111,8 @@ uxn_eval(Uxn *u, Uint16 pc)
case 0x39: t=T2;n=N2; SET(4,-2) PUT2(0, n - t) break;
case 0x1a: /* MUL */ t=T;n=N; SET(2,-1) PUT(0, n * t) break;
case 0x3a: t=T2;n=N2; SET(4,-2) PUT2(0, n * t) break;
- case 0x1b: /* DIV */ t=T;n=N; SET(2,-1) PUT(0, n / t) break;
- case 0x3b: t=T2;n=N2; SET(4,-2) PUT2(0, n / t) break;
+ case 0x1b: /* DIV */ t=T;n=N; SET(2,-1) if(!t) HALT(3) PUT(0, n / t) break;
+ case 0x3b: t=T2;n=N2; SET(4,-2) if(!t) HALT(3) PUT2(0, n / t) break;
case 0x1c: /* AND */ t=T;n=N; SET(2,-1) PUT(0, n & t) break;
case 0x3c: t=T2;n=N2; SET(4,-2) PUT2(0, n & t) break;
case 0x1d: /* ORA */ t=T;n=N; SET(2,-1) PUT(0, n | t) break;