From: notaz Date: Fri, 30 Aug 2013 00:54:48 +0000 (+0300) Subject: frontend: new sync code X-Git-Tag: v1.85~2^2~3 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b59172e3d428eb6848e6874861804c79bbc9d1ec;p=picodrive.git frontend: new sync code should fix video drift/desync on pandora --- diff --git a/platform/common/config_file.c b/platform/common/config_file.c index f058fbd8..f8f7fdf1 100644 --- a/platform/common/config_file.c +++ b/platform/common/config_file.c @@ -308,11 +308,6 @@ static int custom_read(menu_entry *me, const char *var, const char *val) return 0; return 1; - case MA_OPT2_GAMMA: - if (strcasecmp(var, "Gamma correction") != 0) return 0; - currentConfig.gamma = (int) (atof(val) * 100.0); - return 1; - case MA_CDOPT_READAHEAD: if (strcasecmp(var, "ReadAhead buffer") != 0) return 0; PicoCDBuffers = atoi(val) / 2; diff --git a/platform/common/emu.c b/platform/common/emu.c index ee216fe2..8bc83af4 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -43,7 +43,7 @@ void *g_screen_ptr; int g_screen_width = 320; int g_screen_height = 240; -char *PicoConfigFile = "config.cfg"; +const char *PicoConfigFile = "config2.cfg"; currentConfig_t currentConfig, defaultConfig; int state_slot = 0; int config_slot = 0, config_slot_current = 0; @@ -1276,31 +1276,26 @@ static void emu_loop_prep(void) filter_old = currentConfig.filter; } +printf("-- gamma %d\n", currentConfig.gamma); plat_target_gamma_set(currentConfig.gamma, 0); pemu_loop_prep(); } -static void skip_frame(int do_audio) -{ - PicoSkipFrame = do_audio ? 1 : 2; - PicoFrame(); - PicoSkipFrame = 0; -} - /* our tick here is 1 us right now */ #define ms_to_ticks(x) (unsigned int)(x * 1000) #define get_ticks() plat_get_ticks_us() void emu_loop(void) { - int pframes_done; /* "period" frames, used for sync */ int frames_done, frames_shown; /* actual frames for fps counter */ - int target_fps, target_frametime; - unsigned int timestamp_base = 0, timestamp_fps; + int target_frametime_x3; + unsigned int timestamp_x3 = 0; + unsigned int timestamp_aim_x3 = 0; + unsigned int timestamp_fps_x3 = 0; char *notice_msg = NULL; char fpsbuff[24]; - int i; + int fskip_cnt = 0; fpsbuff[0] = 0; @@ -1315,45 +1310,47 @@ void emu_loop(void) pemu_sound_start(); /* number of ticks per frame */ - if (Pico.m.pal) { - target_fps = 50; - target_frametime = ms_to_ticks(1000) / 50; - } else { - target_fps = 60; - target_frametime = ms_to_ticks(1000) / 60 + 1; - } + if (Pico.m.pal) + target_frametime_x3 = 3 * ms_to_ticks(1000) / 50; + else + target_frametime_x3 = 3 * ms_to_ticks(1000) / 60; - timestamp_fps = get_ticks(); reset_timing = 1; - - frames_done = frames_shown = pframes_done = 0; - - plat_video_wait_vsync(); + frames_done = frames_shown = 0; /* loop with resync every 1 sec. */ while (engineState == PGS_Running) { - unsigned int timestamp; - int diff, diff_lim; + int skip = 0; + int diff; pprof_start(main); - timestamp = get_ticks(); if (reset_timing) { reset_timing = 0; - timestamp_base = timestamp; - pframes_done = 0; + plat_video_wait_vsync(); + timestamp_aim_x3 = get_ticks() * 3; + timestamp_fps_x3 = timestamp_aim_x3; + fskip_cnt = 0; + } + else if (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) { + timestamp_aim_x3 = get_ticks() * 3; } + timestamp_x3 = get_ticks() * 3; + // show notice_msg message? if (notice_msg_time != 0) { static int noticeMsgSum; - if (timestamp - ms_to_ticks(notice_msg_time) > ms_to_ticks(STATUS_MSG_TIMEOUT)) { + if (timestamp_x3 - ms_to_ticks(notice_msg_time) * 3 + > ms_to_ticks(STATUS_MSG_TIMEOUT) * 3) + { notice_msg_time = 0; plat_status_msg_clear(); notice_msg = NULL; - } else { + } + else { int sum = noticeMsg[0] + noticeMsg[1] + noticeMsg[2]; if (sum != noticeMsgSum) { plat_status_msg_clear(); @@ -1364,7 +1361,7 @@ void emu_loop(void) } // second changed? - if (timestamp - timestamp_fps >= ms_to_ticks(1000)) + if (timestamp_x3 - timestamp_fps_x3 >= ms_to_ticks(1000) * 3) { #ifdef BENCHMARK static int bench = 0, bench_fps = 0, bench_fps_s = 0, bfp = 0, bf[4]; @@ -1382,86 +1379,79 @@ void emu_loop(void) sprintf(fpsbuff, "%02i/%02i ", frames_shown, frames_done); #endif frames_shown = frames_done = 0; - timestamp_fps += ms_to_ticks(1000); + timestamp_fps_x3 += ms_to_ticks(1000) * 3; } #ifdef PFRAMES sprintf(fpsbuff, "%i", Pico.m.frame_count); #endif - if (timestamp - timestamp_base >= ms_to_ticks(1000)) - { - if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && currentConfig.Frameskip >= 0) - pframes_done = 0; - else - pframes_done -= target_fps; - if (pframes_done < -2) { - /* don't drag more than 2 frames behind */ - pframes_done = -2; - timestamp_base = timestamp - 2 * target_frametime; - } - else - timestamp_base += ms_to_ticks(1000); - } - - diff = timestamp - timestamp_base; - diff_lim = (pframes_done + 1) * target_frametime; + diff = timestamp_aim_x3 - timestamp_x3; - if (currentConfig.Frameskip >= 0) // frameskip enabled + if (currentConfig.Frameskip >= 0) // frameskip enabled (or 0) { - for (i = 0; i < currentConfig.Frameskip; i++) { - emu_update_input(); - skip_frame(1); - pframes_done++; frames_done++; - diff_lim += target_frametime; - - if (!(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT))) { - timestamp = get_ticks(); - diff = timestamp - timestamp_base; - if (!reset_timing && diff < diff_lim) // we are too fast - plat_wait_till_us(timestamp_base + diff_lim); - } + if (fskip_cnt < currentConfig.Frameskip) { + fskip_cnt++; + skip = 1; + } + else { + fskip_cnt = 0; } } - else if (diff > diff_lim) + else if (diff < -target_frametime_x3) { /* no time left for this frame - skip */ /* limit auto frameskip to 8 */ - if (frames_done / 8 <= frames_shown) { - emu_update_input(); - skip_frame(diff < diff_lim + target_frametime * 16); - pframes_done++; frames_done++; - continue; - } + if (frames_done / 8 <= frames_shown) + skip = 1; + } + + // don't go in debt too much + while (diff < -target_frametime_x3 * 3) { + timestamp_aim_x3 += target_frametime_x3; + diff = timestamp_aim_x3 - timestamp_x3; } emu_update_input(); - PicoFrame(); - pemu_finalize_frame(fpsbuff, notice_msg); + if (skip) { + int do_audio = diff > -target_frametime_x3 * 2; + PicoSkipFrame = do_audio ? 1 : 2; + PicoFrame(); + PicoSkipFrame = 0; + } + else { + PicoFrame(); + pemu_finalize_frame(fpsbuff, notice_msg); + frames_shown++; + } + frames_done++; + timestamp_aim_x3 += target_frametime_x3; - if (!flip_after_sync) + if (!skip && !flip_after_sync) plat_video_flip(); /* frame limiter */ - if (!reset_timing && !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT))) + if (!skip && !reset_timing + && !(currentConfig.EmuOpt & (EOPT_NO_FRMLIMIT|EOPT_EXT_FRMLIMIT))) { - timestamp = get_ticks(); - diff = timestamp - timestamp_base; + unsigned int timestamp = get_ticks(); + diff = timestamp_aim_x3 - timestamp * 3; // sleep or vsync if we are still too fast - if (diff < diff_lim) - { + if (diff > target_frametime_x3 && (currentConfig.EmuOpt & EOPT_VSYNC)) { // we are too fast - plat_wait_till_us(timestamp_base + diff_lim - target_frametime / 4); - if (currentConfig.EmuOpt & EOPT_VSYNC) - plat_video_wait_vsync(); + plat_video_wait_vsync(); + timestamp = get_ticks(); + diff = timestamp * 3 - timestamp_aim_x3; + } + if (diff > target_frametime_x3) { + // still too fast + plat_wait_till_us(timestamp + (diff - target_frametime_x3) / 3); } } - if (flip_after_sync) + if (!skip && flip_after_sync) plat_video_flip(); - pframes_done++; frames_done++; frames_shown++; - pprof_end(main); } diff --git a/platform/common/emu.h b/platform/common/emu.h index 4a4b4394..93787c77 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -77,7 +77,7 @@ typedef struct _currentConfig_t { } currentConfig_t; extern currentConfig_t currentConfig, defaultConfig; -extern char *PicoConfigFile; +extern const char *PicoConfigFile; extern int state_slot; extern int config_slot, config_slot_current; extern unsigned char *movie_data; diff --git a/platform/common/main.c b/platform/common/main.c index e8f92b9e..52676676 100644 --- a/platform/common/main.c +++ b/platform/common/main.c @@ -19,7 +19,6 @@ #include -extern char *PicoConfigFile; static int load_state_slot = -1; char **g_argv; diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 14274905..8e723ff6 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -927,7 +927,7 @@ static void debug_menu_loop(void) // ------------ main menu ------------ static const char credits[] = - "PicoDrive v" VERSION " (c) notaz, 2006-2011\n\n\n" + "PicoDrive v" VERSION " (c) notaz, 2006-2013\n\n\n" "Credits:\n" "fDave: Cyclone 68000 core,\n" " base code of PicoDrive\n" @@ -935,7 +935,6 @@ static const char credits[] = "MAME devs: YM2612 and SN76496 cores\n" "Inder, ketchupgun: graphics\n" #ifdef __GP2X__ - "rlyeh and others: minimal SDK\n" "Squidge: mmuhack\n" "Dzz: ARM940 sample\n" #endif @@ -944,7 +943,7 @@ static const char credits[] = " Charles MacDonald, Haze,\n" " Stephane Dallongeville,\n" " Lordus, Exophase, Rokas,\n" - " Nemesis, Tasco Deluxe"; + " Eke, Nemesis, Tasco Deluxe"; static void menu_main_draw_status(void) {