www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/27/11:34:40

From: johne AT parallax DOT co DOT uk (John Eccleston)
Newsgroups: comp.os.msdos.djgpp
Subject: Help: Chaining interrupts
Date: Mon, 27 Jan 97 09:06:32 GMT
Organization: Parallax Solutions Ltd
Message-ID: <854355955.351530@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
Lines: 109
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello All,

Thanks to everybody who replied to my last interrupt question.  I must
say this is the mosty helpful news group on the net!

At the risk of overstaying my welcome could someone please explain why
whenever I chain interrupts using: 

     _go32_dpmi_chain_protected_mode_interrupt_vector

my program crashes, but when just replacing the existing handler with a 
handler wrapped using:

     _go32_dpmi_allocate_iret_wrapper

everything works fine.

Thanks in advance

John.

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

#define KEYBOARD_INTERRUPT 0x9
#define SCAN_CODE_PORT 0x60
#define INTERRUPT_ACK 0x20

static _go32_dpmi_seginfo
  oldKBHandler,
  newKBHandler;

static int
   keyboardScanning = 0;

static int
   keys = 0;
   
void my_handler(void)
{
   keys++;
}

void init_keyboard(void)
{
   if (! keyboardScanning)
   {
      /* Clear the keyboard buffer */
      while (kbhit())
      {
         getch();
      }
   
      /* Lock all the memory we use */
      _go32_dpmi_lock_code(my_handler, (int)(init_keyboard - my_handler));
      _go32_dpmi_lock_data(&keys, sizeof(keys));
 
      /* Get the current keyboard handler for later */
      _go32_dpmi_get_protected_mode_interrupt_vector(KEYBOARD_INTERRUPT,
                                                     &oldKBHandler);

      newKBHandler.pm_offset = (int) my_handler;
      newKBHandler.pm_selector = _go32_my_cs();

      _go32_dpmi_chain_protected_mode_interrupt_vector(KEYBOARD_INTERRUPT,
                                                       &newKBHandler);
      /* Install the new keyboard handler */
      _go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INTERRUPT,
                                                     &newKBHandler);

      keyboardScanning = 1;
   }
}

void restore_keyboard(void)
{
   if (keyboardScanning)
   {
      /* Restore the original keyboard handler */
      _go32_dpmi_set_protected_mode_interrupt_vector(KEYBOARD_INTERRUPT,
                                                     &oldKBHandler);
      _go32_dpmi_free_iret_wrapper(&newKBHandler);
      keyboardScanning = 0;
   }
}

main()
{
   printf("Start\n");
   init_keyboard();
   sleep(10);
   restore_keyboard();
   printf("End\n");
}
-----> 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