Commit | Line | Data |
---|---|---|
cf76e892 JPM |
1 | // |
2 | // riscdasmbrowser.cpp - Jaguar RISC disassembly browser | |
3 | // | |
4 | // by James Hammons | |
5 | // (C) 2013 Underground Software | |
6 | // | |
7 | // JLH = James Hammons <jlhamm@acm.org> | |
8 | // | |
9 | // Who When What | |
10 | // --- ---------- ------------------------------------------------------------- | |
11 | // JLH 01/22/2012 Created this file | |
12 | // | |
13 | ||
14 | // STILL TO DO: | |
15 | // | |
16 | ||
17 | #include "riscdasmbrowser.h" | |
18 | //#include "memory.h" | |
19 | #include "dsp.h" | |
20 | #include "gpu.h" | |
21 | #include "jagdasm.h" | |
22 | ||
23 | ||
24 | RISCDasmBrowserWindow::RISCDasmBrowserWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog), | |
25 | // layout(new QVBoxLayout), text(new QTextBrowser), | |
26 | layout(new QVBoxLayout), text(new QLabel), | |
27 | refresh(new QPushButton(tr("Refresh"))), | |
28 | go(new QPushButton(tr("Go"))), | |
29 | address(new QLineEdit), | |
30 | gpu(new QRadioButton(tr("GPU"))), | |
31 | dsp(new QRadioButton(tr("DSP"))), | |
32 | memBase(0x4000) | |
33 | { | |
34 | setWindowTitle(tr("RISC Disassembly Browser")); | |
35 | ||
36 | address->setInputMask("hhhhhh"); | |
37 | QHBoxLayout * hbox1 = new QHBoxLayout; | |
38 | hbox1->addWidget(refresh); | |
39 | hbox1->addWidget(address); | |
40 | hbox1->addWidget(go); | |
41 | ||
42 | // Need to set the size as well... | |
43 | // resize(560, 480); | |
44 | ||
45 | QFont fixedFont("Lucida Console", 8, QFont::Normal); | |
46 | // QFont fixedFont("", 8, QFont::Normal); | |
47 | fixedFont.setStyleHint(QFont::TypeWriter); | |
48 | text->setFont(fixedFont); | |
49 | //// layout->setSizeConstraint(QLayout::SetFixedSize); | |
50 | setLayout(layout); | |
51 | ||
52 | layout->addWidget(text); | |
53 | // layout->addWidget(refresh); | |
54 | layout->addLayout(hbox1); | |
55 | ||
56 | connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents())); | |
57 | connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress())); | |
58 | } | |
59 | ||
60 | ||
61 | void RISCDasmBrowserWindow::RefreshContents(void) | |
62 | { | |
63 | char string[1024];//, buf[64]; | |
64 | QString s; | |
65 | ||
66 | char buffer[2048]; | |
67 | int pc = memBase, oldpc; | |
68 | ||
69 | if (isVisible()) | |
70 | { | |
71 | for (uint32_t i = 0; i < 32; i++) | |
72 | { | |
73 | oldpc = pc; | |
74 | pc += dasmjag(JAGUAR_GPU, buffer, pc); | |
75 | sprintf(string, "%06X: %s<br>", oldpc, buffer); | |
76 | ||
77 | buffer[0] = 0; // Clear string | |
78 | char singleCharString[2] = { 0, 0 }; | |
79 | ||
80 | for (uint j = 0; j < strlen(string); j++) | |
81 | { | |
82 | if (string[j] == 32) | |
83 | strcat(buffer, " "); | |
84 | else | |
85 | { | |
86 | singleCharString[0] = string[j]; | |
87 | strcat(buffer, singleCharString); | |
88 | } | |
89 | } | |
90 | ||
91 | s += QString(buffer); | |
92 | } | |
93 | ||
94 | text->clear(); | |
95 | text->setText(s); | |
96 | } | |
97 | } | |
98 | ||
99 | ||
100 | void RISCDasmBrowserWindow::keyPressEvent(QKeyEvent * e) | |
101 | { | |
102 | if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return) | |
103 | hide(); | |
104 | #if 1 | |
105 | else if (e->key() == Qt::Key_PageUp) | |
106 | { | |
107 | memBase -= 64; | |
108 | ||
109 | if (memBase < 0) | |
110 | memBase = 0; | |
111 | ||
112 | RefreshContents(); | |
113 | } | |
114 | else if (e->key() == Qt::Key_PageDown) | |
115 | { | |
116 | memBase += 64; | |
117 | ||
118 | if (memBase > (0x1000000 - 480)) | |
119 | memBase = 0x1000000 - 480; | |
120 | ||
121 | RefreshContents(); | |
122 | } | |
123 | else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus) | |
124 | { | |
125 | memBase -= 2; | |
126 | ||
127 | if (memBase < 0) | |
128 | memBase = 0; | |
129 | ||
130 | RefreshContents(); | |
131 | } | |
132 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal) | |
133 | { | |
134 | memBase += 2; | |
135 | ||
136 | if (memBase > (0x1000000 - 480)) | |
137 | memBase = 0x1000000 - 480; | |
138 | ||
139 | RefreshContents(); | |
140 | } | |
141 | #endif | |
142 | } | |
143 | ||
144 | ||
145 | void RISCDasmBrowserWindow::GoToAddress(void) | |
146 | { | |
147 | bool ok; | |
148 | QString newAddress = address->text(); | |
149 | memBase = newAddress.toUInt(&ok, 16); | |
150 | RefreshContents(); | |
151 | } | |
152 |