Trapping the Ctrl-Break Interrupt

When the user presses Ctrl-Break, software interrupt 1BH is invoked. PCDOS uses this interrupt to determine when Ctrl-Break has been entered so that the program running at the time can be terminated in a graceful manner. The default PCDOS routine prints out a ^C on the screen and exits the program.

Note: Ctrl-C is handled by ki() and any abort function you install with se_abortfp().

To replace the interrupt routine installed by PCDOS with one of your own, use se_breakfp():

void se_breakfp(user_fun, fun_stack)
 
ISVRP user_fun;
/* Ptr to break function to install
*/
UINT *fun_stack;
/* Ptr to bottom of stack used when
*/
 
/* user interrupt func. is active
*/

se_breakfp() is most useful for removing the ^C from the screen and preventing the user from leaving the program without saving current files and doing other clean-up.

se_breakfp() requires that you pass a stack buffer to use for the break interrupt. The best way to do this is to allocate 32 or more integers of space local to the main program. For example:

int main(void)

{

    UINT stack[64];

    ...

    ...

    se_breakfp(breakfunc, &stack[64]);

    ...

    ...

    re_breakfp();

    return(0);

}

The break software interrupt, INT 1BH, is called by the ROM BIOS. Therefore, the function installed as the interrupt routine cannot do anything that requires the ROM BIOS, including keyboard input and file I/O. The basic Vermont Views windowing capabilities can be used during a break interrupt rouinte, provided that the specified stack is large enough.

If the stack is allocated as a global or with malloc(), mem_get() or another memory allocation function, then the interrupt function must be compiled with the stack-checking option disabled. See your compiler documentation for more information on disabling stack checking.

The stack parameter must point to the bottom of the stack. In the code example above, the code specifies the stack size as 64, and the call to se_breakfp() to install the break interrupt function uses "&stack[64]", which is the integer after the end of the stack. Stacks grow upward, so it is acceptable to specify the integer after the end of the stack instead of the last integer in the stack buffer. It would be an error, however, to specify "&stack[0]" in the call to se_breakfp(), since this points to the top of the stack instead of the bottom of the stack.

You must restore the default control break interrupt function before you return from the application. To restore the PCDOS break interrupt function, call re_breakfp():

void re_breakfp(void)

This should be done at any exit point in your program, including immediately before calling return(0) in main() and any abort function that you have installed with se_abortfp().


Home Contents Previous Next