keyboard buffer routine
Mark William Hopkins
markh at csd4.csd.uwm.edu
Sun Mar 17 05:11:15 AEST 1991
In article <325 at platypus.uofs.edu> meo3 at jaguar.ucs.uofs.edu writes:
>
> A quick question about a problem I have thus far been unable to
>implement "bug-free". What's the best way to flush the keyboard buffer
>on the PC ? (I'm using TC 2.0)
Set the head pointer of the keyboard buffer to the tail pointer.
------------------------------------------------------------
This is a version written in Quick C. I don't think you'll have much
trouble porting it to Turbo C.
--------------------
#include <dos.h>
static unsigned /* Keyboard buffer pointers */
far *HeadP = (unsigned far *)0x0040001a,
far *TailP = (unsigned far *)0x0040001c;
void FlushKbd(void) [ *HeadP = *TailP; }
------------------------------------------------------------
This does by-pass BIOS. If you don't want that, then here's another version
written using BIOS routines (supplied in the Quick C library):
--------------------
#include <bios.h>
void FlushKbd(void) {
while (_bios_keybrd(_KEYBRD_READY))
(void)_bios_keybrd(_KEYBRD_READ);
}
------------------------------------------------------------
And a version hand-compiled in assembly, if Turbo C doesn't have BIOS keyboard
handlers in its library:
--------------------
_KbdInt EQU 16h ;;; BIOS keyboard services
_KBD_READ EQU 0
_KBD_READY EQU 1
_FlushKbd PROC NEAR
FlushLoop: ;;; while (1) {
mov AH, _KBD_READY
int _KbdInt ;;; z = _bios_keybrd(_KEYBRD_READY);
jz FlushBreak ;;; if (z) break;
mov AH, _KBD_READ
int _KbdInt ;;; (void)_bios_keybrd(_KEYBRD_READ);
jmp FlushLoop ;;; }
FlushBreak:
_FlushKbd ENDP
More information about the Comp.lang.c
mailing list