source: GPL/branches/uniaud32-2.1.x/drv32/init.c@ 588

Last change on this file since 588 was 588, checked in by David Azarewicz, 9 years ago

Build system cleanup

File size: 9.1 KB
Line 
1/* $Id: init.c,v 1.1.1.1 2003/07/02 13:56:56 eleph Exp $ */
2/*
3 * Init strategy handler
4 *
5 * (C) 2000-2002 InnoTek Systemberatung GmbH
6 * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
21 * USA.
22 *
23 */
24
25#define INCL_NOPMAPI
26#define INCL_DOSINFOSEG // Need Global info seg in rm.cpp algorithms
27#include <os2.h>
28#include <string.h>
29
30// Device support
31#include <devhelp.h>
32#include <devtype.h>
33//DAZ #include <devrp.h>
34#include <strategy.h>
35#include "devown.h"
36#include <version.h>
37#include <ossidc32.h>
38#include <dbgos2.h>
39#include <irqos2.h>
40//#include <bsedos16.h>
41#ifdef KEE
42#include <kee.h>
43#endif
44#include "parse.h"
45#include "malloc.h"
46
47const char ERR_ERROR[] = "ERROR: ";
48const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
49const char ERR_INIT[] = "Initialization failed\r\r\n";
50const char ERR_NAMES[] = "Query names failed\r\r\n";
51#ifdef DEBUG
52const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"-DEBUG\r\nBased on ALSA "ALSA_VERSION"\r\n";
53#else
54const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on ALSA "ALSA_VERSION"\r\n";
55#endif
56
57//const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
58const char szCopyRight2[]= "Copyright 2000-2010 The ALSA Project\r\n\r\n";
59const char szCopyRight3[]= "Copyright 2005-2010 Netlabs http://www.netlabs.org\r\n";
60
61const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
62const char szMixerFound[]= "Detected Mixer: ";
63const char szEOL[] = "\r\n";
64
65typedef struct {
66 USHORT MsgLength;
67 WORD32 MsgPtr;
68} MSG_TABLE;
69
70extern FARPTR16 MSG_TABLE32;
71extern char szLastALSAError1[];
72extern char szLastALSAError2[];
73extern int sprintf (char *buffer, const char *format, ...);
74
75extern APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
76extern APIRET APIENTRY DOS16CLOSE(HFILE hFile);
77extern APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
78extern void SaveBuffer(void);
79
80#define VMDHA_FIXED 0x0002
81
82extern APIRET VMAlloc(ULONG size, ULONG flags, char NEAR* *pAddr);
83
84//Print messages with DosWrite when init is done or has failed (see startup.asm)
85void DevSaveMessage(char FAR48 *str, int length)
86{
87 MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32);
88 char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr);
89 int i;
90
91 for(i=0;i<length;i++) {
92 str16[msg->MsgLength + i] = str[i];
93 }
94 str16[msg->MsgLength + length] = 0;
95 msg->MsgLength += length;
96
97 return;
98}
99
100//SvL: Lock our 32 bits data & code segments
101int LockSegments(void)
102{
103#ifdef KEE
104 KEEVMLock lock;
105#else
106 char lock[12];
107 ULONG PgCount;
108#endif
109 ULONG segsize;
110
111 /*
112 * Locks DGROUP into physical memory
113 */
114 //NOTE: VMLock rounds base address down to nearest page
115 // So we MUST take this into account when calculating the
116 // size of our code/data
117 segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
118 if(segsize & 0xFFF) {
119 segsize += PAGE_SIZE;
120 }
121 segsize &= ~0xFFF;
122#ifdef KEE
123 if(KernVMLock(VMDHL_LONG,
124 (PVOID)((OffsetBeginDS32) & ~0xFFF),
125 segsize,
126 &lock,
127 (KEEVMPageList*)-1,
128 0)) {
129#else
130 if(DevVMLock(VMDHL_LONG,
131 ((OffsetBeginDS32) & ~0xFFF),
132 segsize,
133 (LINEAR)-1,
134 (LINEAR)lock,
135 (LINEAR)&PgCount)) {
136#endif
137 return(1);
138 }
139 /*
140 * Locks CODE32 into physical memory
141 */
142 segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
143 if(segsize & 0xFFF) {
144 segsize += PAGE_SIZE;
145 }
146 segsize &= ~0xFFF;
147#ifdef KEE
148 if(KernVMLock(VMDHL_LONG,
149 (PVOID)((OffsetBeginCS32) & ~0xFFF),
150 segsize,
151 &lock,
152 (KEEVMPageList*)-1,
153 0)) {
154#else
155 if(DevVMLock(VMDHL_LONG,
156 ((OffsetBeginCS32) & ~0xFFF),
157 segsize,
158 (LINEAR)-1,
159 (LINEAR)lock,
160 (LINEAR)&PgCount)) {
161#endif
162 return(1);
163 }
164 return 0;
165}
166
167// Write a string of specified length
168static VOID WriteString(const char __far* str, int length)
169{
170 // Write the string
171 DevSaveMessage((char __far *)str, length);
172 return;
173}
174
175#if 0
176void SaveBuffer(void)
177{
178 ULONG result;
179 HFILE hFile;
180 ULONG usAction;
181 // write log to file at end of INIT strategy
182 if(DOS16OPEN((PSZ)"uniaud.log", &hFile, &usAction, 0,
183 FILE_NORMAL, FILE_OPEN | OPEN_ACTION_CREATE_IF_NEW,
184 OPEN_ACCESS_READWRITE |
185 OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH,
186 NULL ) == 0)
187 {
188 if (szprintBuf)
189 DOS16WRITE(hFile, szprintBuf, wrOffset, &result);
190
191 DOS16CLOSE(hFile);
192 }
193
194 return;
195}
196#endif
197// Initialize device driver
198WORD32 DiscardableInit(REQPACKET __far* rp)
199{
200 char debugmsg[64];
201 char FAR48 *args;
202
203#ifdef KEE
204 GetTKSSBase();
205#endif
206
207 if(LockSegments())
208 {
209 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
210 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
211 return RPDONE | RPERR_BADCOMMAND;
212 }
213
214 DebugLevel = 1;
215 rp->init_out.usCodeEnd = 0;
216 rp->init_out.usDataEnd = 0;
217
218 if ( szprintBuf == 0 )
219 {
220 VMAlloc( DBG_MAX_BUF_SIZE, VMDHA_FIXED, &szprintBuf );
221 if (szprintBuf)
222 {
223 memset( szprintBuf, 0, DBG_MAX_BUF_SIZE );
224 wrOffset= 0;
225 }
226 }
227 if (!HeapInit(HEAP_SIZE))
228 {
229 rprintf(("HeapInit failed!"));
230 }
231
232 args = MAKE_FARPTR32(rp->init_in.szArgs);
233 GetParms(args);
234
235 #ifdef DEBUG
236 rprintf(("Uniaud32 version %s-DEBUG",UNIAUD_VERSION));
237 #else
238 rprintf(("Uniaud32 version %s",UNIAUD_VERSION));
239 #endif
240
241 if(fVerbose)
242 {
243 WriteString(szALSA, sizeof(szALSA)-1);
244 WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
245 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
246 }
247
248 if(fDebug)
249 {
250 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
251 WriteString(debugmsg, strlen(debugmsg));
252 }
253
254 //get the current time (to force retrieval of GIS pointer)
255 os2gettimemsec();
256
257 char szMixerName[64];
258 char szDeviceName[128];
259
260 if(OSS32_Initialize() != OSSERR_SUCCESS)
261 {
262 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
263 WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
264 if(szLastALSAError1[0])
265 {
266 WriteString(szLastALSAError1, strlen(szLastALSAError1));
267 }
268 if(szLastALSAError2[0])
269 {
270 WriteString(szLastALSAError2, strlen(szLastALSAError2));
271 }
272 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
273 }
274 else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
275 sizeof(szDeviceName),szMixerName,
276 sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
277 {
278 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
279 WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
280 if(szLastALSAError1[0])
281 {
282 WriteString(szLastALSAError1, strlen(szLastALSAError1));
283 }
284 if(szLastALSAError2[0])
285 {
286 WriteString(szLastALSAError2, strlen(szLastALSAError2));
287 }
288
289 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
290 }
291 else
292 if(fVerbose)
293 {
294 WriteString(szDeviceName, strlen(szDeviceName));
295 WriteString(szEOL, sizeof(szEOL)-1);
296 WriteString(szMixerFound, sizeof(szMixerFound)-1);
297 WriteString(szMixerName, strlen(szMixerName));
298 WriteString(szEOL, sizeof(szEOL)-1);
299
300 #if 0
301 for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++)
302 {
303 if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
304 {
305 WriteString(szDeviceName, strlen(szDeviceName));
306 WriteString(szEOL, sizeof(szEOL)-1);
307 WriteString(szMixerFound, sizeof(szMixerFound)-1);
308 WriteString(szMixerName, strlen(szMixerName));
309 WriteString(szEOL, sizeof(szEOL)-1);
310 }
311 else break;
312 }
313 #endif
314 WriteString(szEOL, sizeof(szEOL)-1);
315 }
316 // Complete the installation
317 rp->init_out.usCodeEnd = _OffsetFinalCS16;
318 rp->init_out.usDataEnd = _OffsetFinalDS16;
319
320 //SaveBuffer();
321
322 // Confirm a successful installation
323 return RPDONE;
324}
325
Note: See TracBrowser for help on using the repository browser.