digitalmars.com                      
Last update Thu Jun 16 23:29:03 2011

int.h


int_gen

Header
int.h
Prototype
void int_gen(int intno);
Description
The int_gen function generates a standard Intel 80x86 interrupt, where intno is the interrupt to generate.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other int_functions
Example
/* Example for int_gen */

#include <int.h>
#include <stdlib.h>

void main()
{
 int_gen(5); /* print-screen interrupt */
}

int_getvector

Header
int.h
Prototype
void int_getvector(unsigned vector, unsigned *poffset, unsigned *psegment);
Description
The int_getvector function gets the contents of the specified interrupt vector, splits it into its segment and offset components, and stores each in the unsigned integers pointed to by poffset and psegment.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other int_functions

int_intercept

Header
int.h
Prototype
int int_intercept(unsigned vector, int(* funcptr) (struct INT_DATA *pd), unsigned stacksize);
Description
The int_intercept function links a standard C function to an interrupt vector that handles interrupts when they occur. The funcptr is a pointer to the C function that will handle the interrupt. This function must be declared as having C linkage. The vector argument defines which interrupt vector the function will be attached to (0 through 255). The stacksize argument is the number of bytes of memory allocated for the stack within the interrupt handler. stacksize should be a minimum of 256 bytes, except that if stacksize is 0, no stack is allocated, and the program stack is used. This is essential for interrupt routines that are required to be re-entrant, such as serial handlers.

If a zero value is returned from the interrupt handler (* funcptr)(), then the previous interrupt vector for this vector is called. Otherwise, a return from the interrupt is performed. Values in registers can be read/ written through the pointer pd, which points to the INT_DATA struct that is passed to (* funcptr)().

Follow these rules when handling interrupts in C++.

1. Do not use DOS or BIOS calls during interrupt handling if the possibility exists that an interrupt can 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. Do 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 can occur.
4. Do not perform 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.

Note
Intercepting interrupts is an advanced technique and requires a good understanding of DOS and the IBM family of PCs to use it successfully.
Return Value
Returns zero if successful. Otherwise, -1 is returned.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other int_functions
Example
/* Example for int_intercept */

#include <int.h>
#include <stdio.h>
#include <stdlib.h>

static volatile int ctrl_c_count = 0;

int do_ctrl_c(struct INT_DATA *pd)
{
 ++ctrl_c_count;
 return 1;
}

void main()
{
 int_intercept(0x23, do_ctrl_c, 256);
 while (ctrl_c_count < 3)
   printf("Number of ctrl-C's is %d\n",
          ctrl_c_count);
 int_restore(0x23);
}
Output
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is ^C
0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 0
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's ^C
is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 1
Number of ctrl-C's is 2
Number of ctrl-C's is 2
Number of ctrl-C's is 2
Number of ctrl^ C
-C's is 2
Number of ctrl-C's is 2
Number of ctrl-C's is 2
Number of ctrl-C's is 2
Number of ctrl-C's is 2

int_on

Header
int.h
Prototype
void int_off(void); void int_on(on);
Description
These functions turn on or off the interrupts. The int_on function does it via an STI (set interrupt flat) instruction; the int_off function does it via a CLI (clear interrupt flag) instruction.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other int_functions

int_prev

Header
int.h
Prototype
long int_prev(struct INT_DATA *idp);
Description
The int_prev function calls the standard interrupt handler from within a user-handler that was installed using int_intercept. The parameter *ipd passes register values into the routine. On exit, it contains the register values at the end of the standard interrupt handler.
Return Value
A long containing the values in the DX and AX registers at the end of the called routine.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other int_functions

int_restore

Header
int.h
Prototype
void int_restore(unsigned vector);
Description
The int_restore function unlinks the first interrupt handler that was hooked into the specified vector via int_intercept. This function must not be called unless an interrupt handler was linked to the vector using int_intercept. int_restore is the complement to the int_intercept function.
Return Value
If successful, a zero is returned. Otherwise, -1 is returned.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
int_intercept
Example
See int_intercept

int_setvector

Header
int.h
Prototype
void int_setvector(unsigned vector, unsigned offset, unsigned segment);
Description
The int_setvector installs the address of a user routine supplied in offset and segment in the specified interrupt vector. The routine where you set the interrupt vector must be marked as __interupt. For example if you want your C function to be a Ctrl_C vector, declare the function as:
void __interupt __far __cdecl func
If the routine is written in assembly, save and restore all registers and return via an IRET instruction.
Return Value
None
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
The other int_functions
Home | Compiler & Tools | IDDE Reference | STL | Search | Download | Forums