1 /****************************************************************************
3 * SciTech Nucleus Audio 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/audio.h"
39 #include "sdd/sddhelp.h"
45 /*---------------------------- Global Variables ---------------------------*/
48 extern PM_imports _VARAPI _PM_imports;
50 AA_exports _VARAPI _AA_exports;
51 static int loaded = false;
52 static PE_MODULE *hModBPD = NULL;
55 extern PM_imports _PM_imports;
60 static N_imports _N_imports = {
66 extern AA_imports _AA_imports;
68 static AA_imports _AA_imports = {
74 /*----------------------------- Implementation ----------------------------*/
76 #define DLL_NAME "audio.bpd"
79 /****************************************************************************
81 Fatal error handler for non-exported AA_exports.
82 ****************************************************************************/
83 static void _AA_fatalErrorHandler(void)
85 PM_fatalError("Unsupported Nucleus export function called! Please upgrade your copy of Nucleus!\n");
88 /****************************************************************************
90 Loads the Nucleus binary portable DLL into memory and initilises it.
91 ****************************************************************************/
92 static ibool LoadDriver(void)
94 AA_initLibrary_t AA_initLibrary;
96 char filename[PM_MAX_PATH];
97 char bpdpath[PM_MAX_PATH];
101 /* Check if we have already loaded the driver */
105 _AA_exports.dwSize = sizeof(_AA_exports);
107 /* Open the BPD file */
108 if (!PM_findBPD(DLL_NAME,bpdpath))
110 strcpy(filename,bpdpath);
111 strcat(filename,DLL_NAME);
112 if ((hModBPD = PE_loadLibrary(filename,false)) == NULL)
114 if ((AA_initLibrary = (AA_initLibrary_t)PE_getProcAddress(hModBPD,"_AA_initLibrary")) == NULL)
116 bpdpath[strlen(bpdpath)-1] = 0;
117 if (strcmp(bpdpath,PM_getNucleusPath()) == 0)
118 strcpy(bpdpath,PM_getNucleusConfigPath());
120 PM_backslash(bpdpath);
121 strcat(bpdpath,"config");
123 if ((aaExp = AA_initLibrary(bpdpath,filename,&_PM_imports,&_N_imports,&_AA_imports)) == NULL)
124 PM_fatalError("AA_initLibrary failed!\n");
126 /* Initialize all default imports to point to fatal error handler
127 * for upwards compatibility, and copy the exported functions.
129 max = sizeof(_AA_exports)/sizeof(AA_initLibrary_t);
130 for (i = 0,p = (ulong*)&_AA_exports; i < max; i++)
131 *p++ = (ulong)_AA_fatalErrorHandler;
132 memcpy(&_AA_exports,aaExp,MIN(sizeof(_AA_exports),aaExp->dwSize));
137 /* The following are stub entry points that the application calls to
138 * initialise the Nucleus loader library, and we use this to load our
139 * driver DLL from disk and initialise the library using it.
143 int NAPI AA_status(void)
146 return nDriverNotFound;
147 return _AA_exports.AA_status();
151 const char * NAPI AA_errorMsg(
155 return "Unable to load Nucleus device driver!";
156 return _AA_exports.AA_errorMsg(status);
160 int NAPI AA_getDaysLeft(void)
164 return _AA_exports.AA_getDaysLeft();
168 int NAPI AA_registerLicense(uchar *license)
172 return _AA_exports.AA_registerLicense(license);
176 int NAPI AA_enumerateDevices(void)
180 return _AA_exports.AA_enumerateDevices();
184 AA_devCtx * NAPI AA_loadDriver(N_int32 deviceIndex)
188 return _AA_exports.AA_loadDriver(deviceIndex);
197 void NAPI _OS_delay8253(N_uint32 microSeconds);
198 ibool NAPI _GA_haveCPUID(void);
199 uint NAPI _GA_getCPUIDFeatures(void);
200 void NAPI _GA_readTimeStamp(AA_largeInteger *time);
201 #define CPU_HaveRDTSC 0x00000010
203 /****************************************************************************
205 This function delays for the specified number of microseconds
206 ****************************************************************************/
208 N_uint32 microSeconds)
210 static ibool inited = false;
213 if (_GA_haveCPUID() && (_GA_getCPUIDFeatures() & CPU_HaveRDTSC) != 0) {
219 while (LZTimerLapExt(&tm) < microSeconds)
224 _OS_delay8253(microSeconds);