中国开发网: 论坛: 程序员情感CBD: 贴子 345039
haitao
好像是0x23还是0x24。。。。
一个例子:

ISR far* far old_isr24;
int fail_fl; // 1: when isr24 has been called

// the following interrupt handler intercepts the Abort/Retry/Fail chore
// and selects the "Fail" option for you. You will not see the prompt.

void interrupt isr24(void) // critical error handler
{
fail_fl = 1; // flag set to let main() know about this
asm mov byte ptr ss:[bp+16],3 // critical error fail (simulate typing F)
// sets AL register to 3 and returns
}

另一个示例:

/*
This program will trap disk errors and
prompt the user for action. Try running it
with no disk in drive A: to invoke its
functions.
*/

#include <stdio.h>
#include <conio.h>
#include <dos.h>

#define IGNORE 0
#define RETRY 1
#define ABORT 2

int buf[500];

/*
define the error messages for trapping disk problems
*/
static char *err_msg[] = {
"write protect",
"unknown unit",
"drive not ready",
"unknown command",
"data error (CRC)",
"bad request",
"seek error",
"unknown media type",
"sector not found",
"printer out of paper",
"write fault",
"read fault",
"general failure",
"reserved",
"reserved",
"invalid disk change"
};

error_win(char *msg)
{
int retval;

cputs(msg);

/*
prompt for user to press a key to abort, retry, ignore
*/
while(1)
{
retval= getch();
if (retval == 'a' || retval == 'A')
{
retval = ABORT;
break;
}
if (retval == 'r' || retval == 'R')
{
retval = RETRY;
break;
}
if (retval == 'i' || retval == 'I')
{
retval = IGNORE;
break;
}
}

return(retval);
}

/*
pragma warn -par reduces warnings which occur
due to the non use of the parameters errval,
bp and si to the handler.
*/
#pragma warn -par

int handler(int errval,int ax,int bp,int si)
{
static char msg[80];
unsigned di;
int drive;
int errorno;

di= _DI;
/*
if this is not a disk error then it was
another device having trouble
*/

if (ax < 0)
{
/* report the error */
error_win("Device error");
/* and return to the program directly requesting abort */
hardretn(ABORT);
}
/* otherwise it was a disk error */
drive = ax & 0x00FF;
errorno = di & 0x00FF;
/* report which error it was */
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
err_msg[errorno], 'A' + drive);
/*
return to the program via dos interrupt 0x23 with abort, retry,
or ignore as input by the user.
*/
hardresume(error_win(msg));
return ABORT;
}
#pragma warn +par

int main(void)
{
/*
install our handler on the hardware problem interrupt
*/
harderr(handler);
clrscr();
printf("Make sure there is no disk in drive A:\n");
printf("Press any key ....\n");
getch();
printf("Trying to access drive A:\n");
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
return 0;
}
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录