Debugger sources code clean-up
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / memory1browser.cpp
CommitLineData
cf76e892
JPM
1//
2// memory1browser.cpp - Jaguar memory window 1 browser
3//
4// by Jean-Paul Mari
5//
6// JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7//
8// Who When What
9// --- ---------- -----------------------------------------------------------
10// JPM 08/07/2017 Created this file
11//
12
13// STILL TO DO:
14//
15
16#include "memory1browser.h"
17#include "memory.h"
5fe21518 18#include "debugger/DBGManager.h"
8d867eb2 19#include "settings.h"
cf76e892
JPM
20
21
22//
23Memory1BrowserWindow::Memory1BrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
cf76e892
JPM
24 layout(new QVBoxLayout), text(new QLabel),
25 refresh(new QPushButton(tr("Refresh"))),
26 address(new QLineEdit),
27 go(new QPushButton(tr("Go"))),
28 memBase(0), memOrigin(0), NumWinOrigin(0)
29{
cf76e892
JPM
30 address->setPlaceholderText("0x<value>, decimal value or symbol name");
31
32 QHBoxLayout * hbox1 = new QHBoxLayout;
33 hbox1->addWidget(refresh);
34 hbox1->addWidget(address);
35 hbox1->addWidget(go);
36
cf76e892 37 QFont fixedFont("Lucida Console", 8, QFont::Normal);
cf76e892
JPM
38 fixedFont.setStyleHint(QFont::TypeWriter);
39 text->setFont(fixedFont);
cf76e892
JPM
40 setLayout(layout);
41
42 layout->addWidget(text);
cf76e892
JPM
43 layout->addLayout(hbox1);
44
45 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContentsWindow()));
46 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
47}
48
49
50// Refresh / Display the window contents
51void Memory1BrowserWindow::RefreshContents(size_t NumWin)
52{
53 char string[100];
54
55 if (isVisible())
56 {
8d867eb2 57 sprintf(string, "Memory %i - 0x%06X", (unsigned int)((NumWinOrigin = NumWin) + 1), (unsigned int)memOrigin);
cf76e892 58 setWindowTitle(tr(string));
cf76e892
JPM
59 RefreshContentsWindow();
60 }
61}
62
63
64// Refresh / Display the window contents
65void Memory1BrowserWindow::RefreshContentsWindow(void)
66{
67 char string[1024], buf[64];
68 QString memDump;
69 size_t i, j;
70 uint8_t c;
71
72 for (i = 0; i < 480; i += 16)
73 {
74 sprintf(string, "%s%06X: ", (i ? "<br>" : ""), (unsigned int)(memBase + i));
75
76 for (j = 0; j < 16; j++)
77 {
78 sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);
79 strcat(string, buf);
80 }
81
82 sprintf(buf, "| ");
83 strcat(string, buf);
84
85 for (j = 0; j < 16; j++)
86 {
87 c = jaguarMainRAM[memBase + i + j];
88 sprintf(buf, "&#%i;", c);
89
90 if (c == 0x20)
91 sprintf(buf, "&nbsp;");
92
93 if ((c < 0x20) || (c > 0x7E))
94 sprintf(buf, ".");
95
96 strcat(string, buf);
97 }
98
99 memDump += QString(string);
100 }
101
102 text->clear();
103 text->setText(memDump);
104}
105
106
107//
108void Memory1BrowserWindow::keyPressEvent(QKeyEvent * e)
109{
110 if (e->key() == Qt::Key_Escape)
111 {
112 hide();
113 }
114 else
115 {
116 if (e->key() == Qt::Key_PageUp)
117 {
a2dfb8e5 118 if ((memBase -= 480) < 0)
8d867eb2 119 {
cf76e892 120 memBase = 0;
8d867eb2 121 }
cf76e892
JPM
122
123 RefreshContentsWindow();
124 }
125 else
126 {
127 if (e->key() == Qt::Key_PageDown)
128 {
a2dfb8e5 129 if ((memBase += 480) > (vjs.DRAM_size - 480))
8d867eb2
JPM
130 {
131 memBase = vjs.DRAM_size - 480;
132 }
cf76e892
JPM
133
134 RefreshContentsWindow();
135 }
136 else
137 {
138 if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
139 {
a2dfb8e5 140 if ((memBase -= 16) < 0)
8d867eb2 141 {
cf76e892 142 memBase = 0;
8d867eb2 143 }
cf76e892
JPM
144
145 RefreshContentsWindow();
146 }
147 else
148 {
149 if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
150 {
a2dfb8e5 151 if ((memBase += 16) > (vjs.DRAM_size - 480))
8d867eb2
JPM
152 {
153 memBase = vjs.DRAM_size - 480;
154 }
cf76e892
JPM
155
156 RefreshContentsWindow();
157 }
158 else
159 {
160 if (e->key() == Qt::Key_Return)
161 {
162 GoToAddress();
163 }
164 }
165 }
166 }
167 }
168 }
169}
170
171
172// Go to the requested address
173// Address can be an hexa, decimal or a symbol name
174void Memory1BrowserWindow::GoToAddress(void)
175{
176 bool ok;
a2dfb8e5 177 size_t len;
cf76e892 178 QString newAddress;
8d867eb2 179 size_t newmemBase;
cf76e892 180
8d867eb2 181 QPalette p = address->palette();
cf76e892
JPM
182 newAddress = address->text();
183
a2dfb8e5 184 if ((len = newAddress.size()))
cf76e892 185 {
a2dfb8e5 186 if ((len > 1) && (newAddress.at(0) == QChar('0')) && (newAddress.at(1) == QChar('x')))
cf76e892 187 {
8d867eb2
JPM
188 newmemBase = newAddress.toUInt(&ok, 16);
189 }
190 else
191 {
192 if (!(newmemBase = DBGManager_GetAdrFromSymbolName(newAddress.toLatin1().data())))
193 {
194 newmemBase = newAddress.toUInt(&ok, 10);
195 }
196 else
197 {
198 ok = true;
199 }
cf76e892 200 }
cf76e892 201
8d867eb2
JPM
202 if (!ok || (newmemBase < 0) || (newmemBase > vjs.DRAM_size))
203 {
204 p.setColor(QPalette::Text, Qt::red);
205 }
206 else
207 {
208 p.setColor(QPalette::Text, Qt::black);
209 memOrigin = (memBase = newmemBase);
210 RefreshContents(NumWinOrigin);
211 }
212 address->setPalette(p);
213 }
cf76e892 214}