Coding style cleanup
[platform/kernel/u-boot.git] / board / MAI / bios_emulator / scitech / src / common / aawin32.c
1 /****************************************************************************
2 *
3 *                   SciTech Nucleus Graphics Architecture
4 *
5 *               Copyright (C) 1991-1998 SciTech Software, Inc.
6 *                            All rights reserved.
7 *
8 *  ======================================================================
9 *  |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
10 *  |                                                                    |
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).                   |
14 *  |                                                                    |
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                   |
19 *  |                                                                    |
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.                           |
24 *  |                                                                    |
25 *  |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
26 *  ======================================================================
27 *
28 * Language:     ANSI C
29 * Environment:  Win32
30 *
31 * Description:  OS specific Nucleus Graphics Architecture services for
32 *               the Win32 operating system environments.
33 *
34 ****************************************************************************/
35
36 #include "pm_help.h"
37 #include "pmapi.h"
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #define STRICT
42 #define WIN32_LEAN_AND_MEAN
43 #include <windows.h>
44
45 /*------------------------- Global Variables ------------------------------*/
46
47 #if GA_MAX_DEVICES > 4
48 #error GA_MAX_DEVICES has changed!
49 #endif
50
51 static ibool            haveRDTSC;
52 static GA_largeInteger  countFreq;
53 static GA_loadDriver_t  ORG_GA_loadDriver;
54 extern HANDLE           _PM_hDevice;
55
56 /*-------------------------- Implementation -------------------------------*/
57
58 /****************************************************************************
59 DESCRIPTION:
60 Get the current graphics driver imports from the VxD
61
62 REMARKS:
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(
69     int device)
70 {
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 */
74
75     PM_init();
76     inBuf[0] = device;
77     if (DeviceIoControl(_PM_hDevice, PMHELP_GETSHAREDINFO32, inBuf, sizeof(inBuf),
78             outBuf, sizeof(outBuf), &count, NULL)) {
79         return (GA_sharedInfo*)outBuf[0];
80         }
81     return NULL;
82 }
83
84 /****************************************************************************
85 REMARKS:
86 Nothing special for this OS.
87 ****************************************************************************/
88 ibool NAPI GA_getSharedExports(
89     GA_exports *gaExp)
90 {
91     (void)gaExp;
92     return false;
93 }
94
95 /****************************************************************************
96 REMARKS:
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(
102     GA_devCtx *dc)
103 {
104     if (_PM_hDevice) {
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 */
108
109         inBuf[0] = (ulong)dc;
110         if (DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOINIT32, inBuf, sizeof(inBuf),
111                 outBuf, sizeof(outBuf), &count, NULL)) {
112             return outBuf[0];
113             }
114         }
115     return false;
116 }
117
118 /****************************************************************************
119 REMARKS:
120 This function turns on software stereo mode, either directly or via the VxD.
121 ****************************************************************************/
122 static void NAPI _GA_softStereoOn(void)
123 {
124     if (_PM_hDevice) {
125         DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOON32, NULL, 0,
126             NULL, 0, NULL, NULL);
127         }
128 }
129
130 /****************************************************************************
131 REMARKS:
132 This function schedules a software stereo mode page flip, either directly
133 or via the VxD.
134 ****************************************************************************/
135 static void NAPI _GA_softStereoScheduleFlip(
136     N_uint32 leftAddr,
137     N_uint32 rightAddr)
138 {
139     if (_PM_hDevice) {
140         DWORD   inBuf[2];   /* Buffer to send data to VxD       */
141         DWORD   count;      /* Count of bytes returned from VxD */
142
143         inBuf[0] = (ulong)leftAddr;
144         inBuf[1] = (ulong)rightAddr;
145         DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOFLIP32, inBuf, sizeof(inBuf),
146             NULL, 0, &count, NULL);
147         }
148 }
149
150 /****************************************************************************
151 REMARKS:
152 This function turns off software stereo mode, either directly or via the VxD.
153 ****************************************************************************/
154 static N_int32 NAPI _GA_softStereoGetFlipStatus(void)
155 {
156     if (_PM_hDevice) {
157         DWORD   outBuf[1];  /* Buffer to receive data from VxD  */
158         DWORD   count;      /* Count of bytes returned from VxD */
159
160         if (DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOFLIPSTATUS32, NULL, 0,
161                 outBuf, sizeof(outBuf), &count, NULL)) {
162             return outBuf[0];
163             }
164         }
165     return 0;
166 }
167
168 /****************************************************************************
169 REMARKS:
170 This function turns off software stereo mode, either directly or via the VxD.
171 ****************************************************************************/
172 static void NAPI _GA_softStereoWaitTillFlipped(void)
173 {
174     while (!_GA_softStereoGetFlipStatus())
175         ;
176 }
177
178 /****************************************************************************
179 REMARKS:
180 This function turns off software stereo mode, either directly or via the VxD.
181 ****************************************************************************/
182 static void NAPI _GA_softStereoOff(void)
183 {
184     if (_PM_hDevice) {
185         DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOOFF32, NULL, 0,
186             NULL, 0, NULL, NULL);
187         }
188 }
189
190 /****************************************************************************
191 REMARKS:
192 This function disable the software stereo handler, either directly or via
193 the VxD.
194 ****************************************************************************/
195 static void NAPI _GA_softStereoExit(void)
196 {
197     if (_PM_hDevice) {
198         DeviceIoControl(_PM_hDevice, PMHELP_GASTEREOEXIT32, NULL, 0,
199             NULL, 0, NULL, NULL);
200         }
201 }
202
203 /****************************************************************************
204 REMARKS:
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(
211     N_int32 deviceIndex,
212     N_int32 shared)
213 {
214     GA_devCtx   *dc;
215     DWORD       inBuf[1];
216     DWORD       outBuf[1];
217     N_int32     totalMemory = 0,oldIOPL;
218
219     if (deviceIndex >= GA_MAX_DEVICES)
220         PM_fatalError("DeviceIndex too large in GA_loadDriver!");
221     PM_init();
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)
227         totalMemory = 8192;
228     _GA_exports.GA_forceMemSize(totalMemory,shared);
229     oldIOPL = PM_setIOPL(3);
230     dc = ORG_GA_loadDriver(deviceIndex,shared);
231     PM_setIOPL(oldIOPL);
232     return dc;
233 }
234
235 /****************************************************************************
236 REMARKS:
237 This function initialises the high precision timing functions for the
238 Nucleus loader library.
239 ****************************************************************************/
240 ibool NAPI GA_TimerInit(void)
241 {
242     if (_GA_haveCPUID() && (_GA_getCPUIDFeatures() & CPU_HaveRDTSC) != 0) {
243         haveRDTSC = true;
244         return true;
245         }
246     else if (QueryPerformanceFrequency((LARGE_INTEGER*)&countFreq)) {
247         haveRDTSC = false;
248         return true;
249         }
250     return false;
251 }
252
253 /****************************************************************************
254 REMARKS:
255 This function reads the high resolution timer.
256 ****************************************************************************/
257 void NAPI GA_TimerRead(
258     GA_largeInteger *value)
259 {
260     if (haveRDTSC)
261         _GA_readTimeStamp(value);
262     else
263         QueryPerformanceCounter((LARGE_INTEGER*)value);
264 }