Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!rpi!uwm.edu!csd4.csd.uwm.edu!markh From: markh@csd4.csd.uwm.edu (Mark William Hopkins) Newsgroups: comp.lang.c Subject: Re: keyboard buffer routine Message-ID: <10276@uwm.edu> Date: 16 Mar 91 19:11:15 GMT References: <325@platypus.uofs.edu> Sender: news@uwm.edu Organization: University of Wisconsin - Milwaukee Lines: 48 In article <325@platypus.uofs.edu> meo3@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 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 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