Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - interrupt_package http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Interrupt_Package
   The  interrupt  package  is  designed to be  a  general  purpose  8086
   interrupt handling package. New interrupt handlers can be defined  for
   each vector. The function handling the interrupt controls whether  the
   interrupt is chained to the previous interrupt vector or not.

   Zortech C++ has support for interrupt service routines in a  different
   way to most other C and C++ interrupt function type.

   It is done with library functions instead of a keyword. The  advantage
   is  that  the library will create a stack for  the  interrupt  service
   routine  of  a  specified  size, and the stack  will  conform  to  the
   constraints of the memory model used.

   There are several rules that must be followed when handling interrupts
   in C++. They are:

   1. No DOS calls or BIOS calls may be made during the handling of  the
   interrupt, if the interrupt could occur when DOS or BIOS is executing.
   This  is because DOS and BIOS are not re-entrant. Beware of  functions
   like new and malloc which use DOS calls internally.

   2. No not let the interrupt handler, or any function called by it, use
   more than the allocated stack space. If the handler is intended to  be
   re-entrant,  use a stacksize of zero to int_intercept so that a  local
   stack is not created and the normal program stack is used instead.

   3.Do  not  call any function that is not re-entrant,  for  example  be
   careful  in your use of global variables. (Unpredictable results  will
   occur.)

   4.  Do not perform any I/O from within the interrupt handler, this  is
   especially true for high level file I/O.
   5.  When  using  variables  set by  interrupt  handlers,  declare  the
   variables to be "volatile".
   6. Turn off stack overflow checking for the handler.

   WARNING: Intercepting interrupts is an advanced technique and requires
   a  good  understanding  of DOS and the IBM family of  PCs  to  use  it
   successfully.

   Example
   #include <int.h>
   #define TRUE 1
   volatile int ctrl_c_count = 0;
   int do_ctrl_c();
   main()
   {
   int_intercept (0x23,do_ctrl_c,256);


   /* set handler */
   while(count<3)
   printf("Number of Ctrl Cs is %d\n",ctrl_c_count);
   int_restore(0x23);
   /* reset old handler */
   }
   do_ctrl_c()
   {
   ++ctrl_c_count;
   return 1;
   }


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson