Hi. I wrote a keyboard handler in c. Sometimes it works sometimes it doesnt.
It works when i do this..
But just doesnt respond when i do this...Code:#include "key.h" int main(void) { KeyboardInstall(); while(bKeys[KEY_ESC] == false) { gfxVSync(); } KeyboardRemove(); return(0); }
Heres the file key.c...Code:#include "key.h" int main(void) { KeyboardInstall(); while(bKeys[KEY_ESC] == false) { } KeyboardRemove(); return(0); }
And heres key.h...Code:#include <dpmi.h> #include <go32.h> #include <pc.h> #include "key.h" bool bKeys[128]; _go32_dpmi_seginfo SegInfoKeyboardNew; _go32_dpmi_seginfo SegInfoKeyboardOld; void KeyboardInstall(void) { _go32_dpmi_get_protected_mode_interrupt_vector(0x09, &SegInfoKeyboardOld); SegInfoKeyboardNew.pm_offset = (unsigned long)KeyboardInterrupt; SegInfoKeyboardNew.pm_selector = _go32_my_cs(); _go32_dpmi_allocate_iret_wrapper(&SegInfoKeyboardNew); _go32_dpmi_set_protected_mode_interrupt_vector(0x09, &SegInfoKeyboardNew); for(uint i = 0; i < (sizeof(bKeys) / sizeof(bool)); i++) { bKeys[i] = false; } } void KeyboardInterrupt(void) { unsigned char key; key = inportb(0x60); if(key & 0x80) bKeys[key - 0x7f] = false; else bKeys[key] = true; key = inportb(0x61); outportb(0x61, key | 0x80); outportb(0x61, key); outportb(0x20, 0x20); } void KeyboardRemove(void) { _go32_dpmi_set_protected_mode_interrupt_vector(0x09, &SegInfoKeyboardOld); } void gfxVSync(void) { while(inp(0x3da) & 0x8) { } while(!(inp(0x3da) & 0x8)) { } }
Ive also attached the files in a zip file. Please if you have any idea why it behaves this way, please tell me.Code:#ifndef _KEY_H #define _KEY_H #define KEY_ESC 0x01 typedef unsigned int uint; typedef uint bool; enum {false, true}; extern bool bKeys[128]; void KeyboardInstall(void); void KeyboardInterrupt(void); void KeyboardRemove(void); void gfxVSync(void); #endif /* _KEY_H */


Reply With Quote