comparison debug.c @ 1129:6b5c92b6205c

Enabled Z80 debugger in PBC mode
author Michael Pavone <pavone@retrodev.com>
date Wed, 28 Dec 2016 12:28:52 -0800
parents 2eb54e24914e
children 8f14767661fa
comparison
equal deleted inserted replaced
1128:093c19f34dfd 1129:6b5c92b6205c
341 if (*this_bp) { 341 if (*this_bp) {
342 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index); 342 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index);
343 } else { 343 } else {
344 zremove_breakpoint(context, address); 344 zremove_breakpoint(context, address);
345 } 345 }
346 uint8_t * pc; 346 uint8_t * pc = get_native_pointer(address, (void **)context->mem_pointers, &context->options->gen);
347 if (address < 0x4000) { 347 if (!pc) {
348 pc = system->zram + (address & 0x1FFF); 348 fatal_error("Failed to get native pointer on entering Z80 debugger at address %X\n", address);
349 } else if (address >= 0x8000) {
350 if (context->bank_reg < (0x400000 >> 15)) {
351 fatal_error("Entered Z80 debugger in banked memory address %X, which is not yet supported\n", address);
352 } else {
353 fatal_error("Entered Z80 debugger in banked memory address %X, but the bank is not pointed to a cartridge address\n", address);
354 }
355 } else {
356 fatal_error("Entered Z80 debugger at address %X\n", address);
357 } 349 }
358 for (disp_def * cur = zdisplays; cur; cur = cur->next) { 350 for (disp_def * cur = zdisplays; cur; cur = cur->next) {
359 zdebugger_print(context, cur->format_char, cur->param); 351 zdebugger_print(context, cur->format_char, cur->param);
360 } 352 }
361 uint8_t * after_pc = z80_decode(pc, &inst); 353 uint8_t * after_pc = z80_decode(pc, &inst);
468 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL]; 460 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL];
469 } 461 }
470 } else if(inst.op == Z80_JR) { 462 } else if(inst.op == Z80_JR) {
471 after += inst.immed; 463 after += inst.immed;
472 } else if(inst.op == Z80_RET) { 464 } else if(inst.op == Z80_RET) {
473 if (context->sp < 0x4000) { 465 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->options->gen);
474 after = system->zram[context->sp & 0x1FFF] | system->zram[(context->sp+1) & 0x1FFF] << 8; 466 if (sp) {
467 after = *sp;
468 sp = get_native_pointer((context->sp + 1) & 0xFFFF, (void **)context->mem_pointers, &context->options->gen);
469 if (sp) {
470 after |= *sp << 8;
471 }
475 } 472 }
476 } 473 }
477 zinsert_breakpoint(context, after, (uint8_t *)zdebugger); 474 zinsert_breakpoint(context, after, (uint8_t *)zdebugger);
478 debugging = 0; 475 debugging = 0;
479 break; 476 break;
493 param = find_param(input_buf); 490 param = find_param(input_buf);
494 if (!param) { 491 if (!param) {
495 fputs("s command requires a file name\n", stderr); 492 fputs("s command requires a file name\n", stderr);
496 break; 493 break;
497 } 494 }
498 FILE * f = fopen(param, "wb"); 495 memmap_chunk const *ram_chunk = NULL;
499 if (f) { 496 for (int i = 0; i < context->options->gen.memmap_chunks; i++)
500 if(fwrite(system->zram, 1, Z80_RAM_BYTES, f) != Z80_RAM_BYTES) { 497 {
501 fputs("Error writing file\n", stderr); 498 memmap_chunk const *cur = context->options->gen.memmap + i;
502 } 499 if (cur->flags & MMAP_WRITE) {
503 fclose(f); 500 ram_chunk = cur;
501 break;
502 }
503 }
504 if (ram_chunk) {
505 uint32_t size = ram_chunk->end - ram_chunk->start;
506 if (size > ram_chunk->mask) {
507 size = ram_chunk->mask+1;
508 }
509 uint8_t *buf = get_native_pointer(ram_chunk->start, (void **)context->mem_pointers, &context->options->gen);
510 FILE * f = fopen(param, "wb");
511 if (f) {
512 if(fwrite(buf, 1, size, f) != size) {
513 fputs("Error writing file\n", stderr);
514 }
515 fclose(f);
516 printf("Wrote %d bytes to %s\n", size, param);
517 } else {
518 fprintf(stderr, "Could not open %s for writing\n", param);
519 }
504 } else { 520 } else {
505 fprintf(stderr, "Could not open %s for writing\n", param); 521 fputs("Failed to find a RAM memory chunk\n", stderr);
506 } 522 }
507 break; 523 break;
508 } 524 }
509 default: 525 default:
510 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf); 526 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf);