# HG changeset patch # User Michael Pavone # Date 1541823369 28800 # Node ID e397766c30286adba7e9a78b9b7d1ca5c4136078 # Parent 9b7cba9ba541e7bb9585218abfb97d6c9ab961ab Added VRAM debug window diff -r 9b7cba9ba541 -r e397766c3028 bindings.c --- a/bindings.c Fri Nov 09 09:26:07 2018 -0800 +++ b/bindings.c Fri Nov 09 20:16:09 2018 -0800 @@ -37,7 +37,8 @@ UI_SMS_PAUSE, UI_SCREENSHOT, UI_EXIT, - UI_PLANE_DEBUG + UI_PLANE_DEBUG, + UI_VRAM_DEBUG } ui_action; typedef struct { @@ -388,6 +389,20 @@ } 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); + } + break; + } } break; } @@ -593,7 +608,9 @@ *subtype_a = UI_EXIT; } else if (!strcmp(target + 3, "plane_debug")) { *subtype_a = UI_PLANE_DEBUG; - } else { + } else if (!strcmp(target + 3, "vram_debug")) { + *subtype_a = UI_VRAM_DEBUG; + } else { warning("Unreconized UI binding type %s\n", target); return 0; } diff -r 9b7cba9ba541 -r e397766c3028 default.cfg --- a/default.cfg Fri Nov 09 09:26:07 2018 -0800 +++ b/default.cfg Fri Nov 09 20:16:09 2018 -0800 @@ -20,6 +20,7 @@ u ui.enter_debugger p ui.screenshot b ui.plane_debug + v ui.vram_debug esc ui.exit ` ui.save_state 0 ui.set_speed.0 diff -r 9b7cba9ba541 -r e397766c3028 vdp.c --- a/vdp.c Fri Nov 09 09:26:07 2018 -0800 +++ b/vdp.c Fri Nov 09 20:16:09 2018 -0800 @@ -1824,6 +1824,35 @@ } render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_PLANE], 1024); } + + if (context->enabled_debuggers & (1 << VDP_DEBUG_VRAM)) { + uint32_t pitch; + uint32_t *fb = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_VRAM], &pitch); + + uint8_t pal = (context->debug_modes[VDP_DEBUG_VRAM] % 4) << 4; + for (int y = 0; y < 512; y++) + { + uint32_t *line = fb + y * pitch / sizeof(uint32_t); + int row = y >> 4; + int yoff = y >> 1 & 7; + for (int col = 0; col < 64; col++) + { + uint16_t address = (row * 64 + col) * 32 + yoff * 4; + for (int x = 0; x < 4; x++) + { + uint8_t byte = context->vdpmem[address++]; + uint8_t left = byte >> 4 | pal; + uint8_t right = byte & 0xF | pal; + *(line++) = context->colors[left]; + *(line++) = context->colors[left]; + *(line++) = context->colors[right]; + *(line++) = context->colors[right]; + } + } + } + + render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_VRAM], 1024); + } } void vdp_force_update_framebuffer(vdp_context *context) @@ -3854,16 +3883,23 @@ if (context->enabled_debuggers & 1 << debug_type) { //TODO: implement me } else { + uint32_t width,height; char *caption; switch(debug_type) { case VDP_DEBUG_PLANE: caption = "BlastEm - VDP Plane Debugger"; + width = height = 1024; + break; + case VDP_DEBUG_VRAM: + caption = "BlastEm - VDP VRAM Debugger"; + width = 1024; + height = 512; break; default: return; } - context->debug_fb_indices[debug_type] = render_create_window(caption, 1024, 1024); + context->debug_fb_indices[debug_type] = render_create_window(caption, width, height); if (context->debug_fb_indices[debug_type]) { context->enabled_debuggers |= 1 << debug_type; }