Results 1 to 2 of 2

Thread: DJGPP Keyboard handler.

  1. #1
    ChimpFace9000
    Guest

    Post DJGPP Keyboard handler.

    Hi. I wrote a keyboard handler in c. Sometimes it works sometimes it doesnt.

    It works when i do this..
    Code:
    #include "key.h"
    
    int main(void)
    {
    	KeyboardInstall();
    
    	while(bKeys[KEY_ESC] == false)
    	{
    		gfxVSync();
    	}
    
    	KeyboardRemove();
    	return(0);
    }
    But just doesnt respond when i do this...
    Code:
    #include "key.h"
    
    int main(void)
    {
    	KeyboardInstall();
    
    	while(bKeys[KEY_ESC] == false)
    	{
    	}
    
    	KeyboardRemove();
    	return(0);
    }
    Heres the file key.c...
    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))
    	{
    	}
    }
    And heres key.h...
    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 */
    Ive also attached the files in a zip file. Please if you have any idea why it behaves this way, please tell me.
    Attached Files Attached Files

  2. #2
    ChimpFace9000
    Guest
    Only 10 people saw this, so im bringing it back up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width