-
Notifications
You must be signed in to change notification settings - Fork 0
/
DETECT.C
87 lines (77 loc) · 2.09 KB
/
DETECT.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
///////////////////////////////////////////////////////////////////////////
//
// SDL_CheckSB() - Checks to see if a SoundBlaster resides at a
// particular I/O location
//
///////////////////////////////////////////////////////////////////////////
static boolean
SDL_CheckSB(int port)
{
int i;
sbLocation = port << 4; // Initialize stuff for later use
sbOut(sbReset,true); // Reset the SoundBlaster DSP
asm mov dx,0x388 // Wait >4usec
asm in al, dx
asm in al, dx
asm in al, dx
asm in al, dx
asm in al, dx
asm in al, dx
asm in al, dx
asm in al, dx
asm in al, dx
sbOut(sbReset,false); // Turn off sb DSP reset
asm mov dx,0x388 // Wait >100usec
asm mov cx,100
usecloop:
asm in al,dx
asm loop usecloop
for (i = 0;i < 100;i++)
{
if (sbIn(sbDataAvail) & 0x80) // If data is available...
{
if (sbIn(sbReadData) == 0xaa) // If it matches correct value
return(true);
else
{
sbLocation = -1; // Otherwise not a SoundBlaster
return(false);
}
}
}
sbLocation = -1; // Retry count exceeded - fail
return(false);
}
///////////////////////////////////////////////////////////////////////////
//
// Checks to see if a SoundBlaster is in the system. If the port passed is
// -1, then it scans through all possible I/O locations. If the port
// passed is 0, then it uses the default (2). If the port is >0, then
// it just passes it directly to SDL_CheckSB()
//
///////////////////////////////////////////////////////////////////////////
static boolean
SDL_DetectSoundBlaster(int port)
{
int i;
if (port == 0) // If user specifies default, use 2
port = 2;
if (port == -1)
{
if (SDL_CheckSB(2)) // Check default before scanning
return(true);
if (SDL_CheckSB(4)) // Check other SB Pro location before scan
return(true);
for (i = 1;i <= 6;i++) // Scan through possible SB locations
{
if ((i == 2) || (i == 4))
continue;
if (SDL_CheckSB(i)) // If found at this address,
return(true); // return success
}
return(false); // All addresses failed, return failure
}
else
return(SDL_CheckSB(port)); // User specified address or default
}