From ee3fc1bc60c15ec15374743636e473270762d95a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herv=C3=A9=20Poussineau?= Date: Fri, 24 Apr 2009 20:35:11 +0000 Subject: [PATCH] Implement ArcGetTime() and ArcGetRelativeTime() svn path=/trunk/; revision=40686 --- .../boot/freeldr/freeldr/arch/amd64/mach.c | 2 +- .../boot/freeldr/freeldr/arch/amd64/pcrtc.c | 103 +-------------- .../boot/freeldr/freeldr/arch/i386/machpc.c | 2 +- .../boot/freeldr/freeldr/arch/i386/machxbox.c | 2 +- .../boot/freeldr/freeldr/arch/i386/pcrtc.c | 121 ++++++++---------- .../boot/freeldr/freeldr/arch/i386/xboxrtc.c | 54 +++----- .../boot/freeldr/freeldr/arch/powerpc/mach.c | 11 +- reactos/boot/freeldr/freeldr/custom.c | 30 ++--- .../freeldr/include/arch/amd64/machpc.h | 2 +- .../freeldr/include/arch/i386/machpc.h | 2 +- .../freeldr/include/arch/i386/machxbox.h | 2 +- .../boot/freeldr/freeldr/include/machine.h | 7 +- reactos/boot/freeldr/freeldr/machine.c | 21 ++- reactos/boot/freeldr/freeldr/ui/tui.c | 45 ++++--- reactos/boot/freeldr/freeldr/ui/tuimenu.c | 21 ++- reactos/include/reactos/arc/arc.h | 10 ++ 16 files changed, 163 insertions(+), 272 deletions(-) diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/mach.c b/reactos/boot/freeldr/freeldr/arch/amd64/mach.c index 21ba1d4bce0..bd168ea69d2 100644 --- a/reactos/boot/freeldr/freeldr/arch/amd64/mach.c +++ b/reactos/boot/freeldr/freeldr/arch/amd64/mach.c @@ -54,7 +54,7 @@ MachInit(const char *CmdLine) MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry; MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount; - MachVtbl.RTCGetCurrentDateTime = PcRTCGetCurrentDateTime; + MachVtbl.GetTime = PcGetTime; MachVtbl.HwDetect = PcHwDetect; } diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c b/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c index cbd3803f95a..1e9234fcdad 100644 --- a/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c +++ b/reactos/boot/freeldr/freeldr/arch/amd64/pcrtc.c @@ -1,104 +1,5 @@ -/* $Id: pcrtc.c 21339 2006-03-18 22:09:16Z peterw $ - * - * FreeLoader - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ +/* No need to duplicate code ; import the i386 version */ -#include - -#define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f)) - -VOID -PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second) -{ - REGS Regs; - - if (NULL != Year || NULL != Month || NULL != Day) - { - /* Some BIOSes, such es the 1998/07/25 system ROM - * in the Compaq Deskpro EP/SB, leave CF unchanged - * if successful, so CF should be cleared before - * calling this function. */ - __asm__ ("clc"); - - /* Int 1Ah AH=04h - * TIME - GET REAL-TIME CLOCK DATE (AT,XT286,PS) - * - * AH = 04h - * CF clear to avoid bug - * Return: - * CF clear if successful - * CH = century (BCD) - * CL = year (BCD) - * DH = month (BCD) - * DL = day (BCD) - * CF set on error - */ - Regs.b.ah = 0x04; - Int386(0x1A, &Regs, &Regs); - - if (NULL != Year) - { - *Year = 100 * BCD_INT(Regs.b.ch) + BCD_INT(Regs.b.cl); - } - if (NULL != Month) - { - *Month = BCD_INT(Regs.b.dh); - } - if (NULL != Day) - { - *Day = BCD_INT(Regs.b.dl); - } - } - - if (NULL != Hour || NULL != Minute || NULL != Second) - { - /* Some BIOSes leave CF unchanged if successful, - * so CF should be cleared before calling this function. */ - __asm__ ("clc"); - - /* Int 1Ah AH=02h - * TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS) - * - * AH = 02h - * CF clear to avoid bug - * Return: - * CF clear if successful - * CH = hour (BCD) - * CL = minutes (BCD) - * DH = seconds (BCD) - * DL = daylight savings flag (00h standard time, 01h daylight time) - * CF set on error (i.e. clock not running or in middle of update) - */ - Regs.b.ah = 0x02; - Int386(0x1A, &Regs, &Regs); - - if (NULL != Hour) - { - *Hour = BCD_INT(Regs.b.ch); - } - if (NULL != Minute) - { - *Minute = BCD_INT(Regs.b.cl); - } - if (NULL != Second) - { - *Second = BCD_INT(Regs.b.dh); - } - } -} +#include "../i386/pcrtc.c" /* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c index f9e87344b05..c9b346706b0 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machpc.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machpc.c @@ -54,7 +54,7 @@ PcMachInit(const char *CmdLine) MachVtbl.DiskGetPartitionEntry = DiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry; MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount; - MachVtbl.RTCGetCurrentDateTime = PcRTCGetCurrentDateTime; + MachVtbl.GetTime = PcGetTime; MachVtbl.HwDetect = PcHwDetect; } diff --git a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c index e09a6d29b53..612404a806b 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/machxbox.c @@ -57,7 +57,7 @@ XboxMachInit(const char *CmdLine) MachVtbl.DiskGetPartitionEntry = XboxDiskGetPartitionEntry; MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry; MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount; - MachVtbl.RTCGetCurrentDateTime = XboxRTCGetCurrentDateTime; + MachVtbl.GetTime = XboxGetTime; MachVtbl.HwDetect = XboxHwDetect; /* Set LEDs to orange after init */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/pcrtc.c b/reactos/boot/freeldr/freeldr/arch/i386/pcrtc.c index dbfb536c506..f6a4f96087c 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/pcrtc.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/pcrtc.c @@ -21,84 +21,63 @@ #define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f)) -VOID -PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second) +TIMEINFO* +PcGetTime(VOID) { - REGS Regs; + static TIMEINFO TimeInfo; + REGS Regs; - if (NULL != Year || NULL != Month || NULL != Day) - { - /* Some BIOSes, such es the 1998/07/25 system ROM - * in the Compaq Deskpro EP/SB, leave CF unchanged - * if successful, so CF should be cleared before - * calling this function. */ - __asm__ ("clc"); + /* Some BIOSes, such as the 1998/07/25 system ROM + * in the Compaq Deskpro EP/SB, leave CF unchanged + * if successful, so CF should be cleared before + * calling this function. */ + __asm__ ("clc"); - /* Int 1Ah AH=04h - * TIME - GET REAL-TIME CLOCK DATE (AT,XT286,PS) - * - * AH = 04h - * CF clear to avoid bug - * Return: - * CF clear if successful - * CH = century (BCD) - * CL = year (BCD) - * DH = month (BCD) - * DL = day (BCD) - * CF set on error - */ - Regs.b.ah = 0x04; - Int386(0x1A, &Regs, &Regs); + /* Int 1Ah AH=04h + * TIME - GET REAL-TIME CLOCK DATE (AT,XT286,PS) + * + * AH = 04h + * CF clear to avoid bug + * Return: + * CF clear if successful + * CH = century (BCD) + * CL = year (BCD) + * DH = month (BCD) + * DL = day (BCD) + * CF set on error + */ + Regs.b.ah = 0x04; + Int386(0x1A, &Regs, &Regs); - if (NULL != Year) - { - *Year = 100 * BCD_INT(Regs.b.ch) + BCD_INT(Regs.b.cl); - } - if (NULL != Month) - { - *Month = BCD_INT(Regs.b.dh); - } - if (NULL != Day) - { - *Day = BCD_INT(Regs.b.dl); - } - } + TimeInfo.Year = 100 * BCD_INT(Regs.b.ch) + BCD_INT(Regs.b.cl); + TimeInfo.Month = BCD_INT(Regs.b.dh); + TimeInfo.Day = BCD_INT(Regs.b.dl); - if (NULL != Hour || NULL != Minute || NULL != Second) - { - /* Some BIOSes leave CF unchanged if successful, - * so CF should be cleared before calling this function. */ - __asm__ ("clc"); + /* Some BIOSes leave CF unchanged if successful, + * so CF should be cleared before calling this function. */ + __asm__ ("clc"); - /* Int 1Ah AH=02h - * TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS) - * - * AH = 02h - * CF clear to avoid bug - * Return: - * CF clear if successful - * CH = hour (BCD) - * CL = minutes (BCD) - * DH = seconds (BCD) - * DL = daylight savings flag (00h standard time, 01h daylight time) - * CF set on error (i.e. clock not running or in middle of update) - */ - Regs.b.ah = 0x02; - Int386(0x1A, &Regs, &Regs); + /* Int 1Ah AH=02h + * TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS) + * + * AH = 02h + * CF clear to avoid bug + * Return: + * CF clear if successful + * CH = hour (BCD) + * CL = minutes (BCD) + * DH = seconds (BCD) + * DL = daylight savings flag (00h standard time, 01h daylight time) + * CF set on error (i.e. clock not running or in middle of update) + */ + Regs.b.ah = 0x02; + Int386(0x1A, &Regs, &Regs); - if (NULL != Hour) - { - *Hour = BCD_INT(Regs.b.ch); - } - if (NULL != Minute) - { - *Minute = BCD_INT(Regs.b.cl); - } - if (NULL != Second) - { - *Second = BCD_INT(Regs.b.dh); - } - } + TimeInfo.Hour = BCD_INT(Regs.b.ch); + TimeInfo.Minute = BCD_INT(Regs.b.cl); + TimeInfo.Second = BCD_INT(Regs.b.dh); + + return &TimeInfo; } /* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/i386/xboxrtc.c b/reactos/boot/freeldr/freeldr/arch/i386/xboxrtc.c index c09c03a0b94..2f301f1f8c9 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/xboxrtc.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/xboxrtc.c @@ -37,46 +37,28 @@ HalpQueryCMOS(UCHAR Reg) return(Val); } -VOID -XboxRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second) +TIMEINFO* +XboxGetTime(VOID) { - while (HalpQueryCMOS (RTC_REGISTER_A) & RTC_REG_A_UIP) - { - ; - } + static TIMEINFO TimeInfo; - if (NULL != Second) - { - *Second = BCD_INT(HalpQueryCMOS(0)); - } - if (NULL != Minute) - { - *Minute = BCD_INT(HalpQueryCMOS(2)); - } - if (NULL != Hour) - { - *Hour = BCD_INT(HalpQueryCMOS(4)); - } - if (NULL != Day) - { - *Day = BCD_INT(HalpQueryCMOS(7)); - } - if (NULL != Month) + while (HalpQueryCMOS (RTC_REGISTER_A) & RTC_REG_A_UIP) { - *Month = BCD_INT(HalpQueryCMOS(8)); - } - if (NULL != Year) - { - *Year = BCD_INT(HalpQueryCMOS(9)); - if (*Year > 80) - { - *Year += 1900; - } - else - { - *Year += 2000; - } + ; } + + TimeInfo.Second = BCD_INT(HalpQueryCMOS(0)); + TimeInfo.Minute = BCD_INT(HalpQueryCMOS(2)); + TimeInfo.Hour = BCD_INT(HalpQueryCMOS(4)); + TimeInfo.Day = BCD_INT(HalpQueryCMOS(7)); + TimeInfo.Month = BCD_INT(HalpQueryCMOS(8)); + TimeInfo.Year = BCD_INT(HalpQueryCMOS(9)); + if (TimeInfo.Year > 80) + TimeInfo.Year += 1900; + else + TimeInfo.Year += 2000; + + return &TimeInfo; } /* EOF */ diff --git a/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c b/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c index 37f6adbd422..01434aa3878 100644 --- a/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c +++ b/reactos/boot/freeldr/freeldr/arch/powerpc/mach.c @@ -342,9 +342,12 @@ ULONG PpcDiskGetCacheableBlockCount( ULONG DriveNumber ) { return 1; } -VOID PpcRTCGetCurrentDateTime( PULONG Hear, PULONG Month, PULONG Day, - PULONG Hour, PULONG Minute, PULONG Second ) { - //printf("RTCGeturrentDateTime\n"); +TIMEINFO* +PpcGetTime(VOID) +{ + static TIMEINFO TimeInfo; + //printf("PpcGetTime\n"); + return &TimeInfo; } VOID NarrowToWide(WCHAR *wide_name, char *name) @@ -534,7 +537,7 @@ void PpcDefaultMachVtbl() MachVtbl.DiskGetDriveGeometry = PpcDiskGetDriveGeometry; MachVtbl.DiskGetCacheableBlockCount = PpcDiskGetCacheableBlockCount; - MachVtbl.RTCGetCurrentDateTime = PpcRTCGetCurrentDateTime; + MachVtbl.GetTime = PpcGetTime; MachVtbl.HwDetect = PpcHwDetect; } diff --git a/reactos/boot/freeldr/freeldr/custom.c b/reactos/boot/freeldr/freeldr/custom.c index 6d9dab25865..b1db80725ff 100644 --- a/reactos/boot/freeldr/freeldr/custom.c +++ b/reactos/boot/freeldr/freeldr/custom.c @@ -79,7 +79,7 @@ VOID OptionMenuCustomBootDisk(VOID) CHAR SectionName[100]; CHAR BootDriveString[20]; ULONG SectionId; - ULONG Year, Month, Day, Hour, Minute, Second; + TIMEINFO* TimeInfo; RtlZeroMemory(SectionName, sizeof(SectionName)); RtlZeroMemory(BootDriveString, sizeof(BootDriveString)); @@ -90,8 +90,8 @@ VOID OptionMenuCustomBootDisk(VOID) } // Generate a unique section name - MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomBootDisk%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); + TimeInfo = ArcGetTime(); + sprintf(SectionName, "CustomBootDisk%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -122,7 +122,7 @@ VOID OptionMenuCustomBootPartition(VOID) CHAR BootDriveString[20]; CHAR BootPartitionString[20]; ULONG SectionId; - ULONG Year, Month, Day, Hour, Minute, Second; + TIMEINFO* TimeInfo; RtlZeroMemory(SectionName, sizeof(SectionName)); RtlZeroMemory(BootDriveString, sizeof(BootDriveString)); @@ -139,8 +139,8 @@ VOID OptionMenuCustomBootPartition(VOID) } // Generate a unique section name - MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomBootPartition%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); + TimeInfo = ArcGetTime(); + sprintf(SectionName, "CustomBootPartition%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -178,7 +178,7 @@ VOID OptionMenuCustomBootBootSectorFile(VOID) CHAR BootPartitionString[20]; CHAR BootSectorFileString[200]; ULONG SectionId; - ULONG Year, Month, Day, Hour, Minute, Second; + TIMEINFO* TimeInfo; RtlZeroMemory(SectionName, sizeof(SectionName)); RtlZeroMemory(BootDriveString, sizeof(BootDriveString)); @@ -201,8 +201,8 @@ VOID OptionMenuCustomBootBootSectorFile(VOID) } // Generate a unique section name - MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomBootSectorFile%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); + TimeInfo = ArcGetTime(); + sprintf(SectionName, "CustomBootSectorFile%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -248,7 +248,7 @@ VOID OptionMenuCustomBootReactOS(VOID) CHAR ReactOSARCPath[200]; CHAR ReactOSOptions[200]; ULONG SectionId; - ULONG Year, Month, Day, Hour, Minute, Second; + TIMEINFO* TimeInfo; RtlZeroMemory(SectionName, sizeof(SectionName)); RtlZeroMemory(BootDriveString, sizeof(BootDriveString)); @@ -277,8 +277,8 @@ VOID OptionMenuCustomBootReactOS(VOID) } // Generate a unique section name - MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomReactOS%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); + TimeInfo = ArcGetTime(); + sprintf(SectionName, "CustomReactOS%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) @@ -321,7 +321,7 @@ VOID OptionMenuCustomBootLinux(VOID) CHAR LinuxInitrdString[200]; CHAR LinuxCommandLineString[200]; ULONG SectionId; - ULONG Year, Month, Day, Hour, Minute, Second; + TIMEINFO* TimeInfo; RtlZeroMemory(SectionName, sizeof(SectionName)); RtlZeroMemory(BootDriveString, sizeof(BootDriveString)); @@ -356,8 +356,8 @@ VOID OptionMenuCustomBootLinux(VOID) } // Generate a unique section name - MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - sprintf(SectionName, "CustomLinux%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second); + TimeInfo = ArcGetTime(); + sprintf(SectionName, "CustomLinux%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second); // Add the section if (!IniAddSection(SectionName, &SectionId)) diff --git a/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h b/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h index aa98eb09ff0..1d2007bb04f 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h +++ b/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h @@ -55,7 +55,7 @@ BOOLEAN PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTI BOOLEAN PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry); ULONG PcDiskGetCacheableBlockCount(ULONG DriveNumber); -VOID PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); +TIMEINFO* PcGetTime(VOID); PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID); diff --git a/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h b/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h index 363720bd872..94b42f6870d 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h +++ b/reactos/boot/freeldr/freeldr/include/arch/i386/machpc.h @@ -54,7 +54,7 @@ BOOLEAN PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTI BOOLEAN PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry); ULONG PcDiskGetCacheableBlockCount(ULONG DriveNumber); -VOID PcRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); +TIMEINFO* PcGetTime(VOID); PCONFIGURATION_COMPONENT_DATA PcHwDetect(VOID); diff --git a/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h b/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h index 7463de4ef66..a1bc397ff7e 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h +++ b/reactos/boot/freeldr/freeldr/include/arch/i386/machxbox.h @@ -57,7 +57,7 @@ BOOLEAN XboxDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPAR BOOLEAN XboxDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry); ULONG XboxDiskGetCacheableBlockCount(ULONG DriveNumber); -VOID XboxRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); +TIMEINFO* XboxGetTime(VOID); PCONFIGURATION_COMPONENT_DATA XboxHwDetect(VOID); diff --git a/reactos/boot/freeldr/freeldr/include/machine.h b/reactos/boot/freeldr/freeldr/include/machine.h index 1e9ba8c8618..b117319544d 100644 --- a/reactos/boot/freeldr/freeldr/include/machine.h +++ b/reactos/boot/freeldr/freeldr/include/machine.h @@ -72,7 +72,8 @@ typedef struct tagMACHVTBL BOOLEAN (*DiskGetDriveGeometry)(ULONG DriveNumber, PGEOMETRY DriveGeometry); ULONG (*DiskGetCacheableBlockCount)(ULONG DriveNumber); - VOID (*RTCGetCurrentDateTime)(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); + TIMEINFO* (*GetTime)(VOID); + ULONG (*GetRelativeTime)(VOID); PCONFIGURATION_COMPONENT_DATA (*HwDetect)(VOID); } MACHVTBL, *PMACHVTBL; @@ -115,7 +116,8 @@ BOOLEAN MachDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, UL BOOLEAN MachDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOLEAN MachDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry); ULONG MachDiskGetCacheableBlockCount(ULONG DriveNumber); -VOID MachRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second); +TIMEINFO* ArcGetTime(VOID); +ULONG ArcGetRelativeTime(VOID); VOID MachHwDetect(VOID); VOID MachPrepareForReactOS(IN BOOLEAN Setup); @@ -147,7 +149,6 @@ VOID MachPrepareForReactOS(IN BOOLEAN Setup); #define MachDiskGetPartitionEntry(Drive, Part, Entry) MachVtbl.DiskGetPartitionEntry((Drive), (Part), (Entry)) #define MachDiskGetDriveGeometry(Drive, Geom) MachVtbl.DiskGetDriveGeometry((Drive), (Geom)) #define MachDiskGetCacheableBlockCount(Drive) MachVtbl.DiskGetCacheableBlockCount(Drive) -#define MachRTCGetCurrentDateTime(Y, Mo, D, H, Mi, S) MachVtbl.RTCGetCurrentDateTime((Y), (Mo), (D), (H), (Mi), (S)); #define MachHwDetect() MachVtbl.HwDetect() #endif /* __MACHINE_H_ */ diff --git a/reactos/boot/freeldr/freeldr/machine.c b/reactos/boot/freeldr/freeldr/machine.c index 08dfb2f7647..54b8e1f50cd 100644 --- a/reactos/boot/freeldr/freeldr/machine.c +++ b/reactos/boot/freeldr/freeldr/machine.c @@ -47,7 +47,6 @@ #undef MachDiskGetPartitionEntry #undef MachDiskGetDriveGeometry #undef MachDiskGetCacheableBlockCount -#undef MachRTCGetCurrentDateTime #undef MachHwDetect MACHVTBL MachVtbl; @@ -228,10 +227,24 @@ MachDiskGetCacheableBlockCount(ULONG DriveNumber) return MachVtbl.DiskGetCacheableBlockCount(DriveNumber); } -VOID -MachRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second) +TIMEINFO* +ArcGetTime(VOID) { - MachVtbl.RTCGetCurrentDateTime(Year, Month, Day, Hour, Minute, Second); + return MachVtbl.GetTime(); +} + +ULONG +ArcGetRelativeTime(VOID) +{ + TIMEINFO* TimeInfo; + ULONG ret; + + if (MachVtbl.GetRelativeTime) + return MachVtbl.GetRelativeTime(); + + TimeInfo = ArcGetTime(); + ret = ((TimeInfo->Hour * 24) + TimeInfo->Minute) * 60 + TimeInfo->Second; + return ret; } VOID diff --git a/reactos/boot/freeldr/freeldr/ui/tui.c b/reactos/boot/freeldr/freeldr/ui/tui.c index ff9d73f189f..5fbf5f278ab 100644 --- a/reactos/boot/freeldr/freeldr/ui/tui.c +++ b/reactos/boot/freeldr/freeldr/ui/tui.c @@ -442,9 +442,8 @@ VOID TuiDrawStatusText(PCSTR StatusText) VOID TuiUpdateDateTime(VOID) { - ULONG Year, Month, Day; - ULONG Hour, Minute, Second; - CHAR DateString[40]; + TIMEINFO* TimeInfo; + char DateString[40]; CHAR TimeString[40]; CHAR TempString[20]; BOOLEAN PMHour = FALSE; @@ -452,27 +451,31 @@ VOID TuiUpdateDateTime(VOID) /* Don't draw the time if this has been disabled */ if (!UiDrawTime) return; - MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second); - if (Year < 1 || 9999 < Year || Month < 1 || 12 < Month || Day < 1 || - 31 < Day || 23 < Hour || 59 < Minute || 59 < Second) + TimeInfo = ArcGetTime(); + if (TimeInfo->Year < 1 || 9999 < TimeInfo->Year || + TimeInfo->Month < 1 || 12 < TimeInfo->Month || + TimeInfo->Day < 1 || 31 < TimeInfo->Day || + 23 < TimeInfo->Hour || + 59 < TimeInfo->Minute || + 59 < TimeInfo->Second) { /* This happens on QEmu sometimes. We just skip updating */ return; } // Get the month name - strcpy(DateString, UiMonthNames[Month - 1]); + strcpy(DateString, UiMonthNames[TimeInfo->Month - 1]); // Get the day - _itoa(Day, TempString, 10); + _itoa(TimeInfo->Day, TempString, 10); // Get the day postfix - if (1 == Day || 21 == Day || 31 == Day) + if (1 == TimeInfo->Day || 21 == TimeInfo->Day || 31 == TimeInfo->Day) { strcat(TempString, "st"); } - else if (2 == Day || 22 == Day) + else if (2 == TimeInfo->Day || 22 == TimeInfo->Day) { strcat(TempString, "nd"); } - else if (3 == Day || 23 == Day) + else if (3 == TimeInfo->Day || 23 == TimeInfo->Day) { strcat(TempString, "rd"); } @@ -486,35 +489,35 @@ VOID TuiUpdateDateTime(VOID) strcat(DateString, " "); // Get the year and add it to the date - _itoa(Year, TempString, 10); + _itoa(TimeInfo->Year, TempString, 10); strcat(DateString, TempString); // Draw the date TuiDrawText(UiScreenWidth-strlen(DateString)-2, 1, DateString, ATTR(UiTitleBoxFgColor, UiTitleBoxBgColor)); // Get the hour and change from 24-hour mode to 12-hour - if (Hour > 12) + if (TimeInfo->Hour > 12) { - Hour -= 12; + TimeInfo->Hour -= 12; PMHour = TRUE; } - if (Hour == 0) + if (TimeInfo->Hour == 0) { - Hour = 12; + TimeInfo->Hour = 12; } - _itoa(Hour, TempString, 10); + _itoa(TimeInfo->Hour, TempString, 10); strcpy(TimeString, " "); strcat(TimeString, TempString); strcat(TimeString, ":"); - _itoa(Minute, TempString, 10); - if (Minute < 10) + _itoa(TimeInfo->Minute, TempString, 10); + if (TimeInfo->Minute < 10) { strcat(TimeString, "0"); } strcat(TimeString, TempString); strcat(TimeString, ":"); - _itoa(Second, TempString, 10); - if (Second < 10) + _itoa(TimeInfo->Second, TempString, 10); + if (TimeInfo->Second < 10) { strcat(TimeString, "0"); } diff --git a/reactos/boot/freeldr/freeldr/ui/tuimenu.c b/reactos/boot/freeldr/freeldr/ui/tuimenu.c index d5078c7ea50..2fa4d5d05f0 100644 --- a/reactos/boot/freeldr/freeldr/ui/tuimenu.c +++ b/reactos/boot/freeldr/freeldr/ui/tuimenu.c @@ -23,6 +23,7 @@ TuiDisplayMenu(PCSTR MenuItemList[], UiMenuKeyPressFilterCallback KeyPressFilter) { UI_MENU_INFO MenuInformation; + ULONG InitialClockSecond; ULONG LastClockSecond; ULONG CurrentClockSecond; ULONG KeyPress; @@ -59,7 +60,7 @@ TuiDisplayMenu(PCSTR MenuItemList[], // // Get the current second of time // - MachRTCGetCurrentDateTime(NULL, NULL, NULL, NULL, NULL, &LastClockSecond); + InitialClockSecond = LastClockSecond = ArcGetRelativeTime(); // // Process keys @@ -87,17 +88,12 @@ TuiDisplayMenu(PCSTR MenuItemList[], // // Check if there is a countdown // - if (MenuInformation.MenuTimeRemaining) + if (MenuInformation.MenuTimeRemaining != -1) { // - // Get the updated time, seconds only + // Get the updated time // - MachRTCGetCurrentDateTime(NULL, - NULL, - NULL, - NULL, - NULL, - &CurrentClockSecond); + CurrentClockSecond = ArcGetRelativeTime(); // // Check if more then a second has now elapsed @@ -108,7 +104,10 @@ TuiDisplayMenu(PCSTR MenuItemList[], // Update the time information // LastClockSecond = CurrentClockSecond; - MenuInformation.MenuTimeRemaining--; + MenuInformation.MenuTimeRemaining = + InitialClockSecond + MenuTimeOut - LastClockSecond; + if (MenuInformation.MenuTimeRemaining < 0) + MenuInformation.MenuTimeRemaining = 0; // // Update the menu @@ -117,7 +116,7 @@ TuiDisplayMenu(PCSTR MenuItemList[], VideoCopyOffScreenBufferToVRAM(); } } - else + else if (MenuInformation.MenuTimeRemaining == 0) { // // A time out occurred, exit this loop and return default OS diff --git a/reactos/include/reactos/arc/arc.h b/reactos/include/reactos/arc/arc.h index 0ce728e6ce7..dcb5b2acb0e 100644 --- a/reactos/include/reactos/arc/arc.h +++ b/reactos/include/reactos/arc/arc.h @@ -121,6 +121,16 @@ typedef enum _MEMORY_TYPE MemoryMaximum } MEMORY_TYPE; +typedef struct _TIMEINFO +{ + USHORT Year; + USHORT Month; + USHORT Day; + USHORT Hour; + USHORT Minute; + USHORT Second; +} TIMEINFO; + typedef struct _MEMORY_DESCRIPTOR { MEMORY_TYPE MemoryType; -- 2.17.1