| 1 | // |
| 2 | // m68kDasmWin.cpp - M68K disassembly window |
| 3 | // |
| 4 | // by Jean-Paul Mari |
| 5 | // |
| 6 | // JPM = Jean-Paul Mari <djipi.mari@gmail.com> |
| 7 | // |
| 8 | // Who When What |
| 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 | // |
| 14 | |
| 15 | // STILL TO DO: |
| 16 | // |
| 17 | |
| 18 | #include <stdlib.h> |
| 19 | #include "debugger\m68kDasmWin.h" |
| 20 | //#include "memory.h" |
| 21 | #include "m68000/m68kinterface.h" |
| 22 | #include "dsp.h" |
| 23 | #include "gpu.h" |
| 24 | //#include "jaguar.h" |
| 25 | //#include "ELFManager.h" |
| 26 | #include "DBGManager.h" |
| 27 | //extern jaguarRunAddress; |
| 28 | #include "settings.h" |
| 29 | |
| 30 | |
| 31 | m68KDasmWindow::m68KDasmWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog), |
| 32 | layout(new QVBoxLayout), text(new QTextBrowser), |
| 33 | // layout(new QTabWidget), text(new QLabel), |
| 34 | #if 0 |
| 35 | refresh(new QPushButton(tr("Refresh"))), |
| 36 | address(new QLineEdit), |
| 37 | go(new QPushButton(tr("Go"))), |
| 38 | #endif |
| 39 | // memBase(0x4000) |
| 40 | memBase(0) |
| 41 | { |
| 42 | // m68kDasmWindow *m68kDasmWin = new m68kDasmWindow(); |
| 43 | // setWindowTitle(tr("Jaguar Disassembly Window")); |
| 44 | // layout->addTab(new m68KDasmWindow(), tr("M68K Disassembly")); |
| 45 | //layout = new QTabWidget; |
| 46 | //layout->QWidget(); |
| 47 | |
| 48 | #if 0 |
| 49 | address->setInputMask("hhhhhh"); |
| 50 | QHBoxLayout * hbox1 = new QHBoxLayout; |
| 51 | hbox1->addWidget(refresh); |
| 52 | hbox1->addWidget(address); |
| 53 | hbox1->addWidget(go); |
| 54 | #endif |
| 55 | |
| 56 | // Need to set the size as well... |
| 57 | // resize(560, 480); |
| 58 | |
| 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); |
| 66 | setLayout(layout); |
| 67 | |
| 68 | layout->addWidget(text); |
| 69 | // layout->addWidget(refresh); |
| 70 | #if 0 |
| 71 | layout->addLayout(hbox1); |
| 72 | #endif |
| 73 | |
| 74 | #if 0 |
| 75 | connect(refresh, SIGNAL(clicked()), this, SLOT(RefreshContents())); |
| 76 | connect(go, SIGNAL(clicked()), this, SLOT(GoToAddress())); |
| 77 | #endif |
| 78 | } |
| 79 | |
| 80 | |
| 81 | // |
| 82 | void m68KDasmWindow::RefreshContents(void) |
| 83 | { |
| 84 | //char ; //, buf[64]; |
| 85 | QString s; |
| 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; |
| 92 | size_t j, i; |
| 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 }; |
| 99 | |
| 100 | text->clear(); |
| 101 | |
| 102 | for (i = 0; i < nbr; i++) |
| 103 | { |
| 104 | oldpc = pc; |
| 105 | // WriteLog("%06X: %s\n", oldpc, buffer); |
| 106 | adr = constant = equal = false; |
| 107 | |
| 108 | // Display source filename based on the program address |
| 109 | if (vjs.displayFullSourceFilename && (PtrFullSource = DBGManager_GetFullSourceFilenameFromAdr(oldpc, &Error)) && strcmp(CurrentPtrFullSource, PtrFullSource)) |
| 110 | { |
| 111 | #if 0 |
| 112 | if (strcmp(OldPtrFullSource, PtrFullSource)) |
| 113 | #endif |
| 114 | { |
| 115 | #if 1 |
| 116 | if (i) |
| 117 | { |
| 118 | nbr++; |
| 119 | s += QString("<br>"); |
| 120 | } |
| 121 | #endif |
| 122 | CurrentNumLine = DBGManager_GetNumLineFromAdr(pc, DBG_NO_TAG) - 1; |
| 123 | nbr++; |
| 124 | CurrentPtrFullSource = (char *)realloc(CurrentPtrFullSource, strlen(PtrFullSource) + 1); |
| 125 | strcpy(CurrentPtrFullSource, PtrFullSource); |
| 126 | if (!Error) |
| 127 | { |
| 128 | sprintf(string, "<font color='#ff0000'><b>%s</b></font><br>", PtrFullSource); |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | sprintf(string, "<font color='#00ff00'><b>%s</b></font><br>", PtrFullSource); |
| 133 | } |
| 134 | s += QString(string); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Display line number based on the program address |
| 139 | if ((NumLine = DBGManager_GetNumLineFromAdr(oldpc, DBG_NO_TAG)) && ((signed)NumLine > (signed)CurrentNumLine)) |
| 140 | { |
| 141 | if ((signed)CurrentNumLine < 0) |
| 142 | { |
| 143 | CurrentNumLine = NumLine - 1; |
| 144 | } |
| 145 | sprintf(string, "| <font color='#006400'>%5u</font> | ", (unsigned int)++CurrentNumLine); // (CurrentNumLine = NumLine)); |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | sprintf(string, "| | "); |
| 150 | } |
| 151 | s += QString(string); |
| 152 | |
| 153 | // Display line source based on the program address |
| 154 | if (((signed)CurrentNumLine > 0) && (LineSrc = DBGManager_GetLineSrcFromNumLineBaseAdr(oldpc, CurrentNumLine)) && (LineSrc != CurrentLineSrc)) |
| 155 | { |
| 156 | sprintf(string, "<font color='#006400'>%s</font><br>", (CurrentLineSrc = LineSrc)); |
| 157 | s += QString(string); |
| 158 | nbr++; |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | // Display symbol, or line source, based on the program address |
| 163 | if (!CurrentLineSrc && !Symbol && (Symbol = DBGManager_GetSymbolnameFromAdr(oldpc))) |
| 164 | { |
| 165 | sprintf(string, "%s:<br>", Symbol); |
| 166 | s += QString(string); |
| 167 | nbr++; |
| 168 | } |
| 169 | // Display the assembly line based on the current PC |
| 170 | else |
| 171 | { |
| 172 | pc += m68k_disassemble(buffer, (unsigned int)pc, 0, vjs.disasmopcodes); |
| 173 | |
| 174 | if (m68kPC == oldpc) |
| 175 | { |
| 176 | sprintf(string, "-> %06X: %s<br>", (unsigned int)oldpc, buffer); |
| 177 | m68kPCShow = true; |
| 178 | } |
| 179 | else |
| 180 | { |
| 181 | sprintf(string, " %06X: %s<br>", (unsigned int)oldpc, buffer); |
| 182 | } |
| 183 | |
| 184 | buffer[0] = 0; // Clear string |
| 185 | //char singleCharString[2] = { 0, 0 }; |
| 186 | |
| 187 | for (j = 0; j < strlen(string); j++) |
| 188 | { |
| 189 | if (string[j] == ' ') |
| 190 | { |
| 191 | strcat(buffer, " "); |
| 192 | adr = constant = false; |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | switch (string[j]) |
| 197 | { |
| 198 | case '#': |
| 199 | constant = true; |
| 200 | break; |
| 201 | |
| 202 | case '$': |
| 203 | adr = true; |
| 204 | break; |
| 205 | |
| 206 | case ',': |
| 207 | constant = adr = equal = false; |
| 208 | break; |
| 209 | |
| 210 | case '=': |
| 211 | equal = true; |
| 212 | break; |
| 213 | } |
| 214 | |
| 215 | if (!constant && adr && !equal) |
| 216 | { |
| 217 | int l = 0; |
| 218 | char *p; |
| 219 | do |
| 220 | { |
| 221 | adresse[l++] = string[++j]; |
| 222 | } while ((string[(j + 1)] >= '0') && (string[(j + 1)] <= '9') || (string[(j + 1)] >= 'A') && (string[(j + 1)] <= 'F')); |
| 223 | adresse[l] = 0; |
| 224 | |
| 225 | if (Symbol = DBGManager_GetSymbolnameFromAdr(strtoul(adresse, &p, 16))) |
| 226 | { |
| 227 | strcat(buffer, Symbol); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | strcat(buffer, "$"); |
| 232 | strcat(buffer, adresse); |
| 233 | } |
| 234 | |
| 235 | adr = false; |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | singleCharString[0] = string[j]; |
| 240 | strcat(buffer, singleCharString); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | Symbol = NULL; |
| 246 | // s += QString(string); |
| 247 | s += QString(buffer); |
| 248 | // text->setStyleSheet("QLabel { background-color : red; color : blue; }"); |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // text->clear(); |
| 254 | |
| 255 | if (m68kPCShow) |
| 256 | { |
| 257 | text->setText(s); |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | Use68KPCAddress(); |
| 262 | RefreshContents(); |
| 263 | } |
| 264 | |
| 265 | free(CurrentPtrFullSource); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | #if 0 |
| 270 | void m68KDasmWindow::keyPressEvent(QKeyEvent * e) |
| 271 | { |
| 272 | // if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Return) |
| 273 | // hide(); |
| 274 | #if 0 |
| 275 | else if (e->key() == Qt::Key_PageUp) |
| 276 | { |
| 277 | memBase -= 64; |
| 278 | |
| 279 | if (memBase < 0) |
| 280 | memBase = 0; |
| 281 | |
| 282 | RefreshContents(); |
| 283 | } |
| 284 | else if (e->key() == Qt::Key_PageDown) |
| 285 | { |
| 286 | memBase += 64; |
| 287 | |
| 288 | if (memBase > (0xF00000 - 64)) |
| 289 | memBase = 0xF00000 - 64; |
| 290 | |
| 291 | RefreshContents(); |
| 292 | } |
| 293 | else if (e->key() == Qt::Key_Up || e->key() == Qt::Key_Minus) |
| 294 | { |
| 295 | memBase -= 16; |
| 296 | |
| 297 | if (memBase < 0) |
| 298 | memBase = 0; |
| 299 | |
| 300 | RefreshContents(); |
| 301 | } |
| 302 | else if (e->key() == Qt::Key_Down || e->key() == Qt::Key_Equal) |
| 303 | { |
| 304 | memBase += 16; |
| 305 | |
| 306 | if (memBase > (0xF00000 - 64)) |
| 307 | memBase = 0xF00000 - 64; |
| 308 | |
| 309 | RefreshContents(); |
| 310 | } |
| 311 | #endif |
| 312 | } |
| 313 | #endif |
| 314 | |
| 315 | |
| 316 | // Set mem base PC address using the 68K pc current address |
| 317 | void m68KDasmWindow::Use68KPCAddress(void) |
| 318 | { |
| 319 | memBase = m68k_get_reg(NULL, M68K_REG_PC); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | // Set mem base PC address |
| 324 | void m68KDasmWindow::SetAddress(int address) |
| 325 | { |
| 326 | memBase = address; |
| 327 | // RefreshContents(); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | // Set mem base PC address based on user interaction |
| 332 | #if 0 |
| 333 | void m68KDasmWindow::GoToAddress(void) |
| 334 | { |
| 335 | bool ok; |
| 336 | |
| 337 | QString newAddress = address->text(); |
| 338 | memBase = newAddress.toUInt(&ok, 16); |
| 339 | RefreshContents(); |
| 340 | } |
| 341 | #endif |