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

Last change on this file since 8706 was 8470, checked in by sandervl, 23 years ago

added debug wrappers (.def)

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