mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-04 21:35:04 +00:00
(uxn.c) Catch underflow with JCI
This commit is contained in:
parent
c9183a02e5
commit
d974111939
3 changed files with 16 additions and 17 deletions
11
src/uxn.c
11
src/uxn.c
|
@ -24,14 +24,13 @@ WITH REGARD TO THIS SOFTWARE.
|
||||||
#define H2 PEEK2((ptr - 2))
|
#define H2 PEEK2((ptr - 2))
|
||||||
#define N2 PEEK2((ptr - 3))
|
#define N2 PEEK2((ptr - 3))
|
||||||
#define L2 PEEK2((ptr - 5))
|
#define L2 PEEK2((ptr - 5))
|
||||||
|
|
||||||
#define HALT(c) { return emu_halt(u, ins, c, pc - 1); }
|
#define HALT(c) { return emu_halt(u, ins, c, pc - 1); }
|
||||||
#define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; }
|
#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 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 PUT1(a) { *ptr = a; }
|
||||||
#define PUT1x2(a, b) { *(ptr) = a; *(ptr - 1) = b; }
|
#define PUT1x2(a, b) { *ptr = a; *(ptr - 1) = b; }
|
||||||
#define PUT1x3(a, b, c) { *(ptr) = a; *(ptr - 1) = b; *(ptr - 2) = c; }
|
#define PUT1x3(a, b, c) { *ptr = a; *(ptr - 1) = b; *(ptr - 2) = c; }
|
||||||
#define PUT2(a) { POKE2(ptr - 1, a) }
|
#define PUT2(a) { r = (a); POKE2(ptr - 1, r) }
|
||||||
#define PUT2x2(a, b) { POKE2(ptr - 1, a) POKE2(ptr - 3, b) }
|
#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) }
|
#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) {
|
switch(ins & 0x1f ? ins & 0x3f : ins << 4) {
|
||||||
/* IMM */
|
/* IMM */
|
||||||
case 0x000: /* BRK */ return 1;
|
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 0x400: /* JMI */ pc += PEEK2(ram + pc) + 2; break;
|
||||||
case 0x600: /* JSI */ SET(0, 2) PUT2(pc + 2) 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;
|
case 0x800: /* LIT */ case 0xc00: SET(0, 1) PUT1(ram[pc++]) break;
|
||||||
|
|
|
@ -72,7 +72,7 @@ main(int argc, char **argv)
|
||||||
system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
|
system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
|
||||||
/* Read flags */
|
/* Read flags */
|
||||||
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
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++]))
|
if(!system_init(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++]))
|
||||||
return system_error("Init", "Failed to initialize uxn.");
|
return system_error("Init", "Failed to initialize uxn.");
|
||||||
/* Game Loop */
|
/* Game Loop */
|
||||||
|
|
|
@ -516,7 +516,7 @@ main(int argc, char **argv)
|
||||||
system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
|
system_connect(0xc, DATETIME_VERSION, DATETIME_DEIMASK, DATETIME_DEOMASK);
|
||||||
/* Read flags */
|
/* Read flags */
|
||||||
if(argv[i][0] == '-' && argv[i][1] == 'v')
|
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)
|
if(strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)
|
||||||
set_zoom(argv[i++][1] - '0', 0);
|
set_zoom(argv[i++][1] - '0', 0);
|
||||||
if(!emu_init())
|
if(!emu_init())
|
||||||
|
|
Loading…
Reference in a new issue