This commit was generated by cvs2svn to compensate for changes in r2,
[btb/d2x.git] / unused / win95 / timer.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: timer.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
17 #pragma on (unreferenced)
18
19 #include "types.h"
20 #include "fix.h"
21 #include "error.h"
22 #include "mono.h"
23
24 #define _WIN32
25 #define WIN32_LEAN_AND_MEAN
26 #include<windows.h>
27 #include<mmsystem.h>
28
29 #define TARGET_RESOLUTION 1
30
31 //@@ static UINT TimerResolution = 0;
32 //@@ static UINT GameTimer = 0;
33 //@@ #define GAME_TIMER_RESOLUTION (TimerResolution<<1)
34
35
36 int timer_initialized=0;
37
38 static UINT GameSystemTime = 0;
39 static UINT GameStartTime = 0;
40
41
42 void timer_normalize();
43
44 //@@ void PASCAL timer_callback(UINT wTimerID, UINT msg, DWORD dwUser, 
45 //@@                                    DWORD dw1, DWORD dw2) 
46 //@@{
47 //@@    static int last_time = 0;
48 //@@    UINT time;
49 //@@    
50 //@@    
51 //@@    time = timeGetTime()-GameStartTime;
52 //@@
53 //@@    if (timeGetTime() < GameStartTime) 
54 //@@            GameStartTime = GameStartTime - timeGetTime();
55 //@@
56 //@@}
57
58 void timer_normalize()
59 {
60         DWORD new_time;
61
62         new_time = timeGetTime();
63
64         if (new_time < GameStartTime) {
65                 GameStartTime = new_time;
66                 return;
67         }
68         
69         if ((new_time - GameStartTime) > 0x01808580)    // 7 hours
70                 GameStartTime = new_time;
71 }
72
73
74 void timer_close();
75
76 void timer_init(int i)
77 {
78         TIMECAPS tc;
79
80         Assert(GameStartTime == 0);
81
82         timer_initialized = 1;
83
84         GameSystemTime = 0;
85         GameStartTime = timeGetTime();
86
87         atexit(timer_close);
88 }
89
90
91 void timer_close()
92 {
93         Assert(GameStartTime > 0);
94
95         timer_initialized = 0;
96
97         GameSystemTime = 0;
98         GameStartTime= 0;
99 }
100
101
102 fix timer_get_fixed_seconds()
103 {
104         fix val;
105         DWORD time;
106
107         timer_normalize();
108
109         time = timeGetTime() - GameStartTime;
110
111         val = fixdiv(time,1000);
112
113         return val;
114 }
115
116 fix timer_get_fixed_secondsX()
117 {
118         fix val;
119         DWORD time;
120
121         timer_normalize();
122
123         time = timeGetTime() - GameStartTime;
124
125         val = fixdiv(time,1000);
126
127         return val;
128 }
129
130 fix timer_get_approx_seconds()
131 {
132         fix val;
133         DWORD time;
134
135         timer_normalize();
136
137         time = timeGetTime() - GameStartTime;
138
139         val = fixdiv(time,1000);
140
141         return val;
142 }
143
144 void timer_set_function( void _far * function ) {}
145
146
147 void timer_delay(fix seconds)
148 {
149         unsigned int numticks = timeGetTime() + (seconds>>16)*1000 + 
150                                         (((seconds & 0x0000ffff)*1000)/65535);
151         while (GetTickCount() < numticks);
152 }