2 // stackbrowser.cpp - Jaguar stack browser
5 // (C) 2012 Underground Software
7 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
10 // --- ---------- -----------------------------------------------------------
11 // JPM 01/11/2017 Created this file
17 #include "stackbrowser.h"
19 #include "m68000/m68kinterface.h"
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
27 StackBrowserWindow::StackBrowserWindow(QWidget
* parent
/*= 0*/): QWidget(parent
, Qt::Dialog
),
28 // layout(new QVBoxLayout), text(new QTextBrowser),
29 layout(new QVBoxLayout
),
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
))
37 address->setInputMask("hhhhhh");
38 QHBoxLayout * hbox1 = new QHBoxLayout;
39 hbox1->addWidget(refresh);
40 hbox1->addWidget(address);
44 // Need to set the size as well...
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);
54 layout
->addWidget(text
);
55 // layout->addWidget(refresh);
57 layout->addLayout(hbox1);
61 connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
62 connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
68 void StackBrowserWindow::RefreshContents(void)
74 #ifdef DEBUG_SPDISPLAY
75 m68k_set_reg(M68K_REG_SP
, (vjs
.DRAM_size
- DEBUG_SPDISPLAY
));
77 if ((stackBase
= m68k_get_reg(NULL
, M68K_REG_SP
)) && (stackBase
< vjs
.DRAM_size
))
80 #ifdef DEBUG_SPDISPLAY
81 for (int i
= 0; i
< DEBUG_SPDISPLAY
; i
++)
83 #if DEBUG_SPDISPLAY < 257
84 jaguarMainRAM
[stackBase
+ i
] = (uint8_t)i
;
86 jaguarMainRAM
[stackBase
+ i
] = (uint8_t)rand();
90 sprintf(string
, "Stack Browser - 0x%06X", (unsigned int)(stackBase
, (unsigned int)stackBase
));
94 sprintf(string
, "Stack Browser");
97 setWindowTitle(tr(string
));
98 RefreshContentsWindow();
103 // Refresh / Display the window contents
104 void StackBrowserWindow::RefreshContentsWindow(void)
106 char string
[2048], buf
[64];
111 if (stackBase
< vjs
.DRAM_size
)
113 for (i
= 0; i
< 480; i
+= 16)
115 if ((stackBase
+ i
) < vjs
.DRAM_size
)
117 sprintf(string
, "%s%06X: ", (i
? "<br>" : ""), (unsigned int)(stackBase
+ i
));
119 for (j
= 0; j
< 16; j
++)
121 if ((stackBase
+ i
+ j
) < vjs
.DRAM_size
)
123 sprintf(buf
, "%02X ", jaguarMainRAM
[stackBase
+ i
+ j
]);
129 sprintf(buf
, " ");
136 #pragma message("Warning: !!! Need to dig the reason(s) why the 2nd line needs to use the instead of space !!!")
138 #warning "!!! Need to dig the reason(s) why the 2nd line needs to use the instead of space !!!"
144 //sprintf(buf, "| ");
145 //strcat(string, buf);
146 strcat(string
, "| ");
148 for (j
= 0; j
< 16; j
++)
150 if ((stackBase
+ i
+ j
) < vjs
.DRAM_size
)
152 c
= jaguarMainRAM
[stackBase
+ i
+ j
];
153 //sprintf(buf, "&#%i;", c);
157 // sprintf(buf, " ");
162 if ((c
< 0x20) || (c
> 0x7E))
169 sprintf(buf
, "&#%i;", c
);
179 memDump
+= QString(string
);
185 memDump
+= QString("");
189 text
->setText(memDump
);
194 void StackBrowserWindow::keyPressEvent(QKeyEvent
* e
)
198 // Escape key to hide the window
199 if (e
->key() == Qt::Key_Escape
)
205 if (stackBase
< vjs
.DRAM_size
)
207 if (e
->key() == Qt::Key_PageUp
)
213 if (e
->key() == Qt::Key_PageDown
)
219 if (e
->key() == Qt::Key_Up
|| e
->key() == Qt::Key_Minus
)
225 if (e
->key() == Qt::Key_Down
|| e
->key() == Qt::Key_Plus
)
241 if ((stackBase
+= offset
) < m68k_get_reg(NULL
, M68K_REG_SP
))
243 stackBase
= m68k_get_reg(NULL
, M68K_REG_SP
);
248 if ((stackBase
+= offset
) > (vjs
.DRAM_size
- 480))
250 stackBase
= vjs
.DRAM_size
- 480;
253 if (stackBase
< m68k_get_reg(NULL
, M68K_REG_SP
))
255 stackBase
= m68k_get_reg(NULL
, M68K_REG_SP
);
259 RefreshContentsWindow();
267 void StackBrowserWindow::GoToAddress(void)
270 QString newAddress = address->text();
271 stackBase = newAddress.toUInt(&ok, 16);