From: "Matthew Conte" Newsgroups: comp.os.msdos.djgpp Subject: Problems with keyboard ISR? Lines: 107 X-Newsreader: Microsoft Outlook Express 4.72.3155.0 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 Message-ID: Date: Sat, 23 Jan 1999 00:10:00 GMT NNTP-Posting-Host: 24.92.58.97 X-Complaints-To: abuse AT nycap DOT rr DOT com X-Trace: typhoon.nycap.rr.com 917050200 24.92.58.97 (Fri, 22 Jan 1999 19:10:00 EDT) NNTP-Posting-Date: Fri, 22 Jan 1999 19:10:00 EDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com [email address is munged to thwart spam bots - please reply to group] Hello, I have a number of ISRs running in my application - sound, mouse, keyboard and timer. I am having a terrible problem upon exit of my application, unfortunately- I will either get a crash traceback, (under Windows98) a little "Application has executed an illegal instruction" pop-up dialog box, or my computer will spontaneously reboot. Now, I don't know if the problem lies in the keyboard ISR - from all perspectives my code looks fine, but when I symify the traceback it tells me that the crash was generated by the call to _go32_dpmi_free_iret_wrapper. Sorry I can't post the exact crash frame, my computer usually ends up rebooting. Anyway, here's the keyboard ISR code that I'm using - I'd appreciate it if someone could tell me if they spot anything wrong with it. Thanks, Matt. // Thanks, Allegro! #define END_OF_FUNCTION(x) static void x##_end(void) {} #define LOCK_VARIABLE(x) _go32_dpmi_lock_data((void*)&x,sizeof(x)) #define LOCK_FUNCTION(x) _go32_dpmi_lock_code(x,(long)x##_end-(long)x) #define KEYBOARD_INT 9 #include #include #include #include "types.h" #include "osdep/msdos/keyboard.h" static _go32_dpmi_seginfo old_key_handler; static _go32_dpmi_seginfo new_key_handler; static uint32 keys_updated; static uint8 key_table[128]; // Return a pointer to the keyboard array uint8 *KeyboardState(void) { return key_table; } // TRUE if keyboard has been updated uint32 KeyboardUpdated(void) { if (FALSE == keys_updated) return 0; keys_updated = FALSE; return 1; } // ISR for keyboard static void key_handler(void) { uint8 raw_key; raw_key = inportb(0x60); // Key has been released if (raw_key & 0x80) key_table[raw_key & 0x7F] = 0; // Key has been pressed else key_table[raw_key & 0x7F] = 1; // Indicate generic end of interrupt outportb(0x20, 0x20); keys_updated = TRUE; } END_OF_FUNCTION(key_handler); // Set up variables, lock code/data, set the new handler and save old one void InitKeyboard(void) { uint32 key; for (key = 0; key < 128; key++) key_table[key] = 0; keys_updated = 0; LOCK_VARIABLE(key_table); LOCK_VARIABLE(keys_updated); LOCK_FUNCTION(key_handler); _go32_dpmi_get_protected_mode_interrupt_vector(KEYBOARD_INT, &old_key_handler); new_key_handler.pm_offset = (int)key_handler; new_key_handler.pm_selector = _go32_my_cs(); _go32_dpmi_allocate_iret_wrapper(&new_key_handler); _go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INT, &new_key_handler); } // Restore old keyboard handler void TrashKeyboard(void) { _go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INT, &old_key_handler); _go32_dpmi_free_iret_wrapper(&new_key_handler); } // EOF