From 08ebc59db04c88b8f99f6acab4f0525f15546e19 Mon Sep 17 00:00:00 2001 From: Eladash Date: Mon, 25 Apr 2022 09:22:11 +0300 Subject: [PATCH] Fix instructions editor, implement preview for to-be-edited instructions --- rpcs3/rpcs3qt/instruction_editor_dialog.cpp | 17 ++++++++--------- rpcs3/rpcs3qt/instruction_editor_dialog.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/rpcs3/rpcs3qt/instruction_editor_dialog.cpp b/rpcs3/rpcs3qt/instruction_editor_dialog.cpp index 02ff01bc4f..1a764b7f05 100644 --- a/rpcs3/rpcs3qt/instruction_editor_dialog.cpp +++ b/rpcs3/rpcs3qt/instruction_editor_dialog.cpp @@ -18,7 +18,7 @@ extern bool ppu_patch(u32 addr, u32 value); instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, CPUDisAsm* _disasm, std::function func) : QDialog(parent) , m_pc(_pc) - , m_disasm(_disasm) + , m_disasm(_disasm->copy_type_erased()) , m_get_cpu(std::move(func)) { setWindowTitle(tr("Edit instruction")); @@ -28,7 +28,6 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C const auto cpu = m_get_cpu(); m_cpu_offset = cpu && cpu->id_type() == 2 ? static_cast(*cpu).ls : vm::g_sudo_addr; - const QString instruction = qstr(fmt::format("%08x", *reinterpret_cast*>(m_cpu_offset + m_pc))); QVBoxLayout* vbox_panel(new QVBoxLayout()); QHBoxLayout* hbox_panel(new QHBoxLayout()); @@ -43,12 +42,12 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C m_instr = new QLineEdit(this); m_instr->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); - m_instr->setPlaceholderText(instruction); - m_instr->setText(instruction); m_instr->setMaxLength(8); m_instr->setMaximumWidth(65); - m_preview = new QLabel("", this); + m_disasm->change_mode(cpu_disasm_mode::normal); + m_disasm->disasm(m_pc); + m_preview = new QLabel(qstr(m_disasm->last_opcode), this); // Layouts vbox_left_panel->addWidget(new QLabel(tr("Address: "))); @@ -141,12 +140,12 @@ instruction_editor_dialog::instruction_editor_dialog(QWidget *parent, u32 _pc, C void instruction_editor_dialog::updatePreview() const { bool ok; - ulong opcode = m_instr->text().toULong(&ok, 16); - Q_UNUSED(opcode) + const be_t opcode{static_cast(m_instr->text().toULong(&ok, 16))}; + m_disasm->change_ptr(reinterpret_cast(&opcode) - std::intptr_t{m_pc}); - if (ok) + if (ok && m_disasm->disasm(m_pc)) { - m_preview->setText(tr("Preview disabled.")); + m_preview->setText(qstr(m_disasm->last_opcode)); } else { diff --git a/rpcs3/rpcs3qt/instruction_editor_dialog.h b/rpcs3/rpcs3qt/instruction_editor_dialog.h index ea48dc25b7..1bd1d5039e 100644 --- a/rpcs3/rpcs3qt/instruction_editor_dialog.h +++ b/rpcs3/rpcs3qt/instruction_editor_dialog.h @@ -17,7 +17,7 @@ class instruction_editor_dialog : public QDialog private: u32 m_pc; u8* m_cpu_offset; - CPUDisAsm* m_disasm; + std::shared_ptr m_disasm; // shared in order to allow an incomplete type QLineEdit* m_instr; QLabel* m_preview; QCheckBox* m_apply_for_spu_group = nullptr;