comparison debug.c @ 2506:b0f314b19964

Some more improvements to Z80 step, next and over commands
author Michael Pavone <pavone@retrodev.com>
date Wed, 14 Aug 2024 22:25:20 -0700
parents 927083238a39
children 54ac5fe14cf9
comparison
equal deleted inserted replaced
2505:927083238a39 2506:b0f314b19964
4495 } else if (inst->ea_reg == Z80_IY) { 4495 } else if (inst->ea_reg == Z80_IY) {
4496 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL]; 4496 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL];
4497 #endif 4497 #endif
4498 } 4498 }
4499 #ifndef NEW_CORE 4499 #ifndef NEW_CORE
4500 } else if (inst->op == Z80_JPCC) { 4500 } else if (inst->op == Z80_JPCC || inst->op == Z80_CALLCC) {
4501 uint8_t invert = 0; 4501 uint8_t invert = 0;
4502 uint8_t flag = 0; 4502 uint8_t flag = 0;
4503 switch (inst->reg) 4503 switch (inst->reg)
4504 { 4504 {
4505 case Z80_CC_NZ: 4505 case Z80_CC_NZ:
4549 flag = !flag; 4549 flag = !flag;
4550 } 4550 }
4551 if (flag) { 4551 if (flag) {
4552 after += inst->immed; 4552 after += inst->immed;
4553 } 4553 }
4554 } else if (inst->op == Z80_DJNZ) {
4555 if (context->regs[Z80_B] != 1) {
4556 after += inst->immed;
4557 }
4554 #endif 4558 #endif
4555 } else if(inst->op == Z80_JR) { 4559 } else if(inst->op == Z80_JR) {
4556 after += inst->immed; 4560 after += inst->immed;
4557 } else if(inst->op == Z80_RET) { 4561 } else if(inst->op == Z80_RET) {
4558 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->Z80_OPTS->gen); 4562 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
4569 } 4573 }
4570 4574
4571 static uint8_t cmd_next_z80(debug_root *root, parsed_command *cmd) 4575 static uint8_t cmd_next_z80(debug_root *root, parsed_command *cmd)
4572 { 4576 {
4573 z80inst *inst = root->inst; 4577 z80inst *inst = root->inst;
4578 if (inst->op != Z80_CALL && inst->op != Z80_CALLCC && inst->op != Z80_RST) {
4579 return cmd_step_z80(root, cmd);
4580 }
4574 z80_context *context = root->cpu_context; 4581 z80_context *context = root->cpu_context;
4575 uint32_t after = root->after; 4582 uint32_t after = root->after;
4576 //TODO: handle conditional branches
4577 if (inst->op == Z80_JP) {
4578 if (inst->addr_mode == Z80_IMMED) {
4579 after = inst->immed;
4580 } else if (inst->ea_reg == Z80_HL) {
4581 #ifndef NEW_CORE
4582 after = context->regs[Z80_H] << 8 | context->regs[Z80_L];
4583 } else if (inst->ea_reg == Z80_IX) {
4584 after = context->regs[Z80_IXH] << 8 | context->regs[Z80_IXL];
4585 } else if (inst->ea_reg == Z80_IY) {
4586 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL];
4587 #endif
4588 }
4589 } else if(inst->op == Z80_JR) {
4590 after += inst->immed;
4591 } else if(inst->op == Z80_RET) {
4592 uint8_t *sp = get_native_pointer(context->sp, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
4593 if (sp) {
4594 after = *sp;
4595 sp = get_native_pointer((context->sp + 1) & 0xFFFF, (void **)context->mem_pointers, &context->Z80_OPTS->gen);
4596 if (sp) {
4597 after |= *sp << 8;
4598 }
4599 }
4600 }
4601 zinsert_breakpoint(context, after, (uint8_t *)zdebugger); 4583 zinsert_breakpoint(context, after, (uint8_t *)zdebugger);
4602 return 0; 4584 return 0;
4603 } 4585 }
4604 4586
4605 static uint8_t cmd_over_z80(debug_root *root, parsed_command *cmd) 4587 static uint8_t cmd_over_z80(debug_root *root, parsed_command *cmd)
4611 if (inst->op == Z80_JPCC) { 4593 if (inst->op == Z80_JPCC) {
4612 if (inst->immed < after) { 4594 if (inst->immed < after) {
4613 zinsert_breakpoint(context, inst->immed, (uint8_t *)zdebugger); 4595 zinsert_breakpoint(context, inst->immed, (uint8_t *)zdebugger);
4614 return 0; 4596 return 0;
4615 } 4597 }
4616 } else if (inst->op == Z80_JRCC) { 4598 } else if (inst->op == Z80_JRCC || inst->op == Z80_DJNZ) {
4617 after += inst->immed; 4599 after += inst->immed;
4618 if (after < root->after) { 4600 if (after < root->after) {
4619 zinsert_breakpoint(context, after, (uint8_t *)zdebugger); 4601 zinsert_breakpoint(context, after, (uint8_t *)zdebugger);
4620 return 0; 4602 return 0;
4621 } 4603 }