#include <stdio.h>
#include <dos.h>
#include <dir.h>
void interrupt (*old)(void);
union REGS in,out;
int main(void)
{
int r;
void interrupt handler(void);
/*Save the original Critical Error handler*/
old=getvect(0x24);
/*Redirect it to my own*/
setvect(0x24,handler);
/*setdisk: 0=A, 1=B, 2=C, etc...*/
setdisk(4);
/*Use service 36h - get free disk space*/
in.h.ah=0x36;
/*0 = default drive*/
in.h.dl=0;
int86(0x21,&in,&out);
r=out.x.ax;
printf("r = %x\n",r);
/*Restore the previous Critical Error handler.*/
setvect(0x24,old);
return 0;
}
void interrupt handler(void)
{
printf("Custom handler stuff...\n");
printf("cflag = %d\n",out.x.cflag);
printf("_doserrno = %d\n",_doserrno);
printf("flags = %#x\n",out.x.flags);
}
Running this on two different systems I get different results. When I
run it through the Windows XP command prompt, and I try to access the
CD-ROM drive, and there is no media, the handler executes, no flags seem
to be set, and the program finishes execution. When I try to access the
DVD-ROM drive, the handler executes and then the program terminates. So
I never see that last printf() statement.
When I run this on an actual Windows 95 machine, and I try to access the
CD-ROM drive with no media, the handler executes, then just before
program termination, the default OS message appears again:
Not ready reading drive X:
Abort? Retry? Fail?
Which is exactly the message I'm trying to override with my handler.
Could someone help explain what's going on? I'm learning a lot of new
stuff but having trouble sorting it out.
TIA,
Brian
> Hello, I posted a little while about difficulties in drive access and
> suppressing/overriding default OS error messages (Subject: Checking for
> disk media), and I got some good advice.
> I'm still getting some odd behavior however. I threw together a quick
> program to play with the things I had just learned (using Borland C 4.52):
[snip main() ]
> void interrupt handler(void)
> {
> printf("Custom handler stuff...\n");
> printf("cflag = %d\n",out.x.cflag);
> printf("_doserrno = %d\n",_doserrno);
> printf("flags = %#x\n",out.x.flags);
> }
I can't see how this sets AX to zero (which it must to ignore the
error). You need something like
void interrupt handler(void)
{
_AX = 0;
}
Whether or not this will work, I don't know, as it's possible
that BC will save and restore all the regs in an interrupt
handler. Suggest you look at the generated ASM code for that; I
can't remember the compiler option to do that (is it '-S'?). If
that's the case, you will need to work around it or recode
handler() in asm, compile this with tasm and link in the OBJ.
And I'm not sure that calling printf() in an interrupt handler is
a good idea...
> Running this on two different systems I get different results. When I
> run it through the Windows XP command prompt, and I try to access the
> CD-ROM drive, and there is no media, the handler executes, no flags seem
> to be set, and the program finishes execution. When I try to access the
> DVD-ROM drive, the handler executes and then the program terminates. So
> I never see that last printf() statement.
It's just possible that on the first system, a side-effect of
your printf()s is setting AX to zero, but not in the latter?
> When I run this on an actual Windows 95 machine, and I try to access the
> CD-ROM drive with no media, the handler executes, then just before
> program termination, the default OS message appears again:
>
> Not ready reading drive X:
> Abort? Retry? Fail?
>
> Which is exactly the message I'm trying to override with my handler.
> Could someone help explain what's going on? I'm learning a lot of new
> stuff but having trouble sorting it out.
>
> TIA,
> Brian
>
Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."