Article View: comp.os.msdos.programmer
Article #6250Re: Flush keyboard buffer
From: Jon K. Salmon
Date: Fri, 01 Jan 1993 18:25
Date: Fri, 01 Jan 1993 18:25
50 lines
2577 bytes
2577 bytes
Lee,
> I have installed my own ISR to chain the INT16h ROM BIOS keyboard driver.
> Therefore the keyboard buffer must be cleared before returning to the
> interrupted program, otherwise the keypress remains in the buffer and is
> read with the next buffer read.
I would suggest either
Mov Ax,40h ;
Mov Ds,Ax ; Ds -> BIOS data area
Cli ; Disable interrupts.
Mov Ax,[1Ah] ; Set head and tail pointers
Mov [1Ch],Ax ; equal.
Sti ; Enable interrupts.
or
@@_Check:
Mov Ah,01h ; Function = Check keyboard
Int 16h ; Call BIOS.
Jz @@_Done ; Exit if nothing in buffer.
Xor Ah,Ah ; Function = Read keyboard
Int 16h ; Call BIOS.
Jmp @@_Check ; Jump to check for keypress.
@@_Done:
The first method clears the buffer at a low level by setting the
head and tail pointers of the circular queue equal, effectively
emptying the queue.
The second method simply uses the BIOS routines to check for a
keypress, and, if one is found, to read (and discard) it. The
routine just keeps reading and discarding keys until there are none
left in the buffer. With this approach you may wish to consider
using the extended keyboard functions, too (11h and 10h, respectively).
Also, you may have to make pseudo-calls to Int 16h to bypass your
own Int 16h handler.
Pushf ; Simulate interrupt.
Call [OldInt16h] ; Call previous handler.
Anyway, I would recommend the second approach. Why? If some other
TSR has taken over Int 16h as a means of stuffing the buffer, setting
the low-level queue to empty will NOT empty any buffer this other TSR
manages internally, whereas the Int 16h method will.
-- Jon
--
Technical Details
Message-ID:
<1993Jan1.182502.3080@news.ysu.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ysu.edu!do-not-reply-to-pathShow Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ysu.edu!do-not-reply-to-path From: af458@yfn.ysu.edu (Jon K. Salmon) Subject: Re: Flush keyboard buffer Message-ID: <1993Jan1.182502.3080@news.ysu.edu> Sender: news@news.ysu.edu (Usenet News Admin) Nntp-Posting-Host: yfn.ysu.edu Organization: Youngstown State University/Youngstown Free-Net Date: Fri, 1 Jan 1993 18:25:02 GMT Lines: 50