summaryrefslogtreecommitdiff
path: root/src/citra_qt/disasm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt/disasm.cpp')
-rw-r--r--src/citra_qt/disasm.cpp135
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
16GDisAsmView::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
42void 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
65void 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
87void GDisAsmView::OnContinue()
88{
89 emu_thread.SetCpuRunning(true);
90}
91
92void GDisAsmView::OnStep()
93{
94 OnStepInto(); // change later
95}
96
97void GDisAsmView::OnStepInto()
98{
99 emu_thread.SetCpuRunning(false);
100 emu_thread.ExecStep();
101}
102
103void GDisAsmView::OnPause()
104{
105 emu_thread.SetCpuRunning(false);
106}
107
108void GDisAsmView::OnToggleStartStop()
109{
110 emu_thread.SetCpuRunning(!emu_thread.IsCpuRunning());
111}
112
113void 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
128int 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