Mail Archives: djgpp/1997/01/27/11:34:40
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 -