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
13 // JPM Aug./2020 Display only the code related to the traced function, added different layouts & a status bar, Qt/HTML text format support
20 #include "debugger/m68kDasmWin.h"
21 #include "m68000/m68kinterface.h"
24 #include "DBGManager.h"
29 m68KDasmWindow::m68KDasmWindow(QWidget
* parent
/*= 0*/): QWidget(parent
, Qt::Dialog
),
30 layout(new QVBoxLayout
),
31 #if MD_LAYOUTFILE == 1
32 statusbar(new QStatusBar
),
35 text(new QTextBrowser
),
40 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
41 fixedFont
.setStyleHint(QFont::Monospace
); //TypeWriter
42 fixedFont
.setLetterSpacing(QFont::PercentageSpacing
, 100);
46 text
->setFont(fixedFont
);
47 layout
->addWidget(text
);
51 #if MD_LAYOUTFILE == 1
52 layout
->addWidget(statusbar
);
62 void m68KDasmWindow::RefreshContents(void)
65 char buffer
[1024], string
[1024], adresse
[16];
66 size_t pc
= memBase
, oldpc
;
67 size_t m68kPC
= m68k_get_reg(NULL
, M68K_REG_PC
);
68 size_t m68KPCNbrDisasmLines
= 0;
69 char *Symbol
= NULL
, *LineSrc
, *CurrentLineSrc
= NULL
;
70 bool m68kPCShow
= false;
71 bool constant
, adr
, equal
;
74 size_t nbr
= vjs
.nbrdisasmlines
;
75 char *PtrFullSource
, *CurrentPtrFullSource
= (char *)calloc(1, 1);
76 size_t NumLine
; // , CurrentNumLine = 0;
77 size_t CurrentNumLine
;
78 char singleCharString
[2] = { 0, 0 };
79 #if MD_LAYOUTFILE == 1
85 for (i
= 0; (i
< nbr
) && In
; i
++)
88 adr
= constant
= equal
= false;
90 // Display source filename based on the program address
91 if (vjs
.displayFullSourceFilename
&& (PtrFullSource
= DBGManager_GetFullSourceFilenameFromAdr(oldpc
, &Status
)) && strcmp(CurrentPtrFullSource
, PtrFullSource
))
93 #if defined(MD_LAYOUTFILE)
95 #if MD_LAYOUTFILE != 1
97 // add an empty line for the display of the new filename
109 CurrentNumLine
= DBGManager_GetNumLineFromAdr(pc
, DBG_NO_TAG
) - 1;
110 CurrentPtrFullSource
= (char *)realloc(CurrentPtrFullSource
, strlen(PtrFullSource
) + 1);
111 strcpy(CurrentPtrFullSource
, PtrFullSource
);
112 #if defined(MD_LAYOUTFILE)
115 // Referenced filename doesn't exist
116 sprintf(string
, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource
);
117 #if MD_LAYOUTFILE == 1
118 // Display status bar
119 if ((Status
& DBGSTATUS_OUTDATEDFILE
))
121 statusbar
->setStyleSheet("background-color: lightyellow; font: bold");
122 statusbar
->showMessage(QString("Outdated source file"));
126 statusbar
->setStyleSheet("background-color: tomato; font: bold");
127 statusbar
->showMessage(QString("Unavailable source file"));
133 // Referenced filename does exist
134 sprintf(string
, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource
);
135 #if MD_LAYOUTFILE == 1
136 // Display status bar
137 statusbar
->setStyleSheet("background-color: transparent; font: bold");
138 statusbar
->showMessage(QString(""));
142 s
+= QString(string
);
148 // Display line number based on the program address
149 if ((NumLine
= DBGManager_GetNumLineFromAdr(oldpc
, DBG_NO_TAG
)) && ((signed)NumLine
> (signed)CurrentNumLine
) && !Status
)
151 #if MD_LAYOUTFILE != 1
152 if ((signed)CurrentNumLine
< 0)
154 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
))
169 // add a color on the line text
170 sprintf(string
, "<font color='#006400'>%s</font><br>", (CurrentLineSrc
= LineSrc
));
171 s
+= QString(string
);
173 // add a color on the line text with HTML encoding
174 s
+= QString("<font color='#006400'>");
175 s
+= QString(QString((CurrentLineSrc
= LineSrc
)).toHtmlEscaped());
176 s
+= QString("</font><br>");
182 // Display symbol, or line source, based on the program address
183 if (!CurrentLineSrc
&& !Symbol
&& (Symbol
= DBGManager_GetSymbolNameFromAdr(oldpc
)))
185 sprintf(string
, "%s:<br>", Symbol
);
186 s
+= QString(string
);
189 // Display the assembly line based on the current PC
192 pc
+= m68k_disassemble(buffer
, (unsigned int)pc
, 0, vjs
.disasmopcodes
);
196 sprintf(string
, "-> <u>%06X: %s</u><br>", (unsigned int)oldpc
, buffer
);
198 m68KPCNbrDisasmLines
= i
;
202 sprintf(string
, " %06X: %s<br>", (unsigned int)oldpc
, buffer
);
205 buffer
[0] = 0; // Clear string
207 for (j
= 0; j
< strlen(string
); j
++)
209 if (string
[j
] == ' ')
211 strcat(buffer
, " ");
212 adr
= constant
= false;
227 constant
= adr
= equal
= false;
235 if (!constant
&& adr
&& !equal
)
241 adresse
[l
++] = string
[++j
];
242 } while ((string
[(j
+ 1)] >= '0') && (string
[(j
+ 1)] <= '9') || (string
[(j
+ 1)] >= 'A') && (string
[(j
+ 1)] <= 'F'));
245 if (Symbol
= DBGManager_GetSymbolNameFromAdr(strtoul(adresse
, &p
, 16)))
247 strcat(buffer
, Symbol
);
252 strcat(buffer
, adresse
);
259 singleCharString
[0] = string
[j
];
260 strcat(buffer
, singleCharString
);
266 s
+= QString(buffer
);
272 // Display generated text
284 // Set the scrollbar position in accordance of the M68K PC pointer
285 if (m68KPCNbrDisasmLines
> (nbr
/ 2))
287 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->maximum());
291 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->minimum());
294 free(CurrentPtrFullSource
);
298 // Set mem base PC address using the 68K pc current address
299 void m68KDasmWindow::Use68KPCAddress(void)
301 memBase
= m68k_get_reg(NULL
, M68K_REG_PC
);
305 // Set mem base PC address
306 void m68KDasmWindow::SetAddress(int address
)