2020-03-28 16:14:18 +01:00
|
|
|
/*
|
|
|
|
* BasicIO.cpp
|
|
|
|
*
|
|
|
|
* Created on: 28 Mar 2020
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-02-06 18:16:46 +01:00
|
|
|
#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>
|
2021-04-03 12:55:25 +02:00
|
|
|
#include "../Platform/BasicIO.h"
|
2020-03-28 16:14:18 +01:00
|
|
|
//#include "EfiExternals.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "Library/UefiBootServicesTableLib.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Keyboard input
|
|
|
|
//
|
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
XBool ReadAllKeyStrokes(void)
|
2020-03-28 16:14:18 +01:00
|
|
|
{
|
2021-09-28 10:28:45 +02:00
|
|
|
XBool GotKeyStrokes;
|
2020-03-28 16:14:18 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_INPUT_KEY key;
|
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
GotKeyStrokes = false;
|
2020-03-28 16:14:18 +01:00
|
|
|
for (;;) {
|
|
|
|
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &key);
|
|
|
|
if (Status == EFI_SUCCESS) {
|
2021-09-28 10:28:45 +02:00
|
|
|
GotKeyStrokes = true;
|
2020-03-28 16:14:18 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return GotKeyStrokes;
|
|
|
|
}
|
|
|
|
|
2021-05-04 12:03:40 +02:00
|
|
|
void PauseForKey(const XString8& msg)
|
2020-03-28 16:14:18 +01:00
|
|
|
{
|
|
|
|
UINTN index;
|
2021-05-04 12:03:40 +02:00
|
|
|
if ( msg.notEmpty() ) {
|
|
|
|
printf("%s", msg.c_str());
|
2020-03-28 16:14:18 +01:00
|
|
|
}
|
2021-05-04 12:03:40 +02:00
|
|
|
if ( msg.lastChar() != '\n' ) printf(" ");
|
|
|
|
printf("Hit any key to continue...\n");
|
2020-03-28 16:14:18 +01:00
|
|
|
|
|
|
|
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
|
2021-09-28 10:28:45 +02:00
|
|
|
// SwitchToText(false);
|
2020-03-28 16:14:18 +01:00
|
|
|
// PauseForKey(L"");
|
|
|
|
//
|
|
|
|
// // reset error flag
|
2021-09-28 10:28:45 +02:00
|
|
|
// haveError = false;
|
2020-03-28 16:14:18 +01:00
|
|
|
//}
|
|
|
|
//#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);
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 10:57:55 +02:00
|
|
|
|
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
XBool CheckFatalError(IN EFI_STATUS Status, IN CONST CHAR16 *where)
|
2021-04-05 10:57:55 +02:00
|
|
|
{
|
|
|
|
// CHAR16 ErrorName[64];
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status))
|
2021-09-28 10:28:45 +02:00
|
|
|
return false;
|
2021-04-05 10:57:55 +02:00
|
|
|
|
|
|
|
MsgLog("Fatal Error: %s %ls\n", efiStrError(Status), where);
|
|
|
|
|
|
|
|
// StatusToString(ErrorName, Status);
|
|
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_RED | EFI_BACKGROUND_BLACK);
|
|
|
|
printf("Fatal Error: %s %ls\n", efiStrError(Status), where);
|
|
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK);
|
2021-09-28 10:28:45 +02:00
|
|
|
haveError = true;
|
2021-04-05 10:57:55 +02:00
|
|
|
|
|
|
|
//gBS->Exit(ImageHandle, ExitStatus, ExitDataSize, ExitData);
|
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
return true;
|
2021-04-05 10:57:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
XBool CheckError(IN EFI_STATUS Status, IN CONST CHAR16 *where)
|
2021-04-05 10:57:55 +02:00
|
|
|
{
|
|
|
|
// CHAR16 ErrorName[64];
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status))
|
2021-09-28 10:28:45 +02:00
|
|
|
return false;
|
2021-04-05 10:57:55 +02:00
|
|
|
|
|
|
|
MsgLog("Fatal Error: %s %ls\n", efiStrError(Status), where);
|
|
|
|
|
|
|
|
// StatusToString(ErrorName, Status);
|
|
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_RED | EFI_BACKGROUND_BLACK);
|
|
|
|
printf("Error: %s %ls\n", efiStrError(Status), where);
|
|
|
|
gST->ConOut->SetAttribute (gST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK);
|
2021-09-28 10:28:45 +02:00
|
|
|
haveError = true;
|
2021-04-05 10:57:55 +02:00
|
|
|
|
2021-09-28 10:28:45 +02:00
|
|
|
return true;
|
2021-04-05 10:57:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|