home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / KBQUEUE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.6 KB  |  69 lines

  1. /**
  2. *
  3. * Name        KBQUEUE -- Return total and remaining capacity of
  4. *               BIOS keyboard queue
  5. *
  6. * Synopsis    avail = kbqueue (ptotal);
  7. *
  8. *        int avail    Number of available spaces in
  9. *                type-ahead queue.
  10. *
  11. *        int *ptotal    Pointer to variable to receive
  12. *                total capacity of queue.
  13. *
  14. * Description    This function reports the total capacity of the of the
  15. *        BIOS type-ahead buffer and the number of unfilled spaces
  16. *        available in it.
  17. *
  18. *        If the returned value ("avail") is to be used, then
  19. *        KBQUEUE should probably be called with interrupts
  20. *        turned off (via UTINTOFF).  That will prevent further
  21. *        keystrokes or other processes from changing the number
  22. *        of available spaces.  Once the value is used,
  23. *        interrupts may be turned back on via UTINTON.
  24. *
  25. *        KBQUEUE assumes that the BIOS type-ahead buffer is at
  26. *        the standard location of 0x40:0x1e.  It will probably
  27. *        malfunction otherwise.
  28. *
  29. * Returns    avail          Number of available spaces in
  30. *                  type-ahead queue.
  31. *        *ptotal       Pointer to variable to receive
  32. *                  total size of queue.
  33. *
  34. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  35. *
  36. *
  37. **/
  38.  
  39.  
  40. #include <bkeybrd.h>
  41. #include <butil.h>
  42.  
  43.  
  44. int kbqueue (ptotal)
  45. int *ptotal;
  46. {
  47.     unsigned int bufhead;
  48.     unsigned int buftail;
  49.     int avail, wason;
  50.  
  51.     *ptotal = KB_BUFACSIZE;
  52.  
  53.     bufhead = utpeekw (KB_BUFHEADADDR);
  54.     buftail = utpeekw (KB_BUFTAILADDR);
  55.  
  56.     wason = utintoff ();
  57.  
  58.     if (bufhead > buftail)
  59.     avail = (bufhead - buftail);
  60.  
  61.     else
  62.     avail = (bufhead + KB_BUFSIZE - buftail);
  63.  
  64.     if (wason)
  65.     utinton ();
  66.  
  67.     return ((avail >> 1) - 1);
  68. }
  69.