changeset 1638:f27142c48567

Initial stab at CRAM debug in a detached window
author Michael Pavone <pavone@retrodev.com>
date Wed, 14 Nov 2018 22:16:35 -0800
parents 95880d947257
children 93518786f882
files bindings.c default.cfg vdp.c vdp.h
diffstat 4 files changed, 102 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/bindings.c	Sun Nov 11 22:39:29 2018 -0800
+++ b/bindings.c	Wed Nov 14 22:16:35 2018 -0800
@@ -38,7 +38,8 @@
 	UI_SCREENSHOT,
 	UI_EXIT,
 	UI_PLANE_DEBUG,
-	UI_VRAM_DEBUG
+	UI_VRAM_DEBUG,
+	UI_CRAM_DEBUG,
 } ui_action;
 
 typedef struct {
@@ -375,7 +376,9 @@
 			}
 #endif
 			break;
-		case UI_PLANE_DEBUG: {
+		case UI_PLANE_DEBUG: 
+		case UI_VRAM_DEBUG: 
+		case UI_CRAM_DEBUG: {
 			vdp_context *vdp = NULL;
 			if (current_system->type == SYSTEM_GENESIS) {
 				genesis_context *gen = (genesis_context *)current_system;
@@ -385,21 +388,15 @@
 				vdp = sms->vdp;
 			}
 			if (vdp) {
-				vdp_toggle_debug_view(vdp, VDP_DEBUG_PLANE);
-			}
-			break;
-		}
-		case UI_VRAM_DEBUG: {
-			vdp_context *vdp = NULL;
-			if (current_system->type == SYSTEM_GENESIS) {
-				genesis_context *gen = (genesis_context *)current_system;
-				vdp = gen->vdp;
-			} else if (current_system->type == SYSTEM_SMS) {
-				sms_context *sms = (sms_context *)current_system;
-				vdp = sms->vdp;
-			}
-			if (vdp) {
-				vdp_toggle_debug_view(vdp, VDP_DEBUG_VRAM);
+				uint8_t debug_type;
+				switch(binding->subtype_a)
+				{
+				case UI_PLANE_DEBUG: debug_type = VDP_DEBUG_PLANE; break;
+				case UI_VRAM_DEBUG: debug_type = VDP_DEBUG_VRAM; break;
+				case UI_CRAM_DEBUG: debug_type = VDP_DEBUG_CRAM; break;
+				default: return;
+				}
+				vdp_toggle_debug_view(vdp, debug_type);
 			}
 			break;
 		}
@@ -610,7 +607,9 @@
 			*subtype_a = UI_PLANE_DEBUG;
 		} else if (!strcmp(target + 3, "vram_debug")) {
 			*subtype_a = UI_VRAM_DEBUG;
-		}  else {
+		} else if (!strcmp(target + 3, "cram_debug")) {
+			*subtype_a = UI_CRAM_DEBUG;
+		} else {
 			warning("Unreconized UI binding type %s\n", target);
 			return 0;
 		}
--- a/default.cfg	Sun Nov 11 22:39:29 2018 -0800
+++ b/default.cfg	Wed Nov 14 22:16:35 2018 -0800
@@ -21,6 +21,7 @@
 		p ui.screenshot
 		b ui.plane_debug
 		v ui.vram_debug
