X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=f43f9b72b4d3c8d50d867169669fbf9a1a6de945;hb=0d0558bde90234a0413433f743cd85aee645eeef;hp=632ad1805cac7a3578acf0ca4c76b061d68a9d91;hpb=d032c15a906f1d54f49648847b996ce5ed4362e6;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index 632ad18..f43f9b7 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -54,13 +54,14 @@ extern int crashed_940; static short sndBuffer[2*44100/50]; static char noticeMsg[64]; // notice msg to draw static struct timeval noticeMsgTime = { 0, 0 }; // when started showing -static int reset_timing, osd_fps_x; +static int osd_fps_x; static int combo_keys = 0, combo_acts = 0; // keys and actions which need button combos static int gp2x_old_gamma = 100; static unsigned char *movie_data = NULL; static int movie_size = 0; unsigned char *framebuff = 0; // temporary buffer for alt renderer int state_slot = 0; +int reset_timing = 0; /* // tmp @@ -789,6 +790,9 @@ static void emu_msg_cb(const char *msg) } gettimeofday(¬iceMsgTime, 0); noticeMsgTime.tv_sec -= 2; + + /* assumption: emu_msg_cb gets called only when something slow is about to happen */ + reset_timing = 1; } static void emu_state_cb(const char *str) @@ -969,13 +973,15 @@ static void updateSound(int len) { if (PicoOpt&8) len<<=1; - gp2x_sound_write(PsndOut, len<<1); + /* avoid writing audio when lagging behind to prevent audio lag */ + if (PicoSkipFrame != 2) + gp2x_sound_write(PsndOut, len<<1); } -static void SkipFrame(void) +static void SkipFrame(int do_audio) { - PicoSkipFrame=1; + PicoSkipFrame=do_audio ? 1 : 2; PicoFrame(); PicoSkipFrame=0; } @@ -987,7 +993,6 @@ void emu_forced_frame(void) PicoOpt |= 0x10; PicoFrameFull(); - PicoOpt = po_old; if (!(Pico.video.reg[12]&1)) { vidCpyM2 = vidCpyM2_32col; @@ -997,6 +1002,8 @@ void emu_forced_frame(void) vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8); vidConvCpyRGB32(localPal, Pico.cram, 0x40); gp2x_video_setpalette(localPal, 0x40); + + PicoOpt = po_old; } static void simpleWait(int thissec, int lim_time) @@ -1156,7 +1163,7 @@ void emu_Loop(void) // when second changes, but we don't want buffer to starve. if(PsndOut && frames_done < target_fps && frames_done > target_fps-5) { updateKeys(); - SkipFrame(); frames_done++; + SkipFrame(1); frames_done++; } frames_done -= target_fps; if (frames_done < 0) frames_done = 0; @@ -1164,12 +1171,14 @@ void emu_Loop(void) if (frames_shown > frames_done) frames_shown = frames_done; } } - +#if 0 + sprintf(fpsbuff, "%05i", Pico.m.frame_count); +#endif lim_time = (frames_done+1) * target_frametime; if(currentConfig.Frameskip >= 0) { // frameskip enabled for(i = 0; i < currentConfig.Frameskip; i++) { updateKeys(); - SkipFrame(); frames_done++; + SkipFrame(1); frames_done++; if (PsndOut) { // do framelimitting if sound is enabled gettimeofday(&tval, 0); if(thissec != tval.tv_sec) tval.tv_usec+=1000000; @@ -1188,7 +1197,7 @@ void emu_Loop(void) continue; } updateKeys(); - SkipFrame(/*tval.tv_usec < lim_time+target_frametime*/); frames_done++; + SkipFrame(tval.tv_usec < lim_time+target_frametime*2); frames_done++; continue; }