System: Consider pending ticks when using global ticks

This commit is contained in:
Stenzek 2024-04-07 19:01:48 +10:00
parent 1782151a7a
commit 71f50566f3
No known key found for this signature in database
4 changed files with 23 additions and 17 deletions

View file

@ -484,7 +484,7 @@ void CDROM::Reset()
s_mode.read_raw_sector = true; s_mode.read_raw_sector = true;
s_interrupt_enable_register = INTERRUPT_REGISTER_MASK; s_interrupt_enable_register = INTERRUPT_REGISTER_MASK;
s_interrupt_flag_register = 0; s_interrupt_flag_register = 0;
s_last_interrupt_time = TimingEvents::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY; s_last_interrupt_time = System::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY;
ClearAsyncInterrupt(); ClearAsyncInterrupt();
s_setloc_position = {}; s_setloc_position = {};
s_seek_start_lba = 0; s_seek_start_lba = 0;
@ -605,7 +605,7 @@ bool CDROM::DoState(StateWrapper& sw)
sw.Do(&s_interrupt_enable_register); sw.Do(&s_interrupt_enable_register);
sw.Do(&s_interrupt_flag_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.Do(&s_pending_async_interrupt);
sw.DoPOD(&s_setloc_position); sw.DoPOD(&s_setloc_position);
sw.Do(&s_current_lba); sw.Do(&s_current_lba);
@ -1097,7 +1097,7 @@ bool CDROM::HasPendingAsyncInterrupt()
void CDROM::SetInterrupt(Interrupt interrupt) void CDROM::SetInterrupt(Interrupt interrupt)
{ {
s_interrupt_flag_register = static_cast<u8>(interrupt); s_interrupt_flag_register = static_cast<u8>(interrupt);
s_last_interrupt_time = TimingEvents::GetGlobalTickCounter(); s_last_interrupt_time = System::GetGlobalTickCounter();
UpdateInterruptRequest(); UpdateInterruptRequest();
} }
@ -1138,7 +1138,7 @@ void CDROM::QueueDeliverAsyncInterrupt()
return; return;
// underflows here are okay // 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) if (diff >= MINIMUM_INTERRUPT_DELAY)
{ {
DeliverAsyncInterrupt(nullptr, 0, 0); DeliverAsyncInterrupt(nullptr, 0, 0);
@ -2442,13 +2442,13 @@ void CDROM::UpdatePositionWhileSeeking()
s_current_lba = current_lba; s_current_lba = current_lba;
s_physical_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; s_physical_lba_update_carry = 0;
} }
void CDROM::UpdatePhysicalPosition(bool update_logical) void CDROM::UpdatePhysicalPosition(bool update_logical)
{ {
const u32 ticks = TimingEvents::GetGlobalTickCounter(); const u32 ticks = System::GetGlobalTickCounter();
if (IsSeeking() || IsReadingOrPlaying() || !IsMotorOn()) 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 // 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_current_lba = lba;
s_physical_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; s_physical_lba_update_carry = 0;
} }
@ -2607,7 +2607,7 @@ bool CDROM::CompleteSeek()
} }
s_physical_lba = s_current_lba; 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_physical_lba_update_carry = 0;
return seek_okay; return seek_okay;
} }
@ -2783,7 +2783,7 @@ void CDROM::DoSectorRead()
s_current_lba = s_reader.GetLastReadSector(); s_current_lba = s_reader.GetLastReadSector();
s_physical_lba = s_current_lba; 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_physical_lba_update_carry = 0;
s_secondary_status.SetReadingBits(s_drive_state == DriveState::Playing); s_secondary_status.SetReadingBits(s_drive_state == DriveState::Playing);

View file

@ -875,11 +875,11 @@ template<PGXPMode pgxp_mode>
void CPU::CodeCache::LogCurrentState() void CPU::CodeCache::LogCurrentState()
{ {
#if 0 #if 0
if ((TimingEvents::GetGlobalTickCounter() + GetPendingTicks()) == 2546728915) if (System::GetGlobalTickCounter() == 2546728915)
__debugbreak(); __debugbreak();
#endif #endif
#if 0 #if 0
if ((TimingEvents::GetGlobalTickCounter() + GetPendingTicks()) < 2546729174) if (System::GetGlobalTickCounter() < 2546729174)
return; return;
#endif #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 " "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 " "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", "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, System::GetGlobalTickCounter(), g_state.pending_ticks, g_state.downcount, g_state.pc, regs.at, regs.v0, regs.v1,
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.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.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.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.k1, regs.gp, regs.sp, regs.fp, regs.ra, regs.hi, regs.lo, 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) ? "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.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<u32>(crc32(0, (const Bytef*)&g_state.gte_regs, sizeof(g_state.gte_regs)))); g_state.cop0_regs.sr.bits, static_cast<u32>(crc32(0, (const Bytef*)&g_state.gte_regs, sizeof(g_state.gte_regs))));

View file

@ -392,6 +392,11 @@ void System::UpdateOverclock()
UpdateThrottlePeriod(); UpdateThrottlePeriod();
} }
u32 System::GetGlobalTickCounter()
{
return TimingEvents::GetGlobalTickCounter() + CPU::GetPendingTicks();
}
u32 System::GetFrameNumber() u32 System::GetFrameNumber()
{ {
return s_frame_number; return s_frame_number;
@ -2547,7 +2552,7 @@ void System::UpdatePerformanceCounters()
const u32 frames_run = s_frame_number - s_last_frame_number; const u32 frames_run = s_frame_number - s_last_frame_number;
const float frames_runf = static_cast<float>(frames_run); const float frames_runf = static_cast<float>(frames_run);
const u32 global_tick_counter = TimingEvents::GetGlobalTickCounter(); const u32 global_tick_counter = GetGlobalTickCounter();
// TODO: Make the math here less rubbish // TODO: Make the math here less rubbish
const double pct_divider = const double pct_divider =
@ -2605,7 +2610,7 @@ void System::ResetPerformanceCounters()
{ {
s_last_frame_number = s_frame_number; s_last_frame_number = s_frame_number;
s_last_internal_frame_number = s_internal_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; 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) if (const Threading::Thread* sw_thread = g_gpu->GetSWThread(); sw_thread)
s_last_sw_time = sw_thread->GetCPUTime(); s_last_sw_time = sw_thread->GetCPUTime();

View file

@ -191,6 +191,7 @@ void UpdateOverclock();
/// direct execution to this executable. /// direct execution to this executable.
bool InjectEXEFromBuffer(const void* buffer, u32 buffer_size, bool patch_loader = true); bool InjectEXEFromBuffer(const void* buffer, u32 buffer_size, bool patch_loader = true);
u32 GetGlobalTickCounter();
u32 GetFrameNumber(); u32 GetFrameNumber();
u32 GetInternalFrameNumber(); u32 GetInternalFrameNumber();
void IncrementInternalFrameNumber(); void IncrementInternalFrameNumber();