ReactOS 0.4.16-dev-297-gc569aee
keyboard.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: subsystems/mvdm/ntvdm/hardware/keyboard.c
5 * PURPOSE: Keyboard emulation
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include "ntvdm.h"
12
13#define NDEBUG
14#include <debug.h>
15
16#include "keyboard.h"
17#include "ps2.h"
18
19/* PRIVATE VARIABLES **********************************************************/
20
22static BYTE KeyboardId = 0; // We only support basic old-type keyboard
24
25static BYTE KbdPS2Port = 0;
26
27/* PRIVATE FUNCTIONS **********************************************************/
28
30{
31 /* Check if we were waiting for a data byte */
33 {
35
36 switch (KbdDataByteWait)
37 {
38 /* Set/Reset Mode Indicators */
39 case 0xED:
40 {
41 // Ignore setting the keyboard LEDs
42 break;
43 }
44
45 /* PS/2 Select/Read Alternate Scan Code Sets */
46 case 0xF0:
47 /* Set Typematic Rate/Delay */
48 case 0xF3:
49 {
50 // FIXME: UNIMPLEMENTED; just return ACKnowledge.
51 // This unblocks some programs that want to initialize
52 // the keyboard by sending keyboard commands and then
53 // performing polling on the port until "valid" data
54 // comes out.
55 DPRINT1("KeyboardCommand(0x%02X) NOT IMPLEMENTED\n", KbdDataByteWait);
56 break;
57 }
58
59 default:
60 {
61 /* Shouldn't happen */
63 }
64 }
65
67 return;
68 }
69
70 switch (Command)
71 {
72 /* Set/Reset Mode Indicators */
73 case 0xED:
74 /* PS/2 Select/Read Alternate Scan Code Sets */
75 case 0xF0:
76 /* Set Typematic Rate/Delay */
77 case 0xF3:
78 {
81 break;
82 }
83
84 /* Echo test command */
85 case 0xEE:
86 {
88 break;
89 }
90
91 /* Get Keyboard ID */
92 case 0xF2:
93 {
96 break;
97 }
98
99 /* Enable Reporting */
100 case 0xF4:
101 {
104 break;
105 }
106
107 /* Disable Reporting */
108 case 0xF5:
109 {
112 break;
113 }
114
115 /* Set Defaults */
116 case 0xF6:
117 {
118 // So far, nothing to reset
120 break;
121 }
122
123 /* PS/2 Typematic & Make/Break key modes */
124 case 0xF7: case 0xF8: case 0xF9:
125 case 0xFA: case 0xFB: case 0xFC: case 0xFD:
126 {
127 /*
128 * Unsupported on PC-AT, they are just ignored
129 * and acknowledged as discussed in:
130 * http://stanislavs.org/helppc/keyboard_commands.html
131 */
133 }
134
135 /* Resend */
136 case 0xFE:
137 {
140 break;
141 }
142
143 /* Reset */
144 case 0xFF:
145 {
146 /* Send ACKnowledge */
148
149 // So far, nothing to reset
150
151 /* Send the Basic Assurance Test success code and the device ID */
154 break;
155 }
156
157 /* Unknown command */
158 default:
159 {
161 }
162 }
163}
164
165/* PUBLIC FUNCTIONS ***********************************************************/
166
168{
169 WORD i;
170 BYTE ScanCode = (BYTE)KeyEvent->wVirtualScanCode;
171
172 /* Check if we're not reporting */
173 if (!KeyboardReporting) return;
174
175 /* If this is a key release, set the highest bit in the scan code */
176 if (!KeyEvent->bKeyDown) ScanCode |= 0x80;
177
178 /* Push the scan code into the PS/2 queue */
179 for (i = 0; i < KeyEvent->wRepeatCount; i++)
180 {
183 }
184
185 DPRINT("Press 0x%X\n", ScanCode);
186}
187
189{
190 /* Finish to plug the keyboard to the specified PS/2 port */
191 KbdPS2Port = PS2Connector;
193 return TRUE;
194}
unsigned char BOOLEAN
UINT ScanCode
Definition: VirtualKey.c:24
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned short WORD
Definition: ntddk_ex.h:93
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
VOID PS2SetDeviceCmdProc(BYTE PS2Port, LPVOID Param, PS2_DEVICE_CMDPROC DeviceCommand)
Definition: ps2.c:478
BOOLEAN PS2QueuePush(BYTE PS2Port, BYTE Data)
Definition: ps2.c:486
#define DPRINT
Definition: sndvol32.h:73
Definition: shell.h:41
WORD wVirtualScanCode
Definition: wincon.h:243
DWORD dwControlKeyState
Definition: wincon.h:248
WORD wRepeatCount
Definition: wincon.h:241
static BYTE KeyboardId
Definition: keyboard.c:22
static BOOLEAN KeyboardReporting
Definition: keyboard.c:21
static VOID WINAPI KeyboardCommand(LPVOID Param, BYTE Command)
Definition: keyboard.c:29
VOID KeyboardEventHandler(PKEY_EVENT_RECORD KeyEvent)
Definition: keyboard.c:167
static BYTE KbdPS2Port
Definition: keyboard.c:25
static BYTE KbdDataByteWait
Definition: keyboard.c:23
BOOLEAN KeyboardInit(BYTE PS2Connector)
Definition: keyboard.c:188
#define KEYBOARD_ACK
Definition: keyboard.h:16
#define KEYBOARD_ERROR
Definition: keyboard.h:17
#define KEYBOARD_BAT_SUCCESS
Definition: keyboard.h:15
#define ENHANCED_KEY
Definition: wincon.h:145
#define WINAPI
Definition: msvc.h:6
unsigned char BYTE
Definition: xxhash.c:193