2 // m68kDasmWin.cpp - M68K disassembly window
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -------------------------------------------------------------
10 // JPM 06/27/2016 Created this file
11 // JPM 12/04/2016 Suport ELF debug information
12 // JPM Replacing the ELF support by the debugger information manager calls
19 #include "debugger\m68kDasmWin.h"
21 #include "m68000/m68kinterface.h"
25 //#include "ELFManager.h"
26 #include "DBGManager.h"
27 //extern jaguarRunAddress;
31 m68KDasmWindow::m68KDasmWindow(QWidget
* parent
/*= 0*/): QWidget(parent
, Qt::Dialog
),
32 layout(new QVBoxLayout
), text(new QTextBrowser
),
33 // layout(new QTabWidget), text(new QLabel),
35 refresh(new QPushButton(tr("Refresh"))),
36 address(new QLineEdit
),
37 go(new QPushButton(tr("Go"))),
42 // m68kDasmWindow *m68kDasmWin = new m68kDasmWindow();
43 // setWindowTitle(tr("Jaguar Disassembly Window"));
44 // layout->addTab(new m68KDasmWindow(), tr("M68K Disassembly"));
45 //layout = new QTabWidget;
49 address
->setInputMask("hhhhhh");
50 QHBoxLayout
* hbox1
= new QHBoxLayout
;
51 hbox1
->addWidget(refresh
);
52 hbox1
->addWidget(address
);
56 // Need to set the size as well...
59 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
60 // QFont fixedFont("", 8, QFont::Normal);
61 fixedFont
.setStyleHint(QFont::Monospace
); //TypeWriter
62 fixedFont
.setLetterSpacing(QFont::PercentageSpacing
, 100);
63 text
->setFont(fixedFont
);
64 // text->setStyleSheet("background-color: DeepSkyBlue;");
65 //// layout->setSizeConstraint(QLayout::SetFixedSize);
68 layout
->addWidget(text
);
69 // layout->addWidget(refresh);
71 layout
->addLayout(hbox1
);
75 connect(refresh
, SIGNAL(clicked()), this, SLOT(RefreshContents()));
76 connect(go
, SIGNAL(clicked()), this, SLOT(GoToAddress()));
82 void m68KDasmWindow::RefreshContents(void)
86 char buffer
[1024], string
[1024], adresse
[16];
87 size_t pc
= memBase
, oldpc
;
88 size_t m68kPC
= m68k_get_reg(NULL
, M68K_REG_PC
);
89 char *Symbol
= NULL
, *LineSrc
, *CurrentLineSrc
= NULL
;
90 bool m68kPCShow
= false;
91 bool constant
, adr
, equal
, Error
;
93 size_t nbr
= vjs
.nbrdisasmlines
;
94 char *PtrFullSource
, *CurrentPtrFullSource
= (char *)calloc(1, 1);
95 size_t NumLine
; // , CurrentNumLine = 0;
96 // size_t CurrentNumLine = DBGManager_GetNumLineFromAdr(pc, DBG_NO_TAG) - 1;
97 size_t CurrentNumLine
;
98 char singleCharString
[2] = { 0, 0 };
102 for (i
= 0; i
< nbr
; i
++)
105 // WriteLog("%06X: %s\n", oldpc, buffer);
106 adr
= constant
= equal
= false;
108 // Display source filename based on the program address
109 if (vjs
.displayFullSourceFilename
&& (PtrFullSource
= DBGManager_GetFullSourceFilenameFromAdr(oldpc
, &Error
)) && strcmp(CurrentPtrFullSource
, PtrFullSource
))
112 if (strcmp(OldPtrFullSource
, PtrFullSource
))
119 s
+= QString("<br>");
122 CurrentNumLine
= DBGManager_GetNumLineFromAdr(pc
, DBG_NO_TAG
) - 1;
124 CurrentPtrFullSource
= (char *)realloc(CurrentPtrFullSource
, strlen(PtrFullSource
) + 1);
125 strcpy(CurrentPtrFullSource
, PtrFullSource
);
128 sprintf(string
, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource
);
132 sprintf(string
, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource
);
134 s
+= QString(string
);
138 // Display line number based on the program address
139 if ((NumLine
= DBGManager_GetNumLineFromAdr(oldpc
, DBG_NO_TAG
)) && ((signed)NumLine
> (signed)CurrentNumLine
))
141 if ((signed)CurrentNumLine
< 0)
143 CurrentNumLine
= NumLine
- 1;
145 sprintf(string
, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine
); // (CurrentNumLine = NumLine));
149 sprintf(string
, "| | ");
151 s
+= QString(string
);
153 // Display line source based on the program address
154 if (((signed)CurrentNumLine
> 0) && (LineSrc
= DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc
, CurrentNumLine
)) && (LineSrc
!= CurrentLineSrc
))
156 sprintf(string
, "<font color='#006400'>%s</font><br>", (CurrentLineSrc
= LineSrc
));
157 s
+= QString(string
);
162 // Display symbol, or line source, based on the program address
163 if (!CurrentLineSrc
&& !Symbol
&& (Symbol
= DBGManager_GetSymbolnameFromAdr(oldpc
)))
165 sprintf(string
, "%s:<br>", Symbol
);
166 s
+= QString(string
);
169 // Display the assembly line based on the current PC
172 pc
+= m68k_disassemble(buffer
, (unsigned int)pc
, 0, vjs
.disasmopcodes
);
176 sprintf(string
, "-> %06X: %s<br>", (unsigned int)oldpc
, buffer
);
181 sprintf(string
, " %06X: %s<br>", (unsigned int)oldpc
, buffer
);
184 buffer
[0] = 0; // Clear string
185 //char singleCharString[2] = { 0, 0 };
187 for (j
= 0; j
< strlen(string
); j
++)
189 if (string
[j
] == ' ')
191 strcat(buffer
, " ");
192 adr
= constant
= false;
207 constant
= adr
= equal
= false;
215 if (!constant
&& adr
&& !equal
)
221 adresse
[l
++] = string
[++j
];
222 } while ((string
[(j
+ 1)] >= '0') && (string
[(j
+ 1)] <= '9') || (string
[(j
+ 1)] >= 'A') && (string
[(j
+ 1)] <= 'F'));
225 if (Symbol
= DBGManager_GetSymbolnameFromAdr(strtoul(adresse
, &p
, 16)))
227 strcat(buffer
, Symbol
);
232 strcat(buffer
, adresse
);
239 singleCharString
[0] = string
[j
];
240 strcat(buffer
, singleCharString
);
246 // s += QString(string);
247 s
+= QString(buffer
);
248 // text->setStyleSheet("QLabel { background-color : red; color : blue; }");
265 free(CurrentPtrFullSource
);
270 void m68KDasmWindow::keyPressEvent(QKeyEvent
* e
)
272 // if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
275 else if (e
->key() == Qt::Key_PageUp
)
284 else if (e
->key() == Qt::Key_PageDown
)
288 if (memBase
> (0xF00000 - 64))
289 memBase
= 0xF00000 - 64;
293 else if (e
->key() == Qt::Key_Up
|| e
->key() == Qt::Key_Minus
)
302 else if (e
->key() == Qt::Key_Down
|| e
->key() == Qt::Key_Equal
)
306 if (memBase
> (0xF00000 - 64))
307 memBase
= 0xF00000 - 64;
316 // Set mem base PC address using the 68K pc current address
317 void m68KDasmWindow::Use68KPCAddress(void)
319 memBase
= m68k_get_reg(NULL
, M68K_REG_PC
);
323 // Set mem base PC address
324 void m68KDasmWindow::SetAddress(int address
)
327 // RefreshContents();
331 // Set mem base PC address based on user interaction
333 void m68KDasmWindow::GoToAddress(void)
337 QString newAddress
= address
->text();
338 memBase
= newAddress
.toUInt(&ok
, 16);