[comp.sys.ibm.pc] Clearing the keyboard buffer

840369k@aucs.UUCP (Elric Kinslayer) (03/13/89)

I'm writing a realtime application which runs a robot arm by reading  
characters from the keyboard. The problem is that too many commands
get "queued" into the keyboard buffer.  What's a quick and easy way
(assembly , turbo-pascal, or just poking memory) to clear the 
keyboard?  Net people with memory maps, any ideas?

Thanks in advance,
       Kelly.

P.S. The "PC compatible" is a Tandy 1000, if it helps.



-- 
-------------------------------------------------------------------------------
| Kelly Kendrick            Acadia University, N.S.  |  "And now GROO does    |
| {seismo|watmath|utai|garfield}!dalcs!aucs!840369k  |  what GROO does best!" |
-------------------------------------------------------------------------------

todd@stiatl.UUCP (Todd Merriman) (03/15/89)

In article <1636@aucs.UUCP> 840369k@aucs.UUCP (Elric Kinslayer) writes:
>What's a quick and easy way to clear the keyboard?
>

ifdef DOCUMENTATION
; ****************************************************************************
   CONFLUSH.ASM
   2/17/89
   Todd Merriman

.MODULE            conflush
.LIBRARY           csub
.TYPE              function
.DESCRIPTION
   Flush the type-ahead buffer
.ARGUMENTS
   void conflush()
.NARRATIVE
   Conflush drains the type-ahead buffer.  All the characters in the buffer
   are thrown away.
.APPLICATION       system
.SYSTEM            msdos
.AUTHOR            Todd Merriman
.RETURNS
   Nothing
.LANGUAGE
   MSDOS small model & VMS, Assembly; all others, C
.ENDOC             END DOCUMENTATION
; ****************************************************************************
endif

	INCLUDE	\HEADER\C.MAC		; symbols and macros for Microsoft

	PSEG				; begin program section

	CFUN	conflush

	PUSH 	BP

	MOV	AX,0C00H		; flush buffer system call
	INT	21H

	POP	BP
	RET

	CFEND	conflush

	ENDPS				; end program section

	END

; ****************************************************************************
; End CONFLUSH.ASM
; ****************************************************************************

	...!gatech!stiatl!todd
	Todd Merriman 404-377-8638
	Atlanta, GA

jmv@sppy00.UUCP (Jim Vickroy) (03/15/89)

In article <1636@aucs.UUCP> 840369k@aucs.UUCP (Elric Kinslayer) writes:

=>get "queued" into the keyboard buffer.  What's a quick and easy way
=>(assembly , turbo-pascal, or just poking memory) to clear the 
=>keyboard?  Net people with memory maps, any ideas?
=>

I'm not sure this is neither quick nor easy but here goes:

I am referencing the IBM Hardware Technical Reference: System BIOS (version
2.02)

	Set up a segment at 40H and setup your own BUFFER_HEAD and BUFFER_TAIL
	    at offset 1AH and 1CH
	Setup your own BUFFER_START and BUFFER_END at offset 80H and 82H

	;
	; Reset Keyboard
	;
		MOV	AX,BUFFER_START
		MOV	BUFFER_HEAD,AX

There is an interrupt function to reset the extended keyboard, however it
escapes me at the moment (I'm responding from home and won't be in the office
for a week). If no one responds by the time I return, I'll post the method. I
do remember I did it in C.

Good luck.

jim
--

!==================================================================!=========!
! Jim Vickroy                          | cbosgd!osu-cis!sppy00!jmv !/././././!
! Online Computer Library Center, Inc. |---------------------------!././././.!
! Dublin, Ohio  43017                  | jmv@sppy00                !/././././!
!------------------------------------------------------------------!././././.!
! "That voodoo stuff don't do nothin' for me"                 -jrr !/././././!
!==================================================================!=========!

	
	

bobmon@iuvax.cs.indiana.edu (RAMontante) (03/21/89)

If you're using Turbo-Pascal, you should have a "kbhit()" function to
tell you whether any keys are queued, and a "kbread()" or something
similar to get those keys.  Turbo-C uses these, and I vaguely remember
something like this from TPascal v3.

You need the kbhit() test because kbread() (or whatever it's called) will
wait until it does get a key.