changeset 2179:9a8dd4ba2753

Implement frame advance debugger command
author Michael Pavone <pavone@retrodev.com>
date Sat, 13 Aug 2022 19:37:17 -0700
parents f6d5bde4d07f
children b87658ba3b94
files debug.c genesis.c sms.c sms.h system.h
diffstat 5 files changed, 50 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/debug.c	Sat Aug 13 19:16:30 2022 -0700
+++ b/debug.c	Sat Aug 13 19:37:17 2022 -0700
@@ -1304,6 +1304,12 @@
 	return 1;
 }
 
+static uint8_t cmd_frames(debug_root *root, char *format, int num_args, command_arg *args)
+{
+	current_system->enter_debugger_frames = args[0].value;
+	return 0;
+}
+
 static uint8_t cmd_delete_m68k(debug_root *root, char *format, int num_args, command_arg *args)
 {
 	bp_def **this_bp = find_breakpoint_idx(&root->breakpoints, args[0].value);
@@ -1683,6 +1689,16 @@
 		.min_args = 2,
 		.max_args = 2,
 		.skip_eval = 1
+	},
+	{
+		.names = (const char *[]){
+			"frames", NULL
+		},
+		.usage = "frames EXPRESSION",
+		.desc = "Resume execution for EXPRESSION video frames",
+		.impl = cmd_frames,
+		.min_args = 1,
+		.max_args = 1
 	}
 };
 #define NUM_COMMON (sizeof(common_commands)/sizeof(*common_commands))
--- a/genesis.c	Sat Aug 13 19:16:30 2022 -0700
+++ b/genesis.c	Sat Aug 13 19:37:17 2022 -0700
@@ -460,14 +460,24 @@
 	}
 	if (v_context->frame != gen->last_frame) {
 		//printf("reached frame end %d | MCLK Cycles: %d, Target: %d, VDP cycles: %d, vcounter: %d, hslot: %d\n", gen->last_frame, mclks, gen->frame_end, v_context->cycles, v_context->vcounter, v_context->hslot);
+		uint32_t elapsed = v_context->frame - gen->last_frame;
 		gen->last_frame = v_context->frame;
 		event_flush(mclks);
 		gen->last_flush_cycle = mclks;
+		if (gen->header.enter_debugger_frames) {
+			if (elapsed >= gen->header.enter_debugger_frames) {
+				gen->header.enter_debugger_frames = 0;
+				gen->header.enter_debugger = 1;
+			} else {
+				gen->header.enter_debugger_frames -= elapsed;
+			}
+		}
 
 		if(exit_after){
-			--exit_after;
-			if (!exit_after) {
+			if (elapsed >= exit_after) {
 				exit(0);
+			} else {
+				exit_after -= elapsed;
 			}
 		}
 		if (context->current_cycle > MAX_NO_ADJUST) {
--- a/sms.c	Sat Aug 13 19:16:30 2022 -0700
+++ b/sms.c	Sat Aug 13 19:37:17 2022 -0700
@@ -386,6 +386,26 @@
 			system->delayed_load_slot = 0;
 
 		}
+		if (sms->vdp->frame != sms->last_frame) {
+			uint32_t elapsed = sms->vdp->frame - sms->last_frame;
+			sms->last_frame = sms->vdp->frame;
+			if (system->enter_debugger_frames) {
+				if (elapsed >= system->enter_debugger_frames) {
+					system->enter_debugger_frames = 0;
+					system->enter_debugger = 1;
+				} else {
+					system->enter_debugger_frames -= elapsed;
+				}
+			}
+			
+			if(exit_after){
+				if (elapsed >= exit_after) {
+					exit(0);
+				} else {
+					exit_after -= elapsed;
+				}
+			}
+		}
 		if (system->enter_debugger && sms->z80->pc) {
 			system->enter_debugger = 0;
 			zdebugger(sms->z80, sms->z80->pc);
--- a/sms.h	Sat Aug 13 19:16:30 2022 -0700
+++ b/sms.h	Sat Aug 13 19:37:17 2022 -0700
@@ -24,6 +24,7 @@
 	uint32_t      rom_size;
 	uint32_t      master_clock;
 	uint32_t      normal_clock;
+	uint32_t      last_frame;
 	uint8_t       should_return;
 	uint8_t       ram[SMS_RAM_SIZE];
 	uint8_t       bank_regs[4];
--- a/system.h	Sat Aug 13 19:16:30 2022 -0700
+++ b/system.h	Sat Aug 13 19:37:17 2022 -0700
@@ -69,6 +69,7 @@
 	arena             *arena;
 	char              *next_rom;
 	char              *save_dir;
+	int               enter_debugger_frames;
 	uint8_t           enter_debugger;
 	uint8_t           should_exit;
 	uint8_t           save_state;