1 | /* $Id: init.cpp 142 2000-04-23 14:55:46Z ktk $ */
|
---|
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 |
|
---|
31 | extern "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 |
|
---|
58 | // Default MIDI timer interval, milliseconds.
|
---|
59 | static USHORT MIDI_TimerInterval = 10;
|
---|
60 |
|
---|
61 | static char szSBLive[] = "SoundBlaster Live! MMPM/2 Audio Driver v"SBLIVE_VERSION;
|
---|
62 | static char szCopyRight[] = "Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)";
|
---|
63 | static char NEWLINE[] = "\r\n";
|
---|
64 |
|
---|
65 | //
|
---|
66 | // ASCII Z-String used to register for PDD-VDD IDC must
|
---|
67 | // Name is copied from header at runtime.
|
---|
68 | //
|
---|
69 | char szPddName [9] = {0};
|
---|
70 |
|
---|
71 | ResourceManager* pRM = 0; // Resource manager object.
|
---|
72 |
|
---|
73 | //
|
---|
74 | // Strategy Init
|
---|
75 | //
|
---|
76 | void StrategyInit(PREQPACKET prp)
|
---|
77 | {
|
---|
78 | Device_Help = (PFN) prp->s.init_in.ulDevHlp;
|
---|
79 | prp->s.init_out.usCodeEnd = 0;
|
---|
80 | prp->s.init_out.usDataEnd = 0;
|
---|
81 | prp->usStatus = RPDONE | RPERR | RPGENFAIL;
|
---|
82 |
|
---|
83 | /* Initialize Heap. */
|
---|
84 | unsigned uInitSize; // Actual size of Heap following initialization.
|
---|
85 | uInitSize = HeapInit( HEAP_SIZE );
|
---|
86 | if ((HEAP_SIZE-uInitSize) > 64) { // Should get size of request, less some overhead.
|
---|
87 | // ### pError->vLog( HeapInitFailure ); //### Error log 'pError' not yet created.
|
---|
88 | return;
|
---|
89 | }
|
---|
90 | /* Heap initialized. */
|
---|
91 |
|
---|
92 | // Initialize global lists.
|
---|
93 | pAudioHWList = new QUEUEHEAD;
|
---|
94 | pStreamList = new QUEUEHEAD;
|
---|
95 | pTimerList = new QUEUEHEAD;
|
---|
96 |
|
---|
97 | // Fetch command line parameters.
|
---|
98 | if (!GetParms(prp->s.init_in.szArgs)) {
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Now that we've grabbed our cmd line options,
|
---|
103 | // we can start processing stuff that depends on those switches.
|
---|
104 |
|
---|
105 | if (fInt3BeforeInit) int3();
|
---|
106 |
|
---|
107 | // If we got a /V (verbose) flag on the DEVICE= command, route messages
|
---|
108 | // to the display.
|
---|
109 | if (fVerbose) {
|
---|
110 | USHORT result;
|
---|
111 |
|
---|
112 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
113 | DosWrite(1, (VOID FAR*)szSBLive, strlen(szSBLive), &result);
|
---|
114 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
115 |
|
---|
116 | DosWrite(1, (VOID FAR*)szCopyRight, sizeof(szCopyRight), &result);
|
---|
117 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
118 | DosWrite(1, (VOID FAR*)NEWLINE, sizeof(NEWLINE)-1, &result);
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (szCL_DevName[0] != ' ') // Was a valid device name specified?
|
---|
122 | memcpy(phdr->abName,szCL_DevName,8); // yes, copy it to the dev header
|
---|
123 |
|
---|
124 | // Resources identified by the Resource Manager are saved into the
|
---|
125 | // *pResourcesWSS and *pResourcesICS objects, repectively.
|
---|
126 |
|
---|
127 | pRM = new ResourceManager(); // Create the RM object.
|
---|
128 | if (! pRM) {
|
---|
129 | return;
|
---|
130 | }
|
---|
131 | else if (pRM->getState() != rmDriverCreated) {
|
---|
132 | return;
|
---|
133 | }
|
---|
134 |
|
---|
135 | // Build the MPU401 object only if we got a good 2115 init.
|
---|
136 | // First create a timer, then the HW object.
|
---|
137 | TIMER* pMPUTimer =
|
---|
138 | new TIMER( NULL, MIDI_TimerInterval, STREAM_MPU401_PLAY );
|
---|
139 | if (pMPUTimer->eState() != TIMER_Disabled)
|
---|
140 | new MPU_401(pMPUTimer);
|
---|
141 |
|
---|
142 | SetHardwareType(AUDIOHW_MPU401_PLAY, MIDI, OPERATION_PLAY, 0);
|
---|
143 | SetHardwareType(AUDIOHW_MPU401_PLAY, DATATYPE_MIDI, OPERATION_PLAY, 0);
|
---|
144 | SetHardwareType(AUDIOHW_MPU401_PLAY, 0, OPERATION_PLAY, 0); //### Must be fixed.
|
---|
145 |
|
---|
146 | // Build the Wave Playback Hardware object
|
---|
147 | new WAVEPLAY();
|
---|
148 | new WAVEREC();
|
---|
149 |
|
---|
150 | #if 0
|
---|
151 | // fill in the ADAPTERINFO
|
---|
152 | codec_info.ulNumPorts = NUMIORANGES;
|
---|
153 | codec_info.Range[0].ulPort = pResourcesWSS->uIOBase[0];
|
---|
154 | codec_info.Range[0].ulRange = pResourcesWSS->uIOLength[0];
|
---|
155 | codec_info.Range[1].ulPort = pResourcesWSS->uIOBase[1];
|
---|
156 | codec_info.Range[1].ulRange = pResourcesWSS->uIOLength[1];
|
---|
157 | codec_info.Range[2].ulPort = pResourcesWSS->uIOBase[2];
|
---|
158 | codec_info.Range[2].ulRange = pResourcesWSS->uIOLength[2];
|
---|
159 | codec_info.Range[3].ulPort = pResourcesICS->uIOBase[0];
|
---|
160 | codec_info.Range[3].ulRange = pResourcesICS->uIOLength[0];
|
---|
161 |
|
---|
162 | // set up the addressing to the codec data for the vdd
|
---|
163 | pfcodec_info = (ADAPTERINFO __far *)&codec_info;
|
---|
164 | DevHelp_VirtToLin (SELECTOROF(pfcodec_info), (ULONG)(OFFSETOF(pfcodec_info)),
|
---|
165 | (PLIN)&pLincodec);
|
---|
166 |
|
---|
167 | // copy the pdd name out of the header.
|
---|
168 | for (int i = 0; i < sizeof(szPddName)-1 ; i++) {
|
---|
169 | if (phdr->abName[i] <= ' ')
|
---|
170 | break;
|
---|
171 | szPddName[i] = phdr->abName[i];
|
---|
172 | }
|
---|
173 | // register the VDD IDC entry point..
|
---|
174 | DevHelp_RegisterPDD ((NPSZ)szPddName, (PFN)IDCEntry_VDD);
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | prp->usStatus = RPDONE;
|
---|
178 | prp->s.init_out.usCodeEnd = (USHORT) &end_of_text;
|
---|
179 | prp->s.init_out.usDataEnd = (USHORT) &end_of_heap;
|
---|
180 | }
|
---|