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