initial fce ultra 0.81 import
[fceu.git] / drivers / cli / throttle.c
CommitLineData
c62d2810 1#include <sys/time.h>
2#include "main.h"
3#include "throttle.h"
4
5static uint64 tfreq;
6static uint64 desiredfps;
7
8void RefreshThrottleFPS(void)
9{
10 desiredfps=FCEUI_GetDesiredFPS()>>8;
11 tfreq=1000000;
12 tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */
13}
14
15static uint64 GetCurTime(void)
16{
17 uint64 ret;
18 struct timeval tv;
19
20 gettimeofday(&tv,0);
21 ret=(uint64)tv.tv_sec*1000000;
22 ret+=tv.tv_usec;
23 return(ret);
24}
25
26void SpeedThrottle(void)
27{
28 static uint64 ttime,ltime;
29
30 waiter:
31
32 ttime=GetCurTime();
33
34 if( (ttime-ltime) < (tfreq/desiredfps) )
35 goto waiter;
36 if( (ttime-ltime) >= (tfreq*4/desiredfps))
37 ltime=ttime;
38 else
39 ltime+=tfreq/desiredfps;
40}
41