diff --git a/Aclock.c b/Aclock.c index 357c4be..9d47466 100644 --- a/Aclock.c +++ b/Aclock.c @@ -11,6 +11,62 @@ #include #include +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define FontWH_Ratio 2 + +// Global variables +SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut; +EFI_SYSTEM_TABLE *eST; + +void draw_circle(int hand_max, int sYcen, int sXcen){ + int x,y,r; + char c; + + for(r=0;r<60;r++){ + x=cos(r*M_PI/180*6)*hand_max*FontWH_Ratio+sXcen; + y=sin(r*M_PI/180*6)*hand_max+sYcen; + switch (r) { + case 0: + case 5: + case 10: + case 15: + case 20: + case 25: + case 30: + case 35: + case 40: + case 45: + case 50: + case 55: + c='o'; + break; + default: + c='.'; + break; + } + ConOut->SetCursorPosition(ConOut, x, y); + Print(L"%c", c); + } +} + +void draw_hand(int minute, int hlenght, char c, int sXcen, int sYcen){ + int x,y,n; + float r=(minute-15)*(M_PI/180)*6; + + for(n=1; nSetCursorPosition(ConOut, x, y); + Print(L"%c", c); + } +} + /** as the real entry point for the application. @@ -28,7 +84,51 @@ UefiMain ( IN EFI_SYSTEM_TABLE *SystemTable ) { - Print(L"Hello World \n"); - return EFI_SUCCESS; + ConOut = SystemTable->ConOut; + eST = SystemTable; + EFI_TIME ltime; + + /*char INFO[]="Copyright (c) 1994-2016 Antoni Sawicki \n" + "Copyright (c) 2016 Natalia Portillo \n" + "Version 1.0 (efi); Canary Islands, May 2016\n";*/ + int sXmax, sYmax, smax, hand_max, sXcen, sYcen; + + sXmax=sYmax=hand_max=sXcen=sYcen=0; + ConOut->ClearScreen(ConOut); + + while(1){ + eST->RuntimeServices->GetTime(<ime, NULL); + + UINTN Columns, Rows; + ConOut->QueryMode(ConOut, ConOut->Mode->Mode, &Columns, &Rows); + sYmax = (int)Rows; + sXmax = (int)Columns; + + if(sXmax/FontWH_Ratio<=sYmax) + smax=sXmax/FontWH_Ratio; + else + smax=sYmax; + + hand_max = (smax/2)-1; + + sXcen = sXmax/2; + sYcen = sYmax/2; + + ConOut->ClearScreen(ConOut); + draw_circle(hand_max, sYcen, sXcen); + + draw_hand((ltime.Hour*5)+(ltime.Minute/10), 2*hand_max/3, 'h', sXcen, sYcen); + draw_hand(ltime.Minute, hand_max-2, 'm', sXcen, sYcen); + draw_hand(ltime.Second, hand_max-1, '.', sXcen, sYcen); + + ConOut->SetCursorPosition(ConOut, sXcen-5, sYcen-(3*hand_max/5)); + Print(L".:ACLOCK:."); + ConOut->SetCursorPosition(ConOut, sXcen-5, sYcen+(3*hand_max/5)); + Print(L"[%02d:%02d:%02d]", ltime.Hour, ltime.Minute, ltime.Second); + + sleep(1); + } + + return EFI_SUCCESS; } diff --git a/Aclock.inf b/Aclock.inf index bd460ed..b69d310 100644 --- a/Aclock.inf +++ b/Aclock.inf @@ -26,11 +26,15 @@ [Packages] MdePkg/MdePkg.dec - + ShellPkg/ShellPkg.dec + StdLib/StdLib.dec + [LibraryClasses] + LibC + LibMath + UefiBootServicesTableLib UefiApplicationEntryPoint - UefiLib - + [Guids] [Ppis] diff --git a/binaries/aclock-efi-x64.efi b/binaries/aclock-efi-x64.efi new file mode 100644 index 0000000..eb235c0 Binary files /dev/null and b/binaries/aclock-efi-x64.efi differ diff --git a/binaries/aclock-efi-x64.iso b/binaries/aclock-efi-x64.iso new file mode 100644 index 0000000..2a4a624 Binary files /dev/null and b/binaries/aclock-efi-x64.iso differ