diff options
| author | 2014-04-08 19:25:03 -0400 | |
|---|---|---|
| committer | 2014-04-08 19:25:03 -0400 | |
| commit | 63e46abdb8764bc97e91bae862c8d461e61b1965 (patch) | |
| tree | e73f4aa25d7b4015a265e7bbfb6004dab7561027 /src/citra_qt/disasm.cpp | |
| parent | fixed some license headers that I missed (diff) | |
| download | yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.tar.gz yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.tar.xz yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.zip | |
got rid of 'src' folders in each sub-project
Diffstat (limited to 'src/citra_qt/disasm.cpp')
| -rw-r--r-- | src/citra_qt/disasm.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/citra_qt/disasm.cpp b/src/citra_qt/disasm.cpp new file mode 100644 index 000000000..ddcbf69d8 --- /dev/null +++ b/src/citra_qt/disasm.cpp | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | #include <QtGui> | ||
| 2 | #include "ui_disasm.h" | ||
| 3 | #include "disasm.hxx" | ||
| 4 | |||
| 5 | #include "bootmanager.hxx" | ||
| 6 | #include "hotkeys.hxx" | ||
| 7 | |||
| 8 | #include "common.h" | ||
| 9 | #include "mem_map.h" | ||
| 10 | |||
| 11 | #include "core.h" | ||
| 12 | #include "break_points.h" | ||
| 13 | #include "arm/interpreter/armdefs.h" | ||
| 14 | #include "arm/disassembler/arm_disasm.h" | ||
| 15 | |||
| 16 | GDisAsmView::GDisAsmView(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread) | ||
| 17 | { | ||
| 18 | disasm_ui.setupUi(this); | ||
| 19 | |||
| 20 | breakpoints = new BreakPoints(); | ||
| 21 | |||
| 22 | model = new QStandardItemModel(this); | ||
| 23 | model->setColumnCount(2); | ||
| 24 | disasm_ui.treeView->setModel(model); | ||
| 25 | |||
| 26 | RegisterHotkey("Disassembler", "Start/Stop", QKeySequence(Qt::Key_F5), Qt::ApplicationShortcut); | ||
| 27 | RegisterHotkey("Disassembler", "Step", QKeySequence(Qt::Key_F10), Qt::ApplicationShortcut); | ||
| 28 | RegisterHotkey("Disassembler", "Step into", QKeySequence(Qt::Key_F11), Qt::ApplicationShortcut); | ||
| 29 | RegisterHotkey("Disassembler", "Set Breakpoint", QKeySequence(Qt::Key_F9), Qt::ApplicationShortcut); | ||
| 30 | |||
| 31 | connect(disasm_ui.button_breakpoint, SIGNAL(clicked()), this, SLOT(OnSetBreakpoint())); | ||
| 32 | connect(disasm_ui.button_step, SIGNAL(clicked()), this, SLOT(OnStep())); | ||
| 33 | connect(disasm_ui.button_pause, SIGNAL(clicked()), this, SLOT(OnPause())); | ||
| 34 | connect(disasm_ui.button_continue, SIGNAL(clicked()), this, SLOT(OnContinue())); | ||
| 35 | |||
| 36 | connect(GetHotkey("Disassembler", "Start/Stop", this), SIGNAL(activated()), this, SLOT(OnToggleStartStop())); | ||
| 37 | connect(GetHotkey("Disassembler", "Step", this), SIGNAL(activated()), this, SLOT(OnStep())); | ||
| 38 | connect(GetHotkey("Disassembler", "Step into", this), SIGNAL(activated()), this, SLOT(OnStepInto())); | ||
| 39 | connect(GetHotkey("Disassembler", "Set Breakpoint", this), SIGNAL(activated()), this, SLOT(OnSetBreakpoint())); | ||
| 40 | } | ||
| 41 | |||
| 42 | void GDisAsmView::Init() | ||
| 43 | { | ||
| 44 | ARM_Disasm* disasm = new ARM_Disasm(); | ||
| 45 | |||
| 46 | base_addr = Core::g_app_core->PC(); | ||
| 47 | unsigned int curInstAddr = base_addr; | ||
| 48 | char result[255]; | ||
| 49 | |||
| 50 | for (int i = 0; i < 10000; i++) // fixed for now | ||
| 51 | { | ||
| 52 | disasm->disasm(curInstAddr, Memory::Read32(curInstAddr), result); | ||
| 53 | model->setItem(i, 0, new QStandardItem(QString("0x%1").arg((uint)(curInstAddr), 8, 16, QLatin1Char('0')))); | ||
| 54 | model->setItem(i, 1, new QStandardItem(QString(result))); | ||
| 55 | curInstAddr += 4; | ||
| 56 | } | ||
| 57 | disasm_ui.treeView->resizeColumnToContents(0); | ||
| 58 | disasm_ui.treeView->resizeColumnToContents(1); | ||
| 59 | |||
| 60 | QModelIndex model_index = model->index(0, 0); | ||
| 61 | disasm_ui.treeView->scrollTo(model_index); | ||
| 62 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 63 | } | ||
| 64 | |||
| 65 | void GDisAsmView::OnSetBreakpoint() | ||
| 66 | { | ||
| 67 | int selected_row = SelectedRow(); | ||
| 68 | |||
| 69 | if (selected_row == -1) | ||
| 70 | return; | ||
| 71 | |||
| 72 | u32 address = base_addr + (selected_row * 4); | ||
| 73 | if (breakpoints->IsAddressBreakPoint(address)) | ||
| 74 | { | ||
| 75 | breakpoints->Remove(address); | ||
| 76 | model->item(selected_row, 0)->setBackground(QBrush()); | ||
| 77 | model->item(selected_row, 1)->setBackground(QBrush()); | ||
| 78 | } | ||
| 79 | else | ||
| 80 | { | ||
| 81 | breakpoints->Add(address); | ||
| 82 | model->item(selected_row, 0)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99))); | ||
| 83 | model->item(selected_row, 1)->setBackground(QBrush(QColor(0xFF, 0x99, 0x99))); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | void GDisAsmView::OnContinue() | ||
| 88 | { | ||
| 89 | emu_thread.SetCpuRunning(true); | ||
| 90 | } | ||
| 91 | |||
| 92 | void GDisAsmView::OnStep() | ||
| 93 | { | ||
| 94 | OnStepInto(); // change later | ||
| 95 | } | ||
| 96 | |||
| 97 | void GDisAsmView::OnStepInto() | ||
| 98 | { | ||
| 99 | emu_thread.SetCpuRunning(false); | ||
| 100 | emu_thread.ExecStep(); | ||
| 101 | } | ||
| 102 | |||
| 103 | void GDisAsmView::OnPause() | ||
| 104 | { | ||
| 105 | emu_thread.SetCpuRunning(false); | ||
| 106 | } | ||
| 107 | |||
| 108 | void GDisAsmView::OnToggleStartStop() | ||
| 109 | { | ||
| 110 | emu_thread.SetCpuRunning(!emu_thread.IsCpuRunning()); | ||
| 111 | } | ||
| 112 | |||
| 113 | void GDisAsmView::OnCPUStepped() | ||
| 114 | { | ||
| 115 | ARMword next_instr = Core::g_app_core->PC(); | ||
| 116 | |||
| 117 | if (breakpoints->IsAddressBreakPoint(next_instr)) | ||
| 118 | { | ||
| 119 | emu_thread.SetCpuRunning(false); | ||
| 120 | } | ||
| 121 | |||
| 122 | unsigned int index = (next_instr - base_addr) / 4; | ||
| 123 | QModelIndex model_index = model->index(index, 0); | ||
| 124 | disasm_ui.treeView->scrollTo(model_index); | ||
| 125 | disasm_ui.treeView->selectionModel()->setCurrentIndex(model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); | ||
| 126 | } | ||
| 127 | |||
| 128 | int GDisAsmView::SelectedRow() | ||
| 129 | { | ||
| 130 | QModelIndex index = disasm_ui.treeView->selectionModel()->currentIndex(); | ||
| 131 | if (!index.isValid()) | ||
| 132 | return -1; | ||
| 133 | |||
| 134 | return model->itemFromIndex(disasm_ui.treeView->selectionModel()->currentIndex())->row(); | ||
| 135 | } \ No newline at end of file | ||