source: sbliveos2/trunk/drv16/init.cpp@ 660

Last change on this file since 660 was 191, checked in by sandervl, 24 years ago

rudi's fixes + dac control added

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1/* $Id: init.cpp 191 2001-09-28 12:10:07Z sandervl $ */
2
3/* SCCSID = %W% %E% */
4/****************************************************************************
5 * *
6 * Copyright (c) IBM Corporation 1994 - 1997. *
7 * *
8 * The following IBM OS/2 source code is provided to you solely for the *
9 * the purpose of assisting you in your development of OS/2 device drivers. *
10 * You may use this code in accordance with the IBM License Agreement *
11 * provided in the IBM Device Driver Source Kit for OS/2. *
12 * *
13 ****************************************************************************/
14/**@internal %W%
15 * Top level device driver initialization.
16 * @version %I%
17 * @context
18 * Physical DD initialization context: Ring3 with I/O privledge.
19 * Discarded after use.
20 * @notes
21 * Creates resource manager object and uses that RM object to figure out
22 * whether audio hardware is present. If present, RM provides IO resources
23 * to operate hardware. This modules uses that information to create
24 * Audio HW objects and other global data structures.
25 * @history
26 */
27
28#pragma code_seg ("_inittext");
29////#pragma data_seg ("_initdata","endds");
30
31extern "C" { // 16-bit header files are not C++ aware
32#define INCL_NOPMAPI
33#define INCL_DOSMISC
34#include <os2.h>
35#include <audio.h>
36#include <os2mixer.h>
37}
38
39#include <ctype.h>
40#include <string.h>
41#include <devhelp.h>
42#include "strategy.h" // OS/2 DD strategy interface
43#include "header.h" // Device driver header
44#include "parse.h" // Parses DEVICE= command line
45#include "malloc.h" // Heap memory used by this driver
46#include "mpu401.hpp" // Object definition
47#include "wavehw.hpp" // Object definition
48#include "irq.hpp" // Object definition
49#include "timer.hpp" // Object definition
50#include "stream.hpp" // pStreamList
51#include "rm.hpp" // Object definition
52#include "end.h" // end_of_data, end_of_text()
53#include "sizedefs.h" // HEAP_SIZE
54#include "idc_vdd.h" // VDD interface and Data Structs
55#include <include.h> // Pragmas and more.
56#include <sbversion.h>
57#include "commdbg.h"
58#include <dbgos2.h>
59
60#ifndef PCI_VENDOR_ID_CREATIVE
61#define PCI_VENDOR_ID_CREATIVE 0x1102UL
62#endif
63
64#ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1
65#define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002UL
66#endif
67
68#ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK
69#define PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK 0x7002
70#endif
71
72#define PCI_ID ((PCI_DEVICE_ID_CREATIVE_EMU10K1<<16UL)|PCI_VENDOR_ID_CREATIVE)
73#define PCI_IDJOY ((PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK<<16UL)|PCI_VENDOR_ID_CREATIVE)
74
75// Default MIDI timer interval, milliseconds.
76static USHORT MIDI_TimerInterval = 10;
77
78static char szSBLive[] = "SoundBlaster Live! MMPM/2 Audio Driver v"SBLIVE_VERSION;
79static char szCopyRight[] = "Copyright 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)";
80static char NEWLINE[] = "\r\n";
81static char szSBLiveNotFound[] = "SB Live! hardware not detected!";
82static char szSBLiveAllocResFailed1[] = "Another device driver was granted exclusive access to IRQ ";
83static char szSBLiveAllocResFailed2[] = "Unable to allocate hardware resources! Aborting...";
84static char szSBLiveConfig1[] = "SB Live! configuration: IRQ ";
85static char szSBLiveConfig2[] = ", IO Port 0x";
86static char szSBLiveConfigJoy[] = "SB Live! Joystick : IO Port 0x";
87
88//
89// ASCII Z-String used to register for PDD-VDD IDC must
90// Name is copied from header at runtime.
91//
92char szPddName[9] = {0};
93char digit[16] = {0};
94
95ResourceManager* pRM = 0; // Resource manager object.
96
97//
98// Strategy Init
99//
100void StrategyInit(PREQPACKET prp)
101{
102 Device_Help = (PFN) prp->s.init_in.ulDevHlp;
103 prp->s.init_out.usCodeEnd = 0;
104 prp->s.init_out.usDataEnd = 0;
105 prp->usStatus = RPDONE | RPERR | RPGENFAIL;
106
107 /* Initialize Heap. */
108 unsigned uInitSize; // Actual size of Heap following initialization.
109 uInitSize = HeapInit( HEAP_SIZE );
110 if ((HEAP_SIZE-uInitSize) > 64) { // Should get size of request, less some overhead.
111 // ### pError->vLog( HeapInitFailure ); //### Error log 'pError' not yet created.
112 return;
113 }
114 /* Heap initialized. */
115
116 // Initialize global lists.
117 pAudioHWList = new QUEUEHEAD;
118 pStreamList = new QUEUEHEAD;
119 pTimerList = new QUEUEHEAD;
120
121 // Fetch command line parameters.
122 if (!GetParms(prp->s.init_in.szArgs)) {
123 return;
124 }
125
126 // Now that we've grabbed our cmd line options,
127 // we can start processing stuff that depends on those switches.
128
129 if (fInt3BeforeInit) DebugInt3();
130
131 // If we got a /V (verbose) flag on the DEVICE= command, route messages
132 // to the display.
133 if (fVerbose) {
134 USHORT result;
135
136 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
137 DosWrite(1, (VOID FAR*)szSBLive, sizeof(szSBLive)-1, &result);
138 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
139
140 DosWrite(1, (VOID FAR*)szCopyRight, sizeof(szCopyRight), &result);
141 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
142 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
143 }
144
145 if (szCL_DevName[0] != ' ') // Was a valid device name specified?
146 memcpy(phdr->abName,szCL_DevName,8); // yes, copy it to the dev header
147
148 pRM = new ResourceManager(PCI_ID); // Create the RM object.
149 if (! pRM) {
150 return;
151 }
152
153 //SvL: Check if SB Live hardware has been detected by the resource manager
154 if(pRM->getState() != rmDriverCreated || !pRM->bIsDevDetected(PCI_ID, SEARCH_ID_DEVICEID, TRUE))
155 {
156hardware_notfound:
157 USHORT result;
158
159 DosWrite(1, (VOID FAR*)szSBLiveNotFound, sizeof(szSBLiveNotFound)-1, &result);
160 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
161 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
162 return;
163 }
164 LDev_Resources *pResources = pRM->pGetDevResources(PCI_ID, SEARCH_ID_DEVICEID, TRUE);
165 if ((!pResources) || pResources->isEmpty()) {
166 goto hardware_notfound;
167 }
168 if (pRM->getState() == rmAllocFailed) {
169 USHORT result;
170
171 DosWrite(1, (VOID FAR*)szSBLiveAllocResFailed1, sizeof(szSBLiveAllocResFailed1)-1, &result);
172 DecWordToASCII(digit, (USHORT)pResources->uIRQLevel[0], 0);
173 DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
174 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
175 DosWrite(1, (VOID FAR*)szSBLiveAllocResFailed2, sizeof(szSBLiveAllocResFailed2)-1, &result);
176 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
177 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
178 return;
179 }
180
181 if (fVerbose) {
182 USHORT result;
183
184 DecWordToASCII(digit, (USHORT)pResources->uIRQLevel[0], 0);
185 DosWrite(1, (VOID FAR*)szSBLiveConfig1, sizeof(szSBLiveConfig1)-1, &result);
186 DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
187
188 DosWrite(1, (VOID FAR*)szSBLiveConfig2, sizeof(szSBLiveConfig2)-1, &result);
189 HexWordToASCII(digit, pResources->uIOBase[0], 0);
190 DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
191 }
192 delete pResources;
193
194 //Joystick detection
195 if(pRM->bIsDevDetected(PCI_IDJOY, SEARCH_ID_DEVICEID, TRUE))
196 {
197 pResources = pRM->pGetDevResources(PCI_IDJOY, SEARCH_ID_DEVICEID, TRUE, TRUE);
198 if((pResources) && !pResources->isEmpty() && fVerbose) {
199 USHORT result;
200 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
201 DosWrite(1, (VOID FAR*)szSBLiveConfigJoy, sizeof(szSBLiveConfigJoy)-1, &result);
202 HexWordToASCII(digit, pResources->uIOBase[0], 0);
203 DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
204 }
205 delete pResources;
206 }
207 if (fVerbose) {
208 USHORT result;
209 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
210 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
211 }
212
213 // Build the MPU401 object only if we got a good 2115 init.
214 // First create a timer, then the HW object.
215 TIMER* pMPUTimer =
216 new TIMER(NULL, MIDI_TimerInterval, STREAM_MPU401_PLAY );
217 if (pMPUTimer->eState() != TIMER_Disabled)
218 new MPU_401(pMPUTimer);
219
220 SetHardwareType(AUDIOHW_MPU401_PLAY, MIDI, OPERATION_PLAY, 0);
221 SetHardwareType(AUDIOHW_MPU401_PLAY, DATATYPE_MIDI, OPERATION_PLAY, 0);
222
223//// SetHardwareType(AUDIOHW_MPU401_PLAY, 0, OPERATION_PLAY, 0); //### Must be fixed.
224 // DART on Warp3
225 SetHardwareType(AUDIOHW_WAVE_PLAY, DATATYPE_NULL, OPERATION_PLAY, 0);
226 SetHardwareType(AUDIOHW_WAVE_CAPTURE, DATATYPE_NULL, OPERATION_RECORD, 0);
227
228 // Build the Wave Playback Hardware object
229 new WAVEPLAY();
230 new WAVEREC();
231
232#if 0
233 // fill in the ADAPTERINFO
234 codec_info.ulNumPorts = NUMIORANGES;
235 codec_info.Range[0].ulPort = pResourcesWSS->uIOBase[0];
236 codec_info.Range[0].ulRange = pResourcesWSS->uIOLength[0];
237 codec_info.Range[1].ulPort = pResourcesWSS->uIOBase[1];
238 codec_info.Range[1].ulRange = pResourcesWSS->uIOLength[1];
239 codec_info.Range[2].ulPort = pResourcesWSS->uIOBase[2];
240 codec_info.Range[2].ulRange = pResourcesWSS->uIOLength[2];
241 codec_info.Range[3].ulPort = pResourcesICS->uIOBase[0];
242 codec_info.Range[3].ulRange = pResourcesICS->uIOLength[0];
243
244 // set up the addressing to the codec data for the vdd
245 pfcodec_info = (ADAPTERINFO __far *)&codec_info;
246 DevHelp_VirtToLin (SELECTOROF(pfcodec_info), (ULONG)(OFFSETOF(pfcodec_info)),
247 (PLIN)&pLincodec);
248
249 // copy the pdd name out of the header.
250 for (int i = 0; i < sizeof(szPddName)-1 ; i++) {
251 if (phdr->abName[i] <= ' ')
252 break;
253 szPddName[i] = phdr->abName[i];
254 }
255 // register the VDD IDC entry point..
256 DevHelp_RegisterPDD ((NPSZ)szPddName, (PFN)IDCEntry_VDD);
257#endif
258
259 prp->usStatus = RPDONE;
260 prp->s.init_out.usCodeEnd = (USHORT) &end_of_text;
261 prp->s.init_out.usDataEnd = (USHORT) &end_of_heap;
262}
Note: See TracBrowser for help on using the repository browser.