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
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.
18 Console based on Win32 APIs.
20 This file creates an Win32 window and attaches a SimpleTextOut protocol.
25 // The package level header files this module uses
30 // The protocols, PPI and GUID defintions for this module
32 #include <Protocol/SimpleTextIn.h>
33 #include <Protocol/WinNtIo.h>
34 #include <Protocol/SimpleTextOut.h>
35 #include <Protocol/ComponentName.h>
36 #include <Protocol/DriverBinding.h>
38 // The Library classes this module consumes
40 #include <Library/DebugLib.h>
41 #include <Library/BaseLib.h>
42 #include <Library/UefiDriverEntryPoint.h>
43 #include <Library/UefiLib.h>
44 #include <Library/BaseMemoryLib.h>
45 #include <Library/UefiBootServicesTableLib.h>
46 #include <Library/MemoryAllocationLib.h>
51 // Private worker functions.
56 WinNtSimpleTextOutScrollScreen (
57 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Console
62 WinNtSimpleTextOutPutChar (
63 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Console
,
68 // Modeule Global for Simple Text Out Mode.
70 #define MAX_SIMPLE_TEXT_OUT_MODE \
71 (sizeof(mWinNtSimpleTextOutSupportedModes)/sizeof(WIN_NT_SIMPLE_TEXT_OUT_MODE))
73 STATIC WIN_NT_SIMPLE_TEXT_OUT_MODE mWinNtSimpleTextOutSupportedModes
[] = {
84 WinNtSimpleTextOutReset (
85 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
86 IN BOOLEAN ExtendedVerification
92 TODO: Add function description
96 This - TODO: add argument description
97 ExtendedVerification - TODO: add argument description
101 EFI_SUCCESS - TODO: Add description for return value
105 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
107 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
109 WinNtSimpleTextOutSetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
111 WinNtSimpleTextOutSetMode (This
, 0);
118 WinNtSimpleTextOutOutputString (
119 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
126 TODO: Add function description
130 This - TODO: add argument description
131 String - TODO: add argument description
135 EFI_SUCCESS - TODO: Add description for return value
139 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
142 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
144 for (Str
= String
; *Str
!= '\0'; Str
++) {
147 if (Private
->Possition
.Y
== (Private
->MaxScreenSize
.Y
- 1)) {
148 WinNtSimpleTextOutScrollScreen (Private
);
151 if (Private
->Possition
.Y
< (Private
->MaxScreenSize
.Y
- 1)) {
152 Private
->Possition
.Y
++;
153 This
->Mode
->CursorRow
++;
158 Private
->Possition
.X
= 0;
159 This
->Mode
->CursorColumn
= 0;
163 if (Private
->Possition
.X
> 0) {
164 Private
->Possition
.X
--;
165 This
->Mode
->CursorColumn
--;
170 WinNtSimpleTextOutPutChar (Private
, *Str
);
179 WinNtSimpleTextOutPutChar (
180 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Console
,
187 TODO: Add function description
191 Console - TODO: add argument description
192 Char - TODO: add argument description
196 TODO: add return values
206 CharInfo
.Char
.UnicodeChar
= Char
;
207 CharInfo
.Attributes
= Console
->Attribute
;
214 Region
.Left
= (INT16
) Console
->Possition
.X
;
215 Region
.Top
= (INT16
) Console
->Possition
.Y
;
216 Region
.Right
= (INT16
) (Console
->Possition
.X
+ 1);
217 Region
.Bottom
= (INT16
) Console
->Possition
.Y
;
219 Console
->WinNtThunk
->WriteConsoleOutput (
220 Console
->NtOutHandle
,
227 if (Console
->Possition
.X
>= (Console
->MaxScreenSize
.X
- 1)) {
229 // If you print off the end wrap around
231 Console
->SimpleTextOut
.OutputString (&Console
->SimpleTextOut
, L
"\n\r");
233 Console
->Possition
.X
++;
234 Console
->SimpleTextOut
.Mode
->CursorColumn
++;
237 Flag
= Console
->WinNtThunk
->SetConsoleCursorPosition (Console
->NtOutHandle
, Console
->Possition
);
242 WinNtSimpleTextOutScrollScreen (
243 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Console
249 TODO: Add function description
253 Console - TODO: add argument description
257 TODO: add return values
265 CharInfo
.Char
.UnicodeChar
= ' ';
266 CharInfo
.Attributes
= Console
->Attribute
;
273 Scroll
.Right
= (INT16
) Console
->MaxScreenSize
.X
;
274 Scroll
.Bottom
= (INT16
) Console
->MaxScreenSize
.Y
;
276 Console
->WinNtThunk
->ScrollConsoleScreenBuffer (
277 Console
->NtOutHandle
,
288 WinNtSimpleTextOutTestString (
289 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
296 TODO: Add function description
300 This - TODO: add argument description
301 String - TODO: add argument description
305 EFI_SUCCESS - TODO: Add description for return value
309 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
311 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
314 // BugBug: The correct answer would be a function of what code pages
315 // are currently loaded? For now we will just return success.
323 WinNtSimpleTextOutQueryMode (
324 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
333 TODO: Add function description
337 This - TODO: add argument description
338 ModeNumber - TODO: add argument description
339 Columns - TODO: add argument description
340 Rows - TODO: add argument description
344 EFI_INVALID_PARAMETER - TODO: Add description for return value
345 EFI_SUCCESS - TODO: Add description for return value
349 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
351 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
353 if (ModeNumber
> MAX_SIMPLE_TEXT_OUT_MODE
) {
354 return EFI_INVALID_PARAMETER
;
357 *Columns
= mWinNtSimpleTextOutSupportedModes
[ModeNumber
].ColumnsX
;
358 *Rows
= mWinNtSimpleTextOutSupportedModes
[ModeNumber
].RowsY
;
366 WinNtSimpleTextOutSetMode (
367 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
374 TODO: Add function description
378 This - TODO: add argument description
379 ModeNumber - TODO: add argument description
383 EFI_INVALID_PARAMETER - TODO: Add description for return value
384 EFI_SUCCESS - TODO: Add description for return value
388 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
390 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
392 if (ModeNumber
> MAX_SIMPLE_TEXT_OUT_MODE
) {
393 return EFI_INVALID_PARAMETER
;
396 Private
->MaxScreenSize
.X
= (WORD
) mWinNtSimpleTextOutSupportedModes
[ModeNumber
].ColumnsX
;
397 Private
->MaxScreenSize
.Y
= (WORD
) mWinNtSimpleTextOutSupportedModes
[ModeNumber
].RowsY
;
399 Private
->WinNtThunk
->SetConsoleScreenBufferSize (Private
->NtOutHandle
, Private
->MaxScreenSize
);
400 Private
->WinNtThunk
->SetConsoleActiveScreenBuffer (Private
->NtOutHandle
);
402 This
->Mode
->Mode
= (INT32
) ModeNumber
;
404 This
->EnableCursor (This
, TRUE
);
405 This
->ClearScreen (This
);
412 WinNtSimpleTextOutSetAttribute (
413 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
420 TODO: Add function description
424 This - TODO: add argument description
425 Attribute - TODO: add argument description
429 EFI_SUCCESS - TODO: Add description for return value
433 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
435 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
437 Private
->Attribute
= (WORD
) Attribute
;
438 This
->Mode
->Attribute
= (INT32
) Attribute
;
446 WinNtSimpleTextOutClearScreen (
447 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
453 TODO: Add function description
457 This - TODO: add argument description
461 EFI_SUCCESS - TODO: Add description for return value
465 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
468 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
470 This
->SetCursorPosition (This
, 0, 0);
472 Private
->WinNtThunk
->FillConsoleOutputCharacter (
473 Private
->NtOutHandle
,
475 Private
->MaxScreenSize
.X
* Private
->MaxScreenSize
.Y
,
479 Private
->WinNtThunk
->FillConsoleOutputAttribute (
480 Private
->NtOutHandle
,
482 Private
->MaxScreenSize
.X
* Private
->MaxScreenSize
.Y
,
493 WinNtSimpleTextOutSetCursorPosition (
494 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
502 TODO: Add function description
506 This - TODO: add argument description
507 Column - TODO: add argument description
508 Row - TODO: add argument description
512 EFI_SUCCESS - TODO: Add description for return value
516 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
518 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
520 Private
->Possition
.X
= (WORD
) Column
;
521 This
->Mode
->CursorColumn
= (INT32
) Column
;
523 Private
->Possition
.Y
= (WORD
) Row
;
524 This
->Mode
->CursorRow
= (INT32
) Row
;
525 Private
->WinNtThunk
->SetConsoleCursorPosition (Private
->NtOutHandle
, Private
->Possition
);
533 WinNtSimpleTextOutEnableCursor (
534 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
541 TODO: Add function description
545 This - TODO: add argument description
546 Enable - TODO: add argument description
550 EFI_SUCCESS - TODO: Add description for return value
554 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
555 CONSOLE_CURSOR_INFO Info
;
557 Private
= WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This
);
558 Private
->CursorEnable
= Enable
;
559 This
->Mode
->CursorVisible
= Enable
;
561 Private
->WinNtThunk
->GetConsoleCursorInfo (Private
->NtOutHandle
, &Info
);
562 Info
.bVisible
= Enable
;
563 Private
->WinNtThunk
->SetConsoleCursorInfo (Private
->NtOutHandle
, &Info
);
569 WinNtSimpleTextOutOpenWindow (
570 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
576 TODO: Add function description
580 Private - TODO: add argument description
584 TODO: add return values
588 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
591 WindowName
= Private
->WinNtIo
->EnvString
;
592 Private
->Attribute
= FOREGROUND_RED
| FOREGROUND_BLUE
| FOREGROUND_GREEN
| FOREGROUND_INTENSITY
;
593 if (*WindowName
== '?') {
594 Private
->Attribute
= BACKGROUND_RED
| FOREGROUND_INTENSITY
| FOREGROUND_RED
| FOREGROUND_BLUE
| FOREGROUND_GREEN
;
595 WindowName
= L
"EFI Emulator Error Console";
600 gWinNtConsoleComponentName
.SupportedLanguages
,
601 &Private
->ControllerNameTable
,
606 // Fill in protocol member functions
608 SimpleTextOut
= &Private
->SimpleTextOut
;
609 SimpleTextOut
->Reset
= WinNtSimpleTextOutReset
;
610 SimpleTextOut
->OutputString
= WinNtSimpleTextOutOutputString
;
611 SimpleTextOut
->TestString
= WinNtSimpleTextOutTestString
;
612 SimpleTextOut
->QueryMode
= WinNtSimpleTextOutQueryMode
;
613 SimpleTextOut
->SetMode
= WinNtSimpleTextOutSetMode
;
614 SimpleTextOut
->SetAttribute
= WinNtSimpleTextOutSetAttribute
;
615 SimpleTextOut
->ClearScreen
= WinNtSimpleTextOutClearScreen
;
616 SimpleTextOut
->SetCursorPosition
= WinNtSimpleTextOutSetCursorPosition
;
617 SimpleTextOut
->EnableCursor
= WinNtSimpleTextOutEnableCursor
;
620 // Initialize SimpleTextOut protocol mode structure
622 SimpleTextOut
->Mode
= &Private
->SimpleTextOutMode
;
623 SimpleTextOut
->Mode
->MaxMode
= MAX_SIMPLE_TEXT_OUT_MODE
;
624 SimpleTextOut
->Mode
->Attribute
= (INT32
) Private
->Attribute
;
627 // Open the window an initialize it!
629 Private
->NtOutHandle
= Private
->WinNtThunk
->CreateConsoleScreenBuffer (
630 GENERIC_WRITE
| GENERIC_READ
,
631 FILE_SHARE_WRITE
| FILE_SHARE_READ
,
633 CONSOLE_TEXTMODE_BUFFER
,
636 Private
->WinNtThunk
->SetConsoleTitle (WindowName
);
638 return SimpleTextOut
->SetMode (SimpleTextOut
, 0);
642 WinNtSimpleTextOutCloseWindow (
643 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Console
649 TODO: Add function description
653 Console - TODO: add argument description
657 EFI_SUCCESS - TODO: Add description for return value
661 Console
->WinNtThunk
->CloseHandle (Console
->NtOutHandle
);