1 | /* $Id: time.cpp,v 1.15 2001-11-22 15:40:46 phaller Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Timer MM apis
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | * Copyright 1999 Patrick Haller (phaller@gmx.net)
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 |
|
---|
14 | /****************************************************************************
|
---|
15 | * Includes *
|
---|
16 | ****************************************************************************/
|
---|
17 | #include <os2win.h>
|
---|
18 | #include <odinwrap.h>
|
---|
19 | #include <misc.h>
|
---|
20 | #include <handlemanager.h>
|
---|
21 |
|
---|
22 | #include "os2timer.h"
|
---|
23 | #include "time.h"
|
---|
24 |
|
---|
25 | #define DBG_LOCALLOG DBG_time
|
---|
26 | #include "dbglocal.h"
|
---|
27 |
|
---|
28 | ODINDEBUGCHANNEL(WINMM-TIME)
|
---|
29 |
|
---|
30 |
|
---|
31 | /*****************************************************************************
|
---|
32 | * Name : mmsystemGetVersion
|
---|
33 | * Purpose : determine version of MM system
|
---|
34 | * Parameters:
|
---|
35 | * Variables :
|
---|
36 | * Result :
|
---|
37 | * Remark :
|
---|
38 | * Status : UNTESTED STUB
|
---|
39 | *
|
---|
40 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
41 | *****************************************************************************/
|
---|
42 |
|
---|
43 |
|
---|
44 | ODINFUNCTION0(UINT, mmsystemGetVersion)
|
---|
45 | {
|
---|
46 | //Returned by winmm.dll from NT4, SP6
|
---|
47 | return 0x030A;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /*****************************************************************************
|
---|
51 | * Name :
|
---|
52 | * Purpose :
|
---|
53 | * Parameters:
|
---|
54 | * Variables :
|
---|
55 | * Result :
|
---|
56 | * Remark :
|
---|
57 | * Status : UNTESTED STUB
|
---|
58 | *
|
---|
59 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
60 | *****************************************************************************/
|
---|
61 |
|
---|
62 | ODINFUNCTION2(MMRESULT, timeGetDevCaps,
|
---|
63 | LPTIMECAPS, ptc,
|
---|
64 | UINT, cbtc)
|
---|
65 | {
|
---|
66 | dprintf(("WINMM:timeGetDevCaps Not really Implemented\n"));
|
---|
67 |
|
---|
68 | /* 2001-09-16 PH
|
---|
69 | add dynamic detection of OS/2's minimum timer resolution
|
---|
70 | */
|
---|
71 |
|
---|
72 | ptc->wPeriodMin = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
73 | ptc->wPeriodMax = OS2TIMER_RESOLUTION_MAXIMUM;
|
---|
74 |
|
---|
75 | return TIMERR_NOERROR;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | /*****************************************************************************
|
---|
80 | * Name :
|
---|
81 | * Purpose :
|
---|
82 | * Parameters:
|
---|
83 | * Variables :
|
---|
84 | * Result :
|
---|
85 | * Remark :
|
---|
86 | * Status : UNTESTED STUB
|
---|
87 | *
|
---|
88 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
89 | *****************************************************************************/
|
---|
90 |
|
---|
91 | ODINFUNCTION1(MMRESULT, timeBeginPeriod,
|
---|
92 | UINT, cMilliseconds)
|
---|
93 | {
|
---|
94 | if (TRUE == OS2TimerResolution::enterResolutionScope(cMilliseconds))
|
---|
95 | return TIMERR_NOERROR;
|
---|
96 | else
|
---|
97 | return TIMERR_NOCANDO;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /*****************************************************************************
|
---|
102 | * Name :
|
---|
103 | * Purpose :
|
---|
104 | * Parameters:
|
---|
105 | * Variables :
|
---|
106 | * Result :
|
---|
107 | * Remark :
|
---|
108 | * Status : UNTESTED STUB
|
---|
109 | *
|
---|
110 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
111 | *****************************************************************************/
|
---|
112 |
|
---|
113 | ODINFUNCTION1(MMRESULT, timeEndPeriod,
|
---|
114 | UINT, cMilliseconds)
|
---|
115 | {
|
---|
116 | if (TRUE == OS2TimerResolution::leaveResolutionScope(cMilliseconds))
|
---|
117 | return TIMERR_NOERROR;
|
---|
118 | else
|
---|
119 | {
|
---|
120 | dprintf(("WINMM: timeEndPeriod didn't match timeBeginPeriod.\n"));
|
---|
121 | return TIMERR_NOCANDO;
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /*****************************************************************************
|
---|
127 | * Name :
|
---|
128 | * Purpose :
|
---|
129 | * Parameters:
|
---|
130 | * Variables :
|
---|
131 | * Result :
|
---|
132 | * Remark :
|
---|
133 | * Status : UNTESTED STUB
|
---|
134 | *
|
---|
135 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
136 | *****************************************************************************/
|
---|
137 |
|
---|
138 | ODINFUNCTION1(MMRESULT, timeKillEvent,
|
---|
139 | UINT, IDEvent)
|
---|
140 | {
|
---|
141 | OS2Timer *os2timer = NULL;
|
---|
142 |
|
---|
143 | if(HMHandleTranslateToOS2(IDEvent, (PULONG)&os2timer) != NO_ERROR) {
|
---|
144 | dprintf(("invalid timer id"));
|
---|
145 | return TIMERR_NOERROR; //TODO: should we return an error here??
|
---|
146 | }
|
---|
147 | HMHandleFree(IDEvent);
|
---|
148 | // return OS2Timer::killEvent(UINT IDEvent)
|
---|
149 |
|
---|
150 | delete os2timer;
|
---|
151 | return TIMERR_NOERROR;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | /*****************************************************************************
|
---|
156 | * Name :
|
---|
157 | * Purpose :
|
---|
158 | * Parameters:
|
---|
159 | * Variables :
|
---|
160 | * Result :
|
---|
161 | * Remark :
|
---|
162 | * Status : UNTESTED STUB
|
---|
163 | *
|
---|
164 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
165 | *****************************************************************************/
|
---|
166 |
|
---|
167 | ODINFUNCTION5(MMRESULT, timeSetEvent,
|
---|
168 | UINT, wDelay,
|
---|
169 | UINT, wResolution,
|
---|
170 | LPTIMECALLBACK, lptc,
|
---|
171 | DWORD, dwUser,
|
---|
172 | UINT, fuEvent)
|
---|
173 | {
|
---|
174 | OS2Timer *timer;
|
---|
175 | ULONG timerID = 0;
|
---|
176 |
|
---|
177 | // @@@PH 1999/10/26 hack for RA95
|
---|
178 | if (wDelay < OS2TIMER_RESOLUTION_MINIMUM)
|
---|
179 | {
|
---|
180 | dprintf(("WINMM:Time:timeSetEvent - Warning: requested delay too low (%08xh)\n",
|
---|
181 | wDelay));
|
---|
182 | wDelay = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (wResolution < OS2TIMER_RESOLUTION_MINIMUM)
|
---|
186 | {
|
---|
187 | dprintf(("WINMM:Time:timeSetEvent - Warning: requested resolution too low (%08xh)\n",
|
---|
188 | wResolution));
|
---|
189 | wResolution = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | // check parameters
|
---|
194 | if ((wDelay < OS2TIMER_RESOLUTION_MINIMUM) ||
|
---|
195 | (wDelay > OS2TIMER_RESOLUTION_MAXIMUM))
|
---|
196 | return NULL;
|
---|
197 |
|
---|
198 | if (wResolution == 0)
|
---|
199 | wResolution = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
200 | else
|
---|
201 | if ((wResolution < OS2TIMER_RESOLUTION_MINIMUM) ||
|
---|
202 | (wResolution > OS2TIMER_RESOLUTION_MAXIMUM))
|
---|
203 | return NULL;
|
---|
204 |
|
---|
205 | timer = new OS2Timer();
|
---|
206 | if(timer == NULL)
|
---|
207 | return(0);
|
---|
208 |
|
---|
209 | if(HMHandleAllocate(&timerID, (ULONG)timer) != NO_ERROR) {
|
---|
210 | dprintf(("HMHandleAllocate failed!!"));
|
---|
211 | delete timer;
|
---|
212 | return 0;
|
---|
213 | }
|
---|
214 |
|
---|
215 | timer->setTimerID(timerID);
|
---|
216 | if(timer->StartTimer(wDelay, wResolution, lptc, dwUser, fuEvent) == FALSE)
|
---|
217 | {
|
---|
218 | dprintf(("WINMM:timeSetEvent: couldn't start timer!\n"));
|
---|
219 | delete(timer);
|
---|
220 | return(0);
|
---|
221 | }
|
---|
222 | return(MMRESULT)timerID;
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | #if 0
|
---|
227 | // Note: 2001-11-22
|
---|
228 | // WinGetCurrentTime does not touch the FS: selector.
|
---|
229 | // It just returns the content of a variable.
|
---|
230 | ULONG OPEN32API WinGetCurrentTime(ULONG hab);
|
---|
231 |
|
---|
232 | inline ULONG _WinGetCurrentTime(ULONG a)
|
---|
233 | {
|
---|
234 | ULONG yyrc;
|
---|
235 | USHORT sel = RestoreOS2FS();
|
---|
236 |
|
---|
237 | yyrc = WinGetCurrentTime(a);
|
---|
238 | SetFS(sel);
|
---|
239 |
|
---|
240 | return yyrc;
|
---|
241 | }
|
---|
242 |
|
---|
243 | #undef WinGetCurrentTime
|
---|
244 | #define WinGetCurrentTime _WinGetCurrentTime
|
---|
245 | #else
|
---|
246 | ULONG OPEN32API WinGetCurrentTime(ULONG hab);
|
---|
247 | #endif
|
---|
248 |
|
---|
249 | /*****************************************************************************
|
---|
250 | * Name :
|
---|
251 | * Purpose :
|
---|
252 | * Parameters:
|
---|
253 | * Variables :
|
---|
254 | * Result :
|
---|
255 | * Remark :
|
---|
256 | * Status : UNTESTED STUB
|
---|
257 | *
|
---|
258 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
259 | *****************************************************************************/
|
---|
260 |
|
---|
261 | ODINFUNCTION2(MMRESULT, timeGetSystemTime,
|
---|
262 | LPMMTIME, pTime,
|
---|
263 | UINT, cbTime)
|
---|
264 | {
|
---|
265 | dprintf2(("timeGetSystemTime %x %d", pTime, cbTime));
|
---|
266 |
|
---|
267 | if(pTime == NULL || cbTime < sizeof(MMTIME)) {
|
---|
268 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
269 | return 0;
|
---|
270 | }
|
---|
271 | pTime->wType = TIME_MS;
|
---|
272 | pTime->u.ms = WinGetCurrentTime(0);
|
---|
273 |
|
---|
274 | SetLastError(ERROR_SUCCESS);
|
---|
275 | return 0;
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | /*****************************************************************************
|
---|
280 | * Name :
|
---|
281 | * Purpose :
|
---|
282 | * Parameters:
|
---|
283 | * Variables :
|
---|
284 | * Result :
|
---|
285 | * Remark :
|
---|
286 | * Status : UNTESTED STUB
|
---|
287 | *
|
---|
288 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
289 | *****************************************************************************/
|
---|
290 |
|
---|
291 | DWORD WIN32API timeGetTime()
|
---|
292 | {
|
---|
293 | #if 0
|
---|
294 | //SvL: TODO: Inaccurate
|
---|
295 | DWORD time = WinGetCurrentTime(0);
|
---|
296 | dprintf2(("timeGetTime %x", time));
|
---|
297 | return time;
|
---|
298 | #else
|
---|
299 | return WinGetCurrentTime(0);
|
---|
300 | #endif
|
---|
301 |
|
---|
302 | #if 0
|
---|
303 | LARGE_INTEGER lint;
|
---|
304 | static LARGE_INTEGER freq;
|
---|
305 | static BOOL fInit = FALSE;
|
---|
306 |
|
---|
307 | if(fInit == FALSE) {
|
---|
308 | QueryPerformanceFrequency(&freq);
|
---|
309 | freq.LowPart /= 1000;
|
---|
310 | fInit = TRUE;
|
---|
311 | }
|
---|
312 | QueryPerformanceCounter(&lint);
|
---|
313 | time = lint.LowPart/freq.LowPart;
|
---|
314 | dprintf2(("timeGetTime %x (%x:%x)", time, lint.LowPart, lint.HighPart));
|
---|
315 | #endif
|
---|
316 | }
|
---|
317 |
|
---|