uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit fb892e4329c37d2b0eaa20ce5652096db02d9f5e
parent a65c1cb9a8c06730a617875a57bbddb002d4e7d7
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat,  2 Sep 2023 13:51:03 -0700

Uxn can no longer error

Diffstat:
Msrc/devices/system.c | 26--------------------------
Msrc/uxn.c | 15+++++++--------
Msrc/uxn.h | 1-
Msrc/uxncli.c | 2+-
Msrc/uxnemu.c | 2+-
5 files changed, 9 insertions(+), 37 deletions(-)

diff --git a/src/devices/system.c b/src/devices/system.c @@ -19,11 +19,6 @@ char *boot_rom; Uint8 dei_masks[0x100], deo_masks[0x100]; Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10]; -static const char *errors[] = { - "underflow", - "overflow", - "division by zero"}; - static int system_load(Uxn *u, char *filename) { @@ -164,24 +159,3 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port) break; } } - -/* Errors */ - -int -emu_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) -{ - Uint8 *d = &u->dev[0]; - Uint16 handler = PEEK2(d); - if(handler) { - u->wst.ptr = 4; - u->wst.dat[0] = addr >> 0x8; - u->wst.dat[1] = addr & 0xff; - u->wst.dat[2] = instr; - u->wst.dat[3] = err; - return uxn_eval(u, handler); - } else { - system_inspect(u); - fprintf(stderr, "%s %s, by %02x at 0x%04x.\n", (instr & 0x40) ? "Return-stack" : "Working-stack", errors[err - 1], instr, addr); - } - return 0; -} diff --git a/src/uxn.c b/src/uxn.c @@ -17,7 +17,7 @@ WITH REGARD TO THIS SOFTWARE. [ L2 ][ N2 ][ T2 ] < */ -#define T *ptr +#define T *(ptr) #define N *(ptr - 1) #define L *(ptr - 2) #define X *(ptr - 3) @@ -31,21 +31,20 @@ WITH REGARD TO THIS SOFTWARE. #define N2_(v) { r = (v); L = r; X = r >> 8; } #define L2_(v) { r = (v); Y = r; Z = r >> 8; } -#define HALT(c) { return emu_halt(u, ins, c, pc - 1); } #define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; } -#define SET(x, y) { r = s->ptr; if(x > r) HALT(1) r += y; if(ins & 0x80) r += x; if(r > 254) HALT(2) ptr = s->dat + r - 1; s->ptr = r; } -#define SHIFT(y) { r = s->ptr + y; if(r > 254) HALT(2) ptr = s->dat + r - 1; s->ptr = r; } +#define SHIFT(y) { r = s->ptr + (y); ptr = s->dat + r - 1; s->ptr = r; } +#define SET(x, y) { SHIFT((ins & 0x80) ? x + y : y) } int uxn_eval(Uxn *u, Uint16 pc) { int t, n, l, r; - Uint8 *ram = u->ram; + Uint8 *ram = u->ram, *rr; if(!pc || u->dev[0x0f]) return 0; for(;;) { int ins = ram[pc++]; Stack *s = ins & 0x40 ? &u->rst : &u->wst; - Uint8 *ptr = s->dat + s->ptr - 1, *rr; + Uint8 *ptr = s->dat + s->ptr - 1; switch(ins & 0x1f ? ins & 0x3f : ins << 4) { /* IMM */ case 0x000: /* BRK */ return 1; @@ -107,8 +106,8 @@ uxn_eval(Uxn *u, Uint16 pc) case 0x39: /* SUB2 */ t=T2;n=N2; SET(4,-2) T2_(n - t) break; case 0x1a: /* MUL */ t=T;n=N; SET(2,-1) T = n * t; break; case 0x3a: /* MUL2 */ t=T2;n=N2; SET(4,-2) T2_(n * t) break; - case 0x1b: /* DIV */ t=T;n=N; SET(2,-1) if(!t) HALT(3) T = n / t; break; - case 0x3b: /* DIV2 */ t=T2;n=N2; SET(4,-2) if(!t) HALT(3) T2_(n / t) break; + case 0x1b: /* DIV */ t=T;n=N; SET(2,-1) T = t ? n / t : 0; break; + case 0x3b: /* DIV2 */ t=T2;n=N2; SET(4,-2) T2_(t ? n / t : 0) break; case 0x1c: /* AND */ t=T;n=N; SET(2,-1) T = n & t; break; case 0x3c: /* AND2 */ t=T2;n=N2; SET(4,-2) T2_(n & t) break; case 0x1d: /* ORA */ t=T;n=N; SET(2,-1) T = n | t; break; diff --git a/src/uxn.h b/src/uxn.h @@ -39,7 +39,6 @@ typedef struct Uxn { extern Uint8 emu_dei(Uxn *u, Uint8 addr); extern void emu_deo(Uxn *u, Uint8 addr); -extern int emu_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr); extern Uint8 dei_masks[0x100], deo_masks[0x100]; extern Uint16 dev_vers[0x10], dei_mask[0x10], deo_mask[0x10]; diff --git a/src/uxncli.c b/src/uxncli.c @@ -72,7 +72,7 @@ main(int argc, char **argv) system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK); /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') - return system_version("Uxncli - Console Varvara Emulator", "29 Aug 2023"); + return system_version("Uxncli - Console Varvara Emulator", "2 Sep 2023"); if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++])) return system_error("Init", "Failed to initialize uxn."); /* Game Loop */ diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -524,7 +524,7 @@ main(int argc, char **argv) system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK); /* Read flags */ if(argv[i][0] == '-' && argv[i][1] == 'v') - return system_version("Uxnemu - Graphical Varvara Emulator", "30 Aug 2023"); + return system_version("Uxnemu - Graphical Varvara Emulator", "2 Sep 2023"); if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) set_zoom(argv[i++][1] - '0', 0); if(!emu_init())