Skip to content

Commit 5ff6a43

Browse files
committed
Improve console output
* Preserve the existing console mode while still fixing the console output of broken platforms (such as the HP DeskPro 600, when connected to a 4k DP display).
1 parent a4ceffb commit 5ff6a43

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/console.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012 James Bottomley <James.Bottomley@HansenPartnership.com>
3-
* Copyright 2024-2025 Pete Batard <pete@akeo.ie>
3+
* Copyright 2024-2026 Pete Batard <pete@akeo.ie>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -96,7 +96,7 @@ EFI_STATUS ConsolePrintBoxAt(
9696
{
9797
INTN i;
9898
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console = gST->ConOut;
99-
UINTN Rows, Cols;
99+
UINTN Cols, Rows;
100100
CHAR16 *Line;
101101

102102
if (Lines == 0)
@@ -371,13 +371,17 @@ VOID ConsoleError(
371371
ConsoleAlertBox(ErrArray);
372372
}
373373

374-
VOID ConsoleReset(VOID)
374+
VOID ConsoleInit(VOID)
375375
{
376+
UINTN Cols, Rows;
376377
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console = gST->ConOut;
377378

378-
Console->Reset(Console, TRUE);
379-
// Set mode 0 - required to be 80x25
380-
Console->SetMode(Console, 0);
379+
// Some broken firmware implementations (<cough>HP ProDesk 600 G1<cough>) have a default
380+
// console where mode 0 overshoots the screen (on a 4k monitor) until SetMode is called.
381+
// So we call SetMode with the current mode to fix that. Also, you do *NOT* want to call
382+
// Console->Reset() as it may switch from a default high res mode to low res mode 0...
383+
Console->QueryMode(Console, Console->Mode->Mode, &Cols, &Rows);
384+
Console->SetMode(Console, Console->Mode->Mode);
381385
Console->ClearScreen(Console);
382386
}
383387

@@ -515,8 +519,9 @@ UINTN EFIAPI RecallPrint(
515519
VOID RecallPrintRestore(VOID)
516520
{
517521
UINTN i;
522+
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console = gST->ConOut;
518523

519-
ConsoleReset();
524+
Console->ClearScreen(Console);
520525
for (i = 0; i < CurrentLine; i++)
521526
Print(L"%s", PrintLine[i]);
522527
}

src/console.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2012 James Bottomley <James.Bottomley@HansenPartnership.com>
3-
* Copyright 2024-2025 Pete Batard <pete@akeo.ie>
3+
* Copyright 2024-2026 Pete Batard <pete@akeo.ie>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -78,7 +78,7 @@ VOID ConsoleError(
7878
IN CONST EFI_STATUS Status
7979
);
8080

81-
VOID ConsoleReset(VOID);
81+
VOID ConsoleInit(VOID);
8282

8383
UINTN EFIAPI Logger(
8484
IN CONST CHAR16 *FormatString,

src/mosby.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ EFI_STATUS EFIAPI efi_main(
315315
}
316316
}
317317

318-
/* Initialize the file logger */
318+
/* Initialize the console and the file logger */
319+
ConsoleInit();
319320
if (LogToFile)
320321
OpenLogger(gBaseImageHandle, L"Mosby.log");
321322
RecallPrint(L"Mosby %a %s\n", VERSION_STRING, ARCH_EXT);

0 commit comments

Comments
 (0)