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

Last change on this file since 498 was 492, checked in by Paul Smedley, 15 years ago

Bump Copyright labels to 2010

File size: 8.9 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#include <devrp.h>
34#include "devown.h"
35#include <version.h>
36#include <ossidc32.h>
37#include <dbgos2.h>
38#include <printfos2.h>
39#include <irqos2.h>
40//#include <bsedos16.h>
41#ifdef KEE
42#include <kee.h>
43#endif
44#include "parse.h"
45
46const char ERR_ERROR[] = "ERROR: ";
47const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
48const char ERR_INIT[] = "Initialization failed\r\r\n";
49const char ERR_NAMES[] = "Query names failed\r\r\n";
50const char szALSA[] = "\r\n"PRODUCT_NAME" v"UNIAUD_VERSION"\r\nBased on ALSA "ALSA_VERSION"\r\n";
51
52//const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
53const char szCopyRight2[]= "Copyright 2000-2010 The ALSA Project\r\n\r\n";
54const char szCopyRight3[]= "Copyright 2005-2010 Netlabs http://www.netlabs.org\r\n";
55
56const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
57const char szMixerFound[]= "Detected Mixer: ";
58const char szEOL[] = "\r\n";
59
60typedef struct {
61 USHORT MsgLength;
62 WORD32 MsgPtr;
63} MSG_TABLE;
64
65extern "C" FARPTR16 MSG_TABLE32;
66extern "C" char szLastALSAError1[];
67extern "C" char szLastALSAError2[];
68extern "C" int sprintf (char *buffer, const char *format, ...);
69
70extern "C" int wrOffset;
71extern "C" char *szprintBuf;
72extern "C" APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
73extern "C" APIRET APIENTRY DOS16CLOSE(HFILE hFile);
74extern "C" APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
75extern "C" void SaveBuffer(void);
76
77//Print messages with DosWrite when init is done or has failed (see startup.asm)
78void DevSaveMessage(char FAR48 *str, int length)
79{
80 MSG_TABLE FAR48 *msg = (MSG_TABLE FAR48 *)MAKE_FARPTR32(MSG_TABLE32);
81 char FAR48 *str16 = (char FAR48 *)MAKE_FARPTR32(msg->MsgPtr);
82 int i;
83
84 for(i=0;i<length;i++) {
85 str16[msg->MsgLength + i] = str[i];
86 }
87 str16[msg->MsgLength + length] = 0;
88 msg->MsgLength += length;
89
90 return;
91}
92
93void _cdecl printfos2(char *string)
94{
95 DevSaveMessage(string, strlen(string));
96}
97
98//SvL: Lock our 32 bits data & code segments
99int LockSegments(void)
100{
101#ifdef KEE
102 KEEVMLock lock;
103#else
104 char lock[12];
105 ULONG PgCount;
106#endif
107 ULONG segsize;
108
109 /*
110 * Locks DGROUP into physical memory
111 */
112 //NOTE: VMLock rounds base address down to nearest page
113 // So we MUST take this into account when calculating the
114 // size of our code/data
115 segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
116 if(segsize & 0xFFF) {
117 segsize += PAGE_SIZE;
118 }
119 segsize &= ~0xFFF;
120#ifdef KEE
121 if(KernVMLock(VMDHL_LONG,
122 (PVOID)((OffsetBeginDS32) & ~0xFFF),
123 segsize,
124 &lock,
125 (KEEVMPageList*)-1,
126 0)) {
127#else
128 if(DevVMLock(VMDHL_LONG,
129 ((OffsetBeginDS32) & ~0xFFF),
130 segsize,
131 (LINEAR)-1,
132 (LINEAR)lock,
133 (LINEAR)&PgCount)) {
134#endif
135 return(1);
136 }
137 /*
138 * Locks CODE32 into physical memory
139 */
140 segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
141 if(segsize & 0xFFF) {
142 segsize += PAGE_SIZE;
143 }
144 segsize &= ~0xFFF;
145#ifdef KEE
146 if(KernVMLock(VMDHL_LONG,
147 (PVOID)((OffsetBeginCS32) & ~0xFFF),
148 segsize,
149 &lock,
150 (KEEVMPageList*)-1,
151 0)) {
152#else
153 if(DevVMLock(VMDHL_LONG,
154 ((OffsetBeginCS32) & ~0xFFF),
155 segsize,
156 (LINEAR)-1,
157 (LINEAR)lock,
158 (LINEAR)&PgCount)) {
159#endif
160 return(1);
161 }
162 return 0;
163}
164
165// Write a string of specified length
166static VOID WriteString(const char __far* str, int length)
167{
168 // Write the string
169 DevSaveMessage((char __far *)str, length);
170 return;
171}
172
173#if 0
174void SaveBuffer(void)
175{
176 ULONG result;
177 HFILE hFile;
178 ULONG usAction;
179 // write log to file at end of INIT strategy
180 if(DOS16OPEN((PSZ)"uniaud.log", &hFile, &usAction, 0,
181 FILE_NORMAL, FILE_OPEN | OPEN_ACTION_CREATE_IF_NEW,
182 OPEN_ACCESS_READWRITE |
183 OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH,
184 NULL ) == 0)
185 {
186 if (szprintBuf)
187 DOS16WRITE(hFile, szprintBuf, wrOffset, &result);
188
189 DOS16CLOSE(hFile);
190 }
191
192 return;
193}
194#endif
195// Initialize device driver
196WORD32 DiscardableInit(RPInit __far* rp)
197{
198 char debugmsg[64];
199 char FAR48 *args;
200
201#ifdef KEE
202 GetTKSSBase();
203#endif
204
205 if(LockSegments()) {
206 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
207 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
208 return RPDONE | RPERR_COMMAND;
209 }
210
211 rp->Out.FinalCS = 0;
212 rp->Out.FinalDS = 0;
213
214 args = MAKE_FARPTR32(rp->In.Args);
215 GetParms(args);
216
217 if(fVerbose) {
218 WriteString(szALSA, sizeof(szALSA)-1);
219 WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
220 WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
221 }
222
223 if(fDebug) {
224 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
225 WriteString(debugmsg, strlen(debugmsg));
226 }
227
228 //get the current time (to force retrieval of GIS pointer)
229 os2gettimemsec();
230
231 char szMixerName[64];
232 char szDeviceName[128];
233
234 if(OSS32_Initialize() != OSSERR_SUCCESS)
235 {
236 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
237 WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
238 if(szLastALSAError1[0]) {
239 WriteString(szLastALSAError1, strlen(szLastALSAError1));
240 }
241 if(szLastALSAError2[0]) {
242 WriteString(szLastALSAError2, strlen(szLastALSAError2));
243 }
244 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
245 } else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
246 sizeof(szDeviceName),szMixerName,
247 sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
248 {
249 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
250 WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
251 if(szLastALSAError1[0]) {
252 WriteString(szLastALSAError1, strlen(szLastALSAError1));
253 }
254 if(szLastALSAError2[0]) {
255 WriteString(szLastALSAError2, strlen(szLastALSAError2));
256 }
257
258 // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
259 }
260 else
261 if(fVerbose) {
262 WriteString(szDeviceName, strlen(szDeviceName));
263 WriteString(szEOL, sizeof(szEOL)-1);
264 WriteString(szMixerFound, sizeof(szMixerFound)-1);
265 WriteString(szMixerName, strlen(szMixerName));
266 WriteString(szEOL, sizeof(szEOL)-1);
267
268#if 0
269 for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++) {
270 if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
271 {
272 WriteString(szDeviceName, strlen(szDeviceName));
273 WriteString(szEOL, sizeof(szEOL)-1);
274 WriteString(szMixerFound, sizeof(szMixerFound)-1);
275 WriteString(szMixerName, strlen(szMixerName));
276 WriteString(szEOL, sizeof(szEOL)-1);
277 }
278 else break;
279 }
280#endif
281 WriteString(szEOL, sizeof(szEOL)-1);
282 }
283#ifdef DEBUG
284 dprintf(("DiscardableInit. cp1"));
285#endif
286 // Complete the installation
287 rp->Out.FinalCS = _OffsetFinalCS16;
288 rp->Out.FinalDS = _OffsetFinalDS16;
289#ifdef DEBUG
290 dprintf(("DiscardableInit. cp2"));
291#endif
292
293// SaveBuffer();
294
295 // Confirm a successful installation
296 return RPDONE;
297}
298
Note: See TracBrowser for help on using the repository browser.