Set maximum resolution for running in qemu

This commit is contained in:
Josh Holtrop 2022-03-15 22:52:56 -04:00
parent a38f95a7b8
commit 3fa8e4a24b

View File

@ -16,8 +16,20 @@ private void wait_key()
}
}
private bool in_qemu()
{
ulong * firmware_vendor = cast(ulong *) st.FirmwareVendor;
ulong fv1 = firmware_vendor[0];
return fv1 ==
((cast(ulong)'E') |
(cast(ulong)'D' << 16) |
(cast(ulong)'K' << 32) |
(cast(ulong)' ' << 48));
}
private bool set_graphics_mode()
{
uint max_horizontal_resolution = in_qemu() ? 1920u : 0xFFFFFFFFu;
UINTN buffer_size = heap_free();
EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
EFI_HANDLE * handles = cast(EFI_HANDLE *)heap_base();
@ -51,14 +63,19 @@ private bool set_graphics_mode()
(status = gop.QueryMode(gop, mode_number, &info_size, &info)) == EFI_SUCCESS;
mode_number++)
{
if (info.HorizontalResolution > best_width)
if ((info.HorizontalResolution > best_width) &&
(info.HorizontalResolution <= max_horizontal_resolution))
{
best_width = info.HorizontalResolution;
best_mode_number = mode_number;
}
st.BootServices.FreePool(info);
}
gop.SetMode(gop, best_mode_number);
if ((status = gop.SetMode(gop, best_mode_number)) != EFI_SUCCESS)
{
writeln("SetMode: Error %u\n", status);
return false;
}
return true;
}