This was wrong.

This commit is contained in:
Brandon Wright 2018-06-01 14:19:59 -05:00
parent 1dd2501e98
commit 718f580342
4 changed files with 11 additions and 13 deletions

View File

@ -259,7 +259,7 @@ void S9xMainLoop (void)
if ((CPU.Cycles >= Timings.NextIRQTimer) && !CPU.IRQLine && !CPU.IRQTransition) if ((CPU.Cycles >= Timings.NextIRQTimer) && !CPU.IRQLine && !CPU.IRQTransition)
{ {
S9xUpdateIRQPositions(false); S9xUpdateIRQPositions();
#ifdef DEBUGGER #ifdef DEBUGGER
S9xTraceMessage ("Timer triggered\n"); S9xTraceMessage ("Timer triggered\n");

18
ppu.cpp
View File

@ -304,9 +304,10 @@ static int CyclesUntilNext (int hc, int vc)
return total; return total;
} }
void S9xUpdateIRQPositions (bool initial) void S9xUpdateIRQPositions ()
{ {
PPU.HTimerPosition = PPU.IRQHBeamPos * ONE_DOT_CYCLE + Timings.IRQTriggerCycles; PPU.HTimerPosition = PPU.IRQHBeamPos * ONE_DOT_CYCLE + Timings.IRQTriggerCycles;
PPU.HTimerPosition -= PPU.IRQHBeamPos ? 0 : ONE_DOT_CYCLE;
PPU.HTimerPosition += PPU.IRQHBeamPos > 322 ? (ONE_DOT_CYCLE / 2) : 0; PPU.HTimerPosition += PPU.IRQHBeamPos > 322 ? (ONE_DOT_CYCLE / 2) : 0;
PPU.HTimerPosition += PPU.IRQHBeamPos > 326 ? (ONE_DOT_CYCLE / 2) : 0; PPU.HTimerPosition += PPU.IRQHBeamPos > 326 ? (ONE_DOT_CYCLE / 2) : 0;
PPU.VTimerPosition = PPU.IRQVBeamPos; PPU.VTimerPosition = PPU.IRQVBeamPos;
@ -335,10 +336,7 @@ void S9xUpdateIRQPositions (bool initial)
} }
else if (!PPU.HTimerEnabled && PPU.VTimerEnabled) else if (!PPU.HTimerEnabled && PPU.VTimerEnabled)
{ {
if (CPU.V_Counter == PPU.VTimerPosition && initial) Timings.NextIRQTimer = CyclesUntilNext (Timings.IRQTriggerCycles, PPU.VTimerPosition);
Timings.NextIRQTimer = CPU.Cycles + Timings.IRQTriggerCycles;
else
Timings.NextIRQTimer = CyclesUntilNext (Timings.IRQTriggerCycles, PPU.VTimerPosition);
} }
else else
{ {
@ -1577,7 +1575,7 @@ void S9xSetCPU (uint8 Byte, uint16 Address)
CPU.IRQTransition = FALSE; CPU.IRQTransition = FALSE;
} }
S9xUpdateIRQPositions(true); S9xUpdateIRQPositions();
// 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) &&
@ -1644,7 +1642,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(false); S9xUpdateIRQPositions();
#ifdef DEBUGGER #ifdef DEBUGGER
missing.hirq_pos = PPU.IRQHBeamPos; missing.hirq_pos = PPU.IRQHBeamPos;
#endif #endif
@ -1654,7 +1652,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(false); S9xUpdateIRQPositions();
#ifdef DEBUGGER #ifdef DEBUGGER
missing.hirq_pos = PPU.IRQHBeamPos; missing.hirq_pos = PPU.IRQHBeamPos;
#endif #endif
@ -1664,7 +1662,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(true); S9xUpdateIRQPositions();
#ifdef DEBUGGER #ifdef DEBUGGER
missing.virq_pos = PPU.IRQVBeamPos; missing.virq_pos = PPU.IRQVBeamPos;
#endif #endif
@ -1674,7 +1672,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(true); S9xUpdateIRQPositions();
#ifdef DEBUGGER #ifdef DEBUGGER
missing.virq_pos = PPU.IRQVBeamPos; missing.virq_pos = PPU.IRQVBeamPos;
#endif #endif

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 (bool initial); void S9xUpdateIRQPositions ();
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(false); S9xUpdateIRQPositions();
S9xFixCycles(); S9xFixCycles();
for (int d = 0; d < 8; d++) for (int d = 0; d < 8; d++)