home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10774 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  2.0 KB

  1. From: andyg@hpcvra.cv.hp.com (Andrew Gryc)
  2. Date: Thu, 19 Nov 1992 18:43:41 GMT
  3. Subject: Re: Floppy Drive Readiness
  4. Message-ID: <198880001@hpcvra.cv.hp.com>
  5. Organization: Hewlett-Packard Co., Corvallis, OR, USA
  6. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-cv!hp-pcd!hpcvra!andyg
  7. Newsgroups: comp.os.msdos.programmer
  8. References: <951@hq.dla.mil>
  9. Lines: 50
  10.  
  11. Below is code I wrote to determine if a disk is in Drive A (the code can
  12. be easily modified to check for B: too, if you load DL from a stack param;
  13. 0=A:, 1=B:).
  14. It is in C inline assembly (best of both worlds, as far as I'm concerned).  
  15. I've used it without problem, but please note that I was coding this for 
  16. a specific BIOS platform (i.e. read the note about ES:BX!).  Have fun...
  17.  
  18.  
  19. o
  20.  \/___________________________________________________________________________
  21.  /\
  22. o
  23.  
  24. int DiskInDriveA(void)
  25. {
  26.   _asm {
  27.     mov cx,4        ; Allow once + 3 retries before we give up 
  28.                     ; (motor may not be on initially, and BIOS will err)
  29.  
  30. TryAgain:
  31.     push cx
  32.     mov ah,4        ; Verify sector (uses ES:BX as ptr to verify buffer)
  33.                     ; Don't care where es:bx points to (NOTE: apparently, this
  34.                     ;   can be a problem for some early versions of BIOS, 
  35.                     ;   to be safe, point to a sector-sized "junk" area) 
  36.     mov al,1        ; 1 sector long
  37.     xor cx,cx       ; cylinder 0, sector 0
  38.     xor dx,dx       ; head 0, drive 0
  39.     int 13h         ; Who cares if it verifies, just want to see if disk present
  40.     cmp ah,80h
  41.     jne DiskThere   ; 80h is disk timeout--anything else is a real disk
  42.  
  43.     mov ah,00h      ; Reset diskette A:
  44.     int 13h
  45.     pop cx
  46.     loop TryAgain   ; Oops, errored on verify...
  47.  
  48.     xor ax,ax
  49.     jmp short ExitDisk
  50. DiskThere:
  51.     pop cx           ; Grab the loop off the stack
  52.     mov ax,1
  53. ExitDisk:
  54.   }
  55. }
  56.  
  57. ----------------------------------------------------------------------
  58. Andrew J. Gryc   |  #include <stddisclaimer.h>
  59. Hewlett-Packard  |
  60. Corvallis, OR    |
  61.