From 32fa0f95c3e2f43471c3d8e273e40400cabe6a36 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Sat, 15 Apr 2023 09:52:08 -0700 Subject: [PATCH] (uxn.c) Catch div-by-zero errors --- projects/examples/devices/system.tal | 4 ++-- src/uxn.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/examples/devices/system.tal b/projects/examples/devices/system.tal index 8d122fc..85c1325 100644 --- 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 index 0307ffa..9ecea01 100644 --- 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;