home *** CD-ROM | disk | FTP | other *** search
- ;---------------------------------------------------------------------
- ; Function DriveValid(DriveChar : Char): Boolean
- ;---------------------------------------------------------------------
- ; USAGE:
- ; Tests whether a particular drive exists in a system.
- ;
- ; NOTES:
- ; For non-network applications DOS 2.0 & above.
- ;
- ; The argument DriveChar is case insensitive, the function
- ; converts it to uppercase then to a zero-based drive number.
- ;
- ; Based on a routine by Darius Thabit originally
- ; listed in PC TECH JOURNAL March 1988
- ;
- ; Converted to TASM as a Turbo Pascal Function by
- ; Cliff Hoag, July 1990
- ;---------------------------------------------------------------------
- ; EXAMPLES:
- ;
- ; Program TestDrv;
- ;
- ; Function DriveValid(DriveChar : Char) : Boolean; External;
- ; {$L VDRV.OBJ}
- ;
- ; Var Dr : Char;
- ;
- ; Begin
- ; Repeat
- ; Write('Enter drive letter - z to quit: ');
- ; Readln(Dr);
- ; If Not DriveValid(Dr) then
- ; Writeln('Nope')
- ; Else
- ; Writeln('Yup');
- ; Until (Dr = 'z');
- ; End.
- ;
- ;
- ; Or, to show all the drives in the system, you could
- ; do something like:
- ;
- ; Program GoodDrvs;
- ;
- ; Function DriveValid(DriveChar : Char) : Boolean; External;
- ; {$L VDRV.OBJ}
- ;
- ; Var Dr : Char;
- ;
- ; Begin
- ; Dr := 'A';
- ; Write('Valid drives are: ');
- ; While DriveValid(Dr) do
- ; Begin
- ; Write(Dr,' ');
- ; Dr := Succ(Dr);
- ; End;
- ; Writeln;
- ; End.
- ;
- ;---------------------------------------------------------------------
-
- IDEAL
- MODEL TPASCAL ;Let TASM figure out the details
-
- CODESEG
-
- Public DriveValid
-
- ;--------------------------------------------------------------------
-
- Proc DriveValid Near
-
- Arg DRIVE:Byte:2 Returns OK:Byte:2
-
-
- mov al,[DRIVE] ;Convert the DriveChar
- and ax,not 20h ;to uppercase
- sub al,41h ;then to a drive number
- mov [DRIVE],al ;save it
-
- mov ah,19h ;DOS Function 19h - Get Default Drive
- int 21h
- mov bl,al ;save current drive in bl
-
- xor dh,dh ;zero out dh
- mov dl,[DRIVE] ;load the argument into dl
- mov ah,0Eh ;DOS Function 0Eh - Select Disk
- int 21h ;try to select disk DRIVE
-
- mov ah,19h ;get the new current drive number
- int 21h
- mov cl,al ;save new default in cl
-
- mov dl,bl ;put the original drive # into dl
- mov ah,0Eh ;and get things back the way they
- int 21h ;were when we came in
-
- mov ax,1 ;load a boolean TRUE into ax
- xor ch,ch ;zero out ch
- cmp cl,[DRIVE] ;if cl = DRIVE then the Select worked
- ;otherwise cl = bl, the original drive
-
- je exit ;yes, quit and return TRUE
- dec ax ;no, set ax to return FALSE
-
- Exit:
- ret ;return to caller
-
- EndP DriveValid
-
- End
-
-