Mail Archives: djgpp/1996/10/15/08:06:36
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 -