From: frampton@vicuna.ocunix.on.ca (Steve Frampton)
Newsgroups: comp.os.msdos.programmer
Subject: Interrupt function impossible to debug!
Summary: Darn, I hate ISR programming!
Keywords: dos borland bc
Date: 23 Nov 92 03:55:12 GMT
Reply-To: frampton@vicuna.ocunix.on.ca
Followup-To: comp.os.msdos.programmer
Organization: Vicuna Systems, Kingston, ON (613) 547-5066
Content-Type: text/plain; charset=us-ascii

Hi everyone:

I am attempting to write an interrupt function for the INT 15h handler,
so that I may intercept the 'SysRq' keypresses and do something useful
with them.

Both "The NEW Peter Norton Programmer's Guide to The IBM PC & PS/2" as
well as "PC System Programming For Developers" state that when this key
is pressed, INT 15h is called with AH = 85h.  Therefore my function
simply checks for this value, and if it is found then execute the
"do_something_useful()" function.

However, for some reason it doesn't work!  I added a "beep" to the
beginning of the handler just to see if it is getting executed, however
as INT 15h is used for many different purposes the end result is a
rapid plethora of beeps dragging the system to an almost halt (but I
have *proved*, however, that the ISR is getting called).

So I don't know if my keyboard is not telling the BIOS I am pressing
'SysRq' (ALT-SysRq on an 101-key, SysRq on an 84-key), or if my BIOS
is not telling the ISR, or my ISR is not reading the value correctly.

My attempts at debugging, both with the Debugger, as well as attempting
to dump the value of AH to the printer have resulted in endless HANGS.

I have always stayed away from ISR's for this very reason (the complexity
of debugging).  I hope, however, that someone with experience in these 
matters can perhaps see something simple out of place, and I will see
how rewarding ISR programming can be.

Here is as much of the code as required to illustrate my problems:

void interrupt (*old_sysreq_function)();

void interrupt sysreq_function(unsigned ax)
/* This function is a replacement for the SYSREQ key interrupt. */
{
  if ((ax & 0xff00)==0x8500) {
    disable();
    reset_sysreq_function(); /* Don't want to be reentrant! */
    enable();

    do_something_useful();  /* Execute the wonderful function. */

    disable();
    set_sysreq_function();
    enable();
  }

  old_sysreq_function(); /* Call old function. */
} /* end sysreq_function() */


void set_sysreq_function(void)
/* This function installs the sysreq_function() interrupt */
/* function as the new INT 15h service 85h handler.       */
{
  old_sysreq_function=getvect(0x15); /* Get INT 15h handler. */
  setvect(0x15,sysreq_function);     /* Install new INT 15h handler. */
} /* end set_sysreq_function() */


void reset_sysreq_function(void)
/* This function resets the sysreq_function() back to normal. */
{
  setvect(0x15,old_sysreq_function); /* Restore old INT 15h handler. */
} /* end reset_sysreq_function() */

That's it!

Please respond via e-mail to preserve bandwidth, I shall be glad to
follow-up here with a summary.  Thanks in advance.

+-----------------------------------------------+--------------------+
| Steve Frampton - frampton@vicuna.ocunix.on.ca | Steve Frampton     |
| I collect postcards!  If you send me one from | 501-A Princess St. |
| your area, I'll send one in return.  Send to >| Kingston, Ontario  |
| (Don't forget both email and mailing address) | CANADA   K7L 1C3   |
+-----------------------------------------------+--------------------+
Newsgroups: comp.os.msdos.programmer,comp.os.ms-windows.programmer.misc