1 /****************************************************************************
3 * Ultra Long Period Timer
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: 32-bit Windows VxD
27 * Description: OS specific implementation for the Zen Timer functions.
29 ****************************************************************************/
31 /*---------------------------- Global variables ---------------------------*/
33 static CPU_largeInteger countFreq;
34 static ulong start,finish;
36 /*----------------------------- Implementation ----------------------------*/
38 /****************************************************************************
40 Initialise the Zen Timer module internals.
41 ****************************************************************************/
42 static void __ZTimerInit(void)
44 KeQueryPerformanceCounter((LARGE_INTEGER*)&countFreq);
47 /****************************************************************************
49 Call the assembler Zen Timer functions to do the timing.
50 ****************************************************************************/
51 static void __LZTimerOn(
54 LARGE_INTEGER lt = KeQueryPerformanceCounter(NULL);
55 tm->start.low = lt.LowPart;
56 tm->start.high = lt.HighPart;
59 /****************************************************************************
61 Call the assembler Zen Timer functions to do the timing.
62 ****************************************************************************/
63 static ulong __LZTimerLap(
66 LARGE_INTEGER tmLap = KeQueryPerformanceCounter(NULL);
67 CPU_largeInteger tmCount;
69 _CPU_diffTime64(&tm->start,(CPU_largeInteger*)&tmLap,&tmCount);
70 return _CPU_calcMicroSec(&tmCount,countFreq.low);
73 /****************************************************************************
75 Call the assembler Zen Timer functions to do the timing.
76 ****************************************************************************/
77 static void __LZTimerOff(
80 LARGE_INTEGER lt = KeQueryPerformanceCounter(NULL);
81 tm->end.low = lt.LowPart;
82 tm->end.high = lt.HighPart;
85 /****************************************************************************
87 Call the assembler Zen Timer functions to do the timing.
88 ****************************************************************************/
89 static ulong __LZTimerCount(
92 CPU_largeInteger tmCount;
94 _CPU_diffTime64(&tm->start,&tm->end,&tmCount);
95 return _CPU_calcMicroSec(&tmCount,countFreq.low);
98 /****************************************************************************
100 Define the resolution of the long period timer as microseconds per timer tick.
101 ****************************************************************************/
102 #define ULZTIMER_RESOLUTION 1
104 /****************************************************************************
106 Read the Long Period timer value from the BIOS timer tick.
107 ****************************************************************************/
108 static ulong __ULZReadTime(void)
111 KeQuerySystemTime(&count);
112 return (ulong)(*((_int64*)&count) / 10);
115 /****************************************************************************
117 Compute the elapsed time from the BIOS timer tick. Note that we check to see
118 whether a midnight boundary has passed, and if so adjust the finish time to
119 account for this. We cannot detect if more that one midnight boundary has
120 passed, so if this happens we will be generating erronous results.
121 ****************************************************************************/
122 ulong __ULZElapsedTime(ulong start,ulong finish)
123 { return finish - start; }