From: "A.Appleyard" To: DJGPP AT delorie DOT com Date: Thu, 21 Mar 1996 12:31:31 GMT Subject: Re: Hooking interrupts Message-ID: I wrote (Hooking interrupts):- > In djgpp, IS there an easy way of hooking an interrupt? ... Sorry: I just found an example in \djgpp\docs\djgpp\libc\libc.tex of how to do this. I just wrote this. (I still use v1. Would it work under v2?) ............................................ #include #include #include #include #include #include #define Regs _go32_dpmi_registers #define Addr _go32_dpmi_seginfo /*-----*//* grabbing the N interrupt */ Addr hook_interrupt(int N, void(*func)(Regs*)) {Addr old_handler,new_handler; _go32_dpmi_get_protected_mode_interrupt_vector(N, &old_handler); new_handler.pm_offset = (int)func; new_handler.pm_selector = _go32_my_cs(); _go32_dpmi_chain_protected_mode_interrupt_vector(N, &new_handler); return old_handler;} /*-----*/ void unhook_interrupt(int N, Addr*old_handler){ _go32_dpmi_set_protected_mode_interrupt_vector(0x21, old_handler);} /*-----*/ unsigned int AX[2048]; volatile int call21 = 0; void func(Regs*R) { AX[call21++]=R->x.ax; } /*-----*/ main() {Addr old_handler; int i; old_handler = hook_interrupt(0x21, func); printf("printing this should get int21 called\n"); unhook_interrupt(0x21, &old_handler); printf("%1d int21 calls:",call21); for(i=0;i