# HG changeset patch # User Michael Pavone # Date 1503382116 25200 # Node ID 40c3be9f1af70640f4a727a2ac799158526805d6 # Parent 178de1432291285a537508ce1738e2862ea61e47 Fix timing of VDP ODD flag toggle diff -r 178de1432291 -r 40c3be9f1af7 vdp.c --- a/vdp.c Wed Aug 16 21:04:28 2017 -0700 +++ b/vdp.c Mon Aug 21 23:08:36 2017 -0700 @@ -149,6 +149,7 @@ context->output = malloc(LINEBUF_SIZE * sizeof(uint32_t)); context->output_pitch = 0; } else { + context->cur_buffer = FRAMEBUFFER_ODD; context->fb = render_get_framebuffer(FRAMEBUFFER_ODD, &context->output_pitch); } context->linebuf = malloc(LINEBUF_SIZE + SCROLL_BUFFER_SIZE*2); @@ -1729,11 +1730,9 @@ : 224 + BORDER_TOP_V28 + BORDER_BOT_V28; if (context->output_lines == lines_max) { - 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)); - if (context->double_res) { - context->flags2 ^= FLAG2_EVEN_FIELD; - } - context->fb = render_get_framebuffer(context->flags2 & FLAG2_EVEN_FIELD ? FRAMEBUFFER_EVEN : FRAMEBUFFER_ODD, &context->output_pitch); + render_framebuffer_updated(context->cur_buffer, context->h40_lines > (context->inactive_start + context->border_top) / 2 ? LINEBUF_SIZE : (256+HORIZ_BORDER)); + context->cur_buffer = context->flags2 & FLAG2_EVEN_FIELD ? FRAMEBUFFER_EVEN : FRAMEBUFFER_ODD; + context->fb = render_get_framebuffer(context->cur_buffer, &context->output_pitch); context->h40_lines = 0; context->frame++; context->output_lines = 0; @@ -1771,13 +1770,13 @@ 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)); + render_framebuffer_updated(context->cur_buffer, 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); + context->fb = render_get_framebuffer(context->cur_buffer, &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; @@ -2825,6 +2824,8 @@ } else if (context->vcounter == vint_line && context->hslot == vint_slot) { context->flags2 |= FLAG2_VINT_PENDING; context->pending_vint_start = context->cycles; + } else if (context->vcounter == context->inactive_start && context->hslot == 1 && (context->regs[REG_MODE_4] & BIT_INTERLACE)) { + context->flags2 ^= FLAG2_EVEN_FIELD; } if (dst) { diff -r 178de1432291 -r 40c3be9f1af7 vdp.h --- a/vdp.h Wed Aug 16 21:04:28 2017 -0700 +++ b/vdp.h Mon Aug 21 23:08:36 2017 -0700 @@ -209,6 +209,7 @@ uint8_t debug_pal; uint8_t pending_byte; uint8_t state; + uint8_t cur_buffer; uint8_t *tmp_buf_a; uint8_t *tmp_buf_b; } vdp_context;