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