www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/14/19:18:20

From: qballlives AT aol DOT com (QBallLives)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Keyboard handler trouble
Date: 15 Mar 1998 00:14:02 GMT
Lines: 133
Message-ID: <19980315001400.TAA26703@ladder03.news.aol.com>
NNTP-Posting-Host: ladder03.news.aol.com
Organization: AOL http://www.aol.com
References: <3506D6A0 DOT E36FE6F0 AT worldonline DOT nl>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>Hi!
>
>I've got this code:
>
>_go32_dpmi_seginfo old_key,new_key;
>
>void keyboard_interrupt(void) {
>  }
>
>void end_keyboard_interrupt(void) {
>  }
>
>void init_keyboard(void) {
>  int i;
>  for(i=0;i<256;i++) key_table[i]=ckey_up;
>  _go32_dpmi_lock_data(&key_table,256);
>
>_go32_dpmi_lock_code(&keyboard_interrupt,(int)end_keyboard_interrupt-(int
)keyboard_int);
>
>  _go32_dpmi_get_protected_mode_interrupt_vector(keyboard_int,&old_key);
>
>  new_key.pm_offset=(int)keyboard_interrupt;
>  _go32_dpmi_allocate_iret_wrapper(&new_key);
>  _go32_dpmi_set_protected_mode_interrupt_vector(keyboard_int,&new_key);
>
>  }
>
>void deinit_keyboard(void) {
>  _go32_dpmi_set_protected_mode_interrupt_vector(keyboard_int,&old_key);
>
>  _go32_dpmi_free_iret_wrapper(&new_key);
>  }
>
>This code works. But when I finish my program, and deinit_keyboard() has
>been called, no keyboard handler seems to be present, could anybody tell
>me what the problem might be?
>
>Thanks, Reinier
>
>

I'd suggest taking a look at some keyboard code at

http://members.aol.com/dhonn

I have a keyboard interrupt too.... I'll show it to you... I don't know how
well I'm effectively locking my code and data though

Here are the routines:

void key_handler(void)
{
	unsigned char al, ah;

	asm("cli; pusha");
	
	raw_key = inportb(0x60);
		
	al = inportb(0x61); 
	al |= 0x82;
	outportb(0x61, al);       
	al &= 0x7f;
	outportb(0x61, al);

	/* you have the option of putting this outside */
	if(raw_key < 128) {
         if(!key_table[raw_key])
            {
     	      key_table[raw_key] = 1;
            keys_active++;
            }
	}
      else {
         if(key_table[raw_key-128])
            {
            key_table[raw_key-128] = 0;
            keys_active--;
            }
      }

	outportb(0x20, 0x20);
	asm("popa; sti");
}

void key_handler_end(void){}

void key_init(void) /* function to swap state */
{
      int index;
	new_key_handler.pm_offset   = (int)key_handler;
	new_key_handler.pm_selector = _go32_my_cs();
	_go32_dpmi_get_protected_mode_interrupt_vector(0x9, &old_key_handler);
	_go32_dpmi_allocate_iret_wrapper(&new_key_handler);
	_go32_dpmi_set_protected_mode_interrupt_vector(0x9,&new_key_handler);
      for(index=0;index<128;index++)
         key_table[index] = 0;
}

void key_delete(void)
{
	_go32_dpmi_set_protected_mode_interrupt_vector(0x9,&old_key_handler);
}

Here's the code in the main module:

// LOCKING is a good idea, because if we get into a situation where
// memory starts "paging" (i.e.: virtual memory is being used by swapping
// pages of memory from mem to disk & vice versa) ... timer & keyboard
// ISRs that aren't LOCKED can crash!

    _go32_dpmi_lock_data(&keys_active,sizeof(keys_active));
    _go32_dpmi_lock_code(key_handler,(long)key_handler_end-(long)key_handler);

    setbuf(stdout,NULL);		/* fix djgpp's buffered output */

    key_init();



when I'm done:

key_delete();

I hope this helps




Jim the loiterer
aloiterer AT juno DOT com
http://www.fortunecity.com/skyscraper/gigahertz/179/index.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019