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 * ======================================================================
29 * Environment: Any 32-bit protected mode environment
31 * Description: C module for the Graphics Accelerator Driver API. Uses
32 * the SciTech PM library for interfacing with DOS
33 * extender specific functions.
35 ****************************************************************************/
37 #include "nucleus/graphics.h"
38 #if defined(__WIN32_VXD__) || defined(__NT_DRIVER__)
39 #include "sdd/sddhelp.h"
45 /*---------------------------- Global Variables ---------------------------*/
48 GA_exports _VARAPI __GA_exports;
49 static int loaded = false;
50 static PE_MODULE *hModBPD = NULL;
52 static N_imports _N_imports = {
57 static GA_imports _GA_imports = {
66 /*----------------------------- Implementation ----------------------------*/
68 #define DLL_NAME "graphics.bpd"
70 /****************************************************************************
72 This function is no longer used but we must implement it and return NULL
73 for compatibility with older binary drivers.
74 ****************************************************************************/
75 GA_sharedInfo * NAPI GA_getSharedInfo(
82 /****************************************************************************
84 Fatal error handler for non-exported GA_exports.
85 ****************************************************************************/
86 static void _GA_fatalErrorHandler(void)
88 PM_fatalError("Unsupported Nucleus export function called! Please upgrade your copy of Nucleus!\n");
91 /****************************************************************************
93 shared - True to load the driver into shared memory.
96 Loads the Nucleus binary portable DLL into memory and initilises it.
97 ****************************************************************************/
98 static ibool LoadDriver(
101 GA_initLibrary_t GA_initLibrary;
103 char filename[PM_MAX_PATH];
104 char bpdpath[PM_MAX_PATH];
108 /* Check if we have already loaded the driver */
113 /* First try to see if we can find the system wide shared exports
114 * if they are available. Under OS/2 this connects to our global
115 * shared Nucleus loader in SDDPMI.DLL.
117 __GA_exports.dwSize = sizeof(__GA_exports);
118 if (GA_getSharedExports(&__GA_exports,shared))
119 return loaded = true;
121 /* Open the BPD file */
122 if (!PM_findBPD(DLL_NAME,bpdpath))
124 strcpy(filename,bpdpath);
125 strcat(filename,DLL_NAME);
126 if ((hModBPD = PE_loadLibrary(filename,shared)) == NULL)
128 if ((GA_initLibrary = (GA_initLibrary_t)PE_getProcAddress(hModBPD,"_GA_initLibrary")) == NULL)
130 bpdpath[strlen(bpdpath)-1] = 0;
131 if (strcmp(bpdpath,PM_getNucleusPath()) == 0)
132 strcpy(bpdpath,PM_getNucleusConfigPath());
134 PM_backslash(bpdpath);
135 strcat(bpdpath,"config");
137 if ((gaExp = GA_initLibrary(shared,bpdpath,filename,GA_getSystemPMImports(),&_N_imports,&_GA_imports)) == NULL)
138 PM_fatalError("GA_initLibrary failed!\n");
140 /* Initialize all default imports to point to fatal error handler
141 * for upwards compatibility, and copy the exported functions.
143 max = sizeof(__GA_exports)/sizeof(GA_initLibrary_t);
144 for (i = 0,p = (ulong*)&__GA_exports; i < max; i++)
145 *p++ = (ulong)_GA_fatalErrorHandler;
146 memcpy(&__GA_exports,gaExp,MIN(sizeof(__GA_exports),gaExp->dwSize));
151 /* The following are stub entry points that the application calls to
152 * initialise the Nucleus loader library, and we use this to load our
153 * driver DLL from disk and initialise the library using it.
157 int NAPI GA_status(void)
160 return nDriverNotFound;
161 return __GA_exports.GA_status();
165 const char * NAPI GA_errorMsg(
169 return "Unable to load Nucleus device driver!";
170 return __GA_exports.GA_errorMsg(status);
174 int NAPI GA_getDaysLeft(N_int32 shared)
176 if (!LoadDriver(shared))
178 return __GA_exports.GA_getDaysLeft(shared);
182 int NAPI GA_registerLicense(uchar *license,N_int32 shared)
184 if (!LoadDriver(shared))
186 return __GA_exports.GA_registerLicense(license,shared);
190 ibool NAPI GA_loadInGUI(N_int32 shared)
192 if (!LoadDriver(shared))
194 return __GA_exports.GA_loadInGUI(shared);
198 int NAPI GA_enumerateDevices(N_int32 shared)
200 if (!LoadDriver(shared))
202 return __GA_exports.GA_enumerateDevices(shared);
206 GA_devCtx * NAPI GA_loadDriver(N_int32 deviceIndex,N_int32 shared)
208 if (!LoadDriver(shared))
210 return __GA_exports.GA_loadDriver(deviceIndex,shared);
214 void NAPI GA_getGlobalOptions(
215 GA_globalOptions *options,
218 if (LoadDriver(shared))
219 __GA_exports.GA_getGlobalOptions(options,shared);
223 PE_MODULE * NAPI GA_loadLibrary(
224 const char *szBPDName,
228 if (!LoadDriver(shared))
230 return __GA_exports.GA_loadLibrary(szBPDName,size,shared);
234 GA_devCtx * NAPI GA_getCurrentDriver(
237 /* Bail for older drivers that didn't export this function! */
238 if (!__GA_exports.GA_getCurrentDriver)
240 return __GA_exports.GA_getCurrentDriver(deviceIndex);
244 REF2D_driver * NAPI GA_getCurrentRef2d(
247 /* Bail for older drivers that didn't export this function! */
248 if (!__GA_exports.GA_getCurrentRef2d)
250 return __GA_exports.GA_getCurrentRef2d(deviceIndex);
254 int NAPI GA_isOEMVersion(ibool shared)
256 if (!LoadDriver(shared))
258 return __GA_exports.GA_isOEMVersion(shared);
262 N_uint32 * NAPI GA_getLicensedDevices(ibool shared)
264 if (!LoadDriver(shared))
266 return __GA_exports.GA_getLicensedDevices(shared);