+// Set a text mode
+// Returns the mode that was actually set.
+UINT32 egSetTextMode(UINT32 RequestedMode) {
+ UINTN i = 0, Width, Height;
+ UINT32 UsedMode = ST->ConOut->Mode->Mode;
+ EFI_STATUS Status;
+ BOOLEAN GoOn = TRUE;
+
+ if (RequestedMode != ST->ConOut->Mode->Mode) {
+ Status = refit_call2_wrapper(ST->ConOut->SetMode, ST->ConOut, RequestedMode);
+ if (Status == EFI_SUCCESS) {
+ UsedMode = RequestedMode;
+ } else {
+ SwitchToText(FALSE);
+ Print(L"Error setting text mode %d; available modes are:\n", ST->ConOut->Mode->Mode);
+ while (GoOn) {
+ Status = refit_call4_wrapper(ST->ConOut->QueryMode, ST->ConOut, i, &Width, &Height);
+ if (Status == EFI_SUCCESS)
+ Print(L"Mode: %d: %d x %d\n", i, Width, Height);
+ else if (i > 1)
+ GoOn = 0;
+ i++;
+ }
+ PauseForKey();
+ SwitchToGraphics();
+ } // if/else successful change
+ } // if need to change mode
+ return UsedMode;
+} // UINT32 egSetTextMode()
+