home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / VDRV.ZIP / VDRV.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-02  |  3.3 KB  |  114 lines

  1. ;---------------------------------------------------------------------
  2. ;       Function DriveValid(DriveChar : Char): Boolean
  3. ;---------------------------------------------------------------------
  4. ; USAGE:
  5. ;       Tests whether a particular drive exists in a system.
  6. ;
  7. ; NOTES:
  8. ;       For non-network applications DOS 2.0 & above.
  9. ;
  10. ;       The argument DriveChar is case insensitive, the function
  11. ;       converts it to uppercase then to a zero-based drive number.
  12. ;
  13. ;       Based on a routine by Darius Thabit originally
  14. ;       listed in PC TECH JOURNAL March 1988
  15. ;
  16. ;       Converted to TASM as a Turbo Pascal Function by
  17. ;       Cliff Hoag, July 1990
  18. ;---------------------------------------------------------------------
  19. ; EXAMPLES:
  20. ;
  21. ;       Program TestDrv;
  22. ;
  23. ;       Function DriveValid(DriveChar : Char) : Boolean; External;
  24. ;       {$L VDRV.OBJ}
  25. ;
  26. ;       Var Dr : Char;
  27. ;
  28. ;       Begin
  29. ;         Repeat
  30. ;           Write('Enter drive letter - z to quit: ');
  31. ;           Readln(Dr);
  32. ;           If Not DriveValid(Dr) then
  33. ;              Writeln('Nope')
  34. ;           Else
  35. ;              Writeln('Yup');
  36. ;         Until (Dr = 'z');
  37. ;       End.
  38. ;
  39. ;
  40. ;       Or, to show all the drives in the system, you could
  41. ;       do something like:
  42. ;
  43. ;       Program GoodDrvs;
  44. ;
  45. ;       Function DriveValid(DriveChar : Char) : Boolean; External;
  46. ;       {$L VDRV.OBJ}
  47. ;
  48. ;       Var Dr : Char;
  49. ;
  50. ;       Begin
  51. ;         Dr := 'A';
  52. ;         Write('Valid drives are: ');
  53. ;         While DriveValid(Dr) do
  54. ;           Begin
  55. ;             Write(Dr,' ');
  56. ;             Dr := Succ(Dr);
  57. ;           End;
  58. ;         Writeln;
  59. ;       End.
  60. ;
  61. ;---------------------------------------------------------------------
  62.  
  63. IDEAL
  64. MODEL TPASCAL                 ;Let TASM figure out the details
  65.  
  66. CODESEG
  67.  
  68. Public  DriveValid
  69.  
  70. ;--------------------------------------------------------------------
  71.  
  72. Proc DriveValid     Near
  73.  
  74.         Arg DRIVE:Byte:2      Returns OK:Byte:2
  75.  
  76.  
  77.         mov     al,[DRIVE]    ;Convert the DriveChar
  78.         and     ax,not 20h    ;to uppercase
  79.         sub     al,41h        ;then to a drive number
  80.         mov     [DRIVE],al    ;save it
  81.  
  82.         mov     ah,19h        ;DOS Function 19h - Get Default Drive
  83.         int     21h
  84.         mov     bl,al         ;save current drive in bl
  85.  
  86.         xor     dh,dh         ;zero out dh
  87.         mov     dl,[DRIVE]    ;load the argument into dl
  88.         mov     ah,0Eh        ;DOS Function 0Eh - Select Disk
  89.         int     21h           ;try to select disk DRIVE
  90.  
  91.         mov     ah,19h        ;get the new current drive number
  92.         int     21h
  93.         mov     cl,al         ;save new default in cl
  94.  
  95.         mov     dl,bl         ;put the original drive # into dl
  96.         mov     ah,0Eh        ;and get things back the way they
  97.         int     21h           ;were when we came in
  98.  
  99.         mov     ax,1          ;load a boolean TRUE into ax
  100.         xor     ch,ch         ;zero out ch
  101.         cmp     cl,[DRIVE]    ;if cl = DRIVE then the Select worked
  102.                               ;otherwise cl = bl, the original drive
  103.  
  104.         je      exit          ;yes, quit and return TRUE
  105.         dec     ax            ;no, set ax to return FALSE
  106.  
  107. Exit:
  108.         ret                   ;return to caller
  109.  
  110. EndP    DriveValid
  111.  
  112.         End
  113.  
  114.