ReactOS  0.4.15-dev-2947-g59e1b78
kdb_keyboard.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdb_keyboard.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define KBD_STATUS_REG   0x64
 
#define KBD_CNTL_REG   0x64
 
#define KBD_DATA_REG   0x60
 
#define KBD_STAT_OBF   0x01
 
#define KBD_STAT_IBF   0x02
 
#define CTRL_WRITE_MOUSE   0xD4
 
#define MOU_ENAB   0xF4
 
#define MOU_DISAB   0xF5
 
#define MOUSE_ACK   0xFA
 
#define KBD_DISABLE_MOUSE   0xA7
 
#define KBD_ENABLE_MOUSE   0xA8
 
#define kbd_write_command(cmd)   WRITE_PORT_UCHAR((PUCHAR)KBD_CNTL_REG,cmd)
 
#define kbd_write_data(cmd)   WRITE_PORT_UCHAR((PUCHAR)KBD_DATA_REG,cmd)
 
#define kbd_read_input()   READ_PORT_UCHAR((PUCHAR)KBD_DATA_REG)
 
#define kbd_read_status()   READ_PORT_UCHAR((PUCHAR)KBD_STATUS_REG)
 

Typedefs

typedef UCHAR byte_t
 

Functions

static VOID KbdSendCommandToMouse (UCHAR Command)
 
VOID KbdEnableMouse ()
 
VOID KbdDisableMouse ()
 
CHAR KdbpTryGetCharKeyboard (PULONG ScanCode, ULONG Retry)
 

Variables

static unsigned char keyb_layout [2][128]
 

Macro Definition Documentation

◆ CTRL_WRITE_MOUSE

#define CTRL_WRITE_MOUSE   0xD4

Definition at line 25 of file kdb_keyboard.c.

◆ KBD_CNTL_REG

#define KBD_CNTL_REG   0x64

Definition at line 19 of file kdb_keyboard.c.

◆ KBD_DATA_REG

#define KBD_DATA_REG   0x60

Definition at line 20 of file kdb_keyboard.c.

◆ KBD_DISABLE_MOUSE

#define KBD_DISABLE_MOUSE   0xA7

Definition at line 30 of file kdb_keyboard.c.

◆ KBD_ENABLE_MOUSE

#define KBD_ENABLE_MOUSE   0xA8

Definition at line 31 of file kdb_keyboard.c.

◆ kbd_read_input

#define kbd_read_input ( )    READ_PORT_UCHAR((PUCHAR)KBD_DATA_REG)

Definition at line 35 of file kdb_keyboard.c.

◆ kbd_read_status

#define kbd_read_status ( )    READ_PORT_UCHAR((PUCHAR)KBD_STATUS_REG)

Definition at line 36 of file kdb_keyboard.c.

◆ KBD_STAT_IBF

#define KBD_STAT_IBF   0x02

Definition at line 23 of file kdb_keyboard.c.

◆ KBD_STAT_OBF

#define KBD_STAT_OBF   0x01

Definition at line 22 of file kdb_keyboard.c.

◆ KBD_STATUS_REG

#define KBD_STATUS_REG   0x64

Definition at line 18 of file kdb_keyboard.c.

◆ kbd_write_command

#define kbd_write_command (   cmd)    WRITE_PORT_UCHAR((PUCHAR)KBD_CNTL_REG,cmd)

Definition at line 33 of file kdb_keyboard.c.

◆ kbd_write_data

#define kbd_write_data (   cmd)    WRITE_PORT_UCHAR((PUCHAR)KBD_DATA_REG,cmd)

Definition at line 34 of file kdb_keyboard.c.

◆ MOU_DISAB

#define MOU_DISAB   0xF5

Definition at line 27 of file kdb_keyboard.c.

◆ MOU_ENAB

#define MOU_ENAB   0xF4

Definition at line 26 of file kdb_keyboard.c.

◆ MOUSE_ACK

#define MOUSE_ACK   0xFA

Definition at line 28 of file kdb_keyboard.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file kdb_keyboard.c.

Typedef Documentation

◆ byte_t

typedef UCHAR byte_t

Definition at line 57 of file kdb_keyboard.c.

Function Documentation

◆ KbdDisableMouse()

VOID KbdDisableMouse ( )

Definition at line 98 of file kdb_keyboard.c.

99 {
101 }
static VOID KbdSendCommandToMouse(UCHAR Command)
Definition: kdb_keyboard.c:62
#define MOU_DISAB
Definition: kdb_keyboard.c:27

◆ KbdEnableMouse()

VOID KbdEnableMouse ( )

Definition at line 93 of file kdb_keyboard.c.

