i8048Kbd.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:24k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* i8048Kbd.c - Intel 8048 keyboard driver routines */
  2. /* Copyright 1993-1996 Wind River System, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01c,11jun96,wlf  doc: cleanup.
  8. 01b,14jun95,hdn  removed function declarations defined in sysLib.h.
  9. 01a,20oct93,vin  created
  10. */
  11. /*
  12. DESCRIPTION
  13. This is the driver for the Intel 8048 Keyboard Controller Chip used on a 
  14. personal computer 386 / 486. This driver handles the 83 key  keyboard for
  15. PC, PC XT, and PC PORTABLE. This driver does not change the defaults set by 
  16. the BIOS. The BIOS initializes the scan code set to 1.
  17. USER CALLABLE ROUTINES
  18. The routines in this driver are accessed from external modules
  19. through the hook routine, the pointer to which is initialized
  20. in the KBD_CON_DEV structure at the time of initialization.
  21. This makes the access to these routines more generic without declaring
  22. these functions as external. 
  23. The routines in this driver which are accessed from an external module
  24. are kbdIntr() and kbdHrdInit(). kbdIntr() is installed as an interrupt
  25. service routine through the intConnect call in sysHwInit2(). 
  26. kbdHrdInit() is called to initialize the device descriptors and the 
  27. key board. 
  28. The kbdIntr() is the interrupt handler which handles the key board interrupt
  29. and is responsible for the handing the character received to whichever
  30. console the kbdDv.currCon is initialized to. By default this is initialized
  31. to PC_CONSOLE. If the user has to change the current console he will have
  32. to make an ioctl call with the option CONIOCURCONSOLE and the argument 
  33. as the console number which he wants to change to. To return to the console
  34. owned by the shell the user has to do an ioctl call back to the console number
  35. owned the shell from his application. 
  36.  
  37. Before using the driver, it must be initialized by calling kbdHrdInit(). 
  38. This routine should be called exactly once. Normally, it is called from 
  39. a generic driver for eg. from tyCoDrv() which is called before tyCoDevCreate.
  40. SEE ALSO
  41. conLib
  42. NOTES
  43. The following macros should be defined in <target>.h file
  44. COMMAND_8048, DATA_8048,STATUS_8048. These refer to the io base addresses
  45. of the various key board controller registers. The macros N_VIRTUAL_CONSOLES
  46. and PC_CONSOLE should be defined in config.h file.
  47. */
  48. /* includes */
  49. #include "vxWorks.h"
  50. #include "iv.h"
  51. #include "ioLib.h"
  52. #include "iosLib.h"
  53. #include "memLib.h"
  54. #include "tyLib.h"
  55. #include "errnoLib.h"
  56. #include "config.h"
  57. #include "drv/serial/pcConsole.h"
  58. /* externals */
  59. IMPORT PC_CON_DEV pcConDv [N_VIRTUAL_CONSOLES] ;
  60. /* locals */
  61. LOCAL KBD_CON_DEV kbdConDv; /* key board device descriptor */
  62. LOCAL unsigned char enhancedKeys[] =  /* 16 extended keys */
  63.     {
  64.     0x1c,   /* keypad enter */
  65.     0x1d,   /* right control */
  66.     0x35,   /* keypad slash */
  67.     0x37,   /* print screen */
  68.     0x38,   /* right alt */
  69.     0x46,   /* break (control-pause) */
  70.     0x47,   /* editpad home */
  71.     0x48,   /* editpad up */
  72.     0x49,   /* editpad pgup */
  73.     0x4b,   /* editpad left */
  74.     0x4d,   /* editpad right */
  75.     0x4f,   /* editpad end */
  76.     0x50,   /* editpad dn */
  77.     0x51,   /* editpad pgdn */
  78.     0x52,   /* editpad ins */
  79.     0x53    /* editpad del */
  80.     };
  81. /* action table*/
  82. LOCAL UCHAR action [144] =
  83.     { /* Action table for scanCode */
  84.     0,   AS,   AS,   AS,   AS,   AS,   AS,   AS, /* scan  0- 7 */
  85.    AS,   AS,   AS,   AS,   AS,   AS,   AS,   AS, /* scan  8- F */
  86.    AS,   AS,   AS,   AS,   AS,   AS,   AS,   AS, /* scan 10-17 */
  87.    AS,   AS,   AS,   AS,   AS,   CN,   AS,   AS, /* scan 18-1F */
  88.    AS,   AS,   AS,   AS,   AS,   AS,   AS,   AS, /* scan 20-27 */
  89.    AS,   AS,   SH,   AS,   AS,   AS,   AS,   AS, /* scan 28-2F */
  90.    AS,   AS,   AS,   AS,   AS,   AS,   SH,   AS, /* scan 30-37 */
  91.    AS,   AS,   CP,   0,    0,    0,    0,     0, /* scan 38-3F */
  92.     0,   0,    0,    0,    0,    NM,   ST,   ES, /* scan 40-47 */
  93.    ES,   ES,   ES,   ES,   ES,   ES,   ES,   ES, /* scan 48-4F */
  94.    ES,   ES,   ES,   ES,   0,    0,    0,     0, /* scan 50-57 */
  95.     0,   0,    0,    0,    0,    0,    0,     0, /* scan 58-5F */
  96.     0,   0,    0,    0,    0,    0,    0,     0, /* scan 60-67 */
  97.     0,   0,    0,    0,    0,    0,    0,     0, /* scan 68-6F */
  98.    AS,   0,    0,    AS,   0,    0,    AS,    0, /* scan 70-77 */
  99.     0,   AS,   0,    0,    0,    AS,   0,     0, /* scan 78-7F */
  100.    AS,   CN,   AS,   AS,   AS,   ST,   EX,   EX, /* enhanced   */
  101.    AS,   EX,   EX,   AS,   EX,   AS,   EX,   EX  /* enhanced   */
  102.     };
  103. /*  key board Maps Japanese and english */
  104. LOCAL UCHAR keyMap [2][4][144] =
  105.     { 
  106.     { /* Japanese Enhanced keyboard */
  107.     { /* unshift code */
  108.     0,  0x1b,   '1',   '2',   '3',   '4',   '5',   '6', /* scan  0- 7 */
  109.   '7',   '8',   '9',   '0',   '-',   '^',  0x08,  't', /* scan  8- F */
  110.   'q',   'w',   'e',   'r',   't',   'y',   'u',   'i', /* scan 10-17 */
  111.   'o',   'p',   '@',   '[',  'r',   CN,    'a',   's', /* scan 18-1F */
  112.   'd',   'f',   'g',   'h',   'j',   'k',   'l',   ';', /* scan 20-27 */
  113.   ':',     0,   SH,    ']',   'z',   'x',   'c',   'v', /* scan 28-2F */
  114.   'b',   'n',   'm',   ',',   '.',   '/',   SH,    '*', /* scan 30-37 */
  115.   ' ',   ' ',   CP,     0,     0,     0,     0,     0, /* scan 38-3F */
  116.     0,     0,     0,     0,     0,   NM,    ST,    '7', /* scan 40-47 */
  117.   '8',   '9',   '-',   '4',   '5',   '6',   '+',   '1', /* scan 48-4F */
  118.   '2',   '3',   '0',   '.',     0,     0,     0,     0, /* scan 50-57 */
  119.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 58-5F */
  120.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 60-67 */
  121.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 68-6F */
  122.   ' ',     0,     0,  '\',     0,     0,   ' ',     0, /* scan 70-77 */
  123.     0,   ' ',     0,     0,     0,  '\',     0,     0, /* scan 78-7F */
  124.   'r',   CN,   '/',   '*',   ' ',    ST,    'F',   'A', /* extended */
  125.     0,   'D',   'C',     0,   'B',     0,    '@',   'P'  /* extended */
  126.     },
  127.     { /* shift code */
  128.     0,  0x1b,   '!',   '"',   '#',   '$',   '%',   '&', /* scan  0- 7 */
  129.  ''',   '(',   ')',     0,   '=',   '~',  0x08,  't', /* scan  8- F */
  130.   'Q',   'W',   'E',   'R',   'T',   'Y',   'U',   'I', /* scan 10-17 */
  131.   'O',   'P',   '`',   '{',  'r',   CN,    'A',   'S', /* scan 18-1F */
  132.   'D',   'F',   'G',   'H',   'J',   'K',   'L',   '+', /* scan 20-27 */
  133.   '*',     0,   SH,    '}',   'Z',   'X',   'C',   'V', /* scan 28-2F */
  134.   'B',   'N',   'M',   '<',   '>',   '?',   SH,    '*', /* scan 30-37 */
  135.   ' ',   ' ',   CP,      0,     0,     0,     0,     0, /* scan 38-3F */
  136.     0,     0,     0,     0,     0,   NM,    ST,    '7', /* scan 40-47 */
  137.   '8',   '9',   '-',   '4',   '5',   '6',   '+',   '1', /* scan 48-4F */
  138.   '2',   '3',   '0',   '.',     0,     0,     0,     0, /* scan 50-57 */
  139.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 58-5F */
  140.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 60-67 */
  141.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 68-6F */
  142.   ' ',     0,     0,   '_',     0,     0,   ' ',     0, /* scan 70-77 */
  143.     0,   ' ',     0,     0,     0,   '|',     0,     0, /* scan 78-7F */
  144.   'r',   CN,   '/',   '*',   ' ',    ST,    'F',   'A', /* extended */
  145.     0,   'D',   'C',     0,   'B',     0,    '@',   'P'  /* extended */
  146.     },
  147.     { /* Control code */
  148.  0xff,  0x1b,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan  0- 7 */
  149.  0xff,  0xff,  0xff,  0xff,  0xff,  0x1e,  0xff,  't', /* scan  8- F */
  150.  0x11,  0x17,  0x05,  0x12,  0x14,  0x19,  0x15,  0x09, /* scan 10-17 */
  151.  0x0f,  0x10,  0x00,  0x1b,  'r',   CN,  0x01,   0x13, /* scan 18-1F */
  152.  0x04,  0x06,  0x07,  0x08,  0x0a,  0x0b,  0x0c,  0xff, /* scan 20-27 */
  153.  0xff,  0xff,   SH,   0x1d,  0x1a,  0x18,  0x03,  0x16, /* scan 28-2F */
  154.  0x02,  0x0e,  0x0d,  0xff,  0xff,  0xff,  SH,    0xff, /* scan 30-37 */
  155.  0xff,  0xff,   CP,   0xff,  0xff,  0xff,  0xff,  0xff, /* scan 38-3F */
  156.  0xff,  0xff,  0xff,  0xff,  0xff,   NM,   ST,    0xff, /* scan 40-47 */
  157.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 48-4F */
  158.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 50-57 */
  159.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 58-5F */
  160.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 60-67 */
  161.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 68-6F */
  162.  0xff,  0xff,  0xff,  0x1f,  0xff,  0xff,  0xff,  0xff, /* scan 70-77 */
  163.  0xff,  0xff,  0xff,  0xff,  0xff,  0x1c,  0xff,  0xff, /* scan 78-7F */
  164.   'r',   CN,   '/',   '*',   ' ',    ST,  0x0c,  0xff, /* extended */
  165.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff  /* extended */
  166.     },
  167.     { /* non numeric code */
  168.     0,  0x1b,   '1',   '2',   '3',   '4',   '5',   '6', /* scan  0- 7 */
  169.   '7',   '8',   '9',   '0',   '-',   '^',  0x08,  't', /* scan  8- F */
  170.   'q',   'w',   'e',   'r',   't',   'y',   'u',   'i', /* scan 10-17 */
  171.   'o',   'p',   '@',   '[',  'r',   CN,    'a',   's', /* scan 18-1F */
  172.   'd',   'f',   'g',   'h',   'j',   'k',   'l',   ';', /* scan 20-27 */
  173.   ':',     0,   SH,    ']',   'z',   'x',   'c',   'v', /* scan 28-2F */
  174.   'b',   'n',   'm',   ',',   '.',   '/',   SH,    '*', /* scan 30-37 */
  175.   ' ',   ' ',   CP,     0,     0,     0,     0,     0, /* scan 38-3F */
  176.     0,     0,     0,     0,     0,   NM,    ST,    'w', /* scan 40-47 */
  177.   'x',   'y',   'l',   't',   'u',   'v',   'm',   'q', /* scan 48-4F */
  178.   'r',   's',   'p',   'n',     0,     0,     0,     0, /* scan 50-57 */
  179.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 58-5F */
  180.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 60-67 */
  181.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 68-6F */
  182.   ' ',     0,     0,  '\',     0,     0,   ' ',     0, /* scan 70-77 */
  183.     0,   ' ',     0,     0,     0,  '\',     0,     0, /* scan 78-7F */
  184.   'r',   CN,   '/',   '*',   ' ',    ST,    'F',   'A', /* extended */
  185.     0,   'D',   'C',     0,   'B',     0,    '@',   'P'  /* extended */
  186.     }
  187.     },
  188.     { /* English Enhanced keyboard */
  189.     { /* unshift code */
  190.     0,  0x1b,   '1',   '2',   '3',   '4',   '5',   '6', /* scan  0- 7 */
  191.   '7',   '8',   '9',   '0',   '-',   '=',  0x08,  't', /* scan  8- F */
  192.   'q',   'w',   'e',   'r',   't',   'y',   'u',   'i', /* scan 10-17 */
  193.   'o',   'p',   '[',   ']',  'r',   CN,    'a',   's', /* scan 18-1F */
  194.   'd',   'f',   'g',   'h',   'j',   'k',   'l',   ';', /* scan 20-27 */
  195.  ''',   '`',   SH,   '\',   'z',   'x',   'c',   'v', /* scan 28-2F */
  196.   'b',   'n',   'm',   ',',   '.',   '/',   SH,    '*', /* scan 30-37 */
  197.   ' ',   ' ',   CP,      0,     0,     0,     0,     0, /* scan 38-3F */
  198.     0,     0,     0,     0,     0,   NM,    ST,    '7', /* scan 40-47 */
  199.   '8',   '9',   '-',   '4',   '5',   '6',   '+',   '1', /* scan 48-4F */
  200.   '2',   '3',   '0',   '.',     0,     0,     0,     0, /* scan 50-57 */
  201.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 58-5F */
  202.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 60-67 */
  203.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 68-6F */
  204.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 70-77 */
  205.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 78-7F */
  206.   'r',   CN,   '/',   '*',   ' ',    ST,   'F',   'A', /* extended */
  207.     0,   'D',   'C',     0,   'B',     0,    '@',  'P'  /* extended */
  208.     },
  209.     { /* shift code */
  210.     0,  0x1b,   '!',   '@',   '#',   '$',   '%',   '^', /* scan  0- 7 */
  211.   '&',   '*',   '(',   ')',   '_',   '+',  0x08,  't', /* scan  8- F */
  212.   'Q',   'W',   'E',   'R',   'T',   'Y',   'U',   'I', /* scan 10-17 */
  213.   'O',   'P',   '{',   '}',  'r',   CN,    'A',   'S', /* scan 18-1F */
  214.   'D',   'F',   'G',   'H',   'J',   'K',   'L',   ':', /* scan 20-27 */
  215.   '"',   '~',   SH,    '|',   'Z',   'X',   'C',   'V', /* scan 28-2F */
  216.   'B',   'N',   'M',   '<',   '>',   '?',   SH,    '*', /* scan 30-37 */
  217.   ' ',   ' ',   CP,      0,     0,     0,     0,     0, /* scan 38-3F */
  218.     0,     0,     0,     0,     0,   NM,    ST,    '7', /* scan 40-47 */
  219.   '8',   '9',   '-',   '4',   '5',   '6',   '+',   '1', /* scan 48-4F */
  220.   '2',   '3',   '0',   '.',     0,     0,     0,     0, /* scan 50-57 */
  221.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 58-5F */
  222.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 60-67 */
  223.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 68-6F */
  224.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 70-77 */
  225.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 78-7F */
  226.   'r',   CN,   '/',   '*',   ' ',    ST,   'F',   'A', /* extended */
  227.     0,   'D',   'C',     0,   'B',     0,   '@',   'P'  /* extended */
  228.     },
  229.     { /* Control code */
  230.  0xff,  0x1b,  0xff,  0x00,  0xff,  0xff,  0xff,  0xff, /* scan  0- 7 */
  231.  0x1e,  0xff,  0xff,  0xff,  0x1f,  0xff,  0xff,  't', /* scan  8- F */
  232.  0x11,  0x17,  0x05,  0x12,  0x14,  0x19,  0x15,  0x09, /* scan 10-17 */
  233.  0x0f,  0x10,  0x1b,  0x1d,  'r',   CN,   0x01,  0x13, /* scan 18-1F */
  234.  0x04,  0x06,  0x07,  0x08,  0x0a,  0x0b,  0x0c,  0xff, /* scan 20-27 */
  235.  0xff,  0x1c,   SH,   0xff,  0x1a,  0x18,  0x03,  0x16, /* scan 28-2F */
  236.  0x02,  0x0e,  0x0d,  0xff,  0xff,  0xff,   SH,   0xff, /* scan 30-37 */
  237.  0xff,  0xff,   CP,   0xff,  0xff,  0xff,  0xff,  0xff, /* scan 38-3F */
  238.  0xff,  0xff,  0xff,  0xff,  0xff,   NM,    ST,   0xff, /* scan 40-47 */
  239.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 48-4F */
  240.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 50-57 */
  241.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 58-5F */
  242.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 60-67 */
  243.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 68-6F */
  244.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 70-77 */
  245.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, /* scan 78-7F */
  246.   'r',   CN,   '/',   '*',   ' ',    ST,  0xff,  0xff, /* extended */
  247.  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff  /* extended */
  248.     },
  249.     { /* non numeric code */
  250.     0,  0x1b,   '1',   '2',   '3',   '4',   '5',   '6', /* scan  0- 7 */
  251.   '7',   '8',   '9',   '0',   '-',   '=',  0x08,  't', /* scan  8- F */
  252.   'q',   'w',   'e',   'r',   't',   'y',   'u',   'i', /* scan 10-17 */
  253.   'o',   'p',   '[',   ']',  'r',   CN,    'a',   's', /* scan 18-1F */
  254.   'd',   'f',   'g',   'h',   'j',   'k',   'l',   ';', /* scan 20-27 */
  255.  ''',   '`',   SH,   '\',   'z',   'x',   'c',   'v', /* scan 28-2F */
  256.   'b',   'n',   'm',   ',',   '.',   '/',   SH,    '*', /* scan 30-37 */
  257.   ' ',   ' ',   CP,      0,     0,     0,     0,     0, /* scan 38-3F */
  258.     0,     0,     0,     0,     0,   NM,    ST,    'w', /* scan 40-47 */
  259.   'x',   'y',   'l',   't',   'u',   'v',   'm',   'q', /* scan 48-4F */
  260.   'r',   's',   'p',   'n',     0,     0,     0,     0, /* scan 50-57 */
  261.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 58-5F */
  262.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 60-67 */
  263.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 68-6F */
  264.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 70-77 */
  265.     0,     0,     0,     0,     0,     0,     0,     0, /* scan 78-7F */
  266.   'r',   CN,   '/',   '*',   ' ',    ST,   'F',   'A', /* extended */
  267.     0,   'D',   'C',     0,   'B',     0,    '@',  'P'  /* extended */
  268.     }
  269.     }
  270.     };
  271. /* forward declarations */
  272. LOCAL void kbdStatInit (void);
  273. LOCAL void kbdConvChar(unsigned char scanCode);
  274. LOCAL void kbdNormal (unsigned char scanCode);
  275. LOCAL void kbdShift (unsigned char scanCode);
  276. LOCAL void kbdCtrl (unsigned char scanCode);
  277. LOCAL void kbdNum (unsigned char scanCode);
  278. LOCAL void kbdCaps (unsigned char scanCode);
  279. LOCAL void kbdStp (unsigned char scanCode);
  280. LOCAL void kbdExt (unsigned char scanCode);
  281. LOCAL void kbdEs (unsigned char scanCode);
  282. LOCAL void  (*keyHandler[]) (unsigned char scanCode)  =
  283.     {
  284.     kbdNormal,   kbdShift,   kbdCtrl,   kbdNum,   kbdCaps,
  285.     kbdStp,      kbdExt,     kbdEs
  286.     };
  287. LOCAL void kbdHook (int opCode);
  288. /*******************************************************************************
  289. *
  290. * kbdHrdInit - initialize the Keyboard
  291. * This routine is called to do the key board initialization from an external
  292. * routine
  293. *
  294. * RETURNS: N/A
  295. *
  296. * NOMANUAL
  297. */
  298. void kbdHrdInit (void)
  299.     {
  300.     UCHAR  cond;
  301.     cond = sysInByte (STATUS_8048); /* get the status */
  302.     
  303.     sysOutByte ( COMMAND_8048, (cond | 0x40)); /* enable the keyboard */
  304.     kbdStatInit ();
  305.     } 
  306. /*******************************************************************************
  307. *
  308. * kbdStatInit - initialize the Keyboard state
  309. *
  310. * This routine initializes the keyboard descriptor in the virtual consoles.
  311. * The same keybaord descriptor is used for all the virtual consoles.
  312. *
  313. */
  314. LOCAL void kbdStatInit (void)
  315.     {
  316.     int ix; /* to hold temp variable */
  317.     /* initialize all the key board descriptors in the virtual consoles */
  318.     for ( ix = 0; ix < N_VIRTUAL_CONSOLES; ix++)
  319. {
  320. pcConDv [ix].ks = &kbdConDv; /* kbd device descriptor */
  321. }
  322.     kbdConDv.curMode = TRUE; /* default mode is normal */
  323.     
  324.     /* default keyboard is English Enhanced key */
  325.     
  326.     kbdConDv.kbdMode  = ENGLISH_KBD; 
  327.     kbdConDv.kbdFlags = NORMAL|NUM; /* Numeric mode on */
  328.     kbdConDv.kbdState = 0;  /* unshift state */
  329.     kbdConDv.kbdHook  = (FUNCPTR) kbdHook; /* hook routine */
  330.     kbdConDv.currCon  = PC_CONSOLE;      /* console tty */
  331.     
  332.     }
  333. /*******************************************************************************
  334. *
  335. * kbdIntr - interrupt level processing
  336. *
  337. * This routine handles the keyboard interrupts
  338. *
  339. * RETURNS: N/A
  340. *
  341. * NOMANUAL
  342. */
  343. void kbdIntr (void)
  344.     {
  345.     FAST UCHAR scanCode; /* to hold the scanCode */
  346.     FAST UCHAR status; /* to hold the status */
  347.     scanCode = sysInByte (DATA_8048); /* get the scan code */
  348.     status = sysInByte (STATUS_8048); /* get the status    */
  349.     sysOutByte (COMMAND_8048, (status | 0x80)); /* send acknowledgment    */
  350.     sysOutByte (STATUS_8048, status); /* restore previous status */
  351.     if (scanCode == 0xfa)
  352. {
  353. return;
  354. }
  355.     kbdConvChar (scanCode); /* convert scancode to ASCII character and */
  356. /* announce it to tyIRd        */
  357.     }
  358. /*******************************************************************************
  359. *
  360. * kbdConvChar - Convert scan code to character
  361. *
  362. * This routine convert scanCode to ASCII character
  363. */
  364. LOCAL void kbdConvChar 
  365.     (
  366.     UCHAR scanCode /* scan Code from the keyboard */
  367.     )
  368.     {
  369.     if (scanCode == 0xe0)
  370. {
  371. kbdConDv.kbdFlags |= EXT;
  372. return;
  373. }
  374.     /* if high bit of scanCode,set break flag */
  375.     if (((scanCode & 0x80) << 2) == BRK)  
  376.        kbdConDv.kbdFlags |=  BRK;
  377.     else
  378.        kbdConDv.kbdFlags &= ~BRK;
  379.     if ((scanCode == 0xe1) || (kbdConDv.kbdFlags & E1))
  380. {
  381. if (scanCode == 0xe1)
  382.     {
  383.     kbdConDv.kbdFlags ^= BRK;  /* reset the break flag */
  384.     kbdConDv.kbdFlags ^= E1;   /* bitwise EXOR with E1 flag */
  385.     }
  386. return;
  387. }
  388.     scanCode &= 0x7f;
  389.     if ((kbdConDv.kbdFlags & EXT) == EXT)
  390. {
  391. int  ix;
  392. for (ix = 0; ix < EXTND_SIZE; ix++)
  393.     {
  394.     if (scanCode == enhancedKeys [ix])
  395. {
  396. scanCode = E0_BASE + ix;
  397. ix = -1;
  398. break;
  399. }
  400.     }
  401. kbdConDv.kbdFlags ^= EXT;  /* reset the extended flag */
  402. if (ix != -1)
  403.     {
  404.     return ;  /* unknown scancode */
  405.     }
  406. }
  407.     /* invoke the respective handler */
  408.     (*keyHandler [action [scanCode]]) (scanCode);
  409.     }
  410. /******************************************************************************
  411. *
  412. *
  413. * kbdNormal - Normal key
  414. *
  415. * This routine does the normal key processing
  416. */
  417. LOCAL void kbdNormal
  418.     (
  419.     UCHAR scanCode /* scan code recieved */
  420.     )
  421.     {
  422.     FAST UCHAR chr;
  423.     FAST int ix = kbdConDv.currCon; /* to hold the console no. */
  424.     if ((kbdConDv.kbdFlags & BRK) == NORMAL) 
  425. {
  426. chr = keyMap [kbdConDv.kbdMode][kbdConDv.kbdState][scanCode];
  427. if ((chr == 0xff) || (chr == 0x00))
  428.     {
  429.     return;
  430.     }
  431. /* if caps lock convert upper to lower */
  432. if (((kbdConDv.kbdFlags & CAPS) == CAPS) && 
  433.     (chr >= 'a' && chr <= 'z'))
  434.     { 
  435.     chr -= 'a' - 'A';
  436.     } 
  437. tyIRd (&(pcConDv [ix].tyDev), chr); /* give input to buffer */
  438. }
  439.     }
  440. /******************************************************************************
  441. *
  442. *
  443. * kbdShift - Shift key operation
  444. *
  445. * This routine sets the shift state of the key board
  446. */
  447. LOCAL void kbdShift
  448.     (
  449.     UCHAR scanCode /* scan code recieved */
  450.     )
  451.     {
  452.     if ((kbdConDv.kbdFlags & BRK) == BRK) 
  453. {
  454. kbdConDv.kbdState = AS;
  455. kbdConDv.kbdFlags &= (~SHIFT);
  456. }
  457.     else
  458. {
  459. kbdConDv.kbdState = SH;
  460. kbdConDv.kbdFlags |= SHIFT;
  461. }
  462.     }
  463. /******************************************************************************
  464. *
  465. *
  466. * kbdCtrl - Control key operation
  467. *
  468. * This routine sets the shift state of key board to control state
  469. */
  470. LOCAL void kbdCtrl
  471.     (
  472.     UCHAR scanCode /* scan code recieved */
  473.     )
  474.     {
  475.     if ((kbdConDv.kbdFlags & BRK) == BRK) 
  476. {
  477. kbdConDv.kbdState = AS;
  478. kbdConDv.kbdFlags &= (~CTRL);
  479. }
  480.     else
  481. {
  482. kbdConDv.kbdState = CN;
  483. kbdConDv.kbdFlags |= CTRL;
  484. }
  485.     }
  486. /******************************************************************************
  487. *
  488. *
  489. * kbdCaps - Capslock key operation
  490. *
  491. * This routine sets the capslock state and the key board flags. 
  492. */
  493. LOCAL void kbdCaps
  494.     (
  495.     UCHAR scanCode /* scan code recieved */
  496.     )
  497.     {
  498.     if ((kbdConDv.kbdFlags & BRK) == NORMAL) 
  499. {
  500. kbdConDv.kbdFlags ^= CAPS;
  501. }
  502.     }
  503. /******************************************************************************
  504. *
  505. *
  506. * kbdNum - Numerlock set key operation
  507. *
  508. * This routine sets the numeric lock state of the key board.
  509. * The keyboard state is numeric by default. If the numeric lock is off
  510. * then this routine initializes the keyboard state to non numeric state.
  511. */
  512. LOCAL void kbdNum
  513.     (
  514.     UCHAR scanCode /* scan code recieved */
  515.     )
  516.     {
  517.     if ((kbdConDv.kbdFlags & BRK) == NORMAL) 
  518. {
  519. kbdConDv.kbdFlags ^= NUM;
  520. kbdConDv.kbdState = (kbdConDv.kbdFlags & NUM) ? AS : NM;
  521. }
  522.     }
  523. /******************************************************************************
  524. *
  525. *
  526. * kbdStp - Scroll lock set key operation
  527. * This routine sets the scroll lock state of the key board. 
  528. * This routine outputs 0x13 if ^S is pressed or 0x11 if ^Q is pressed.
  529. */
  530. LOCAL void kbdStp
  531.     (
  532.     UCHAR scanCode /* scan code recieved */
  533.     )
  534.     {
  535.     FAST int ix = kbdConDv.currCon; /* to hold the console no. */
  536.     if ((kbdConDv.kbdFlags & BRK) == NORMAL) 
  537. {
  538. kbdConDv.kbdFlags ^= STP;
  539. (kbdConDv.kbdFlags & STP) ? tyIRd (&(pcConDv [ix].tyDev),0x13) : 
  540.                               tyIRd (&(pcConDv [ix].tyDev),0x11);
  541. }
  542.     }
  543. /******************************************************************************
  544. *
  545. *
  546. * kbdExt - Extended key board operation
  547. *
  548. * This routine processes the extended scan code operations
  549. * and ouputs an escape sequence. ESC [ <chr> . The character is for example
  550. * one of the following. (A, B, C, D, F, L, P)
  551. */
  552. LOCAL void kbdExt
  553.     (
  554.     UCHAR  scanCode /* scan code recieved */
  555.     )
  556.     {
  557.     FAST UCHAR chr;
  558.     FAST int ix = kbdConDv.currCon; /* to hold the console no. */
  559.     if ((kbdConDv.kbdFlags & BRK) == NORMAL) 
  560. {
  561. chr = keyMap [kbdConDv.kbdMode][kbdConDv.kbdState][scanCode];
  562. tyIRd (&pcConDv [ix].tyDev, 0x1b);  /* escape character */
  563. kbdConDv.curMode ? tyIRd (&pcConDv [ix].tyDev, '[') : 
  564.                      tyIRd (&pcConDv [ix].tyDev, 'O');
  565. tyIRd (&pcConDv [ix].tyDev, chr);
  566. }
  567.     }
  568. /******************************************************************************
  569. *
  570. *
  571. * kbdEs - Non Numeric key board operation
  572. *
  573. * This routine processes the non numeric scan code operations
  574. */
  575. LOCAL void kbdEs
  576.     (
  577.     UCHAR scanCode /* scan code recieved */
  578.     )
  579.     {
  580.     FAST UCHAR chr;
  581.     FAST int ix = kbdConDv.currCon; /* to hold the console no. */
  582.     if ((kbdConDv.kbdFlags & BRK) == NORMAL) 
  583. {
  584. chr = keyMap [kbdConDv.kbdMode][kbdConDv.kbdState][scanCode];
  585. if ((kbdConDv.kbdFlags & NUM) == NORMAL)
  586.     {
  587.     tyIRd (&pcConDv [ix].tyDev, 0x1b);  /* escape character */
  588.     tyIRd (&pcConDv [ix].tyDev, 'O');
  589.     }
  590. tyIRd (&pcConDv [ix].tyDev, chr);
  591. }
  592.     }
  593. /******************************************************************************
  594. *
  595. * kbdHook - key board function called from an external routine
  596. *
  597. * This function does the respective key board operation according to the
  598. * opCode. The user can extend this function to perform any key board 
  599. * operation called as a hook from any external function for eg
  600. * from the vga driver. 
  601. *
  602. */
  603. LOCAL void kbdHook
  604.     (
  605.     int opCode /* operation to perform */
  606.     )
  607.     {
  608.     switch (opCode)
  609. {
  610. case 0: /* reinitialize the keyboard state */
  611.       kbdStatInit ();
  612.       break;
  613. case 1:
  614.       break;
  615. default:
  616.       break;
  617. }
  618.     }