; Routines to detect a Sound Blaster
         .MODEL  LARGE
          .DATA
          EXTRN _G8015_ : WORD
         .CODE
F8058_       proc near
                push    cx
                mov     cx, 200h
                mov     ah, al
loc_129AC:
                in      al, dx
                or      al, al
                jns     loc_129B6
                loop    loc_129AC
                stc
                jmp     short loc_129BA
loc_129B6:
                mov     al, ah
                out     dx, al
                clc
loc_129BA:
                pop     cx
                retn
F8058_       endp

F8059_       proc near
                push    cx
                push    dx
                mov     dx, _G8015_
                add     dl, 0Eh
                mov     cx, 200h
loc_129C8:
                in      al, dx
                or      al, al
                js      loc_129D2
                loop    loc_129C8
                stc
                jmp     short loc_129D7
loc_129D2:
                sub     dl, 4
                in      al, dx
                clc
loc_129D7:
                pop     dx
                pop     cx
                retn
F8059_       endp

F8060_       proc near
                mov     dx, _G8015_
                add     dl, 6
                mov     al, 1
                out     dx, al
                in      al, dx
loc_129E5:
                inc     al
                jnz     loc_129E5
                out     dx, al
                mov     cl, 20h
loc_129EC:
                call    F8059_
                cmp     al, 0AAh
                jz      loc_129FC
                dec     cl
                jnz     loc_129EC
                mov     ax, 2
                jmp     short loc_129FE
loc_129FC:
                sub     ax, ax
loc_129FE:
                or      ax, ax
                retn
F8060_       endp

         PUBLIC  _F8061_
_F8061_       proc far
                push    ds
                mov     ax, DGROUP
                mov     ds, ax
                sub     bx, bx
                mov     dx, _G8015_
                add     dl, 6
                mov     al, 0C6h
                out     dx, al
                sub     al, al
                add     dl, 4
                out     dx, al
                in      al, dx
                cmp     al, 0C6h
                jnz     loc_12A34
                sub     dl, 4
                mov     al, 39h
                out     dx, al
                sub     al, al
                add     dl, 4
                out     dx, al
                in      al, dx
                cmp     al, 39h
                jnz     loc_12A34
                mov     bx, 1
                jmp     short loc_12A5A
loc_12A34:
                call    F8060_
                jnz     loc_12A5A
                mov     dx, _G8015_
                add     dl, 0Ch
                mov     al, 0E0h
                call    F8058_
                jb      loc_12A5A
                mov     al, 0C6h
                call    F8058_
                jb      loc_12A5A
                call    F8059_
                jb      loc_12A5A
                cmp     al, 39h
                jnz     loc_12A5A
                mov     bx, 5
loc_12A5A:
                mov     ax, bx
                pop     ds
                retf
_F8061_       endp
         END
