galib.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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: Any 32-bit protected mode environment
  30. *
  31. * Description: C module for the Graphics Accelerator Driver API. Uses
  32. * the SciTech PM library for interfacing with DOS
  33. * extender specific functions.
  34. *
  35. ****************************************************************************/
  36. #include "nucleus/graphics.h"
  37. #if defined(__WIN32_VXD__) || defined(__NT_DRIVER__)
  38. #include "sdd/sddhelp.h"
  39. #else
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #endif
  43. /*---------------------------- Global Variables ---------------------------*/
  44. #ifndef TEST_HARNESS
  45. GA_exports _VARAPI __GA_exports;
  46. static int loaded = false;
  47. static PE_MODULE *hModBPD = NULL;
  48. static N_imports _N_imports = {
  49. sizeof(N_imports),
  50. _OS_delay,
  51. };
  52. static GA_imports _GA_imports = {
  53. sizeof(GA_imports),
  54. GA_getSharedInfo,
  55. GA_TimerInit,
  56. GA_TimerRead,
  57. GA_TimerDifference,
  58. };
  59. #endif
  60. /*----------------------------- Implementation ----------------------------*/
  61. #define DLL_NAME "graphics.bpd"
  62. /****************************************************************************
  63. REMARKS:
  64. This function is no longer used but we must implement it and return NULL
  65. for compatibility with older binary drivers.
  66. ****************************************************************************/
  67. GA_sharedInfo * NAPI GA_getSharedInfo(
  68. int device)
  69. {
  70. return NULL;
  71. }
  72. #ifndef TEST_HARNESS
  73. /****************************************************************************
  74. REMARKS:
  75. Fatal error handler for non-exported GA_exports.
  76. ****************************************************************************/
  77. static void _GA_fatalErrorHandler(void)
  78. {
  79. PM_fatalError("Unsupported Nucleus export function called! Please upgrade your copy of Nucleus!\n");
  80. }
  81. /****************************************************************************
  82. PARAMETERS:
  83. shared - True to load the driver into shared memory.
  84. REMARKS:
  85. Loads the Nucleus binary portable DLL into memory and initilises it.
  86. ****************************************************************************/
  87. static ibool LoadDriver(
  88. ibool shared)
  89. {
  90. GA_initLibrary_t GA_initLibrary;
  91. GA_exports *gaExp;
  92. char filename[PM_MAX_PATH];
  93. char bpdpath[PM_MAX_PATH];
  94. int i,max;
  95. ulong *p;
  96. /* Check if we have already loaded the driver */
  97. if (loaded)
  98. return true;
  99. PM_init();
  100. /* First try to see if we can find the system wide shared exports
  101. * if they are available. Under OS/2 this connects to our global
  102. * shared Nucleus loader in SDDPMI.DLL.
  103. */
  104. __GA_exports.dwSize = sizeof(__GA_exports);
  105. if (GA_getSharedExports(&__GA_exports,shared))
  106. return loaded = true;
  107. /* Open the BPD file */
  108. if (!PM_findBPD(DLL_NAME,bpdpath))
  109. return false;
  110. strcpy(filename,bpdpath);
  111. strcat(filename,DLL_NAME);
  112. if ((hModBPD = PE_loadLibrary(filename,shared)) == NULL)
  113. return false;
  114. if ((GA_initLibrary = (GA_initLibrary_t)PE_getProcAddress(hModBPD,"_GA_initLibrary")) == NULL)
  115. return false;
  116. bpdpath[strlen(bpdpath)-1] = 0;
  117. if (strcmp(bpdpath,PM_getNucleusPath()) == 0)
  118. strcpy(bpdpath,PM_getNucleusConfigPath());
  119. else {
  120. PM_backslash(bpdpath);
  121. strcat(bpdpath,"config");
  122. }
  123. if ((gaExp = GA_initLibrary(shared,bpdpath,filename,GA_getSystemPMImports(),&_N_imports,&_GA_imports)) == NULL)
  124. PM_fatalError("GA_initLibrary failed!\n");
  125. /* Initialize all default imports to point to fatal error handler
  126. * for upwards compatibility, and copy the exported functions.
  127. */
  128. max = sizeof(__GA_exports)/sizeof(GA_initLibrary_t);
  129. for (i = 0,p = (ulong*)&__GA_exports; i < max; i++)
  130. *p++ = (ulong)_GA_fatalErrorHandler;
  131. memcpy(&__GA_exports,gaExp,MIN(sizeof(__GA_exports),gaExp->dwSize));
  132. loaded = true;
  133. return true;
  134. }
  135. /* The following are stub entry points that the application calls to
  136. * initialise the Nucleus loader library, and we use this to load our
  137. * driver DLL from disk and initialise the library using it.
  138. */
  139. /* {secret} */
  140. int NAPI GA_status(void)
  141. {
  142. if (!loaded)
  143. return nDriverNotFound;
  144. return __GA_exports.GA_status();
  145. }
  146. /* {secret} */
  147. const char * NAPI GA_errorMsg(
  148. N_int32 status)
  149. {
  150. if (!loaded)
  151. return "Unable to load Nucleus device driver!";
  152. return __GA_exports.GA_errorMsg(status);
  153. }
  154. /* {secret} */
  155. int NAPI GA_getDaysLeft(N_int32 shared)
  156. {
  157. if (!LoadDriver(shared))
  158. return -1;
  159. return __GA_exports.GA_getDaysLeft(shared);
  160. }
  161. /* {secret} */
  162. int NAPI GA_registerLicense(uchar *license,N_int32 shared)
  163. {
  164. if (!LoadDriver(shared))
  165. return 0;
  166. return __GA_exports.GA_registerLicense(license,shared);
  167. }
  168. /* {secret} */
  169. ibool NAPI GA_loadInGUI(N_int32 shared)
  170. {
  171. if (!LoadDriver(shared))
  172. return false;
  173. return __GA_exports.GA_loadInGUI(shared);
  174. }
  175. /* {secret} */
  176. int NAPI GA_enumerateDevices(N_int32 shared)
  177. {
  178. if (!LoadDriver(shared))
  179. return 0;
  180. return __GA_exports.GA_enumerateDevices(shared);
  181. }
  182. /* {secret} */
  183. GA_devCtx * NAPI GA_loadDriver(N_int32 deviceIndex,N_int32 shared)
  184. {
  185. if (!LoadDriver(shared))
  186. return NULL;
  187. return __GA_exports.GA_loadDriver(deviceIndex,shared);
  188. }
  189. /* {secret} */
  190. void NAPI GA_getGlobalOptions(
  191. GA_globalOptions *options,
  192. ibool shared)
  193. {
  194. if (LoadDriver(shared))
  195. __GA_exports.GA_getGlobalOptions(options,shared);
  196. }
  197. /* {secret} */
  198. PE_MODULE * NAPI GA_loadLibrary(
  199. const char *szBPDName,
  200. ulong *size,
  201. ibool shared)
  202. {
  203. if (!LoadDriver(shared))
  204. return NULL;
  205. return __GA_exports.GA_loadLibrary(szBPDName,size,shared);
  206. }
  207. /* {secret} */
  208. GA_devCtx * NAPI GA_getCurrentDriver(
  209. N_int32 deviceIndex)
  210. {
  211. /* Bail for older drivers that didn't export this function! */
  212. if (!__GA_exports.GA_getCurrentDriver)
  213. return NULL;
  214. return __GA_exports.GA_getCurrentDriver(deviceIndex);
  215. }
  216. /* {secret} */
  217. REF2D_driver * NAPI GA_getCurrentRef2d(
  218. N_int32 deviceIndex)
  219. {
  220. /* Bail for older drivers that didn't export this function! */
  221. if (!__GA_exports.GA_getCurrentRef2d)
  222. return NULL;
  223. return __GA_exports.GA_getCurrentRef2d(deviceIndex);
  224. }
  225. /* {secret} */
  226. int NAPI GA_isOEMVersion(ibool shared)
  227. {
  228. if (!LoadDriver(shared))
  229. return 0;
  230. return __GA_exports.GA_isOEMVersion(shared);
  231. }
  232. /* {secret} */
  233. N_uint32 * NAPI GA_getLicensedDevices(ibool shared)
  234. {
  235. if (!LoadDriver(shared))
  236. return 0;
  237. return __GA_exports.GA_getLicensedDevices(shared);
  238. }
  239. #endif