]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/debug/m68kdasmbrowser.cpp
Fix for bad branch handling in OP.
[virtualjaguar] / src / gui / debug / m68kdasmbrowser.cpp
1 //
2 // m68kdasmbrowser.cpp - Jaguar M68K disassembly 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  12/01/2012  Created this file
12 //
13
14 // STILL TO DO:
15 //
16
17 #include "m68kdasmbrowser.h"
18 //#include "memory.h"
19 #include "m68000/m68kinterface.h"
20 #include "dsp.h"
21 #include "gpu.h"
22
23
24 M68KDasmBrowserWindow::M68KDasmBrowserWindow(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         address(new QLineEdit),
29         go(new QPushButton(tr("Go"))),
30         memBase(0x4000)
31 {
32         setWindowTitle(tr("M68K Disassembly Browser"));
33
34         address->setInputMask("hhhhhh");
35         QHBoxLayout * hbox1 = new QHBoxLayout;
36         hbox1->addWidget(refresh);
37         hbox1->addWidget(address);
38         hbox1->addWidget(go);
39
40         // Need to set the size as well...
41 //      resize(560, 480);
42
43         QFont fixedFont("Lucida Console", 8, QFont::Normal);
44 //      QFont fixedFont("", 8, QFont::Normal);
45         fixedFont.setStyleHint(QFont::TypeWriter);
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 M68KDasmBrowserWindow::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 += m68k_disassemble(buffer, pc, 0);
71 //              WriteLog("%06X: %s\n", oldpc, buffer);
72                 sprintf(string, "%06X: %s<br>", oldpc, buffer);
73
74                 buffer[0] = 0;  // Clear string
75                 char singleCharString[2] = { 0, 0 };
76
77                 for(int 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(string);
89                 s += QString(buffer);
90         }
91
92         text->clear();
93         text->setText(s);
94 }
95
96
97 void M68KDasmBrowserWindow::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 > (0xF00000 - 64))
116                         memBase = 0xF00000 - 64;
117
118                 RefreshContents();
119         }
120         else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
121         {
122                 memBase -= 16;
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 += 16;
132
133                 if (memBase > (0xF00000 - 64))
134                         memBase = 0xF00000 - 64;
135
136                 RefreshContents();
137         }
138 #endif
139 }
140
141
142 void M68KDasmBrowserWindow::GoToAddress(void)
143 {
144         bool ok;
145         QString newAddress = address->text();
146         memBase = newAddress.toUInt(&ok, 16);
147         RefreshContents();
148 }
149