]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/debug/memorybrowser.cpp
Added RISC disassembly browser.
[virtualjaguar] / src / gui / debug / memorybrowser.cpp
1 //
2 // memorybrowser.cpp - Jaguar memory browser
3 //
4 // by James Hammons
5 // (C) 2012 Underground Software
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // Who  When        What
10 // ---  ----------  -------------------------------------------------------------
11 // JLH  08/14/2012  Created this file
12 //
13
14 // STILL TO DO:
15 //
16
17 #include "memorybrowser.h"
18 #include "memory.h"
19
20
21 MemoryBrowserWindow::MemoryBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog),
22 //      layout(new QVBoxLayout), text(new QTextBrowser),
23         layout(new QVBoxLayout), text(new QLabel),
24         refresh(new QPushButton(tr("Refresh"))),
25         memBase(0)
26 {
27         setWindowTitle(tr("Memory Browser"));
28
29         // Need to set the size as well...
30 //      resize(560, 480);
31
32         QFont fixedFont("Lucida Console", 8, QFont::Normal);
33         text->setFont(fixedFont);
34 ////    layout->setSizeConstraint(QLayout::SetFixedSize);
35         setLayout(layout);
36
37         layout->addWidget(text);
38         layout->addWidget(refresh);
39
40         connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
41 }
42
43
44 void MemoryBrowserWindow::RefreshContents(void)
45 {
46         char string[1024], buf[64];
47         QString memDump;
48
49         for(uint32_t i=0; i<480; i+=16)
50         {
51                 sprintf(string, "%s%06X: ", (i != 0 ? "<br>" : ""), memBase + i);
52
53                 for(uint32_t j=0; j<16; j++)
54                 {
55                         sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);
56                         strcat(string, buf);
57                 }
58
59                 sprintf(buf, "| ");
60                 strcat(string, buf);
61
62                 for(uint32_t j=0; j<16; j++)
63                 {
64                         uint8_t c = jaguarMainRAM[memBase + i + j];
65                         sprintf(buf, "&#%i;", c);
66
67                         if (c == 0x20)
68                                 sprintf(buf, "&nbsp;");
69
70                         if ((c < 0x20) || ((c > 0x7F) && (c < 0xA0)))
71                                 sprintf(buf, ".");
72
73                         strcat(string, buf);
74                 }
75
76                 memDump += QString(string);
77         }
78
79         text->clear();
80         text->setText(memDump);
81 }
82
83
84 void MemoryBrowserWindow::keyPressEvent(QKeyEvent * e)
85 {
86         if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
87                 hide();
88         else if (e->key() == Qt::Key_PageUp)
89         {
90                 memBase -= 480;
91
92                 if (memBase < 0)
93                         memBase = 0;
94
95                 RefreshContents();
96         }
97         else if (e->key() == Qt::Key_PageDown)
98         {
99                 memBase += 480;
100
101                 if (memBase > (0x200000 - 480))
102                         memBase = 0x200000 - 480;
103
104                 RefreshContents();
105         }
106         else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
107         {
108                 memBase -= 16;
109
110                 if (memBase < 0)
111                         memBase = 0;
112
113                 RefreshContents();
114         }
115         else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
116         {
117                 memBase += 16;
118
119                 if (memBase > (0x200000 - 480))
120                         memBase = 0x200000 - 480;
121
122                 RefreshContents();
123         }
124 }