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