Skip to content

Commit 71f5056

Browse files
committed
System: Consider pending ticks when using global ticks
1 parent 1782151 commit 71f5056

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/core/cdrom.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void CDROM::Reset()
484484
s_mode.read_raw_sector = true;
485485
s_interrupt_enable_register = INTERRUPT_REGISTER_MASK;
486486
s_interrupt_flag_register = 0;
487-
s_last_interrupt_time = TimingEvents::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY;
487+
s_last_interrupt_time = System::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY;
488488
ClearAsyncInterrupt();
489489
s_setloc_position = {};
490490
s_seek_start_lba = 0;
@@ -605,7 +605,7 @@ bool CDROM::DoState(StateWrapper& sw)
605605

606606
sw.Do(&s_interrupt_enable_register);
607607
sw.Do(&s_interrupt_flag_register);
608-
sw.DoEx(&s_last_interrupt_time, 57, TimingEvents::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY);
608+
sw.DoEx(&s_last_interrupt_time, 57, System::GetGlobalTickCounter() - MINIMUM_INTERRUPT_DELAY);
609609
sw.Do(&s_pending_async_interrupt);
610610
sw.DoPOD(&s_setloc_position);
611611
sw.Do(&s_current_lba);
@@ -1097,7 +1097,7 @@ bool CDROM::HasPendingAsyncInterrupt()
10971097
void CDROM::SetInterrupt(Interrupt interrupt)
10981098
{
10991099
s_interrupt_flag_register = static_cast<u8>(interrupt);
1100-
s_last_interrupt_time = TimingEvents::GetGlobalTickCounter();
1100+
s_last_interrupt_time = System::GetGlobalTickCounter();
11011101
UpdateInterruptRequest();
11021102
}
11031103

@@ -1138,7 +1138,7 @@ void CDROM::QueueDeliverAsyncInterrupt()
11381138
return;
11391139

11401140
// underflows here are okay
1141-
const u32 diff = TimingEvents::GetGlobalTickCounter() - s_last_interrupt_time;
1141+
const u32 diff = System::GetGlobalTickCounter() - s_last_interrupt_time;
11421142
if (diff >= MINIMUM_INTERRUPT_DELAY)
11431143
{
11441144
DeliverAsyncInterrupt(nullptr, 0, 0);
@@ -2442,13 +2442,13 @@ void CDROM::UpdatePositionWhileSeeking()
24422442

24432443
s_current_lba = current_lba;
24442444
s_physical_lba = current_lba;
2445-
s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter();
2445+
s_physical_lba_update_tick = System::GetGlobalTickCounter();
24462446
s_physical_lba_update_carry = 0;
24472447
}
24482448

24492449
void CDROM::UpdatePhysicalPosition(bool update_logical)
24502450
{
2451-
const u32 ticks = TimingEvents::GetGlobalTickCounter();
2451+
const u32 ticks = System::GetGlobalTickCounter();
24522452
if (IsSeeking() || IsReadingOrPlaying() || !IsMotorOn())
24532453
{
24542454
// 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)
25392539

25402540
s_current_lba = lba;
25412541
s_physical_lba = lba;
2542-
s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter();
2542+
s_physical_lba_update_tick = System::GetGlobalTickCounter();
25432543
s_physical_lba_update_carry = 0;
25442544
}
25452545

@@ -2607,7 +2607,7 @@ bool CDROM::CompleteSeek()
26072607
}
26082608

26092609
s_physical_lba = s_current_lba;
2610-
s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter();
2610+
s_physical_lba_update_tick = System::GetGlobalTickCounter();
26112611
s_physical_lba_update_carry = 0;
26122612
return seek_okay;
26132613
}
@@ -2783,7 +2783,7 @@ void CDROM::DoSectorRead()
27832783

27842784
s_current_lba = s_reader.GetLastReadSector();
27852785
s_physical_lba = s_current_lba;
2786-
s_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter();
2786+
s_physical_lba_update_tick = System::GetGlobalTickCounter();
27872787
s_physical_lba_update_carry = 0;
27882788

