1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 07:29:33 +00:00

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 committed by mrdudz
parent c2608599aa
commit 623e951e33

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