home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8552 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  3.0 KB

  1. Path: sparky!uunet!munnari.oz.au!ariel!ucsvc.ucs.unimelb.edu.au!lugb!lux!9125113g
  2. From: 9125113g@lux.latrobe.edu.au (Mitch Davis)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: Detecting a disk in floppy drive
  5. Message-ID: <1992Aug15.051006.3845@lugb.latrobe.edu.au>
  6. Date: 15 Aug 92 05:10:06 GMT
  7. References: <4672@blue.cis.pitt.edu.UUCP>
  8. Sender: news@lugb.latrobe.edu.au (USENET News System)
  9. Organization: La Trobe University
  10. Lines: 98
  11.  
  12. In article <4672@blue.cis.pitt.edu.UUCP> demented+@pitt.edu (Scott E Berry) writes:
  13. >
  14. >How can I detect if a drive contains a disk without getting the 
  15. >and run Turbo C or Turbo Pascal etc. with the appropriate configuration.
  16.  
  17. Try these:
  18.  
  19. [Turbo Pascal code]
  20.  
  21. unit mydos;
  22.  
  23. interface
  24.  
  25. function DskReady (disk:char):boolean;
  26.  
  27. implementation
  28.  
  29. uses dos, Errors;
  30.  
  31. function dskready (disk:char):boolean;
  32.  
  33. {This function tries to read into a buffer the first sector off a volume.}
  34.  
  35. const buffsize = 8192; {Largest anticipated sector size}
  36.  
  37. var buffer:pointer;
  38.     regs:registers;
  39.  
  40. begin
  41.   dskready := false; {so the EXITs give the right value}
  42.   disk := upcase (disk);
  43.   if disk < 'A' then exit;
  44.   if disk > 'Z' then exit;
  45.   if maxavail < buffsize then error (8,fatal);
  46.   getmem (buffer, buffsize);
  47.   asm
  48.     mov   al,disk        { Gets the passed parameter. }
  49.     and   al,1fh         { Cvt from ASCII to drive num }
  50.     dec   al             { Adjust because A: is drive 0 }
  51.     mov   cx,1           { Try to read one sector }
  52.     xor   dx,dx          { starting at sector 0 }
  53.     push  ds
  54.     lds   bx,buffer      { Get the address of the buffer }
  55.     push  bp
  56.     int   25h            { Do the disk read. }
  57.     pop   si             { Remove the flags int 25h leaves on stack}
  58.     pop   bp
  59.     pop   ds
  60.     mov   al,0ffh
  61.     jnc   @1
  62.     mov   al,0
  63.     @1:
  64.     mov   @result, al
  65.   end;
  66.   freemem (buffer,buffsize);
  67. end;
  68.  
  69. end.
  70.  
  71. [And here's something for batch files which returns an errorlevel.  It]
  72. [uses the same method:                                                ]
  73.  
  74. On: Tue 21 May 91  5:15p
  75. By: William Hughes
  76. To: Dayton Livingston
  77. Re: Drive checking
  78. -----------------------------------------------------------------------------
  79.  DL> What I need is a way to check the drive to see if there is
  80.  DL> a disk in it that will not "freeze" things if there isn't.
  81.  DL> THEN I can have it check for the file.
  82.  DL> Comments?  Suggestions?  Help?
  83.  
  84. Run the following script file in DEBUG. You will get DSKREADY.COM,
  85. which can be used in a batch file, as follows:
  86.  
  87. dskready a
  88. if errorlevel 0 goto DoSomething
  89. if errorlevel 2 echo Drive door open or no disk in drive
  90. if errorlevel 12 echo Disk not formatted
  91. if errorlevel 255 echo What drive?
  92.  
  93. Bill
  94.  
  95. -*-*-*-*-*-*-*-*-* DSKREADY.SCR  *-*-*-*-*-*-*-*-*-*-*-*-*-
  96. n dskready.com
  97. e 0100 08 c0 75 13 a0 5c 00 fe c8 b9 01 00 31 d2 bb 1b
  98. e 0110 01 cd 25 72 02 30 c0 b4 4c cd 21
  99. rcx
  100. 001b
  101. w
  102. q
  103. -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  104.  
  105. Type this: DEBUG < DSKREADY.SCR
  106.  
  107. [I wrote the Pascal code, but not the .COM file.]
  108.  
  109. Mitch.
  110.