]> 4ch.mooo.com Git - 16.git/blobdiff - 16/sod8086/detect.c
got 8086 port of wolf3d to work and sod to work
[16.git] / 16 / sod8086 / detect.c
diff --git a/16/sod8086/detect.c b/16/sod8086/detect.c
new file mode 100755 (executable)
index 0000000..c56f4bd
--- /dev/null
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+//     SDL_CheckSB() - Checks to see if a SoundBlaster resides at a\r
+//             particular I/O location\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static boolean\r
+SDL_CheckSB(int port)\r
+{\r
+       int     i;\r
+\r
+       sbLocation = port << 4;         // Initialize stuff for later use\r
+\r
+       sbOut(sbReset,true);            // Reset the SoundBlaster DSP\r
+asm    mov     dx,0x388                                // Wait >4usec\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+asm    in      al, dx\r
+\r
+       sbOut(sbReset,false);           // Turn off sb DSP reset\r
+asm    mov     dx,0x388                                // Wait >100usec\r
+asm    mov     cx,100\r
+usecloop:\r
+asm    in      al,dx\r
+asm    loop usecloop\r
+\r
+       for (i = 0;i < 100;i++)\r
+       {\r
+               if (sbIn(sbDataAvail) & 0x80)           // If data is available...\r
+               {\r
+                       if (sbIn(sbReadData) == 0xaa)   // If it matches correct value\r
+                               return(true);\r
+                       else\r
+                       {\r
+                               sbLocation = -1;                        // Otherwise not a SoundBlaster\r
+                               return(false);\r
+                       }\r
+               }\r
+       }\r
+       sbLocation = -1;                                                // Retry count exceeded - fail\r
+       return(false);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+//     Checks to see if a SoundBlaster is in the system. If the port passed is\r
+//             -1, then it scans through all possible I/O locations. If the port\r
+//             passed is 0, then it uses the default (2). If the port is >0, then\r
+//             it just passes it directly to SDL_CheckSB()\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static boolean\r
+SDL_DetectSoundBlaster(int port)\r
+{\r
+       int     i;\r
+\r
+       if (port == 0)                                  // If user specifies default, use 2\r
+               port = 2;\r
+       if (port == -1)\r
+       {\r
+               if (SDL_CheckSB(2))                     // Check default before scanning\r
+                       return(true);\r
+\r
+               if (SDL_CheckSB(4))                     // Check other SB Pro location before scan\r
+                       return(true);\r
+\r
+               for (i = 1;i <= 6;i++)          // Scan through possible SB locations\r
+               {\r
+                       if ((i == 2) || (i == 4))\r
+                               continue;\r
+\r
+                       if (SDL_CheckSB(i))             // If found at this address,\r
+                               return(true);           //      return success\r
+               }\r
+               return(false);                          // All addresses failed, return failure\r
+       }\r
+       else\r
+               return(SDL_CheckSB(port));      // User specified address or default\r
+}\r
+\r
+\1a
\ No newline at end of file