]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Console/ConsoleIn.c
Obsoleted by new schema and new build tools.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Console / ConsoleIn.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ConsoleIn.c
15
16 Abstract:
17
18 Console based on Win32 APIs.
19
20 This file attaches a SimpleTextIn protocol to a previously open window.
21
22 The constructor for this protocol depends on an open window. Currently
23 the SimpleTextOut protocol creates a window when it's constructor is called.
24 Thus this code must run after the constructor for the SimpleTextOut
25 protocol
26
27 --*/
28
29 #include "Console.h"
30
31 //
32 // Private worker functions
33 //
34 STATIC
35 EFI_STATUS
36 WinNtSimpleTextInCheckKey (
37 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private
38 );
39
40 EFI_STATUS
41 EFIAPI
42 WinNtSimpleTextInReset (
43 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
44 IN BOOLEAN ExtendedVerification
45 )
46 /*++
47
48 Routine Description:
49
50 TODO: Add function description
51
52 Arguments:
53
54 This - TODO: add argument description
55 ExtendedVerification - TODO: add argument description
56
57 Returns:
58
59 EFI_SUCCESS - TODO: Add description for return value
60
61 --*/
62 {
63 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
64
65 Private = WIN_NT_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
66 return EFI_SUCCESS;
67 }
68
69 STATIC
70 EFI_STATUS
71 WinNtConvertInputRecordToEfiKey (
72 IN INPUT_RECORD *InputRecord,
73 OUT EFI_INPUT_KEY *Key
74 )
75 /*++
76
77 Routine Description:
78
79 TODO: Add function description
80
81 Arguments:
82
83 InputRecord - TODO: add argument description
84 Key - TODO: add argument description
85
86 Returns:
87
88 EFI_NOT_READY - TODO: Add description for return value
89 EFI_NOT_READY - TODO: Add description for return value
90 EFI_NOT_READY - TODO: Add description for return value
91 EFI_SUCCESS - TODO: Add description for return value
92
93 --*/
94 {
95 //
96 // Make sure InputRecord is an event that represents a keypress
97 //
98 if (InputRecord->EventType == KEY_EVENT) {
99 if (!InputRecord->Event.KeyEvent.bKeyDown) {
100 return EFI_NOT_READY;
101 }
102 } else {
103 return EFI_NOT_READY;
104 }
105
106 //
107 // Check to see if we should return a scan code in place of Unicode character.
108 //
109 Key->ScanCode = 0;
110 Key->UnicodeChar = 0;
111 if ((InputRecord->Event.KeyEvent.dwControlKeyState & (NUMLOCK_ON | ENHANCED_KEY)) != NUMLOCK_ON) {
112 //
113 // Only check these scan codes if num lock is off.
114 //
115 switch (InputRecord->Event.KeyEvent.wVirtualScanCode) {
116 case 0x48: Key->ScanCode = SCAN_UP; break;
117 case 0x50: Key->ScanCode = SCAN_DOWN; break;
118 case 0x4d: Key->ScanCode = SCAN_RIGHT; break;
119 case 0x4b: Key->ScanCode = SCAN_LEFT; break;
120 case 0x47: Key->ScanCode = SCAN_HOME; break;
121 case 0x4F: Key->ScanCode = SCAN_END; break;
122 case 0x52: Key->ScanCode = SCAN_INSERT; break;
123 case 0x53: Key->ScanCode = SCAN_DELETE; break;
124 case 0x49: Key->ScanCode = SCAN_PAGE_UP; break;
125 case 0x51: Key->ScanCode = SCAN_PAGE_DOWN; break;
126 }
127 }
128
129 switch (InputRecord->Event.KeyEvent.wVirtualScanCode) {
130 case 0x3b: Key->ScanCode = SCAN_F1; break;
131 case 0x3c: Key->ScanCode = SCAN_F2; break;
132 case 0x3d: Key->ScanCode = SCAN_F3; break;
133 case 0x3e: Key->ScanCode = SCAN_F4; break;
134 case 0x3f: Key->ScanCode = SCAN_F5; break;
135 case 0x40: Key->ScanCode = SCAN_F6; break;
136 case 0x41: Key->ScanCode = SCAN_F7; break;
137 case 0x42: Key->ScanCode = SCAN_F8; break;
138 case 0x43: Key->ScanCode = SCAN_F9; break;
139 case 0x44: Key->ScanCode = SCAN_F10; break;
140 case 0x01: Key->ScanCode = SCAN_ESC; break;
141 }
142
143 //
144 // If there's a scan code pass it, and don't pass the char code
145 //
146 if (Key->ScanCode == 0) {
147 Key->UnicodeChar = InputRecord->Event.KeyEvent.uChar.UnicodeChar;
148 if (Key->UnicodeChar == 0) {
149 return EFI_NOT_READY;
150 }
151 }
152
153 return EFI_SUCCESS;
154 }
155
156 STATIC
157 EFI_STATUS
158 EFIAPI
159 WinNtSimpleTextInReadKeyStroke (
160 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
161 OUT EFI_INPUT_KEY *Key
162 )
163 /*++
164
165 Routine Description:
166
167 TODO: Add function description
168
169 Arguments:
170
171 This - TODO: add argument description
172 Key - TODO: add argument description
173
174 Returns:
175
176 EFI_DEVICE_ERROR - TODO: Add description for return value
177 EFI_NOT_READY - TODO: Add description for return value
178
179 --*/
180 {
181 EFI_STATUS Status;
182 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
183 INPUT_RECORD InputRecord;
184 DWORD NtEventCount;
185
186 Private = WIN_NT_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
187
188 Status = WinNtSimpleTextInCheckKey (Private);
189 if (EFI_ERROR (Status)) {
190 return Status;
191 }
192
193 do {
194
195 if (!Private->WinNtThunk->ReadConsoleInput (Private->NtInHandle, &InputRecord, 1, &NtEventCount)) {
196 return EFI_DEVICE_ERROR;
197 }
198
199 if (NtEventCount == 0) {
200 return EFI_NOT_READY;
201 }
202
203 //
204 // Convert the Input Record to an EFI Keystroke.
205 //
206 Status = WinNtConvertInputRecordToEfiKey (&InputRecord, Key);
207 } while (EFI_ERROR (Status));
208
209 return Status;
210 }
211
212 STATIC
213 VOID
214 EFIAPI
215 WinNtSimpleTextInWaitForKey (
216 IN EFI_EVENT Event,
217 IN VOID *Context
218 )
219 /*++
220
221 Routine Description:
222
223 TODO: Add function description
224
225 Arguments:
226
227 Event - TODO: add argument description
228 Context - TODO: add argument description
229
230 Returns:
231
232 TODO: add return values
233
234 --*/
235 {
236 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
237 EFI_STATUS Status;
238
239 Private = (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *) Context;
240 Status = WinNtSimpleTextInCheckKey (Private);
241 if (!EFI_ERROR (Status)) {
242 gBS->SignalEvent (Event);
243 }
244 }
245
246 STATIC
247 EFI_STATUS
248 WinNtSimpleTextInCheckKey (
249 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private
250 )
251 /*++
252
253 Routine Description:
254
255 TODO: Add function description
256
257 Arguments:
258
259 Private - TODO: add argument description
260
261 Returns:
262
263 TODO: add return values
264
265 --*/
266 {
267 INPUT_RECORD *InputRecord;
268 DWORD NtEventCount;
269 DWORD ActualNtEventCount;
270 EFI_STATUS Status;
271 BOOLEAN Success;
272 UINTN Index;
273 EFI_INPUT_KEY Key;
274
275 InputRecord = NULL;
276 NtEventCount = 0;
277 Private->WinNtThunk->GetNumberOfConsoleInputEvents (Private->NtInHandle, &NtEventCount);
278 if (NtEventCount == 0) {
279 Status = EFI_NOT_READY;
280 goto Done;
281 }
282
283 Status = gBS->AllocatePool (
284 EfiBootServicesData,
285 sizeof (INPUT_RECORD) * NtEventCount,
286 &InputRecord
287 );
288 if (EFI_ERROR (Status)) {
289 Status = EFI_NOT_READY;
290 goto Done;
291 }
292
293 Success = (BOOLEAN) Private->WinNtThunk->PeekConsoleInput (
294 Private->NtInHandle,
295 InputRecord,
296 NtEventCount,
297 &ActualNtEventCount
298 );
299 if (!Success) {
300 Status = EFI_NOT_READY;
301 goto Done;
302 }
303
304 Status = EFI_NOT_READY;
305 for (Index = 0; Index < (UINTN) ActualNtEventCount; Index++) {
306 //
307 // Convert the Input Record to an EFI Keystroke.
308 //
309 Status = WinNtConvertInputRecordToEfiKey (&InputRecord[Index], &Key);
310 if (!EFI_ERROR (Status)) {
311 Status = EFI_SUCCESS;
312 goto Done;
313 }
314 }
315
316 Done:
317 if (InputRecord != NULL) {
318 gBS->FreePool (InputRecord);
319 }
320
321 return Status;
322 }
323
324 EFI_STATUS
325 WinNtSimpleTextInAttachToWindow (
326 IN WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private
327 )
328 /*++
329
330 Routine Description:
331
332 TODO: Add function description
333
334 Arguments:
335
336 Private - TODO: add argument description
337
338 Returns:
339
340 TODO: add return values
341
342 --*/
343 {
344 EFI_STATUS Status;
345
346 Private->NtInHandle = Private->WinNtThunk->GetStdHandle (STD_INPUT_HANDLE);
347
348 Private->SimpleTextIn.Reset = WinNtSimpleTextInReset;
349 Private->SimpleTextIn.ReadKeyStroke = WinNtSimpleTextInReadKeyStroke;
350
351 Status = gBS->CreateEvent (
352 EFI_EVENT_NOTIFY_WAIT,
353 EFI_TPL_NOTIFY,
354 WinNtSimpleTextInWaitForKey,
355 Private,
356 &Private->SimpleTextIn.WaitForKey
357 );
358 ASSERT_EFI_ERROR (Status);
359
360 return Status;
361 }