forked from meepingsnesroms/libretro-meowPC98
-
Notifications
You must be signed in to change notification settings - Fork 11
/
timing.c
58 lines (42 loc) · 930 Bytes
/
timing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "compiler.h"
#include "pccore.h"
#include "fdd/diskdrv.h"
#include "fdd/fdd_mtr.h"
#include "timing.h"
#define MSSHIFT 16
typedef struct {
UINT32 tick;
UINT32 msstep;
UINT cnt;
UINT32 fraction;
} TIMING;
static TIMING timing;
void timing_reset(void) {
timing.tick = GETTICK();
timing.cnt = 0;
timing.fraction = 0;
}
void timing_setrate(UINT lines, UINT crthz) {
timing.msstep = (crthz << (MSSHIFT - 3)) / lines / (1000 >> 3);
}
void timing_setcount(UINT value) {
timing.cnt = value;
}
UINT timing_getcount(void) {
UINT32 ticknow;
UINT32 span;
UINT32 fraction;
ticknow = GETTICK();
span = ticknow - timing.tick;
if (span) {
timing.tick = ticknow;
fddmtr_callback(ticknow);
if (span >= 1000) {
span = 1000;
}
fraction = timing.fraction + (span * timing.msstep);
timing.cnt += fraction >> MSSHIFT;
timing.fraction = fraction & ((1 << MSSHIFT) - 1);
}
return(timing.cnt);
}