+		c ui.cram_debug
 		esc ui.exit
 		` ui.save_state
 		0 ui.set_speed.0
--- a/vdp.c	Sun Nov 11 22:39:29 2018 -0800
+++ b/vdp.c	Wed Nov 14 22:16:35 2018 -0800
@@ -1676,31 +1676,56 @@
 	}
 	last_line = context->cycles;
 #endif
-	context->vcounter++;
-	
+	uint16_t jump_start, jump_end;
 	uint8_t is_mode_5 = context->regs[REG_MODE_2] & BIT_MODE_5;
 	if (is_mode_5) {
 		if (context->flags2 & FLAG2_REGION_PAL) {
 			if (context->regs[REG_MODE_2] & BIT_PAL) {
-				if (context->vcounter == 0x10B) {
-					context->vcounter = 0x1D2;
-				}
-			} else if (context->vcounter == 0x103){
-				context->vcounter = 0x1CA;
+				jump_start = 0x10B;
+				jump_end = 0x1D2;
+			} else {
+				jump_start = 0x103;
+				jump_end = 0x1CA;
 			}
+		} else if (context->regs[REG_MODE_2] & BIT_PAL) {
+			jump_start = 0x100;
+			jump_end = 0x1FA;
 		} else {
-			if (context->regs[REG_MODE_2] & BIT_PAL) {
-				if (context->vcounter == 0x100) {
-					context->vcounter = 0x1FA;
-				}
-			} else if (context->vcounter == 0xEB) {
-				context->vcounter = 0x1E5;
+			jump_start = 0xEB;
+			jump_end = 0x1E5;
+		}
+	} else {
+		jump_start = 0xDB;
+		jump_end = 0x1D5;
+	}
+
+	if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) {
+		uint32_t line = context->vcounter;
+		if (line >= jump_end) {
+			line -= jump_end - jump_start;
+		}
+		uint32_t total_lines = (context->flags2 & FLAG2_REGION_PAL) ? 313 : 262;
+		
+		if (total_lines - line <= context->border_top) {
+			line -= total_lines - context->border_top;
+		} else {
+			line += context->border_top;
+		}
+		uint32_t *fb = context->debug_fbs[VDP_DEBUG_CRAM] + context->debug_fb_pitch[VDP_DEBUG_CRAM] * line / sizeof(uint32_t);
+		for (int i = 0; i < 64; i++)
+		{
+			for (int x = 0; x < 8; x++)
+			{
+				*(fb++) = context->colors[i];
 			}
 		}
-	} else if (context->vcounter == 0xDB) {
-		context->vcounter = 0x1D5;
 	}
-	context->vcounter &= 0x1FF;
+	context->vcounter++;
+	if (context->vcounter == jump_start) {
+		context->vcounter = jump_end;
+	} else {
+		context->vcounter &= 0x1FF;
+	}
 	if (context->state == PREPARING) {
 		context->state = ACTIVE;
 	}
@@ -1849,6 +1874,37 @@
 		
 		render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_VRAM], 1024);
 	}
+	
+	if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) {
+		uint32_t starting_line = 512 - 32*4;
+		uint32_t *line = context->debug_fbs[VDP_DEBUG_CRAM] 
+			+ context->debug_fb_pitch[VDP_DEBUG_CRAM]  * starting_line / sizeof(uint32_t);
+		for (int pal = 0; pal < 4; pal ++)
+		{
+			uint32_t *cur;
+			for (int y = 0; y < 31; y++)
+			{
+				cur = line;
+				for (int offset = 0; offset < 16; offset++)
+				{
+					for (int x = 0; x < 31; x++)
+					{
+						*(cur++) = context->colors[pal * 16 + offset];
+					}
+					*(cur++) = 0xFF000000;
+				}
+				line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t);
+			}
+			cur = line;
+			for (int x = 0; x < 512; x++)
+			{
+				*(cur++) = 0xFF000000;
+			}
+			line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t);
+		}
+		render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_CRAM], 512);
+		context->debug_fbs[VDP_DEBUG_CRAM] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_CRAM], &context->debug_fb_pitch[VDP_DEBUG_CRAM]);
+	}
 }
 
 void vdp_force_update_framebuffer(vdp_context *context)
@@ -3880,6 +3936,7 @@
 		//TODO: implement me
 	} else {
 		uint32_t width,height;
+		uint8_t fetch_immediately = 0;
 		char *caption;
 		switch(debug_type)
 		{
@@ -3892,6 +3949,12 @@
 			width = 1024;
 			height = 512;
 			break;
+		case VDP_DEBUG_CRAM:
+			caption = "BlastEm - VDP CRAM Debugger";
+			width = 512;
+			height = 512;
+			fetch_immediately = 1;
+			break;
 		default:
 			return;
 		}
@@ -3899,6 +3962,9 @@
 		if (context->debug_fb_indices[debug_type]) {
 			context->enabled_debuggers |= 1 << debug_type;
 		}
+		if (fetch_immediately) {
+			context->debug_fbs[debug_type] = render_get_framebuffer(context->debug_fb_indices[debug_type], &context->debug_fb_pitch[debug_type]);
+		}
 	}
 }
 
--- a/vdp.h	Sun Nov 11 22:39:29 2018 -0800
+++ b/vdp.h	Wed Nov 14 22:16:35 2018 -0800
@@ -175,6 +175,8 @@
 	uint32_t    *output;
 	uint32_t    *done_output;
 	uint32_t    *fb;
+	uint32_t    *debug_fbs[VDP_NUM_DEBUG_TYPES];
+	uint32_t    debug_fb_pitch[VDP_NUM_DEBUG_TYPES];
 	system_header  *system;
 	uint16_t    cram[CRAM_SIZE];
 	uint32_t    colors[CRAM_SIZE*4];