home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_09 / 2n09044b < prev    next >
Text File  |  1991-07-23  |  3KB  |  107 lines

  1.  
  2. ;
  3. ; extkeys.asm -- Function package to handle extended keycodes
  4. ;                Written by Tom Wurzbach
  5. ;
  6.  
  7.     MODEL  small, C
  8.  
  9. CODESEG
  10.     public  kbhit, getkey, getshift
  11.  
  12. ; ---> DoKeyboardInt
  13. ;    INT 16, function 00h, 01h, 02h are keyboard read routines that do not
  14. ; recognize different keys on enhanced (or 101-key) keyboards.  Functions 
  15. ; 10h, 11h, and 12h do recognize these extended codes.  This routine check 
  16. ; the keyboard bit at 0040:0096h before calling INT 16 to adjust the function 
  17. ; number if the keyboard is enhanced.
  18. ;
  19. ;    This routine should be called with bh set to one of the following values,
  20. ; depending on the desired function:
  21. ;
  22. ;    00h  Check if a key is pressed.
  23. ;    01h  Read the next key from buffer, wait if no key is ready
  24. ;    02h  Get the current shift state
  25.  
  26. PROC      DoKeyboardInt         ; modifies ax
  27.     push    ds                   
  28.     mov     ax, 40h
  29.     mov     ds, ax
  30.     mov     ah, ds:96h
  31.     pop     ds
  32.     and     ah, 10h
  33.     or      ah, bh
  34.     xor     al, al
  35.     int     16h
  36.     ret
  37. ENDP
  38.  
  39. ; ---> kbhit
  40. ; Returns 0 if no key is ready otherwise, the scan code of the next key 
  41. ; in the keyboard buffer is returned.  No keys are removed from the buffer.
  42.  
  43. PROC      kbhit
  44.     push    bp
  45.     mov     bp, sp
  46.     mov     bh, 01h
  47.     call    DoKeyboardInt
  48.     jnz     KeyHit
  49.     xor     ax, ax
  50.     jmp     SHORT KbRtn
  51. KeyHit:
  52.     mov     ax, 1
  53. KbRtn:
  54.     mov     sp, bp
  55.     pop     bp
  56.       ret  
  57. ENDP      kbhit   
  58.  
  59. ; ---> getkey 
  60. ; Returns the scan code of the next key in the keyboard buffer and 
  61. ; removes the key from the buffer.  Will wait until a key is pressed to
  62. ; return.                                                         
  63.  
  64. PROC      getkey
  65.     push    bp
  66.     mov     bp, sp
  67.     xor     bh, bh
  68.     call    DoKeyboardInt
  69.     mov     sp, bp
  70.     pop     bp
  71.     ret
  72. ENDP     getkey
  73.  
  74. ; ---> getshift
  75. ; Returns the current shift state of the keyboard.  Shift state may be
  76. ; determined as follows:
  77. ; in AL
  78. ;    bit 0    Right-Shift pressed
  79. ;    bit 1    Left-Shift pressed
  80. ;    bit 2    Ctrl pressed
  81. ;    bit 3    Alt pressed
  82. ;    bit 4    Scroll lock on
  83. ;    bit 5    Num lock on
  84. ;    bit 6    Caps lock on
  85. ;    bit 7    Ins on
  86. ;
  87. ; Enhanced keyboards return further shift-state information in AH.
  88. ;    bit 7: SysRq key pressed
  89. ;    bit 6: Caps lock key pressed
  90. ;    bit 5: Num lock pressed
  91. ;    bit 4: Scroll lock pressed
  92. ;    bit 3: Right-Alt pressed
  93. ;    bit 2: Right-Ctrl pressed
  94. ;    bit 1: Left-Alt pressed
  95. ;    bit 0: Left-Ctrl pressed
  96.  
  97. PROC     getshift
  98.     push   bp
  99.     mov    bp, sp
  100.     mov    bh, 02h
  101.     call   DoKeyboardInt
  102.     mov    sp, bp
  103.     pop    bp
  104.     ret
  105. ENDP     getshift
  106. END
  107.