home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / keyboard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  1.8 KB  |  84 lines

  1. //
  2. //      *******************************************************************
  3. //        JdeBP C++ Library Routines          General Public Licence v1.00
  4. //            Copyright (c) 1991,1992     Jonathan de Boyne Pollard
  5. //      *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "dosdos.h"
  12.  
  13. #pragma argsused
  14. //
  15. //    Read from the keyboard
  16. //
  17. USHORT _APICALL
  18. KbdCharIn ( KBDKEYINFO far * pkinfo,
  19.             unsigned short nowait,
  20.             unsigned short KbdHandle)
  21. {
  22.     if (nowait) {
  23.         _AH = 0x11 ;                        // BIOS poll keyboard
  24.         geninterrupt(0x16) ;
  25.         if (_FLAGS & 0x0040) {                // If ZF is set
  26.             pkinfo->fbStatus &= ~0x0040 ;    // No character received
  27.             return 0 ;                        // But still success
  28.         }
  29.     }
  30.  
  31.     _AH = 0x10 ;                            // BIOS read keyboard
  32.     geninterrupt(0x16) ;
  33.     pkinfo->chChar = _AL ;
  34.     pkinfo->chScan = _AH ;
  35.     _AH = 0x12 ;
  36.     geninterrupt(0x16) ;                    // BIOS get shift state
  37.     pkinfo->fsState = _AX ;
  38.     pkinfo->fbStatus |= 0x0040 ;            // Final character received
  39.  
  40.     return 0 ;
  41. }
  42.  
  43. #pragma argsused
  44. //
  45. //    Read from the keyboard
  46. //
  47. USHORT _APICALL
  48. KbdPeek ( KBDKEYINFO far * pkinfo,
  49.           unsigned short KbdHandle)
  50. {
  51.     unsigned short ax ;
  52.     _AH = 0x11 ;                            // BIOS poll keyboard
  53.     geninterrupt(0x16) ;
  54.     ax = _AX ;
  55.     if (_FLAGS & 0x0040) {                    // If ZF is set
  56.         pkinfo->fbStatus &= ~0x0040 ;        // No character received
  57.         return 0 ;                            // But still success
  58.     }
  59.     _AX = ax ;
  60.     pkinfo->chChar = _AL ;
  61.     pkinfo->chScan = _AH ;
  62.     _AH = 0x12 ;
  63.     geninterrupt(0x16) ;                    // BIOS get shift state
  64.     pkinfo->fsState = _AL ;
  65.     pkinfo->fbStatus |= 0x0040 ;            // Final character received
  66.  
  67.     return 0 ;
  68. }
  69.  
  70. #pragma argsused
  71. //
  72. //    Flush the keyboard buffer
  73. //
  74. USHORT _APICALL
  75. KbdFlushBuffer ( unsigned short KbdHandle)
  76. {
  77.     do {
  78.         _AH = 0 ;
  79.         geninterrupt(0x16) ;
  80.     } while (_FLAGS & 0x4000) ;
  81.  
  82.     return 0 ;
  83. }
  84.