311d9fd46fdbc2b1aa91ff8a6a837a142d47ec1e
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/kdbg/kdb_keyboard.c
5 * PURPOSE: Keyboard driver
7 * PROGRAMMERS: Victor Kirhenshtein (sauros@iname.com)
8 * Jason Filby (jasonfilby@yahoo.com)
11 /* INCLUDES ****************************************************************/
18 #define KBD_STATUS_REG 0x64
19 #define KBD_CNTL_REG 0x64
20 #define KBD_DATA_REG 0x60
22 #define KBD_STAT_OBF 0x01
23 #define KBD_STAT_IBF 0x02
25 #define CTRL_WRITE_MOUSE 0xD4
27 #define MOU_DISAB 0xF5
28 #define MOUSE_ACK 0xFA
30 #define KBD_DISABLE_MOUSE 0xA7
31 #define KBD_ENABLE_MOUSE 0xA8
33 #define kbd_write_command(cmd) WRITE_PORT_UCHAR((PUCHAR)KBD_CNTL_REG,cmd)
34 #define kbd_write_data(cmd) WRITE_PORT_UCHAR((PUCHAR)KBD_DATA_REG,cmd)
35 #define kbd_read_input() READ_PORT_UCHAR((PUCHAR)KBD_DATA_REG)
36 #define kbd_read_status() READ_PORT_UCHAR((PUCHAR)KBD_STATUS_REG)
38 static unsigned char keyb_layout
[2][128] =
40 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
41 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
42 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
43 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
44 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
45 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
46 "\r\000/" /* 0x60 - 0x6f */
48 "\000\033!@#$%^&*()_+\177\t" /* 0x00 - 0x0f */
49 "QWERTYUIOP{}\r\000AS" /* 0x10 - 0x1f */
50 "DFGHJKL:\"`\000\\ZXCV" /* 0x20 - 0x2f */
51 "BNM<>?\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
52 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
53 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
54 "\r\000/" /* 0x60 - 0x6f */
59 /* FUNCTIONS *****************************************************************/
62 KbdSendCommandToMouse(UCHAR Command
)
66 while (kbd_read_status() & KBD_STAT_OBF
&& Retry
--)
69 KeStallExecutionProcessor(50);
73 while (kbd_read_status() & KBD_STAT_IBF
&& Retry
--)
74 KeStallExecutionProcessor(50);
76 kbd_write_command(CTRL_WRITE_MOUSE
);
79 while (kbd_read_status() & KBD_STAT_IBF
&& Retry
--)
80 KeStallExecutionProcessor(50);
82 kbd_write_data(Command
);
85 while (!(kbd_read_status() & KBD_STAT_OBF
) && Retry
--)
86 KeStallExecutionProcessor(50);
88 if (kbd_read_input() != MOUSE_ACK
) { ; }
95 KbdSendCommandToMouse(MOU_ENAB
);
98 VOID
KbdDisableMouse()
100 KbdSendCommandToMouse(MOU_DISAB
);
104 KdbpTryGetCharKeyboard(PULONG ScanCode
, ULONG Retry
)
106 static byte_t last_key
= 0;
107 static byte_t shift
= 0;
109 BOOLEAN KeepRetrying
= (Retry
== 0);
111 while (KeepRetrying
|| Retry
-- > 0)
113 while (kbd_read_status() & KBD_STAT_OBF
)
117 scancode
= kbd_read_input();
119 /* check for SHIFT-keys */
120 if (((scancode
& 0x7F) == 42) || ((scancode
& 0x7F) == 54))
122 shift
= !(scancode
& 0x80);
126 /* ignore all other RELEASED-codes */
131 else if (last_key
!= scancode
)
133 //printf("kbd: %d, %d, %c\n", scancode, last_key, keyb_layout[shift][scancode]);
135 c
= keyb_layout
[shift
][scancode
];
136 *ScanCode
= scancode
;