Skip to content

Commit

Permalink
Merge pull request #3134 from lioncash/namespace
Browse files Browse the repository at this point in the history
CPU: Convert CCPU into a namespace
  • Loading branch information
shuffle2 committed Oct 4, 2015
2 parents 55ea9e7 + ef1cc2c commit 3b1375f
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 68 deletions.
16 changes: 8 additions & 8 deletions Source/Core/Core/Core.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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).
Expand Down
31 changes: 18 additions & 13 deletions Source/Core/Core/HW/CPU.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -156,7 +159,7 @@ bool CCPU::PauseAndLock(bool doLock, bool unpauseOnUnlock)
}
else
{
if (unpauseOnUnlock)
if (unpause_on_unlock)
{
PowerPC::Start();
m_StepEvent.Set();
Expand All @@ -167,3 +170,5 @@ bool CCPU::PauseAndLock(bool doLock, bool unpauseOnUnlock)
}
return wasUnpaused;
}

}
60 changes: 30 additions & 30 deletions Source/Core/Core/HW/CPU.h
Expand Up @@ -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);

// Shutdown
void Shutdown();

// Starts the CPU
void Run();

// starts the CPU
static void Run();
// Causes shutdown
void Stop();

// causes shutdown
static void Stop();
// Reset
static void Reset();
// Reset
void Reset();

// StepOpcode (Steps one Opcode)
static void StepOpcode(Common::Event *event = nullptr);
// StepOpcode (Steps one Opcode)
void StepOpcode(Common::Event* event = nullptr);

// Enable or Disable Stepping
static void EnableStepping(const bool _bStepping);
// Enable or Disable Stepping
void EnableStepping(bool stepping);

// break, same as EnableStepping(true).
static void Break();
// Break, same as EnableStepping(true).
void Break();

// is stepping ?
static bool IsStepping();
// 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.
static bool PauseAndLock(bool doLock, bool unpauseOnUnlock=true);
};
// 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);

}
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/HW.cpp
Expand Up @@ -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)
Expand All @@ -63,7 +63,7 @@ namespace HW
void Shutdown()
{
SystemTimers::Shutdown();
CCPU::Shutdown();
CPU::Shutdown();
ExpansionInterface::Shutdown();
DVDInterface::Shutdown();
DSP::Shutdown();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/GDBStub.cpp
Expand Up @@ -247,7 +247,7 @@ static void gdb_read_command()
}
else if (c == 0x03)
{
CCPU::Break();
CPU::Break();
gdb_signal(SIGTRAP);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/PowerPC/MMU.cpp
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions Source/Core/DolphinWX/Debugger/CodeWindow.cpp
Expand Up @@ -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);
Expand All @@ -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();
}
Expand All @@ -321,7 +321,7 @@ void CCodeWindow::StepOver()

void CCodeWindow::StepOut()
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
PowerPC::breakpoints.ClearAllTemporary();

Expand Down Expand Up @@ -365,7 +365,7 @@ void CCodeWindow::StepOut()

void CCodeWindow::ToggleBreakpoint()
{
if (CCPU::IsStepping())
if (CPU::IsStepping())
{
if (codeview) codeview->ToggleBreakpoint(codeview->GetSelection());
Update();
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions Source/Core/DolphinWX/FrameTools.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 3b1375f

Please sign in to comment.