]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Console/ConsoleOut.c
Initial import.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Console / ConsoleOut.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 ConsoleOut.c
15
16 Abstract:
17
18 Console based on Win32 APIs.
19
20 This file creates an Win32 window and attaches a SimpleTextOut protocol.
21
22 --*/
23
24 #include "Console.h"
25 //
26 // Private worker functions.
27 //
28
29 STATIC
30 VOID
31 WinNtSimpleTextOutScrollScreen (
32 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console
33 );
34
35 STATIC
36 VOID
37 WinNtSimpleTextOutPutChar (
38 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console,
39 IN CHAR16 Char
40 );
41
42 //
43 // Modeule Global for Simple Text Out Mode.
44 //
45 #define MAX_SIMPLE_TEXT_OUT_MODE \
46 (sizeof(mWinNtSimpleTextOutSupportedModes)/sizeof(WIN_NT_SIMPLE_TEXT_OUT_MODE))
47
48 STATIC WIN_NT_SIMPLE_TEXT_OUT_MODE mWinNtSimpleTextOutSupportedModes[] = {
49 { 80, 25 },
50 { 80, 50 },
51 { 80, 43 },
52 { 100, 100 },
53 { 100, 999 }
54 };
55
56 STATIC
57 EFI_STATUS
58 EFIAPI
59 WinNtSimpleTextOutReset (
60 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
61 IN BOOLEAN ExtendedVerification
62 )
63 /*++
64
65 Routine Description:
66
67 TODO: Add function description
68
69 Arguments:
70
71 This - TODO: add argument description
72 ExtendedVerification - TODO: add argument description
73
74 Returns:
75
76 EFI_SUCCESS - TODO: Add description for return value
77
78 --*/
79 {
80 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
81
82 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
83
84 WinNtSimpleTextOutSetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
85
86 WinNtSimpleTextOutSetMode (This, 0);
87 return EFI_SUCCESS;
88 }
89
90 STATIC
91 EFI_STATUS
92 EFIAPI
93 WinNtSimpleTextOutOutputString (
94 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
95 IN CHAR16 *String
96 )
97 /*++
98
99 Routine Description:
100
101 TODO: Add function description
102
103 Arguments:
104
105 This - TODO: add argument description
106 String - TODO: add argument description
107
108 Returns:
109
110 EFI_SUCCESS - TODO: Add description for return value
111
112 --*/
113 {
114 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
115 CHAR16 *Str;
116
117 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
118
119 for (Str = String; *Str != '\0'; Str++) {
120 switch (*Str) {
121 case '\n':
122 if (Private->Possition.Y == (Private->MaxScreenSize.Y - 1)) {
123 WinNtSimpleTextOutScrollScreen (Private);
124 }
125
126 if (Private->Possition.Y < (Private->MaxScreenSize.Y - 1)) {
127 Private->Possition.Y++;
128 This->Mode->CursorRow++;
129 }
130 break;
131
132 case '\r':
133 Private->Possition.X = 0;
134 This->Mode->CursorColumn = 0;
135 break;
136
137 case '\b':
138 if (Private->Possition.X > 0) {
139 Private->Possition.X--;
140 This->Mode->CursorColumn--;
141 }
142 break;
143
144 default:
145 WinNtSimpleTextOutPutChar (Private, *Str);
146 }
147 }
148
149 return EFI_SUCCESS;
150 }
151
152 STATIC
153 VOID
154 WinNtSimpleTextOutPutChar (
155 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console,
156 IN CHAR16 Char
157 )
158 /*++
159
160 Routine Description:
161
162 TODO: Add function description
163
164 Arguments:
165
166 Console - TODO: add argument description
167 Char - TODO: add argument description
168
169 Returns:
170
171 TODO: add return values
172
173 --*/
174 {
175 SMALL_RECT Region;
176 COORD StrCoordinate;
177 COORD StrSize;
178 CHAR_INFO CharInfo;
179 BOOL Flag;
180
181 CharInfo.Char.UnicodeChar = Char;
182 CharInfo.Attributes = Console->Attribute;
183
184 StrSize.X = 1;
185 StrSize.Y = 1;
186 StrCoordinate.X = 0;
187 StrCoordinate.Y = 0;
188
189 Region.Left = (INT16) Console->Possition.X;
190 Region.Top = (INT16) Console->Possition.Y;
191 Region.Right = (INT16) (Console->Possition.X + 1);
192 Region.Bottom = (INT16) Console->Possition.Y;
193
194 Console->WinNtThunk->WriteConsoleOutput (
195 Console->NtOutHandle,
196 &CharInfo,
197 StrSize,
198 StrCoordinate,
199 &Region
200 );
201
202 if (Console->Possition.X >= (Console->MaxScreenSize.X - 1)) {
203 //
204 // If you print off the end wrap around
205 //
206 Console->SimpleTextOut.OutputString (&Console->SimpleTextOut, L"\n\r");
207 } else {
208 Console->Possition.X++;
209 Console->SimpleTextOut.Mode->CursorColumn++;
210 }
211
212 Flag = Console->WinNtThunk->SetConsoleCursorPosition (Console->NtOutHandle, Console->Possition);
213 }
214
215 STATIC
216 VOID
217 WinNtSimpleTextOutScrollScreen (
218 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console
219 )
220 /*++
221
222 Routine Description:
223
224 TODO: Add function description
225
226 Arguments:
227
228 Console - TODO: add argument description
229
230 Returns:
231
232 TODO: add return values
233
234 --*/
235 {
236 SMALL_RECT Scroll;
237 CHAR_INFO CharInfo;
238 COORD Origin;
239
240 CharInfo.Char.UnicodeChar = ' ';
241 CharInfo.Attributes = Console->Attribute;
242
243 Origin.X = 0;
244 Origin.Y = 0;
245
246 Scroll.Top = 1;
247 Scroll.Left = 0;
248 Scroll.Right = (INT16) Console->MaxScreenSize.X;
249 Scroll.Bottom = (INT16) Console->MaxScreenSize.Y;
250
251 Console->WinNtThunk->ScrollConsoleScreenBuffer (
252 Console->NtOutHandle,
253 &Scroll,
254 NULL,
255 Origin,
256 &CharInfo
257 );
258 }
259
260 STATIC
261 EFI_STATUS
262 EFIAPI
263 WinNtSimpleTextOutTestString (
264 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
265 IN CHAR16 *String
266 )
267 /*++
268
269 Routine Description:
270
271 TODO: Add function description
272
273 Arguments:
274
275 This - TODO: add argument description
276 String - TODO: add argument description
277
278 Returns:
279
280 EFI_SUCCESS - TODO: Add description for return value
281
282 --*/
283 {
284 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
285
286 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
287
288 //
289 // BugBug: The correct answer would be a function of what code pages
290 // are currently loaded? For now we will just return success.
291 //
292 return EFI_SUCCESS;
293 }
294
295 STATIC
296 EFI_STATUS
297 EFIAPI
298 WinNtSimpleTextOutQueryMode (
299 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
300 IN UINTN ModeNumber,
301 OUT UINTN *Columns,
302 OUT UINTN *Rows
303 )
304 /*++
305
306 Routine Description:
307
308 TODO: Add function description
309
310 Arguments:
311
312 This - TODO: add argument description
313 ModeNumber - TODO: add argument description
314 Columns - TODO: add argument description
315 Rows - TODO: add argument description
316
317 Returns:
318
319 EFI_INVALID_PARAMETER - TODO: Add description for return value
320 EFI_SUCCESS - TODO: Add description for return value
321
322 --*/
323 {
324 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
325
326 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
327
328 if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
329 return EFI_INVALID_PARAMETER;
330 }
331
332 *Columns = mWinNtSimpleTextOutSupportedModes[ModeNumber].ColumnsX;
333 *Rows = mWinNtSimpleTextOutSupportedModes[ModeNumber].RowsY;
334
335 return EFI_SUCCESS;
336 }
337
338 STATIC
339 EFI_STATUS
340 EFIAPI
341 WinNtSimpleTextOutSetMode (
342 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
343 IN UINTN ModeNumber
344 )
345 /*++
346
347 Routine Description:
348
349 TODO: Add function description
350
351 Arguments:
352
353 This - TODO: add argument description
354 ModeNumber - TODO: add argument description
355
356 Returns:
357
358 EFI_INVALID_PARAMETER - TODO: Add description for return value
359 EFI_SUCCESS - TODO: Add description for return value
360
361 --*/
362 {
363 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
364
365 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
366
367 if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
368 return EFI_INVALID_PARAMETER;
369 }
370
371 Private->MaxScreenSize.X = (WORD) mWinNtSimpleTextOutSupportedModes[ModeNumber].ColumnsX;
372 Private->MaxScreenSize.Y = (WORD) mWinNtSimpleTextOutSupportedModes[ModeNumber].RowsY;
373
374 Private->WinNtThunk->SetConsoleScreenBufferSize (Private->NtOutHandle, Private->MaxScreenSize);
375 Private->WinNtThunk->SetConsoleActiveScreenBuffer (Private->NtOutHandle);
376
377 This->Mode->Mode = (INT32) ModeNumber;
378
379 This->EnableCursor (This, TRUE);
380 This->ClearScreen (This);
381 return EFI_SUCCESS;
382 }
383
384 STATIC
385 EFI_STATUS
386 EFIAPI
387 WinNtSimpleTextOutSetAttribute (
388 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
389 IN UINTN Attribute
390 )
391 /*++
392
393 Routine Description:
394
395 TODO: Add function description
396
397 Arguments:
398
399 This - TODO: add argument description
400 Attribute - TODO: add argument description
401
402 Returns:
403
404 EFI_SUCCESS - TODO: Add description for return value
405
406 --*/
407 {
408 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
409
410 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
411
412 Private->Attribute = (WORD) Attribute;
413 This->Mode->Attribute = (INT32) Attribute;
414
415 return EFI_SUCCESS;
416 }
417
418 STATIC
419 EFI_STATUS
420 EFIAPI
421 WinNtSimpleTextOutClearScreen (
422 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This
423 )
424 /*++
425
426 Routine Description:
427
428 TODO: Add function description
429
430 Arguments:
431
432 This - TODO: add argument description
433
434 Returns:
435
436 EFI_SUCCESS - TODO: Add description for return value
437
438 --*/
439 {
440 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
441 DWORD ConsoleWindow;
442
443 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
444
445 This->SetCursorPosition (This, 0, 0);
446
447 Private->WinNtThunk->FillConsoleOutputCharacter (
448 Private->NtOutHandle,
449 ' ',
450 Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
451 Private->Possition,
452 &ConsoleWindow
453 );
454 Private->WinNtThunk->FillConsoleOutputAttribute (
455 Private->NtOutHandle,
456 Private->Attribute,
457 Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
458 Private->Possition,
459 &ConsoleWindow
460 );
461
462 return EFI_SUCCESS;
463 }
464
465 STATIC
466 EFI_STATUS
467 EFIAPI
468 WinNtSimpleTextOutSetCursorPosition (
469 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
470 IN UINTN Column,
471 IN UINTN Row
472 )
473 /*++
474
475 Routine Description:
476
477 TODO: Add function description
478
479 Arguments:
480
481 This - TODO: add argument description
482 Column - TODO: add argument description
483 Row - TODO: add argument description
484
485 Returns:
486
487 EFI_SUCCESS - TODO: Add description for return value
488
489 --*/
490 {
491 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
492
493 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
494
495 Private->Possition.X = (WORD) Column;
496 This->Mode->CursorColumn = (INT32) Column;
497
498 Private->Possition.Y = (WORD) Row;
499 This->Mode->CursorRow = (INT32) Row;
500 Private->WinNtThunk->SetConsoleCursorPosition (Private->NtOutHandle, Private->Possition);
501
502 return EFI_SUCCESS;
503 }
504
505 STATIC
506 EFI_STATUS
507 EFIAPI
508 WinNtSimpleTextOutEnableCursor (
509 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
510 IN BOOLEAN Enable
511 )
512 /*++
513
514 Routine Description:
515
516 TODO: Add function description
517
518 Arguments:
519
520 This - TODO: add argument description
521 Enable - TODO: add argument description
522
523 Returns:
524
525 EFI_SUCCESS - TODO: Add description for return value
526
527 --*/
528 {
529 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
530 CONSOLE_CURSOR_INFO Info;
531
532 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
533 Private->CursorEnable = Enable;
534 This->Mode->CursorVisible = Enable;
535
536 Private->WinNtThunk->GetConsoleCursorInfo (Private->NtOutHandle, &Info);
537 Info.bVisible = Enable;
538 Private->WinNtThunk->SetConsoleCursorInfo (Private->NtOutHandle, &Info);
539
540 return EFI_SUCCESS;
541 }
542
543 EFI_STATUS
544 WinNtSimpleTextOutOpenWindow (
545 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private
546 )
547 /*++
548
549 Routine Description:
550
551 TODO: Add function description
552
553 Arguments:
554
555 Private - TODO: add argument description
556
557 Returns:
558
559 TODO: add return values
560
561 --*/
562 {
563 EFI_SIMPLE_TEXT_OUT_PROTOCOL *SimpleTextOut;
564 CHAR16 *WindowName;
565
566 WindowName = Private->WinNtIo->EnvString;
567 Private->Attribute = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
568 if (*WindowName == '?') {
569 Private->Attribute = BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
570 WindowName = L"EFI Emulator Error Console";
571 }
572
573 AddUnicodeString (
574 "eng",
575 gWinNtConsoleComponentName.SupportedLanguages,
576 &Private->ControllerNameTable,
577 WindowName
578 );
579
580 //
581 // Fill in protocol member functions
582 //
583 SimpleTextOut = &Private->SimpleTextOut;
584 SimpleTextOut->Reset = WinNtSimpleTextOutReset;
585 SimpleTextOut->OutputString = WinNtSimpleTextOutOutputString;
586 SimpleTextOut->TestString = WinNtSimpleTextOutTestString;
587 SimpleTextOut->QueryMode = WinNtSimpleTextOutQueryMode;
588 SimpleTextOut->SetMode = WinNtSimpleTextOutSetMode;
589 SimpleTextOut->SetAttribute = WinNtSimpleTextOutSetAttribute;
590 SimpleTextOut->ClearScreen = WinNtSimpleTextOutClearScreen;
591 SimpleTextOut->SetCursorPosition = WinNtSimpleTextOutSetCursorPosition;
592 SimpleTextOut->EnableCursor = WinNtSimpleTextOutEnableCursor;
593
594 //
595 // Initialize SimpleTextOut protocol mode structure
596 //
597 SimpleTextOut->Mode = &Private->SimpleTextOutMode;
598 SimpleTextOut->Mode->MaxMode = MAX_SIMPLE_TEXT_OUT_MODE;
599 SimpleTextOut->Mode->Attribute = (INT32) Private->Attribute;
600
601 //
602 // Open the window an initialize it!
603 //
604 Private->NtOutHandle = Private->WinNtThunk->CreateConsoleScreenBuffer (
605 GENERIC_WRITE | GENERIC_READ,
606 FILE_SHARE_WRITE | FILE_SHARE_READ,
607 NULL,
608 CONSOLE_TEXTMODE_BUFFER,
609 NULL
610 );
611 Private->WinNtThunk->SetConsoleTitle (WindowName);
612
613 return SimpleTextOut->SetMode (SimpleTextOut, 0);
614 }
615
616 EFI_STATUS
617 WinNtSimpleTextOutCloseWindow (
618 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console
619 )
620 /*++
621
622 Routine Description:
623
624 TODO: Add function description
625
626 Arguments:
627
628 Console - TODO: add argument description
629
630 Returns:
631
632 EFI_SUCCESS - TODO: Add description for return value
633
634 --*/
635 {
636 Console->WinNtThunk->CloseHandle (Console->NtOutHandle);
637 return EFI_SUCCESS;
638 }