CloverBootloader/rEFIt_UEFI/PlatformEFI/BasicIO.cpp

103 lines
2.1 KiB
C++
Raw Normal View History

2020-03-28 16:14:18 +01:00
/*
* BasicIO.cpp
*
* Created on: 28 Mar 2020
*
*/
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include <Efi.h>
2020-03-28 16:14:18 +01:00
#include <stdio.h>
#include "../Platform/BasicIO.h"
2020-03-28 16:14:18 +01:00
//#include "EfiExternals.h"
extern "C" {
#include "Library/UefiBootServicesTableLib.h"
}
//
// Keyboard input
//
2020-10-03 19:02:31 +02:00
BOOLEAN ReadAllKeyStrokes(void)
2020-03-28 16:14:18 +01:00
{
BOOLEAN GotKeyStrokes;
EFI_STATUS Status;
EFI_INPUT_KEY key;
GotKeyStrokes = FALSE;
for (;;) {
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
if (Status == EFI_SUCCESS) {
GotKeyStrokes = TRUE;
continue;
}
break;
}
return GotKeyStrokes;
}
2020-10-03 19:02:31 +02:00
void PauseForKey(CONST CHAR16* msg)
2020-03-28 16:14:18 +01:00
{
UINTN index;
if (msg) {
printf("\n %ls", msg);
}
printf("\n* Hit any key to continue *");
if (ReadAllKeyStrokes()) { // remove buffered key strokes
gBS->Stall(5000000); // 5 seconds delay
ReadAllKeyStrokes(); // empty the buffer again
}
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
ReadAllKeyStrokes(); // empty the buffer to protect the menu
printf("\n");
}
// Jief, TODO : not sure of the difference between this and PauseForKey. Looks like none. Can it be removed ?
2020-10-03 19:02:31 +02:00
void
2020-03-28 16:14:18 +01:00
WaitForKeyPress(
CHAR16 *Message
)
{
EFI_STATUS Status;
UINTN index;
EFI_INPUT_KEY key;
printf("%ls", Message);
do {
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
} while(Status == EFI_SUCCESS);
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
do {
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
} while(Status == EFI_SUCCESS);
}
//#if REFIT_DEBUG > 0
2020-10-03 19:02:31 +02:00
//void DebugPause(void)
2020-03-28 16:14:18 +01:00
//{
// // show console and wait for key
// SwitchToText(FALSE);
// PauseForKey(L"");
//
// // reset error flag
// haveError = FALSE;
//}
//#endif
2020-10-03 19:02:31 +02:00
void EndlessIdleLoop(void)
2020-03-28 16:14:18 +01:00
{
UINTN index;
for (;;) {
ReadAllKeyStrokes();
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
}
}