a94ea84de27a69e19c5bbae3488a31664ad6d3d1
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / memory1browser.cpp
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"
18 #include "debugger/DBGManager.h"
19 #include "settings.h"
20
21
22 //
23 Memory1BrowserWindow::Memory1BrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
24 // layout(new QVBoxLayout), text(new QTextBrowser),
25 layout(new QVBoxLayout), text(new QLabel),
26 refresh(new QPushButton(tr("Refresh"))),
27 address(new QLineEdit),
28 go(new QPushButton(tr("Go"))),
29 memBase(0), memOrigin(0), NumWinOrigin(0)
30 {
31 //setWindowTitle(tr("Memory 1 Browser"));
32
33 //address->setInputMask("hhhhhh");
34 address->setPlaceholderText("0x<value>, decimal value or symbol name");
35
36 QHBoxLayout * hbox1 = new QHBoxLayout;
37 hbox1->addWidget(refresh);
38 hbox1->addWidget(address);
39 hbox1->addWidget(go);
40
41 // Need to set the size as well...
42 // resize(560, 480);
43
44 QFont fixedFont("Lucida Console", 8, QFont::Normal);
45 // QFont fixedFont("", 8, QFont::Normal);
46 fixedFont.setStyleHint(QFont::TypeWriter);
47 text->setFont(fixedFont);
48 //// layout->setSizeConstraint(QLayout::SetFixedSize);
49 setLayout(layout);
50
51 layout->addWidget(text);
52 //layout->addWidget(refresh);
53 layout->addLayout(hbox1);
54
55 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContentsWindow()));
56 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
57 }
58
59
60 // Refresh / Display the window contents
61 void Memory1BrowserWindow::RefreshContents(size_t NumWin)
62 {
63 char string[100];
64
65 if (isVisible())
66 {
67 sprintf(string, "Memory %i - 0x%06X", (unsigned int)((NumWinOrigin = NumWin) + 1), (unsigned int)memOrigin);
68 setWindowTitle(tr(string));
69 RefreshContentsWindow();
70 }
71 }
72
73
74 // Refresh / Display the window contents
75 void 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 //
118 void 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 if ((memBase -= 480) < 0)
129 {
130 memBase = 0;
131 }
132
133 RefreshContentsWindow();
134 }
135 else
136 {
137 if (e->key() == Qt::Key_PageDown)
138 {
139 if ((memBase += 480) > (vjs.DRAM_size - 480))
140 {
141 memBase = vjs.DRAM_size - 480;
142 }
143
144 RefreshContentsWindow();
145 }
146 else
147 {
148 if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
149 {
150 if ((memBase -= 16) < 0)
151 {
152 memBase = 0;
153 }
154
155 RefreshContentsWindow();
156 }
157 else
158 {
159 if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
160 {
161 if ((memBase += 16) > (vjs.DRAM_size - 480))
162 {
163 memBase = vjs.DRAM_size - 480;
164 }
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
184 void Memory1BrowserWindow::GoToAddress(void)
185 {
186 bool ok;
187 size_t len;
188 QString newAddress;
189 size_t newmemBase;
190
191 QPalette p = address->palette();
192 newAddress = address->text();
193
194 if ((len = newAddress.size()))
195 {
196 if ((len > 1) && (newAddress.at(0) == QChar('0')) && (newAddress.at(1) == QChar('x')))
197 {
198 newmemBase = newAddress.toUInt(&ok, 16);
199 }
200 else
201 {
202 if (!(newmemBase = DBGManager_GetAdrFromSymbolName(newAddress.toLatin1().data())))
203 {
204 newmemBase = newAddress.toUInt(&ok, 10);
205 }
206 else
207 {
208 ok = true;
209 }
210 }
211
212 if (!ok || (newmemBase < 0) || (newmemBase > vjs.DRAM_size))
213 {
214 p.setColor(QPalette::Text, Qt::red);
215 }
216 else
217 {
218 p.setColor(QPalette::Text, Qt::black);
219 memOrigin = (memBase = newmemBase);
220 RefreshContents(NumWinOrigin);
221 }
222 address->setPalette(p);
223 }
224 }