delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/21/00:32:47

Date: Tue, 20 Sep 1994 19:51:38 -0400 (EDT)
From: "Don L." <lopez AT vsl DOT ist DOT ucf DOT edu>
Subject: Int 9 keyboard interupt handler
To: djgpp AT sun DOT soe DOT clarkson DOT edu

Hello All,

I need to write an Int9 handler for a game I am writing. I tried to based on
the _go32 examples in the INFO pages. However when I touch the keyboard it
just locks up. If someone could help I would greatly appreciate it. I 
have little knowledge about Protected Mode programming so I'm wading 
through the dark here.
Heres the code for DJGPP v1.12
----------------------------------------------------------------
#include <iostream.h>
#include <dpmi.h>
#include <pc.h>
#include <go32.h>

void setupInt9( void );
void restoreInt9( void );
void kbd_handler( _go32_dpmi_registers *r );
_go32_dpmi_registers regs;
_go32_dpmi_seginfo info_pm, old_vector_pm, info_rm, old_vector_rm;

int quit = 0;
static int active = 0;

int main( void )
{
	setupInt9();
	do{
		cout << "Current_key is: ";
		if ( active ){
			cout << "active\n";
			active = 0;
		}
		else
			cout << "in-active\n";
	}while( !quit );
	restoreInt9();
}

void setupInt9( void )
{
	_go32_dpmi_get_protected_mode_interrupt_vector( 9, &old_vector_pm );
	info_pm.pm_selector = _go32_my_cs();
	info_pm.pm_offset = ( unsigned int ) kbd_handler;
  	_go32_dpmi_allocate_iret_wrapper(&info_pm);
	_go32_dpmi_set_protected_mode_interrupt_vector( 9, &info_pm );
  	_go32_dpmi_chain_protected_mode_interrupt_vector(9, &info_pm);
	
	_go32_dpmi_get_real_mode_interrupt_vector( 9, &old_vector_rm );
	info_rm.pm_selector = _go32_my_cs();
	info_rm.pm_offset = ( unsigned int ) kbd_handler;
   	_go32_dpmi_allocate_real_mode_callback_iret(&info_rm, &regs);
	_go32_dpmi_set_real_mode_interrupt_vector( 9, &info_rm );
}

void restoreInt9( void )
{
  _go32_dpmi_set_real_mode_interrupt_vector( 9, &old_vector_rm);
  _go32_dpmi_free_real_mode_callback(&info_rm);
  _go32_dpmi_set_protected_mode_interrupt_vector( 9, &old_vector_pm);
  _go32_dpmi_free_iret_wrapper(&info_pm);
}	

void kbd_handler( _go32_dpmi_registers *r )
{
	unsigned char incomming;
	active = 1;

	incomming = inportb( 0x60 );
/*
	if ( incomming == 1 )
		active = 1;
	else if ( incomming == 2 )
		quit = 1;
	else
		active = 0;
*/
	outportb( 0x20, 0x20 );
}

--------------------------------------
<end of code>

thanks,
Don ;) 


/////////////////////////////////////////////////////
	Don L.
	Institute for Simulation and Training
	lopez AT vsl DOT ist DOT ucf DOT edu
	http://www.vsl.ist.ucf.edu/~lopez

	Nothing is real......
	Reality is like a broken glass....
	The harder you try and put it together....
	The worse it looks....
/////////////////////////////////////////////////////



- Raw text -


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