Auto Detect Sound Card
- Posted by Greg Harris <blackdog at MAIL.CDC.NET> Apr 27, 1997
- 996 views
Here is a little utility to Autodetect a sound card and return the base address of the card (for Adlib compatible cards). This works on my Sound Blaster 16. You need ports.e to use this code. If you find any bugs or anything please let me know. If you know how to get the IRQ and DMA channel without using the enviroment string please let me know also. Usual disclaimer. If it breaks your computer or anyone elses, I am not responsible. Use at your own risk. Released to the public domain . Tip of the Day:The light at the end of the tunnel is usually a train. -------------------Code Below------------------- --Checks for Sound Card --Detects the presence of an Adlib Compatable Sound Card --You need ports.e for this to work --Released to the Public Domain include ports.e constant DATA_READY = #AA -------------Write Sound Card Register---------------- procedure WriteSndReg(integer reg, integer val) --Write to a sound card register integer temp Output(reg, #388) for tmp = 1 to 6 do --wait 6 miliseconds temp = Input(#388) end for Output(val, #389) for tmp = 1 to 35 do --wait 35 miliseconds temp = Input(#388) end for end procedure ----------------Detect Sound Card-------------------- function Detect_Sound_Card() --Detects a Adlib Compatible Card --Return 1 if true 0 if not found integer a, b, c, success WriteSndReg(#4, #60) WriteSndReg(#4, #80) b=Input(#388) WriteSndReg(#2, #FF) WriteSndReg(#4, #21) for tmp = 1 to 130 do a = Input(#388) end for c = Input(#388) WriteSndReg(#4, #60) WriteSndReg(#4, #80) if and_bits(b,#E0) = 0 then if and_bits(c,#E0) = #C0 then success = 1 for tmp = 1 to #F5 do --reset Sound Card WriteSndReg(tmp, 0) end for end if end if return success end function ------------Get_Base_Address---------------- function Get_Base_Address() -- Get Base Address of Card integer baseport, resetport, readport, data data = 0 baseport = #210 resetport = #216 readport = #21A while (data != DATA_READY) and (baseport<#270) do Output(1, resetport) for x = 1 to 3 do end for Output(0, resetport) data = 0 for x = 0 to 99 do data = Input(readport) end for if data = DATA_READY then exit else baseport = baseport + #10 resetport = resetport + #10 readport = readport + #10 end if end while if baseport = #270 then return 0 else return baseport end if end function function DetectCard() integer temp if Detect_Sound_Card() then temp = Get_Base_Address() return temp else return 0 end if end function -------------------End of Support Code------------------------ integer temp temp = DetectCard() if temp then puts(1, "Sound Card Detected\n") printf(1, "Base Address is %x\n", temp) else puts(1, "Sound Card not detected\n") end if