diff --git a/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.cpp b/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.cpp index a130576e08..293cc4cba9 100644 --- a/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.cpp +++ b/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.cpp @@ -10,6 +10,7 @@ #include #include +#include "Core/Core.h" #include "Common/Assembler/GekkoAssembler.h" #include "Common/StringUtil.h" @@ -38,8 +39,8 @@ QString HtmlFormatErrorLine(const Common::GekkoAssembler::AssemblerError& err) } } // namespace -AssembleInstructionDialog::AssembleInstructionDialog(QWidget* parent, u32 address, u32 value) - : QDialog(parent), m_code(value), m_address(address) +AssembleInstructionDialog::AssembleInstructionDialog(QWidget* parent, u32 address, u32 value, QString disasm ) + : QDialog(parent), m_code(value), m_address(address), m_disassembly(disasm) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowModality(Qt::WindowModal); @@ -66,7 +67,9 @@ void AssembleInstructionDialog::CreateWidgets() layout->addWidget(m_error_line_label); layout->addWidget(m_msg_label); layout->addWidget(m_button_box); - m_input_edit->setText(QStringLiteral(".4byte 0x%1").arg(m_code, 8, 16, QLatin1Char('0'))); + +// m_input_edit->setText(QStringLiteral(".4byte 0x%1").arg(m_code, 8, 16, QLatin1Char('0'))); + m_input_edit->setText( m_disassembly ); setLayout(layout); OnEditChanged(); @@ -86,6 +89,34 @@ void AssembleInstructionDialog::OnEditChanged() std::string line = m_input_edit->text().toStdString(); Common::ToLower(&line); + size_t posArrow = line.find("->"); + if (posArrow != std::string::npos) + { + std::string start = line.substr(0, posArrow); + std::string dest = line.substr(posArrow + 2); + u32 destAddress = 0; + size_t posHex = dest.find("0x"); + try + { + if (posHex == std::string::npos) + { + destAddress = (u32)std::stoi(dest); + } + else + { + destAddress = (u32)std::stoul(dest.substr(posHex + 2), NULL, 16); + } + } catch (...) {} + if (destAddress < m_address) + { + line = start + " -" + std::to_string(m_address - destAddress); + } + else + { + line = start + " " + std::to_string(destAddress - m_address); + } + } + FailureOr> asm_result = Assemble(line, m_address); if (IsFailure(asm_result)) diff --git a/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.h b/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.h index de2191e2c7..5be13f6bd3 100644 --- a/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.h +++ b/Source/Core/DolphinQt/Debugger/AssembleInstructionDialog.h @@ -15,7 +15,7 @@ class AssembleInstructionDialog : public QDialog { Q_OBJECT public: - explicit AssembleInstructionDialog(QWidget* parent, u32 address, u32 value); + explicit AssembleInstructionDialog(QWidget* parent, u32 address, u32 value, QString disasm ); u32 GetCode() const; @@ -27,7 +27,7 @@ private: u32 m_code; u32 m_address; - + QString m_disassembly; QLineEdit* m_input_edit; QLabel* m_error_loc_label; QLabel* m_error_line_label; diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index 7c5b8fb3b8..4e7abb9e13 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -1060,7 +1060,15 @@ void CodeViewWidget::DoPatchInstruction(bool assemble) if (assemble) { - AssembleInstructionDialog dialog(this, addr, debug_interface.ReadInstruction(guard, addr)); + std::string code_line = [this, addr] { + Core::CPUThreadGuard guard(m_system); + return m_system.GetPowerPC().GetDebugInterface().Disassemble(&guard, addr); + }(); + + std::ranges::replace(code_line, '\t', ' ' ); + + AssembleInstructionDialog dialog(this, addr, debug_interface.ReadInstruction(guard, addr), + QString::fromStdString(code_line)); SetQWidgetWindowDecorations(&dialog); if (dialog.exec() == QDialog::Accepted) {