[541] | 1 | /*
|
---|
| 2 | * This file is part of uniaud.dll.
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2010 Mensys BV
|
---|
| 5 | * Copyright (c) 2007 Vlad Stelmahovsky aka Vladest
|
---|
| 6 | *
|
---|
| 7 | * This library is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU Lesser General Public License as
|
---|
| 9 | * published by the Free Software Foundation, either version 3 of
|
---|
| 10 | * the License, or (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * This library is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU Lesser General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 18 | * License and the GNU General Public License along with this library.
|
---|
| 19 | * If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 | #define INCL_DOS
|
---|
| 22 | #define INCL_DOSERRORS
|
---|
| 23 | #include <os2.h>
|
---|
| 24 | #include <stdlib.h>
|
---|
| 25 | #include <stdio.h>
|
---|
| 26 | #include <string.h>
|
---|
| 27 |
|
---|
| 28 | #include "internal.h"
|
---|
| 29 |
|
---|
| 30 | UniaudCardInstance UniInst[MAX_CARDS] = {0};
|
---|
| 31 |
|
---|
| 32 | int cards_num = 0;
|
---|
| 33 | int DebugMode = 0;
|
---|
| 34 |
|
---|
| 35 | int DriverOpen(void)
|
---|
| 36 | {
|
---|
| 37 | HFILE hFile = 0;
|
---|
| 38 | ULONG usAction;
|
---|
| 39 |
|
---|
| 40 | if(DosOpen((PSZ)"ALSA32$", &hFile, &usAction, 0,
|
---|
| 41 | FILE_NORMAL, FILE_OPEN, OPEN_ACCESS_READWRITE |
|
---|
| 42 | OPEN_SHARE_DENYNONE | OPEN_FLAGS_WRITE_THROUGH,
|
---|
| 43 | NULL ) == NO_ERROR)
|
---|
| 44 | return (int)hFile;
|
---|
| 45 |
|
---|
| 46 | return -UNIAUD_ALSA32OPEN_ERROR;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | int uniaud_get_card_info(int card_id, UniaudCardInfo *info)
|
---|
| 50 | {
|
---|
| 51 | HFILE hFile = 0;
|
---|
| 52 | //ULONG usAction;
|
---|
| 53 | ULONG id_len;
|
---|
| 54 | ULONG len;
|
---|
| 55 | ULONG rc;
|
---|
| 56 |
|
---|
| 57 | /* checking cards range */
|
---|
| 58 | if (card_id < 0 || card_id >= cards_num) // counting cards from 0
|
---|
| 59 | return -UNIAUD_INVALID_CARD;
|
---|
| 60 |
|
---|
| 61 | if ((int)(hFile = DriverOpen()) >= 0)
|
---|
| 62 | {
|
---|
| 63 | rc = DosDevIOCtl(hFile, CAT_IOCTL_OSS32, IOCTL_OSS32_CARD_INFO,
|
---|
| 64 | &card_id, sizeof(card_id), &id_len,
|
---|
| 65 | &info, sizeof(info), &len);
|
---|
| 66 | DosClose(hFile);
|
---|
| 67 | if (rc != 0)
|
---|
| 68 | return -UNIAUD_ERROR_IN_DRIVER;
|
---|
| 69 |
|
---|
| 70 | return UNIAUD_NO_ERROR;
|
---|
| 71 | }
|
---|
| 72 | else
|
---|
| 73 | return -UNIAUD_ALSA32OPEN_ERROR;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | static int _uniaud_get_cards(void)
|
---|
| 77 | {
|
---|
| 78 | HFILE hFile = 0;
|
---|
| 79 | //ULONG usAction;
|
---|
| 80 | ULONG len;
|
---|
| 81 | //ULONG id_len;
|
---|
| 82 | ULONG rc;
|
---|
| 83 | int cards = 0;
|
---|
| 84 |
|
---|
| 85 | if ((int)(hFile = DriverOpen()) >= 0)
|
---|
| 86 | {
|
---|
| 87 | rc = DosDevIOCtl(hFile, CAT_IOCTL_OSS32, IOCTL_OSS32_CARDS_NUM,
|
---|
| 88 | NULL, 0, NULL,
|
---|
| 89 | &cards, sizeof(cards), &len);
|
---|
| 90 | DosClose(hFile);
|
---|
| 91 | if (rc != 0)
|
---|
| 92 | return -UNIAUD_ERROR_IN_DRIVER;
|
---|
| 93 |
|
---|
| 94 | return cards;
|
---|
| 95 | }
|
---|
| 96 | else
|
---|
| 97 | return -UNIAUD_ALSA32OPEN_ERROR;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | int uniaud_get_cards(void)
|
---|
| 102 | {
|
---|
| 103 | return cards_num;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | int uniaud_get_version(void)
|
---|
| 107 | {
|
---|
| 108 | HFILE hFile = 0;
|
---|
| 109 | //ULONG usAction;
|
---|
| 110 | ULONG len;
|
---|
| 111 | ULONG rc;
|
---|
| 112 | int ver = 0;
|
---|
| 113 |
|
---|
| 114 | if ((int)(hFile = DriverOpen()) >= 0)
|
---|
| 115 | {
|
---|
| 116 | rc = DosDevIOCtl(hFile, CAT_IOCTL_OSS32, IOCTL_OSS32_VERSION,
|
---|
| 117 | NULL, 0, NULL, &ver, sizeof(ver), &len);
|
---|
| 118 | DosClose(hFile);
|
---|
| 119 | if (rc != 0)
|
---|
| 120 | return -UNIAUD_ERROR_IN_DRIVER;
|
---|
| 121 | return ver;
|
---|
| 122 | }
|
---|
| 123 | else
|
---|
| 124 | return -UNIAUD_ALSA32OPEN_ERROR;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | //#pragma linkage (_DLL_InitTerm, system)
|
---|
| 128 | unsigned long APIENTRY LibMain( unsigned long hModule, unsigned long ulFlag )
|
---|
| 129 | {
|
---|
| 130 |
|
---|
| 131 | int i;
|
---|
| 132 | PSZ pszTmpLoc;
|
---|
| 133 |
|
---|
| 134 | if(ulFlag == 0) { /* initialize */
|
---|
| 135 | if (!DosScanEnv("UNIAUDLIB", &pszTmpLoc)) {
|
---|
| 136 | if (stricmp(pszTmpLoc, "DEBUG") == 0) DebugMode = 1;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | i = uniaud_get_version();
|
---|
| 140 | if (DebugMode) printf("Uniaud version %i detected.\n", i);
|
---|
| 141 | if (i < 113) return 0;
|
---|
| 142 |
|
---|
| 143 | cards_num = _uniaud_get_cards();
|
---|
| 144 | if (DebugMode) printf("%i cards detected\n", cards_num);
|
---|
| 145 |
|
---|
| 146 | for (i=0;i<cards_num;i++) {
|
---|
| 147 | UniInst[i].ctls_num = _uniaud_mixer_get_ctls_number(i);
|
---|
| 148 | if (UniInst[i].ctls_num > 0) {
|
---|
| 149 | UniInst[i].ctls_list = (UniaudControl *) _uniaud_mixer_get_ctl_list(i);
|
---|
| 150 | if (!UniInst[i].ctls_list) {
|
---|
| 151 | //printf("no list at %i\n", i);
|
---|
| 152 | //return 0;
|
---|
| 153 | }
|
---|
| 154 | } else {
|
---|
| 155 | //printf("ctls num: %i at %i\n", UniInst[i].ctls_num, i);
|
---|
| 156 | //return 0;
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | } else { /* terminate */
|
---|
| 160 | }
|
---|
| 161 | return 1;
|
---|
| 162 | }
|
---|
| 163 |
|
---|