Don't schedule recurring vtimer for current line immediately.

This commit is contained in:
Brandon Wright 2018-05-28 11:24:18 -05:00
parent 1cd8d65705
commit 09c4e97c32
4 changed files with 15 additions and 13 deletions

View File

@ -243,7 +243,7 @@ void S9xMainLoop (void)
S9xDoHEventProcessing(); S9xDoHEventProcessing();
} }
S9xUpdateIRQPositions();
CPU.IRQPending = Timings.IRQPendCount; CPU.IRQPending = Timings.IRQPendCount;
CPU.IRQTransition = FALSE; CPU.IRQTransition = FALSE;
CPU.IRQLine = TRUE; CPU.IRQLine = TRUE;
@ -251,6 +251,8 @@ void S9xMainLoop (void)
if ((CPU.Cycles >= Timings.NextIRQTimer) && !CPU.IRQLine && !CPU.IRQTransition) if ((CPU.Cycles >= Timings.NextIRQTimer) && !CPU.IRQLine && !CPU.IRQTransition)
{ {
S9xUpdateIRQPositions(false);
if (CPU.IRQPending) if (CPU.IRQPending)
CPU.IRQPending--; CPU.IRQPending--;
else else

20
ppu.cpp
View File

@ -304,7 +304,7 @@ static int CyclesUntilNext (int hc, int vc)
return total; return total;
} }
void S9xUpdateIRQPositions (void) void S9xUpdateIRQPositions (bool initial)
{ {
PPU.HTimerPosition = PPU.IRQHBeamPos * ONE_DOT_CYCLE + Timings.IRQTriggerCycles; PPU.HTimerPosition = PPU.IRQHBeamPos * ONE_DOT_CYCLE + Timings.IRQTriggerCycles;
if (Timings.H_Max == Timings.H_Max_Master) // 1364 if (Timings.H_Max == Timings.H_Max_Master) // 1364
@ -338,7 +338,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 && initial)
Timings.NextIRQTimer = Timings.IRQTriggerCycles; Timings.NextIRQTimer = Timings.IRQTriggerCycles;
else else
Timings.NextIRQTimer = CyclesUntilNext (Timings.IRQTriggerCycles, PPU.VTimerPosition); Timings.NextIRQTimer = CyclesUntilNext (Timings.IRQTriggerCycles, PPU.VTimerPosition);
@ -349,8 +349,8 @@ void S9xUpdateIRQPositions (void)
} }
#ifdef DEBUGGER #ifdef DEBUGGER
S9xTraceFormattedMessage("--- IRQ Timer set HTimer:%d Pos:%04d VTimer:%d Pos:%03d", S9xTraceFormattedMessage("--- IRQ Timer set %d cycles HTimer:%d Pos:%04d->%04d VTimer:%d Pos:%03d->%03d",
PPU.HTimerEnabled, PPU.HTimerPosition, PPU.VTimerEnabled, PPU.VTimerPosition); Timings.NextIRQTimer, PPU.HTimerEnabled, PPU.IRQHBeamPos, PPU.HTimerPosition, PPU.VTimerEnabled, PPU.IRQVBeamPos, PPU.VTimerPosition);
#endif #endif
} }
@ -1566,7 +1566,7 @@ void S9xSetCPU (uint8 Byte, uint16 Address)
CPU.IRQTransition = FALSE; CPU.IRQTransition = FALSE;
} }
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(true);
// NMI can trigger immediately during VBlank as long as NMI_read ($4210) wasn't cleard. // NMI can trigger immediately during VBlank as long as NMI_read ($4210) wasn't cleard.
if ((Byte & 0x80) && !(Memory.FillRAM[0x4200] & 0x80) && if ((Byte & 0x80) && !(Memory.FillRAM[0x4200] & 0x80) &&
@ -1633,7 +1633,7 @@ if (Settings.TraceHCEvent)
pos = PPU.IRQHBeamPos; pos = PPU.IRQHBeamPos;
PPU.IRQHBeamPos = (PPU.IRQHBeamPos & 0xff00) | Byte; PPU.IRQHBeamPos = (PPU.IRQHBeamPos & 0xff00) | Byte;
if (PPU.IRQHBeamPos != pos) if (PPU.IRQHBeamPos != pos)
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(false);
#ifdef DEBUGGER #ifdef DEBUGGER
missing.hirq_pos = PPU.IRQHBeamPos; missing.hirq_pos = PPU.IRQHBeamPos;
#endif #endif
@ -1643,7 +1643,7 @@ if (Settings.TraceHCEvent)
pos = PPU.IRQHBeamPos; pos = PPU.IRQHBeamPos;
PPU.IRQHBeamPos = (PPU.IRQHBeamPos & 0xff) | ((Byte & 1) << 8); PPU.IRQHBeamPos = (PPU.IRQHBeamPos & 0xff) | ((Byte & 1) << 8);
if (PPU.IRQHBeamPos != pos) if (PPU.IRQHBeamPos != pos)
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(false);
#ifdef DEBUGGER #ifdef DEBUGGER
missing.hirq_pos = PPU.IRQHBeamPos; missing.hirq_pos = PPU.IRQHBeamPos;
#endif #endif
@ -1653,7 +1653,7 @@ if (Settings.TraceHCEvent)
pos = PPU.IRQVBeamPos; pos = PPU.IRQVBeamPos;
PPU.IRQVBeamPos = (PPU.IRQVBeamPos & 0xff00) | Byte; PPU.IRQVBeamPos = (PPU.IRQVBeamPos & 0xff00) | Byte;
if (PPU.IRQVBeamPos != pos) if (PPU.IRQVBeamPos != pos)
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(true);
#ifdef DEBUGGER #ifdef DEBUGGER
missing.virq_pos = PPU.IRQVBeamPos; missing.virq_pos = PPU.IRQVBeamPos;
#endif #endif
@ -1663,7 +1663,7 @@ if (Settings.TraceHCEvent)
pos = PPU.IRQVBeamPos; pos = PPU.IRQVBeamPos;
PPU.IRQVBeamPos = (PPU.IRQVBeamPos & 0xff) | ((Byte & 1) << 8); PPU.IRQVBeamPos = (PPU.IRQVBeamPos & 0xff) | ((Byte & 1) << 8);
if (PPU.IRQVBeamPos != pos) if (PPU.IRQVBeamPos != pos)
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(true);
#ifdef DEBUGGER #ifdef DEBUGGER
missing.virq_pos = PPU.IRQVBeamPos; missing.virq_pos = PPU.IRQVBeamPos;
#endif #endif
@ -1851,7 +1851,7 @@ uint8 S9xGetCPU (uint16 Address)
byte = CPU.IRQLine ? 0x80 : 0; byte = CPU.IRQLine ? 0x80 : 0;
CPU.IRQLine = FALSE; CPU.IRQLine = FALSE;
CPU.IRQTransition = FALSE; CPU.IRQTransition = FALSE;
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(false);
return (byte | (OpenBus & 0x7f)); return (byte | (OpenBus & 0x7f));

2
ppu.h
View File

@ -389,7 +389,7 @@ void S9xSetPPU (uint8, uint16);
uint8 S9xGetPPU (uint16); uint8 S9xGetPPU (uint16);
void S9xSetCPU (uint8, uint16); void S9xSetCPU (uint8, uint16);
uint8 S9xGetCPU (uint16); uint8 S9xGetCPU (uint16);
void S9xUpdateIRQPositions (void); void S9xUpdateIRQPositions (bool initial);
void S9xFixColourBrightness (void); void S9xFixColourBrightness (void);
void S9xDoAutoJoypad (void); void S9xDoAutoJoypad (void);

View File

@ -1780,7 +1780,7 @@ int S9xUnfreezeFromStream (STREAM stream)
ICPU.ShiftedDB = Registers.DB << 16; ICPU.ShiftedDB = Registers.DB << 16;
S9xSetPCBase(Registers.PBPC); S9xSetPCBase(Registers.PBPC);
S9xUnpackStatus(); S9xUnpackStatus();
S9xUpdateIRQPositions(); S9xUpdateIRQPositions(false);
S9xFixCycles(); S9xFixCycles();
for (int d = 0; d < 8; d++) for (int d = 0; d < 8; d++)