home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / msdos / programm / 11734 < prev    next >
Encoding:
Text File  |  1993-01-01  |  2.5 KB  |  62 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!news.ysu.edu!do-not-reply-to-path
  3. From: af458@yfn.ysu.edu (Jon K. Salmon)
  4. Subject: Re: Flush keyboard buffer
  5. Message-ID: <1993Jan1.182502.3080@news.ysu.edu>
  6. Sender: news@news.ysu.edu (Usenet News Admin)
  7. Nntp-Posting-Host: yfn.ysu.edu
  8. Organization: Youngstown State University/Youngstown Free-Net
  9. Date: Fri, 1 Jan 1993 18:25:02 GMT
  10. Lines: 50
  11.  
  12.  
  13. Lee,
  14.  
  15. > I have installed my own ISR to chain the INT16h ROM BIOS keyboard driver.
  16. > Therefore the keyboard buffer must be cleared before returning to the
  17. > interrupted program, otherwise the keypress remains in the buffer and is
  18. > read with the next buffer read.
  19.  
  20. I would suggest either
  21.  
  22.                Mov    Ax,40h                ;
  23.                Mov    Ds,Ax                 ;  Ds -> BIOS data area
  24.                Cli                          ; Disable interrupts.
  25.                Mov    Ax,[1Ah]              ; Set head and tail pointers
  26.                Mov    [1Ch],Ax              ;  equal.
  27.                Sti                          ; Enable interrupts.
  28.  
  29. or
  30.  
  31.     @@_Check:
  32.                Mov    Ah,01h                ; Function = Check keyboard
  33.                Int    16h                   ; Call BIOS.
  34.                Jz     @@_Done               ; Exit if nothing in buffer.
  35.                Xor    Ah,Ah                 ; Function = Read keyboard
  36.                Int    16h                   ; Call BIOS.
  37.                Jmp    @@_Check              ; Jump to check for keypress.
  38.     @@_Done:
  39.  
  40. The first method clears the buffer at a low level by setting the
  41. head and tail pointers of the circular queue equal, effectively
  42. emptying the queue.
  43.  
  44. The second method simply uses the BIOS routines to check for a
  45. keypress, and, if one is found, to read (and discard) it.  The
  46. routine just keeps reading and discarding keys until there are none
  47. left in the buffer.  With this approach you may wish to consider
  48. using the extended keyboard functions, too (11h and 10h, respectively).
  49. Also, you may have to make pseudo-calls to Int 16h to bypass your
  50. own Int 16h handler.
  51.  
  52.                Pushf                        ; Simulate interrupt.
  53.                Call   [OldInt16h]           ; Call previous handler.
  54.  
  55. Anyway, I would recommend the second approach.  Why?  If some other
  56. TSR has taken over Int 16h as a means of stuffing the buffer, setting
  57. the low-level queue to empty will NOT empty any buffer this other TSR
  58. manages internally, whereas the Int 16h method will.
  59.  
  60. -- Jon
  61. -- 
  62.