Commit | Line | Data |
---|---|---|
cf76e892 JPM |
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 | // QFont fixedFont("", 8, QFont::Normal); | |
42 | fixedFont.setStyleHint(QFont::TypeWriter); | |
43 | text->setFont(fixedFont); | |
44 | //// layout->setSizeConstraint(QLayout::SetFixedSize); | |
45 | setLayout(layout); | |
46 | ||
47 | layout->addWidget(text); | |
48 | // layout->addWidget(refresh); | |
49 | layout->addLayout(hbox1); | |
50 | ||
51 | connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents())); | |
52 | connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress())); | |
53 | } | |
54 | ||
55 | ||
56 | void MemoryBrowserWindow::RefreshContents(void) | |
57 | { | |
58 | char string[1024], buf[64]; | |
59 | QString memDump; | |
60 | ||
61 | if (isVisible()) | |
62 | { | |
63 | for (uint32_t i = 0; i < 480; i += 16) | |
64 | { | |
65 | sprintf(string, "%s%06X: ", (i != 0 ? "<br>" : ""), memBase + i); | |
66 | ||
67 | for (uint32_t j = 0; j < 16; j++) | |
68 | { | |
69 | sprintf(buf, "%02X ", jaguarMainRAM[memBase + i + j]); | |
70 | strcat(string, buf); | |
71 | } | |
72 | ||
73 | sprintf(buf, "| "); | |
74 | strcat(string, buf); | |
75 | ||
76 | for (uint32_t j = 0; j < 16; j++) | |
77 | { | |
78 | uint8_t c = jaguarMainRAM[memBase + i + j]; | |
79 | sprintf(buf, "&#%i;", c); | |
80 | ||
81 | if (c == 0x20) | |
82 | sprintf(buf, " "); | |
83 | ||
84 | if ((c < 0x20) || (c > 0x7E)) | |
85 | sprintf(buf, "."); | |
86 | ||
87 | strcat(string, buf); | |
88 | } | |
89 | ||
90 | memDump += QString(string); | |
91 | } | |
92 | ||
93 | text->clear(); | |
94 | text->setText(memDump); | |
95 | } | |
96 | } | |
97 | ||
98 | ||
99 | void MemoryBrowserWindow::keyPressEvent(QKeyEvent * e) | |
100 | { | |
101 | if (e->key() == Qt::Key_Escape) | |
102 | hide(); | |
103 | else if (e->key() == Qt::Key_PageUp) | |
104 | { | |
105 | memBase -= 480; | |
106 | ||
107 | if (memBase < 0) | |
108 | memBase = 0; | |
109 | ||
110 | RefreshContents(); | |
111 | } | |
112 | else if (e->key() == Qt::Key_PageDown) | |
113 | { | |
114 | memBase += 480; | |
115 | ||
116 | if (memBase > (0x200000 - 480)) | |
117 | memBase = 0x200000 - 480; | |
118 | ||
119 | RefreshContents(); | |
120 | } | |
121 | else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus) | |
122 | { | |
123 | memBase -= 16; | |
124 | ||
125 | if (memBase < 0) | |
126 | memBase = 0; | |
127 | ||
128 | RefreshContents(); | |
129 | } | |
130 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal) | |
131 | { | |
132 | memBase += 16; | |
133 | ||
134 | if (memBase > (0x200000 - 480)) | |
135 | memBase = 0x200000 - 480; | |
136 | ||
137 | RefreshContents(); | |
138 | } | |
139 | } | |
140 | ||
141 | ||
142 | void MemoryBrowserWindow::GoToAddress(void) | |
143 | { | |
144 | bool ok; | |
145 | QString newAddress = address->text(); | |
146 | memBase = newAddress.toUInt(&ok, 16); | |
147 | RefreshContents(); | |
148 | } | |
149 |