home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / BIOS_KEY.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.6 KB  |  88 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - bios_key.cas
  3.  *
  4.  * function(s)
  5.  *        _bios_keybrd - keyboard interface (MSC compatible)
  6.  *--------------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1991, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <bios.h>
  20.  
  21.  
  22. /*--------------------------------------------------------------------------*
  23.  
  24. Name            _bios_keybrd - keyboard interface
  25.  
  26. Usage           unsigned _bios_keybrd(unsigned cmd);
  27.  
  28. Prototype in    bios.h
  29.  
  30. Description     performs various keyboard operations using BIOS
  31.                 interrupt 0x16.  The parameter cmd determines the exact
  32.                 function:
  33.  
  34.                 _KEYBRD_READ        (0x00) = Get next key
  35.                 _KEYBRD_READY       (0x01) = Test for key
  36.                 _KEYBRD_SHIFTSTATUS (0x02) = Get shift status
  37.  
  38.                 _NKEYBRD_READ       (0x10) = Get next key for enhanced keyboard
  39.                 _NKEYBRD_READY      (0x11) = Test for key for enhanced keyboard
  40.                 _NKEYBRD_SHIFTSTATUS(0x12) = Get shift status for enhanced
  41.                                              keyboard
  42.  
  43.                 This function is compatible with Microsoft C, and is identical
  44.                 to the older bioskey() function, except for the type of the
  45.                 return value and the cmd parameter.
  46.  
  47. Return value    value returned to the AX register for the function specified
  48.                 when cmd is 0x00, 0x10, 0x02, or 0x12.
  49.  
  50.                 When cmd is 0x01 or 0x11 it returns zero if no key is waiting,
  51.                 0xFFFF if control break was pressed, otherwise the keycode.
  52.  
  53. *---------------------------------------------------------------------------*/
  54.  
  55. unsigned _bios_keybrd(unsigned cmd)
  56. {
  57. //  Clear zero flag
  58.     asm xor  al, al
  59.  
  60.     asm mov  ah, cmd
  61.     asm int  16h
  62.  
  63. //  If zero flag set then no key is waiting
  64.     asm jz   nokey
  65.  
  66. //  If we aren't checking status, just return key
  67.     asm test byte ptr (cmd), 1
  68.     asm jnz  keydone
  69.  
  70. //  Here we have status command and key waiting
  71. //  If keycode is zero (control-break) then signal with 0FFFFh
  72.     asm or   ax, ax
  73.     asm jnz  keydone
  74.     asm mov  ax, 0FFFFh
  75.     asm jmp  keydone
  76.  
  77. nokey:
  78. //  Zero flag wasn't set, if not checking status just return key
  79.     asm test byte ptr (cmd), 1
  80.     asm jz   keydone
  81.  
  82. //  Here we have status command and no key waiting
  83.     asm xor  ax, ax
  84.  
  85. keydone:
  86.     return _AX;
  87. }
  88.