1 /****************************************************************************
3 * SciTech Nucleus Graphics Architecture
5 * Copyright (C) 1991-1998 SciTech Software, Inc.
8 * ======================================================================
9 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
11 * |This copyrighted computer code contains proprietary technology |
12 * |owned by SciTech Software, Inc., located at 505 Wall Street, |
13 * |Chico, CA 95928 USA (http://www.scitechsoft.com). |
15 * |The contents of this file are subject to the SciTech Nucleus |
16 * |License; you may *not* use this file or related software except in |
17 * |compliance with the License. You may obtain a copy of the License |
18 * |at http://www.scitechsoft.com/nucleus-license.txt |
20 * |Software distributed under the License is distributed on an |
21 * |"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
22 * |implied. See the License for the specific language governing |
23 * |rights and limitations under the License. |
25 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
26 * ======================================================================
31 * Description: OS specific Nucleus Graphics Architecture services for
32 * the Win32 operating system environments.
34 ****************************************************************************/
42 #define WIN32_LEAN_AND_MEAN
45 /*------------------------- Global Variables ------------------------------*/
47 #if GA_MAX_DEVICES > 4
48 #error GA_MAX_DEVICES has changed!
51 static ibool haveRDTSC;
52 static GA_largeInteger countFreq;
53 static GA_loadDriver_t ORG_GA_loadDriver;
54 extern HANDLE _PM_hDevice;
56 /*-------------------------- Implementation -------------------------------*/
58 /****************************************************************************
60 Get the current graphics driver imports from the VxD
63 This function returns a pointer to the common graphics driver loaded in the
64 helper VxD. The memory for the VxD is shared between all processes via
65 the VxD, so that the VxD, 16-bit code and 32-bit code all see the same
66 state when accessing the graphics binary portable driver.
67 ****************************************************************************/
68 GA_sharedInfo * NAPI GA_getSharedInfo(
71 DWORD inBuf[1]; /* Buffer to send data to VxD */
72 DWORD outBuf[2]; /* Buffer to receive data from VxD */
73 DWORD count; /* Count of bytes returned from VxD */
77 if (DeviceIoControl(_PM_hDevice, PMHELP_GETSHAREDINFO32, inBuf, sizeof(inBuf),
78 outBuf, sizeof(outBuf), &count, NULL)) {
79 return (GA_sharedInfo*)outBuf[0];
84 /****************************************************************************
86 Nothing special for this OS.
87 ****************************************************************************/
88 ibool NAPI GA_getSharedExports(
95 /****************************************************************************
97 This function initialises the software stereo module by either calling
98 the Nucleus libraries directly, or calling into the VxD if we are running
99 on the shared Nucleus libraries loaded by the Windows VxD.
100 ****************************************************************************/
101 static ibool NAPI _GA_softStereoInit(
105 DWORD inBuf[1]; /* Buffer to send data to VxD */
106 DWORD outBuf[1]; /* Buffer to receive data from VxD */
107 DWORD count; /* Count of bytes returned from VxD */
109 inBuf[0] = (ulong)dc;
110 if (DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOINIT32, inBuf, sizeof(inBuf),
111 outBuf, sizeof(outBuf), &count, NULL)) {
118 /****************************************************************************
120 This function turns on software stereo mode, either directly or via the VxD.
121 ****************************************************************************/
122 static void NAPI _GA_softStereoOn(void)
125 DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOON32, NULL, 0,
126 NULL, 0, NULL, NULL);
130 /****************************************************************************
132 This function schedules a software stereo mode page flip, either directly
134 ****************************************************************************/
135 static void NAPI _GA_softStereoScheduleFlip(
140 DWORD inBuf[2]; /* Buffer to send data to VxD */
141 DWORD count; /* Count of bytes returned from VxD */
143 inBuf[0] = (ulong)leftAddr;
144 inBuf[1] = (ulong)rightAddr;
145 DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOFLIP32, inBuf, sizeof(inBuf),
146 NULL, 0, &count, NULL);
150 /****************************************************************************
152 This function turns off software stereo mode, either directly or via the VxD.
153 ****************************************************************************/
154 static N_int32 NAPI _GA_softStereoGetFlipStatus(void)
157 DWORD outBuf[1]; /* Buffer to receive data from VxD */
158 DWORD count; /* Count of bytes returned from VxD */
160 if (DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOFLIPSTATUS32, NULL, 0,
161 outBuf, sizeof(outBuf), &count, NULL)) {
168 /****************************************************************************
170 This function turns off software stereo mode, either directly or via the VxD.
171 ****************************************************************************/
172 static void NAPI _GA_softStereoWaitTillFlipped(void)
174 while (!_GA_softStereoGetFlipStatus())
178 /****************************************************************************
180 This function turns off software stereo mode, either directly or via the VxD.
181 ****************************************************************************/
182 static void NAPI _GA_softStereoOff(void)
185 DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOOFF32, NULL, 0,
186 NULL, 0, NULL, NULL);
190 /****************************************************************************
192 This function disable the software stereo handler, either directly or via
194 ****************************************************************************/
195 static void NAPI _GA_softStereoExit(void)
198 DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOEXIT32, NULL, 0,
199 NULL, 0, NULL, NULL);
203 /****************************************************************************
205 We hook this function in here so that we can avoid the memory detect and
206 other destructive sequences in the drivers if we are loading the driver
207 from a Win32 application (our display drivers in contrast load them inside
208 the VxD directly, but the control panel applets use this function).
209 ****************************************************************************/
210 static GA_devCtx * NAPI _GA_loadDriver(
217 N_int32 totalMemory = 0,oldIOPL;
219 if (deviceIndex >= GA_MAX_DEVICES)
220 PM_fatalError("DeviceIndex too large in GA_loadDriver!");
222 inBuf[0] = deviceIndex;
223 if (DeviceIoControl(_PM_hDevice, PMHELP_GETMEMSIZE32,
224 inBuf, sizeof(inBuf), outBuf, sizeof(outBuf), NULL, NULL))
225 totalMemory = outBuf[0];
226 if (totalMemory == 0)
228 _GA_exports.GA_forceMemSize(totalMemory,shared);
229 oldIOPL = PM_setIOPL(3);
230 dc = ORG_GA_loadDriver(deviceIndex,shared);
235 /****************************************************************************
237 This function initialises the high precision timing functions for the
238 Nucleus loader library.
239 ****************************************************************************/
240 ibool NAPI GA_TimerInit(void)
242 if (_GA_haveCPUID() && (_GA_getCPUIDFeatures() & CPU_HaveRDTSC) != 0) {
246 else if (QueryPerformanceFrequency((LARGE_INTEGER*)&countFreq)) {
253 /****************************************************************************
255 This function reads the high resolution timer.
256 ****************************************************************************/
257 void NAPI GA_TimerRead(
258 GA_largeInteger *value)
261 _GA_readTimeStamp(value);
263 QueryPerformanceCounter((LARGE_INTEGER*)value);