home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / KBREADY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.6 KB  |  57 lines

  1. /**
  2. *
  3. * Name        kbready -- Return a character and scan code if one is
  4. *               ready in the keyboard buffer.
  5. *        (Formerly called UTRDYKEY.)
  6. *
  7. * Synopsis    isrdy = kbready(pch,pscan);
  8. *
  9. *        int  isrdy      1 if a character is in the buffer,
  10. *                  0 if not.
  11. *        char *pch      If a character is ready, the character
  12. *                  is returned.
  13. *        int  *pscan      If a character is ready, its scan code
  14. *                  is returned.
  15. *
  16. * Description    This function returns the character and scan code of the
  17. *        next character in the BIOS type-ahead buffer if one is
  18. *        ready.    If the buffer is empty, the values of *pch and
  19. *        *pscan are both undefined.
  20. *
  21. *        KBREADY is similar to KBIN, but the latter suspends
  22. *        execution until the buffer has an available character.
  23. *        Moreover, KBIN removes the waiting character from the
  24. *        buffer, while KBREADY leaves the character waiting to be
  25. *        read again.
  26. *
  27. * Returns    isrdy          Character ready flag:  1 if ready, 0 if not.
  28. *        *pch          Next character in buffer.
  29. *        *pscan          Next scan code in the buffer.
  30. *
  31. * Version    3.0 (C)Copyright Blaise Computing Inc.    1984, 1985, 1986
  32. *
  33. **/
  34.  
  35. #include <bkeybd.h>
  36. #include <butility.h>
  37.  
  38. int kbready(pch,pscan)
  39. int  *pscan;
  40. char *pch;
  41. {
  42.     int ax,bx,cx,dx,flags;           /* General registers           */
  43.  
  44.     /* The BIOS function 22 to query the status of the keyboard buffer.*/
  45.  
  46.     flags = 0;
  47.     ax      = 0x0100;
  48.     bios(22,&ax,&bx,&cx,&dx,&flags);
  49.     if ((flags & 0x40) == 0)           /* ZF = 0               */
  50.     {
  51.        *pscan = uthibyte(ax);           /* The scan code            */
  52.        *pch   = (char)utlobyte(ax);
  53.        return(1);
  54.     }
  55.     return(0);
  56. }
  57.