delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/04/13:09:09

From: morphine AT server DOT cs DOT jhu DOT edu (Michael Phelps)
Sender: morphine AT server DOT cs DOT jhu DOT edu
Date: Thu, 4 May 1995 11:05:07 -0400
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Checking for disk in drive

DJ recommended to:
>Try to read the first sector with BIOS (retry if error==6).  If that
>fails, the disk isn't in the drive.
I tried this method, using what I could get from the Info about the _go32 calls
and Ralf Brown's interrupt list.  I have managed (at least, in a crude way) to
figure out if a disk is in the drive or not:

#include <dpmi.h>

int	main()
{
	char	disk_buffer[1024];
	_go32_dpmi_registers	regs;

	regs.h.ah = 0x02; /* BIOS disk read */
	regs.h.al = 0x01; /* read one sector */
	regs.h.ch = 0x00; /* track zero?? */
	regs.h.cl = 0x00; /* sector zero?? */
	regs.h.dh = 0x00; /* head zero?? */
	regs.h.dl = 0x00; /* drive A?? */
	regs.x.bx = (int)disk_buffer; /* pointer to buffer???? */
	regs.x.es = _go32_my_ds(); /* fill in DS */
	regs.x.ss = regs.x.sp = 0;

	_go32_dpmi_simulate_int(0x13, &regs); /* call BIOS function */

	if (regs.h.ah != 0x80)
		printf("Disk is in drive.\n");

	return 0; /* exit program */
}


(Oh, I forgot:  #include <stdio.h>)

Now, there are a couple shortcomings with my feeble little routine, it seems.
First of all, AL is supposed to have the number of sectors read.  That is 
always zero.  (It may actually be for the best, since I really don't know how
to implement pointers like this, so it might be saving my from a general
protection fault(?).)  By trial and error, I found that 0x80 (disk time out)
is the result if there is no disk in the drive, and 0x06 is the result from
the first trial after inserting a valid disk, and 0x02 for all subsequent reads
(that is, assuming you keep the disk in).  So I guess this routine can't tell
the difference between a good disk in the drive or a bad disk.  (I haven't 
tried it yet with a Macintosh or unformatted disk--that's next on the agenda.)
Does anyone have any suggestions for the proper settings for the buffer pointer
and/or the head, sector, and track #'s?  (I assumed the first sector corresponds
to zeros for all of these three; my assumption could easily be incorrect.)
	Thanks for all who responded.  It now seems possible to do this!
						---Michael Phelps, MD

- Raw text -


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