home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / PASCAL / DRIVEI2 / PBCDINT.PAS < prev   
Pascal/Delphi Source File  |  1995-02-28  |  4KB  |  134 lines

  1. {+------------------------------------------------------------
  2.  | Unit PBCDInt
  3.  |
  4.  | Version: 1.0  Last modified: 02/27/95, 22:09:07
  5.  | Author : P. Below  CIS [100113,1101]
  6.  | Project: Common utilities
  7.  | Description:
  8.  |   This DLL exports a number of functions of the MSCDEX interface
  9.  |     for the use of other Windows programs. Was originally written
  10.  |     for a Visual Basic app that needed a method do detect whether
  11.  |     a given drive is a CD-ROM and whether it contains a CD or not.
  12.  |
  13.  |   Released to public domain
  14.  +------------------------------------------------------------}
  15. Library PBCDINT;
  16.  
  17. Uses WinTypes, WinProcs, Utils;
  18.  
  19. Const
  20.   CD_ERROR = -1;
  21.   CD_NOTACDDRIVE = 0;
  22.   CD_DRIVEEMPTY = 1;
  23.   CD_CDFOUND = 2;
  24.  
  25. (* returns TRUE if MSCDEX is loaded, False otherwise *)
  26. FUNCTION Is_MSCDEX_loaded: BOOLEAN; assembler;
  27.   ASM
  28.     mov AX, $1500   (* MSCDEX installed check *)
  29.     xor BX, BX
  30.     int $2F
  31.     xor ax, ax      (* set default return value to false *)
  32.     or  BX, BX      (* returns bx <> 0 if MSCDEX installed *)
  33.     jz  @no_mscdex
  34.     mov al, TRUE
  35.   @no_mscdex:
  36.   END;
  37.  
  38. (* returns -1 ( VB True ) if drive is CD-ROM, 0 otherwise. 
  39.    drivenum = 1 for A:, 2 for B: etc. *)
  40. Function CDDriveIsCD( drivenum: Integer): Integer; export;
  41.   Begin
  42.     ASM
  43.       mov AX, $150B (* MSCDEX check drive function *)
  44.       mov CX, drivenum
  45.       sub BX,BX
  46.       int $2F
  47.       cmp bx, $ADAD
  48.       jne @no_cdrom
  49.       or  AX, AX
  50.       jz  @no_cdrom
  51.       mov @result, $FFFF
  52.       jmp @exit
  53.     @no_cdrom:
  54.       mov @result, 0
  55.     @exit:
  56.     END;
  57.   End;
  58.  
  59.  
  60. (* returns one of the CD_xxx constants. 
  61.    drivenum = 1 for A:, 2 for B: etc. *)
  62. Function CDDriveStatus( drivenum: integer ): integer; export;
  63.   Var
  64.     RealModeReg: TRealModeReg;
  65.     dwGlobalDosBuffer: LongInt;
  66.   Begin
  67.     If CDDriveIsCD( drivenum ) = 0 Then
  68.       CDDriveStatus := CD_NOTACDDRIVE
  69.     Else Begin
  70.       CDDriveStatus := CD_ERROR;
  71.       { alloc a buffer for the MSCDEX call to put the copyright filename into.
  72.         this has to reside in low dos memory since the function needs a real mode
  73.         pointer in es:bx. We ignore the info put into the buffer. }
  74.       dwGlobalDosBuffer := GlobalDosAlloc(40);
  75.       if (dwGlobalDosBuffer <> 0) then Begin
  76.         { initialize the real mode register structure }
  77.         FillChar(RealModeReg, sizeof(RealModeReg), 0);
  78.         RealModeReg.rmEAX := $1502;
  79.         RealModeReg.rmECX := Longint(drivenum);
  80.         RealModeReg.rmES  := HIWORD(dwGlobalDosBuffer);  { real mode segment }
  81.         RealModeReg.rmEBX := 0;         { offset is zero }
  82.  
  83.         { simulate the real mode interrupt. we have to jump thru these hoops
  84.           because loading a real mode segment value into a register in
  85.           protected mode is a sure recipe for a GPF. }
  86.         if RealInt($2F, RealModeReg) then
  87.           If (LoWord(RealModeReg.rmCPUFlags) and 1) = 0 Then
  88.             { carry clear, CD drive containing a readable CD }
  89.             CDDriveStatus := CD_CDFOUND
  90.           Else
  91.             If LoWord( RealModeReg.rmEAX ) = $F Then
  92.               { DOS error "invalid drive" }
  93.               CDDriveStatus := CD_NOTACDDRIVE
  94.             Else
  95.               { normally DOS error 1Eh: read fault }
  96.               CDDriveStatus := CD_DRIVEEMPTY;
  97.         GlobalDosFree(LOWORD(dwGlobalDosBuffer));
  98.       End;
  99.     End;
  100.   End;
  101.  
  102. (* returns the number of CD drives supported by MSCDEX *)
  103. Function CDNumberOfDrives: Integer; export;
  104.   Begin
  105.     ASM
  106.       mov AX, $1500   (* MSCDEX installed check *)
  107.       xor BX, BX
  108.       int $2F
  109.       mov @result, bx
  110.     END;
  111.   End;
  112.  
  113. (* returns the number of the first drive supported by MSCDEX *)
  114. Function CDFirstDrive: Integer; export;
  115.   Begin
  116.     ASM
  117.       mov AX, $1500   (* MSCDEX installed check *)
  118.       xor BX, BX
  119.       int $2F
  120.       mov @result, cx
  121.     END;
  122.   End;
  123.  
  124. exports
  125.   CDDriveStatus    index 1,
  126.   CDNumberOfDrives index 2,
  127.   CDFirstDrive     index 3,
  128.   CDDriveIsCD      index 4;
  129.  
  130. Begin
  131.   (* make the fixed DLL data segment moveable *)
  132.   GlobalPageUnlock( DSeg );
  133.   GlobalReAlloc(DSeg, 0, GMEM_MODIFY or GMEM_MOVEABLE);
  134. End.