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

Last change on this file since 175 was 152, checked in by sandervl, 25 years ago

misc updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/* $Id: init.cpp 152 2000-07-17 18:37:33Z 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#define PCI_ID ((PCI_DEVICE_ID_CREATIVE_EMU10K1<<16UL)|PCI_VENDOR_ID_CREATIVE)
68
69// Default MIDI timer interval, milliseconds.
70static USHORT MIDI_TimerInterval = 10;
71
72static char szSBLive[] = "SoundBlaster Live! MMPM/2 Audio Driver v"SBLIVE_VERSION;
73static char szCopyRight[] = "Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)";
74static char NEWLINE[] = "\r\n";
75static char szSBLiveNotFound[] = "SB Live! hardware not detected!";
76static char szSBLiveConfig1[] = "SB Live! configuration: IRQ ";
77static char szSBLiveConfig2[] = ", IO Port 0x";
78
79
80//
81// ASCII Z-String used to register for PDD-VDD IDC must
82// Name is copied from header at runtime.
83//
84char szPddName[9] = {0};
85char digit[16] = {0};
86
87ResourceManager* pRM = 0; // Resource manager object.
88
89//
90// Strategy Init
91//
92void StrategyInit(PREQPACKET prp)
93{
94 Device_Help = (PFN) prp->s.init_in.ulDevHlp;
95 prp->s.init_out.usCodeEnd = 0;
96 prp->s.init_out.usDataEnd = 0;
97 prp->usStatus = RPDONE | RPERR | RPGENFAIL;
98
99 /* Initialize Heap. */
100 unsigned uInitSize; // Actual size of Heap following initialization.
101 uInitSize = HeapInit( HEAP_SIZE );
102 if ((HEAP_SIZE-uInitSize) > 64) { // Should get size of request, less some overhead.
103 // ### pError->vLog( HeapInitFailure ); //### Error log 'pError' not yet created.
104 return;
105 }
106 /* Heap initialized. */
107
108 // Initialize global lists.
109 pAudioHWList = new QUEUEHEAD;
110 pStreamList = new QUEUEHEAD;
111 pTimerList = new QUEUEHEAD;
112
113 // Fetch command line parameters.
114 if (!GetParms(prp->s.init_in.szArgs)) {
115 return;
116 }
117
118 // Now that we've grabbed our cmd line options,
119 // we can start processing stuff that depends on those switches.
120
121 if (fInt3BeforeInit) int3();
122
123 // If we got a /V (verbose) flag on the DEVICE= command, route messages
124 // to the display.
125 if (fVerbose) {
126 USHORT result;
127
128 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
129 DosWrite(1, (VOID FAR*)szSBLive, sizeof(szSBLive)-1, &result);
130 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
131
132 DosWrite(1, (VOID FAR*)szCopyRight, sizeof(szCopyRight), &result);
133 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
134 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
135 }
136
137 if (szCL_DevName[0] != ' ') // Was a valid device name specified?
138 memcpy(phdr->abName,szCL_DevName,8); // yes, copy it to the dev header
139
140 pRM = new ResourceManager(PCI_ID); // Create the RM object.
141 if (! pRM) {
142 return;
143 }
144
145 //SvL: Check if SB Live hardware has been detected by the resource manager
146 if(pRM->getState() != rmDriverCreated || !pRM->bIsDevDetected(PCI_ID, SEARCH_ID_DEVICEID, TRUE))
147 {
148hardware_notfound:
149 USHORT result;
150
151 DosWrite(1, (VOID FAR*)szSBLiveNotFound, sizeof(szSBLiveNotFound)-1, &result);
152 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
153 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
154 return;
155 }
156 LDev_Resources *pResources = pRM->pGetDevResources(PCI_ID, SEARCH_ID_DEVICEID, TRUE);
157 if ((!pResources) || pResources->isEmpty()) {
158 goto hardware_notfound;
159 }
160
161 if (fVerbose) {
162 USHORT result;
163
164 DecWordToASCII(digit, (USHORT)pResources->uIRQLevel[0], 0);
165 DosWrite(1, (VOID FAR*)szSBLiveConfig1, sizeof(szSBLiveConfig1)-1, &result);
166 DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
167
168 DosWrite(1, (VOID FAR*)szSBLiveConfig2, sizeof(szSBLiveConfig2)-1, &result);
169 HexWordToASCII(digit, pResources->uIOBase[0], 0);
170 DosWrite(1, (VOID FAR*)digit, strlen(digit), &result);
171
172 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
173 DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
174 }
175 delete pResources;
176
177 // Build the MPU401 object only if we got a good 2115 init.
178 // First create a timer, then the HW object.
179 TIMER* pMPUTimer =
180 new TIMER(NULL, MIDI_TimerInterval, STREAM_MPU401_PLAY );
181 if (pMPUTimer->eState() != TIMER_Disabled)
182 new MPU_401(pMPUTimer);
183
184 SetHardwareType(AUDIOHW_MPU401_PLAY, MIDI, OPERATION_PLAY, 0);
185 SetHardwareType(AUDIOHW_MPU401_PLAY, DATATYPE_MIDI, OPERATION_PLAY, 0);
186 SetHardwareType(AUDIOHW_MPU401_PLAY, 0, OPERATION_PLAY, 0); //### Must be fixed.
187
188 // Build the Wave Playback Hardware object
189 new WAVEPLAY();
190 new WAVEREC();
191
192#if 0
193 // fill in the ADAPTERINFO
194 codec_info.ulNumPorts = NUMIORANGES;
195 codec_info.Range[0].ulPort = pResourcesWSS->uIOBase[0];
196 codec_info.Range[0].ulRange = pResourcesWSS->uIOLength[0];
197 codec_info.Range[1].ulPort = pResourcesWSS->uIOBase[1];
198 codec_info.Range[1].ulRange = pResourcesWSS->uIOLength[1];
199 codec_info.Range[2].ulPort = pResourcesWSS->uIOBase[2];
200 codec_info.Range[2].ulRange = pResourcesWSS->uIOLength[2];
201 codec_info.Range[3].ulPort = pResourcesICS->uIOBase[0];
202 codec_info.Range[3].ulRange = pResourcesICS->uIOLength[0];
203
204 // set up the addressing to the codec data for the vdd
205 pfcodec_info = (ADAPTERINFO __far *)&codec_info;
206 DevHelp_VirtToLin (SELECTOROF(pfcodec_info), (ULONG)(OFFSETOF(pfcodec_info)),
207 (PLIN)&pLincodec);
208
209 // copy the pdd name out of the header.
210 for (int i = 0; i < sizeof(szPddName)-1 ; i++) {
211 if (phdr->abName[i] <= ' ')
212 break;
213 szPddName[i] = phdr->abName[i];
214 }
215 // register the VDD IDC entry point..
216 DevHelp_RegisterPDD ((NPSZ)szPddName, (PFN)IDCEntry_VDD);
217#endif
218
219 prp->usStatus = RPDONE;
220 prp->s.init_out.usCodeEnd = (USHORT) &end_of_text;
221 prp->s.init_out.usDataEnd = (USHORT) &end_of_heap;
222}
Note: See TracBrowser for help on using the repository browser.