home *** CD-ROM | disk | FTP | other *** search
- /*
- * diskstat.c
- * contains: diskstatus()
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "gfuncts.h"
-
- /*
- * int
- * diskstatus(drive,option)
- *
- * ARGUMENT
- * (int) drive - 0=A:, 1=B:, max = 1
- * (int) option - 0 = read only, 1=attempt re-write sector 1
- *
- * DESCRIPTION
- * This function determines the status of a diskette drive. It works only
- * for drives A: and B:. The operation is dependent upon the value used
- * for option.
- * If opt = 0,
- * This function tries to verify track 0, side 0 sector 1. The result
- * of this will be a status code which is used to derive the return.
- * If the second argument is a 1 then this sector is read and rewritten.
- * If it cannot be rewritten, then the write protect status may be
- * returned.
- *
- * RETURNS
- *
- * 0 = Drive OK
- * 1 = Drive Door Open (timeout, drive failed to respond)
- * 2 = Write Protected
- * 3 = Bad Address Mark (i.e. wrong format)
- * 4 = Sector Not Found
- * 5 = Other Problem - data error or seek error.
- * 6 = Argument error (drive > 1)
- * 7 = Cannot allocate memory.
- *
- * NOTE: Function returns 0 if no problems, else > 0.
- *
- * AUTHOR
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * MODIFICATIONS
- * "" Wed 09-Nov-1988 10:01:28
- * Modified (!opt) case to reset disk system (SAR #114)
- */
- int GF_CONV diskstatus(drv,opt)
- int drv;
- int opt;
- {
- unsigned stat;
- struct GFREGS in,out;
- int cyf;
- char *buf;
-
-
- if(drv>1)
- return 32;
- if(!opt) {
- in.ax=0x0; /* Reset disk system */
- in.dx=drv;
- cyf=sysint(0x13,&in,&out);
- in.ax=0x0401; /* Attempt verify */
- in.dx=drv;
- in.cx=1;
- cyf=sysint(0x13,&in,&out);
- if((cyf&1)==0)
- return 0;
- else
- goto pt1;
- } else {
- buf=malloc(2049);
- if(buf==NULL)
- return(7);
- in.bx=ofsspu(buf);
- in.es=segspu(buf);
- in.ax=0x0201;
- in.dx=drv;
- in.cx=1;
- cyf=sysint(0x13,&in,&out);
- if((cyf&1)==1) {
- free(buf);
- goto pt1;
- }
- in.bx=ofsspu(buf);
- in.es=segspu(buf);
- in.ax=0x0301;
- in.dx=drv;
- in.cx=1;
- cyf=sysint(0x13,&in,&out);
- free(buf);
- if((cyf&1)==0)
- return 0;
- pt1:
- stat=(unsigned)((out.ax&0xFF00)>>8);
- if(stat==0)
- return 0;
- if(stat==0x0003)
- return 2;
- if(stat&0x0080)
- return 1;
- if(stat&0x0004)
- return 4;
- if(stat&0x0040)
- return 5;
- if(stat&0x0010)
- return 5;
- if(stat&0x0002)
- return 3;
- }
- return 6;
- }
-