ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

kdb_keyboard.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS kernel
00004  * FILE:            ntoskrnl/dbg/kdb_keyboard.c
00005  * PURPOSE:         Keyboard driver
00006  *
00007  * PROGRAMMERS:     Victor Kirhenshtein (sauros@iname.com)
00008  *                  Jason Filby (jasonfilby@yahoo.com)
00009  */
00010 
00011 /* INCLUDES ****************************************************************/
00012 
00013 #include <ntoskrnl.h>
00014 #define NDEBUG
00015 #include <debug.h>
00016 
00017 
00018 #define KBD_STATUS_REG          0x64
00019 #define KBD_CNTL_REG            0x64
00020 #define KBD_DATA_REG            0x60
00021 
00022 #define KBD_STAT_OBF            0x01
00023 #define KBD_STAT_IBF            0x02
00024 
00025 #define CTRL_WRITE_MOUSE        0xD4
00026 #define MOU_ENAB                0xF4
00027 #define MOU_DISAB               0xF5
00028 #define MOUSE_ACK               0xFA
00029 
00030 #define KBD_DISABLE_MOUSE       0xA7
00031 #define KBD_ENABLE_MOUSE        0xA8
00032 
00033 #define kbd_write_command(cmd)  WRITE_PORT_UCHAR((PUCHAR)KBD_CNTL_REG,cmd)
00034 #define kbd_write_data(cmd)     WRITE_PORT_UCHAR((PUCHAR)KBD_DATA_REG,cmd)
00035 #define kbd_read_input()        READ_PORT_UCHAR((PUCHAR)KBD_DATA_REG)
00036 #define kbd_read_status()       READ_PORT_UCHAR((PUCHAR)KBD_STATUS_REG)
00037 
00038 static unsigned char keyb_layout[2][128] =
00039 {
00040     "\000\0331234567890-=\177\t"                                        /* 0x00 - 0x0f */
00041     "qwertyuiop[]\r\000as"                                              /* 0x10 - 0x1f */
00042     "dfghjkl;'`\000\\zxcv"                                              /* 0x20 - 0x2f */
00043     "bnm,./\000*\000 \000\201\202\203\204\205"                          /* 0x30 - 0x3f */
00044     "\206\207\210\211\212\000\000789-456+1"                             /* 0x40 - 0x4f */
00045     "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000"   /* 0x50 - 0x5f */
00046     "\r\000/"                                                           /* 0x60 - 0x6f */
00047     ,
00048     "\000\033!@#$%^&*()_+\177\t"                                        /* 0x00 - 0x0f */
00049     "QWERTYUIOP{}\r\000AS"                                              /* 0x10 - 0x1f */
00050     "DFGHJKL:\"`\000\\ZXCV"                                             /* 0x20 - 0x2f */
00051     "BNM<>?\000*\000 \000\201\202\203\204\205"                          /* 0x30 - 0x3f */
00052     "\206\207\210\211\212\000\000789-456+1"                             /* 0x40 - 0x4f */
00053     "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000"   /* 0x50 - 0x5f */
00054     "\r\000/"                                                           /* 0x60 - 0x6f */
00055 };
00056 
00057 typedef UCHAR byte_t;
00058 
00059 /* FUNCTIONS *****************************************************************/
00060 
00061 static VOID
00062 KbdSendCommandToMouse(UCHAR Command)
00063 {
00064     ULONG Retry = 20000;
00065 
00066     while (kbd_read_status() & KBD_STAT_OBF && Retry--)
00067     {
00068         kbd_read_input();
00069         KeStallExecutionProcessor(50);
00070     }
00071 
00072     Retry = 20000;
00073     while (kbd_read_status() & KBD_STAT_IBF && Retry--)
00074         KeStallExecutionProcessor(50);
00075 
00076     kbd_write_command(CTRL_WRITE_MOUSE);
00077 
00078     Retry = 20000;
00079     while (kbd_read_status() & KBD_STAT_IBF && Retry--)
00080         KeStallExecutionProcessor(50);
00081 
00082     kbd_write_data(Command);
00083 
00084     Retry = 20000;
00085     while (!(kbd_read_status() & KBD_STAT_OBF) && Retry--)
00086         KeStallExecutionProcessor(50);
00087 
00088     if (kbd_read_input() != MOUSE_ACK) { ; }
00089 
00090     return;
00091 }
00092 
00093 VOID KbdEnableMouse()
00094 {
00095     KbdSendCommandToMouse(MOU_ENAB);
00096 }
00097 
00098 VOID KbdDisableMouse()
00099 {
00100     KbdSendCommandToMouse(MOU_DISAB);
00101 }
00102 
00103 CHAR
00104 KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
00105 {
00106     static byte_t last_key = 0;
00107     static byte_t shift = 0;
00108     char c;
00109     BOOLEAN KeepRetrying = (Retry == 0);
00110 
00111     while (KeepRetrying || Retry-- > 0)
00112     {
00113         while (kbd_read_status() & KBD_STAT_OBF)
00114         {
00115             byte_t scancode;
00116 
00117             scancode = kbd_read_input();
00118 
00119             /* check for SHIFT-keys */
00120             if (((scancode & 0x7F) == 42) || ((scancode & 0x7F) == 54))
00121             {
00122                 shift = !(scancode & 0x80);
00123                 continue;
00124             }
00125 
00126             /* ignore all other RELEASED-codes */
00127             if (scancode & 0x80)
00128             {
00129                 last_key = 0;
00130             }
00131             else if (last_key != scancode)
00132             {
00133                 //printf("kbd: %d, %d, %c\n", scancode, last_key, keyb_layout[shift][scancode]);
00134                 last_key = scancode;
00135                 c = keyb_layout[shift][scancode];
00136                 *ScanCode = scancode;
00137 
00138                 if (c > 0)
00139                     return c;
00140             }
00141         }
00142     }
00143 
00144     return -1;
00145 }
00146 
00147 /* EOF */

Generated on Sat May 26 2012 04:36:17 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.