Local variables window detects now if a variable is used or not by the code
[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"
cf76e892
JPM
19
20
21//
22Memory1BrowserWindow::Memory1BrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
23// layout(new QVBoxLayout), text(new QTextBrowser),
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{
30 //setWindowTitle(tr("Memory 1 Browser"));
31
32 //address->setInputMask("hhhhhh");
33 address->setPlaceholderText("0x<value>, decimal value or symbol name");
34
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(RefreshContentsWindow()));
55 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
56}
57
58
59// Refresh / Display the window contents
60void Memory1BrowserWindow::RefreshContents(size_t NumWin)
61{
62 char string[100];
63
64 if (isVisible())
65 {
66 sprintf(string, "Memory %i - %06X", (unsigned int)((NumWinOrigin = NumWin) + 1), (unsigned int)memOrigin);
67 setWindowTitle(tr(string));
68
69 RefreshContentsWindow();
70 }
71}
72
73
74// Refresh / Display the window contents
75void Memory1BrowserWindow::RefreshContentsWindow(void)
76{
77 char string[1024], buf[64];
78 QString memDump;
79 size_t i, j;
80 uint8_t c;
81
82 for (i = 0; i < 480; i += 16)
83 {
84 sprintf(string, "%s%06X: ", (i ? "<br>" : ""), (unsigned int)(memBase + i));
85
86 for (j = 0; j < 16; j++)
87 {
88 sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);
89 strcat(string, buf);
90 }
91
92 sprintf(buf, "| ");
93 strcat(string, buf);
94
95 for (j = 0; j < 16; j++)
96 {
97 c = jaguarMainRAM[memBase + i + j];
98 sprintf(buf, "&#%i;", c);
99
100 if (c == 0x20)
101 sprintf(buf, "&nbsp;");
102
103 if ((c < 0x20) || (c > 0x7E))
104 sprintf(buf, ".");
105
106 strcat(string, buf);
107 }
108
109 memDump += QString(string);
110 }
111
112 text->clear();
113 text->setText(memDump);
114}
115
116
117//
118void Memory1BrowserWindow::keyPressEvent(QKeyEvent * e)
119{
120 if (e->key() == Qt::Key_Escape)
121 {
122 hide();
123 }
124 else
125 {
126 if (e->key() == Qt::Key_PageUp)
127 {
128 memBase -= 480;
129
130 if (memBase < 0)
131 memBase = 0;
132
133 RefreshContentsWindow();
134 }
135 else
136 {
137 if (e->key() == Qt::Key_PageDown)
138 {
139 memBase += 480;
140
141 if (memBase > (0x200000 - 480))
142 memBase = 0x200000 - 480;
143
144 RefreshContentsWindow();
145 }
146 else
147 {
148 if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
149 {
150 memBase -= 16;
151
152 if (memBase < 0)
153 memBase = 0;
154
155 RefreshContentsWindow();
156 }
157 else
158 {
159 if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
160 {
161 memBase += 16;
162
163 if (memBase > (0x200000 - 480))
164 memBase = 0x200000 - 480;
165
166 RefreshContentsWindow();
167 }
168 else
169 {
170 if (e->key() == Qt::Key_Return)
171 {
172 GoToAddress();
173 }
174 }
175 }
176 }
177 }
178 }
179}
180
181
182// Go to the requested address
183// Address can be an hexa, decimal or a symbol name
184void Memory1BrowserWindow::GoToAddress(void)
185{
186 bool ok;
187 QString newAddress;
188
189 newAddress = address->text();
190
191 if (( newAddress.at(0) == QChar('0')) && (newAddress.at(1) == QChar('x')))
192 {
193 memBase = newAddress.toUInt(&ok, 16);
194 }
195 else
196 {
197 if (!(memBase = DBGManager_GetAdrFromSymbolName(newAddress.toLatin1().data())))
198 {
199 memBase = newAddress.toUInt(&ok, 10);
200 }
201 }
202
203 memOrigin = memBase;
204 RefreshContents(NumWinOrigin);
205}