From fbee2cafe073276de9a3ed66001be7fadfc5db00 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 5 May 2018 18:50:53 +0300 Subject: [PATCH] Lagless vsync updates --- custom.cpp | 25 +++--- events.cpp | 226 +++++++++++++++++++++++++++++------------------------ 2 files changed, 135 insertions(+), 116 deletions(-) diff --git a/custom.cpp b/custom.cpp index d84aba1c..528283e4 100644 --- a/custom.cpp +++ b/custom.cpp @@ -8276,6 +8276,14 @@ static void linesync_first_last_line(int *first, int *last) *first += y; } +static int vsyncnextscanline; +static int vsyncnextscanline_add; +static int nextwaitvpos; +static int display_slice_cnt; +static int display_slice_lines; +static int display_slices; +static bool display_rendered; + static bool linesync_beam_single(void) { frame_time_t maxtime = read_processor_time() + 2 * vsynctimebase; @@ -8315,12 +8323,6 @@ static bool linesync_beam_single(void) static bool linesync_beam_multi_dual(void) { frame_time_t maxtime = read_processor_time() + 2 * vsynctimebase; - static int vsyncnextscanline; - static int nextwaitvpos; - static int display_slice_cnt; - static int display_slice_lines; - static int display_slices; - static bool display_rendered; bool input_read_done = false; bool was_syncline = is_syncline != 0; @@ -8422,13 +8424,6 @@ static bool linesync_beam_multi_dual(void) static bool linesync_beam_multi_single(void) { frame_time_t maxtime = read_processor_time() + 2 * vsynctimebase; - static int vsyncnextscanline; - static int vsyncnextscanline_add; - static int nextwaitvpos; - static int display_slice_cnt; - static int display_slice_lines; - static int display_slices; - static bool display_rendered; bool input_read_done = false; bool was_syncline = is_syncline != 0; @@ -8647,6 +8642,10 @@ static bool linesync_beam_multi_single(void) // called when extra CPU wait is done void vsync_event_done(void) { + if (!isvsync_chipset()) { + is_syncline = 0; + return; + } if (currprefs.gfx_display_sections <= 1) { linesync_beam_single(); } else { diff --git a/events.cpp b/events.cpp index 3819b216..c496fcde 100644 --- a/events.cpp +++ b/events.cpp @@ -52,59 +52,126 @@ void events_schedule (void) extern void vsync_event_done(void); extern int vsync_activeheight; -void do_cycles_slow (unsigned long cycles_to_add) +static bool event_check_vsync(void) { -#ifdef WITH_X86 - if (x86_turbo_on) { - execute_other_cpu_single(); - } + /* Keep only CPU emulation running while waiting for sync point. */ + if (is_syncline == -1) { + + if (!isvsync_chipset()) { + is_syncline = 0; + return false; + } + // wait for vblank + audio_finish_pull(); + int done = vsync_isdone(NULL); + if (!done) { +#ifdef WITH_PPC + if (ppc_state) { + if (is_syncline == 1) { + uae_ppc_execute_check(); + } else { + uae_ppc_execute_quick(); + } + } #endif + if (currprefs.cachesize) + pissoff = pissoff_value; + else + pissoff = pissoff_nojit_value; + return true; + } + vsync_clear(); + vsync_event_done(); - if ((pissoff -= cycles_to_add) >= 0) - return; + } else if (is_syncline == -2) { - cycles_to_add = -pissoff; - pissoff = 0; + if (!isvsync_chipset()) { + is_syncline = 0; + return false; + } + // wait for vblank or early vblank + audio_finish_pull(); + int done = vsync_isdone(NULL); + int vp = target_get_display_scanline(-1); + if (vp < 0 || vp >= is_syncline_end) + done = true; + if (!done) { +#ifdef WITH_PPC + if (ppc_state) { + if (is_syncline == 1) { + uae_ppc_execute_check(); + } else { + uae_ppc_execute_quick(); + } + } +#endif + if (currprefs.cachesize) + pissoff = pissoff_value; + else + pissoff = pissoff_nojit_value; + return true; + } + vsync_clear(); + vsync_event_done(); - while ((nextevent - currcycle) <= cycles_to_add) { + } else if (is_syncline > 0) { + + if (!isvsync_chipset()) { + is_syncline = 0; + return false; + } + audio_finish_pull(); + // wait for specific scanline + int vp = target_get_display_scanline(-1); + if (vp < 0 || is_syncline > vp) { +#ifdef WITH_PPC + if (ppc_state) { + uae_ppc_execute_check(); + } +#endif + if (currprefs.cachesize) + pissoff = pissoff_value; + else + pissoff = pissoff_nojit_value; + return true; + } + vsync_event_done(); - /* Keep only CPU emulation running while waiting for sync point. */ - if (is_syncline == -1) { + } else if (is_syncline == -10) { - // wait for vblank - audio_finish_pull(); - int done = vsync_isdone(NULL); - if (!done) { + // wait is_syncline_end + if (event_wait) { + int rpt = read_processor_time(); + int v = rpt - is_syncline_end; + if (v < 0) { #ifdef WITH_PPC if (ppc_state) { - if (is_syncline == 1) { - uae_ppc_execute_check(); - } else { - uae_ppc_execute_quick(); - } + uae_ppc_execute_check(); } #endif if (currprefs.cachesize) pissoff = pissoff_value; else pissoff = pissoff_nojit_value; - return; + return true; } - vsync_clear(); - vsync_event_done(); - - } else if (is_syncline == -2) { - - // wait for vblank or early vblank - audio_finish_pull(); - int done = vsync_isdone(NULL); - int vp = target_get_display_scanline(-1); - if (vp < 0 || vp >= is_syncline_end) - done = true; - if (!done) { + } + is_syncline = 0; + + } else if (is_syncline < -10) { + + // wait is_syncline_end/vsyncmintime + if (event_wait) { + int rpt = read_processor_time(); + int v = rpt - vsyncmintime; + int v2 = rpt - is_syncline_end; + if (v > vsynctimebase || v < -vsynctimebase) { + v = 0; + } + if (v < 0 && v2 < 0) { #ifdef WITH_PPC if (ppc_state) { - if (is_syncline == 1) { + if (is_syncline == -11) { uae_ppc_execute_check(); } else { uae_ppc_execute_quick(); @@ -115,80 +182,33 @@ void do_cycles_slow (unsigned long cycles_to_add) pissoff = pissoff_value; else pissoff = pissoff_nojit_value; - return; + return true; } - vsync_clear(); - vsync_event_done(); - - } else if (is_syncline > 0) { + } + is_syncline = 0; + } + return false; +} - audio_finish_pull(); - // wait for specific scanline - int vp = target_get_display_scanline(-1); - if (vp < 0 || is_syncline > vp) { -#ifdef WITH_PPC - if (ppc_state) { - uae_ppc_execute_check(); - } +void do_cycles_slow (unsigned long cycles_to_add) +{ +#ifdef WITH_X86 + if (x86_turbo_on) { + execute_other_cpu_single(); + } #endif - if (currprefs.cachesize) - pissoff = pissoff_value; - else - pissoff = pissoff_nojit_value; - return; - } - vsync_event_done(); - } else if (is_syncline == -10) { + if ((pissoff -= cycles_to_add) >= 0) + return; - // wait is_syncline_end - if (event_wait) { - int rpt = read_processor_time(); - int v = rpt - is_syncline_end; - if (v < 0) { -#ifdef WITH_PPC - if (ppc_state) { - uae_ppc_execute_check(); - } -#endif - if (currprefs.cachesize) - pissoff = pissoff_value; - else - pissoff = pissoff_nojit_value; - return; - } - } - is_syncline = 0; - - } else if (is_syncline < -10) { - - // wait is_syncline_end/vsyncmintime - if (event_wait) { - int rpt = read_processor_time(); - int v = rpt - vsyncmintime; - int v2 = rpt - is_syncline_end; - if (v > vsynctimebase || v < -vsynctimebase) { - v = 0; - } - if (v < 0 && v2 < 0) { -#ifdef WITH_PPC - if (ppc_state) { - if (is_syncline == -11) { - uae_ppc_execute_check(); - } else { - uae_ppc_execute_quick(); - } - } -#endif - if (currprefs.cachesize) - pissoff = pissoff_value; - else - pissoff = pissoff_nojit_value; - return; - } - } - is_syncline = 0; + cycles_to_add = -pissoff; + pissoff = 0; + while ((nextevent - currcycle) <= cycles_to_add) { + + if (is_syncline) { + if (event_check_vsync()) + return; } cycles_to_add -= nextevent - currcycle; -- 2.47.3