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;
32 m68KDasmWindow::m68KDasmWindow(QWidget
* parent
/*= 0*/): QWidget(parent
, Qt::Dialog
),
33 layout(new QVBoxLayout
), text(new QTextBrowser
),
34 // layout(new QTabWidget), text(new QLabel),
36 refresh(new QPushButton(tr("Refresh"))),
37 address(new QLineEdit
),
38 go(new QPushButton(tr("Go"))),
44 // m68kDasmWindow *m68kDasmWin = new m68kDasmWindow();
45 // setWindowTitle(tr("Jaguar Disassembly Window"));
46 // layout->addTab(new m68KDasmWindow(), tr("M68K Disassembly"));
47 //layout = new QTabWidget;
51 address
->setInputMask("hhhhhh");
52 QHBoxLayout
* hbox1
= new QHBoxLayout
;
53 hbox1
->addWidget(refresh
);
54 hbox1
->addWidget(address
);
58 // Need to set the size as well...
61 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
62 // QFont fixedFont("", 8, QFont::Normal);
63 fixedFont
.setStyleHint(QFont::Monospace
); //TypeWriter
64 fixedFont
.setLetterSpacing(QFont::PercentageSpacing
, 100);
65 text
->setFont(fixedFont
);
66 // sb = layout->text->verticalScrollBar();
67 // text->setStyleSheet("background-color: DeepSkyBlue;");
68 //// layout->setSizeConstraint(QLayout::SetFixedSize);
71 layout
->addWidget(text
);
72 // layout->addWidget(refresh);
74 layout
->addLayout(hbox1
);
78 connect(refresh
, SIGNAL(clicked()), this, SLOT(RefreshContents()));
79 connect(go
, SIGNAL(clicked()), this, SLOT(GoToAddress()));
85 void m68KDasmWindow::RefreshContents(void)
89 char buffer
[1024], string
[1024], adresse
[16];
90 size_t pc
= memBase
, oldpc
;
91 size_t m68kPC
= m68k_get_reg(NULL
, M68K_REG_PC
);
92 size_t m68KPCNbrDisasmLines
= 0;
93 char *Symbol
= NULL
, *LineSrc
, *CurrentLineSrc
= NULL
;
94 bool m68kPCShow
= false;
95 bool constant
, adr
, equal
, Error
;
97 size_t nbr
= vjs
.nbrdisasmlines
;
98 char *PtrFullSource
, *CurrentPtrFullSource
= (char *)calloc(1, 1);
99 size_t NumLine
; // , CurrentNumLine = 0;
100 // size_t CurrentNumLine = DBGManager_GetNumLineFromAdr(pc, DBG_NO_TAG) - 1;
101 size_t CurrentNumLine
;
102 char singleCharString
[2] = { 0, 0 };
106 for (i
= 0; i
< nbr
; i
++)
108 //sb->setValue(sb->maximum());
109 //j = text->verticalScrollBar()->maximum();
110 //text->verticalScrollBar()->setValue(text->verticalScrollBar()->maximum());
111 //if (text->verticalScrollBar()->value())
117 // WriteLog("%06X: %s\n", oldpc, buffer);
118 adr
= constant
= equal
= false;
120 // Display source filename based on the program address
121 if (vjs
.displayFullSourceFilename
&& (PtrFullSource
= DBGManager_GetFullSourceFilenameFromAdr(oldpc
, &Error
)) && strcmp(CurrentPtrFullSource
, PtrFullSource
))
124 if (strcmp(OldPtrFullSource
, PtrFullSource
))
131 s
+= QString("<br>");
134 CurrentNumLine
= DBGManager_GetNumLineFromAdr(pc
, DBG_NO_TAG
) - 1;
136 CurrentPtrFullSource
= (char *)realloc(CurrentPtrFullSource
, strlen(PtrFullSource
) + 1);
137 strcpy(CurrentPtrFullSource
, PtrFullSource
);
140 sprintf(string
, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource
);
144 sprintf(string
, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource
);
146 s
+= QString(string
);
150 // Display line number based on the program address
151 if ((NumLine
= DBGManager_GetNumLineFromAdr(oldpc
, DBG_NO_TAG
)) && ((signed)NumLine
> (signed)CurrentNumLine
))
153 if ((signed)CurrentNumLine
< 0)
155 CurrentNumLine
= NumLine
- 1;
157 sprintf(string
, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine
); // (CurrentNumLine = NumLine));
161 sprintf(string
, "| | ");
163 s
+= QString(string
);
165 // Display line source based on the program address
166 if (((signed)CurrentNumLine
> 0) && (LineSrc
= DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc
, CurrentNumLine
)) && (LineSrc
!= CurrentLineSrc
))
168 sprintf(string
, "<font color='#006400'>%s</font><br>", (CurrentLineSrc
= LineSrc
));
169 s
+= QString(string
);
174 // Display symbol, or line source, based on the program address
175 if (!CurrentLineSrc
&& !Symbol
&& (Symbol
= DBGManager_GetSymbolNameFromAdr(oldpc
)))
177 sprintf(string
, "%s:<br>", Symbol
);
178 s
+= QString(string
);
181 // Display the assembly line based on the current PC
184 pc
+= m68k_disassemble(buffer
, (unsigned int)pc
, 0, vjs
.disasmopcodes
);
188 sprintf(string
, "-> <u>%06X: %s</u><br>", (unsigned int)oldpc
, buffer
);
190 m68KPCNbrDisasmLines
= i
;
194 sprintf(string
, " %06X: %s<br>", (unsigned int)oldpc
, buffer
);
197 buffer
[0] = 0; // Clear string
198 //char singleCharString[2] = { 0, 0 };
200 for (j
= 0; j
< strlen(string
); j
++)
202 if (string
[j
] == ' ')
204 strcat(buffer
, " ");
205 adr
= constant
= false;
220 constant
= adr
= equal
= false;
228 if (!constant
&& adr
&& !equal
)
234 adresse
[l
++] = string
[++j
];
235 } while ((string
[(j
+ 1)] >= '0') && (string
[(j
+ 1)] <= '9') || (string
[(j
+ 1)] >= 'A') && (string
[(j
+ 1)] <= 'F'));
238 if (Symbol
= DBGManager_GetSymbolNameFromAdr(strtoul(adresse
, &p
, 16)))
240 strcat(buffer
, Symbol
);
245 strcat(buffer
, adresse
);
252 singleCharString
[0] = string
[j
];
253 strcat(buffer
, singleCharString
);
259 // s += QString(string);
260 s
+= QString(buffer
);
261 // text->setStyleSheet("QLabel { background-color : red; color : blue; }");
266 // Display generated text
278 // Set the scrollbar position in accordance of the M68K PC pointer
279 if (m68KPCNbrDisasmLines
> (nbr
/ 2))
281 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->maximum());
285 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->minimum());
288 free(CurrentPtrFullSource
);
294 void m68KDasmWindow::keyPressEvent(QKeyEvent
* e
)
296 // if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return)
299 else if (e
->key() == Qt::Key_PageUp
)
308 else if (e
->key() == Qt::Key_PageDown
)
312 if (memBase
> (0xF00000 - 64))
313 memBase
= 0xF00000 - 64;
317 else if (e
->key() == Qt::Key_Up
|| e
->key() == Qt::Key_Minus
)
326 else if (e
->key() == Qt::Key_Down
|| e
->key() == Qt::Key_Equal
)
330 if (memBase
> (0xF00000 - 64))
331 memBase
= 0xF00000 - 64;
340 // Set mem base PC address using the 68K pc current address
341 void m68KDasmWindow::Use68KPCAddress(void)
343 memBase
= m68k_get_reg(NULL
, M68K_REG_PC
);
347 // Set mem base PC address
348 void m68KDasmWindow::SetAddress(int address
)
351 // RefreshContents();
356 // Set mem base PC address based on user interaction
357 void m68KDasmWindow::GoToAddress(void)
361 QString newAddress
= address
->text();
362 memBase
= newAddress
.toUInt(&ok
, 16);