[BOOTLIB] Remove stray semicolon from a condition in ConsoleCreateLocalInputConsole...
[reactos.git] / reactos / boot / environ / lib / io / display / textcons.c
1 /*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/io/display/textcons.c
5 * PURPOSE: Boot Library Text Console Routines
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12
13 /* DATA VARIABLES ************************************************************/
14
15 BL_TEXT_CONSOLE_VTABLE ConsoleTextLocalVtbl =
16 {
17 ConsoleTextLocalDestruct,
18 ConsoleTextLocalReinitialize,
19 ConsoleTextBaseGetTextState,
20 ConsoleTextLocalSetTextState,
21 ConsoleTextBaseGetTextResolution,
22 ConsoleTextLocalSetTextResolution,
23 ConsoleTextLocalClearText,
24 ConsoleTextLocalWriteText
25 };
26
27 /* FUNCTIONS *****************************************************************/
28
29 VOID
30 ConsoleTextLocalDestruct (
31 _In_ struct _BL_TEXT_CONSOLE* Console
32 )
33 {
34
35 }
36
37 NTSTATUS
38 ConsoleTextLocalReinitialize (
39 _In_ struct _BL_TEXT_CONSOLE* Console
40 )
41 {
42 EfiPrintf(L"Not active yet!\r\n");
43 return STATUS_NOT_IMPLEMENTED;
44 }
45
46 NTSTATUS
47 ConsoleTextBaseGetTextState (
48 _In_ struct _BL_TEXT_CONSOLE* Console,
49 _Out_ PBL_DISPLAY_STATE TextState
50 )
51 {
52 return STATUS_NOT_IMPLEMENTED;
53 }
54
55 NTSTATUS
56 ConsoleTextLocalSetTextState (
57 _In_ struct _BL_TEXT_CONSOLE* Console,
58 _In_ ULONG Mask,
59 _In_ PBL_DISPLAY_STATE TextState
60 )
61 {
62 return ConsoleFirmwareTextSetState(Console, Mask, TextState);
63 }
64
65 NTSTATUS
66 ConsoleTextBaseGetTextResolution (
67 _In_ struct _BL_TEXT_CONSOLE* Console,
68 _Out_ PULONG TextResolution
69 )
70 {
71 return STATUS_NOT_IMPLEMENTED;
72 }
73
74 NTSTATUS
75 ConsoleTextLocalSetTextResolution (
76 _In_ struct _BL_TEXT_CONSOLE* Console,
77 _In_ ULONG NewTextResolution,
78 _Out_ PULONG OldTextResolution
79 )
80 {
81 return STATUS_NOT_IMPLEMENTED;
82 }
83
84 NTSTATUS
85 ConsoleTextLocalClearText (
86 _In_ struct _BL_TEXT_CONSOLE* Console,
87 _In_ BOOLEAN LineOnly
88 )
89 {
90 return ConsoleFirmwareTextClear(Console, LineOnly);
91 }
92
93 NTSTATUS
94 ConsoleTextLocalWriteText (
95 _In_ struct _BL_TEXT_CONSOLE* Console,
96 _In_ PCHAR Text,
97 _In_ ULONG Attribute
98 )
99 {
100 return STATUS_NOT_IMPLEMENTED;
101 }
102
103 NTSTATUS
104 ConsoleTextLocalConstruct (
105 _In_ PBL_TEXT_CONSOLE TextConsole,
106 _In_ BOOLEAN Activate
107 )
108 {
109 NTSTATUS Status;
110 BL_DISPLAY_STATE TextState;
111
112 /* Set our callbacks */
113 TextConsole->Callbacks = &ConsoleTextLocalVtbl;
114
115 /* Are we activating this console? */
116 if (Activate)
117 {
118 /* Call firmware to activate it */
119 Status = ConsoleFirmwareTextOpen(TextConsole);
120 if (!NT_SUCCESS(Status))
121 {
122 EfiPrintf(L"Failed to activate console: %lx\r\n", Status);
123 return Status;
124 }
125 }
126
127 /* Set default text state */
128 TextState.BgColor = 0;
129 TextState.XPos = 0;
130 TextState.YPos = 0;
131 TextState.CursorVisible = FALSE;
132 TextState.FgColor = White;
133
134 /* Are we activating? */
135 if (Activate)
136 {
137 /* Call firmware to set it */
138 Status = ConsoleFirmwareTextSetState(TextConsole, 0xF, &TextState);
139 if (!NT_SUCCESS(Status))
140 {
141 /* We failed, back down */
142 EfiPrintf(L"Failed to set console state: %lx\r\n", Status);
143 ConsoleFirmwareTextClose(TextConsole);
144 return Status;
145 }
146 }
147 else
148 {
149 /* Just save the state for now, someone else can activate later */
150 TextConsole->State = TextState;
151 }
152
153 /* Remember if we activated it */
154 TextConsole->Active = Activate;
155 return STATUS_SUCCESS;
156 }
157
158 BOOLEAN
159 ConsolepFindResolution (
160 _In_ PBL_DISPLAY_MODE Mode,
161 _In_ PBL_DISPLAY_MODE List,
162 _In_ ULONG MaxIndex
163 )
164 {
165 PBL_DISPLAY_MODE ListEnd;
166
167 /* Loop until we hit the maximum supported list index */
168 ListEnd = &List[MaxIndex];
169 while (List != ListEnd)
170 {
171 /* Does this resolution match? */
172 if ((Mode->HRes == List->HRes) && (Mode->VRes == List->VRes))
173 {
174 /* Yep -- we got a match */
175 return TRUE;
176
177 }
178
179 /* Try another one*/
180 List++;
181 }
182
183 /* No matches were found */
184 return FALSE;
185 }
186
187 BL_INPUT_CONSOLE_VTABLE ConsoleInputLocalVtbl =
188 {
189 (PCONSOLE_DESTRUCT)ConsoleInputLocalDestruct,
190 (PCONSOLE_REINITIALIZE)ConsoleInputBaseReinitialize,
191 };
192
193 VOID
194 ConsoleInputLocalDestruct (
195 _In_ PBL_INPUT_CONSOLE Console
196 )
197 {
198 /* Erase the current input buffer, and tear down the console */
199 ConsoleInputLocalEraseBuffer(Console, NULL);
200 BlMmFreeHeap(Console->Buffer);
201 }
202
203 NTSTATUS
204 ConsoleInputBaseConstruct (
205 _In_ PBL_INPUT_CONSOLE Console
206 )
207 {
208 PULONG Buffer;
209
210 /* Allocate a new 512 byte buffer */
211 Buffer = BlMmAllocateHeap(512);
212 Console->Buffer = Buffer;
213 if (!Buffer)
214 {
215 return STATUS_INSUFFICIENT_RESOURCES;
216 }
217
218 /* Set the current buffer pointers to it */
219 Console->DataStart = Buffer;
220 Console->DataEnd = Buffer;
221
222 /* Set the end 128 data entries into the buffer */
223 Console->EndBuffer = Buffer + 128;
224 return STATUS_SUCCESS;
225 }
226
227 NTSTATUS
228 ConsoleInputBaseReinitialize (
229 _In_ PBL_INPUT_CONSOLE Console
230 )
231 {
232 PULONG Buffer;
233
234 /* Reset all the buffer pointers to the current buffer */
235 Buffer = Console->Buffer;
236 Console->DataStart = Buffer;
237 Console->DataEnd = Buffer;
238 Console->EndBuffer = Buffer + 128;
239 return STATUS_SUCCESS;
240 }
241
242 NTSTATUS
243 ConsoleCreateLocalInputConsole (
244 VOID
245 )
246 {
247 PBL_INPUT_CONSOLE InputConsole;
248 NTSTATUS Status;
249
250 /* Allocate the input console */
251 InputConsole = BlMmAllocateHeap(sizeof(*InputConsole));
252 if (!InputConsole)
253 {
254 return STATUS_INSUFFICIENT_RESOURCES;
255 }
256
257 /* Construct it */
258 Status = ConsoleInputBaseConstruct(InputConsole);
259 if (!NT_SUCCESS(Status))
260 {
261 /* Tear down on failure */
262 BlMmFreeHeap(InputConsole);
263 return Status;
264 }
265
266 /* Set the callback table, and set us as the local input console */
267 InputConsole->Callbacks = &ConsoleInputLocalVtbl;
268 DspLocalInputConsole = InputConsole;
269 return STATUS_SUCCESS;
270 }