delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/16/20:54:05

X-Sent: 17 Jul 2001 00:52:23 GMT
Message-ID: <002b01c10e5a$f13c7040$e33e1d18@nycap.rr.com>
From: "Matthew Conte" <matt AT conte DOT com>
To: <djgpp AT delorie DOT com>
Cc: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1010716075833 DOT 10108A-100000 AT is>
Subject: Re: '9x and raise in interrupt service routines
Date: Mon, 16 Jul 2001 20:53:48 -0400
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2479.0006
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2479.0006
Reply-To: djgpp AT delorie DOT com

From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>

> You mean, your handler is written in C?  I never assumed that, I
thought
> it was in assembly.  Did I say you didn't post enough info about
your
> code?

i'm sorry to force you into assumptions- i should have posted code
directly.  i just favor concept explanations over particular code
references.

brace yourself for many lines (not-so-important stuff omitted):

-- snip --

#define  KEYBOARD_INT      0x09

static int key_status[THIN_MAX_KEYS];
static bool key_repeat = false;
static bool ext_key = false;
static _go32_dpmi_seginfo new_key_handler;

/* keyboard ISR */
static void key_handler(void)
{
   thin_event_t event;
   uint8 raw_code, ack_code;

   /* read the key */
   raw_code = inportb(0x60);
   ack_code = inportb(0x61);
   outportb(0x61, ack_code | 0x80);
   outportb(0x61, ack_code);
   outportb(0x20, 0x20);

   if (0xE0 == raw_code)
   {
      ext_key = true;
   }
   else
   {
      if (ext_key)
      {
         ext_key = false;
         event.data.keysym = ext_tab[raw_code & 0x7F];
      }
      else
      {
         event.data.keysym = raw_code & 0x7F;
      }

      event.type = (raw_code & 0x80) ? THIN_KEY_RELEASE :
THIN_KEY_PRESS;

      if (key_repeat || (event.type != key_status[event.data.keysym]))
      {
         key_status[event.data.keysym] = event.type;
         thin_event_add(&event);
      }
   }
}

int thin_key_init(void)
{
   new_key_handler.pm_offset = (uint32) key_handler;
   new_key_handler.pm_selector = _go32_my_cs();
   _go32_dpmi_chain_protected_mode_interrupt_vector(KEYBOARD_INT,
&new_key_handler);

   memset(key_status, THIN_KEY_RELEASE, sizeof(key_status));

   return 0;
}

-- snip --

> You _are_ aware that with a C handler you will have
> to lock most, if not all of the code and data, and will have other
> complications, as the FAQ explains?

yes, i am.  i mentioned in my previous email that i've set up my crt0
flags to have a non-moving sbrk and all code & data locked.

> Hm... one possibility to solve the keyboard buffer overflow would be
to
> call `getkey' or similar function in your main program (not in the
> keyboard handler).  That would remove the keys from the keyboard
buffer
> and prevent BIOS from beeping.

that's a pretty unportable and 'ugly' solution, in my opinion.  i'd
like to not require the users of my library to do such things...

> Another possibility is to remove the keys from the keyboard
controller,
> unless you see the Ctrl-C or Ctrl-BREAK keypress.  You remove the
key by
> sending a suitable command to the keyboard controller (sorry, I
don't
> remember the details and don't have a good reference book nearby to
look
> it up).

that's a solution that will probably work for me: if i can't use raise
within an interrupt handler, and i can't ask the user to call a
low-level bios service routine, i'd rather figure out how to do this
instead.

thank you for the suggestion.

regards,
matthew.

- Raw text -


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