From: "Anthony.Appleyard" Organization: Materials Science Centre To: DJGPP AT delorie DOT com Date: Thu, 17 Jul 1997 16:02:26 GMT-1 Subject: A funny with hooking interrupts Reply-to: Anthony DOT Appleyard AT umist DOT ac DOT uk Message-ID: <11F855EE6@fs2.mt.umist.ac.uk> Precedence: bulk I have re-subscribed to djgpp. I wrote a Gnu C++ program which uses the program below to hook interrupt 9 so that it can detect all key presses and also key releases. With thanks to Eli Zaretski for help. It works OK on my desktop. But if run on a Toshiba Satellite laptop, the program runs OK, and duly calls clearreadkeys() before exiting, but sometimes the laptop has errors after the program has exited:- (1) Sometimes on exit from the program, there is a DOS prompt, then something about "Bad TTR" or something like that, and a hex dump, then another DOS prompt. After that, the laptop to run OK. (2) Yesterday I ran the program, and exited OK; but when I then typed WIN at the DOS prompt, Windows started as far as the initial blue screen that says `WINDOWS' etc in big letters, then locked tight & I had to press ctrl-alt-del. Both these computers have DOS 6.22 & Windows for Workgroups. The laptop presumably has special software to translate `function' key combinations into simulations of the full keyboard keys that aren't on the laptop, interrupt 9 looks at them. Could it be that this special software interferes with the process of hooking and unhooking interrupt 9? /*-----*/ volatile uns char k_after0xe0=0,Keydown[256],Keypressed[256]; _go32_dpmi_seginfo old_I9handler,new_I9handler; /*-----*/ void I9handler() {uns char c,d; c=inportb(0x60); if(c==0xe0) {k_after0xe0=128; return;} d=(c&127)+k_after0xe0; if(c&128) Keydown[d]=0; else {if(!Keydown[d]) Keypressed[d]++; Keydown[d]=1;} k_after0xe0=0;} /*-----*/ int keypressed(uns char c){int i=Keypressed[c]; Keypressed[c]=0; return i;} /*-----*/ void setreadkeys(){int i; for(i=0;i<256;i++) Keydown[i]=Keypressed[i]=0; _go32_dpmi_get_protected_mode_interrupt_vector(9, &old_I9handler); new_I9handler.pm_offset = (int)I9handler; new_I9handler.pm_selector = _go32_my_cs(); _go32_dpmi_chain_protected_mode_interrupt_vector(9, &new_I9handler);}; /*-----*/ void clearreadkeys(){int i; for(i=0;i<256;i++) Keydown[i]=0; _go32_dpmi_set_protected_mode_interrupt_vector(9, &old_I9handler);}; /*-----*/