EXI_DeviceIPL: Get rid of a pointer cast

Also moves the RTC updating code to its own function.
This commit is contained in:
Lioncash 2015-09-06 14:42:39 -04:00
parent c08a83a5aa
commit ec3d55b093
2 changed files with 21 additions and 14 deletions

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cstring>
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/CommonTypes.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 bool CEXIIPL::IsPresent() const
{ {
return true; return true;
@ -177,9 +194,6 @@ bool CEXIIPL::IsPresent() const
void CEXIIPL::TransferByte(u8& _uByte) 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 // The first 4 bytes must be the address
// If we haven't read it, do it now // If we haven't read it, do it now
if (m_uPosition <= 3) if (m_uPosition <= 3)
@ -192,17 +206,8 @@ void CEXIIPL::TransferByte(u8& _uByte)
// Check if the command is complete // Check if the command is complete
if (m_uPosition == 3) if (m_uPosition == 3)
{ {
// Get the time ... // Get the time...
u32 &rtc = *((u32 *)&m_RTC); UpdateRTC();
if (SConfig::GetInstance().bWii)
{
// Subtract Wii bias
rtc = Common::swap32(CEXIIPL::GetGCTime() - cWiiBias);
}
else
{
rtc = Common::swap32(CEXIIPL::GetGCTime());
}
// Log the command // Log the command
std::string device_name; std::string device_name;

View File

@ -64,6 +64,8 @@ private:
std::string m_buffer; std::string m_buffer;
bool m_FontsLoaded; bool m_FontsLoaded;
void UpdateRTC();
void TransferByte(u8& _uByte) override; void TransferByte(u8& _uByte) override;
bool IsWriteCommand() const { return !!(m_uAddress & (1 << 31)); } bool IsWriteCommand() const { return !!(m_uAddress & (1 << 31)); }
u32 CommandRegion() const { return (m_uAddress & ~(1 << 31)) >> 8; } u32 CommandRegion() const { return (m_uAddress & ~(1 << 31)) >> 8; }