Fix Pop() implementation in src/sim65/paravirt.c (fixes #1625)

The Pop() function was not handling stack pointer wrap around correctly.

Also, change the simulated RTS implementation in ParaVirtHooks() to
explicitly sequence the two Pop() calls in the correct order.
This commit is contained in:
Matthew D. Steele 2022-01-07 09:56:46 -05:00
parent 6ac4aa4e20
commit cf1bc4fad4

View file

@ -105,7 +105,7 @@ static void SetAX (CPURegs* Regs, unsigned Val)
static unsigned char Pop (CPURegs* Regs)
{
return MemReadByte (0x0100 + ++Regs->SP);
return MemReadByte (0x0100 + (++Regs->SP & 0xFF));
}
@ -327,5 +327,7 @@ void ParaVirtHooks (CPURegs* Regs)
Hooks[Regs->PC - PARAVIRT_BASE] (Regs);
/* Simulate RTS */
Regs->PC = Pop(Regs) + (Pop(Regs) << 8) + 1;
unsigned lo = Pop(Regs);
unsigned hi = Pop(Regs);
Regs->PC = lo + (hi << 8) + 1;
}