🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.misc
Article #9615

letting keypress always gen interrupt

#9615
From: Valent MG
Date: Wed, 01 May 1991 07:18
97 lines
4121 bytes
Hello everybody out there,

Here I have a problem handling the keyboard the way I want
it. I'm (still, for those who read my previous posted question)
trying to write a (fast) game, so reading & acting to a keypress
must be done fast. I've installed my own keyboarddriver (see below)
and ACKnowledge each key that has been pressed by setting bit 7 of
port 0x61 to 1 for a short time.
This works ALMOST the way I want. The problem is the following
(you can check it by running the program): 
	Hold down a key. You will see it's scancode being printed 
	continuously. Now, while holding the key, press another and kee
	it pressed also. This latter keypress will take over and
	it's scancode will be printed. Till so far, ok. Now release
	the key you have pressed down last. It's (release) scancode
	will be printed as expected, but after this, NO MORE printing
	(even though you're still holding down the key you pressed
	first !). This is my problem; I want to see the printing of
	the first scancode again (= let it generate interrupts again
	so my interrupt handler will be invoked). 
	The only reason I can think of why this happens is that the
	new keypressing overrules the old one, and the old one isn't
	queued or anything.

So what I'm asking you all is: how should I solve this ?
(One way could be to do some bookkeeping of which key has already
been released and which not, but that makes it all much more 
complicated: Not every keypress generates an interrupt anymore and
I'll have to check variables; there goes my fast reacting to a keypress.
The same goes for buffering the keys which are pressed.
THIS are not the ways I'm looking for.)
I hope there's another way to acknowledge the keypressing or 
do something with the keyboard and/or interrupt controller (like telling
it to queue interrupts). 


				In advance, thank you for your reaction,
						Marco V. 

PS1: I know there must be an efficient way, because check out (almost)
any action game. In such a game, it is
possible for the player to move to left/right, in between firing by 
pressing the firekey (while keeping the 'move to the left/right' 
pressed). This gives the effect as if moving to the left/right and 
firing happen simultaneous.)

PS2: Below is my keyboard interrupt controller (in Turbo C). 
I've added a simple main-loop to let each keypress to be printed.

---------------------------cut here---------------------------------
/* This simple program takes over the original keyboard handling
   routine. Each time a key is pressed or released, it's scancode
   is printed on the screen. 
   Exit this program by hitting the ESC key (scancode == 1). 
*/

#include "dos.h"

/* Ptr to original interrupt handler */
static void (interrupt far *origint) ();

static int code = 0; /* Will contain the scancode */

void interrupt far newhandler()
{
int val; /* Used for ack-ing the keystroke interrupt */

	/* Get scancode in code */
	code = inportb(0x60);
	/* Ack the receiving by making bit 7 of 0x61 temporarily 1 */
	val = inportb(0x61);
	/* Make bit7 1 */
	outportb(0x61, val|0x80);
	/* Set the port back to it's old value (set bit 7 to 0) */
	outportb(0x61, val);
	/* Enable interrupts again */
	outportb(0x20, 0x20);
}


main ()
{
	/* Save original kbd interrupt handler */
	origint = getvect(0x09);
	/* Set new handler */
	setvect(0x09, newhandler);
	/* Print each time something is pressed until ESC is pressed */
	while(code != 1) {
		code = 0;
		while (code == 0) ;
		printf("Just pressed an %d\n",code);
	}
	/* Restore old handler */
	setvect(0x09, origint);
}
---------------------------cut here---------------------------------
Technical Details
Message-ID: <9819@star.cs.vu.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!star.cs.vu.nl!mgvalen

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!star.cs.vu.nl!mgvalen
From: mgvalen@cs.vu.nl (Valent MG)
Newsgroups: comp.sys.ibm.pc.misc,rec.games.programmer
Subject: letting keypress always gen interrupt
Keywords: keyboard, interrupt
Message-ID: <9819@star.cs.vu.nl>
Date: 1 May 91 07:18:04 GMT
Sender: news@cs.vu.nl
Lines: 97