]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/debug/memorybrowser.cpp
Added HOSTCC to m68000 Makefile, improvements to M68K disassembler.
[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         address(new QLineEdit),
26         go(new QPushButton(tr("Go"))),
27         memBase(0)
28 {
29         setWindowTitle(tr("Memory Browser"));
30
31         address->setInputMask("hhhhhh");
32         QHBoxLayout * hbox1 = new QHBoxLayout;
33         hbox1->addWidget(refresh);
34         hbox1->addWidget(address);
35         hbox1->addWidget(go);
36
37         // Need to set the size as well...
38 //      resize(560, 480);
39
40         QFont fixedFont("Lucida Console", 8, QFont::Normal);
41         text->setFont(fixedFont);
42 ////    layout->setSizeConstraint(QLayout::SetFixedSize);
43         setLayout(layout);
44
45         layout->addWidget(text);
46 //      layout->addWidget(refresh);
47         layout->addLayout(hbox1);
48
49         connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
50         connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
51 }
52
53
54 void MemoryBrowserWindow::RefreshContents(void)
55 {
56         char string[1024], buf[64];
57         QString memDump;
58
59         for(uint32_t i=0; i<480; i+=16)
60         {
61                 sprintf(string, "%s%06X: ", (i != 0 ? "<br>" : ""), memBase + i);
62
63                 for(uint32_t j=0; j<16; j++)
64                 {
65                         sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]);
66                         strcat(string, buf);
67                 }
68
69                 sprintf(buf, "| ");
70                 strcat(string, buf);
71
72                 for(uint32_t j=0; j<16; j++)
73                 {
74                         uint8_t c = jaguarMainRAM[memBase + i + j];
75                         sprintf(buf, "&#%i;", c);
76
77                         if (c == 0x20)
78                                 sprintf(buf, "&nbsp;");
79
80                         if ((c < 0x20) || ((c > 0x7F) && (c < 0xA0)))
81                                 sprintf(buf, ".");
82
83                         strcat(string, buf);
84                 }
85
86                 memDump += QString(string);
87         }
88
89         text->clear();
90         text->setText(memDump);
91 }
92
93
94 void MemoryBrowserWindow::keyPressEvent(QKeyEvent * e)
95 {
96         if (e->key() == Qt::Key_Escape)
97                 hide();
98         else if (e->key() == Qt::Key_PageUp)
99         {
100                 memBase -= 480;
101
102                 if (memBase < 0)
103                         memBase = 0;
104
105                 RefreshContents();
106         }
107         else if (e->key() == Qt::Key_PageDown)
108         {
109                 memBase += 480;
110
111                 if (memBase > (0x200000 - 480))
112                         memBase = 0x200000 - 480;
113
114                 RefreshContents();
115         }
116         else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
117         {
118                 memBase -= 16;
119
120                 if (memBase < 0)
121                         memBase = 0;
122
123                 RefreshContents();
124         }
125         else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
126         {
127                 memBase += 16;
128
129                 if (memBase > (0x200000 - 480))
130                         memBase = 0x200000 - 480;
131
132                 RefreshContents();
133         }
134 }
135
136
137 void MemoryBrowserWindow::GoToAddress(void)
138 {
139         bool ok;
140         QString newAddress = address->text();
141         memBase = newAddress.toUInt(&ok, 16);
142         RefreshContents();
143 }
144