vsync bugfix + refactoring
[picodrive.git] / platform / common / emu.c
index 4341d6a..118dc38 100644 (file)
@@ -1276,9 +1276,6 @@ void emu_loop(void)
        if (PicoAHW & PAHW_MCD)\r
                PicoCDBufferInit();\r
 \r
-       if (currentConfig.EmuOpt & EOPT_PSYNC)\r
-               plat_video_wait_vsync();\r
-\r
        pemu_loop_prep();\r
 \r
        timestamp_fps = get_ticks();\r
@@ -1286,6 +1283,8 @@ void emu_loop(void)
 \r
        frames_done = frames_shown = pframes_done = 0;\r
 \r
+       plat_video_wait_vsync();\r
+\r
        /* loop with resync every 1 sec. */\r
        while (engineState == PGS_Running)\r
        {\r
@@ -1414,12 +1413,9 @@ void emu_loop(void)
                        if (diff < diff_lim)\r
                        {\r
                                // we are too fast\r
-                               if (currentConfig.EmuOpt & EOPT_PSYNC) {\r
-                                       if (diff_lim - diff > target_frametime/2)\r
-                                               plat_wait_till_us(timestamp_base + target_frametime/4);\r
+                               plat_wait_till_us(timestamp_base + diff_lim - target_frametime / 4);\r
+                               if (currentConfig.EmuOpt & EOPT_VSYNC)\r
                                        plat_video_wait_vsync();\r
-                               } else\r
-                                       plat_wait_till_us(timestamp_base + diff_lim);\r
                        }\r
                }\r
 \r