home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!ariel!ucsvc.ucs.unimelb.edu.au!lugb!lux!9125113g
- From: 9125113g@lux.latrobe.edu.au (Mitch Davis)
- Newsgroups: comp.os.msdos.programmer
- Subject: Re: Detecting a disk in floppy drive
- Message-ID: <1992Aug15.051006.3845@lugb.latrobe.edu.au>
- Date: 15 Aug 92 05:10:06 GMT
- References: <4672@blue.cis.pitt.edu.UUCP>
- Sender: news@lugb.latrobe.edu.au (USENET News System)
- Organization: La Trobe University
- Lines: 98
-
- In article <4672@blue.cis.pitt.edu.UUCP> demented+@pitt.edu (Scott E Berry) writes:
- >
- >How can I detect if a drive contains a disk without getting the
- >and run Turbo C or Turbo Pascal etc. with the appropriate configuration.
-
- Try these:
-
- [Turbo Pascal code]
-
- unit mydos;
-
- interface
-
- function DskReady (disk:char):boolean;
-
- implementation
-
- uses dos, Errors;
-
- function dskready (disk:char):boolean;
-
- {This function tries to read into a buffer the first sector off a volume.}
-
- const buffsize = 8192; {Largest anticipated sector size}
-
- var buffer:pointer;
- regs:registers;
-
- begin
- dskready := false; {so the EXITs give the right value}
- disk := upcase (disk);
- if disk < 'A' then exit;
- if disk > 'Z' then exit;
- if maxavail < buffsize then error (8,fatal);
- getmem (buffer, buffsize);
- asm
- mov al,disk { Gets the passed parameter. }
- and al,1fh { Cvt from ASCII to drive num }
- dec al { Adjust because A: is drive 0 }
- mov cx,1 { Try to read one sector }
- xor dx,dx { starting at sector 0 }
- push ds
- lds bx,buffer { Get the address of the buffer }
- push bp
- int 25h { Do the disk read. }
- pop si { Remove the flags int 25h leaves on stack}
- pop bp
- pop ds
- mov al,0ffh
- jnc @1
- mov al,0
- @1:
- mov @result, al
- end;
- freemem (buffer,buffsize);
- end;
-
- end.
-
- [And here's something for batch files which returns an errorlevel. It]
- [uses the same method: ]
-
- On: Tue 21 May 91 5:15p
- By: William Hughes
- To: Dayton Livingston
- Re: Drive checking
- -----------------------------------------------------------------------------
- DL> What I need is a way to check the drive to see if there is
- DL> a disk in it that will not "freeze" things if there isn't.
- DL> THEN I can have it check for the file.
- DL> Comments? Suggestions? Help?
-
- Run the following script file in DEBUG. You will get DSKREADY.COM,
- which can be used in a batch file, as follows:
-
- dskready a
- if errorlevel 0 goto DoSomething
- if errorlevel 2 echo Drive door open or no disk in drive
- if errorlevel 12 echo Disk not formatted
- if errorlevel 255 echo What drive?
-
- Bill
-
- -*-*-*-*-*-*-*-*-* DSKREADY.SCR *-*-*-*-*-*-*-*-*-*-*-*-*-
- n dskready.com
- e 0100 08 c0 75 13 a0 5c 00 fe c8 b9 01 00 31 d2 bb 1b
- e 0110 01 cd 25 72 02 30 c0 b4 4c cd 21
- rcx
- 001b
- w
- q
- -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
-
- Type this: DEBUG < DSKREADY.SCR
-
- [I wrote the Pascal code, but not the .COM file.]
-
- Mitch.
-