source: trunk/src/winmm/time.cpp@ 6728

Last change on this file since 6728 was 6728, checked in by phaller, 24 years ago

Added support for new kernels with better timer granularity

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