agplib.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. #include "nucleus/agp.h"
  38. /*---------------------------- Global Variables ---------------------------*/
  39. #ifndef DEBUG_AGP_DRIVER
  40. static AGP_exports _AGP_exports;
  41. static int loaded = false;
  42. static PE_MODULE *hModBPD = NULL;
  43. static N_imports _N_imports = {
  44. sizeof(N_imports),
  45. _OS_delay,
  46. };
  47. static AGP_imports _AGP_imports = {
  48. sizeof(AGP_imports),
  49. };
  50. #endif
  51. #include "pmimp.h"
  52. /*----------------------------- Implementation ----------------------------*/
  53. #define DLL_NAME "agp.bpd"
  54. #ifndef DEBUG_AGP_DRIVER
  55. /****************************************************************************
  56. REMARKS:
  57. Fatal error handler for non-exported GA_exports.
  58. ****************************************************************************/
  59. static void _AGP_fatalErrorHandler(void)
  60. {
  61. PM_fatalError("Unsupported AGP export function called! Please upgrade your copy of AGP!\n");
  62. }
  63. /****************************************************************************
  64. PARAMETERS:
  65. shared - True to load the driver into shared memory.
  66. REMARKS:
  67. Loads the Nucleus binary portable DLL into memory and initilises it.
  68. ****************************************************************************/
  69. static ibool LoadDriver(void)
  70. {
  71. AGP_initLibrary_t AGP_initLibrary;
  72. AGP_exports *agpExp;
  73. char filename[PM_MAX_PATH];
  74. char bpdpath[PM_MAX_PATH];
  75. int i,max;
  76. ulong *p;
  77. /* Check if we have already loaded the driver */
  78. if (loaded)
  79. return true;
  80. PM_init();
  81. /* Open the BPD file */
  82. if (!PM_findBPD(DLL_NAME,bpdpath))
  83. return false;
  84. strcpy(filename,bpdpath);
  85. strcat(filename,DLL_NAME);
  86. if ((hModBPD = PE_loadLibrary(filename,false)) == NULL)
  87. return false;
  88. if ((AGP_initLibrary = (AGP_initLibrary_t)PE_getProcAddress(hModBPD,"_AGP_initLibrary")) == NULL)
  89. return false;
  90. bpdpath[strlen(bpdpath)-1] = 0;
  91. if (strcmp(bpdpath,PM_getNucleusPath()) == 0)
  92. strcpy(bpdpath,PM_getNucleusConfigPath());
  93. else {
  94. PM_backslash(bpdpath);
  95. strcat(bpdpath,"config");
  96. }
  97. if ((agpExp = AGP_initLibrary(bpdpath,filename,GA_getSystemPMImports(),&_N_imports,&_AGP_imports)) == NULL)
  98. PM_fatalError("AGP_initLibrary failed!\n");
  99. _AGP_exports.dwSize = sizeof(_AGP_exports);
  100. max = sizeof(_AGP_exports)/sizeof(AGP_initLibrary_t);
  101. for (i = 0,p = (ulong*)&_AGP_exports; i < max; i++)
  102. *p++ = (ulong)_AGP_fatalErrorHandler;
  103. memcpy(&_AGP_exports,agpExp,MIN(sizeof(_AGP_exports),agpExp->dwSize));
  104. loaded = true;
  105. return true;
  106. }
  107. /* The following are stub entry points that the application calls to
  108. * initialise the Nucleus loader library, and we use this to load our
  109. * driver DLL from disk and initialise the library using it.
  110. */
  111. /* {secret} */
  112. int NAPI AGP_status(void)
  113. {
  114. if (!loaded)
  115. return nDriverNotFound;
  116. return _AGP_exports.AGP_status();
  117. }
  118. /* {secret} */
  119. const char * NAPI AGP_errorMsg(
  120. N_int32 status)
  121. {
  122. if (!loaded)
  123. return "Unable to load Nucleus device driver!";
  124. return _AGP_exports.AGP_errorMsg(status);
  125. }
  126. /* {secret} */
  127. AGP_devCtx * NAPI AGP_loadDriver(N_int32 deviceIndex)
  128. {
  129. if (!LoadDriver())
  130. return NULL;
  131. return _AGP_exports.AGP_loadDriver(deviceIndex);
  132. }
  133. /* {secret} */
  134. void NAPI AGP_unloadDriver(
  135. AGP_devCtx *dc)
  136. {
  137. if (loaded)
  138. _AGP_exports.AGP_unloadDriver(dc);
  139. }
  140. /* {secret} */
  141. void NAPI AGP_getGlobalOptions(
  142. AGP_globalOptions *options)
  143. {
  144. if (LoadDriver())
  145. _AGP_exports.AGP_getGlobalOptions(options);
  146. }
  147. /* {secret} */
  148. void NAPI AGP_setGlobalOptions(
  149. AGP_globalOptions *options)
  150. {
  151. if (LoadDriver())
  152. _AGP_exports.AGP_setGlobalOptions(options);
  153. }
  154. /* {secret} */
  155. void NAPI AGP_saveGlobalOptions(
  156. AGP_globalOptions *options)
  157. {
  158. if (loaded)
  159. _AGP_exports.AGP_saveGlobalOptions(options);
  160. }
  161. #endif
  162. /* {secret} */
  163. void NAPI _OS_delay8253(N_uint32 microSeconds);
  164. /****************************************************************************
  165. REMARKS:
  166. This function delays for the specified number of microseconds
  167. ****************************************************************************/
  168. void NAPI _OS_delay(
  169. N_uint32 microSeconds)
  170. {
  171. static ibool inited = false;
  172. static ibool haveRDTSC;
  173. LZTimerObject tm;
  174. if (!inited) {
  175. #ifndef __WIN32_VXD__
  176. /* This has been causing problems in VxD's for some reason, so for now */
  177. /* we avoid using it. */
  178. if (_GA_haveCPUID() && (_GA_getCPUIDFeatures() & CPU_HaveRDTSC) != 0) {
  179. ZTimerInit();
  180. haveRDTSC = true;
  181. }
  182. else
  183. #endif
  184. haveRDTSC = false;
  185. inited = true;
  186. }
  187. if (haveRDTSC) {
  188. LZTimerOnExt(&tm);
  189. while (LZTimerLapExt(&tm) < microSeconds)
  190. ;
  191. LZTimerOnExt(&tm);
  192. }
  193. else
  194. _OS_delay8253(microSeconds);
  195. }