# HG changeset patch # User Michael Pavone # Date 1497545121 25200 # Node ID b56c8c51ca5dc10a22f578bc25b2113fd0cec981 # Parent 6a0e3bb6981faee00111e613f1d3e365952a9bbe Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer diff -r 6a0e3bb6981f -r b56c8c51ca5d genesis.c --- a/genesis.c Wed Jun 14 21:59:30 2017 -0700 +++ b/genesis.c Thu Jun 15 09:45:21 2017 -0700 @@ -896,6 +896,7 @@ //Is there any sort of VDP reset? m68k_reset(gen->m68k); } + vdp_release_framebuffer(gen->vdp); } static void start_genesis(system_header *system, char *statefile) @@ -931,6 +932,7 @@ genesis_context *gen = (genesis_context *)system; map_all_bindings(&gen->io); render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC); + vdp_reacquire_framebuffer(gen->vdp); resume_68k(gen->m68k); handle_reset_requests(gen); } diff -r 6a0e3bb6981f -r b56c8c51ca5d sms.c --- a/sms.c Wed Jun 14 21:59:30 2017 -0700 +++ b/sms.c Thu Jun 15 09:45:21 2017 -0700 @@ -226,10 +226,18 @@ target_cycle -= adjust; } } + vdp_release_framebuffer(sms->vdp); sms->should_return = 0; render_enable_ym(); } +static void resume_sms(system_header *system) +{ + sms_context *sms = (sms_context *)system; + vdp_reacquire_framebuffer(sms->vdp); + run_sms(system); +} + static void start_sms(system_header *system, char *statefile) { sms_context *sms = (sms_context *)system; @@ -361,7 +369,7 @@ sms->header.set_speed_percent = set_speed_percent; sms->header.start_context = start_sms; - sms->header.resume_context = run_sms; + sms->header.resume_context = resume_sms; sms->header.load_save = load_save; sms->header.persist_save = persist_save; sms->header.free_context = free_sms; diff -r 6a0e3bb6981f -r b56c8c51ca5d vdp.c --- a/vdp.c Wed Jun 14 21:59:30 2017 -0700 +++ b/vdp.c Thu Jun 15 09:45:21 2017 -0700 @@ -1761,6 +1761,25 @@ } } +void vdp_release_framebuffer(vdp_context *context) +{ + render_framebuffer_updated(context->flags2 & FLAG2_EVEN_FIELD ? FRAMEBUFFER_EVEN: FRAMEBUFFER_ODD, context->h40_lines > (context->inactive_start + context->border_top) / 2 ? LINEBUF_SIZE : (256+HORIZ_BORDER)); + context->output = context->fb = NULL; +} + +void vdp_reacquire_framebuffer(vdp_context *context) +{ + context->fb = render_get_framebuffer(context->flags2 & FLAG2_EVEN_FIELD ? FRAMEBUFFER_EVEN : FRAMEBUFFER_ODD, &context->output_pitch); + uint16_t lines_max = (context->flags2 & FLAG2_REGION_PAL) + ? 240 + BORDER_TOP_V30_PAL + BORDER_BOT_V30_PAL + : 224 + BORDER_TOP_V28 + BORDER_BOT_V28; + if (context->output_lines <= lines_max && context->output_lines > 0) { + context->output = (uint32_t *)(((char *)context->fb) + context->output_pitch * (context->output_lines - 1)); + } else { + context->output = (uint32_t *)(((char *)context->fb) + context->output_pitch * INVALID_LINE); + } +} + static void render_border_garbage(vdp_context *context, uint32_t address, uint8_t *buf, uint8_t buf_off, uint16_t col) { uint8_t base = col >> 9 & 0x30; diff -r 6a0e3bb6981f -r b56c8c51ca5d vdp.h --- a/vdp.h Wed Jun 14 21:59:30 2017 -0700 +++ b/vdp.h Thu Jun 15 09:45:21 2017 -0700 @@ -248,5 +248,7 @@ void write_cram(vdp_context * context, uint16_t address, uint16_t value); void vdp_check_update_sat_byte(vdp_context *context, uint32_t address, uint8_t value); void vdp_pbc_pause(vdp_context *context); +void vdp_release_framebuffer(vdp_context *context); +void vdp_reacquire_framebuffer(vdp_context *context); #endif //VDP_H_