C   102
Untitled
Guest on 4th February 2023 09:43:50 PM


  1. #include "gnu-efi/inc/efi.h"
  2. #include "gnu-efi/inc/efilib.h"
  3. #include "main.h"
  4.  
  5. extern EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
  6. {
  7.     EFI_STATUS Status;
  8.     EFI_INPUT_KEY Key;
  9.     EFI_BOOT_SERVICES* BS;
  10.  
  11.     /* Store the system table for future use in other functions */
  12.     ST = SystemTable;
  13.     BS = ST->BootServices;
  14.     /* Say hi */
  15.     Status = ST->ConOut->OutputString(ST->ConOut, L"Hello World\r\n"); // EFI Applications use Unicode and CRLF, a la Windows
  16.     if (EFI_ERROR(Status))
  17.         return Status;
  18.     EFI_GUID gopGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  19.     EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
  20.  
  21.     Status = BS->LocateProtocol(&gopGuid, NULL, (void**)&gop);
  22.     if(EFI_ERROR(Status))
  23.       Status = ST->ConOut->OutputString(ST->ConOut, L"Unable To  alocate gop");
  24.     EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info;
  25.     UINTN SizeOfInfo, numModes, nativeMode;
  26.    
  27.     Status = gop->QueryMode(gop, gop->Mode==NULL?0:gop->Mode->Mode, &SizeOfInfo, &info);
  28.     // this is needed to get the current video mode
  29.     if (Status == EFI_NOT_STARTED)
  30.       Status = gop->SetMode(gop, 0);
  31.     if(EFI_ERROR(Status)) {
  32.       Status = ST->ConOut->OutputString(ST->ConOut, L"Unable to get native mode\n");
  33.     } else {
  34.       nativeMode = gop->Mode->Mode;
  35.       numModes = gop->Mode->MaxMode;
  36.     }
  37.     for (int i = 0; i < numModes; i++) {
  38.       char X[33];
  39.       char B[1080];
  40.       unsigned char HZR = (unsigned char)info->HorizontalResolution;
  41.       unsigned char VRR = (unsigned char)info->VerticalResolution;
  42.  
  43.       Status = gop->QueryMode(gop, i, &SizeOfInfo, &info);
  44.       Status = ST->ConOut->OutputString(ST->ConOut, L"mode");
  45.       Status = ST->ConOut->OutputString(ST->ConOut, (CHAR16*)itoa(i, X, 10));
  46.       EndLine(Status);
  47.       Status = ST->ConOut->OutputString(ST->ConOut, L"width");
  48.       Status = ST->ConOut->OutputString(ST->ConOut, (CHAR16*)itoa(info->HorizontalResolution, B, 10));
  49.       EndLine(Status);
  50.       Status = ST->ConOut->OutputString(ST->ConOut, L"Height");
  51.       Status = ST->ConOut->OutputString(ST->ConOut, (CHAR16*)itoa(info->VerticalResolution, B, 10));
  52.       EndLine(Status);
  53.       Status = ST->ConOut->OutputString(ST->ConOut, L"Format");
  54.       Status = ST->ConOut->OutputString(ST->ConOut, (CHAR16*)itoa(info->PixelFormat,B,10));
  55.       EndLine(Status);
  56.       if(i == nativeMode)
  57.           Status = ST->ConOut->OutputString(ST->ConOut, L"(Current)");
  58.       else
  59.           Status = ST->ConOut->OutputString(ST->ConOut, L"...");
  60.  
  61.  
  62.     }
  63.  
  64.    
  65.     while(1 == 1);
  66. }

Raw Paste

Login or Register to edit or fork this paste. It's free.