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"
20 #include "m68000/m68kinterface.h"
23 #include "DBGManager.h"
28 m68KDasmWindow::m68KDasmWindow(QWidget
* parent
/*= 0*/): QWidget(parent
, Qt::Dialog
),
29 layout(new QVBoxLayout
), text(new QTextBrowser
),
32 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
33 fixedFont
.setStyleHint(QFont::Monospace
); //TypeWriter
34 fixedFont
.setLetterSpacing(QFont::PercentageSpacing
, 100);
35 text
->setFont(fixedFont
);
38 layout
->addWidget(text
);
43 void m68KDasmWindow::RefreshContents(void)
46 char buffer
[1024], string
[1024], adresse
[16];
47 size_t pc
= memBase
, oldpc
;
48 size_t m68kPC
= m68k_get_reg(NULL
, M68K_REG_PC
);
49 size_t m68KPCNbrDisasmLines
= 0;
50 char *Symbol
= NULL
, *LineSrc
, *CurrentLineSrc
= NULL
;
51 bool m68kPCShow
= false;
52 bool constant
, adr
, equal
, Error
;
54 size_t nbr
= vjs
.nbrdisasmlines
;
55 char *PtrFullSource
, *CurrentPtrFullSource
= (char *)calloc(1, 1);
56 size_t NumLine
; // , CurrentNumLine = 0;
57 size_t CurrentNumLine
;
58 char singleCharString
[2] = { 0, 0 };
60 for (i
= 0; i
< nbr
; i
++)
63 adr
= constant
= equal
= false;
65 // Display source filename based on the program address
66 if (vjs
.displayFullSourceFilename
&& (PtrFullSource
= DBGManager_GetFullSourceFilenameFromAdr(oldpc
, &Error
)) && strcmp(CurrentPtrFullSource
, PtrFullSource
))
69 if (strcmp(OldPtrFullSource
, PtrFullSource
))
78 CurrentNumLine
= DBGManager_GetNumLineFromAdr(pc
, DBG_NO_TAG
) - 1;
80 CurrentPtrFullSource
= (char *)realloc(CurrentPtrFullSource
, strlen(PtrFullSource
) + 1);
81 strcpy(CurrentPtrFullSource
, PtrFullSource
);
84 sprintf(string
, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource
);
88 sprintf(string
, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource
);
94 // Display line number based on the program address
95 if ((NumLine
= DBGManager_GetNumLineFromAdr(oldpc
, DBG_NO_TAG
)) && ((signed)NumLine
> (signed)CurrentNumLine
))
97 if ((signed)CurrentNumLine
< 0)
99 CurrentNumLine
= NumLine
- 1;
101 sprintf(string
, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine
); // (CurrentNumLine = NumLine));
105 sprintf(string
, "| | ");
107 s
+= QString(string
);
109 // Display line source based on the program address
110 if (((signed)CurrentNumLine
> 0) && (LineSrc
= DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc
, CurrentNumLine
)) && (LineSrc
!= CurrentLineSrc
))
112 sprintf(string
, "<font color='#006400'>%s</font><br>", (CurrentLineSrc
= LineSrc
));
113 s
+= QString(string
);
118 // Display symbol, or line source, based on the program address
119 if (!CurrentLineSrc
&& !Symbol
&& (Symbol
= DBGManager_GetSymbolNameFromAdr(oldpc
)))
121 sprintf(string
, "%s:<br>", Symbol
);
122 s
+= QString(string
);
125 // Display the assembly line based on the current PC
128 pc
+= m68k_disassemble(buffer
, (unsigned int)pc
, 0, vjs
.disasmopcodes
);
132 sprintf(string
, "-> <u>%06X: %s</u><br>", (unsigned int)oldpc
, buffer
);
134 m68KPCNbrDisasmLines
= i
;
138 sprintf(string
, " %06X: %s<br>", (unsigned int)oldpc
, buffer
);
141 buffer
[0] = 0; // Clear string
143 for (j
= 0; j
< strlen(string
); j
++)
145 if (string
[j
] == ' ')
147 strcat(buffer
, " ");
148 adr
= constant
= false;
163 constant
= adr
= equal
= false;
171 if (!constant
&& adr
&& !equal
)
177 adresse
[l
++] = string
[++j
];
178 } while ((string
[(j
+ 1)] >= '0') && (string
[(j
+ 1)] <= '9') || (string
[(j
+ 1)] >= 'A') && (string
[(j
+ 1)] <= 'F'));
181 if (Symbol
= DBGManager_GetSymbolNameFromAdr(strtoul(adresse
, &p
, 16)))
183 strcat(buffer
, Symbol
);
188 strcat(buffer
, adresse
);
195 singleCharString
[0] = string
[j
];
196 strcat(buffer
, singleCharString
);
202 s
+= QString(buffer
);
207 // Display generated text
219 // Set the scrollbar position in accordance of the M68K PC pointer
220 if (m68KPCNbrDisasmLines
> (nbr
/ 2))
222 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->maximum());
226 text
->verticalScrollBar()->setValue(text
->verticalScrollBar()->minimum());
229 free(CurrentPtrFullSource
);
233 // Set mem base PC address using the 68K pc current address
234 void m68KDasmWindow::Use68KPCAddress(void)
236 memBase
= m68k_get_reg(NULL
, M68K_REG_PC
);
240 // Set mem base PC address
241 void m68KDasmWindow::SetAddress(int address
)