home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 1.ddi / TOOLS.1 / INCLUDE / BKEYBRD.H < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  7.0 KB  |  189 lines

  1. /**
  2. *
  3. *  BKEYBRD.H    Header file for BIOS keyboard functions for Turbo C TOOLS
  4. *
  5. *  Version    6.00 (C)Copyright Blaise Computing Inc.  1986,1987,1989
  6. *
  7. **/
  8.  
  9. #ifndef DEF_BKEYBRD        /* Prevent redefinition.        */
  10. #define DEF_BKEYBRD 1        /* Prevent second reading of these  */
  11.                 /* definitions.             */
  12.  
  13. #include <ctype.h>
  14. #include <butil.h>
  15.  
  16. #define KB_BIOS_INT 0x16    /* General BIOS keyboard gate.        */
  17.  
  18.  
  19. #define KB_HEAD     0        /* KBSTUFF, KBPLACE: Whether to     */
  20.                 /* place char(s) at HEAD or at        */
  21. #define KB_TAIL     1        /* TAIL of queue.            */
  22.  
  23.                 /* KBPLACE error returns:        */
  24. #define KB_OK        0        /*   no error,                */
  25. #define KB_FULL     1        /*   buffer full,            */
  26. #define KB_PLACE    2        /*   bad "where" specification.     */
  27.  
  28. #define KB_DATASEG  0x40    /* Segment value of BIOS keyboard   */
  29.                 /* data.                */
  30. #define KB_HEADLOC  0x1a    /* Location of queue head pointer.  */
  31. #define KB_TAILOC   0x1c    /* Location of queue tail pointer.  */
  32.                 /*                    */
  33. #define KB_SHIFTLOC 0x17    /* Location of shift status register*/
  34.                 /*                    */
  35. #define KB_BUFEND   0x3e    /* Address of keyboard buffer end.  */
  36. #define KB_BUFSTART 0x1e    /* Address of keyboard buffer start.*/
  37.                 /*                    */
  38.                 /* Size of buffer in bytes.        */
  39. #define KB_BUFSIZE    (KB_BUFEND - KB_BUFSTART)
  40.                 /*                    */
  41.                 /* Size of buffer in keystrokes.    */
  42.                 /*                    */
  43. #define KB_BUFACSIZE  (((KB_BUFEND - KB_BUFSTART) >> 1) - 1)
  44.                 /* Far pointer to buffer head word. */
  45. #define KB_BUFHEADADDR (uttofaru (KB_DATASEG, KB_HEADLOC))
  46.                 /*                    */
  47.                 /* Far pointer to buffer tail word. */
  48. #define KB_BUFTAILADDR (uttofaru (KB_DATASEG, KB_TAILOC))
  49.                 /*                    */
  50.                 /* Far pointer to shift status byte.*/
  51. #define KB_SHIFTADDR (uttofaru (KB_DATASEG, KB_SHIFTLOC))
  52.  
  53. #define KB_NOEXTENDED    0    /* Values for b_kbxten.         */
  54. #define KB_EXTENDED    1
  55.  
  56. #define KB_NOENHANCED    0    /* Values for b_kbnhan.         */
  57. #define KB_ENHANCED    1
  58.  
  59. #define KB_USE_NORMAL    0    /* Values for b_kbusex.         */
  60. #define KB_USE_EXTEND    1
  61. #define KB_ERROR      (-1)    /* Additional value returned by     */
  62.                 /*   KBEXTEND.                */
  63.  
  64. #define KB_NO_KEY_FOUND 0    /* Values for the key_found field   */
  65. #define KB_KEY_FOUND    1    /*   of KB_DATA.            */
  66.  
  67.         /* Values to be placed in the control_action field  */
  68.         /* of KB_DATA.                        */
  69. #define KB_NO_REMOVE_KEY    0    /* Do not remove key from buffer.   */
  70. #define KB_REMOVE_KEY        1    /* Remove key from head of buffer.  */
  71. #define KB_FLUSH        2    /* Flush the keyboard buffer.        */
  72.  
  73.  
  74. typedef struct kstatus        /* KEYSTATUS structure:         */
  75. {                /* Maps keyboard status register    */
  76.                 /* onto unsigned integer.        */
  77.    unsigned right_shift  : 1;    /* Right Shift key depressed.        */
  78.    unsigned left_shift     : 1;    /* Left  Shift key depressed.        */
  79.    unsigned ctrl_shift     : 1;    /* Ctrl        key depressed.        */
  80.    unsigned alt_shift     : 1;    /* Alt           key depressed.        */
  81.    unsigned scroll_state : 1;    /* Scroll Lock has been toggled.    */
  82.    unsigned num_state     : 1;    /* Num Lock has been toggled.        */
  83.    unsigned caps_state     : 1;    /* Caps Lock has been toggled.        */
  84.    unsigned ins_state     : 1;    /* Insert state is active.        */
  85.                 /*                    */
  86.    unsigned filler     : 3;    /* Filler for word alignment.        */
  87.    unsigned hold_state     : 1;    /* Suspend key has been toggled.    */
  88.    unsigned scroll_shift : 1;    /* Scroll Lock key depressed.        */
  89.    unsigned num_shift     : 1;    /* Num Lock    key depressed.        */
  90.    unsigned caps_shift     : 1;    /* Caps Lock   key depressed.        */
  91.    unsigned ins_shift     : 1;    /* Insert      key depressed.        */
  92. } KEYSTATUS;
  93.  
  94.  
  95. typedef struct            /* KEY_SEQUENCE structure:        */
  96. {                /*  character & key codes for a key.*/
  97.     unsigned char   character_code;
  98.     unsigned char   key_code;
  99. } KEY_SEQUENCE;
  100.  
  101.  
  102. typedef struct            /* KB_DATA structure:            */
  103. {                /*   information for key control    */
  104.                 /*   function.                */
  105.     int key_found;        /* Key was pressed if equal to        */
  106.                 /*   KB_KEY_FOUND.            */
  107.     KEY_SEQUENCE key_seq;    /* Character and scan codes of key  */
  108.                 /*   (if key_found is KB_KEY_FOUND).*/
  109.     void *pfunction_data;    /* Pointer to user-supplied        */
  110.                 /*   information structure.        */
  111.     int control_action;     /* Special action for key control   */
  112.                 /*   function to take.            */
  113.     int returned_action;    /* Action to be taken on return     */
  114.                 /*   from key control function.     */
  115.                 /*   Either KB_REMOVE_KEY if the    */
  116.                 /*   caller should remove the        */
  117.                 /*   detected keystroke (if there   */
  118.                 /*   was one), or KB_NO_REMOVE_KEY  */
  119.                 /*   otherwise.             */
  120. } KB_DATA;
  121.  
  122.  
  123. typedef void (*PKEY_CONTROL)    /* PKEY_CONTROL: address of key     */
  124.            (KB_DATA *); /*   control function  -- pointer   */
  125.                 /*   to function returning void,    */
  126.                 /*   accepting a pointer to KB_DATA.*/
  127.  
  128.  
  129. /* Global variables                            */
  130.  
  131. extern unsigned char b_keycod [];
  132.  
  133. extern int b_kbxten;        /* Presence of extended BIOS functions. */
  134.  
  135. extern int b_kbnhan;        /* Presence of enhanced keyboard.        */
  136.  
  137. extern int b_kbusex;        /* Flag controlling whether to use        */
  138.                 /* normal or extended keyboard functions*/
  139.  
  140. extern PKEY_CONTROL b_key_ctrl;     /* Default key control procedure*/
  141.                     /* for user input functions.    */
  142.  
  143. /* Function declarations.                        */
  144.  
  145.         /* Equipment options.                    */
  146. int   cdecl kbequip (void);        /* Sense extended BIOS and  */
  147.                     /*   enhanced keyboard.     */
  148. int   cdecl kbextend (int);        /* Specify extended or        */
  149.                     /*   traditional services.  */
  150.  
  151.         /* Normal BIOS operations.                */
  152. int   cdecl kbready (char *, int *);    /* Check for a keystroke.   */
  153. char  cdecl kbquery (char *, int, int *,/* Get a string from CON.   */
  154.              int *);        /*                */
  155. int   cdecl kbgetkey (int *);        /* Await & return char and  */
  156.                     /*   scan code via BIOS.    */
  157. int   cdecl kbflush (void);        /* Flush keyboard buffer.   */
  158. int   cdecl kbqueue (int *);        /* Total and # remaining in */
  159.                     /*   keyboard queue.        */
  160.  
  161.         /* Key control functions.                */
  162. int   cdecl kbpoll (PKEY_CONTROL,void *,/* Poll keyboard once for a */
  163.             KEY_SEQUENCE *,    /*   keystroke.         */
  164.             int);        /*                */
  165. KEY_SEQUENCE cdecl kbwait(PKEY_CONTROL, /* Await a keystroke using  */
  166.             void *);        /*   polling.            */
  167. void  cdecl kbkcflsh (PKEY_CONTROL,    /* Call key control function*/
  168.               void *);        /*   to flush keyboard        */
  169.                     /*   buffer.            */
  170.  
  171.         /* Controlling keyboard.                */
  172. void  cdecl kbset (const KEYSTATUS *);    /* Set shift status.        */
  173. char *cdecl kbstuff (int, char *);    /* Stuff string into queue. */
  174. int   cdecl kbplace (int, char, char);    /* Place one key into queue.*/
  175.  
  176.  
  177. #define kbstatus(pkeybd) ((*((int *) (pkeybd))) = utpeekw (KB_SHIFTADDR))
  178.  
  179. #define kbscanof(c) (isascii ((int) c)                     \
  180.             ? ((int) b_keycod [((int) (c))])             \
  181.             : (-1))
  182.  
  183. #define kbcharof(c) (isascii ((int) c)                     \
  184.             ? ((int) (c))                     \
  185.             : (-1))
  186.  
  187.  
  188. #endif                /* Ends "#ifndef DEF_BKEYBRD"       */
  189.