]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/debug/riscdasmbrowser.cpp
194bb110c577ecf84e074b14eaec6a01c4359548
[virtualjaguar] / src / gui / debug / riscdasmbrowser.cpp
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
43         // Need to set the size as well...
44 //      resize(560, 480);
45
46         QFont fixedFont("Lucida Console", 8, QFont::Normal);
47         text->setFont(fixedFont);
48 ////    layout->setSizeConstraint(QLayout::SetFixedSize);
49         setLayout(layout);
50
51         layout->addWidget(text);
52 //      layout->addWidget(refresh);
53         layout->addLayout(hbox1);
54
55         connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
56         connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress()));
57 }
58
59
60 void RISCDasmBrowserWindow::RefreshContents(void)
61 {
62         char string[1024];//, buf[64];
63         QString s;
64
65         char buffer[2048];
66         int pc = memBase, oldpc;
67
68         for(uint32_t i=0; i<32; i++)
69         {
70                 oldpc = pc;
71                 pc += dasmjag(JAGUAR_GPU, buffer, pc);
72                 sprintf(string, "%06X: %s<br>", oldpc, buffer);
73
74                 buffer[0] = 0;  // Clear string
75                 char singleCharString[2] = { 0, 0 };
76
77                 for(uint j=0; j<strlen(string); j++)
78                 {
79                         if (string[j] == 32)
80                                 strcat(buffer, "&nbsp;");
81                         else
82                         {
83                                 singleCharString[0] = string[j];
84                                 strcat(buffer, singleCharString);
85                         }
86                 }
87
88                 s += QString(buffer);
89         }
90
91         text->clear();
92         text->setText(s);
93 }
94
95
96 void RISCDasmBrowserWindow::keyPressEvent(QKeyEvent * e)
97 {
98         if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
99                 hide();
100 #if 1
101         else if (e->key() == Qt::Key_PageUp)
102         {
103                 memBase -= 64;
104
105                 if (memBase < 0)
106                         memBase = 0;
107
108                 RefreshContents();
109         }
110         else if (e->key() == Qt::Key_PageDown)
111         {
112                 memBase += 64;
113
114                 if (memBase > (0x1000000 - 480))
115                         memBase = 0x1000000 - 480;
116
117                 RefreshContents();
118         }
119         else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
120         {
121                 memBase -= 2;
122
123                 if (memBase < 0)
124                         memBase = 0;
125
126                 RefreshContents();
127         }
128         else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
129         {
130                 memBase += 2;
131
132                 if (memBase > (0x1000000 - 480))
133                         memBase = 0x1000000 - 480;
134
135                 RefreshContents();
136         }
137 #endif
138 }
139
140
141 void RISCDasmBrowserWindow::GoToAddress(void)
142 {
143         bool ok;
144         QString newAddress = address->text();
145         memBase = newAddress.toUInt(&ok, 16);
146         RefreshContents();
147 }
148