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

  1. /**
  2. *
  3. * Name        kbin -- Return a character or scan code from the
  4. *               keyboard.
  5. *        (Formerly called UTINKEY.)
  6. *
  7. * Synopsis    isch = kbin(pscan);
  8. *
  9. *        int isch      1 if a character is entered,
  10. *                  0 if an extended key sequence is
  11. *                    entered.
  12. *        int *pscan      For a character (ASCII code 0 - 255),
  13. *                  the ASCII code is returned; for an
  14. *                  extended key sequence, the scan code
  15. *                  is returned.
  16. *
  17. * Description    This function waits for a key sequence to be pressed
  18. *        (unless one is already waiting in the BIOS typeahead
  19. *        buffer) and then returns either the ASCII code for the
  20. *        character or the scan code for the extended character
  21. *        sequence.  If an ASCII character is entered, the value
  22. *        of the function is 1; otherwise it is 0.  See also the
  23. *        function KBREADY.
  24. *
  25. * Returns    isch          Flag:  1 if a character is entered,
  26. *                     0 if an extended key sequence is
  27. *                       entered.
  28. *        pscan          Pointer to either the ASCII code or
  29. *                  scan code
  30. *
  31. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1986
  32. *
  33. **/
  34.  
  35. #include <bkeybd.h>
  36. #include <butility.h>
  37.  
  38. int kbin(pscan)
  39. int *pscan;
  40. {
  41.     int ax,bx,cx,dx,flags;           /* General registers          */
  42.  
  43.     /* The BIOS function 22 is called because getch() does not trap   */
  44.     /* Ctrl/Break or return scan codes.  DOS functions 1 or 8 are not */
  45.     /* used because those functions trap Ctrl/Q, Ctrl/P and some      */
  46.     /* others.                                  */
  47.  
  48.     ax = 0;
  49.     bios(22,&ax,&bx,&cx,&dx,&flags);
  50.     *pscan = uthibyte(ax);           /* The scan code           */
  51.     if (utlobyte(ax) == 0)           /* Extended sequence typed     */
  52.        return(0);
  53.  
  54.     *pscan = utlobyte(ax);           /* Character typed          */
  55.     return(1);
  56. }
  57.