Mercurial > repos > blastem
comparison debug.c @ 1103:22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 09 Dec 2016 09:48:48 -0800 |
parents | 751280fb4494 |
children | 2eb54e24914e |
comparison
equal
deleted
inserted
replaced
1102:c15896605bf2 | 1103:22e87b739ad6 |
---|---|
1 #include "debug.h" | 1 #include "debug.h" |
2 #include "blastem.h" | 2 #include "genesis.h" |
3 #include "68kinst.h" | 3 #include "68kinst.h" |
4 #include <stdlib.h> | 4 #include <stdlib.h> |
5 #include <string.h> | 5 #include <string.h> |
6 #ifndef _WIN32 | 6 #ifndef _WIN32 |
7 #include <sys/select.h> | 7 #include <sys/select.h> |
138 void zdebugger_print(z80_context * context, char format_char, char * param) | 138 void zdebugger_print(z80_context * context, char format_char, char * param) |
139 { | 139 { |
140 uint32_t value; | 140 uint32_t value; |
141 char format[8]; | 141 char format[8]; |
142 strcpy(format, "%s: %d\n"); | 142 strcpy(format, "%s: %d\n"); |
143 genesis_context *system = context->system; | |
143 switch (format_char) | 144 switch (format_char) |
144 { | 145 { |
145 case 'x': | 146 case 'x': |
146 case 'X': | 147 case 'X': |
147 case 'd': | 148 case 'd': |
303 break; | 304 break; |
304 case '0': | 305 case '0': |
305 if (param[1] == 'x') { | 306 if (param[1] == 'x') { |
306 uint16_t p_addr = strtol(param+2, NULL, 16); | 307 uint16_t p_addr = strtol(param+2, NULL, 16); |
307 if (p_addr < 0x4000) { | 308 if (p_addr < 0x4000) { |
308 value = z80_ram[p_addr & 0x1FFF]; | 309 value = system->zram[p_addr & 0x1FFF]; |
309 } else if(p_addr >= 0x8000) { | 310 } else if(p_addr >= 0x8000) { |
310 uint32_t v_addr = context->bank_reg << 15; | 311 uint32_t v_addr = context->bank_reg << 15; |
311 v_addr += p_addr & 0x7FFF; | 312 v_addr += p_addr & 0x7FFF; |
312 if (v_addr < 0x400000) { | 313 if (v_addr < 0x400000) { |
313 value = cart[v_addr/2]; | 314 value = system->cart[v_addr/2]; |
314 } else if(v_addr > 0xE00000) { | 315 } else if(v_addr > 0xE00000) { |
315 value = ram[(v_addr & 0xFFFF)/2]; | 316 value = system->work_ram[(v_addr & 0xFFFF)/2]; |
316 } | 317 } |
317 if (v_addr & 1) { | 318 if (v_addr & 1) { |
318 value &= 0xFF; | 319 value &= 0xFF; |
319 } else { | 320 } else { |
320 value >>= 8; | 321 value >>= 8; |
331 static char last_cmd[1024]; | 332 static char last_cmd[1024]; |
332 char input_buf[1024]; | 333 char input_buf[1024]; |
333 static uint16_t branch_t; | 334 static uint16_t branch_t; |
334 static uint16_t branch_f; | 335 static uint16_t branch_f; |
335 z80inst inst; | 336 z80inst inst; |
337 genesis_context *system = context->system; | |
336 init_terminal(); | 338 init_terminal(); |
337 //Check if this is a user set breakpoint, or just a temporary one | 339 //Check if this is a user set breakpoint, or just a temporary one |
338 bp_def ** this_bp = find_breakpoint(&zbreakpoints, address); | 340 bp_def ** this_bp = find_breakpoint(&zbreakpoints, address); |
339 if (*this_bp) { | 341 if (*this_bp) { |
340 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index); | 342 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index); |
341 } else { | 343 } else { |
342 zremove_breakpoint(context, address); | 344 zremove_breakpoint(context, address); |
343 } | 345 } |
344 uint8_t * pc; | 346 uint8_t * pc; |
345 if (address < 0x4000) { | 347 if (address < 0x4000) { |
346 pc = z80_ram + (address & 0x1FFF); | 348 pc = system->zram + (address & 0x1FFF); |
347 } else if (address >= 0x8000) { | 349 } else if (address >= 0x8000) { |
348 if (context->bank_reg < (0x400000 >> 15)) { | 350 if (context->bank_reg < (0x400000 >> 15)) { |
349 fatal_error("Entered Z80 debugger in banked memory address %X, which is not yet supported\n", address); | 351 fatal_error("Entered Z80 debugger in banked memory address %X, which is not yet supported\n", address); |
350 } else { | 352 } else { |
351 fatal_error("Entered Z80 debugger in banked memory address %X, but the bank is not pointed to a cartridge address\n", address); | 353 fatal_error("Entered Z80 debugger in banked memory address %X, but the bank is not pointed to a cartridge address\n", address); |
467 } | 469 } |
468 } else if(inst.op == Z80_JR) { | 470 } else if(inst.op == Z80_JR) { |
469 after += inst.immed; | 471 after += inst.immed; |
470 } else if(inst.op == Z80_RET) { | 472 } else if(inst.op == Z80_RET) { |
471 if (context->sp < 0x4000) { | 473 if (context->sp < 0x4000) { |
472 after = z80_ram[context->sp & 0x1FFF] | z80_ram[(context->sp+1) & 0x1FFF] << 8; | 474 after = system->zram[context->sp & 0x1FFF] | system->zram[(context->sp+1) & 0x1FFF] << 8; |
473 } | 475 } |
474 } | 476 } |
475 zinsert_breakpoint(context, after, (uint8_t *)zdebugger); | 477 zinsert_breakpoint(context, after, (uint8_t *)zdebugger); |
476 debugging = 0; | 478 debugging = 0; |
477 break; | 479 break; |
493 fputs("s command requires a file name\n", stderr); | 495 fputs("s command requires a file name\n", stderr); |
494 break; | 496 break; |
495 } | 497 } |
496 FILE * f = fopen(param, "wb"); | 498 FILE * f = fopen(param, "wb"); |
497 if (f) { | 499 if (f) { |
498 if(fwrite(z80_ram, 1, sizeof(z80_ram), f) != sizeof(z80_ram)) { | 500 if(fwrite(system->zram, 1, Z80_RAM_BYTES, f) != Z80_RAM_BYTES) { |
499 fputs("Error writing file\n", stderr); | 501 fputs("Error writing file\n", stderr); |
500 } | 502 } |
501 fclose(f); | 503 fclose(f); |
502 } else { | 504 } else { |
503 fprintf(stderr, "Could not open %s for writing\n", param); | 505 fprintf(stderr, "Could not open %s for writing\n", param); |
519 | 521 |
520 int run_debugger_command(m68k_context *context, char *input_buf, m68kinst inst, uint32_t after) | 522 int run_debugger_command(m68k_context *context, char *input_buf, m68kinst inst, uint32_t after) |
521 { | 523 { |
522 char * param; | 524 char * param; |
523 char format_char; | 525 char format_char; |
526 genesis_context *system = context->system; | |
524 uint32_t value; | 527 uint32_t value; |
525 bp_def *new_bp, **this_bp; | 528 bp_def *new_bp, **this_bp; |
526 switch(input_buf[0]) | 529 switch(input_buf[0]) |
527 { | 530 { |
528 case 'c': | 531 case 'c': |
569 uint32_t stack = context->aregs[7]; | 572 uint32_t stack = context->aregs[7]; |
570 if (stack >= 0xE00000) { | 573 if (stack >= 0xE00000) { |
571 stack &= 0xFFFF; | 574 stack &= 0xFFFF; |
572 uint8_t non_adr_count = 0; | 575 uint8_t non_adr_count = 0; |
573 do { | 576 do { |
574 uint32_t bt_address = ram[stack/2] << 16 | ram[stack/2+1]; | 577 uint32_t bt_address = system->work_ram[stack/2] << 16 | system->work_ram[stack/2+1]; |
575 bt_address = get_instruction_start(context->options, context->native_code_map, bt_address - 2); | 578 bt_address = get_instruction_start(context->options, context->native_code_map, bt_address - 2); |
576 if (bt_address) { | 579 if (bt_address) { |
577 stack += 4; | 580 stack += 4; |
578 non_adr_count = 0; | 581 non_adr_count = 0; |
579 uint16_t *bt_pc = NULL; | 582 uint16_t *bt_pc = NULL; |
580 if (bt_address < 0x400000) { | 583 if (bt_address < 0x400000) { |
581 bt_pc = cart + bt_address/2; | 584 bt_pc = system->cart + bt_address/2; |
582 } else if(bt_address > 0xE00000) { | 585 } else if(bt_address > 0xE00000) { |
583 bt_pc = ram + (bt_address & 0xFFFF)/2; | 586 bt_pc = system->work_ram + (bt_address & 0xFFFF)/2; |
584 } | 587 } |
585 m68k_decode(bt_pc, &inst, bt_address); | 588 m68k_decode(bt_pc, &inst, bt_address); |
586 m68k_disasm(&inst, input_buf); | 589 m68k_disasm(&inst, input_buf); |
587 printf("%X: %s\n", bt_address, input_buf); | 590 printf("%X: %s\n", bt_address, input_buf); |
588 } else { | 591 } else { |
849 remove_breakpoint(context, branch_t); | 852 remove_breakpoint(context, branch_t); |
850 } | 853 } |
851 branch_t = branch_f = 0; | 854 branch_t = branch_f = 0; |
852 } | 855 } |
853 | 856 |
854 uint16_t * pc; | 857 uint16_t * pc = get_native_pointer(address, (void **)context->mem_pointers, &context->options->gen); |
855 if (address < 0x400000) { | 858 if (!pc) { |
856 pc = cart + address/2; | |
857 } else if(address > 0xE00000) { | |
858 pc = ram + (address & 0xFFFF)/2; | |
859 } else { | |
860 fatal_error("Entered 68K debugger at address %X\n", address); | 859 fatal_error("Entered 68K debugger at address %X\n", address); |
861 } | 860 } |
862 uint16_t * after_pc = m68k_decode(pc, &inst, address); | 861 uint16_t * after_pc = m68k_decode(pc, &inst, address); |
863 uint32_t after = address + (after_pc-pc)*2; | 862 uint32_t after = address + (after_pc-pc)*2; |
864 int debugging = 1; | 863 int debugging = 1; |