delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/15/08:06:36

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: timgunn AT eastwind DOT livewire DOT com DOT au, djgpp AT delorie DOT com
Date: Tue, 15 Oct 1996 12:43:05 GMT
Subject: Re: Drive Help
Message-ID: <10C901E6AF7@fs2.mt.umist.ac.uk>

  timgunn AT eastwind DOT livewire DOT com DOT au (Tim Gunn) wrote:-
> I am in serious need of a quick way to check what drives are available, I
> know of using mntent.h, but this checks if the drive is currently valid,
> this is no use for floppy drives. All I want is a quick way to detect
> available drives.

  I use these functions:-
  -------------------------------------------------------
/* Sometimes accessing or examining a nonexistent drive acts odd if Novell */
/* Net software is active */
#define Rcarry (R.x.flags&1)
#define SEL _go32_info_block.selector_for_linear_memory
#define TBaddr _go32_info_block.linear_address_of_transfer_buffer
#define segoff(x,y,z) ((x)=(z)>>4,(y)=(z)&15)
#define Int int86dpmi
int nfloppies;
/*-----*/
main(){int i; ......
for(i='A';i<='Z';i++) {
    R.x.ax=0x4408; R.x.bx=i&31; Int(0x21); if(Rcarry?:R.x.ax&15) break;}
nfloppies=i-'A'; ......}
/*----- current drive */
byte drive(){R.x.ax=0x1900; Int(0x21); return (R.x.ax&255)+'a';}
/*-----*/
void set_current_drive(int i){R.x.ax=0xe00; R.x.dx=(i-'A')&31; Int(0x21);}
/*-----*/
int driveexists(char D){int j=drive(); set_current_drive(D);
int i=(drive()&31)==(D&31); set_current_drive(j); return i;}
/*-----*//* try to read the start of the floppy by absolute disc address */
int nofloppyin(char D){int i=4,j,k; if((D&31)>nfloppies) return 0;
A: segoff(R.x.es,R.x.bx,TBaddr); R.x.cx=R.x.ss=R.x.sp=R.x.flags=0;
R.x.ax=0x0201; R.x.dx=(D-1)&31; Int(0x13); j=R.x.flags; k=R.x.ax&0xff00;
R.x.ax=0;      R.x.dx=(D-1)&31; Int(0x13);
if(--i) if(j&1) if(k==0x8000) goto A; return !i;}
/*-----*//* Returns 1 if drive D is a CD-ROM drive, else 0 */
/* Works with MSCDEX 2.x, but what about other CD-ROM device drivers? */
int is_cdrom_drive(int D) {R.x.ax=0x150b; R.x.cx=(D-1)&31; Int(0x2f);
if(R.x.bx==0xadad) if(R.x.ax) return 1; return 0; }
/*-----*//* Return 1 if CD-ROM drive D has a CD-ROM (not audio disk) in */
int cdrom_drive_ready(int D) {int i=2;
segoff(R.x.es,R.x.bx,TBaddr); R.x.cx=(D-1)&31; R.x.dx=R.x.flags=0;
/* Get 1st descriptor (usually, the only one) (volume table of contents) */
/* 1st time after door is closed might fail, so try twice before giving up. */
do{R.x.ax=0x1505; Int(0x2f);} while (--i && Rcarry);
if(!Rcarry) if(R.x.ax==0?:R.x.ax==1) return 1; return 0; }
/*-----*//* returns 0 if the drive is OK */
char*drive_is_empty(char D){
static char n[]="there is no such drive as A:"; n[26]=64+(D&31);
static char c[]=
  "drive A: is empty, or the CD-ROM in it is audio or wrong mode or bad";
static char f[]="drive A: is empty, or the floppy in it is bad or unformatted \
or not PC mode"; f[6]=c[6]=64+(D&31);
return !driveexists(D) ?n:
  nofloppyin(D) ?f: !is_cdrom_drive(D) ?0: cdrom_drive_ready(D) ?0:c;}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019