comparison debug.c @ 1752:d6d4c006a7b3

Initial attempt at interrupts in new Z80 core and integrating it into main executable
author Michael Pavone <pavone@retrodev.com>
date Sun, 10 Feb 2019 11:58:23 -0800
parents 5aa0c3c43b97
children 0a26f3657295 7b41cb36e7df
comparison
equal deleted inserted replaced
1751:c5d4e1d14dac 1752:d6d4c006a7b3
7 #include <sys/select.h> 7 #include <sys/select.h>
8 #endif 8 #endif
9 #include "render.h" 9 #include "render.h"
10 #include "util.h" 10 #include "util.h"
11 #include "terminal.h" 11 #include "terminal.h"
12 #include "z80inst.h"
13
14 #ifdef NEW_CORE
15 #define Z80_OPTS opts
16 #else
17 #define Z80_OPTS options
18 #endif
12 19
13 static bp_def * breakpoints = NULL; 20 static bp_def * breakpoints = NULL;
14 static bp_def * zbreakpoints = NULL; 21 static bp_def * zbreakpoints = NULL;
15 static uint32_t bp_index = 0; 22 static uint32_t bp_index = 0;
16 static uint32_t zbp_index = 0; 23 static uint32_t zbp_index = 0;
188 default: 195 default:
189 fprintf(stderr, "Unrecognized format character: %c\n", format_char); 196 fprintf(stderr, "Unrecognized format character: %c\n", format_char);
190 } 197 }
191 switch (param[0]) 198 switch (param[0])
192 { 199 {
200 #ifndef NEW_CORE
193 case 'a': 201 case 'a':
194 if (param[1] == 'f') { 202 if (param[1] == 'f') {
195 if(param[2] == '\'') { 203 if(param[2] == '\'') {
196 value = context->alt_regs[Z80_A] << 8; 204 value = context->alt_regs[Z80_A] << 8;
197 value |= context->alt_flags[ZF_S] << 7; 205 value |= context->alt_flags[ZF_S] << 7;
329 value = context->iff2; 337 value = context->iff2;
330 } else { 338 } else {
331 value = context->im; 339 value = context->im;
332 } 340 }
333 break; 341 break;
342 #endif
334 case 's': 343 case 's':
335 if (param[1] == 'p') { 344 if (param[1] == 'p') {
336 value = context->sp; 345 value = context->sp;
337 } 346 }
338 break; 347 break;
340 if (param[1] == 'x') { 349 if (param[1] == 'x') {
341 uint16_t p_addr = strtol(param+2, NULL, 16); 350 uint16_t p_addr = strtol(param+2, NULL, 16);
342 if (p_addr < 0x4000) { 351 if (p_addr < 0x4000) {
343 value = system->zram[p_addr & 0x1FFF]; 352 value = system->zram[p_addr & 0x1FFF];
344 } else if(p_addr >= 0x8000) { 353 } else if(p_addr >= 0x8000) {
345 uint32_t v_addr = context->bank_reg << 15; 354 uint32_t v_addr = system->z80_bank_reg << 15;
346 v_addr += p_addr & 0x7FFF; 355 v_addr += p_addr & 0x7FFF;
347 if (v_addr < 0x400000) { 356 if (v_addr < 0x400000) {
348 value = system->cart[v_addr/2]; 357 value = system->cart[v_addr/2];
349 } else if(v_addr > 0xE00000) { 358 } else if(v_addr > 0xE00000) {
350 value = system->work_ram[(v_addr & 0xFFFF)/2]; 359 value = system->work_ram[(v_addr & 0xFFFF)/2];
375 if (*this_bp) { 384 if (*this_bp) {
376 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index); 385 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index);
377 } else { 386 } else {
378 zremove_breakpoint(context, address); 387 zremove_breakpoint(context, address);
379 } 388 }
380 uint8_t * pc = get_native_pointer(address, (void **)context->mem_pointers, &context->options->gen); 389 uint8_t * pc = get_native_pointer(address, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
381 if (!pc) { 390 if (!pc) {
382 fatal_error("Failed to get native pointer on entering Z80 debugger at address %X\n", address); 391 fatal_error("Failed to get native pointer on entering Z80 debugger at address %X\n", address);
383 } 392 }
384 for (disp_def * cur = zdisplays; cur; cur = cur->next) { 393 for (disp_def * cur = zdisplays; cur; cur = cur->next) {
385 zdebugger_print(context, cur->format_char, cur->param); 394 zdebugger_print(context, cur->format_char, cur->param);
485 //TODO: Handle conditional branch instructions 494 //TODO: Handle conditional branch instructions
486 if (inst.op == Z80_JP) { 495 if (inst.op == Z80_JP) {
487 if (inst.addr_mode == Z80_IMMED) { 496 if (inst.addr_mode == Z80_IMMED) {
488 after = inst.immed; 497 after = inst.immed;
489 } else if (inst.ea_reg == Z80_HL) { 498 } else if (inst.ea_reg == Z80_HL) {
499 #ifndef NEW_CORE
490 after = context->regs[Z80_H] << 8 | context->regs[Z80_L]; 500 after = context->regs[Z80_H] << 8 | context->regs[Z80_L];
491 } else if (inst.ea_reg == Z80_IX) { 501 } else if (inst.ea_reg == Z80_IX) {
492 after = context->regs[Z80_IXH] << 8 | context->regs[Z80_IXL]; 502 after = context->regs[Z80_IXH] << 8 | context->regs[Z80_IXL];
493 } else if (inst.ea_reg == Z80_IY) { 503 } else if (inst.ea_reg == Z80_IY) {
494 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL]; 504 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL];
505 #endif
495 } 506 }
496 } else if(inst.op == Z80_JR) { 507 } else if(inst.op == Z80_JR) {
497 after += inst.immed; 508 after += inst.immed;
498 } else if(inst.op == Z80_RET) { 509 } else if(inst.op == Z80_RET) {
499 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->options->gen); 510 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
500 if (sp) { 511 if (sp) {
501 after = *sp; 512 after = *sp;
502 sp = get_native_pointer((context->sp + 1) & 0xFFFF, (void **)context->mem_pointers, &context->options->gen); 513 sp = get_native_pointer((context->sp + 1) & 0xFFFF, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
503 if (sp) { 514 if (sp) {
504 after |= *sp << 8; 515 after |= *sp << 8;
505 } 516 }
506 } 517 }
507 } 518 }
525 if (!param) { 536 if (!param) {
526 fputs("s command requires a file name\n", stderr); 537 fputs("s command requires a file name\n", stderr);
527 break; 538 break;
528 } 539 }
529 memmap_chunk const *ram_chunk = NULL; 540 memmap_chunk const *ram_chunk = NULL;
530 for (int i = 0; i < context->options->gen.memmap_chunks; i++) 541 for (int i = 0; i < context->Z80_OPTS->gen.memmap_chunks; i++)
531 { 542 {
532 memmap_chunk const *cur = context->options->gen.memmap + i; 543 memmap_chunk const *cur = context->Z80_OPTS->gen.memmap + i;
533 if (cur->flags & MMAP_WRITE) { 544 if (cur->flags & MMAP_WRITE) {
534 ram_chunk = cur; 545 ram_chunk = cur;
535 break; 546 break;
536 } 547 }
537 } 548 }
538 if (ram_chunk) { 549 if (ram_chunk) {
539 uint32_t size = ram_chunk->end - ram_chunk->start; 550 uint32_t size = ram_chunk->end - ram_chunk->start;
540 if (size > ram_chunk->mask) { 551 if (size > ram_chunk->mask) {
541 size = ram_chunk->mask+1; 552 size = ram_chunk->mask+1;
542 } 553 }
543 uint8_t *buf = get_native_pointer(ram_chunk->start, (void **)context->mem_pointers, &context->options->gen); 554 uint8_t *buf = get_native_pointer(ram_chunk->start, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
544 FILE * f = fopen(param, "wb"); 555 FILE * f = fopen(param, "wb");
545 if (f) { 556 if (f) {
546 if(fwrite(buf, 1, size, f) != size) { 557 if(fwrite(buf, 1, size, f) != size) {
547 fputs("Error writing file\n", stderr); 558 fputs("Error writing file\n", stderr);
548 } 559 }
556 } 567 }
557 break; 568 break;
558 } 569 }
559 default: 570 default:
560 if ( 571 if (
561 !context->options->gen.debug_cmd_handler 572 !context->Z80_OPTS->gen.debug_cmd_handler
562 || !context->options->gen.debug_cmd_handler(&system->header, input_buf) 573 || !context->Z80_OPTS->gen.debug_cmd_handler(&system->header, input_buf)
563 ) { 574 ) {
564 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf); 575 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf);
565 } 576 }
566 break; 577 break;
567 } 578 }