From aae0e966826cffa37501e6dfc648d8617fbe618b Mon Sep 17 00:00:00 2001 From: PerfectInduction Date: Thu, 26 Aug 2010 19:24:47 +0000 Subject: [PATCH] Fix RTC to report the correct system time in Wii and GC titles as reported in Issue 1817 Modify GetLocalTimeSinceJan1970 to account for DST. GetGCTime() returns only GC epoch time(used by most Wii titles.) IPL-DEV subtracts Wii bias before copying to m_RTC(mostly used by homebrew.) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6133 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Timer.cpp | 12 ++++++++++-- Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp | 14 +++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Source/Core/Common/Src/Timer.cpp b/Source/Core/Common/Src/Timer.cpp index 039770ebd7..67bb6874b4 100644 --- a/Source/Core/Common/Src/Timer.cpp +++ b/Source/Core/Common/Src/Timer.cpp @@ -174,15 +174,23 @@ u64 Timer::GetTimeSinceJan1970() u64 Timer::GetLocalTimeSinceJan1970() { - time_t sysTime, tzDiff; + time_t sysTime, tzDiff, tzDST; struct tm * gmTime; time(&sysTime); + + // Account for DST where needed + gmTime = localtime(&sysTime); + if(gmTime->tm_isdst == 1) + tzDST = 3600; + else + tzDST = 0; + // Lazy way to get local time in sec gmTime = gmtime(&sysTime); tzDiff = sysTime - mktime(gmTime); - return (u64)(sysTime + tzDiff); + return (u64)(sysTime + tzDiff + tzDST); } // Return the current time formatted as Minutes:Seconds:Milliseconds diff --git a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp index 7217cca819..29e7f71998 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp @@ -254,6 +254,9 @@ bool CEXIIPL::IsPresent() void CEXIIPL::TransferByte(u8& _uByte) { + // Seconds between 1.1.2000 and 4.1.2008 16:00:38 + const u32 cWiiBias = 0x0F1114A6; + // The first 4 bytes must be the address // If we haven't read it, do it now if (m_uPosition < 4) @@ -267,7 +270,8 @@ void CEXIIPL::TransferByte(u8& _uByte) if (m_uPosition == 3) { // Get the time ... - u32 GCTime = CEXIIPL::GetGCTime(); + // Subtract Wii bias + u32 GCTime = CEXIIPL::GetGCTime() - cWiiBias; u8* pGCTime = (u8*)&GCTime; for (int i=0; i<4; i++) { @@ -405,8 +409,7 @@ void CEXIIPL::TransferByte(u8& _uByte) u32 CEXIIPL::GetGCTime() { u64 ltime = 0; - const u32 cJanuary2000 = 0x386D42C0; // Seconds between 1.1.1970 and 1.1.2000 - const u32 cWiiBias = 0x0F111566; // Seconds between 1.1.2000 and 5.1.2008 (Wii epoch) + const u32 cJanuary2000 = 0x386D4380; // Seconds between 1.1.1970 and 1.1.2000 #if defined(HAVE_WX) && HAVE_WX // hack in some netplay stuff @@ -415,10 +418,7 @@ u32 CEXIIPL::GetGCTime() if (0 == ltime) ltime = Common::Timer::GetLocalTimeSinceJan1970(); - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) - return ((u32)ltime - cJanuary2000 - cWiiBias/* + 32434790*/); - else - return ((u32)ltime - cJanuary2000); + return ((u32)ltime - cJanuary2000); #if 0 // (mb2): I think we can get rid of the IPL bias.