'===========================================================================
' Subject: DETECTION ROUTINES FOR PB          Date: 07-18-98 (13:10)       
'  Author: Hans Lunsing                       Code: PB                     
'  Origin: jlunsing@doge.nl                 Packet: PB.ABC
'===========================================================================
'-------------------------------------------------------------------------
' Miscellaneous Detection Routines for PowerBASIC
'-------------------------------------------------------------------------
'Credits:
'  Original Author: Salvatore Meschini
'                   - INFORMATION SOURCE := RALF BROWN INT. LIST R51
'  Converted to PB: William Yu (10-13-97)
'  Several improvements and corrections: Hans Lunsing (07-18-98)
'-------------------------------------------------------------------------

$CPU 8086            ' program works on any CPU

$LIB   ALL OFF       ' turn off all libraries.

$ERROR ALL OFF       ' turn off all error checking

$DIM ARRAY                ' force arrays to be pre-dimensioned before they can
                          ' be used
$DYNAMIC                  ' all arrays will be dynamic by default

DEFINT A-Z

DIM X AS WORD: SHARED X
DIM Y AS BYTE: SHARED Y

CLS
?"4DOS ";: if is4dos then present else notpresent
?"ANSI.SYS ";: if isansisys then present else notpresent
?"APPEND.EXE ";: if isappend then present else notpresent
?"ASSIGN.COM ";: if isassign then present else notpresent
?"CRITICAL ERROR HANDLER ";: if iscriterror then present else notpresent
?"DBLSPACE ";: if isdblspace then present else notpresent
?"DESQVIEW ";: if isdesqview then present else notpresent
?"DOS/4G ";: if isdos4g then present else notpresent
?"DOSKEY ";: if isdoskey then present else notpresent
?"DOUBLEDOS ";: if isdoubledos then present else notpresent
?"DRIVER.SYS ";: if isdriversys then present else notpresent
?"EMM386 ";: if isemm386 then present else notpresent
?"EMS ";:if isems then present else notpresent
?"GRAFTABL ";: if isgraftabl then present else notpresent
?"KEYB.COM ";: if iskeyb then present else notpresent
?"MOUSE ";: if ismouse then present else notpresent
?"NORTON GUIDES ";: if isng then present else notpresent
?"NLSFUNC.EXE ";: if isnlsfunc then present else notpresent
?"QEMM386 ";: if isqemm386 then present else notpresent
?"SHARE.EXE ";: if isshare then present else notpresent
?"SMARTDRIVE ";: if issmartdrv then present else notpresent
?"SRDISK ";: if issrdisk then present else notpresent
?"THELP ";: if isthelp then present else notpresent
?"XMS ";: if isxms then present else notpresent
?"WINDOWS ENHANCED ";:if iswinenh then present else notpresent

END

FUNCTION Is4dos as byte
  !  mov AX, &hD44D
  !  xor BX,BX
  !  INT &h2F
  !  mov X,AX
  IF X=&H44DD THEN Is4dos=1 ELSE Is4dos=0
End Function

Function IsAnsiSys as byte
  ! MOV AX,&H1A00
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsAnsiSys=1 ELSE IsAnsiSys=0
End Function

Function IsAppend as byte
  ! MOV AX,&HB700
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsAppend=1 ELSE IsAppend=0
End Function

Function IsAssign as byte
  ! MOV AX,&H600
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsAssign=1 ELSE IsAssign=0
End Function

Function IsCritError as byte
  ! MOV AX,&H0500
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsCritError=1 ELSE IsCritError=0
End Function

Function IsDesqView as byte
  ! MOV AH,&H2B
  ! MOV CX,&H4445
  ! MOV DX,&H5351
  ! MOV AL,1
  ! INT &H21
  ! MOV Y,AL
  IF Y<>&HFF THEN IsDesqView=1 ELSE IsDesqView=0
End Function

Function IsDos4G as byte
  ! MOV AX, &HFF00
  ! MOV DX, &H78
  ! INT &H21
  ! MOV Y,AL
  IF Y<>0 THEN IsDos4G=1 ELSE IsDos4G=0
End Function

Function IsDosKey as byte
  ! MOV AX,&H4800
  ! INT &H2F
  ! MOV Y,AL
  IF Y<>0 THEN IsDosKey=1 ELSE IsDosKey=0
End Function

Function IsDoubleDos as byte
  ! MOV AX,&HE400
  ! INT &H21
  ! MOV Y,AL
  IF Y<>0 THEN IsDoubleDos=1 ELSE IsDoubleDos=0
End Function

Function IsDriverSys as byte
  ! MOV AX,&H800
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&H0FF THEN IsDriverSys=1 ELSE IsDriverSys=0
End Function

Function IsEmm386 as byte
  IsEmm386=0
  IF IsEMS=0 THEN EXIT FUNCTION
  ! MOV AX,&HFFA5
  ! INT &H67
  ! MOV X,AX
  IF X = &H845A?? OR X = &H84A5?? THEN
    ' &h845A inside Windows, otherwise &h84A5
    IsEmm386=1
  ELSE
    IsEmm386=0
  END IF
