diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 21cedee3b..30ec753ca 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -484,7 +484,7 @@ void CDROM::Reset() s_mode.read_raw_sector = true; s_interrupt_enable_register = INTERRUPT_REGISTER_MASK; s_interrupt_flag_register = 0; - s_last_interrupt_time = TimingEvents::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY; + s_last_interrupt_time = System::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY; ClearAsyncInterrupt(); s_setloc_position = {}; s_seek_start_lba = 0; @@ -605,7 +605,7 @@ bool CDROM::DoState(StateWrapper& sw) sw.Do(&s_interrupt_enable_register); sw.Do(&s_interrupt_flag_register); - sw.DoEx(&s_last_interrupt_time, 57, TimingEvents::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY); + sw.DoEx(&s_last_interrupt_time, 57, System::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY); sw.Do(&s_pending_async_interrupt); sw.DoPOD(&s_setloc_position); sw.Do(&s_current_lba); @@ -1097,7 +1097,7 @@ bool CDROM::HasPendingAsyncInterrupt() void CDROM::SetInterrupt(Interrupt interrupt) { s_interrupt_flag_register = static_cast(interrupt); - s_last_interrupt_time = TimingEvents::GetGlobalTickCounter(); + s_last_interrupt_time = System::GetGlobalTickCounter(); UpdateInterruptRequest(); } @@ -1138,7 +1138,7 @@ void CDROM::QueueDeliverAsyncInterrupt() return; // underflows here are okay - const u32 diff = TimingEvents::GetGlobalTickCounter() - s_last_interrupt_time; + const u32 diff = System::GetGlobalTickCounter() - s_last_interrupt_time; if (diff >= MINIMUM_INTERRUPT_DELAY) { DeliverAsyncInterrupt(nullptr, 0, 0); @@ -2442,13 +2442,13 @@ void CDROM::UpdatePositionWhileSeeking() s_current_lba = current_lba; s_physical_lba = current_lba; - s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter(); + s_physical_lba_update_tick = System::GetGlobalTickCounter(); s_physical_lba_update_carry = 0; } void CDROM::UpdatePhysicalPosition(bool update_logical) { - const u32 ticks = TimingEvents::GetGlobalTickCounter(); + const u32 ticks = System::GetGlobalTickCounter(); if (IsSeeking() || IsReadingOrPlaying() || !IsMotorOn()) { // If we're seeking+reading the first sector (no stat bits set), we need to return the set/current lba, not the last @@ -2539,7 +2539,7 @@ void CDROM::SetHoldPosition(CDImage::LBA lba, bool update_subq) s_current_lba = lba; s_physical_lba = lba; - s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter(); + s_physical_lba_update_tick = System::GetGlobalTickCounter(); s_physical_lba_update_carry = 0; } @@ -2607,7 +2607,7 @@ bool CDROM::CompleteSeek() } s_physical_lba = s_current_lba; - s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter(); + s_physical_lba_update_tick = System::GetGlobalTickCounter(); s_physical_lba_update_carry = 0; return seek_okay; } @@ -2783,7 +2783,7 @@ void CDROM::DoSectorRead() s_current_lba = s_reader.GetLastReadSector(); s_physical_lba = s_current_lba; - s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter(); + s_physical_lba_update_tick = System::GetGlobalTickCounter(); s_physical_lba_update_carry = 0; s_secondary_status.SetReadingBits(s_drive_state == DriveState::Playing); diff --git a/src/core/cpu_code_cache.cpp b/src/core/cpu_code_cache.cpp index ab387b0b9..dd8e0eb35 100644 --- a/src/core/cpu_code_cache.cpp +++ b/src/core/cpu_code_cache.cpp @@ -875,11 +875,11 @@ template void CPU::CodeCache::LogCurrentState() { #if 0 - if ((TimingEvents::GetGlobalTickCounter() + GetPendingTicks()) == 2546728915) + if (System::GetGlobalTickCounter() == 2546728915) __debugbreak(); #endif #if 0 - if ((TimingEvents::GetGlobalTickCounter() + GetPendingTicks()) < 2546729174) + if (System::GetGlobalTickCounter() < 2546729174) return; #endif @@ -888,10 +888,10 @@ void CPU::CodeCache::LogCurrentState() "tick=%u dc=%u/%u pc=%08X at=%08X v0=%08X v1=%08X a0=%08X a1=%08X a2=%08X a3=%08X t0=%08X t1=%08X t2=%08X t3=%08X " "t4=%08X t5=%08X t6=%08X t7=%08X s0=%08X s1=%08X s2=%08X s3=%08X s4=%08X s5=%08X s6=%08X s7=%08X t8=%08X t9=%08X " "k0=%08X k1=%08X gp=%08X sp=%08X fp=%08X ra=%08X hi=%08X lo=%08X ldr=%s ldv=%08X cause=%08X sr=%08X gte=%08X\n", - TimingEvents::GetGlobalTickCounter() + GetPendingTicks(), g_state.pending_ticks, g_state.downcount, g_state.pc, - regs.at, regs.v0, regs.v1, regs.a0, regs.a1, regs.a2, regs.a3, regs.t0, regs.t1, regs.t2, regs.t3, regs.t4, regs.t5, - regs.t6, regs.t7, regs.s0, regs.s1, regs.s2, regs.s3, regs.s4, regs.s5, regs.s6, regs.s7, regs.t8, regs.t9, regs.k0, - regs.k1, regs.gp, regs.sp, regs.fp, regs.ra, regs.hi, regs.lo, + System::GetGlobalTickCounter(), g_state.pending_ticks, g_state.downcount, g_state.pc, regs.at, regs.v0, regs.v1, + regs.a0, regs.a1, regs.a2, regs.a3, regs.t0, regs.t1, regs.t2, regs.t3, regs.t4, regs.t5, regs.t6, regs.t7, regs.s0, + regs.s1, regs.s2, regs.s3, regs.s4, regs.s5, regs.s6, regs.s7, regs.t8, regs.t9, regs.k0, regs.k1, regs.gp, regs.sp, + regs.fp, regs.ra, regs.hi, regs.lo, (g_state.next_load_delay_reg == Reg::count) ? "NONE" : GetRegName(g_state.next_load_delay_reg), (g_state.next_load_delay_reg == Reg::count) ? 0 : g_state.next_load_delay_value, g_state.cop0_regs.cause.bits, g_state.cop0_regs.sr.bits, static_cast(crc32(0, (const Bytef*)&g_state.gte_regs, sizeof(g_state.gte_regs)))); diff --git a/src/core/system.cpp b/src/core/system.cpp index c683a531c..992227185 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -392,6 +392,11 @@ void System::UpdateOverclock() UpdateThrottlePeriod(); } +u32 System::GetGlobalTickCounter() +{ + return TimingEvents::GetGlobalTickCounter() + CPU::GetPendingTicks(); +} + u32 System::GetFrameNumber() { return s_frame_number; @@ -2547,7 +2552,7 @@ void System::UpdatePerformanceCounters() const u32 frames_run = s_frame_number - s_last_frame_number; const float frames_runf = static_cast(frames_run); - const u32 global_tick_counter = TimingEvents::GetGlobalTickCounter(); + const u32 global_tick_counter = GetGlobalTickCounter(); // TODO: Make the math here less rubbish const double pct_divider = @@ -2605,7 +2610,7 @@ void System::ResetPerformanceCounters() { s_last_frame_number = s_frame_number; s_last_internal_frame_number = s_internal_frame_number; - s_last_global_tick_counter = TimingEvents::GetGlobalTickCounter(); + s_last_global_tick_counter = GetGlobalTickCounter(); s_last_cpu_time = s_cpu_thread_handle ? s_cpu_thread_handle.GetCPUTime() : 0; if (const Threading::Thread* sw_thread = g_gpu->GetSWThread(); sw_thread) s_last_sw_time = sw_thread->GetCPUTime(); diff --git a/src/core/system.h b/src/core/system.h index 3ef7ee23f..46574d962 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -191,6 +191,7 @@ void UpdateOverclock(); /// direct execution to this executable. bool InjectEXEFromBuffer(const void* buffer, u32 buffer_size, bool patch_loader = true); +u32 GetGlobalTickCounter(); u32 GetFrameNumber(); u32 GetInternalFrameNumber(); void IncrementInternalFrameNumber();