| 1 | /* $Id: time.cpp,v 1.17 2003-03-05 14:48:45 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 |
|
|---|
| 42 | UINT 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 |
|
|---|
| 60 | MMRESULT 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 |
|
|---|
| 87 | MMRESULT WINAPI timeBeginPeriod(UINT cMilliseconds)
|
|---|
| 88 | {
|
|---|
| 89 | if (cMilliseconds < OS2TIMER_RESOLUTION_MINIMUM || cMilliseconds > OS2TIMER_RESOLUTION_MAXIMUM)
|
|---|
| 90 | return TIMERR_NOCANDO;
|
|---|
| 91 |
|
|---|
| 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 |
|
|---|
| 111 | MMRESULT WINAPI timeEndPeriod(UINT cMilliseconds)
|
|---|
| 112 | {
|
|---|
| 113 | if (cMilliseconds < OS2TIMER_RESOLUTION_MINIMUM || cMilliseconds > OS2TIMER_RESOLUTION_MAXIMUM)
|
|---|
| 114 | return TIMERR_NOCANDO;
|
|---|
| 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 | MMRESULT WINAPI timeKillEvent(UINT IDEvent)
|
|---|
| 139 | {
|
|---|
| 140 | OS2Timer *os2timer = NULL;
|
|---|
| 141 |
|
|---|
| 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);
|
|---|
| 147 | // return OS2Timer::killEvent(UINT IDEvent)
|
|---|
| 148 |
|
|---|
| 149 | delete os2timer;
|
|---|
| 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 |
|
|---|
| 166 | MMRESULT WINAPI timeSetEvent(UINT wDelay, UINT wResolution,
|
|---|
| 167 | LPTIMECALLBACK lptc, DWORD dwUser,
|
|---|
| 168 | UINT fuEvent)
|
|---|
| 169 | {
|
|---|
| 170 | OS2Timer *timer;
|
|---|
| 171 | ULONG timerID = 0;
|
|---|
| 172 |
|
|---|
| 173 | // @@@PH 1999/10/26 hack for RA95
|
|---|
| 174 | if (wDelay < OS2TIMER_RESOLUTION_MINIMUM)
|
|---|
| 175 | {
|
|---|
| 176 | dprintf(("WINMM:Time:timeSetEvent - Warning: requested delay too low (%08xh)\n",
|
|---|
| 177 | wDelay));
|
|---|
| 178 | wDelay = OS2TIMER_RESOLUTION_MINIMUM;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | if (wResolution < OS2TIMER_RESOLUTION_MINIMUM)
|
|---|
| 182 | {
|
|---|
| 183 | dprintf(("WINMM:Time:timeSetEvent - Warning: requested resolution too low (%08xh)\n",
|
|---|
| 184 | wResolution));
|
|---|
| 185 | wResolution = OS2TIMER_RESOLUTION_MINIMUM;
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | // check parameters
|
|---|
| 190 | if ((wDelay < OS2TIMER_RESOLUTION_MINIMUM) ||
|
|---|
| 191 | (wDelay > OS2TIMER_RESOLUTION_MAXIMUM))
|
|---|
| 192 | return NULL;
|
|---|
| 193 |
|
|---|
| 194 | if (wResolution == 0)
|
|---|
| 195 | wResolution = OS2TIMER_RESOLUTION_MINIMUM;
|
|---|
| 196 | else
|
|---|
| 197 | if ((wResolution < OS2TIMER_RESOLUTION_MINIMUM) ||
|
|---|
| 198 | (wResolution > OS2TIMER_RESOLUTION_MAXIMUM))
|
|---|
| 199 | return NULL;
|
|---|
| 200 |
|
|---|
| 201 | timer = new OS2Timer();
|
|---|
| 202 | if(timer == NULL)
|
|---|
| 203 | return(0);
|
|---|
| 204 |
|
|---|
| 205 | if(HMHandleAllocate(&timerID, (ULONG)timer) != NO_ERROR) {
|
|---|
| 206 | dprintf(("HMHandleAllocate failed!!"));
|
|---|
| 207 | delete timer;
|
|---|
| 208 | return 0;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | timer->setTimerID(timerID);
|
|---|
| 212 | if(timer->StartTimer(wDelay, wResolution, lptc, dwUser, fuEvent) == FALSE)
|
|---|
| 213 | {
|
|---|
| 214 | dprintf(("WINMM:timeSetEvent: couldn't start timer!\n"));
|
|---|
| 215 | delete(timer);
|
|---|
| 216 | return(0);
|
|---|
| 217 | }
|
|---|
| 218 | return(MMRESULT)timerID;
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 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.
|
|---|
| 226 | ULONG OPEN32API WinGetCurrentTime(ULONG hab);
|
|---|
| 227 |
|
|---|
| 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
|
|---|
| 241 | #else
|
|---|
| 242 | ULONG OPEN32API WinGetCurrentTime(ULONG hab);
|
|---|
| 243 | #endif
|
|---|
| 244 |
|
|---|
| 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 |
|
|---|
| 257 | MMRESULT WINAPI timeGetSystemTime(LPMMTIME pTime, UINT cbTime)
|
|---|
| 258 | {
|
|---|
| 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;
|
|---|
| 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 |
|
|---|
| 285 | DWORD WIN32API timeGetTime()
|
|---|
| 286 | {
|
|---|
| 287 | #if 0
|
|---|
| 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
|
|---|
| 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
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|