Fixed the SP (Stack) window UI potential missing data
[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 26 // To fill up to 256 bytes with values from 0 to $FF below the SP pointer
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 memBase(m68k_get_reg(NULL, M68K_REG_SP))
35 {
36 setWindowTitle(tr("Stack Browser"));
37
38 /*
39 address->setInputMask("hhhhhh");
40 QHBoxLayout * hbox1 = new QHBoxLayout;
41 hbox1->addWidget(refresh);
42 hbox1->addWidget(address);
43 hbox1->addWidget(go);
44 */
45
46 // Need to set the size as well...
47 // resize(560, 480);
48
49 QFont fixedFont("Lucida Console", 8, QFont::Normal);
50 // QFont fixedFont("", 8, QFont::Normal);
51 fixedFont.setStyleHint(QFont::TypeWriter);
52 text->setFont(fixedFont);
53 //// layout->setSizeConstraint(QLayout::SetFixedSize);
54 setLayout(layout);
55
56 layout->addWidget(text);
57 // layout->addWidget(refresh);
58 /*
59 layout->addLayout(hbox1);
60 */
61
62 /*
63 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
64 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
65 */
66 }
67
68
69 //
70 void StackBrowserWindow::RefreshContents(void)
71 {
72 char string[1024], buf[64];
73 QString memDump;
74 size_t i, j;
75 uint8_t c;
76
77 if (isVisible())
78 {
79 memBase = m68k_get_reg(NULL, M68K_REG_SP);
80
81 #ifdef DEBUG_SPDISPLAY
82 #if DEBUG_SPDISPLAY < 257
83 memBase -= DEBUG_SPDISPLAY;
84 for (i = 0; i < DEBUG_SPDISPLAY; i++)
85 {
86 jaguarMainRAM[memBase + i] = (uint8_t)i;
87 }
88 #endif
89 #endif
90
91 for (i = 0; i < 480; i += 16)
92 {
93 if ((memBase + i) < vjs.DRAM_size)
94 {
95 sprintf(string, "%s%06X: ", (i ? "<br>" : ""), (unsigned int)(memBase + i));
96
97 for (j = 0; j < 16; j++)
98 {
99 if ((memBase + i + j) < vjs.DRAM_size)
100 {
101 sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);
102 }
103 else
104 {
105 if (i)
106 {
107 sprintf(buf, "&nbsp;&nbsp;&nbsp;");
108 }
109 else
110 {
111 sprintf(buf, " ");
112 }
113 #ifdef _MSC_VER
114 #pragma message("Warning: !!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!")
115 #else
116 #warning "!!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!"
117 #endif // _MSC_VER
118 }
119 strcat(string, buf);
120 }
121
122 //sprintf(buf, "| ");
123 //strcat(string, buf);
124 strcat(string, "| ");
125
126 for (j = 0; j < 16; j++)
127 {
128 if ((memBase + i + j) < vjs.DRAM_size)
129 {
130 c = jaguarMainRAM[memBase + i + j];
131 //sprintf(buf, "&#%i;", c);
132
133 //if (c == 0x20)
134 //{
135 // sprintf(buf, "&nbsp;");
136 //}
137 //else
138 {
139 //if (c < 0x20)
140 if ((c < 0x20) || (c > 0x7E))
141 {
142 sprintf(buf, ".");
143 //buf[0] = '.';
144 }
145 else
146 {
147 sprintf(buf, "&#%i;", c);
148 //buf[0] = c;
149 }
150 //buf[1] = 0;
151 }
152
153 strcat(string, buf);
154 }
155 }
156
157 memDump += QString(string);
158 }
159 }
160
161 text->clear();
162 text->setText(memDump);
163 }
164 }
165
166
167 /*
168 void StackBrowserWindow::keyPressEvent(QKeyEvent * e)
169 {
170 if (e->key() == Qt::Key_Escape)
171 hide();
172 else if (e->key() == Qt::Key_PageUp)
173 {
174 memBase -= 480;
175
176 if (memBase < 0)
177 memBase = 0;
178
179 RefreshContents();
180 }
181 else if (e->key() == Qt::Key_PageDown)
182 {
183 memBase += 480;
184
185 if (memBase > (0x200000 - 480))
186 memBase = 0x200000 - 480;
187
188 RefreshContents();
189 }
190 else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
191 {
192 memBase -= 16;
193
194 if (memBase < 0)
195 memBase = 0;
196
197 RefreshContents();
198 }
199 else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
200 {
201 memBase += 16;
202
203 if (memBase > (0x200000 - 480))
204 memBase = 0x200000 - 480;
205
206 RefreshContents();
207 }
208 }
209 */
210
211
212 /*
213 void StackBrowserWindow::GoToAddress(void)
214 {
215 bool ok;
216 QString newAddress = address->text();
217 memBase = newAddress.toUInt(&ok, 16);
218 RefreshContents();
219 }
220 */