delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/20/10:06:16

Date: Sun, 20 Apr 1997 16:51:33 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Flynn <cargumu AT eui DOT upv DOT es>
cc: djgpp AT delorie DOT com
Subject: Re: Clear key buffer
In-Reply-To: <5j4rvv$5h2@maia.cc.upv.es>
Message-ID: <Pine.SUN.3.91.970420165056.578E-100000@is>
MIME-Version: 1.0

On 17 Apr 1997, Flynn wrote:

> I've some problems clearing the key buffer ring. In watcom I used:
> 
> 
>   static short * const KeyBufferFirst=(short * const)0x41a;
>   static short * const KeyBufferLast=(short * const)0x41c;
> 
>   *KeyBufferFirst=*KeyBufferLast;
> 
> but in DJGPP it doesn't work.... 

Others already have told you why it doesn't work.  But I would like to
point out that this is just plain wrong: this code will break even in
Watcom on systems where keyboard enhancer is installed.  Many keyboard
enhancers replace the brain-damaged 15-character BIOS keyboard buffer
with a larger one, which is of course at different address in memory.
Your code will fail miserably in such cases.

I suggest to do it the usual way:

	#include <conio.h>
	while (kbhit ())
	  getch ();

This clears the keyboard buffer, no matter what TSR has taken over
Int 16h.  It might be slower, but how many times per second do you
need to clear the keyboard buffer, anyway?

- Raw text -


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