(uxn.c) Catch underflow with JCI

This commit is contained in:
neauoire 2023-08-30 09:24:09 -07:00
parent c9183a02e5
commit d974111939
3 changed files with 16 additions and 17 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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())