uxn

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

commit d974111939089a65b1f4c078c5008f675fff5531
parent c9183a02e5a0d0eb8da34c71c2ca67eb2e2e7453
Author: neauoire <aliceffekt@gmail.com>
Date:   Wed, 30 Aug 2023 09:24:09 -0700

(uxn.c) Catch underflow with JCI

Diffstat:
Msrc/uxn.c | 29++++++++++++++---------------
Msrc/uxncli.c | 2+-
Msrc/uxnemu.c | 2+-
3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/src/uxn.c b/src/uxn.c @@ -18,20 +18,19 @@ WITH REGARD TO THIS SOFTWARE. */ #define T *ptr -#define N *(ptr-1) -#define L *(ptr-2) -#define T2 PEEK2((ptr-1)) -#define H2 PEEK2((ptr-2)) -#define N2 PEEK2((ptr-3)) -#define L2 PEEK2((ptr-5)) - -#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 += (x & k) + y; if(r > 254) HALT(2) ptr = s->dat + r - 1; s->ptr = r; } -#define PUT1(a) { *(ptr) = a; } -#define PUT1x2(a, b) { *(ptr) = a; *(ptr - 1) = b; } -#define PUT1x3(a, b, c) { *(ptr) = a; *(ptr - 1) = b; *(ptr - 2) = c; } -#define PUT2(a) { POKE2(ptr - 1, a) } +#define N *(ptr - 1) +#define L *(ptr - 2) +#define T2 PEEK2((ptr - 1)) +#define H2 PEEK2((ptr - 2)) +#define N2 PEEK2((ptr - 3)) +#define L2 PEEK2((ptr - 5)) +#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 += (x & k) + y; if(r > 254) HALT(2) ptr = s->dat + r - 1; s->ptr = r; } +#define PUT1(a) { *ptr = a; } +#define PUT1x2(a, b) { *ptr = a; *(ptr - 1) = b; } +#define PUT1x3(a, b, c) { *ptr = a; *(ptr - 1) = b; *(ptr - 2) = c; } +#define PUT2(a) { r = (a); POKE2(ptr - 1, r) } #define PUT2x2(a, b) { POKE2(ptr - 1, a) POKE2(ptr - 3, b) } #define PUT2x3(a, b, c) { POKE2(ptr - 1, a) POKE2(ptr - 3, b) POKE2(ptr - 5, c) } @@ -49,7 +48,7 @@ uxn_eval(Uxn *u, Uint16 pc) switch(ins & 0x1f ? ins & 0x3f : ins << 4) { /* IMM */ case 0x000: /* BRK */ return 1; - case 0x200: /* JCI */ if(!s->dat[--s->ptr]) { pc += 2; break; } /* else fallthrough */ + case 0x200: /* JCI */ t=T; SET(0,-1) if(!t) { pc += 2; break; } /* else fallthrough */ case 0x400: /* JMI */ pc += PEEK2(ram + pc) + 2; break; case 0x600: /* JSI */ SET(0, 2) PUT2(pc + 2) pc += PEEK2(ram + pc) + 2; break; case 0x800: /* LIT */ case 0xc00: SET(0, 1) PUT1(ram[pc++]) break; 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", "30 Aug 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 @@ -516,7 +516,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", "29 Aug 2023"); + return system_version("Uxnemu - Graphical Varvara Emulator", "30 Aug 2023"); if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0) set_zoom(argv[i++][1] - '0', 0); if(!emu_init())