diff --git a/pcsx2/Counters.cpp b/pcsx2/Counters.cpp index 70226b3bd0..33034de1d9 100644 --- a/pcsx2/Counters.cpp +++ b/pcsx2/Counters.cpp @@ -162,6 +162,24 @@ static __fi void cpuRcntSet() cpuSetNextEvent(nextsCounter, nextCounter); // Need to update on counter resets/target changes } + +struct vSyncTimingInfo +{ + double Framerate; // frames per second (8 bit fixed) + GS_VideoMode VideoMode; // used to detect change (interlaced/progressive) + u32 Render; // time from vblank end to vblank start (cycles) + u32 Blank; // time from vblank start to vblank end (cycles) + + u32 GSBlank; // GS CSR is swapped roughly 3.5 hblank's after vblank start + + u32 hSyncError; // rounding error after the duration of a rendered frame (cycles) + u32 hRender; // time from hblank end to hblank start (cycles) + u32 hBlank; // time from hblank start to hblank end (cycles) + u32 hScanlinesPerFrame; // number of scanlines per frame (525/625 for NTSC/PAL) +}; + +static vSyncTimingInfo vSyncInfo; + void rcntInit() { int i; @@ -180,9 +198,16 @@ void rcntInit() counters[2].interrupt = 11; counters[3].interrupt = 12; + std::memset(&vSyncInfo, 0, sizeof(vSyncInfo)); + + gsVideoMode = GS_VideoMode::Uninitialized; + gsIsInterlaced = VMManager::Internal::IsFastBootInProgress(); + hsyncCounter.Mode = MODE_HRENDER; hsyncCounter.sCycle = cpuRegs.cycle; + vsyncCounter.CycleT = vSyncInfo.hRender; vsyncCounter.Mode = MODE_VRENDER; + vsyncCounter.CycleT = vSyncInfo.Render; vsyncCounter.sCycle = cpuRegs.cycle; for (i = 0; i < 4; i++) @@ -190,23 +215,6 @@ void rcntInit() cpuRcntSet(); } -struct vSyncTimingInfo -{ - double Framerate; // frames per second (8 bit fixed) - GS_VideoMode VideoMode; // used to detect change (interlaced/progressive) - u32 Render; // time from vblank end to vblank start (cycles) - u32 Blank; // time from vblank start to vblank end (cycles) - - u32 GSBlank; // GS CSR is swapped roughly 3.5 hblank's after vblank start - - u32 hSyncError; // rounding error after the duration of a rendered frame (cycles) - u32 hRender; // time from hblank end to hblank start (cycles) - u32 hBlank; // time from hblank start to hblank end (cycles) - u32 hScanlinesPerFrame; // number of scanlines per frame (525/625 for NTSC/PAL) -}; - -static vSyncTimingInfo vSyncInfo; - static void vSyncInfoCalc(vSyncTimingInfo* info, double framesPerSecond, u32 scansPerFrame) { constexpr double clock = static_cast(PS2CLK); diff --git a/pcsx2/Hw.cpp b/pcsx2/Hw.cpp index 7b61133d59..61fa2b0dfa 100644 --- a/pcsx2/Hw.cpp +++ b/pcsx2/Hw.cpp @@ -40,19 +40,19 @@ void hwReset() psHu32(DMAC_ENABLEW) = 0x1201; psHu32(DMAC_ENABLER) = 0x1201; + rcntInit(); + // Sets SPU2 sample rate to PS2 standard (48KHz) whenever emulator is reset. // For PSX mode sample rate setting, see HwWrite.cpp SPU2::Reset(false); sifReset(); - gsReset(); gifUnit.Reset(); ipuReset(); vif0Reset(); vif1Reset(); gif_fifo.init(); - rcntInit(); USBreset(); } diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 47a0d3afb2..1cbf758117 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -1240,6 +1240,14 @@ bool VMManager::Initialize(VMBootParameters boot_params) s_target_speed = GetTargetSpeedForLimiterMode(s_limiter_mode); s_use_vsync_for_timing = false; + s_cpu_implementation_changed = false; + s_cpu_provider_pack->ApplyConfig(); + SetCPUState(EmuConfig.Cpu.sseMXCSR, EmuConfig.Cpu.sseVU0MXCSR, EmuConfig.Cpu.sseVU1MXCSR); + SysClearExecutionCache(); + memBindConditionalHandlers(); + SysMemory::Reset(); + cpuReset(); + Console.WriteLn("Opening GS..."); s_gs_open_on_initialize = MTGS::IsOpen(); if (!s_gs_open_on_initialize && !MTGS::WaitForOpen()) @@ -1338,13 +1346,6 @@ bool VMManager::Initialize(VMBootParameters boot_params) s_mxcsr_saved = static_cast(a64_getfpcr()); #endif - s_cpu_implementation_changed = false; - s_cpu_provider_pack->ApplyConfig(); - SetCPUState(EmuConfig.Cpu.sseMXCSR, EmuConfig.Cpu.sseVU0MXCSR, EmuConfig.Cpu.sseVU1MXCSR); - SysClearExecutionCache(); - memBindConditionalHandlers(); - SysMemory::Reset(); - cpuReset(); hwReset(); Console.WriteLn("VM subsystems initialized in %.2f ms", init_timer.GetTimeMilliseconds());