Skip to content

Commit

Permalink
Update with new fault handler behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
cancel committed Jan 13, 2023
1 parent 9ddc27c commit aeef034
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions uxn32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1184,19 +1184,21 @@ static void RunUxn(EmuWindow *d, UINT steps, BOOL initial)
/* TODO add checkbox to enable this debris check if (u->wst->ptr || u->rst->ptr) u->fault_code = 127; */
if (u->fault_code != UXN_FAULT_DONE)
{
UINT fault_handler;
UINT last_addr = ((UINT)u->pc - 1) % UXN_RAM_SIZE, last_op = u->ram[last_addr], fault_handler;
DEVPEEK(d->box->device_memory, fault_handler, 0x0);
if (u->fault_code <= UXN_FAULT_DIVIDE_BY_ZERO && fault_handler)
if (fault_handler && u->fault_code <= UXN_FAULT_DIVIDE_BY_ZERO)
{
u->wst->ptr = 4;
u->wst->dat[0] = last_addr >> 8, u->wst->dat[1] = last_addr;
u->wst->dat[2] = last_op;
u->wst->dat[3] = u->fault_code - 1;
u->fault_code = 0;
u->pc = fault_handler;
u->wst->ptr = 1;
u->wst->dat[0] = u->fault_code - 1;
goto residual;
}
/* If there's a division by zero, push 0xFF onto the stack to rebalance it. Then, if the user hits resume, the program has a better chance of not faulting again. */
if (u->fault_code == UXN_FAULT_DIVIDE_BY_ZERO)
{
UINT last_op = u->ram[((UINT)u->pc - 1) % UXN_RAM_SIZE]; /* Get last op executed */
UxnStack *s = last_op & 0x40 ? u->rst : u->wst; /* Which stack to push to */
int i = 0, count = (last_op & 0x20) >> 5; /* Push 1 or 2 bytes */
for (; i <= count; i++) s->dat[s->ptr++] = 0xFF;
Expand Down

0 comments on commit aeef034

Please sign in to comment.