Add IRQ transition.

This commit is contained in:
Brandon Wright 2018-05-27 11:03:21 -05:00
parent 15f76f7eca
commit c932d4e37a
3 changed files with 26 additions and 15 deletions

View File

@ -229,6 +229,7 @@ static void S9xSoftResetCPU (void)
CPU.PCBase = NULL; CPU.PCBase = NULL;
CPU.NMIPending = FALSE; CPU.NMIPending = FALSE;
CPU.IRQLine = FALSE; CPU.IRQLine = FALSE;
CPU.IRQTransition = FALSE;
CPU.IRQExternal = FALSE; CPU.IRQExternal = FALSE;
CPU.IRQPending = Timings.IRQPendCount; CPU.IRQPending = Timings.IRQPendCount;
CPU.MemSpeed = SLOW_ONE_CYCLE; CPU.MemSpeed = SLOW_ONE_CYCLE;

View File

@ -223,7 +223,7 @@ void S9xMainLoop (void)
{ {
CPU.WaitingForInterrupt = FALSE; CPU.WaitingForInterrupt = FALSE;
Registers.PCw++; Registers.PCw++;
CPU.Cycles += 14; CPU.Cycles += ONE_CYCLE;
while (CPU.Cycles >= CPU.NextEvent) while (CPU.Cycles >= CPU.NextEvent)
S9xDoHEventProcessing(); S9xDoHEventProcessing();
} }
@ -232,24 +232,30 @@ void S9xMainLoop (void)
} }
} }
if ((CPU.Cycles >= Timings.NextIRQTimer || CPU.IRQExternal) && !CPU.IRQLine) if (CPU.IRQTransition)
{
if (CPU.WaitingForInterrupt)
{
CPU.WaitingForInterrupt = FALSE;
Registers.PCw++;
CPU.Cycles += ONE_CYCLE;
while (CPU.Cycles >= CPU.NextEvent)
S9xDoHEventProcessing();
}
S9xUpdateIRQPositions();
CPU.IRQPending = Timings.IRQPendCount;
CPU.IRQTransition = FALSE;
CPU.IRQLine = TRUE;
}
if ((CPU.Cycles >= Timings.NextIRQTimer || CPU.IRQExternal) && !CPU.IRQLine && !CPU.IRQTransition)
{ {
if (CPU.IRQPending) if (CPU.IRQPending)
CPU.IRQPending--; CPU.IRQPending--;
else else
{ {
if (CPU.WaitingForInterrupt) CPU.IRQTransition = TRUE;
{
CPU.WaitingForInterrupt = FALSE;
Registers.PCw++;
CPU.Cycles += 14;
while (CPU.Cycles >= CPU.NextEvent)
S9xDoHEventProcessing();
}
S9xUpdateIRQPositions();
CPU.IRQPending = Timings.IRQPendCount;
CPU.IRQLine = TRUE;
} }
} }

View File

@ -334,7 +334,7 @@ void S9xUpdateIRQPositions (void)
else if (!PPU.HTimerEnabled && PPU.VTimerEnabled) else if (!PPU.HTimerEnabled && PPU.VTimerEnabled)
{ {
if (CPU.V_Counter == PPU.VTimerPosition) if (CPU.V_Counter == PPU.VTimerPosition)
Timings.NextIRQTimer = 0; Timings.NextIRQTimer = Timings.IRQTriggerCycles;
else else
Timings.NextIRQTimer = CyclesUntilNext (Timings.IRQTriggerCycles, PPU.VTimerPosition); Timings.NextIRQTimer = CyclesUntilNext (Timings.IRQTriggerCycles, PPU.VTimerPosition);
} }
@ -1556,7 +1556,10 @@ void S9xSetCPU (uint8 Byte, uint16 Address)
PPU.HTimerEnabled = FALSE; PPU.HTimerEnabled = FALSE;
if (!(Byte & 0x10) && !(Byte & 0x20)) if (!(Byte & 0x10) && !(Byte & 0x20))
{
CPU.IRQLine = FALSE; CPU.IRQLine = FALSE;
CPU.IRQTransition = FALSE;
}
S9xUpdateIRQPositions(); S9xUpdateIRQPositions();
@ -1842,6 +1845,7 @@ uint8 S9xGetCPU (uint16 Address)
case 0x4211: // TIMEUP case 0x4211: // TIMEUP
byte = CPU.IRQLine ? 0x80 : 0; byte = CPU.IRQLine ? 0x80 : 0;
CPU.IRQLine = FALSE; CPU.IRQLine = FALSE;
CPU.IRQTransition = FALSE;
S9xUpdateIRQPositions(); S9xUpdateIRQPositions();
return (byte | (OpenBus & 0x7f)); return (byte | (OpenBus & 0x7f));