delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/23/15:57:58

From: johne AT parallax DOT co DOT uk (John Eccleston)
Newsgroups: comp.os.msdos.djgpp
Subject: Help: Keyboard interrupt
Date: Thu, 23 Jan 97 12:29:40 GMT
Organization: Parallax Solutions Ltd
Lines: 118
Message-ID: <854022514.613673@red.parallax.co.uk>
NNTP-Posting-Host: red.parallax.co.uk
Cache-Post-Path: red.parallax.co.uk!unknown AT parsnip DOT parallax DOT co DOT uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi All,

Could someone please give me some pointers as to what I am doing wrong
with this interrupt handler for the keyboard.

Currently if you hit a key whilst the program is running it completes
but does not re assign the old keyboard handler, and also if you press
several keys it only counts to 1 and misses the others.  However if you
leave the keyboard alone it exits properly and the keyboard works again.

Another couple of quick questions:

How would I get hold of the scancode for the key within the
function my_handler?

Is it OK to write an interrupt handler in C if you lock the code and
data?  I know the FAQ says to write it in assembler but it mentions nothing
about _go32_dpmi_lock_ functions.

Thanks in advance

John

-----> CUT HERE <-----
#include <stdio.h>
#include <dpmi.h>
#include <go32.h>
#include <unistd.h>
#include <dos.h>

#define INTERRUPT_ID 0x09

_go32_dpmi_seginfo
  old_vector,
  new_vector;

int
  keys = 0;

void my_handler(void)
{
   keys++;
}

void init_keyboard(void)
{
   int
      failed;
      
   while (kbhit())
   {
      getch();
   }
   
   _go32_dpmi_lock_code(my_handler, (int)(init_keyboard - my_handler));
   _go32_dpmi_lock_data(&keys, sizeof(int));
   
   failed = _go32_dpmi_get_protected_mode_interrupt_vector(INTERRUPT_ID, 
&old_vector);

   if (failed)
   {
      printf("Failed to get the current keyboard IRQ!\n");
   }
   
   new_vector.pm_offset = (int) my_handler;
   new_vector.pm_selector = _go32_my_cs();
   _go32_dpmi_allocate_iret_wrapper(&new_vector);
   /*_go32_dpmi_chain_protected_mode_interrupt_vector(INTERRUPT_ID, 
&new_vector);*/

   failed = _go32_dpmi_set_protected_mode_interrupt_vector(INTERRUPT_ID, 
&new_vector);

   if (failed)
   {
      printf("Failed to set the new keyboard IRQ!\n");
   }
}

void restore_keyboard(void)
{
   int
      failed;
      
   failed = _go32_dpmi_set_protected_mode_interrupt_vector(INTERRUPT_ID, 
&old_vector);
   _go32_dpmi_free_iret_wrapper(&new_vector);
   
   if (failed)
   {
      printf("Failed to restore keyboard IRQ!\n");
   }
}
 
main()
{
   printf("Start %d\n", keys);
   init_keyboard();
   sleep(10);
   restore_keyboard();
   printf("End %d\n", keys);
   sleep(10);
   printf("After restore: %d\n", keys);
}
-----> CUT HERE <-----


________________________________________________________________
Parallax Solutions Ltd.   Tel.: 01203 514522
Stonecourt,               Fax.: 01203 514401
Siskin Drive,             Web : http://www.parallax.co.uk/~johne
Coventry CV3 4FJ          Mail: johne AT parallax DOT co DOT uk
________________________________________________________________
 Good manners cost nothing, bad manners can cost you everything
________________________________________________________________


- Raw text -


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