1. Error in AutoDetect

Sorry guys,

I found a bug in my Autodetect routine. I failed to init a the
success variable to zero. It didn't show up on my machine but we did
find it on a machine without a sound card. Here is the corrected
code. Sorry for any trouble. It show work fine now!

Greg.

---Code Below-----

--Checks for Sound Card
--Detects the presence of an Adlib Compatable Sound Card
--You need ports.e for this to work

include d:\programs\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
        success = 0                --This was missing
        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

function Get_Base_Address()
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

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu