From 9a313244ff81f681ab2f30e617a3fdc1f139bb72 Mon Sep 17 00:00:00 2001 From: Pierre Guillod Date: Fri, 29 Mar 2024 01:42:02 +0100 Subject: [PATCH] =?UTF-8?q?T=C3=A9l=C3=A9verser=20les=20fichiers=20vers=20?= =?UTF-8?q?"/"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EfiClock.inf | 28 ++++++++++++ UefiMain.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 EfiClock.inf create mode 100644 UefiMain.c diff --git a/EfiClock.inf b/EfiClock.inf new file mode 100644 index 0000000..cf791c5 --- /dev/null +++ b/EfiClock.inf @@ -0,0 +1,28 @@ +[Defines] + INF_VERSION = 1.25 + BASE_NAME = EfiClock + FILE_GUID = 8e2228f9-6249-48a0-bfd6-f99479ad8a46 # Get a GUID from guidgen.com + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiEntry + +[Sources] + UefiMain.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + UefiLib + TimerLib + +[Guids] + +[Ppis] + +[Protocols] + +[FeaturePcd] + +[Pcd] diff --git a/UefiMain.c b/UefiMain.c new file mode 100644 index 0000000..836dae2 --- /dev/null +++ b/UefiMain.c @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include +#include + +EFI_GUID gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; +EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop = NULL; +UINT64 Gop_FrameBufferBase = 0; +UINT32 Gop_PixelsPerScanLine = 0; + +static inline void drawPixel(UINT32 x, UINT32 y, UINT32 pixel) +{ + *((UINT32*)(Gop_FrameBufferBase + 4 * Gop_PixelsPerScanLine * y + 4 * x)) = pixel; +} + +static inline void drawRectangle(UINT32 x, UINT32 y, UINT32 w, UINT32 h, UINT32 pixel) +{ + for(int ix = 0; ix < w; ++ix) + { + for(int iy = 0; iy < w; ++iy) + { + drawPixel(x+ix, y+iy, pixel); + } + } +} + +EFI_STATUS EFIAPI UefiEntry(IN EFI_HANDLE imgHandle, IN EFI_SYSTEM_TABLE* sysTable) +{ + gST = sysTable; + gBS = sysTable->BootServices; + gImageHandle = imgHandle; + + gBS->SetWatchdogTimer(0, 0, 0, NULL); + + EFI_STATUS status = 0; + + /** + * GOP Setup + */ + + status = gBS->LocateProtocol(&gop_guid, NULL, (VOID **)&Gop); + if (EFI_ERROR(status)) { + Print(u"\r\nERROR: %x; Cannot locate GOP protocol. Return.\r\n", status); + return status; + } + + Gop_FrameBufferBase = Gop->Mode->FrameBufferBase; + Gop_PixelsPerScanLine = Gop->Mode->Info->PixelsPerScanLine; + UINT32 W = Gop->Mode->Info->HorizontalResolution; + UINT32 H = Gop->Mode->Info->VerticalResolution; + + /** + * Fills framebuffer + */ + + drawRectangle(0,0,W,H,0x000000); + + UINT32 sq_sid = W * 50 / 1000; + UINT32 sq_gap = W * 17 / 1000; + + /** + * Computes squares coordinates + */ + + UINT32 col0 = W/2 - 7*sq_gap/2 - 4*sq_sid; + UINT32 col1 = W/2 - 5*sq_gap/2 - 3*sq_sid; + UINT32 col2 = W/2 - sq_gap/2 - sq_sid; + UINT32 col3 = W/2 + sq_gap/2 ; + UINT32 col4 = W/2 + 5*sq_gap/2 + 2*sq_sid; + UINT32 col5 = W/2 + 7*sq_gap/2 + 3*sq_sid; + + UINT32 row0 = H/2 - 3*sq_sid/2 - sq_gap; + UINT32 row1 = H/2 - sq_sid/2 ; + UINT32 row2 = H/2 + sq_sid/2 + sq_gap; + + /** + * Loops drawing the clockface + */ + + EFI_TIME Time; + UINT16 second, minute, hour; + const UINT32 accentColor = 0xFFAB3F, idleColor = 0x555555; + + while(1) + { + gRT->GetTime(&Time, NULL); + second = Time.Second; + minute = Time.Minute; + hour = Time.Hour; + + second & 0b000001 ? drawRectangle(col5,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col5,row2,sq_sid,sq_sid,idleColor); + second & 0b000010 ? drawRectangle(col5,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col5,row1,sq_sid,sq_sid,idleColor); + second & 0b000100 ? drawRectangle(col5,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col5,row0,sq_sid,sq_sid,idleColor); + second & 0b001000 ? drawRectangle(col4,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col4,row2,sq_sid,sq_sid,idleColor); + second & 0b010000 ? drawRectangle(col4,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col4,row1,sq_sid,sq_sid,idleColor); + second & 0b100000 ? drawRectangle(col4,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col4,row0,sq_sid,sq_sid,idleColor); + + minute & 0b000001 ? drawRectangle(col3,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col3,row2,sq_sid,sq_sid,idleColor); + minute & 0b000010 ? drawRectangle(col3,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col3,row1,sq_sid,sq_sid,idleColor); + minute & 0b000100 ? drawRectangle(col3,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col3,row0,sq_sid,sq_sid,idleColor); + minute & 0b001000 ? drawRectangle(col2,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col2,row2,sq_sid,sq_sid,idleColor); + minute & 0b010000 ? drawRectangle(col2,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col2,row1,sq_sid,sq_sid,idleColor); + minute & 0b100000 ? drawRectangle(col2,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col2,row0,sq_sid,sq_sid,idleColor); + + hour & 0b00001 ? drawRectangle(col1,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col1,row2,sq_sid,sq_sid,idleColor); + hour & 0b00010 ? drawRectangle(col1,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col1,row1,sq_sid,sq_sid,idleColor); + hour & 0b00100 ? drawRectangle(col1,row0,sq_sid,sq_sid,accentColor) : drawRectangle(col1,row0,sq_sid,sq_sid,idleColor); + hour & 0b01000 ? drawRectangle(col0,row2,sq_sid,sq_sid,accentColor) : drawRectangle(col0,row2,sq_sid,sq_sid,idleColor); + hour & 0b10000 ? drawRectangle(col0,row1,sq_sid,sq_sid,accentColor) : drawRectangle(col0,row1,sq_sid,sq_sid,idleColor); + + MicroSecondDelay(1e6); + } + + return EFI_SUCCESS; +}