94 {
96 }
#define MOU_ENAB
Definition: kdb_keyboard.c:26
static VOID KbdSendCommandToMouse(UCHAR Command)
Definition: kdb_keyboard.c:62

◆ KbdSendCommandToMouse()

static VOID KbdSendCommandToMouse ( UCHAR  Command)
static

Definition at line 62 of file kdb_keyboard.c.

63 {
64  ULONG Retry = 20000;
65 
66  while (kbd_read_status() & KBD_STAT_OBF && Retry--)
67  {
70  }
71 
72  Retry = 20000;
73  while (kbd_read_status() & KBD_STAT_IBF && Retry--)
75 
77 
78  Retry = 20000;
79  while (kbd_read_status() & KBD_STAT_IBF && Retry--)
81 
83 
84  Retry = 20000;
85  while (!(kbd_read_status() & KBD_STAT_OBF) && Retry--)
87 
88  if (kbd_read_input() != MOUSE_ACK) { ; }
89 
90  return;
91 }
#define MOUSE_ACK
Definition: kdb_keyboard.c:28
Definition: shell.h:41
#define CTRL_WRITE_MOUSE
Definition: kdb_keyboard.c:25
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
#define KBD_STAT_OBF
Definition: kdb_keyboard.c:22
#define kbd_read_input()
Definition: kdb_keyboard.c:35
#define kbd_read_status()
Definition: kdb_keyboard.c:36
#define KBD_STAT_IBF
Definition: kdb_keyboard.c:23
#define kbd_write_command(cmd)
Definition: kdb_keyboard.c:33
#define kbd_write_data(cmd)
Definition: kdb_keyboard.c:34
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:96

Referenced by KbdDisableMouse(), and KbdEnableMouse().

◆ KdbpTryGetCharKeyboard()

CHAR KdbpTryGetCharKeyboard ( PULONG  ScanCode,
ULONG  Retry 
)

Definition at line 104 of file kdb_keyboard.c.

105 {
106  static byte_t last_key = 0;
107  static byte_t shift = 0;
108  char c;
109  BOOLEAN KeepRetrying = (Retry == 0);
110 
111  while (KeepRetrying || Retry-- > 0)
112  {
113  while (kbd_read_status() & KBD_STAT_OBF)
114  {
115  byte_t scancode;
116 
117  scancode = kbd_read_input();
118 
119  /* check for SHIFT-keys */
120  if (((scancode & 0x7F) == 42) || ((scancode & 0x7F) == 54))
121  {
122  shift = !(scancode & 0x80);
123  continue;
124  }
125 
126  /* ignore all other RELEASED-codes */
127  if (scancode & 0x80)
128  {
129  last_key = 0;
130  }
131  else if (last_key != scancode)
132  {
133  //printf("kbd: %d, %d, %c\n", scancode, last_key, keyb_layout[shift][scancode]);
134  last_key = scancode;
135  c = keyb_layout[shift][scancode];
136  *ScanCode = scancode;
137 
138  if (c > 0)
139  return c;
140  }
141  }
142  }
143 
144  return -1;
145 }
#define shift
Definition: input.c:1756
ULONG ScanCode
Definition: api.c:39
unsigned char BOOLEAN
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
static unsigned char keyb_layout[2][128]
Definition: kdb_keyboard.c:38
#define KBD_STAT_OBF
Definition: kdb_keyboard.c:22
#define kbd_read_input()
Definition: kdb_keyboard.c:35
const GLubyte * c
Definition: glext.h:8905
#define kbd_read_status()
Definition: kdb_keyboard.c:36
UCHAR byte_t
Definition: kdb_keyboard.c:57
#define c
Definition: ke_i.h:80

Referenced by KdbpCliMainLoop(), KdbpPager(), KdbpPrint(), KdbpReadCommand(), and KdReceivePacket().

Variable Documentation

◆ keyb_layout

unsigned char keyb_layout[2][128]
static
Initial value:
=
{
"\000\0331234567890-=\177\t"
"qwertyuiop[]\r\000as"
"dfghjkl;'`\000\\zxcv"
"bnm,./\000*\000 \000\201\202\203\204\205"
"\206\207\210\211\212\000\000789-456+1"
"230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000"
"\r\000/"
,
"\000\033!@#$%^&*()_+\177\t"
"QWERTYUIOP{}\r\000AS"
"DFGHJKL:\"`\000\\ZXCV"
"BNM<>?\000*\000 \000\201\202\203\204\205"
"\206\207\210\211\212\000\000789-456+1"
"230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000"
"\r\000/"
}

Definition at line 38 of file kdb_keyboard.c.

Referenced by KdbpTryGetCharKeyboard().