From ec3d55b093866e86b83ea8639a59d672df465a9d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 6 Sep 2015 14:42:39 -0400 Subject: [PATCH] EXI_DeviceIPL: Get rid of a pointer cast Also moves the RTC updating code to its own function. --- Source/Core/Core/HW/EXI_DeviceIPL.cpp | 33 +++++++++++++++------------ Source/Core/Core/HW/EXI_DeviceIPL.h | 2 ++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI_DeviceIPL.cpp index 246903eae9..36962bd826 100644 --- a/Source/Core/Core/HW/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI_DeviceIPL.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include + #include "Common/ChunkFile.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" @@ -170,6 +172,21 @@ void CEXIIPL::SetCS(int _iCS) } } +void CEXIIPL::UpdateRTC() +{ + // Seconds between 1.1.2000 and 4.1.2008 16:00:38 + static constexpr u32 WII_BIAS = 0x0F1114A6; + + u32 rtc; + + if (SConfig::GetInstance().bWii) + rtc = Common::swap32(GetGCTime() - WII_BIAS); + else + rtc = Common::swap32(GetGCTime()); + + std::memcpy(m_RTC, &rtc, sizeof(u32)); +} + bool CEXIIPL::IsPresent() const { return true; @@ -177,9 +194,6 @@ bool CEXIIPL::IsPresent() const 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 <= 3) @@ -192,17 +206,8 @@ void CEXIIPL::TransferByte(u8& _uByte) // Check if the command is complete if (m_uPosition == 3) { - // Get the time ... - u32 &rtc = *((u32 *)&m_RTC); - if (SConfig::GetInstance().bWii) - { - // Subtract Wii bias - rtc = Common::swap32(CEXIIPL::GetGCTime() - cWiiBias); - } - else - { - rtc = Common::swap32(CEXIIPL::GetGCTime()); - } + // Get the time... + UpdateRTC(); // Log the command std::string device_name; diff --git a/Source/Core/Core/HW/EXI_DeviceIPL.h b/Source/Core/Core/HW/EXI_DeviceIPL.h index 25bb53c9b9..40af936de2 100644 --- a/Source/Core/Core/HW/EXI_DeviceIPL.h +++ b/Source/Core/Core/HW/EXI_DeviceIPL.h @@ -64,6 +64,8 @@ private: std::string m_buffer; bool m_FontsLoaded; + void UpdateRTC(); + void TransferByte(u8& _uByte) override; bool IsWriteCommand() const { return !!(m_uAddress & (1 << 31)); } u32 CommandRegion() const { return (m_uAddress & ~(1 << 31)) >> 8; }