Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core/FifoPlayer: Avoid global System accessor. #12497

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 22 additions & 34 deletions Source/Core/Core/FifoPlayer/FifoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ class FifoPlayer::CPUCore final : public CPUCoreBase
IsPlayingBackFifologWithBrokenEFBCopies = m_parent->m_File->HasBrokenEFBCopies();
// Without this call, we deadlock in initialization in dual core, as the FIFO is disabled and
// thus ClearEfb()'s call to WaitForGPUInactive() never returns
auto& system = Core::System::GetInstance();
system.GetCPU().EnableStepping(false);
m_parent->m_system.GetCPU().EnableStepping(false);

m_parent->m_CurrentFrame = m_parent->m_FrameRangeStart;
m_parent->LoadMemory();
Expand All @@ -251,8 +250,7 @@ class FifoPlayer::CPUCore final : public CPUCoreBase
const char* GetName() const override { return "FifoPlayer"; }
void Run() override
{
auto& system = Core::System::GetInstance();
auto& cpu = system.GetCPU();
auto& cpu = m_parent->m_system.GetCPU();
while (cpu.GetState() == CPU::State::Running)
{
switch (m_parent->AdvanceFrame())
Expand Down Expand Up @@ -404,9 +402,8 @@ void FifoPlayer::SetFrameRangeEnd(u32 end)
void FifoPlayer::WriteFrame(const FifoFrameInfo& frame, const AnalyzedFrameInfo& info)
{
// Core timing information
auto& system = Core::System::GetInstance();
auto& vi = system.GetVideoInterface();
m_CyclesPerFrame = static_cast<u64>(system.GetSystemTimers().GetTicksPerSecond()) *
auto& vi = m_system.GetVideoInterface();
m_CyclesPerFrame = static_cast<u64>(m_system.GetSystemTimers().GetTicksPerSecond()) *
vi.GetTargetRefreshRateDenominator() / vi.GetTargetRefreshRateNumerator();
m_ElapsedCycles = 0;
m_FrameFifoSize = static_cast<u32>(frame.fifoData.size());
Expand Down Expand Up @@ -495,8 +492,7 @@ void FifoPlayer::WriteAllMemoryUpdates()

void FifoPlayer::WriteMemory(const MemoryUpdate& memUpdate)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
auto& memory = m_system.GetMemory();
u8* mem = nullptr;

if (memUpdate.address & 0x10000000)
Expand All @@ -512,11 +508,10 @@ void FifoPlayer::WriteFifo(const u8* data, u32 start, u32 end)
u32 written = start;
u32 lastBurstEnd = end - 1;

auto& system = Core::System::GetInstance();
auto& cpu = system.GetCPU();
auto& core_timing = system.GetCoreTiming();
auto& gpfifo = system.GetGPFifo();
auto& ppc_state = system.GetPPCState();
auto& cpu = m_system.GetCPU();
auto& core_timing = m_system.GetCoreTiming();
auto& gpfifo = m_system.GetGPFifo();
auto& ppc_state = m_system.GetPPCState();

// Write up to 256 bytes at a time
while (written < end)
Expand Down Expand Up @@ -632,8 +627,7 @@ void FifoPlayer::ClearEfb()

void FifoPlayer::LoadMemory()
{
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
auto& ppc_state = m_system.GetPPCState();

UReg_MSR newMSR;
newMSR.DR = 1;
Expand All @@ -648,7 +642,7 @@ void FifoPlayer::LoadMemory()

PowerPC::MSRUpdated(ppc_state);

auto& mmu = system.GetMMU();
auto& mmu = m_system.GetMMU();
mmu.DBATUpdated();
mmu.IBATUpdated();

Expand Down Expand Up @@ -708,18 +702,17 @@ void FifoPlayer::LoadTextureMemory()

void FifoPlayer::WriteCP(u32 address, u16 value)
{
Core::System::GetInstance().GetMMU().Write_U16(value, 0xCC000000 | address);
m_system.GetMMU().Write_U16(value, 0xCC000000 | address);
}

void FifoPlayer::WritePI(u32 address, u32 value)
{
Core::System::GetInstance().GetMMU().Write_U32(value, 0xCC003000 | address);
m_system.GetMMU().Write_U32(value, 0xCC003000 | address);
}

void FifoPlayer::FlushWGP()
{
auto& system = Core::System::GetInstance();
auto& gpfifo = system.GetGPFifo();
auto& gpfifo = m_system.GetGPFifo();

// Send 31 0s through the WGP
for (int i = 0; i < 7; ++i)
Expand All @@ -732,9 +725,8 @@ void FifoPlayer::FlushWGP()

void FifoPlayer::WaitForGPUInactive()
{
auto& system = Core::System::GetInstance();
auto& core_timing = system.GetCoreTiming();
auto& cpu = system.GetCPU();
auto& core_timing = m_system.GetCoreTiming();
auto& cpu = m_system.GetCPU();

// Sleep while the GPU is active
while (!IsIdleSet() && cpu.GetState() != CPU::State::PowerDown)
Expand All @@ -746,8 +738,7 @@ void FifoPlayer::WaitForGPUInactive()

void FifoPlayer::LoadBPReg(u8 reg, u32 value)
{
auto& system = Core::System::GetInstance();
auto& gpfifo = system.GetGPFifo();
auto& gpfifo = m_system.GetGPFifo();

gpfifo.Write8(0x61); // load BP reg

Expand All @@ -758,8 +749,7 @@ void FifoPlayer::LoadBPReg(u8 reg, u32 value)

void FifoPlayer::LoadCPReg(u8 reg, u32 value)
{
auto& system = Core::System::GetInstance();
auto& gpfifo = system.GetGPFifo();
auto& gpfifo = m_system.GetGPFifo();

gpfifo.Write8(0x08); // load CP reg
gpfifo.Write8(reg);
Expand All @@ -768,8 +758,7 @@ void FifoPlayer::LoadCPReg(u8 reg, u32 value)

void FifoPlayer::LoadXFReg(u16 reg, u32 value)
{
auto& system = Core::System::GetInstance();
auto& gpfifo = system.GetGPFifo();
auto& gpfifo = m_system.GetGPFifo();

gpfifo.Write8(0x10); // load XF reg
gpfifo.Write32((reg & 0x0fff) | 0x1000); // load 4 bytes into reg
Expand All @@ -778,8 +767,7 @@ void FifoPlayer::LoadXFReg(u16 reg, u32 value)

void FifoPlayer::LoadXFMem16(u16 address, const u32* data)
{
auto& system = Core::System::GetInstance();
auto& gpfifo = system.GetGPFifo();
auto& gpfifo = m_system.GetGPFifo();

// Loads 16 * 4 bytes in xf memory starting at address
gpfifo.Write8(0x10); // load XF reg
Expand Down Expand Up @@ -818,13 +806,13 @@ bool FifoPlayer::ShouldLoadXF(u8 reg)
bool FifoPlayer::IsIdleSet() const
{
CommandProcessor::UCPStatusReg status =
Core::System::GetInstance().GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
m_system.GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
return status.CommandIdle;
}

bool FifoPlayer::IsHighWatermarkSet() const
{
CommandProcessor::UCPStatusReg status =
Core::System::GetInstance().GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
m_system.GetMMU().Read_U16(0xCC000000 | CommandProcessor::STATUS_REGISTER);
return status.OverflowHiWatermark;
}
1 change: 1 addition & 0 deletions Source/Core/Core/FifoPlayer/FifoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class FifoPlayer

private:
class CPUCore;
friend class CPUCore;

CPU::State AdvanceFrame();

Expand Down