DolphinQt: Avoid ppcState global.

This commit is contained in:
Admiral H. Curtiss
2023-03-28 23:52:36 +02:00
parent 192d8b6e40
commit 2d1f661118
6 changed files with 143 additions and 127 deletions

View File

@ -135,7 +135,7 @@ constexpr int CODE_VIEW_COLUMN_DESCRIPTION = 4;
constexpr int CODE_VIEW_COLUMN_BRANCH_ARROWS = 5;
constexpr int CODE_VIEW_COLUMNCOUNT = 6;
CodeViewWidget::CodeViewWidget()
CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance())
{
setColumnCount(CODE_VIEW_COLUMNCOUNT);
setShowGrid(false);
@ -168,11 +168,11 @@ CodeViewWidget::CodeViewWidget()
&CodeViewWidget::FontBasedSizing);
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [this] {
m_address = PowerPC::ppcState.pc;
m_address = m_system.GetPPCState().pc;
Update();
});
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] {
m_address = PowerPC::ppcState.pc;
m_address = m_system.GetPPCState().pc;
Update();
});
@ -259,7 +259,7 @@ void CodeViewWidget::Update()
if (Core::GetState() == Core::State::Paused)
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
Update(&guard);
}
else
@ -294,7 +294,8 @@ void CodeViewWidget::Update(const Core::CPUThreadGuard* guard)
for (int i = 0; i < rows; i++)
setRowHeight(i, rowh);
const std::optional<u32> pc = guard ? std::make_optional(PowerPC::ppcState.pc) : std::nullopt;
const std::optional<u32> pc =
guard ? std::make_optional(m_system.GetPPCState().pc) : std::nullopt;
const bool dark_theme = qApp->palette().color(QPalette::Base).valueF() < 0.5;
@ -533,7 +534,7 @@ void CodeViewWidget::SetAddress(u32 address, SetAddressUpdate update)
void CodeViewWidget::ReplaceAddress(u32 address, ReplaceWith replace)
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
PowerPC::debug_interface.SetPatch(guard, address,
replace == ReplaceWith::BLR ? 0x4e800020 : 0x60000000);
@ -595,10 +596,11 @@ void CodeViewWidget::OnContextMenu()
bool follow_branch_enabled = false;
if (paused)
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, PowerPC::ppcState.pc);
Core::CPUThreadGuard guard(m_system);
const u32 pc = m_system.GetPPCState().pc;
const std::string disasm = PowerPC::debug_interface.Disassemble(&guard, pc);
if (addr == PowerPC::ppcState.pc)
if (addr == pc)
{
const auto target_it = std::find(disasm.begin(), disasm.end(), '\t');
const auto target_end = std::find(target_it, disasm.end(), ',');
@ -651,7 +653,7 @@ void CodeViewWidget::AutoStep(CodeTrace::AutoStop option)
// Autosteps and follows value in the target (left-most) register. The Used and Changed options
// silently follows target through reshuffles in memory and registers and stops on use or update.
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
CodeTrace code_trace;
bool repeat = false;
@ -741,8 +743,8 @@ void CodeViewWidget::OnCopyTargetAddress()
const u32 addr = GetContextAddress();
const std::string code_line = [addr] {
Core::CPUThreadGuard guard(Core::System::GetInstance());
const std::string code_line = [this, addr] {
Core::CPUThreadGuard guard(m_system);
return PowerPC::debug_interface.Disassemble(&guard, addr);
}();
@ -771,8 +773,8 @@ void CodeViewWidget::OnShowTargetInMemory()
const u32 addr = GetContextAddress();
const std::string code_line = [addr] {
Core::CPUThreadGuard guard(Core::System::GetInstance());
const std::string code_line = [this, addr] {
Core::CPUThreadGuard guard(m_system);
return PowerPC::debug_interface.Disassemble(&guard, addr);
}();
@ -790,8 +792,8 @@ void CodeViewWidget::OnCopyCode()
{
const u32 addr = GetContextAddress();
const std::string text = [addr] {
Core::CPUThreadGuard guard(Core::System::GetInstance());
const std::string text = [this, addr] {
Core::CPUThreadGuard guard(m_system);
return PowerPC::debug_interface.Disassemble(&guard, addr);
}();
@ -809,7 +811,7 @@ void CodeViewWidget::OnCopyFunction()
std::string text = symbol->name + "\r\n";
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
// we got a function
const u32 start = symbol->address;
@ -828,8 +830,8 @@ void CodeViewWidget::OnCopyHex()
{
const u32 addr = GetContextAddress();
const u32 instruction = [addr] {
Core::CPUThreadGuard guard(Core::System::GetInstance());
const u32 instruction = [this, addr] {
Core::CPUThreadGuard guard(m_system);
return PowerPC::debug_interface.ReadInstruction(guard, addr);
}();
@ -857,7 +859,7 @@ void CodeViewWidget::OnAddFunction()
{
const u32 addr = GetContextAddress();
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
g_symbolDB.AddFunction(guard, addr);
emit SymbolsChanged();
@ -882,8 +884,8 @@ void CodeViewWidget::OnFollowBranch()
{
const u32 addr = GetContextAddress();
const u32 branch_addr = [addr] {
Core::CPUThreadGuard guard(Core::System::GetInstance());
const u32 branch_addr = [this, addr] {
Core::CPUThreadGuard guard(m_system);
return GetBranchFromAddress(guard, addr);
}();
@ -917,7 +919,7 @@ void CodeViewWidget::OnRenameSymbol()
void CodeViewWidget::OnSelectionChanged()
{
if (m_address == PowerPC::ppcState.pc)
if (m_address == m_system.GetPPCState().pc)
{
setStyleSheet(
QStringLiteral("QTableView::item:selected {background-color: #00FF00; color: #000000;}"));
@ -946,7 +948,7 @@ void CodeViewWidget::OnSetSymbolSize()
if (!good)
return;
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, size);
emit SymbolsChanged();
@ -974,7 +976,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()
if (!good)
return;
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
PPCAnalyst::ReanalyzeFunction(guard, symbol->address, *symbol, address - symbol->address);
emit SymbolsChanged();
@ -983,7 +985,7 @@ void CodeViewWidget::OnSetSymbolEndAddress()
void CodeViewWidget::OnReplaceInstruction()
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
const u32 addr = GetContextAddress();
@ -1006,7 +1008,7 @@ void CodeViewWidget::OnReplaceInstruction()
void CodeViewWidget::OnRestoreInstruction()
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
Core::CPUThreadGuard guard(m_system);
const u32 addr = GetContextAddress();