c62d2810 |
1 | #include <sys/time.h> |
2 | #include "main.h" |
3 | #include "throttle.h" |
4 | |
5 | static uint64 tfreq; |
6 | static uint64 desiredfps; |
7 | |
8 | void RefreshThrottleFPS(void) |
9 | { |
5232c20c |
10 | uint64 f=FCEUI_GetDesiredFPS(); |
11 | // great, a bit faster than before |
12 | //f = (f*65) >> 6; |
13 | desiredfps=f>>8; |
c62d2810 |
14 | tfreq=1000000; |
15 | tfreq<<=16; /* Adjustment for fps returned from FCEUI_GetDesiredFPS(). */ |
16 | } |
17 | |
18 | static uint64 GetCurTime(void) |
19 | { |
20 | uint64 ret; |
21 | struct timeval tv; |
22 | |
23 | gettimeofday(&tv,0); |
24 | ret=(uint64)tv.tv_sec*1000000; |
25 | ret+=tv.tv_usec; |
26 | return(ret); |
27 | } |
28 | |
5232c20c |
29 | INLINE void SpeedThrottle(void) |
c62d2810 |
30 | { |
31 | static uint64 ttime,ltime; |
32 | |
33 | waiter: |
34 | |
35 | ttime=GetCurTime(); |
36 | |
37 | if( (ttime-ltime) < (tfreq/desiredfps) ) |
5232c20c |
38 | { |
c62d2810 |
39 | goto waiter; |
5232c20c |
40 | } |
c62d2810 |
41 | if( (ttime-ltime) >= (tfreq*4/desiredfps)) |
42 | ltime=ttime; |
43 | else |
44 | ltime+=tfreq/desiredfps; |
45 | } |
46 | |