[comp.lang.c] Detect Floppy In Drive EXAMPLE!!!!

kji@vpnet.chi.il.us (Ken Isacson) (07/12/90)

I had posted, and at least one other has as well, a question regarding
detecting the presence of a floppy in the disk drive.  Well here
are my results:
 
----------- cut here -----------
/*********************************************************
 *                                                       *
 * PURPOSE : A sample C program written in TC to test    *
 *           if a disk in drive A.                       *
 *                                                       *
 * AUTHOR  : Ken Isacson                 July 11, 1990   *
 *                                                       *
 *           kji@vpnet.chi.il.us                         *
 *                                                       *
 * NOTES   : This program accomplishes this test in two  *
 *           ways.  The first way I attempted was with   *
 *           the use of interrupt 0x25.  It works, but   *
 *           then I stumbled across 'absread.'  They     *
 *           both do the same thing, but I would         *
 *           recommend using 'absread' for portability   *
 *           purposes.                                   *
 *                                                       *
 * CREDIT  : The assembler version was partially         *
 *           suggested by Bill Wilson; however, his      *
 *           version had some mistakes and errors which  *
 *           I have corrected in this version.           *
 *                                                       *
 *********************************************************/
  
  
  
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
  
  
main() {
  
  union  REGS  regs;
  struct SREGS segreg;
  char         junk[1024];
  
  /* read an absolute sector */
  regs.x.cx=1;  /* # of sectors to read */
  regs.x.dx=1;  /* starting sector number */
  segreg.ds=FP_SEG(junk);  /* segment of buffer */
  regs.x.bx=FP_OFF(junk);  /* offset of buffer */
  regs.x.ax=1;  /* drive to read, a=0, b=1 ... */
  int86x(0x25,&regs,&regs,&segreg);
  
  
  if (regs.x.cflag == 0) {
printf("There IS a disk in the drive,\n");
  } else {
printf("There is NOT a disk in the drive,\n");
  }
  printf("according to int86x(0x25,&regs,&regs,&segreg).\n");
  
  if (absread(1,1,0,junk) == 0) {
printf("There IS a disk in the drive,\n");
  } else {
printf("There is NOT a disk in the drive,\n");
  }
  printf("according to absread(0,1,0,junk).\n");
  
  
}
  
-------- cut end -------------

If you find this useful or if you have any comments, please send me
some EMAIL.  
 
Ken Isacson
kji@vpnet.chi.il.us