End Function

Function IsEMS as byte
  ' Returns 0 if not EMS available, and version number otherwise

  DIM EMM_Name AS STRING * 8
  DIM NameSeg AS WORD, NameOfs AS WORD
  EMM_Name = "EMMXXXX0"
  NameSeg = VARSEG(EMM_Name)
  NameOfs = VARPTR(EMM_Name)

  ! push    ds
  ! push    si
  ! push    di
  ! mov     ah, &h35                    ; Get EMM interrupt vector
  ! mov     al, &h67                    ; EMM accessed through Int 67h
  ! int     &h21                        ; Call DOS to get vector
  ! mov     di, &h0a                    ; ES:DI = driver name
  ! mov     ax, NameSeg
  ! mov     ds, ax                      ; DS:SI -> EMM device driver name
  ! mov     si, NameOfs                 ; Compare with EMM device name
  ! mov     cx, 8
  ! cld
  ! repe    cmpsb                       ; Compare bytes
  ! pop     di
  ! pop     si
  ! pop     ds
  ! jnz     ems_no                      ; Name OK?  If not, EMS not installed

ems_yes:
  ! mov     ah, &h46                    ; Get EMM version number
  ! int     &h67                        ; Returns BCD in al
  ! shr     al, 1
  ! shr     al, 1
  ! shr     al, 1
  ! shr     al, 1                       ; Version in high 4 bytes
  ! jmp     short ems_ret

ems_no:
  ! xor     al, al                      ; if EMS not installed, return 0

ems_ret:
  ! mov     Y, al
  IsEMS = Y
End Function

Function IsGrafTabl as byte
  ! MOV AX,&HB000
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsGrafTabl=1 ELSE IsGrafTabl=0
End Function

Function IsKeyb as byte
  ! MOV AX,&HAD80
  ! PUSH DI
  ! INT &H2F
  ! POP DI
  ! MOV Y,AL
  IF Y=&HFF THEN IsKeyb=1 ELSE IsKeyb=0
End Function

Function IsMouse as byte
  ! XOR AX,AX
  ! INT &H33
  ! MOV X,AX
  IF X=&H0FFFF THEN IsMouse=1 ELSE IsMouse=0
End Function

Function IsNG as byte
  ! MOV AX,&HF398
  ! INT &H16
  ! MOV X,AX
  IF X=&H6A73 THEN IsNG=1 ELSE IsNG=0
End Function

Function IsNlsFunc as byte
  ! MOV AX,&H1400
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsNlsFunc=1 ELSE IsNlsFunc=0
End Function

Function IsQEmm386 as byte
  IsQEmm386=0
  IF IsEMS=0 THEN EXIT FUNCTION
  ! MOV AX,&H3F00
  ! MOV CX,&H5145  ; "QE"
  ! MOV DX,&H4D4D  ; "MM"
  ! INT &H67
  ! MOV Y,AH
  IF Y=0 THEN IsQEmm386=1 ELSE IsQEmm386=0
End Function

Function IsShare as byte
  ! MOV AX,&H1000
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsShare=1 ELSE IsShare=0
End Function

Function IsSmartDrv as byte
  ! PUSH SI
  ! PUSH DI
  ! PUSH BP
  ! MOV AX,&H4A10
  ! MOV BX,0
  ! MOV CX,&HEBAB
  ! INT &H2F
  ! POP BP
  ! POP DI
  ! POP SI
  ! MOV X,AX
  IF X=&HBABE?? THEN IsSmartDrv=1 ELSE IsSmartDrv=0
End Function

Function IsSrdisk as byte
  ! MOV AX,&H7200
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&HFF THEN IsSrdisk=1 ELSE IsSrdisk=0
End Function

Function IsThelp as byte
  ! MOV AX,&HCAFE
  ! XOR BX,BX
  ! INT &H2F
  ! MOV X,BX
  IF X<>0 THEN IsThelp=1 ELSE IsThelp=0
End Function

Function IsXMS as byte
  ! MOV AX, &H4300
  ! INT &H2F
  ! MOV Y,AL
  IF Y=&H80 THEN IsXMS=1 ELSE IsXMS=0
End Function

Function IsWinEnh as byte
  ! MOV AX,&H1600
  ! INT &H2F
  ! MOV Y,AL
  IF Y<>0 THEN IsWinEnh=1 ELSE IsWinEnh=0
End Function

Function IsDblSpace as byte
  ! MOV AX,&H4A11
  ! XOR BX,BX
  ! INT &H2F
  ! MOV X,AX
  IF X=0 THEN IsDblSpace=1 ELSE IsDblSpace=0
End Function

SUB Present
  ?"[Y]"
END SUB

SUB NotPresent
  ?"[-]"
END SUB