27892789
s_secondary_status.SetReadingBits(s_drive_state == DriveState::Playing);

src/core/cpu_code_cache.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,11 @@ template<PGXPMode pgxp_mode>
875875
void CPU::CodeCache::LogCurrentState()
876876
{
877877
#if 0
878-
if ((TimingEvents::GetGlobalTickCounter() + GetPendingTicks()) == 2546728915)
878+
if (System::GetGlobalTickCounter() == 2546728915)
879879
__debugbreak();
880880
#endif
881881
#if 0
882-
if ((TimingEvents::GetGlobalTickCounter() + GetPendingTicks()) < 2546729174)
882+
if (System::GetGlobalTickCounter() < 2546729174)
883883
return;
884884
#endif
885885

@@ -888,10 +888,10 @@ void CPU::CodeCache::LogCurrentState()
888888
"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 "
889889
"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 "
890890
"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",
891-
TimingEvents::GetGlobalTickCounter() + GetPendingTicks(), g_state.pending_ticks, g_state.downcount, g_state.pc,
892-
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,
893-
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,
894-
regs.k1, regs.gp, regs.sp, regs.fp, regs.ra, regs.hi, regs.lo,
891+
System::GetGlobalTickCounter(), g_state.pending_ticks, g_state.downcount, g_state.pc, regs.at, regs.v0, regs.v1,
892+
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,
893+
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,
894+
regs.fp, regs.ra, regs.hi, regs.lo,
895895
(g_state.next_load_delay_reg == Reg::count) ? "NONE" : GetRegName(g_state.next_load_delay_reg),
896896
(g_state.next_load_delay_reg == Reg::count) ? 0 : g_state.next_load_delay_value, g_state.cop0_regs.cause.bits,
897897
g_state.cop0_regs.sr.bits, static_cast<u32>(crc32(0, (const Bytef*)&g_state.gte_regs, sizeof(g_state.gte_regs))));

src/core/system.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ void System::UpdateOverclock()
392392
UpdateThrottlePeriod();
393393
}
394394

395+
u32 System::GetGlobalTickCounter()
396+
{
397+
return TimingEvents::GetGlobalTickCounter() + CPU::GetPendingTicks();
398+
}
399+
395400
u32 System::GetFrameNumber()
396401
{
397402
return s_frame_number;
@@ -2547,7 +2552,7 @@ void System::UpdatePerformanceCounters()
25472552

25482553
const u32 frames_run = s_frame_number - s_last_frame_number;
25492554
const float frames_runf = static_cast<float>(frames_run);
2550-
const u32 global_tick_counter = TimingEvents::GetGlobalTickCounter();
2555+
const u32 global_tick_counter = GetGlobalTickCounter();
25512556

25522557
// TODO: Make the math here less rubbish
25532558
const double pct_divider =
@@ -2605,7 +2610,7 @@ void System::ResetPerformanceCounters()
26052610
{
26062611
s_last_frame_number = s_frame_number;
26072612
s_last_internal_frame_number = s_internal_frame_number;
2608-
s_last_global_tick_counter = TimingEvents::GetGlobalTickCounter();
2613+
s_last_global_tick_counter = GetGlobalTickCounter();
26092614
s_last_cpu_time = s_cpu_thread_handle ? s_cpu_thread_handle.GetCPUTime() : 0;
26102615
if (const Threading::Thread* sw_thread = g_gpu->GetSWThread(); sw_thread)
26112616
s_last_sw_time = sw_thread->GetCPUTime();

src/core/system.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ void UpdateOverclock();
191191
/// direct execution to this executable.
192192
bool InjectEXEFromBuffer(const void* buffer, u32 buffer_size, bool patch_loader = true);
193193

194+
u32 GetGlobalTickCounter();
194195
u32 GetFrameNumber();
195196
u32 GetInternalFrameNumber();
196197
void IncrementInternalFrameNumber();

0 commit comments

Comments
 (0)