[10269] | 1 | /* $Id: time.cpp,v 1.18 2003-10-13 09:18:38 sandervl Exp $ */
|
---|
[756] | 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>
|
---|
[6933] | 20 | #include <handlemanager.h>
|
---|
[756] | 21 |
|
---|
| 22 | #include "os2timer.h"
|
---|
| 23 | #include "time.h"
|
---|
| 24 |
|
---|
[2812] | 25 | #define DBG_LOCALLOG DBG_time
|
---|
| 26 | #include "dbglocal.h"
|
---|
| 27 |
|
---|
[756] | 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 |
|
---|
[8470] | 42 | UINT WINAPI mmsystemGetVersion()
|
---|
[756] | 43 | {
|
---|
[5364] | 44 | //Returned by winmm.dll from NT4, SP6
|
---|
| 45 | return 0x030A;
|
---|
[756] | 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 |
|
---|
[8470] | 60 | MMRESULT WINAPI timeGetDevCaps(LPTIMECAPS ptc, UINT cbtc)
|
---|
[756] | 61 | {
|
---|
| 62 | dprintf(("WINMM:timeGetDevCaps Not really Implemented\n"));
|
---|
[6728] | 63 |
|
---|
| 64 | /* 2001-09-16 PH
|
---|
| 65 | add dynamic detection of OS/2's minimum timer resolution
|
---|
| 66 | */
|
---|
| 67 |
|
---|
[757] | 68 | ptc->wPeriodMin = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
| 69 | ptc->wPeriodMax = OS2TIMER_RESOLUTION_MAXIMUM;
|
---|
[756] | 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 |
|
---|
[8470] | 87 | MMRESULT WINAPI timeBeginPeriod(UINT cMilliseconds)
|
---|
[756] | 88 | {
|
---|
[9901] | 89 | if (cMilliseconds < OS2TIMER_RESOLUTION_MINIMUM || cMilliseconds > OS2TIMER_RESOLUTION_MAXIMUM)
|
---|
| 90 | return TIMERR_NOCANDO;
|
---|
| 91 |
|
---|
[756] | 92 | if (TRUE == OS2TimerResolution::enterResolutionScope(cMilliseconds))
|
---|
| 93 | return TIMERR_NOERROR;
|
---|
| 94 | else
|
---|
| 95 | return TIMERR_NOCANDO;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | /*****************************************************************************
|
---|
| 100 | * Name :
|
---|
| 101 | * Purpose :
|
---|
| 102 | * Parameters:
|
---|
| 103 | * Variables :
|
---|
| 104 | * Result :
|
---|
| 105 | * Remark :
|
---|
| 106 | * Status : UNTESTED STUB
|
---|
| 107 | *
|
---|
| 108 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
| 109 | *****************************************************************************/
|
---|
| 110 |
|
---|
[8470] | 111 | MMRESULT WINAPI timeEndPeriod(UINT cMilliseconds)
|
---|
[756] | 112 | {
|
---|
[9901] | 113 | if (cMilliseconds < OS2TIMER_RESOLUTION_MINIMUM || cMilliseconds > OS2TIMER_RESOLUTION_MAXIMUM)
|
---|
| 114 | return TIMERR_NOCANDO;
|
---|
| 115 |
|
---|
[756] | 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 |
|
---|
[8470] | 138 | MMRESULT WINAPI timeKillEvent(UINT IDEvent)
|
---|
[756] | 139 | {
|
---|
[6933] | 140 | OS2Timer *os2timer = NULL;
|
---|
[756] | 141 |
|
---|
[6933] | 142 | if(HMHandleTranslateToOS2(IDEvent, (PULONG)&os2timer) != NO_ERROR) {
|
---|
| 143 | dprintf(("invalid timer id"));
|
---|
| 144 | return TIMERR_NOERROR; //TODO: should we return an error here??
|
---|
| 145 | }
|
---|
| 146 | HMHandleFree(IDEvent);
|
---|
[756] | 147 |
|
---|
[10269] | 148 | os2timer->KillTimer();
|
---|
| 149 | os2timer->release();
|
---|
[756] | 150 | return TIMERR_NOERROR;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | /*****************************************************************************
|
---|
| 155 | * Name :
|
---|
| 156 | * Purpose :
|
---|
| 157 | * Parameters:
|
---|
| 158 | * Variables :
|
---|
| 159 | * Result :
|
---|
| 160 | * Remark :
|
---|
| 161 | * Status : UNTESTED STUB
|
---|
| 162 | *
|
---|
| 163 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
| 164 | *****************************************************************************/
|
---|
| 165 |
|
---|
[8470] | 166 | MMRESULT WINAPI timeSetEvent(UINT wDelay, UINT wResolution,
|
---|
| 167 | LPTIMECALLBACK lptc, DWORD dwUser,
|
---|
| 168 | UINT fuEvent)
|
---|
[756] | 169 | {
|
---|
| 170 | OS2Timer *timer;
|
---|
[6933] | 171 | ULONG timerID = 0;
|
---|
[756] | 172 |
|
---|
[1465] | 173 | // @@@PH 1999/10/26 hack for RA95
|
---|
| 174 | if (wDelay < OS2TIMER_RESOLUTION_MINIMUM)
|
---|
[2242] | 175 | {
|
---|
| 176 | dprintf(("WINMM:Time:timeSetEvent - Warning: requested delay too low (%08xh)\n",
|
---|
| 177 | wDelay));
|
---|
[1465] | 178 | wDelay = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
[2242] | 179 | }
|
---|
[1465] | 180 |
|
---|
| 181 | if (wResolution < OS2TIMER_RESOLUTION_MINIMUM)
|
---|
[2242] | 182 | {
|
---|
| 183 | dprintf(("WINMM:Time:timeSetEvent - Warning: requested resolution too low (%08xh)\n",
|
---|
| 184 | wResolution));
|
---|
[1465] | 185 | wResolution = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
[2242] | 186 | }
|
---|
[1465] | 187 |
|
---|
| 188 |
|
---|
[757] | 189 | // check parameters
|
---|
| 190 | if ((wDelay < OS2TIMER_RESOLUTION_MINIMUM) ||
|
---|
[764] | 191 | (wDelay > OS2TIMER_RESOLUTION_MAXIMUM))
|
---|
[757] | 192 | return NULL;
|
---|
| 193 |
|
---|
| 194 | if (wResolution == 0)
|
---|
| 195 | wResolution = OS2TIMER_RESOLUTION_MINIMUM;
|
---|
| 196 | else
|
---|
| 197 | if ((wResolution < OS2TIMER_RESOLUTION_MINIMUM) ||
|
---|
[762] | 198 | (wResolution > OS2TIMER_RESOLUTION_MAXIMUM))
|
---|
[757] | 199 | return NULL;
|
---|
| 200 |
|
---|
[756] | 201 | timer = new OS2Timer();
|
---|
| 202 | if(timer == NULL)
|
---|
| 203 | return(0);
|
---|
| 204 |
|
---|
[6933] | 205 | if(HMHandleAllocate(&timerID, (ULONG)timer) != NO_ERROR) {
|
---|
| 206 | dprintf(("HMHandleAllocate failed!!"));
|
---|
[10269] | 207 | timer->release();
|
---|
[6933] | 208 | return 0;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | timer->setTimerID(timerID);
|
---|
[756] | 212 | if(timer->StartTimer(wDelay, wResolution, lptc, dwUser, fuEvent) == FALSE)
|
---|
| 213 | {
|
---|
| 214 | dprintf(("WINMM:timeSetEvent: couldn't start timer!\n"));
|
---|
[10269] | 215 | timer->release();
|
---|
[756] | 216 | return(0);
|
---|
| 217 | }
|
---|
[6933] | 218 | return(MMRESULT)timerID;
|
---|
[756] | 219 | }
|
---|
| 220 |
|
---|
[7428] | 221 |
|
---|
| 222 | #if 0
|
---|
| 223 | // Note: 2001-11-22
|
---|
| 224 | // WinGetCurrentTime does not touch the FS: selector.
|
---|
| 225 | // It just returns the content of a variable.
|
---|
[6408] | 226 | ULONG OPEN32API WinGetCurrentTime(ULONG hab);
|
---|
[756] | 227 |
|
---|
[6408] | 228 | inline ULONG _WinGetCurrentTime(ULONG a)
|
---|
| 229 | {
|
---|
| 230 | ULONG yyrc;
|
---|
| 231 | USHORT sel = RestoreOS2FS();
|
---|
| 232 |
|
---|
| 233 | yyrc = WinGetCurrentTime(a);
|
---|
| 234 | SetFS(sel);
|
---|
| 235 |
|
---|
| 236 | return yyrc;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | #undef WinGetCurrentTime
|
---|
| 240 | #define WinGetCurrentTime _WinGetCurrentTime
|
---|
[7428] | 241 | #else
|
---|
| 242 | ULONG OPEN32API WinGetCurrentTime(ULONG hab);
|
---|
| 243 | #endif
|
---|
[6408] | 244 |
|
---|
[756] | 245 | /*****************************************************************************
|
---|
| 246 | * Name :
|
---|
| 247 | * Purpose :
|
---|
| 248 | * Parameters:
|
---|
| 249 | * Variables :
|
---|
| 250 | * Result :
|
---|
| 251 | * Remark :
|
---|
| 252 | * Status : UNTESTED STUB
|
---|
| 253 | *
|
---|
| 254 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
| 255 | *****************************************************************************/
|
---|
| 256 |
|
---|
[8470] | 257 | MMRESULT WINAPI timeGetSystemTime(LPMMTIME pTime, UINT cbTime)
|
---|
[756] | 258 | {
|
---|
[6408] | 259 | dprintf2(("timeGetSystemTime %x %d", pTime, cbTime));
|
---|
| 260 |
|
---|
| 261 | if(pTime == NULL || cbTime < sizeof(MMTIME)) {
|
---|
| 262 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 263 | return 0;
|
---|
| 264 | }
|
---|
| 265 | pTime->wType = TIME_MS;
|
---|
| 266 | pTime->u.ms = WinGetCurrentTime(0);
|
---|
| 267 |
|
---|
| 268 | SetLastError(ERROR_SUCCESS);
|
---|
| 269 | return 0;
|
---|
[756] | 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 | /*****************************************************************************
|
---|
| 274 | * Name :
|
---|
| 275 | * Purpose :
|
---|
| 276 | * Parameters:
|
---|
| 277 | * Variables :
|
---|
| 278 | * Result :
|
---|
| 279 | * Remark :
|
---|
| 280 | * Status : UNTESTED STUB
|
---|
| 281 | *
|
---|
| 282 | * Author : Patrick Haller [Tue, 1998/06/16 23:00]
|
---|
| 283 | *****************************************************************************/
|
---|
| 284 |
|
---|
[1404] | 285 | DWORD WIN32API timeGetTime()
|
---|
[756] | 286 | {
|
---|
[5348] | 287 | #if 0
|
---|
[7428] | 288 | //SvL: TODO: Inaccurate
|
---|
| 289 | DWORD time = WinGetCurrentTime(0);
|
---|
| 290 | dprintf2(("timeGetTime %x", time));
|
---|
| 291 | return time;
|
---|
| 292 | #else
|
---|
| 293 | return WinGetCurrentTime(0);
|
---|
| 294 | #endif
|
---|
| 295 |
|
---|
| 296 | #if 0
|
---|
[5348] | 297 | LARGE_INTEGER lint;
|
---|
| 298 | static LARGE_INTEGER freq;
|
---|
| 299 | static BOOL fInit = FALSE;
|
---|
| 300 |
|
---|
| 301 | if(fInit == FALSE) {
|
---|
| 302 | QueryPerformanceFrequency(&freq);
|
---|
| 303 | freq.LowPart /= 1000;
|
---|
| 304 | fInit = TRUE;
|
---|
| 305 | }
|
---|
| 306 | QueryPerformanceCounter(&lint);
|
---|
| 307 | time = lint.LowPart/freq.LowPart;
|
---|
| 308 | dprintf2(("timeGetTime %x (%x:%x)", time, lint.LowPart, lint.HighPart));
|
---|
| 309 | #endif
|
---|
[756] | 310 | }
|
---|
| 311 |
|
---|