First commit
[clinton/Virtual-Jaguar-Rx.git] / src / gui / debug / m68kdasmbrowser.cpp
CommitLineData
cf76e892
JPM
1//
2// m68kdasmbrowser.cpp - Jaguar M68K disassembly browser
3//
4// by James Hammons
5// (C) 2012 Underground Software
6//
7// JLH = James Hammons <jlhamm@acm.org>
8//
9// Who When What
10// --- ---------- -------------------------------------------------------------
11// JLH 12/01/2012 Created this file
12//
13
14// STILL TO DO:
15//
16
17#include "m68kdasmbrowser.h"
18//#include "memory.h"
19#include "m68000/m68kinterface.h"
20#include "dsp.h"
21#include "gpu.h"
22
23
24M68KDasmBrowserWindow::M68KDasmBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
25// layout(new QVBoxLayout), text(new QTextBrowser),
26 layout(new QVBoxLayout), text(new QLabel),
27 refresh(new QPushButton(tr("Refresh"))),
28 address(new QLineEdit),
29 go(new QPushButton(tr("Go"))),
30 memBase(0x4000)
31{
32 setWindowTitle(tr("M68K Disassembly Browser"));
33
34 address->setInputMask("hhhhhh");
35 QHBoxLayout * hbox1 = new QHBoxLayout;
36 hbox1->addWidget(refresh);
37 hbox1->addWidget(address);
38 hbox1->addWidget(go);
39
40 // Need to set the size as well...
41// resize(560, 480);
42
43 QFont fixedFont("Lucida Console", 8, QFont::Normal);
44// QFont fixedFont("", 8, QFont::Normal);
45 fixedFont.setStyleHint(QFont::TypeWriter);
46 text->setFont(fixedFont);
47//// layout->setSizeConstraint(QLayout::SetFixedSize);
48 setLayout(layout);
49
50 layout->addWidget(text);
51// layout->addWidget(refresh);
52 layout->addLayout(hbox1);
53
54 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
55 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
56}
57
58
59void M68KDasmBrowserWindow::RefreshContents(void)
60{
61 char string[1024];//, buf[64];
62 QString s;
63
64 char buffer[2048];
65 int pc = memBase, oldpc;
66
67 if (isVisible())
68 {
69 for (uint32_t i = 0; i < 32; i++)
70 {
71 oldpc = pc;
72 pc += m68k_disassemble(buffer, pc, 0, 1);
73 // WriteLog("%06X: %s\n", oldpc, buffer);
74 sprintf(string, "%06X: %s<br>", oldpc, buffer);
75
76 buffer[0] = 0; // Clear string
77 char singleCharString[2] = { 0, 0 };
78
79 for (int j = 0; j < strlen(string); j++)
80 {
81 if (string[j] == 32)
82 strcat(buffer, "&nbsp;");
83 else
84 {
85 singleCharString[0] = string[j];
86 strcat(buffer, singleCharString);
87 }
88 }
89
90 // s += QString(string);
91 s += QString(buffer);
92 }
93
94 text->clear();
95 text->setText(s);
96 }
97}
98
99
100void M68KDasmBrowserWindow::keyPressEvent(QKeyEvent * e)
101{
102 if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
103 hide();
104#if 1
105 else if (e->key() == Qt::Key_PageUp)
106 {
107 memBase -= 64;
108
109 if (memBase < 0)
110 memBase = 0;
111
112 RefreshContents();
113 }
114 else if (e->key() == Qt::Key_PageDown)
115 {
116 memBase += 64;
117
118 if (memBase > (0xF00000 - 64))
119 memBase = 0xF00000 - 64;
120
121 RefreshContents();
122 }
123 else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
124 {
125 memBase -= 16;
126
127 if (memBase < 0)
128 memBase = 0;
129
130 RefreshContents();
131 }
132 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
133 {
134 memBase += 16;
135
136 if (memBase > (0xF00000 - 64))
137 memBase = 0xF00000 - 64;
138
139 RefreshContents();
140 }
141#endif
142}
143
144
145void M68KDasmBrowserWindow::GoToAddress(void)
146{
147 bool ok;
148 QString newAddress = address->text();
149 memBase = newAddress.toUInt(&ok, 16);
150 RefreshContents();
151}
152