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