'===========================================================================
' Subject: COLLECTED DETECTION ROUTINES       Date: 10-10-97 (00:00)       
'  Author: The ABC Programmer                 Code: PB                     
'  Origin: voxel@freenet.edmonton.ab.ca     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)        
'
'Errors: Only known error in detection when under DOS real-mode with EMS
'        or EMM386 not enabled, or SmartDrv enabled.  Under Windows it
'        runs fine.  I've commented out those two buggy detection
'        routines, as they will lock up your system.  Uncomment them at
'        your own discretion.  Sorry, I don't guarantee that all detection
'        routines will work.  I just converted the code from TP to PB.
'        One note: For SmartDrv, use Interrupt instead, and it works
'        fine.  Should work for most routines too.
'-------------------------------------------------------------------------

$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

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
?"SHARE.EXE ";: if isshare then present else notpresent
?"SMARDRIVE ";: 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 X,AL
  IF X=&HFF THEN IsAnsiSys=1 ELSE IsAnsiSys=0
End Function

Function IsAppend as byte
  ! MOV AX,&HB700
  ! INT &H2F
  ! MOV X,AL
  IF X=&HFF THEN IsAppend=1 ELSE IsAppend=0
End Function

Function IsAssign as byte
  ! MOV AX,&H600
  ! INT &H2F
  ! MOV X,AL
  IF X=&HFF THEN IsAssign=1 ELSE IsAssign=0
End Function

Function IsCritError as byte
  ! MOV AX,&H0500
  ! INT &H2F
  ! MOV X,AL
  IF X=&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 X,AL
  IF X<>&HFF THEN IsDesqView=1 ELSE IsDesqView=0
End Function

Function IsDos4G as byte
  ! MOV AX, &HFF00
  ! MOV DX, &H78
  ! INT &H21
  ! MOV X,AL
  IF X<>0 THEN IsDos4G=1 ELSE IsDos4G=0
End Function

Function IsDosKey as byte
  ! MOV AX,&H4800
  ! INT &H2F
  ! MOV X,AL
  IF X<>0 THEN IsDosKey=1 ELSE IsDosKey=0
End Function

Function IsDoubleDos as byte
  ! MOV AX,&HE400
  ! INT &H21
  ! MOV X,AL
  IF X<>0 THEN IsDoubleDos=1 ELSE IsDoubleDos=0
End Function

Function IsDriverSys as byte
  ! MOV AX,&H800
  ! INT &H2F
  ! MOV X,AL
  IF X=&H0FF THEN IsDriverSys=1 ELSE IsDriverSys=0
End Function

Function IsEmm386 as byte
  ! MOV AX,&HFFA5
  ! INT &H67
  ! MOV X,AX
  IF X=&H845A THEN
    IsEmm386=1    
  ELSE
    IF X=&H84A5 THEN
      IsEmm386=1
    ELSE
      ! XOR AL,AL
      ! MOV X,AL
      IsEmm386=X
    END IF
  END IF
End Function

Function IsEMS as byte
  ! MOV AH,&H46
  ! INT &H67
  ! MOV X,AH
  IF X=&H0 THEN IsEMS=1 ELSE IsEMS=0
End Function

Function IsGrafTabl as byte
  ! MOV AX,&HB000
  ! INT &H2F
  ! MOV X,AL
  IF X=&HFF THEN IsGrafTabl=1 ELSE IsGrafTabl=0
End Function

Function IsKeyb as byte
  ! MOV AX,&HAD80
  ! INT &H2F
  ! MOV X,AL
  IF X=&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 X,AL
  IF X=&HFF THEN IsNlsFunc=1 ELSE IsNlsFunc=0
End Function

Function IsShare as byte
  ! MOV AX,&H1000
  ! INT &H2F
  ! MOV X,AL
  IF X=&HFF THEN IsShare=1 ELSE IsShare=0
End Function

Function IsSmartDrv as byte
  ! MOV AX,&H4A10
  ! MOV BX,0
  ! MOV CX,&HEBAB
  ! INT &H2F
  ! MOV X,AX
  IF X=&HBABE THEN IsSmartDrv=1 ELSE IsSmartDrv=0
End Function

Function IsSrdisk as byte
  ! MOV AX,&H7200
  ! INT &H2F
  ! MOV X,AL
  IF X=&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 X,AL
  IF X=&H80 THEN IsXMS=1 ELSE IsXMS=0
End Function

Function IsWinEnh as byte
  ! MOV AX,&H1600
  ! INT &H2F
  ! MOV X,AL
  IF X<>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
