aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgameblabla2019-10-20 03:20:08 +0200
committergameblabla2019-10-20 03:20:08 +0200
commit1a51fa791356b52a88e8ae0e6941034b23cd354f (patch)
treed65c6ced010ab55c8207229bc0fd2ff69bf0bf41
parentb029a0b25f2f0cf9775f6f720756760e1f6c6438 (diff)
downloadsnesemu-1a51fa791356b52a88e8ae0e6941034b23cd354f.tar.gz
snesemu-1a51fa791356b52a88e8ae0e6941034b23cd354f.tar.bz2
snesemu-1a51fa791356b52a88e8ae0e6941034b23cd354f.zip
Improve frameskipping code. (to be tested)
-rw-r--r--shell/emu/core.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/shell/emu/core.c b/shell/emu/core.c
index be99e72..e20e43d 100644
--- a/shell/emu/core.c
+++ b/shell/emu/core.c
@@ -255,12 +255,40 @@ void SaveState(char* path, uint_fast8_t state)
if (buffer) free(buffer);
}
+
+#ifdef FRAMESKIP
+static uint32_t Timer_Read(void)
+{
+ /* Timing. */
+ struct timeval tval;
+ gettimeofday(&tval, 0);
+ return (((tval.tv_sec*1000000) + (tval.tv_usec)));
+}
+static long lastTick = 0, newTick;
+static uint32_t SkipCnt = 0, video_frames = 0, FPS = 60, FrameSkip;
+static const uint32_t TblSkip[4][4] = {
+ {0, 0, 0, 0},
+ {0, 0, 0, 1},
+ {0, 0, 1, 1},
+ {0, 1, 1, 1}
+};
+#endif
+
void Emulation_Run (void)
{
#ifndef USE_BLARGG_APU
static int16_t audio_buf[2048];
#endif
+
+#ifdef FRAMESKIP
+ SkipCnt++;
+ if (SkipCnt > 3) SkipCnt = 0;
+ if (TblSkip[FrameSkip][SkipCnt]) IPPU.RenderThisFrame = false;
+ else IPPU.RenderThisFrame = true;
+#else
IPPU.RenderThisFrame = true;
+#endif
+
#ifdef USE_BLARGG_APU
S9xSetSoundMute(false);
#endif
@@ -295,6 +323,26 @@ void Emulation_Run (void)
IPPU.RenderThisFrame = true;
}
#endif
+
+#ifdef FRAMESKIP
+ video_frames++;
+ newTick = Timer_Read();
+ if ( (newTick) - (lastTick) > 1000000)
+ {
+ FPS = video_frames;
+ video_frames = 0;
+ lastTick = newTick;
+ if (FPS >= 60)
+ {
+ FrameSkip = 0;
+ }
+ else
+ {
+ FrameSkip = 60 / FPS;
+ if (FrameSkip > 3) FrameSkip = 3;
+ }
+ }
+#endif
}