forked from AZO234/NP2kai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timing.c
executable file
·102 lines (79 loc) · 1.8 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <compiler.h>
#include <pccore.h>
#include <fdd/diskdrv.h>
#include <fdd/fdd_mtr.h>
#include <timing.h>
#define MSSHIFT 16
void wabrly_callback(UINT nowtime);
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;
}
#ifdef SUPPORT_WAB
void wabrly_callback(UINT nowtime);
#endif
UINT timing_getcount(void) {
UINT32 ticknow;
UINT32 span;
UINT32 fraction;
ticknow = GETTICK();
span = ticknow - timing.tick;
if (span) {
timing.tick = ticknow;
fddmtr_callback(ticknow);
#ifdef SUPPORT_WAB
wabrly_callback(ticknow);
#endif
if (span >= 1000) {
span = 1000;
}
fraction = timing.fraction + (span * timing.msstep);
timing.cnt += fraction >> MSSHIFT;
timing.fraction = fraction & ((1 << MSSHIFT) - 1);
}
return(timing.cnt);
}
UINT timing_getcount_baseclock(void) {
UINT32 ticknow;
UINT32 span;
UINT32 fraction;
UINT32 ret = 0;
ticknow = GETTICK();
span = ticknow - timing.tick;
if (span) {
if (span >= 1000) {
span = 1000;
}
fraction = timing.fraction + (span * timing.msstep);
ret = timing.cnt + (fraction >> MSSHIFT);
}
return(ret);
}
double timing_getcount_raw(void) {
UINT32 ticknow;
UINT32 span;
UINT32 fraction;
double ret = 0;
ticknow = GETTICK();
span = ticknow - timing.tick;
if (span >= 1000) {
span = 1000;
}
fraction = timing.fraction + (span * timing.msstep);
ret = timing.cnt + ((double)fraction / (1 << MSSHIFT));
return(ret);
}