diff options
author | Michael Pavone <pavone@retrodev.com> | 2018-11-14 22:16:35 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2018-11-14 22:16:35 -0800 |
commit | c4d4fb343ea0c125febe578585b79cf0d3c09a7f (patch) | |
tree | 7cad2ed81248df898a0f4286d28451e84a754ec4 | |
parent | e1a275cbd9a8b620040cf06f24879926dbaf2065 (diff) |
Initial stab at CRAM debug in a detached window
-rw-r--r-- | bindings.c | 35 | ||||
-rw-r--r-- | default.cfg | 1 | ||||
-rw-r--r-- | vdp.c | 98 | ||||
-rw-r--r-- | vdp.h | 2 |
4 files changed, 102 insertions, 34 deletions
@@ -38,7 +38,8 @@ typedef enum { UI_SCREENSHOT, UI_EXIT, UI_PLANE_DEBUG, - UI_VRAM_DEBUG + UI_VRAM_DEBUG, + UI_CRAM_DEBUG, } ui_action; typedef struct { @@ -375,7 +376,9 @@ void handle_binding_up(keybinding * binding) } #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 @@ void handle_binding_up(keybinding * binding) 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 @@ int parse_binding_target(int device_num, char * target, tern_node * padbuttons, *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; } diff --git a/default.cfg b/default.cfg index fec512d..723445a 100644 --- a/default.cfg +++ b/default.cfg @@ -21,6 +21,7 @@ bindings { 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 @@ -1676,31 +1676,56 @@ static void vdp_advance_line(vdp_context *context) } 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 @@ static void vdp_update_per_frame_debug(vdp_context *context) 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 @@ void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type) //TODO: implement me } else { uint32_t width,height; + uint8_t fetch_immediately = 0; char *caption; switch(debug_type) { @@ -3892,6 +3949,12 @@ void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type) 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 @@ void vdp_toggle_debug_view(vdp_context *context, uint8_t debug_type) 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]); + } } } @@ -175,6 +175,8 @@ typedef struct { 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]; |