CPU: Convert CCPU into a namespace

There's not much point to a class with only static member functions.
This commit is contained in:
Lioncash 2015-10-04 15:06:31 -04:00
parent e076de137b
commit ef1cc2cec4
9 changed files with 70 additions and 68 deletions

View File

@ -263,7 +263,7 @@ void Stop() // - Hammertime!
PowerPC::Stop();
// Kick it if it's waiting (code stepping wait loop)
CCPU::StepOpcode();
CPU::StepOpcode();
if (_CoreParameter.bCPUThread)
{
@ -344,7 +344,7 @@ static void CpuThread()
#endif
// Enter CPU run loop. When we leave it - we are done.
CCPU::Run();
CPU::Run();
s_is_started = false;
@ -606,11 +606,11 @@ void SetState(EState _State)
switch (_State)
{
case CORE_PAUSE:
CCPU::EnableStepping(true); // Break
CPU::EnableStepping(true); // Break
Wiimote::Pause();
break;
case CORE_RUN:
CCPU::EnableStepping(false);
CPU::EnableStepping(false);
Wiimote::Resume();
break;
default:
@ -626,10 +626,10 @@ EState GetState()
if (s_hardware_initialized)
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
return CORE_PAUSE;
else
return CORE_RUN;
return CORE_RUN;
}
return CORE_UNINITIALIZED;
@ -707,7 +707,7 @@ bool PauseAndLock(bool doLock, bool unpauseOnUnlock)
return true;
// first pause or unpause the CPU
bool wasUnpaused = CCPU::PauseAndLock(doLock, unpauseOnUnlock);
bool wasUnpaused = CPU::PauseAndLock(doLock, unpauseOnUnlock);
ExpansionInterface::PauseAndLock(doLock, unpauseOnUnlock);
// audio has to come after CPU, because CPU thread can wait for audio thread (m_throttle).

View File

@ -24,19 +24,22 @@ namespace
static std::mutex m_csCpuOccupied;
}
void CCPU::Init(int cpu_core)
namespace CPU
{
void Init(int cpu_core)
{
PowerPC::Init(cpu_core);
m_SyncEvent = nullptr;
}
void CCPU::Shutdown()
void Shutdown()
{
PowerPC::Shutdown();
m_SyncEvent = nullptr;
}
void CCPU::Run()
void Run()
{
std::lock_guard<std::mutex> lk(m_csCpuOccupied);
Host_UpdateDisasmDialog();
@ -81,22 +84,22 @@ void CCPU::Run()
}
}
void CCPU::Stop()
void Stop()
{
PowerPC::Stop();
m_StepEvent.Set();
}
bool CCPU::IsStepping()
bool IsStepping()
{
return PowerPC::GetState() == PowerPC::CPU_STEPPING;
}
void CCPU::Reset()
void Reset()
{
}
void CCPU::StepOpcode(Common::Event *event)
void StepOpcode(Common::Event* event)
{
m_StepEvent.Set();
if (PowerPC::GetState() == PowerPC::CPU_STEPPING)
@ -105,9 +108,9 @@ void CCPU::StepOpcode(Common::Event *event)
}
}
void CCPU::EnableStepping(const bool _bStepping)
void EnableStepping(const bool stepping)
{
if (_bStepping)
if (stepping)
{
PowerPC::Pause();
m_StepEvent.Reset();
@ -139,15 +142,15 @@ void CCPU::EnableStepping(const bool _bStepping)
}
}
void CCPU::Break()
void Break()
{
EnableStepping(true);
}
bool CCPU::PauseAndLock(bool doLock, bool unpauseOnUnlock)
bool PauseAndLock(bool do_lock, bool unpause_on_unlock)
{
bool wasUnpaused = !IsStepping();
if (doLock)
if (do_lock)
{
// we can't use EnableStepping, that would causes deadlocks with both audio and video
PowerPC::Pause();
@ -156,7 +159,7 @@ bool CCPU::PauseAndLock(bool doLock, bool unpauseOnUnlock)
}
else
{
if (unpauseOnUnlock)
if (unpause_on_unlock)
{
PowerPC::Start();
m_StepEvent.Set();
@ -167,3 +170,5 @@ bool CCPU::PauseAndLock(bool doLock, bool unpauseOnUnlock)
}
return wasUnpaused;
}
}

View File

