1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13 
14 char cdmix32_rcsid[] = "$Id: cdmix32.c,v 1.1.1.1 2001/01/19 03:30:14 bradleyb Exp $";
15 
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 #include <conio.h>
20 #include <ctype.h>
21 
22 #include "inferno.h"
23 #include "sos.h"
24 #include "mono.h"
25 #include "error.h"
26 
27 typedef struct
28  {
29   int id;
30   char *name;
31  } DigiDevices;
32 
33 #define _AWE32_8_ST				0xe208
34 
35 #define NUM_OF_CARDS 4
36 
37 #ifndef WINDOWS
38 DigiDevices SBCards[NUM_OF_CARDS]={
39   {_SOUND_BLASTER_8_MONO      , "Sound Blaster" },
40   {_SOUND_BLASTER_8_ST        , "Sound Blaster Pro" },
41   {_SB16_8_ST                 , "Sound Blaster 16/AWE32" },
42   {_AWE32_8_ST				 		,  "Sound Blaster AWE32"}
43  };
44 #endif
45 
CD_blast_mixer()46 int CD_blast_mixer ()
47  {
48   FILE *InFile;
49   char line[100],nosbcard=1;
50   char *ptr,*token,*value;
51   int i;
52   int digiport=0,digiboard=0;
53   short int DataPort=0,AddressPort=0;
54   char redvol=0;
55 
56 
57 #ifndef WINDOWS
58   InFile = fopen("descent.cfg", "rt");
59   if (InFile == NULL)
60 	 return (NULL);
61 
62   while (!feof(InFile)) {
63 		memset(line, 0, 80);
64 		fgets(line, 80, InFile);
65 		ptr = &(line[0]);
66 		while (isspace(*ptr))
67 			ptr++;
68 		if (*ptr != '\0') {
69 			token = strtok(ptr, "=");
70 			value = strtok(NULL, "=");
71 	 		if (value[strlen(value)-1] == '\n')
72    			value[strlen(value)-1] = 0;
73 			if (!strcmp(token, "DigiDeviceID8"))
74 				digiboard = strtol(value, NULL, 16);
75 			else if (!strncmp(token, "DigiPort",8))
76 			 {
77 				digiport = strtol(value, NULL, 16);
78 			 }
79 			else if (!strcmp(token, "RedbookVolume"))
80 				redvol = strtol(value, NULL, 10);
81 		}
82 	}
83 
84   mprintf ((0,"Digiport=0x%x\n",digiport));
85   mprintf ((0,"Digiboard=0x%x\n",digiboard));
86   mprintf ((0,"Redbook volume=%d\n",redvol));
87   for (nosbcard=1,i=0;i<NUM_OF_CARDS;i++)
88    {
89     if (SBCards[i].id==digiboard)
90 		{
91        mprintf ((0,"Sound board=%s\n",SBCards[i].name));
92 		 digiboard=i;
93 		 nosbcard=0;
94 		 break;
95 		}
96 	}
97 
98   fclose (InFile);
99 
100   if (nosbcard)
101 	{
102 	 mprintf ((0,"No Soundblaster type card was found!"));
103     return (0);
104 	}
105 
106   AddressPort=digiport+4;
107   DataPort=digiport+5;
108 
109   if (digiboard==0)	// Plain SB
110 	SetRedSB(AddressPort,DataPort,redvol);
111   else if (digiboard==1)	// SB Pro
112 	SetRedSBPro(AddressPort,DataPort,redvol);
113   else if (digiboard==2 || digiboard==3) // Sound blaster 16/AWE 32
114    SetRedSB16 (AddressPort,DataPort,redvol);
115   else
116 	Int3(); // What? Get Jason, this shouldn't have happened
117 
118 #endif
119 
120   return (1);
121  }
122 
SetRedSB16(short aport,short dport,char vol)123 void SetRedSB16 (short aport,short dport,char vol)
124  {
125   char val;
126 
127   if (vol>15)
128    vol=15;
129 
130   outp (aport,0x36);
131   val=inp (dport);
132 
133   if ((val>>3)==0)
134    {
135 	  val|=(25<<3);
136 	  outp (dport,val);
137 	}
138 
139   outp (aport,0x37);
140   val=inp (dport);
141   if ((val>>3)==0)
142    {
143 	  val|=(25<<3);
144 	  outp (dport,val);
145 	}
146  }
SetRedSB(short aport,short dport,char vol)147 void SetRedSB (short aport,short dport,char vol)
148  {
149   char val;
150 
151   if (vol>15)
152    vol=15;
153 
154   vol=11;
155 
156   outp (aport,0x08);
157   val=inp (dport);
158   if ((val & 7)==0)
159 	{
160 	 val|=0x05;
161 	 outp (dport,val);
162 	}
163  }
SetRedSBPro(short aport,short dport,char vol)164 void SetRedSBPro (short aport,short dport,char vol)
165  {
166   char val;
167 
168   if (vol>15)
169    vol=15;
170 
171   vol=11;
172 
173   outp (aport,0x28);
174   val=inp (dport);
175   if ((val & 7)==0)
176 	{
177 	  val|=0x55;
178 	  outp (dport,val);
179 	}
180  }
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191