core: Fix libdwarf and Qt build failure
[clinton/Virtual-Jaguar-Rx.git] / src / gui / debug / stackbrowser.cpp
1 //
2 // stackbrowser.cpp - Jaguar stack browser
3 //
4 // by James Hammons
5 // (C) 2012 Underground Software
6 //
7 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
8 //
9 // Who When What
10 // --- ---------- -----------------------------------------------------------
11 // JPM 01/11/2017 Created this file
12 //
13
14 // STILL TO DO:
15 //
16
17 #include "stackbrowser.h"
18 #include "memory.h"
19 #include "m68000/m68kinterface.h"
20 #include "settings.h"
21
22
23 //#define DEBUG_SPDISPLAY 1000 // To fill up to 256 bytes with values from 0 to $FF below the SP pointer any above are random values
24
25
26 //
27 StackBrowserWindow::StackBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
28 // layout(new QVBoxLayout), text(new QTextBrowser),
29 layout(new QVBoxLayout),
30 text(new QLabel),
31 //refresh(new QPushButton(tr("Refresh"))),
32 //address(new QLineEdit),
33 //go(new QPushButton(tr("Go"))),
34 stackBase(m68k_get_reg(NULL, M68K_REG_SP))
35 {
36 /*
37 address->setInputMask("hhhhhh");
38 QHBoxLayout * hbox1 = new QHBoxLayout;
39 hbox1->addWidget(refresh);
40 hbox1->addWidget(address);
41 hbox1->addWidget(go);
42 */
43
44 // Need to set the size as well...
45 // resize(560, 480);
46
47 QFont fixedFont("Lucida Console", 8, QFont::Normal);
48 // QFont fixedFont("", 8, QFont::Normal);
49 fixedFont.setStyleHint(QFont::TypeWriter);
50 text->setFont(fixedFont);
51 //// layout->setSizeConstraint(QLayout::SetFixedSize);
52 setLayout(layout);
53
54 layout->addWidget(text);
55 // layout->addWidget(refresh);
56 /*
57 layout->addLayout(hbox1);
58 */
59
60 /*
61 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
62 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
63 */
64 }
65
66
67 //
68 void StackBrowserWindow::RefreshContents(void)
69 {
70 char string[1024];
71
72 if (isVisible())
73 {
74 #ifdef DEBUG_SPDISPLAY
75 m68k_set_reg(M68K_REG_SP, (vjs.DRAM_size - DEBUG_SPDISPLAY));
76 #endif
77 if ((stackBase = m68k_get_reg(NULL, M68K_REG_SP)) && (stackBase < vjs.DRAM_size))
78 {
79
80 #ifdef DEBUG_SPDISPLAY
81 for (int i = 0; i < DEBUG_SPDISPLAY; i++)
82 {
83 #if DEBUG_SPDISPLAY < 257
84 jaguarMainRAM[stackBase + i] = (uint8_t)i;
85 #else
86 jaguarMainRAM[stackBase + i] = (uint8_t)rand();
87 #endif
88 }
89 #endif
90 sprintf(string, "Stack Browser - 0x%06X", (unsigned int)(stackBase, (unsigned int)stackBase));
91 }
92 else
93 {
94 sprintf(string, "Stack Browser");
95 }
96
97 setWindowTitle(tr(string));
98 RefreshContentsWindow();
99 }
100 }
101
102
103 // Refresh / Display the window contents
104 void StackBrowserWindow::RefreshContentsWindow(void)
105 {
106 char string[2048], buf[64];
107 QString memDump;
108 size_t i, j;
109 uint8_t c;
110
111 if (stackBase < vjs.DRAM_size)
112 {
113 for (i = 0; i < 480; i += 16)
114 {
115 if ((stackBase + i) < vjs.DRAM_size)
116 {
117 sprintf(string, "%s%06X: ", (i ? "<br>" : ""), (unsigned int)(stackBase + i));
118
119 for (j = 0; j < 16; j++)
120 {
121 if ((stackBase + i + j) < vjs.DRAM_size)
122 {
123 sprintf(buf, "%02X ", jaguarMainRAM[stackBase + i + j]);
124 }
125 else
126 {
127 if (i)
128 {
129 sprintf(buf, "&nbsp;&nbsp;&nbsp;");
130 }
131 else
132 {
133 sprintf(buf, " ");
134 }
135 #ifdef _MSC_VER
136 #pragma message("Warning: !!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!")
137 #else
138 #warning "!!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!"
139 #endif // _MSC_VER
140 }
141 strcat(string, buf);
142 }
143
144 //sprintf(buf, "| ");
145 //strcat(string, buf);
146 strcat(string, "| ");
147
148 for (j = 0; j < 16; j++)
149 {
150 if ((stackBase + i + j) < vjs.DRAM_size)
151 {
152 c = jaguarMainRAM[stackBase + i + j];
153 //sprintf(buf, "&#%i;", c);
154
155 //if (c == 0x20)
156 //{
157 // sprintf(buf, "&nbsp;");
158 //}
159 //else
160 {
161 //if (c < 0x20)
162 if ((c < 0x20) || (c > 0x7E))
163 {
164 sprintf(buf, ".");
165 //buf[0] = '.';
166 }
167 else
168 {
169 sprintf(buf, "&#%i;", c);
170 //buf[0] = c;
171 }
172 //buf[1] = 0;
173 }
174
175 strcat(string, buf);
176 }
177 }
178
179 memDump += QString(string);
180 }
181 }
182 }
183 else
184 {
185 memDump += QString("");
186 }
187
188 text->clear();
189 text->setText(memDump);
190 }
191
192
193 //
194 void StackBrowserWindow::keyPressEvent(QKeyEvent * e)
195 {
196 size_t offset;
197
198 // Escape key to hide the window
199 if (e->key() == Qt::Key_Escape)
200 {
201 hide();
202 }
203 else
204 {
205 if (stackBase < vjs.DRAM_size)
206 {
207 if (e->key() == Qt::Key_PageUp)
208 {
209 offset = -480;
210 }
211 else
212 {
213 if (e->key() == Qt::Key_PageDown)
214 {
215 offset = 480;
216 }
217 else
218 {
219 if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
220 {
221 offset = -16;
222 }
223 else
224 {
225 if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Plus)
226 {
227 offset = 16;
228 }
229 else
230 {
231 offset = 0;
232 }
233 }
234 }
235 }
236
237 if (offset)
238 {
239 if (offset < 0)
240 {
241 if ((stackBase += offset) < m68k_get_reg(NULL, M68K_REG_SP))
242 {
243 stackBase = m68k_get_reg(NULL, M68K_REG_SP);
244 }
245 }
246 else
247 {
248 if ((stackBase += offset) > (vjs.DRAM_size - 480))
249 {
250 stackBase = vjs.DRAM_size - 480;
251 }
252
253 if (stackBase < m68k_get_reg(NULL, M68K_REG_SP))
254 {
255 stackBase = m68k_get_reg(NULL, M68K_REG_SP);
256 }
257 }
258
259 RefreshContentsWindow();
260 }
261 }
262 }
263 }
264
265
266 /*
267 void StackBrowserWindow::GoToAddress(void)
268 {
269 bool ok;
270 QString newAddress = address->text();
271 stackBase = newAddress.toUInt(&ok, 16);
272 RefreshContents();
273 }
274 */