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, 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
),
32 text(new QTextBrowser
),
37 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
38 fixedFont
.setStyleHint(QFont::Monospace
); //TypeWriter
39 fixedFont
.setLetterSpacing(QFont::PercentageSpacing
, 100);
43 text
->setFont(fixedFont
);
44 layout
->addWidget(text
);
53 void m68KDasmWindow::RefreshContents(void)
56 char buffer
[1024], string
[1024], adresse
[16];
57 size_t pc
= memBase
, oldpc
;
58 size_t m68kPC
= m68k_get_reg(NULL
, M68K_REG_PC
);
59 size_t m68KPCNbrDisasmLines
= 0;
60 char *Symbol
= NULL
, *LineSrc
, *CurrentLineSrc
= NULL
;
61 bool m68kPCShow
= false;
62 bool constant
, adr
, equal
, Error
;
64 size_t nbr
= vjs
.nbrdisasmlines
;
65 char *PtrFullSource
, *CurrentPtrFullSource
= (char *)calloc(1, 1);
66 size_t NumLine
; // , CurrentNumLine = 0;
67 size_t CurrentNumLine
;
68 char singleCharString
[2] = { 0, 0 };
69 #if MD_LAYOUTFILE == 1
75 for (i
= 0; (i
< nbr
) && In
; i
++)
78 adr
= constant
= equal
= false;
80 // Display source filename based on the program address
81 if (vjs
.displayFullSourceFilename
&& (PtrFullSource
= DBGManager_GetFullSourceFilenameFromAdr(oldpc
, &Error
)) && strcmp(CurrentPtrFullSource
, PtrFullSource
))
83 #if defined(MD_LAYOUTFILE)
85 #if MD_LAYOUTFILE != 1
87 // add an empty line for the display of the new filename
99 CurrentNumLine
= DBGManager_GetNumLineFromAdr(pc
, DBG_NO_TAG
) - 1;
100 CurrentPtrFullSource
= (char *)realloc(CurrentPtrFullSource
, strlen(PtrFullSource
) + 1);
101 strcpy(CurrentPtrFullSource
, PtrFullSource
);
102 #if defined(MD_LAYOUTFILE)
105 // Referenced filename does exist
106 sprintf(string
, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource
);
110 // Referenced filename doesn't exist
111 sprintf(string
, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource
);
114 s
+= QString(string
);
120 // Display line number based on the program address
121 if ((NumLine
= DBGManager_GetNumLineFromAdr(oldpc
, DBG_NO_TAG
)) && ((signed)NumLine
> (signed)CurrentNumLine
))
123 #if MD_LAYOUTFILE != 1
124 if ((signed)CurrentNumLine
< 0)
126 CurrentNumLine
= NumLine
- 1;
129 sprintf(string
, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine
); // (CurrentNumLine = NumLine));
133 sprintf(string
, "| | ");
135 s
+= QString(string
);
137 // Display line source based on the program address
138 if (((signed)CurrentNumLine
> 0) && (LineSrc
= DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc
, CurrentNumLine
)) && (LineSrc
!= CurrentLineSrc
))
141 // add a color on the line text
142 sprintf(string
, "<font color='#006400'>%s</font><br>", (CurrentLineSrc
= LineSrc
));
143 s
+= QString(string
);
145 // add a color on the line text with HTML encoding
146 s
+= QString("<font color='#006400'>");
147 s
+= QString(QString((CurrentLineSrc
= LineSrc
)).toHtmlEscaped());
148 s
+= QString("</font><br>");
154 // Display symbol, or line source, based on the program address
155 if (!CurrentLineSrc
&& !Symbol
&& (Symbol
= DBGManager_GetSymbolNameFromAdr(oldpc
)))
157 sprintf(string
, "%s:<br>", Symbol
);
158 s
+= QString(string
);
161 // Display the assembly line based on the current PC
164 pc
+= m68k_disassemble(buffer
, (unsigned int)pc
, 0, vjs
.disasmopcodes
);
168 sprintf(string
, "-> <u>%06X: %s</u><br>", (unsigned int)oldpc
, buffer
);
170 m68KPCNbrDisasmLines
= i
;
174 sprintf(string
, " %06X: %s<br>", (unsigned int)oldpc
, buffer
);
177 buffer
[0] = 0; // Clear string
179 for (j
= 0; j
< strlen(string
); j
++)
181 if (string
[j
] == ' ')
183 strcat(buffer
, " ");
184 adr
= constant
= false;
199 constant
= adr
= equal
= false;
207 if (!constant
&& adr
&& !equal
)
213 adresse
[l
++] = string
[++j
];
214 } while ((string
[(j
+ 1)] >= '0') && (string
[(j
+ 1)] <= '9') || (string
[(j
+ 1)] >= 'A') && (string
[(j
+ 1)] <= 'F'));
217 if (Symbol
= DBGManager_GetSymbolNameFromAdr(strtoul(adresse
, &p
, 16)))
219 strcat(buffer
, Symbol
);
224 strcat(buffer
, adresse
);
231 singleCharString
[0] = string
[j
];
232 strcat(buffer
, singleCharString
);
238 s
+= QString(buffer
);
244 // Display generated text
256 // Set the scrollbar position in accordance of the M68K PC pointer
257 if (m68KPCNbrDisasmLines
> (nbr
/ 2))
259 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->maximum());
263 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->minimum());
266 free(CurrentPtrFullSource
);
270 // Set mem base PC address using the 68K pc current address
271 void m68KDasmWindow::Use68KPCAddress(void)
273 memBase
= m68k_get_reg(NULL
, M68K_REG_PC
);
277 // Set mem base PC address
278 void m68KDasmWindow::SetAddress(int address
)