| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include <stdlib.h> |
| 14 |
#include <stdio.h> |
| 15 |
#include <string.h> |
| 16 |
#include <inttypes.h> |
| 17 |
#include <stdbool.h> |
| 18 |
#include <SDL.h> |
| 19 |
#include "glue.h" |
| 20 |
#include "timing.h" |
| 21 |
#include "disasm.h" |
| 22 |
#include "memory.h" |
| 23 |
#include "video.h" |
| 24 |
#include "cpu/fake6502.h" |
| 25 |
#include "debugger.h" |
| 26 |
#include "debug_server.h" |
| 27 |
#include "dbg_info.h" |
| 28 |
#include "rendertext.h" |
| 29 |
|
| 30 |
static void DEBUGHandleKeyEvent(SDL_Keycode key,int isShift); |
| 31 |
|
| 32 |
static void DEBUGNumber(int x,int y,int n,int w, SDL_Color colour); |
| 33 |
static void DEBUGNumberDec(int x, int y, int n, int w, SDL_Color colour); |
| 34 |
static void DEBUGAddress(int x, int y, int x16Bank, int addr, uint8_t bank, SDL_Color colour); |
| 35 |
static void DEBUGVAddress(int x, int y, int addr, SDL_Color colour); |
| 36 |
|
| 37 |
static void DEBUGRenderData(int y,uint32_t data); |
| 38 |
static int DEBUGRenderZeroPageRegisters(int y); |
| 39 |
static void DEBUGRenderVERAState(int y); |
| 40 |
static int DEBUGRenderRegisters(void); |
| 41 |
static void DEBUGRenderVRAM(int y, int data); |
| 42 |
static void DEBUGRenderCode(int lines,int initialPC); |
| 43 |
static void DEBUGRenderStack(int bytesCount); |
| 44 |
static void DEBUGRenderCmdLine(int x, int width, int height); |
| 45 |
static bool DEBUGEditCmdLine(SDL_Keycode key); |
| 46 |
static void DEBUGBuildCmdLine(char *text); |
| 47 |
static void DEBUGExecCmd(); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
#define DBGKEY_HOME SDLK_F1 |
| 83 |
#define DBGKEY_RESET SDLK_F2 |
| 84 |
#define DBGKEY_RUN SDLK_F5 |
| 85 |
#define DBGKEY_SETBRK SDLK_F9 |
| 86 |
#define DBGKEY_STEP SDLK_F11 |
| 87 |
#define DBGKEY_STEPOVER SDLK_F10 |
| 88 |
#define DBGKEY_BANK_NEXT SDLK_KP_PLUS |
| 89 |
#define DBGKEY_BANK_PREV SDLK_KP_MINUS |
| 90 |
|
| 91 |
#define DBGSCANKEY_BRK SDL_SCANCODE_F12 |
| 92 |
#define DBGSCANKEY_SHOW SDL_SCANCODE_TAB |
| 93 |
|
| 94 |
|
| 95 |
#define DBGMAX_ZERO_PAGE_REGISTERS 16 |
| 96 |
|
| 97 |
#define DDUMP_RAM 0 |
| 98 |
#define DDUMP_VERA 1 |
| 99 |
|
| 100 |
enum DBG_CMD { CMD_DUMP_MEM='m', CMD_DUMP_VERA='v', CMD_DISASM='d', CMD_SET_BANK='b', CMD_SET_REGISTER='r', CMD_FILL_MEMORY='f' }; |
| 101 |
|
| 102 |
|
| 103 |
const SDL_Color col_bkgnd= {0, 0, 0, 255}; |
| 104 |
const SDL_Color col_label= {0, 255, 0, 255}; |
| 105 |
const SDL_Color col_data= {0, 255, 255, 255}; |
| 106 |
const SDL_Color col_highlight= {255, 255, 0, 255}; |
| 107 |
const SDL_Color col_cmdLine= {255, 255, 255, 255}; |
| 108 |
|
| 109 |
const SDL_Color col_directpage= {192, 224, 255, 255}; |
| 110 |
|
| 111 |
const SDL_Color col_vram_tilemap = {0, 255, 255, 255}; |
| 112 |
const SDL_Color col_vram_tiledata = {0, 255, 0, 255}; |
| 113 |
const SDL_Color col_vram_special = {255, 92, 92, 255}; |
| 114 |
const SDL_Color col_vram_other = {128, 128, 128, 255}; |
| 115 |
|
| 116 |
int showDebugOnRender = 0; |
| 117 |
int showFullDisplay = 0; |
| 118 |
int currentPC = -1; |
| 119 |
uint8_t currentPCBank = 0; |
| 120 |
int currentData = 0; |
| 121 |
int currentPCX16Bank = -1; |
| 122 |
int currentX16Bank = -1; |
| 123 |
int currentMode = DMODE_RUN; |
| 124 |
uint32_t debugCPUClocks = 0; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
static bool srcStepActive; |
| 130 |
static bool DEBUGSourceStepContinue(void); |
| 131 |
|
| 132 |
int dumpmode = DDUMP_RAM; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
static int resumeSkipPC = -1; |
| 153 |
static uint8_t resumeSkipBank = 0; |
| 154 |
static uint32_t resumeSkipClock = 0; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
static bool watchpointStopPending = false; |
| 160 |
|
| 161 |
static void DEBUGClearStepBreakPoint(void); |
| 162 |
|
| 163 |
static void DEBUGArmResumeSkip(void) { |
| 164 |
resumeSkipPC = regs.pc; |
| 165 |
resumeSkipBank = regs.k; |
| 166 |
resumeSkipClock = clockticks6502; |
| 167 |
} |
| 168 |
|
| 169 |
struct breakpoint stepBreakPoint = { -1, 0, -1, 0, true }; |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
static debug_owner_t stepOwner = DEBUG_OWNER_COUNT; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
static bool followInterrupts = false; |
| 184 |
static bool breakOnInterrupt = false; |
| 185 |
|
| 186 |
void DEBUGSetFollowInterrupts(bool on) { followInterrupts = on; } |
| 187 |
bool DEBUGGetFollowInterrupts(void) { return followInterrupts; } |
| 188 |
void DEBUGSetBreakOnInterrupt(bool on) { breakOnInterrupt = on; } |
| 189 |
bool DEBUGGetBreakOnInterrupt(void) { return breakOnInterrupt; } |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
static const char *lastStopReason = ""; |
| 198 |
|
| 199 |
void |
| 200 |
DEBUGSetStopReason(const char *reason) |
| 201 |
{ |
| 202 |
lastStopReason = reason ? reason : ""; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
void |
| 217 |
DEBUGAnnounceStop(const char *reason) |
| 218 |
{ |
| 219 |
DEBUGSetStopReason(reason); |
| 220 |
debug_server_notify_stopped(lastStopReason); |
| 221 |
} |
| 222 |
|
| 223 |
const char * |
| 224 |
DEBUGGetStopReason(void) |
| 225 |
{ |
| 226 |
return lastStopReason; |
| 227 |
} |
| 228 |
char cmdLine[64]= ""; |
| 229 |
int currentPosInLine= 0; |
| 230 |
int currentLineLen= 0; |
| 231 |
|
| 232 |
int oldRegisters[DBGMAX_ZERO_PAGE_REGISTERS]; |
| 233 |
char * oldRegChange[DBGMAX_ZERO_PAGE_REGISTERS]; |
| 234 |
int oldRegisterTicks = 0; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
SDL_Renderer *dbgRenderer; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
static int bank_window_of(int addr) { |
| 245 |
if (addr < 0xA000) |
| 246 |
return 0; |
| 247 |
return addr < 0xC000 ? 1 : 2; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
static inline int getCurrentBank(int pc, uint8_t bank) { |
| 255 |
return debug_current_x16_bank(pc, bank); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
static inline bool hitBreakpoint(int pc, uint8_t bank, struct breakpoint bp) { |
| 265 |
|
| 266 |
|
| 267 |
return pc == bp.pc && bank == bp.bank |
| 268 |
&& debug_bank_selector_matches(bp.x16Bank, pc, bank); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
int DEBUGGetCurrentStatus(void) { |
| 281 |
|
| 282 |
SDL_Event event; |
| 283 |
if (currentPC < 0) currentPC = regs.pc; |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
{ |
| 295 |
const bool entered = cpu_irq_take_entered_flag(); |
| 296 |
const bool wasStepping = (currentMode == DMODE_STEP) || (stepBreakPoint.pc >= 0); |
| 297 |
if (entered && (breakOnInterrupt |
| 298 |
|| (followInterrupts && wasStepping && currentMode != DMODE_STOP))) { |
| 299 |
currentPC = regs.pc; |
| 300 |
currentPCBank = regs.k; |
| 301 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 302 |
currentMode = DMODE_STOP; |
| 303 |
stepBreakPoint.pc = -1; |
| 304 |
stepBreakPoint.bank = 0; |
| 305 |
stepBreakPoint.x16Bank = -1; |
| 306 |
srcStepActive = false; |
| 307 |
DEBUGAnnounceStop("interrupt"); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
if (watchpointStopPending) { |
| 315 |
watchpointStopPending = false; |
| 316 |
currentPC = regs.pc; |
| 317 |
currentPCBank = regs.k; |
| 318 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 319 |
|
| 320 |
|
| 321 |
DEBUGAnnounceStop("data breakpoint"); |
| 322 |
} |
| 323 |
|
| 324 |
if (currentMode == DMODE_STEP) { |
| 325 |
if (currentPC != regs.pc || currentPCBank != regs.k || currentPCX16Bank != getCurrentBank(regs.pc, regs.k)) { |
| 326 |
currentPC = regs.pc; |
| 327 |
currentPCBank = regs.k; |
| 328 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
if (!DEBUGSourceStepContinue()) { |
| 334 |
currentMode = DMODE_STOP; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
DEBUGAnnounceStop("step"); |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
const bool cpuAdvanced = (clockticks6502 != resumeSkipClock) && !waiting; |
| 355 |
if (resumeSkipPC >= 0 |
| 356 |
&& (regs.pc != resumeSkipPC || regs.k != resumeSkipBank || cpuAdvanced)) { |
| 357 |
resumeSkipPC = -1; |
| 358 |
} |
| 359 |
const bool stopped = (currentMode == DMODE_STOP); |
| 360 |
const bool justResumed = (resumeSkipPC >= 0); |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
if (!stopped && !justResumed && !waiting) { |
| 374 |
|
| 375 |
|
| 376 |
const bool viaUser = debug_bp_on_arrival(regs.pc, regs.k); |
| 377 |
const bool viaStep = !viaUser && hitBreakpoint(regs.pc, regs.k, stepBreakPoint); |
| 378 |
if (viaUser || viaStep) { |
| 379 |
currentPC = regs.pc; |
| 380 |
currentPCBank = regs.k; |
| 381 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 382 |
DEBUGClearStepBreakPoint(); |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
bool keepStepping = false; |
| 387 |
if (viaUser) |
| 388 |
srcStepActive = false; |
| 389 |
else |
| 390 |
keepStepping = DEBUGSourceStepContinue(); |
| 391 |
if (!keepStepping) { |
| 392 |
currentMode = DMODE_STOP; |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
DEBUGAnnounceStop(viaStep ? "step" : "breakpoint"); |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
|
| 402 |
if (SDL_GetKeyboardState(NULL)[DBGSCANKEY_BRK]) { |
| 403 |
const bool wasRunning = (currentMode != DMODE_STOP); |
| 404 |
currentMode = DMODE_STOP; |
| 405 |
srcStepActive = false; |
| 406 |
DEBUGSetStopReason("user"); |
| 407 |
currentPC = regs.pc; |
| 408 |
currentPCBank = regs.k; |
| 409 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 410 |
if (wasRunning) { |
| 411 |
DEBUGAnnounceStop("pause"); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
if (currentPCX16Bank < 0) { |
| 421 |
currentPCX16Bank = debug_current_x16_bank(currentPC, currentPCBank); |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
const bool imguiOwnsUI = (!debug_window_enabled && video_debug_ui_available()); |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
if (currentMode != DMODE_RUN) { |
| 443 |
debug_server_poll(); |
| 444 |
if (currentMode == DMODE_RUN || currentMode == DMODE_STEP) { |
| 445 |
return 0; |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
if (currentMode == DMODE_STOP && imguiOwnsUI) { |
| 457 |
showDebugOnRender = 0; |
| 458 |
return video_debug_ui_pump_paused(); |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
if (currentMode != DMODE_RUN && !imguiOwnsUI) { |
| 469 |
showFullDisplay = |
| 470 |
SDL_GetKeyboardState(NULL)[DBGSCANKEY_SHOW]; |
| 471 |
while (SDL_PollEvent(&event)) { |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
if (video_debug_ui_available()) { |
| 480 |
video_debug_ui_feed_event(&event); |
| 481 |
|
| 482 |
|
| 483 |
if (video_event_targets_debug_ui(&event)) { |
| 484 |
if (event.type == SDL_WINDOWEVENT && |
| 485 |
event.window.event == SDL_WINDOWEVENT_CLOSE) { |
| 486 |
continue; |
| 487 |
} |
| 488 |
video_debug_ui_shortcut_key(&event); |
| 489 |
continue; |
| 490 |
} |
| 491 |
} |
| 492 |
switch(event.type) { |
| 493 |
case SDL_QUIT: |
| 494 |
return -1; |
| 495 |
|
| 496 |
case SDL_WINDOWEVENT: |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
if (event.window.event == SDL_WINDOWEVENT_CLOSE) { |
| 503 |
return -1; |
| 504 |
} |
| 505 |
break; |
| 506 |
|
| 507 |
case SDL_KEYDOWN: |
| 508 |
DEBUGHandleKeyEvent(event.key.keysym.sym, event.key.keysym.mod & (KMOD_LSHIFT|KMOD_RSHIFT)); |
| 509 |
break; |
| 510 |
|
| 511 |
case SDL_TEXTINPUT: |
| 512 |
DEBUGBuildCmdLine(event.text.text); |
| 513 |
break; |
| 514 |
} |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
showDebugOnRender = (currentMode != DMODE_RUN); |
| 519 |
if (currentMode == DMODE_STOP) { |
| 520 |
video_update(); |
| 521 |
SDL_Delay(10); |
| 522 |
return 1; |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
{ |
| 530 |
static int poll_counter = 0; |
| 531 |
if (++poll_counter >= 1000) { |
| 532 |
poll_counter = 0; |
| 533 |
if (debug_server_poll()) { |
| 534 |
return (currentMode == DMODE_STOP) ? 1 : 0; |
| 535 |
} |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
return 0; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
void DEBUGInitUI(SDL_Renderer *pRenderer) { |
| 548 |
DEBUGInitChars(pRenderer); |
| 549 |
dbgRenderer = pRenderer; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
void DEBUGFreeUI() { |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
void DEBUGBreakToDebugger(void) { |
| 567 |
const bool wasRunning = (currentMode != DMODE_STOP); |
| 568 |
srcStepActive = false; |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
DEBUGSetStopReason("user"); |
| 574 |
currentMode = DMODE_STOP; |
| 575 |
currentPC = regs.pc; |
| 576 |
currentPCBank = regs.k; |
| 577 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
if (wasRunning) { |
| 583 |
DEBUGAnnounceStop("pause"); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
void DEBUGBreakOnWatchpoint(void) { |
| 600 |
if (currentMode != DMODE_STOP) { |
| 601 |
currentMode = DMODE_STOP; |
| 602 |
watchpointStopPending = true; |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
static void DEBUGClearStepBreakPoint(void) { |
| 620 |
|
| 621 |
stepOwner = DEBUG_OWNER_COUNT; |
| 622 |
stepBreakPoint.pc = -1; |
| 623 |
stepBreakPoint.bank = 0; |
| 624 |
stepBreakPoint.x16Bank = -1; |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
#define SRC_STEP_MAX_INSNS 500000 |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
static bool srcStepOver = false; |
| 646 |
static debug_owner_t srcStepOwner = DEBUG_OWNER_UI; |
| 647 |
static char srcStepFile[260]; |
| 648 |
static int srcStepLine = -1; |
| 649 |
static uint16_t srcStepSP = 0; |
| 650 |
static long srcStepBudget = 0; |
| 651 |
static bool sourceStepPref = true; |
| 652 |
|
| 653 |
void DEBUGSetSourceStep(bool on) { sourceStepPref = on; } |
| 654 |
bool DEBUGGetSourceStep(void) { return sourceStepPref; } |
| 655 |
|
| 656 |
|
| 657 |
static bool debug_line_at_pc(char *file, size_t size, int *line) |
| 658 |
{ |
| 659 |
const char *f = NULL; |
| 660 |
int l = 0; |
| 661 |
if (!dbg_info_addr_to_source_banked(regs.pc, (int)memory_get_ram_bank(), &f, &l) || !f) |
| 662 |
return false; |
| 663 |
snprintf(file, size, "%s", f); |
| 664 |
*line = l; |
| 665 |
return true; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
static bool debug_source_step_available(void) |
| 673 |
{ |
| 674 |
if (!sourceStepPref || !dbg_info_has_high_level()) |
| 675 |
return false; |
| 676 |
char f[260]; |
| 677 |
int l = 0; |
| 678 |
return debug_line_at_pc(f, sizeof f, &l); |
| 679 |
} |
| 680 |
|
| 681 |
void DEBUGCancelSourceStep(void) { srcStepActive = false; } |
| 682 |
|
| 683 |
static void DEBUGBeginSourceStep(bool over, debug_owner_t owner) |
| 684 |
{ |
| 685 |
srcStepActive = false; |
| 686 |
if (!debug_line_at_pc(srcStepFile, sizeof srcStepFile, &srcStepLine)) { |
| 687 |
if (over) DEBUGStepOver(owner); else DEBUGStepInto(); |
| 688 |
return; |
| 689 |
} |
| 690 |
srcStepOver = over; |
| 691 |
srcStepOwner = owner; |
| 692 |
srcStepSP = regs.sp; |
| 693 |
srcStepBudget = SRC_STEP_MAX_INSNS; |
| 694 |
srcStepActive = true; |
| 695 |
if (over) DEBUGStepOver(owner); else DEBUGStepInto(); |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
static bool DEBUGSourceStepContinue(void) |
| 702 |
{ |
| 703 |
if (!srcStepActive) |
| 704 |
return false; |
| 705 |
|
| 706 |
if (--srcStepBudget <= 0) { |
| 707 |
srcStepActive = false; |
| 708 |
return false; |
| 709 |
} |
| 710 |
|
| 711 |
char f[260]; |
| 712 |
int l = 0; |
| 713 |
if (!debug_line_at_pc(f, sizeof f, &l)) { |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
if (regs.sp < srcStepSP) { |
| 720 |
DEBUGStepOut(srcStepOwner); |
| 721 |
return true; |
| 722 |
} |
| 723 |
srcStepActive = false; |
| 724 |
return false; |
| 725 |
} |
| 726 |
|
| 727 |
if (l == srcStepLine && strcmp(f, srcStepFile) == 0) { |
| 728 |
if (srcStepOver) DEBUGStepOver(srcStepOwner); else DEBUGStepInto(); |
| 729 |
return true; |
| 730 |
} |
| 731 |
|
| 732 |
srcStepActive = false; |
| 733 |
return false; |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
void DEBUGStepIntoAuto(void) |
| 739 |
{ |
| 740 |
if (debug_source_step_available()) |
| 741 |
DEBUGBeginSourceStep(false, DEBUG_OWNER_UI); |
| 742 |
else |
| 743 |
DEBUGStepInto(); |
| 744 |
} |
| 745 |
|
| 746 |
void DEBUGStepOverAuto(debug_owner_t owner) |
| 747 |
{ |
| 748 |
if (debug_source_step_available()) |
| 749 |
DEBUGBeginSourceStep(true, owner); |
| 750 |
else |
| 751 |
DEBUGStepOver(owner); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
void DEBUGCancelStep(void) { |
| 757 |
srcStepActive = false; |
| 758 |
DEBUGClearStepBreakPoint(); |
| 759 |
} |
| 760 |
|
| 761 |
debug_owner_t DEBUGStepOwner(void) { |
| 762 |
return stepBreakPoint.pc < 0 ? DEBUG_OWNER_COUNT : stepOwner; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
bool DEBUGCancelStepFor(debug_owner_t owner) { |
| 773 |
if (DEBUGStepOwner() != owner) |
| 774 |
return false; |
| 775 |
DEBUGClearStepBreakPoint(); |
| 776 |
return true; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
void DEBUGContinue(void) { |
| 788 |
srcStepActive = false; |
| 789 |
DEBUGClearStepBreakPoint(); |
| 790 |
DEBUGArmResumeSkip(); |
| 791 |
currentMode = DMODE_RUN; |
| 792 |
debugCPUClocks = clockticks6502; |
| 793 |
timing_init(); |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
debug_server_note_resumed(); |
| 798 |
} |
| 799 |
|
| 800 |
void DEBUGStepInto(void) { |
| 801 |
DEBUGArmResumeSkip(); |
| 802 |
currentMode = DMODE_STEP; |
| 803 |
currentPC = regs.pc; |
| 804 |
currentPCBank = regs.k; |
| 805 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 806 |
debugCPUClocks = clockticks6502; |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
debug_server_note_resumed(); |
| 811 |
} |
| 812 |
|
| 813 |
void DEBUGStepOver(debug_owner_t owner) { |
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
int x16Bank = getCurrentBank(regs.pc, regs.k); |
| 818 |
int opcode = debug_read6502(regs.pc, regs.k, x16Bank); |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
const bool is_call = (opcode == 0x20) |
| 824 |
|| (regs.is65c816 && (opcode == 0xFC || opcode == 0x22)); |
| 825 |
if (is_call) { |
| 826 |
const int target = (regs.pc + 3 + (opcode == 0x22)) & 0xFFFF; |
| 827 |
stepBreakPoint.pc = target; |
| 828 |
stepBreakPoint.bank = regs.k; |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
stepBreakPoint.x16Bank = debug_current_x16_bank(target, regs.k); |
| 835 |
stepOwner = owner; |
| 836 |
DEBUGArmResumeSkip(); |
| 837 |
currentMode = DMODE_RUN; |
| 838 |
debugCPUClocks = clockticks6502; |
| 839 |
timing_init(); |
| 840 |
} else { |
| 841 |
DEBUGArmResumeSkip(); |
| 842 |
currentMode = DMODE_STEP; |
| 843 |
currentPC = regs.pc; |
| 844 |
currentPCBank = regs.k; |
| 845 |
currentPCX16Bank = x16Bank; |
| 846 |
debugCPUClocks = clockticks6502; |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
debug_server_note_resumed(); |
| 852 |
} |
| 853 |
|
| 854 |
void DEBUGStepOut(debug_owner_t owner) { |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
bool native = regs.is65c816 && !regs.e; |
| 862 |
uint32_t sp = regs.sp; |
| 863 |
uint32_t start = native ? (sp + 1) : (0x100 + (sp & 0xFF) + 1); |
| 864 |
uint32_t end = native ? (sp + 1 + 256) : 0x200; |
| 865 |
|
| 866 |
int retAddr = -1; |
| 867 |
uint8_t retBank = regs.k; |
| 868 |
for (uint32_t a = start; a + 1 < end; a++) { |
| 869 |
uint8_t lo = debug_read6502((uint16_t)a, 0, -1); |
| 870 |
uint8_t hi = debug_read6502((uint16_t)(a + 1), 0, -1); |
| 871 |
uint16_t pushed = (uint16_t)(lo | (hi << 8)); |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
uint8_t o2 = debug_read6502((uint16_t)(pushed - 2), regs.k, -1); |
| 877 |
if (o2 == 0x20 || (regs.is65c816 && o2 == 0xFC)) { |
| 878 |
retAddr = (pushed + 1) & 0xFFFF; |
| 879 |
break; |
| 880 |
} |
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
if (regs.is65c816 && a + 2 < end) { |
| 889 |
uint8_t callerBank = debug_read6502((uint16_t)(a + 2), 0, -1); |
| 890 |
if (debug_read6502((uint16_t)(pushed - 3), callerBank, -1) == 0x22) { |
| 891 |
retAddr = (pushed + 1) & 0xFFFF; |
| 892 |
retBank = callerBank; |
| 893 |
break; |
| 894 |
} |
| 895 |
} |
| 896 |
} |
| 897 |
|
| 898 |
if (retAddr < 0) { |
| 899 |
|
| 900 |
|
| 901 |
DEBUGStepInto(); |
| 902 |
return; |
| 903 |
} |
| 904 |
|
| 905 |
stepBreakPoint.pc = retAddr; |
| 906 |
stepBreakPoint.bank = retBank; |
| 907 |
stepBreakPoint.x16Bank = getCurrentBank(stepBreakPoint.pc, retBank); |
| 908 |
stepOwner = owner; |
| 909 |
DEBUGArmResumeSkip(); |
| 910 |
currentMode = DMODE_RUN; |
| 911 |
debugCPUClocks = clockticks6502; |
| 912 |
timing_init(); |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
debug_server_note_resumed(); |
| 917 |
} |
| 918 |
|
| 919 |
void DEBUGPause(void) { |
| 920 |
DEBUGBreakToDebugger(); |
| 921 |
} |
| 922 |
|
| 923 |
void DEBUGRunTo(uint16_t pc, uint8_t bank, debug_owner_t owner) { |
| 924 |
srcStepActive = false; |
| 925 |
stepBreakPoint.pc = pc; |
| 926 |
stepBreakPoint.bank = bank; |
| 927 |
stepBreakPoint.x16Bank = getCurrentBank(pc, bank); |
| 928 |
stepOwner = owner; |
| 929 |
DEBUGArmResumeSkip(); |
| 930 |
currentMode = DMODE_RUN; |
| 931 |
debugCPUClocks = clockticks6502; |
| 932 |
timing_init(); |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
debug_server_note_resumed(); |
| 937 |
} |
| 938 |
|
| 939 |
bool DEBUGIsRunning(void) { |
| 940 |
return currentMode == DMODE_RUN; |
| 941 |
} |
| 942 |
|
| 943 |
bool DEBUGIsPaused(void) { |
| 944 |
return currentMode == DMODE_STOP; |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
static void DEBUGHandleKeyEvent(SDL_Keycode key, int isShift) { |
| 955 |
|
| 956 |
switch(key) { |
| 957 |
|
| 958 |
case DBGKEY_STEP: |
| 959 |
if (isShift) { |
| 960 |
DEBUGStepOut(DEBUG_OWNER_UI); |
| 961 |
} else { |
| 962 |
DEBUGStepInto(); |
| 963 |
} |
| 964 |
break; |
| 965 |
|
| 966 |
case DBGKEY_STEPOVER: |
| 967 |
DEBUGStepOver(DEBUG_OWNER_UI); |
| 968 |
break; |
| 969 |
|
| 970 |
case DBGKEY_RUN: |
| 971 |
DEBUGContinue(); |
| 972 |
break; |
| 973 |
|
| 974 |
case DBGKEY_SETBRK: |
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
debug_bp_toggle_for(currentPC, (uint8_t)currentPCBank, currentPCX16Bank, |
| 984 |
DEBUG_OWNER_UI); |
| 985 |
break; |
| 986 |
|
| 987 |
case DBGKEY_HOME: |
| 988 |
currentPC = regs.pc; |
| 989 |
currentPCBank = regs.k; |
| 990 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 991 |
break; |
| 992 |
|
| 993 |
case DBGKEY_RESET: |
| 994 |
reset6502(regs.is65c816); |
| 995 |
currentPC = regs.pc; |
| 996 |
currentPCBank = regs.k; |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
currentPCX16Bank = getCurrentBank(regs.pc, regs.k); |
| 1002 |
break; |
| 1003 |
|
| 1004 |
case DBGKEY_BANK_NEXT: |
| 1005 |
currentX16Bank += 1; |
| 1006 |
break; |
| 1007 |
|
| 1008 |
case DBGKEY_BANK_PREV: |
| 1009 |
currentX16Bank -= 1; |
| 1010 |
break; |
| 1011 |
|
| 1012 |
case SDLK_PAGEDOWN: |
| 1013 |
if (isShift) { |
| 1014 |
currentPC = (currentPC + 0x10) & 0xFFFF; |
| 1015 |
if (currentPCBank == 0 && currentPC < 0xA000) { |
| 1016 |
currentPCX16Bank = -1; |
| 1017 |
} |
| 1018 |
} else { |
| 1019 |
if (dumpmode == DDUMP_RAM) { |
| 1020 |
currentData = (currentData + 0x100) & (is_gen2 ? 0xFFFFFF : 0xFFFF); |
| 1021 |
} else { |
| 1022 |
currentData = (currentData + 0x200) & 0x1FFFF; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
break; |
| 1026 |
|
| 1027 |
case SDLK_PAGEUP: |
| 1028 |
if (isShift) { |
| 1029 |
currentPC = (currentPC - 0x10) & 0xFFFF; |
| 1030 |
if (currentPCBank == 0 && currentPC < 0xA000) { |
| 1031 |
currentPCX16Bank = -1; |
| 1032 |
} |
| 1033 |
} else { |
| 1034 |
if (dumpmode == DDUMP_RAM) { |
| 1035 |
currentData = (currentData - 0x100) & (is_gen2 ? 0xFFFFFF : 0xFFFF); |
| 1036 |
} else { |
| 1037 |
currentData = (currentData - 0x200) & 0x1FFFF; |
| 1038 |
} |
| 1039 |
} |
| 1040 |
break; |
| 1041 |
|
| 1042 |
case SDLK_DOWN: |
| 1043 |
if (isShift) { |
| 1044 |
currentPC = (currentPC + 1) & 0xFFFF; |
| 1045 |
if (currentPCBank == 0 && currentPC < 0xA000) { |
| 1046 |
currentPCX16Bank = -1; |
| 1047 |
} |
| 1048 |
} else { |
| 1049 |
if (dumpmode == DDUMP_RAM) { |
| 1050 |
currentData = (currentData + 0x08) & (is_gen2 ? 0xFFFFFF : 0xFFFF); |
| 1051 |
} else { |
| 1052 |
currentData = (currentData + 0x10) & 0x1FFFF; |
| 1053 |
} |
| 1054 |
} |
| 1055 |
break; |
| 1056 |
|
| 1057 |
case SDLK_UP: |
| 1058 |
if (isShift) { |
| 1059 |
currentPC = (currentPC - 1) & 0xFFFF; |
| 1060 |
if (currentPCBank == 0 && currentPC < 0xA000) { |
| 1061 |
currentPCX16Bank = -1; |
| 1062 |
} |
| 1063 |
} else { |
| 1064 |
if (dumpmode == DDUMP_RAM) { |
| 1065 |
currentData = (currentData - 0x08) & (is_gen2 ? 0xFFFFFF : 0xFFFF); |
| 1066 |
} else { |
| 1067 |
currentData = (currentData - 0x10) & 0x1FFFF; |
| 1068 |
} |
| 1069 |
} |
| 1070 |
break; |
| 1071 |
|
| 1072 |
default: |
| 1073 |
if(DEBUGEditCmdLine(key)) { |
| 1074 |
|
| 1075 |
DEBUGExecCmd(); |
| 1076 |
} |
| 1077 |
break; |
| 1078 |
} |
| 1079 |
|
| 1080 |
} |
| 1081 |
|
| 1082 |
static void DEBUGBuildCmdLine(char *text) { |
| 1083 |
uint8_t *ptr = (uint8_t *)text; |
| 1084 |
while(currentLineLen < sizeof(cmdLine)-1 && *ptr != 0) { |
| 1085 |
if (*ptr < 0x80) { |
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
uint8_t key = *ptr; |
| 1090 |
|
| 1091 |
if (key >= 0x20 && key <= 0x7D) { |
| 1092 |
if (key >= 'A' && key <= 'Z') { |
| 1093 |
key += 0x20; |
| 1094 |
} |
| 1095 |
cmdLine[currentPosInLine++]= key; |
| 1096 |
if(currentPosInLine > currentLineLen) { |
| 1097 |
currentLineLen++; |
| 1098 |
cmdLine[currentLineLen]= 0; |
| 1099 |
} |
| 1100 |
} |
| 1101 |
} |
| 1102 |
ptr++; |
| 1103 |
} |
| 1104 |
} |
| 1105 |
|
| 1106 |
static bool DEBUGEditCmdLine(SDL_Keycode key) { |
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
if(key == SDLK_BACKSPACE) { |
| 1111 |
currentPosInLine--; |
| 1112 |
if(currentPosInLine<0) { |
| 1113 |
currentPosInLine= 0; |
| 1114 |
} |
| 1115 |
currentLineLen--; |
| 1116 |
if(currentLineLen<0) { |
| 1117 |
currentLineLen= 0; |
| 1118 |
} |
| 1119 |
cmdLine[currentLineLen]= 0; |
| 1120 |
} |
| 1121 |
return (key == SDLK_RETURN) || (key == SDLK_KP_ENTER); |
| 1122 |
} |
| 1123 |
|
| 1124 |
static void DEBUGExecCmd() { |
| 1125 |
int number, bnumber, addr, size, incr; |
| 1126 |
char reg[10]; |
| 1127 |
char cmd; |
| 1128 |
char *line= ltrim(cmdLine); |
| 1129 |
|
| 1130 |
cmd= *line; |
| 1131 |
if(*line) { |
| 1132 |
line++; |
| 1133 |
} |
| 1134 |
|
| 1135 |
|
| 1136 |
switch (cmd) { |
| 1137 |
case CMD_DUMP_MEM: |
| 1138 |
if (sscanf(line, "%x:%x", &bnumber, &number) == 2) { |
| 1139 |
currentX16Bank = bnumber & 0xFF; |
| 1140 |
} else if (sscanf(line, "%x", &number) == 1) { |
| 1141 |
if (!is_gen2) { |
| 1142 |
currentX16Bank = (number >> 16) & 0xFF; |
| 1143 |
} |
| 1144 |
} else { |
| 1145 |
break; |
| 1146 |
} |
| 1147 |
addr = number & (is_gen2 ? 0xFFFFFF : 0xFFFF); |
| 1148 |
currentData = addr; |
| 1149 |
dumpmode = DDUMP_RAM; |
| 1150 |
break; |
| 1151 |
|
| 1152 |
case CMD_DUMP_VERA: |
| 1153 |
if (sscanf(line, "%x", &number) == 1) { |
| 1154 |
addr = number & 0x1FFFF; |
| 1155 |
currentData = addr; |
| 1156 |
dumpmode = DDUMP_VERA; |
| 1157 |
} |
| 1158 |
break; |
| 1159 |
|
| 1160 |
case CMD_FILL_MEMORY: |
| 1161 |
size = 1; |
| 1162 |
incr = 1; |
| 1163 |
if (sscanf(line, "%x %x %d %d", &addr, &number, &size, &incr) >= 2) { |
| 1164 |
if (dumpmode == DDUMP_RAM) { |
| 1165 |
addr &= 0xFFFFFF; |
| 1166 |
do { |
| 1167 |
if (addr >= 0xC000 && addr < 0x10000) { |
| 1168 |
|
| 1169 |
} else if (addr >= 0xA000 && addr < 0xC000) { |
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
const int fill_bank = currentX16Bank < 0 |
| 1182 |
? (int)memory_get_ram_bank() |
| 1183 |
: currentX16Bank; |
| 1184 |
if (fill_bank >= 0 && fill_bank < (int)num_ram_banks) { |
| 1185 |
BRAM[(fill_bank << 13) + addr - 0xA000] = number; |
| 1186 |
} |
| 1187 |
} else if ((addr >> 16) < num_banks) { |
| 1188 |
RAM[addr] = number; |
| 1189 |
} |
| 1190 |
if (incr) { |
| 1191 |
addr += incr; |
| 1192 |
} else { |
| 1193 |
++addr; |
| 1194 |
} |
| 1195 |
addr &= 0xFFFFFF; |
| 1196 |
--size; |
| 1197 |
} while (size > 0); |
| 1198 |
} else { |
| 1199 |
addr &= 0x1FFFF; |
| 1200 |
do { |
| 1201 |
video_space_write(addr, number); |
| 1202 |
if (incr) { |
| 1203 |
addr += incr; |
| 1204 |
} else { |
| 1205 |
++addr; |
| 1206 |
} |
| 1207 |
addr &= 0x1FFFF; |
| 1208 |
--size; |
| 1209 |
} while (size > 0); |
| 1210 |
} |
| 1211 |
} |
| 1212 |
break; |
| 1213 |
|
| 1214 |
case CMD_DISASM: |
| 1215 |
if (sscanf(line, "%x:%x", &bnumber, &number) == 2) { |
| 1216 |
currentPCX16Bank = (number >= 0xA000 && number <= 0xFFFF) ? bnumber & 0xFF : -1; |
| 1217 |
} else if (sscanf(line, "%x", &number) == 1) { |
| 1218 |
if (!is_gen2) { |
| 1219 |
currentPCX16Bank = (number & 0xFFFF) >= 0xA000 ? (number >> 16) & 0xFF : -1; |
| 1220 |
} else if (number < 0x00A000 || number >= 0x010000) { |
| 1221 |
currentPCX16Bank = -1; |
| 1222 |
} |
| 1223 |
} else { |
| 1224 |
break; |
| 1225 |
} |
| 1226 |
|
| 1227 |
addr = number & (is_gen2 ? 0xFFFFFF : 0xFFFF); |
| 1228 |
|
| 1229 |
currentPC = addr & 0xFFFF; |
| 1230 |
if (is_gen2) { |
| 1231 |
currentPCBank = (addr >> 16) & 0xFF; |
| 1232 |
} |
| 1233 |
break; |
| 1234 |
|
| 1235 |
case CMD_SET_BANK: |
| 1236 |
if (sscanf(line, "%s %d", reg, &number) != 2) { |
| 1237 |
break; |
| 1238 |
} |
| 1239 |
|
| 1240 |
if (!strcmp(reg, "rom")) { |
| 1241 |
memory_set_rom_bank(number & 0x00FF); |
| 1242 |
} else if (!strcmp(reg, "ram")) { |
| 1243 |
memory_set_ram_bank(number & 0x00FF); |
| 1244 |
} |
| 1245 |
break; |
| 1246 |
|
| 1247 |
case CMD_SET_REGISTER: |
| 1248 |
if (sscanf(line, "%s %x", reg, &number) != 2) { |
| 1249 |
break; |
| 1250 |
} |
| 1251 |
|
| 1252 |
if(!strcmp(reg, "pc")) { |
| 1253 |
regs.pc= number & 0xFFFF; |
| 1254 |
waiting = 0; |
| 1255 |
} |
| 1256 |
if(!strcmp(reg, "a")) { |
| 1257 |
regs.a= number & 0x00FF; |
| 1258 |
} |
| 1259 |
if(!strcmp(reg, "b")) { |
| 1260 |
regs.b= number & 0x00FF; |
| 1261 |
} |
| 1262 |
if(!strcmp(reg, "c")) { |
| 1263 |
regs.c= number & 0xFFFF; |
| 1264 |
} |
| 1265 |
if(!strcmp(reg, "d")) { |
| 1266 |
regs.dp= number & 0xFFFF; |
| 1267 |
} |
| 1268 |
if(!strcmp(reg, "k")) { |
| 1269 |
regs.k= number & 0x00FF; |
| 1270 |
} |
| 1271 |
if(!strcmp(reg, "dbr")) { |
| 1272 |
regs.db= number & 0x00FF; |
| 1273 |
} |
| 1274 |
if(!strcmp(reg, "x")) { |
| 1275 |
if (regs.e) { |
| 1276 |
regs.xl= number & 0x00FF; |
| 1277 |
} else { |
| 1278 |
regs.x= number & 0xFFFF; |
| 1279 |
} |
| 1280 |
} |
| 1281 |
if(!strcmp(reg, "y")) { |
| 1282 |
if (regs.e) { |
| 1283 |
regs.yl= number & 0x00FF; |
| 1284 |
} else { |
| 1285 |
regs.y= number & 0xFFFF; |
| 1286 |
} |
| 1287 |
} |
| 1288 |
if(!strcmp(reg, "sp")) { |
| 1289 |
if (regs.e) { |
| 1290 |
regs.sp= 0x100 | (number & 0x00FF); |
| 1291 |
} else { |
| 1292 |
regs.sp= number & 0xFFFF; |
| 1293 |
} |
| 1294 |
} |
| 1295 |
break; |
| 1296 |
|
| 1297 |
default: |
| 1298 |
break; |
| 1299 |
} |
| 1300 |
|
| 1301 |
currentPosInLine= currentLineLen= *cmdLine= 0; |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
void DEBUGRenderDisplay(int width, int height) { |
| 1311 |
if (showFullDisplay) return; |
| 1312 |
|
| 1313 |
SDL_Rect rc; |
| 1314 |
rc.w = DBG_WIDTH * 6 * CHAR_SCALE; |
| 1315 |
rc.h = height; |
| 1316 |
xPos = width-rc.w;yPos = 0; |
| 1317 |
rc.x = xPos;rc.y = yPos; |
| 1318 |
SDL_SetRenderDrawColor(dbgRenderer,0,0,0,SDL_ALPHA_OPAQUE); |
| 1319 |
SDL_RenderFillRect(dbgRenderer,&rc); |
| 1320 |
|
| 1321 |
int register_lines = DEBUGRenderRegisters(); |
| 1322 |
DEBUGRenderCode(register_lines, currentPC); |
| 1323 |
if (dumpmode == DDUMP_RAM) { |
| 1324 |
DEBUGRenderData(register_lines + 1, currentData); |
| 1325 |
int zp_lines = DEBUGRenderZeroPageRegisters(register_lines + 1); |
| 1326 |
DEBUGRenderVERAState(zp_lines + 1); |
| 1327 |
} else { |
| 1328 |
DEBUGRenderVRAM(register_lines + 1, currentData); |
| 1329 |
} |
| 1330 |
DEBUGRenderStack(register_lines); |
| 1331 |
|
| 1332 |
DEBUGRenderCmdLine(xPos, rc.w, height); |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
static void DEBUGRenderCmdLine(int x, int width, int height) { |
| 1342 |
char buffer[sizeof(cmdLine)+1]; |
| 1343 |
|
| 1344 |
SDL_SetRenderDrawColor(dbgRenderer, 255, 255, 255, SDL_ALPHA_OPAQUE); |
| 1345 |
SDL_RenderDrawLine(dbgRenderer, x, height-12, x+width, height-12); |
| 1346 |
|
| 1347 |
sprintf(buffer, ">%s", cmdLine); |
| 1348 |
DEBUGString(dbgRenderer, 0, DBG_HEIGHT-1, buffer, col_cmdLine); |
| 1349 |
DEBUGString(dbgRenderer, currentPosInLine+1, DBG_HEIGHT-1, "_", col_cmdLine); |
| 1350 |
} |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
static int DEBUGRenderZeroPageRegisters(int y) { |
| 1359 |
#define LAST_R 15 |
| 1360 |
unsigned char reg = 0; |
| 1361 |
int y_start = y; |
| 1362 |
char lbl[12]; |
| 1363 |
while (reg < DBGMAX_ZERO_PAGE_REGISTERS) { |
| 1364 |
if (((y-y_start) % 5) != 0) { |
| 1365 |
if (reg <= LAST_R) |
| 1366 |
sprintf(lbl, "R%d", reg); |
| 1367 |
else |
| 1368 |
sprintf(lbl, "x%d", reg); |
| 1369 |
|
| 1370 |
DEBUGString(dbgRenderer, DBG_ZP_REG, y, lbl, col_label); |
| 1371 |
|
| 1372 |
int reg_addr = 2 + reg * 2; |
| 1373 |
int n = debug_read6502(direct_page_add(reg_addr+1), 0, USE_CURRENT_X16_BANK)*256+debug_read6502(direct_page_add(reg_addr), 0, USE_CURRENT_X16_BANK); |
| 1374 |
|
| 1375 |
DEBUGNumber(DBG_ZP_REG+5, y, n, 4, col_data); |
| 1376 |
|
| 1377 |
if (oldRegChange[reg] != NULL) |
| 1378 |
DEBUGString(dbgRenderer, DBG_ZP_REG+9, y, oldRegChange[reg], col_data); |
| 1379 |
|
| 1380 |
if (oldRegisterTicks != clockticks6502) { |
| 1381 |
oldRegChange[reg] = n != oldRegisters[reg] ? "*" : " "; |
| 1382 |
oldRegisters[reg]=n; |
| 1383 |
} |
| 1384 |
reg++; |
| 1385 |
} |
| 1386 |
y++; |
| 1387 |
} |
| 1388 |
|
| 1389 |
if (oldRegisterTicks != clockticks6502) { |
| 1390 |
oldRegisterTicks = clockticks6502; |
| 1391 |
} |
| 1392 |
|
| 1393 |
return y; |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
static void DEBUGRenderData(int y,uint32_t data) { |
| 1403 |
while (y < DBG_HEIGHT-2) { |
| 1404 |
DEBUGAddress(DBG_MEMX, y, (uint8_t)currentX16Bank, data & 0xFFFF, data >> 16, col_label); |
| 1405 |
|
| 1406 |
for (int i = 0;i < 8;i++) { |
| 1407 |
bool isDP = (data >> 16) == 0 && ((data+i - regs.dp) & 0xffff) < 256; |
| 1408 |
int byte = debug_read6502((data+i) & 0xFFFF, data >> 16, currentX16Bank); |
| 1409 |
DEBUGNumber(DBG_MEMX+8+i*3,y,byte,2, isDP ? col_directpage : col_data); |
| 1410 |
DEBUGWrite(dbgRenderer, DBG_MEMX+33+i,y,byte, isDP ? col_directpage : col_data); |
| 1411 |
} |
| 1412 |
y++; |
| 1413 |
data = (data + 8) & 0xFFFFFF; |
| 1414 |
} |
| 1415 |
} |
| 1416 |
|
| 1417 |
static void DEBUGRenderVRAM(int y, int data) { |
| 1418 |
while (y < DBG_HEIGHT - 2) { |
| 1419 |
DEBUGVAddress(DBG_MEMX, y, data & 0x1FFFF, col_label); |
| 1420 |
|
| 1421 |
for (int i = 0; i < 16; i++) { |
| 1422 |
int addr = (data + i) & 0x1FFFF; |
| 1423 |
int byte = video_space_read(addr); |
| 1424 |
|
| 1425 |
if (video_is_tilemap_address(addr)) { |
| 1426 |
DEBUGNumber(DBG_MEMX + 6 + i * 3, y, byte, 2, col_vram_tilemap); |
| 1427 |
} else if (video_is_tiledata_address(addr)) { |
| 1428 |
DEBUGNumber(DBG_MEMX + 6 + i * 3, y, byte, 2, col_vram_tiledata); |
| 1429 |
} else if (video_is_special_address(addr)) { |
| 1430 |
DEBUGNumber(DBG_MEMX + 6 + i * 3, y, byte, 2, col_vram_special); |
| 1431 |
} else { |
| 1432 |
DEBUGNumber(DBG_MEMX + 6 + i * 3, y, byte, 2, col_vram_other); |
| 1433 |
} |
| 1434 |
} |
| 1435 |
y++; |
| 1436 |
data += 16; |
| 1437 |
} |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
static void DEBUGRenderCode(int lines, int initialPC) { |
| 1448 |
char buffer[32]; |
| 1449 |
uint8_t implied_status = regs.status; |
| 1450 |
uint8_t implied_e = regs.e; |
| 1451 |
uint8_t opcode, operand, carry; |
| 1452 |
int implied_x16_bank = currentPCX16Bank; |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
int implied_window = bank_window_of(initialPC); |
| 1458 |
|
| 1459 |
for (int y = 0; y < lines; y++) { |
| 1460 |
DEBUGAddress(DBG_ASMX, y, implied_x16_bank, initialPC, currentPCBank, col_label); |
| 1461 |
int32_t eff_addr; |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
if (regs.is65c816) { |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
opcode = debug_read6502(initialPC, currentPCBank, implied_x16_bank); |
| 1480 |
switch (opcode) { |
| 1481 |
case 0x81: |
| 1482 |
implied_status &= ~FLAG_CARRY; |
| 1483 |
;; |
| 1484 |
case 0x83: |
| 1485 |
implied_status |= FLAG_CARRY; |
| 1486 |
;; |
| 1487 |
case 0xC2: |
| 1488 |
operand = debug_read6502((initialPC+1) & 0xffff, currentPCBank, implied_x16_bank); |
| 1489 |
implied_status = ~operand & implied_status; |
| 1490 |
;; |
| 1491 |
case 0xE2: |
| 1492 |
operand = debug_read6502((initialPC+1) & 0xffff, currentPCBank, implied_x16_bank); |
| 1493 |
implied_status = operand | implied_status; |
| 1494 |
;; |
| 1495 |
case 0xFB: |
| 1496 |
carry = implied_status & FLAG_CARRY; |
| 1497 |
implied_status = (implied_status & ~FLAG_CARRY) | (implied_e ? FLAG_CARRY : 0); |
| 1498 |
implied_e = carry != 0; |
| 1499 |
;; |
| 1500 |
default: |
| 1501 |
;; |
| 1502 |
} |
| 1503 |
if (implied_e) implied_status |= FLAG_INDEX_WIDTH | FLAG_MEMORY_WIDTH; |
| 1504 |
|
| 1505 |
} |
| 1506 |
int size = disasm(initialPC, currentPCBank, RAM, buffer, sizeof(buffer), implied_x16_bank, implied_status, &eff_addr); |
| 1507 |
|
| 1508 |
DEBUGString(dbgRenderer, DBG_ASMX+8, y, buffer, initialPC == regs.pc ? col_highlight : col_data); |
| 1509 |
|
| 1510 |
if (initialPC == regs.pc) { |
| 1511 |
if (eff_addr < 0) { |
| 1512 |
DEBUGString(dbgRenderer, DBG_DATX, lines-1, "----", col_data); |
| 1513 |
} else { |
| 1514 |
DEBUGNumber(DBG_DATX, lines-1, eff_addr, 4, col_data); |
| 1515 |
} |
| 1516 |
} |
| 1517 |
initialPC = (initialPC + size) & 0xFFFF; |
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
if (bank_window_of(initialPC) != implied_window) { |
| 1523 |
implied_window = bank_window_of(initialPC); |
| 1524 |
implied_x16_bank = debug_current_x16_bank(initialPC, currentPCBank); |
| 1525 |
} |
| 1526 |
} |
| 1527 |
} |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
static char *labels_c816[] = { "NVMXDIZCE","","","A","B","C","X","Y","K","DB","","PC","DP","SP","BKA","BKO","","BRK","EFF", NULL }; |
| 1536 |
static char *labels_c02[] = { "NV-BDIZC","","","A","X","Y","","PC","SP","BKA","BKO","","BRK","EFF", NULL }; |
| 1537 |
|
| 1538 |
static void DEBUGNumberHighByteCondition(int x, int y, int n, bool condition, SDL_Color ifTrue, SDL_Color ifFalse) { |
| 1539 |
if (condition) { |
| 1540 |
DEBUGNumber(x, y, n >> 8, 2, ifTrue); |
| 1541 |
DEBUGNumber(x + 2, y, n & 0xFF, 2, ifFalse); |
| 1542 |
} else { |
| 1543 |
DEBUGNumber(x, y, n, 4, ifFalse); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
static int DEBUGRenderRegisters(void) { |
| 1548 |
int n = 0,yc = 0; |
| 1549 |
if (regs.is65c816) { |
| 1550 |
while (labels_c816[n] != NULL) { |
| 1551 |
DEBUGString(dbgRenderer, DBG_LBLX,n,labels_c816[n], col_label);n++; |
| 1552 |
} |
| 1553 |
yc++; |
| 1554 |
DEBUGNumber(DBG_LBLX, yc, (regs.status >> 7) & 1, 1, col_data); |
| 1555 |
DEBUGNumber(DBG_LBLX+1, yc, (regs.status >> 6) & 1, 1, col_data); |
| 1556 |
DEBUGNumber(DBG_LBLX+2, yc, (regs.status >> 5) & 1, 1, regs.e ? col_vram_other : col_data); |
| 1557 |
DEBUGNumber(DBG_LBLX+3, yc, (regs.status >> 4) & 1, 1, regs.e ? col_vram_other : col_data); |
| 1558 |
DEBUGNumber(DBG_LBLX+4, yc, (regs.status >> 3) & 1, 1, col_data); |
| 1559 |
DEBUGNumber(DBG_LBLX+5, yc, (regs.status >> 2) & 1, 1, col_data); |
| 1560 |
DEBUGNumber(DBG_LBLX+6, yc, (regs.status >> 1) & 1, 1, col_data); |
| 1561 |
DEBUGNumber(DBG_LBLX+7, yc, (regs.status >> 0) & 1, 1, col_data); |
| 1562 |
DEBUGNumber(DBG_LBLX+8, yc, regs.e, 1, col_data); |
| 1563 |
yc+= 2; |
| 1564 |
|
| 1565 |
DEBUGNumber(DBG_DATX, yc++, regs.a, 2, col_data); |
| 1566 |
DEBUGNumber(DBG_DATX, yc++, regs.b, 2, col_data); |
| 1567 |
DEBUGNumber(DBG_DATX, yc++, regs.c, 4, col_data); |
| 1568 |
DEBUGNumberHighByteCondition(DBG_DATX, yc++, regs.x, (regs.status >> 4) & 1, col_vram_other, col_data); |
| 1569 |
DEBUGNumberHighByteCondition(DBG_DATX, yc++, regs.y, (regs.status >> 4) & 1, col_vram_other, col_data); |
| 1570 |
DEBUGNumber(DBG_DATX, yc++, regs.k, 2, col_data); |
| 1571 |
DEBUGNumber(DBG_DATX, yc++, regs.db, 2, col_data); |
| 1572 |
yc++; |
| 1573 |
|
| 1574 |
DEBUGNumber(DBG_DATX, yc++, regs.pc, 4, col_data); |
| 1575 |
DEBUGNumber(DBG_DATX, yc++, regs.dp, 4, col_data); |
| 1576 |
DEBUGNumberHighByteCondition(DBG_DATX, yc++, regs.sp, regs.e, col_vram_other, col_data); |
| 1577 |
DEBUGNumber(DBG_DATX, yc++, memory_get_ram_bank(), 2, col_data); |
| 1578 |
DEBUGNumber(DBG_DATX, yc++, memory_get_rom_bank(), 2, col_data); |
| 1579 |
yc++; |
| 1580 |
} else { |
| 1581 |
while (labels_c02[n] != NULL) { |
| 1582 |
DEBUGString(dbgRenderer, DBG_LBLX,n,labels_c02[n], col_label);n++; |
| 1583 |
} |
| 1584 |
yc++; |
| 1585 |
DEBUGNumber(DBG_LBLX, yc, (regs.status >> 7) & 1, 1, col_data); |
| 1586 |
DEBUGNumber(DBG_LBLX+1, yc, (regs.status >> 6) & 1, 1, col_data); |
| 1587 |
DEBUGNumber(DBG_LBLX+3, yc, (regs.status >> 4) & 1, 1, col_data); |
| 1588 |
DEBUGNumber(DBG_LBLX+4, yc, (regs.status >> 3) & 1, 1, col_data); |
| 1589 |
DEBUGNumber(DBG_LBLX+5, yc, (regs.status >> 2) & 1, 1, col_data); |
| 1590 |
DEBUGNumber(DBG_LBLX+6, yc, (regs.status >> 1) & 1, 1, col_data); |
| 1591 |
DEBUGNumber(DBG_LBLX+7, yc, (regs.status >> 0) & 1, 1, col_data); |
| 1592 |
yc+= 2; |
| 1593 |
|
| 1594 |
DEBUGNumber(DBG_DATX, yc++, regs.a, 2, col_data); |
| 1595 |
DEBUGNumber(DBG_DATX, yc++, regs.xl, 2, col_data); |
| 1596 |
DEBUGNumber(DBG_DATX, yc++, regs.yl, 2, col_data); |
| 1597 |
yc++; |
| 1598 |
|
| 1599 |
DEBUGNumber(DBG_DATX, yc++, regs.pc, 4, col_data); |
| 1600 |
DEBUGNumber(DBG_DATX, yc++, regs.sp|0x100, 4, col_data); |
| 1601 |
DEBUGNumber(DBG_DATX, yc++, memory_get_ram_bank(), 2, col_data); |
| 1602 |
DEBUGNumber(DBG_DATX, yc++, memory_get_rom_bank(), 2, col_data); |
| 1603 |
yc++; |
| 1604 |
|
| 1605 |
} |
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
if (numBreakpoints == 0) { |
| 1611 |
DEBUGString(dbgRenderer, DBG_DATX, yc++, "--:----", col_data); |
| 1612 |
} else { |
| 1613 |
const struct breakpoint *bp = &breakPoints[0]; |
| 1614 |
if (bp->x16Bank < 0) { |
| 1615 |
if (is_gen2) { |
| 1616 |
DEBUGNumber(DBG_DATX, yc, bp->bank, 2, col_data); |
| 1617 |
DEBUGNumber(DBG_DATX+3, yc, bp->pc, 4, col_data); |
| 1618 |
} else { |
| 1619 |
DEBUGString(dbgRenderer, DBG_DATX, yc, "--:", col_data); |
| 1620 |
DEBUGNumber(DBG_DATX+3, yc, (uint16_t)bp->pc, 4, col_data); |
| 1621 |
} |
| 1622 |
} else { |
| 1623 |
DEBUGNumber(DBG_DATX, yc, bp->x16Bank, 2, col_data); |
| 1624 |
DEBUGString(dbgRenderer, DBG_DATX+2, yc, ":", col_data); |
| 1625 |
DEBUGNumber(DBG_DATX+3, yc, bp->pc, 4, col_data); |
| 1626 |
} |
| 1627 |
if (numBreakpoints > 1) { |
| 1628 |
char more[16]; |
| 1629 |
snprintf(more, sizeof(more), "+%d", numBreakpoints - 1); |
| 1630 |
DEBUGString(dbgRenderer, DBG_DATX+8, yc, more, col_data); |
| 1631 |
} |
| 1632 |
yc++; |
| 1633 |
} |
| 1634 |
yc++; |
| 1635 |
|
| 1636 |
return n; |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
static char *vera_labels[] = { "ADDR0", "ADDR1", "DATA0","DATA1", "CTRL", "VIDEO", "HSCLE", "VSCLE", "FXCTL", "FXMUL", "CACHE", "ACCUM", "", "CLOCKS ELAPSED", NULL }; |
| 1641 |
|
| 1642 |
static void DEBUGRenderVERAState(int y) { |
| 1643 |
int n=0; |
| 1644 |
int yc=y; |
| 1645 |
while (vera_labels[n] != NULL) { |
| 1646 |
DEBUGString(dbgRenderer, DBG_VERA_REGX, yc, vera_labels[n], col_label);n++;yc++; |
| 1647 |
} |
| 1648 |
|
| 1649 |
yc=y; |
| 1650 |
|
| 1651 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_address(0), 5, col_data); |
| 1652 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_address(1), 5, col_data); |
| 1653 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_read(3, true), 2, col_data); |
| 1654 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_read(4, true), 2, col_data); |
| 1655 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_read(5, true), 2, col_data); |
| 1656 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_dc_value(0), 2, col_data); |
| 1657 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_dc_value(1), 2, col_data); |
| 1658 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_dc_value(2), 2, col_data); |
| 1659 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_dc_value(8), 2, col_data); |
| 1660 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_dc_value(11), 2, col_data); |
| 1661 |
DEBUGNumber(DBG_VERA_REGX+6, yc, video_get_dc_value(24), 2, col_data); |
| 1662 |
DEBUGNumber(DBG_VERA_REGX+8, yc, video_get_dc_value(25), 2, col_data); |
| 1663 |
DEBUGNumber(DBG_VERA_REGX+10, yc, video_get_dc_value(26), 2, col_data); |
| 1664 |
DEBUGNumber(DBG_VERA_REGX+12, yc++, video_get_dc_value(27), 2, col_data); |
| 1665 |
DEBUGNumber(DBG_VERA_REGX+6, yc++, video_get_fx_accum(), 8, col_data); |
| 1666 |
|
| 1667 |
yc+=2; |
| 1668 |
DEBUGNumberDec(DBG_VERA_REGX, yc++, clockticks6502 - debugCPUClocks, 14, col_data); |
| 1669 |
} |
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
static void DEBUGRenderStack(int bytesCount) { |
| 1678 |
uint16_t sp = regs.sp; |
| 1679 |
increment_wrap_at_page_boundary(&sp); |
| 1680 |
|
| 1681 |
int y= 0; |
| 1682 |
while (y < bytesCount) { |
| 1683 |
DEBUGNumber(DBG_STCK,y, sp,4, col_label); |
| 1684 |
int byte = debug_read6502(sp, 0, USE_CURRENT_X16_BANK); |
| 1685 |
DEBUGNumber(DBG_STCK+5,y,byte,2, col_data); |
| 1686 |
DEBUGWrite(dbgRenderer, DBG_STCK+9,y,byte, col_data); |
| 1687 |
y++; |
| 1688 |
increment_wrap_at_page_boundary(&sp); |
| 1689 |
} |
| 1690 |
} |
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
static void DEBUGNumber(int x, int y, int n, int w, SDL_Color colour) { |
| 1699 |
char fmtString[8],buffer[16]; |
| 1700 |
snprintf(fmtString, sizeof(fmtString), "%%0%dX", w); |
| 1701 |
snprintf(buffer, sizeof(buffer), fmtString, n); |
| 1702 |
DEBUGString(dbgRenderer, x, y, buffer, colour); |
| 1703 |
} |
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
static void DEBUGNumberDec(int x, int y, int n, int w, SDL_Color colour) { |
| 1712 |
char buf1[32], buf2[32]; |
| 1713 |
int i,j; |
| 1714 |
snprintf(buf1, sizeof(buf1), "%d", n); |
| 1715 |
buf2[sizeof(buf2)-1] = 0; |
| 1716 |
int count = 0; |
| 1717 |
for (i=strlen(buf1) - 1, j=sizeof(buf2) - 1; i >= 0 && j > 1; i--) { |
| 1718 |
buf2[--j] = buf1[i]; |
| 1719 |
count++; |
| 1720 |
|
| 1721 |
if (count == 3) { |
| 1722 |
buf2[--j] = ' '; |
| 1723 |
count = 0; |
| 1724 |
} |
| 1725 |
} |
| 1726 |
|
| 1727 |
if (buf2[j] == ' ') j++; |
| 1728 |
DEBUGString(dbgRenderer, x+(w-strlen(buf2+j)), y, buf2+j, colour); |
| 1729 |
} |
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
static void DEBUGAddress(int x, int y, int x16Bank, int addr, uint8_t bank, SDL_Color colour) { |
| 1737 |
char buffer[4]; |
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
if (debug_current_x16_bank(addr, bank) >= 0) { |
| 1744 |
snprintf(buffer, sizeof(buffer), "%.2X:", x16Bank); |
| 1745 |
} else if (is_gen2) { |
| 1746 |
snprintf(buffer, sizeof(buffer), "%.2X ", bank); |
| 1747 |
} else { |
| 1748 |
strcpy(buffer, "--:"); |
| 1749 |
} |
| 1750 |
|
| 1751 |
DEBUGString(dbgRenderer, x, y, buffer, colour); |
| 1752 |
|
| 1753 |
DEBUGNumber(x+3, y, addr, 4, colour); |
| 1754 |
|
| 1755 |
} |
| 1756 |
|
| 1757 |
static void |
| 1758 |
DEBUGVAddress(int x, int y, int addr, SDL_Color colour) |
| 1759 |
{ |
| 1760 |
DEBUGNumber(x, y, addr, 5, colour); |
| 1761 |
} |