source: cmedia/trunk/Drv32/init.c@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 6.7 KB
Line 
1/* $Id: init.c,v 1.3 2001/04/14 17:03:35 sandervl Exp $ */
2
3//******************************************************************************
4// Init strategy handler
5//
6// Copyright 2000 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//******************************************************************************
24extern "C" { // 16-bit header files are not C++ aware
25#define INCL_NOPMAPI
26#define INCL_DOSMISC
27#include <os2.h>
28}
29#include <string.h>
30
31// Device support
32#include <devhelp.h>
33#include <devtype.h>
34#include <devrp.h>
35#include "devown.h"
36#include <sbversion.h>
37#include <dbgos2.h>
38#ifdef KEE
39#include <kee.h>
40#endif
41
42const char ERR_ERROR[] = "\r\nERROR: ";
43const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\n";
44#ifdef KEE
45const char szSBLive[] = "\r\n\r\n"PRODUCT_NAME" Audio Driver v"PRODUCT_VERSION" (32 Bits KEE)\r\n";
46#else
47const char szSBLive[] = "\r\n\r\n"PRODUCT_NAME" Audio Driver v"PRODUCT_VERSION" (32 Bits)\r\n";
48#endif
49const char szCopyRight[] = "Copyright 1999 ChenLi Tien (Linux Version)\r\n"
50 "Copyright 2000-2001 Sander van Leeuwen (OS/2 Port)\r\n"
51 "Copyright 2001-2005 Rdiger Ihle (OS/2 Port)\r\n\r\n";
52const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
53
54typedef struct {
55 USHORT MsgLength;
56 WORD32 MsgPtr;
57} MSG_TABLE;
58
59
60extern "C" {
61 //Messages
62 extern WORD32 MSG_TABLE32;
63
64 //Module parameters
65 extern int use_line_as_rear;
66 extern int use_line_as_bass;
67 extern int joystick;
68 extern int spdif_inverse;
69 extern int spdif_5v;
70 extern int spdif_src;
71 extern int spdif_copyright;
72 extern int spdif_enable;
73 extern int spdif_loop;
74 extern int mic_boost;
75
76 int sprintf (char *buffer, const char *format, ...);
77};
78
79
80//Print messages with DosWrite when init is done or has failed (see startup.asm)
81void DevSaveMessage(char __far *str, int length)
82{
83 MSG_TABLE __far *msg = (MSG_TABLE __far *)__Make48Pointer(MSG_TABLE32);
84 char __far *str16 = (char __far *)__Make48Pointer(msg->MsgPtr);
85
86 if( length >= 0 ) {
87 _fmemcpy(str16 + msg->MsgLength, str, length);
88 msg->MsgLength += length;
89 } else {
90 msg->MsgLength = 0;
91 }
92
93 str16[msg->MsgLength] = 0;
94}
95
96//SvL: Lock our 32 bits data & code segments
97int LockSegments(void)
98{
99#ifdef KEE
100 KEEVMLock lock;
101#else
102 char lock[12];
103 ULONG PgCount;
104#endif
105 ULONG segsize;
106
107 /*
108 * Locks DGROUP into physical memory
109 */
110 //NOTE: VMLock rounds base address down to nearest page
111 // So we MUST take this into account when calculating the
112 // size of our code/data
113 segsize = OffsetFinalDS32 - ((OffsetBeginDS32) & ~0xFFF);
114 if(segsize & 0xFFF) {
115 segsize += PAGE_SIZE;
116 }
117 segsize &= ~0xFFF;
118#ifdef KEE
119 if(KernVMLock(VMDHL_LONG,
120 (PVOID)((OffsetBeginDS32) & ~0xFFF),
121 segsize,
122 &lock,
123 (KEEVMPageList*)-1,
124 0)) {
125#else
126 if(DevVMLock(VMDHL_LONG,
127 ((OffsetBeginDS32) & ~0xFFF),
128 segsize,
129 (LINEAR)-1,
130 __StackToFlat((ULONG)lock),
131 (LINEAR)__StackToFlat((ULONG)&PgCount))) {
132#endif
133 return(1);
134 }
135 /*
136 * Locks CODE32 into physical memory
137 */
138 segsize = OffsetFinalCS32 - ((OffsetBeginCS32) & ~0xFFF);
139 if(segsize & 0xFFF) {
140 segsize += PAGE_SIZE;
141 }
142 segsize &= ~0xFFF;
143#ifdef KEE
144 if(KernVMLock(VMDHL_LONG,
145 (PVOID)((OffsetBeginCS32) & ~0xFFF),
146 segsize,
147 &lock,
148 (KEEVMPageList*)-1,
149 0)) {
150#else
151 if(DevVMLock(VMDHL_LONG,
152 ((OffsetBeginCS32) & ~0xFFF),
153 segsize,
154 (LINEAR)-1,
155 __StackToFlat((ULONG)lock),
156 (LINEAR)__StackToFlat((ULONG)&PgCount))) {
157#endif
158 return(1);
159 }
160 return 0;
161}
162
163
164// Write a string of specified length
165static VOID WriteString(const char __far* str, int length)
166{
167 // Write the string
168 DevSaveMessage((char __far *)str, length);
169 return;
170}
171
172// Initialize device driver
173WORD32 DiscardableInit(RPInit __far* rp)
174{
175 unsigned twochars, options;
176 char debugmsg[64];
177 char FAR48 *args;
178 char ch;
179
180 GetTKSSBase();
181
182 WriteString(szSBLive, sizeof(szSBLive)-1);
183
184 if(LockSegments()) {
185 WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
186 WriteString(ERR_LOCK, sizeof(ERR_LOCK)-1);
187
188 rp->Out.FinalCS = rp->Out.FinalDS = 0;
189 return RPDONE | RPERR;
190 }
191
192 WriteString(szCopyRight, sizeof(szCopyRight)-1);
193
194 //Do you init here:
195
196 args = __Make48Pointer(rp->In.Args);
197 while(*args && *args == ' ') args++;
198 while(*args && *args != ' ') args++;
199
200 twochars = options = 0;
201 while( (ch = *args++) != '\0' ) {
202 if( ch >= 'a' && ch <= 'z' ) ch &= 0x5f;
203 twochars = (twochars << 8) | ch;
204 switch( twochars & 0xffff ) {
205 case ('/' << 8) | 'D' : options |= 3; break;
206 case ('/' << 8) | 'V' : options |= 2; break;
207 case ('/' << 8) | 'R' : use_line_as_rear ^= 1; break;
208 case ('/' << 8) | 'B' : use_line_as_bass ^= 1; break;
209 case ('/' << 8) | 'N' : joystick ^= 1; break;
210 case ('/' << 8) | 'I' : spdif_inverse ^= 1; break;
211 case ('/' << 8) | '0' : spdif_5v ^= 1; break;
212 case ('/' << 8) | '2' : spdif_src ^= 1; break;
213 case ('/' << 8) | 'C' : spdif_copyright ^= 1; break;
214 case ('/' << 8) | 'S' : spdif_enable ^= 1; break;
215 case ('/' << 8) | 'L' : spdif_loop ^= 1; break;
216 case ('/' << 8) | 'M' : mic_boost ^= 1; break;
217 }
218 }
219
220 if( options & 1 ) {
221 WriteString(debugmsg,
222 sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32));
223 }
224
225 if( !(options & 2) ) {
226 WriteString(NULL, -1);
227 }
228
229 // Complete the installation
230 rp->Out.FinalCS = _OffsetFinalCS16;
231 rp->Out.FinalDS = _OffsetFinalDS16;
232
233 // Confirm a successful installation
234 return RPDONE;
235}
236
237
238
239
Note: See TracBrowser for help on using the repository browser.