]> Shamusworld >> Repos - virtualjaguar/blob - src/gui/debug/m68kdasmbrowser.cpp
Added RISC disassembly browser.
[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         memBase(0x4000)
29 {
30         setWindowTitle(tr("M68K Disassembly Browser"));
31
32         // Need to set the size as well...
33 //      resize(560, 480);
34
35         QFont fixedFont("Lucida Console", 8, QFont::Normal);
36         text->setFont(fixedFont);
37 ////    layout->setSizeConstraint(QLayout::SetFixedSize);
38         setLayout(layout);
39
40         layout->addWidget(text);
41         layout->addWidget(refresh);
42
43         connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents()));
44 }
45
46
47 void M68KDasmBrowserWindow::RefreshContents(void)
48 {
49         char string[1024];//, buf[64];
50         QString s;
51
52         char buffer[2048];
53         int pc = memBase, oldpc;
54
55         for(uint32_t i=0; i<32; i++)
56         {
57                 oldpc = pc;
58                 pc += m68k_disassemble(buffer, pc, 0);
59 //              WriteLog("%06X: %s\n", oldpc, buffer);
60                 sprintf(string, "%06X: %s<br>", oldpc, buffer);
61
62                 buffer[0] = 0;  // Clear string
63                 char singleCharString[2] = { 0, 0 };
64
65                 for(int j=0; j<strlen(string); j++)
66                 {
67                         if (string[j] == 32)
68                                 strcat(buffer, "&nbsp;");
69                         else
70                         {
71                                 singleCharString[0] = string[j];
72                                 strcat(buffer, singleCharString);
73                         }
74                 }
75
76 //              s += QString(string);
77                 s += QString(buffer);
78         }
79
80         text->clear();
81         text->setText(s);
82 }
83
84
85 void M68KDasmBrowserWindow::keyPressEvent(QKeyEvent * e)
86 {
87         if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
88                 hide();
89 #if 1
90         else if (e->key() == Qt::Key_PageUp)
91         {
92                 memBase -= 480;
93
94                 if (memBase < 0)
95                         memBase = 0;
96
97                 RefreshContents();
98         }
99         else if (e->key() == Qt::Key_PageDown)
100         {
101                 memBase += 480;
102
103                 if (memBase > (0x200000 - 480))
104                         memBase = 0x200000 - 480;
105
106                 RefreshContents();
107         }
108         else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus)
109         {
110                 memBase -= 16;
111
112                 if (memBase < 0)
113                         memBase = 0;
114
115                 RefreshContents();
116         }
117         else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal)
118         {
119                 memBase += 16;
120
121                 if (memBase > (0x200000 - 480))
122                         memBase = 0x200000 - 480;
123
124                 RefreshContents();
125         }
126 #endif
127 }