https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e5053944664f1e74d407f…
commit e5053944664f1e74d407fdf77d4ee2d7f8d23205
Author: Justin Miller <justin.miller(a)reactos.org>
AuthorDate: Tue Jul 11 11:07:31 2023 -0700
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Jul 11 11:07:31 2023 -0700
[FREELDR] Add UEFI Console input support. CORE-11954 (#5426)
Co-authored-by: Stanislav Motylkov <x86corez(a)gmail.com>
---
boot/freeldr/freeldr/arch/uefi/stubs.c | 12 -----
boot/freeldr/freeldr/arch/uefi/ueficon.c | 82 ++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 12 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/uefi/stubs.c
b/boot/freeldr/freeldr/arch/uefi/stubs.c
index 48b436bd68d..ac5cebab51c 100644
--- a/boot/freeldr/freeldr/arch/uefi/stubs.c
+++ b/boot/freeldr/freeldr/arch/uefi/stubs.c
@@ -55,18 +55,6 @@ UefiPcBeep(VOID)
/* Not possible on UEFI, for now */
}
-BOOLEAN
-UefiConsKbHit(VOID)
-{
- return FALSE;
-}
-
-int
-UefiConsGetCh(void)
-{
- return 0;
-}
-
VOID
UefiHwIdle(VOID)
{
diff --git a/boot/freeldr/freeldr/arch/uefi/ueficon.c
b/boot/freeldr/freeldr/arch/uefi/ueficon.c
index 944d9707bc7..000b6b9d3a7 100644
--- a/boot/freeldr/freeldr/arch/uefi/ueficon.c
+++ b/boot/freeldr/freeldr/arch/uefi/ueficon.c
@@ -16,6 +16,9 @@ extern EFI_SYSTEM_TABLE* GlobalSystemTable;
static unsigned CurrentCursorX = 0;
static unsigned CurrentCursorY = 0;
static unsigned CurrentAttr = 0x0f;
+static EFI_INPUT_KEY Key;
+static BOOLEAN ExtendedKey = FALSE;
+static char ExtendedScanCode = 0;
/* FUNCTIONS ******************************************************************/
@@ -59,3 +62,82 @@ UefiConsPutChar(int c)
CurrentCursorY++;
}
}
+
+static
+UCHAR
+ConvertToBiosExtValue(UCHAR KeyIn)
+{
+ switch (KeyIn)
+ {
+ case SCAN_UP:
+ return KEY_UP;
+ case SCAN_DOWN:
+ return KEY_DOWN;
+ case SCAN_RIGHT:
+ return KEY_RIGHT;
+ case SCAN_LEFT:
+ return KEY_LEFT;
+ case SCAN_F1:
+ return KEY_F1;
+ case SCAN_F2:
+ return KEY_F2;
+ case SCAN_F3:
+ return KEY_F3;
+ case SCAN_F4:
+ return KEY_F4;
+ case SCAN_F5:
+ return KEY_F5;
+ case SCAN_F6:
+ return KEY_F6;
+ case SCAN_F7:
+ return KEY_F7;
+ case SCAN_F8:
+ return KEY_F8;
+ case SCAN_F9:
+ return KEY_F9;
+ case SCAN_F10:
+ return KEY_F10;
+ case SCAN_ESC:
+ return KEY_ESC;
+ case SCAN_DELETE:
+ return KEY_DELETE;
+ }
+ return 0;
+}
+
+BOOLEAN
+UefiConsKbHit(VOID)
+{
+ return (GlobalSystemTable->ConIn->ReadKeyStroke(GlobalSystemTable->ConIn,
&Key) != EFI_NOT_READY);
+}
+
+int
+UefiConsGetCh(VOID)
+{
+ UCHAR KeyOutput = 0;
+
+ /* If an extended key press was detected the last time we were called
+ * then return the scan code of that key. */
+ if (ExtendedKey)
+ {
+ ExtendedKey = FALSE;
+ return ExtendedScanCode;
+ }
+
+ if (Key.UnicodeChar != 0)
+ {
+ KeyOutput = Key.UnicodeChar;
+ }
+ else
+ {
+ ExtendedKey = TRUE;
+ ExtendedScanCode = ConvertToBiosExtValue(Key.ScanCode);
+ KeyOutput = KEY_EXTENDED;
+ }
+
+ /* UEFI will stack input requests, we have to clear it */
+ Key.UnicodeChar = 0;
+ Key.ScanCode = 0;
+ GlobalSystemTable->ConIn->Reset(GlobalSystemTable->ConIn, FALSE);
+ return KeyOutput;
+}