]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/debug/riscdasmbrowser.cpp
Fix for bad branch handling in OP.
[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 //      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         for(uint32_t i=0; i<32; i++)
70         {
71                 oldpc = pc;
72                 pc += dasmjag(JAGUAR_GPU, buffer, pc);
73                 sprintf(string, "%06X: %s<br>", oldpc, buffer);
74
75                 buffer[0] = 0;  // Clear string
76                 char singleCharString[2] = { 0, 0 };
77
78                 for(uint j=0; j<strlen(string); j++)
79                 {
80                         if (string[j] == 32)
81                                 strcat(buffer, "&nbsp;");
82                         else
83                         {
84                                 singleCharString[0] = string[j];
85                                 strcat(buffer, singleCharString);
86                         }
87                 }
88
89                 s += QString(buffer);
90         }
91
92         text->clear();
93         text->setText(s);
94 }
95
96
97 void RISCDasmBrowserWindow::keyPressEvent(QKeyEvent * e)
98 {
99         if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
100                 hide();
101 #if 1
102         else if (e->key() == Qt::Key_PageUp)
103         {
104                 memBase -= 64;
105
106                 if (memBase < 0)
107                         memBase = 0;
108
109                 RefreshContents();
110         }
111         else if (e->key() == Qt::Key_PageDown)
112         {
113                 memBase += 64;
114
115                 if (memBase > (0x1000000 - 480))
116                         memBase = 0x1000000 - 480;
117
118                 RefreshContents();
119         }
120         else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
121         {
122                 memBase -= 2;
123
124                 if (memBase < 0)
125                         memBase = 0;
126
127                 RefreshContents();
128         }
129         else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
130         {
131                 memBase += 2;
132
133                 if (memBase > (0x1000000 - 480))
134                         memBase = 0x1000000 - 480;
135
136                 RefreshContents();
137         }
138 #endif
139 }
140
141
142 void RISCDasmBrowserWindow::GoToAddress(void)
143 {
144         bool ok;
145         QString newAddress = address->text();
146         memBase = newAddress.toUInt(&ok, 16);
147         RefreshContents();
148 }
149