Fixed the SP (Stack) window UI potential missing data
[clinton/Virtual-Jaguar-Rx.git] / src / gui / debug / stackbrowser.cpp
index 43e970e..ebd68ac 100644 (file)
-//
-// stackbrowser.cpp - Jaguar stack  browser
-//
-// by James Hammons
-// (C) 2012 Underground Software
-//
-// JPM = Jean-Paul Mari <djipi.mari@gmail.com>
-//
-// Who  When        What
-// ---  ----------  -----------------------------------------------------------
-// JPM  01/11/2017  Created this file
-//
-
-// STILL TO DO:
-//
-
-#include "stackbrowser.h"
-#include "memory.h"
-#include "m68000/m68kinterface.h"
-#include "settings.h"
-
-
-StackBrowserWindow::StackBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
-//     layout(new QVBoxLayout), text(new QTextBrowser),
-       layout(new QVBoxLayout),
-       text(new QLabel),
-       //refresh(new QPushButton(tr("Refresh"))),
-       //address(new QLineEdit),
-       //go(new QPushButton(tr("Go"))),
-       memBase(m68k_get_reg(NULL, M68K_REG_SP))
-{
-       setWindowTitle(tr("Stack Browser"));
-
-/*
-       address->setInputMask("hhhhhh");
-       QHBoxLayout * hbox1 = new QHBoxLayout;
-       hbox1->addWidget(refresh);
-       hbox1->addWidget(address);
-       hbox1->addWidget(go);
-*/
-
-       // Need to set the size as well...
-//     resize(560, 480);
-
-       QFont fixedFont("Lucida Console", 8, QFont::Normal);
-//     QFont fixedFont("", 8, QFont::Normal);
-       fixedFont.setStyleHint(QFont::TypeWriter);
-       text->setFont(fixedFont);
-////   layout->setSizeConstraint(QLayout::SetFixedSize);
-       setLayout(layout);
-
-       layout->addWidget(text);
-//     layout->addWidget(refresh);
-/*
-       layout->addLayout(hbox1);
-*/
-
-/*
-       connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
-       connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
-*/
-}
-
-
-// 
-void StackBrowserWindow::RefreshContents(void)
-{
-       char string[1024], buf[64];
-       QString memDump;
-       size_t i, j;
-       uint8_t c;
-
-       if (isVisible())
-       {
-               memBase = m68k_get_reg(NULL, M68K_REG_SP);
-
-               for (i = 0; i < 480; i += 16)
-               {
-                       if ((memBase + i) < vjs.DRAM_size)
-                       {
-                               sprintf(string, "%s%06X: ", (i ? "<br>" : ""), (unsigned int)(memBase + i));
-
-                               for (j = 0; j < 16; j++)
-                               {
-                                       if ((memBase + i + j) < vjs.DRAM_size)
-                                       {
-                                               sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);
-                                       }
-                                       else
-                                       {
-                                               if (i)
-                                               {
-                                                       sprintf(buf, "&nbsp;&nbsp;&nbsp;");
-                                               }
-                                               else
-                                               {
-                                                       sprintf(buf, "   ");
-                                               }
-#ifdef _MSC_VER
-#pragma message("Warning: !!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!")
-#else
-#warning "!!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!"
-#endif // _MSC_VER
-                                       }
-                                       strcat(string, buf);
-                               }
-
-                               //sprintf(buf, "| ");
-                               //strcat(string, buf);
-                               strcat(string, "| ");
-
-                               for (j = 0; j < 16; j++)
-                               {
-                                       if ((memBase + i + j) < vjs.DRAM_size)
-                                       {
-                                               c = jaguarMainRAM[memBase + i + j];
-                                               //sprintf(buf, "&#%i;", c);
-
-                                               //if (c == 0x20)
-                                               //{
-                                               //      sprintf(buf, "&nbsp;");
-                                               //}
-                                               //else
-                                               {
-                                                       if ((c <= 0x20) || (c > 0x7E))
-                                                       {
-                                                               //sprintf(buf, ".");
-                                                               buf[0] = '.';
-                                                       }
-                                                       else
-                                                       {
-                                                               //sprintf(buf, "&#%i;", c);
-                                                               buf[0] = c;
-                                                       }
-                                                       buf[1] = 0;
-                                               }
-
-                                               strcat(string, buf);
-                                       }
-                               }
-
-                               memDump += QString(string);
-                       }
-               }
-
-               text->clear();
-               text->setText(memDump);
-       }
-}
-
-
-/*
-void StackBrowserWindow::keyPressEvent(QKeyEvent * e)
-{
-       if (e->key() == Qt::Key_Escape)
-               hide();
-       else if (e->key() == Qt::Key_PageUp)
-       {
-               memBase -= 480;
-
-               if (memBase < 0)
-                       memBase = 0;
-
-               RefreshContents();
-       }
-       else if (e->key() == Qt::Key_PageDown)
-       {
-               memBase += 480;
-
-               if (memBase > (0x200000 - 480))
-                       memBase = 0x200000 - 480;
-
-               RefreshContents();
-       }
-       else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
-       {
-               memBase -= 16;
-
-               if (memBase < 0)
-                       memBase = 0;
-
-               RefreshContents();
-       }
-       else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
-       {
-               memBase += 16;
-
-               if (memBase > (0x200000 - 480))
-                       memBase = 0x200000 - 480;
-
-               RefreshContents();
-       }
-}
-*/
-
-
-/*
-void StackBrowserWindow::GoToAddress(void)
-{
-       bool ok;
-       QString newAddress = address->text();
-       memBase = newAddress.toUInt(&ok, 16);
-       RefreshContents();
-}
-*/
+//\r
+// stackbrowser.cpp - Jaguar stack  browser\r
+//\r
+// by James Hammons\r
+// (C) 2012 Underground Software\r
+//\r
+// JPM = Jean-Paul Mari <djipi.mari@gmail.com>\r
+//\r
+// Who  When        What\r
+// ---  ----------  -----------------------------------------------------------\r
+// JPM  01/11/2017  Created this file\r
+//\r
+\r
+// STILL TO DO:\r
+//\r
+\r
+#include "stackbrowser.h"\r
+#include "memory.h"\r
+#include "m68000/m68kinterface.h"\r
+#include "settings.h"\r
+\r
+\r
+//#define DEBUG_SPDISPLAY 26                   // To fill up to 256 bytes with values from 0 to $FF below the SP pointer\r
+\r
+\r
+//\r
+StackBrowserWindow::StackBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),\r
+//     layout(new QVBoxLayout), text(new QTextBrowser),\r
+       layout(new QVBoxLayout),\r
+       text(new QLabel),\r
+       //refresh(new QPushButton(tr("Refresh"))),\r
+       //address(new QLineEdit),\r
+       //go(new QPushButton(tr("Go"))),\r
+       memBase(m68k_get_reg(NULL, M68K_REG_SP))\r
+{\r
+       setWindowTitle(tr("Stack Browser"));\r
+\r
+/*\r
+       address->setInputMask("hhhhhh");\r
+       QHBoxLayout * hbox1 = new QHBoxLayout;\r
+       hbox1->addWidget(refresh);\r
+       hbox1->addWidget(address);\r
+       hbox1->addWidget(go);\r
+*/\r
+\r
+       // Need to set the size as well...\r
+//     resize(560, 480);\r
+\r
+       QFont fixedFont("Lucida Console", 8, QFont::Normal);\r
+//     QFont fixedFont("", 8, QFont::Normal);\r
+       fixedFont.setStyleHint(QFont::TypeWriter);\r
+       text->setFont(fixedFont);\r
+////   layout->setSizeConstraint(QLayout::SetFixedSize);\r
+       setLayout(layout);\r
+\r
+       layout->addWidget(text);\r
+//     layout->addWidget(refresh);\r
+/*\r
+       layout->addLayout(hbox1);\r
+*/\r
+\r
+/*\r
+       connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));\r
+       connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));\r
+*/\r
+}\r
+\r
+\r
+// \r
+void StackBrowserWindow::RefreshContents(void)\r
+{\r
+       char string[1024], buf[64];\r
+       QString memDump;\r
+       size_t i, j;\r
+       uint8_t c;\r
+\r
+       if (isVisible())\r
+       {\r
+               memBase = m68k_get_reg(NULL, M68K_REG_SP);\r
+\r
+#ifdef DEBUG_SPDISPLAY\r
+#if DEBUG_SPDISPLAY < 257\r
+               memBase -= DEBUG_SPDISPLAY;\r
+               for (i = 0; i < DEBUG_SPDISPLAY; i++)\r
+               {\r
+                       jaguarMainRAM[memBase + i] = (uint8_t)i;\r
+               }\r
+#endif\r
+#endif\r
+\r
+               for (i = 0; i < 480; i += 16)\r
+               {\r
+                       if ((memBase + i) < vjs.DRAM_size)\r
+                       {\r
+                               sprintf(string, "%s%06X: ", (i ? "<br>" : ""), (unsigned int)(memBase + i));\r
+\r
+                               for (j = 0; j < 16; j++)\r
+                               {\r
+                                       if ((memBase + i + j) < vjs.DRAM_size)\r
+                                       {\r
+                                               sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if (i)\r
+                                               {\r
+                                                       sprintf(buf, "&nbsp;&nbsp;&nbsp;");\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       sprintf(buf, "   ");\r
+                                               }\r
+#ifdef _MSC_VER\r
+#pragma message("Warning: !!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!")\r
+#else\r
+#warning "!!! Need to dig the reason(s) why the 2nd line needs to use the &nbsp; instead of space !!!"\r
+#endif // _MSC_VER\r
+                                       }\r
+                                       strcat(string, buf);\r
+                               }\r
+\r
+                               //sprintf(buf, "| ");\r
+                               //strcat(string, buf);\r
+                               strcat(string, "| ");\r
+\r
+                               for (j = 0; j < 16; j++)\r
+                               {\r
+                                       if ((memBase + i + j) < vjs.DRAM_size)\r
+                                       {\r
+                                               c = jaguarMainRAM[memBase + i + j];\r
+                                               //sprintf(buf, "&#%i;", c);\r
+\r
+                                               //if (c == 0x20)\r
+                                               //{\r
+                                               //      sprintf(buf, "&nbsp;");\r
+                                               //}\r
+                                               //else\r
+                                               {\r
+                                                       //if (c < 0x20)\r
+                                                       if ((c < 0x20) || (c > 0x7E))\r
+                                                       {\r
+                                                               sprintf(buf, ".");\r
+                                                               //buf[0] = '.';\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               sprintf(buf, "&#%i;", c);\r
+                                                               //buf[0] = c;\r
+                                                       }\r
+                                                       //buf[1] = 0;\r
+                                               }\r
+\r
+                                               strcat(string, buf);\r
+                                       }\r
+                               }\r
+\r
+                               memDump += QString(string);\r
+                       }\r
+               }\r
+\r
+               text->clear();\r
+               text->setText(memDump);\r
+       }\r
+}\r
+\r
+\r
+/*\r
+void StackBrowserWindow::keyPressEvent(QKeyEvent * e)\r
+{\r
+       if (e->key() == Qt::Key_Escape)\r
+               hide();\r
+       else if (e->key() == Qt::Key_PageUp)\r
+       {\r
+               memBase -= 480;\r
+\r
+               if (memBase < 0)\r
+                       memBase = 0;\r
+\r
+               RefreshContents();\r
+       }\r
+       else if (e->key() == Qt::Key_PageDown)\r
+       {\r
+               memBase += 480;\r
+\r
+               if (memBase > (0x200000 - 480))\r
+                       memBase = 0x200000 - 480;\r
+\r
+               RefreshContents();\r
+       }\r
+       else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)\r
+       {\r
+               memBase -= 16;\r
+\r
+               if (memBase < 0)\r
+                       memBase = 0;\r
+\r
+               RefreshContents();\r
+       }\r
+       else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)\r
+       {\r
+               memBase += 16;\r
+\r
+               if (memBase > (0x200000 - 480))\r
+                       memBase = 0x200000 - 480;\r
+\r
+               RefreshContents();\r
+       }\r
+}\r
+*/\r
+\r
+\r
+/*\r
+void StackBrowserWindow::GoToAddress(void)\r
+{\r
+       bool ok;\r
+       QString newAddress = address->text();\r
+       memBase = newAddress.toUInt(&ok, 16);\r
+       RefreshContents();\r
+}\r
+*/\r