@ -4,46 +4,46 @@
#pragma once
#include "Common/CommonTypes.h"
namespace Common {
class Event;
}
class CCPU
namespace CPU
{
public:
// init
static void Init(int cpu_core);
// shutdown
static void Shutdown();
// Init
void Init(int cpu_core);
// starts the CPU
static void Run();
// Shutdown
void Shutdown();
// causes shutdown
static void Stop();
// Reset
static void Reset();
// Starts the CPU
void Run();
// StepOpcode (Steps one Opcode)
static void StepOpcode(Common::Event *event = nullptr);
// Causes shutdown
void Stop();
// Enable or Disable Stepping
static void EnableStepping(const bool _bStepping);
// Reset
void Reset();
// break, same as EnableStepping(true).
static void Break();
// StepOpcode (Steps one Opcode)
void StepOpcode(Common::Event* event = nullptr);
// is stepping ?
static bool IsStepping();
// Enable or Disable Stepping
void EnableStepping(bool stepping);
// waits until is stepping and is ready for a command (paused and fully idle), and acquires a lock on that state.
// or, if doLock is false, releases a lock on that state and optionally re-disables stepping.
// calls must be balanced and non-recursive (once with doLock true, then once with doLock false).
// intended (but not required) to be called from another thread,
// e.g. when the GUI thread wants to make sure everything is paused so that it can create a savestate.
// the return value is whether the CPU was unpaused before the call.
static bool PauseAndLock(bool doLock, bool unpauseOnUnlock=true);
};
// Break, same as EnableStepping(true).
void Break();
// Is stepping ?
bool IsStepping();
// Waits until is stepping and is ready for a command (paused and fully idle), and acquires a lock on that state.
// or, if doLock is false, releases a lock on that state and optionally re-disables stepping.
// calls must be balanced and non-recursive (once with doLock true, then once with doLock false).
// intended (but not required) to be called from another thread,
// e.g. when the GUI thread wants to make sure everything is paused so that it can create a savestate.
// the return value is whether the CPU was unpaused before the call.
bool PauseAndLock(bool do_lock, bool unpause_on_unlock = true);
}

View File

@ -47,7 +47,7 @@ namespace HW
DSP::Init(SConfig::GetInstance().bDSPHLE);
DVDInterface::Init();
GPFifo::Init();
CCPU::Init(SConfig::GetInstance().iCPUCore);
CPU::Init(SConfig::GetInstance().iCPUCore);
SystemTimers::Init();
if (SConfig::GetInstance().bWii)
@ -63,7 +63,7 @@ namespace HW
void Shutdown()
{
SystemTimers::Shutdown();
CCPU::Shutdown();
CPU::Shutdown();
ExpansionInterface::Shutdown();
DVDInterface::Shutdown();
DSP::Shutdown();

View File

@ -247,7 +247,7 @@ static void gdb_read_command()
}
else if (c == 0x03)
{
CCPU::Break();
CPU::Break();
gdb_signal(SIGTRAP);
return;
}

View File

@ -244,7 +244,7 @@ void Interpreter::Run()
}
#endif
INFO_LOG(POWERPC, "Hit Breakpoint - %08x", PC);
CCPU::Break();
CPU::Break();
if (PowerPC::breakpoints.IsTempBreakPoint(PC))
PowerPC::breakpoints.Remove(PC);

View File

@ -453,7 +453,7 @@ static __forceinline void Memcheck(u32 address, u32 var, bool write, int size)
TMemCheck *mc = PowerPC::memchecks.GetMemCheck(address);
if (mc)
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
// Disable when stepping so that resume works.
return;
@ -462,7 +462,7 @@ static __forceinline void Memcheck(u32 address, u32 var, bool write, int size)
bool pause = mc->Action(&PowerPC::debug_interface, var, address, write, size, PC);
if (pause)
{
CCPU::Break();
CPU::Break();
// Fake a DSI so that all the code that tests for it in order to skip
// the rest of the instruction will apply. (This means that
// watchpoints will stop the emulator before the offending load/store,

View File

@ -283,11 +283,11 @@ void CCodeWindow::OnCallsListChange(wxCommandEvent& event)
void CCodeWindow::SingleStep()
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
PowerPC::breakpoints.ClearAllTemporary();
JitInterface::InvalidateICache(PC, 4, true);
CCPU::StepOpcode(&sync_event);
CPU::StepOpcode(&sync_event);
wxThread::Sleep(20);
// need a short wait here
JumpToAddress(PC);
@ -297,14 +297,14 @@ void CCodeWindow::SingleStep()
void CCodeWindow::StepOver()
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
UGeckoInstruction inst = PowerPC::HostRead_Instruction(PC);
if (inst.LK)
{
PowerPC::breakpoints.ClearAllTemporary();
PowerPC::breakpoints.Add(PC + 4, true);
CCPU::EnableStepping(false);
CPU::EnableStepping(false);
JumpToAddress(PC);
Update();
}
@ -321,7 +321,7 @@ void CCodeWindow::StepOver()
void CCodeWindow::StepOut()
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
PowerPC::breakpoints.ClearAllTemporary();
@ -365,7 +365,7 @@ void CCodeWindow::StepOut()
void CCodeWindow::ToggleBreakpoint()
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
if (codeview) codeview->ToggleBreakpoint(codeview->GetSelection());
Update();
@ -700,7 +700,7 @@ void CCodeWindow::UpdateButtonStates()
{
bool Initialized = (Core::GetState() != Core::CORE_UNINITIALIZED);
bool Pause = (Core::GetState() == Core::CORE_PAUSE);
bool Stepping = CCPU::IsStepping();
bool Stepping = CPU::IsStepping();
wxToolBar* ToolBar = GetToolBar();
// Toolbar

View File

@ -845,10 +845,7 @@ void CFrame::OnPlay(wxCommandEvent& WXUNUSED (event))
// Core is initialized and emulator is running
if (UseDebugger)
{
if (CCPU::IsStepping())
CCPU::EnableStepping(false);
else
CCPU::EnableStepping(true); // Break
CPU::EnableStepping(!CPU::IsStepping());
wxThread::Sleep(20);
g_pCodeWindow->JumpToAddress(PC);