Next Previous Contents

## 3.131 set_brk

> Function

>   Set the break vector to a user function.

> Header

>   `6502.h`

> Declaration

>   `void __fastcall__ set_brk (brk_handler func);`

> Description

>   `set_brk` allows a user program to handle breaks within the program code by letting the vector point to a user written C function. The runtime library installs a small stub that saves the registers into global variables that may be accessed (and changed) by the break handler.

> Limits

>   - The function is only available as fastcall function, so it may only be used in presence of a prototype.
>   - The stub saves the zero page registers used by the C runtime and switches to a small break handler stack. This means that it is safe to execute C code, even if C code was interrupted. Be careful however not to use too many local variables, and do not enable stack checks for the handler function or any other function called from it.
>   - The `brk_pc` variable points to the `BRK` instruction. If you want the continue with the interrupted code, you have to adjust `brk_pc`, otherwise the `BRK` instruction will get executed over and over again.
>   - Since `set_brk` installs an exit handler, it is not strictly necessary to call `reset_brk` as part of the cleanup when the program terminates.
> Availability

>   cc65

> See also

>   reset_brk

> Example

>   None.

Next Previous Contents