[18] | 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 |
|
---|
| 46 | #pragma comment(copyright,"@#Netlabs: Universal audio driver for OS/2 v.1.1.3#@ (c) Netlabs 2005")
|
---|
| 47 |
|
---|
| 48 | const char ERR_ERROR[] = "ERROR: ";
|
---|
| 49 | const char ERR_LOCK[] = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
|
---|
| 50 | const char ERR_INIT[] = "Initialization failed\r\r\n";
|
---|
| 51 | const char ERR_NAMES[] = "Query names failed\r\r\n";
|
---|
| 52 | const char szALSA[] = "\r\n\r\nOS/2 Universal Audio Core Driver v"ALSA_VERSION"\r\n";
|
---|
| 53 | const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
|
---|
| 54 | const char szCopyRight2[]= "Copyright 2000-2002 The ALSA Project\r\n\r\n";
|
---|
| 55 | //const char szCopyRight3[]= "Maintained by http://os2.kiev.ua/en/uniaud.php\r\n\r\n";
|
---|
| 56 | const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
|
---|
| 57 | const char szMixerFound[]= "Detected Mixer: ";
|
---|
| 58 | const char szEOL[] = "\r\n";
|
---|
| 59 |
|
---|
| 60 | typedef struct {
|
---|
| 61 | USHORT MsgLength;
|
---|
| 62 | WORD32 MsgPtr;
|
---|
| 63 | } MSG_TABLE;
|
---|
| 64 |
|
---|
| 65 | extern "C" FARPTR16 MSG_TABLE32;
|
---|
| 66 | extern "C" char szLastALSAError1[];
|
---|
| 67 | extern "C" char szLastALSAError2[];
|
---|
| 68 | extern "C" int sprintf (char *buffer, const char *format, ...);
|
---|
| 69 |
|
---|
| 70 | extern "C" int wrOffset;
|
---|
| 71 | extern "C" char *szprintBuf;
|
---|
| 72 | extern "C" APIRET APIENTRY DOS16OPEN(PSZ pszFileName, PHFILE phf, PULONG pulAction, ULONG cbFile, ULONG ulAttribute, ULONG fsOpenFlags, ULONG fsOpenMode, PEAOP2 peaop2 );
|
---|
| 73 | extern "C" APIRET APIENTRY DOS16CLOSE(HFILE hFile);
|
---|
| 74 | extern "C" APIRET APIENTRY DOS16WRITE(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
|
---|
| 75 | extern "C" void SaveBuffer(void);
|
---|
| 76 |
|
---|
| 77 | //Print messages with DosWrite when init is done or has failed (see startup.asm)
|
---|
| 78 | void 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 |
|
---|
| 93 | void _cdecl printfos2(char *string)
|
---|
| 94 | {
|
---|
| 95 | DevSaveMessage(string, strlen(string));
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | //SvL: Lock our 32 bits data & code segments
|
---|
| 99 | int 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
|
---|
| 166 | static 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
|
---|
| 174 | void 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
|
---|
| 196 | WORD32 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(szCopyRight1, sizeof(szCopyRight1)-1);
|
---|
| 220 | WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | // if(fDebug) {
|
---|
| 224 | if(1) {
|
---|
| 225 | sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
|
---|
| 226 | WriteString(debugmsg, strlen(debugmsg));
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | //get the current time (to force retrieval of GIS pointer)
|
---|
| 230 | os2gettimemsec();
|
---|
| 231 |
|
---|
| 232 | char szMixerName[64];
|
---|
| 233 | char szDeviceName[128];
|
---|
| 234 |
|
---|
| 235 | if(OSS32_Initialize() != OSSERR_SUCCESS)
|
---|
| 236 | {
|
---|
| 237 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
|
---|
| 238 | WriteString(ERR_INIT, sizeof(ERR_INIT)-1);
|
---|
| 239 | if(szLastALSAError1[0]) {
|
---|
| 240 | WriteString(szLastALSAError1, strlen(szLastALSAError1));
|
---|
| 241 | }
|
---|
| 242 | if(szLastALSAError2[0]) {
|
---|
| 243 | WriteString(szLastALSAError2, strlen(szLastALSAError2));
|
---|
| 244 | }
|
---|
| 245 | // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
|
---|
| 246 | } else if (OSS32_QueryNames(OSS32_DEFAULT_DEVICE, szDeviceName,
|
---|
| 247 | sizeof(szDeviceName),szMixerName,
|
---|
| 248 | sizeof(szMixerName), TRUE) != OSSERR_SUCCESS)
|
---|
| 249 | {
|
---|
| 250 | WriteString(ERR_ERROR, sizeof(ERR_ERROR)-1);
|
---|
| 251 | WriteString(ERR_NAMES, sizeof(ERR_INIT)-1);
|
---|
| 252 | if(szLastALSAError1[0]) {
|
---|
| 253 | WriteString(szLastALSAError1, strlen(szLastALSAError1));
|
---|
| 254 | }
|
---|
| 255 | if(szLastALSAError2[0]) {
|
---|
| 256 | WriteString(szLastALSAError2, strlen(szLastALSAError2));
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | // !! dont exit when error !! return RPDONE | RPERR_COMMAND;
|
---|
| 260 | }
|
---|
| 261 | else
|
---|
| 262 | if(fVerbose) {
|
---|
| 263 | WriteString(szDeviceName, strlen(szDeviceName));
|
---|
| 264 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
| 265 | WriteString(szMixerFound, sizeof(szMixerFound)-1);
|
---|
| 266 | WriteString(szMixerName, strlen(szMixerName));
|
---|
| 267 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
| 268 |
|
---|
| 269 | #if 0
|
---|
| 270 | for(int i=1;i<OSS32_MAX_AUDIOCARDS;i++) {
|
---|
| 271 | if(OSS32_QueryNames(i, szDeviceName, sizeof(szDeviceName), szMixerName, sizeof(szMixerName)) == OSSERR_SUCCESS)
|
---|
| 272 | {
|
---|
| 273 | WriteString(szDeviceName, strlen(szDeviceName));
|
---|
| 274 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
| 275 | WriteString(szMixerFound, sizeof(szMixerFound)-1);
|
---|
| 276 | WriteString(szMixerName, strlen(szMixerName));
|
---|
| 277 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
| 278 | }
|
---|
| 279 | else break;
|
---|
| 280 | }
|
---|
| 281 | #endif
|
---|
| 282 | WriteString(szEOL, sizeof(szEOL)-1);
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | // Complete the installation
|
---|
| 286 | rp->Out.FinalCS = _OffsetFinalCS16;
|
---|
| 287 | rp->Out.FinalDS = _OffsetFinalDS16;
|
---|
| 288 |
|
---|
| 289 | // SaveBuffer();
|
---|
| 290 |
|
---|
| 291 | // Confirm a successful installation
|
---|
| 292 | return RPDONE;
|
---|
| 293 | }
|
---|
| 294 |
|
---|