fixup net/kd/time

This commit is contained in:
Shawn Hoffman 2012-02-09 10:21:26 -08:00
parent 3ec25a9e3f
commit c8129bc802

View File

@ -28,6 +28,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <ws2tcpip.h> #include <ws2tcpip.h>
#endif #endif
#include "Timer.h"
// data layout of the network configuration file (/shared2/sys/net/02/config.dat) // data layout of the network configuration file (/shared2/sys/net/02/config.dat)
@ -161,12 +162,12 @@ private:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
class CWII_IPC_HLE_Device_net_kd_time : public IWII_IPC_HLE_Device class CWII_IPC_HLE_Device_net_kd_time : public IWII_IPC_HLE_Device
{ {
u64 timediff;
public: public:
CWII_IPC_HLE_Device_net_kd_time(u32 _DeviceID, const std::string& _rDeviceName) CWII_IPC_HLE_Device_net_kd_time(u32 _DeviceID, const std::string& _rDeviceName)
: IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
, rtc()
, utcdiff()
{ {
timediff = 1337; // this must be stored somewhere?
} }
virtual ~CWII_IPC_HLE_Device_net_kd_time() virtual ~CWII_IPC_HLE_Device_net_kd_time()
@ -192,59 +193,81 @@ public:
u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C); u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C);
u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10); u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10);
u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14); u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14);
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C); u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C);
u32 result = 0;
u32 common_result = 0;
// TODO Writes stuff to /shared2/nwc24/misc.bin
u32 update_misc = 0;
static bool init = false;
switch (Parameter) switch (Parameter)
{ {
case IOCTL_NW24_SET_RTC_COUNTER: // NWC24iSetRtcCounter (but prolly just the first 4 bytes are intresting...) case IOCTL_NW24_GET_UNIVERSAL_TIME:
{ Memory::Write_U64(GetAdjustedUTC(), BufferOut + 4);
_dbg_assert_msg_(WII_IPC_NET, BufferInSize==0x20, "NET_KD_TIME: Set RTC Counter BufferIn to small"); break;
_dbg_assert_msg_(WII_IPC_NET, BufferOutSize==0x20, "NET_KD_TIME: Set RTC Counter BufferOut to small");
u64 rtctime = Memory::Read_U64(BufferIn+4);
Memory::Write_U32(0, BufferOut);
Memory::Write_U64(rtctime + timediff, BufferOut+4);
INFO_LOG(WII_IPC_NET, "NET_KD_TIME: Set RTC Counter");
Memory::Write_U32(0, _CommandAddress + 0x4); case IOCTL_NW24_SET_UNIVERSAL_TIME:
return true; SetAdjustedUTC(Memory::Read_U64(BufferIn));
} update_misc = Memory::Read_U32(BufferIn + 8);
break;
case IOCTL_NW24_SET_RTC_COUNTER:
rtc = Memory::Read_U32(BufferIn);
update_misc = Memory::Read_U32(BufferIn + 4);
break;
case IOCTL_NW24_GET_TIME_DIFF: case IOCTL_NW24_GET_TIME_DIFF:
{ Memory::Write_U64(GetAdjustedUTC() - rtc, BufferOut + 4);
Memory::Write_U32(0, BufferOut); break;
Memory::Write_U64(timediff, BufferOut+4);
INFO_LOG(WII_IPC_NET, "NET_KD_TIME: Get time diff");
Memory::Write_U32(0, _CommandAddress + 0x4); case IOCTL_NW24_UNIMPLEMENTED:
return true; result = -9;
} break;
default: default:
ERROR_LOG(WII_IPC_NET, "%s - IOCtl:\n" ERROR_LOG(WII_IPC_NET, "%s - unknown IOCtl: %x\n",
" Parameter: 0x%x (0x17 NWC24iSetRtcCounter) \n" GetDeviceName().c_str(), Parameter);
" BufferIn: 0x%08x\n"
" BufferInSize: 0x%08x\n"
" BufferOut: 0x%08x\n"
" BufferOutSize: 0x%08x\n",
GetDeviceName().c_str(), Parameter, BufferIn, BufferInSize, BufferOut, BufferOutSize);
break; break;
} }
// write return value // write return values
Memory::Write_U32(0, _CommandAddress + 0x4); Memory::Write_U32(common_result, BufferOut);
Memory::Write_U32(result, _CommandAddress + 4);
return true; return true;
} }
private: private:
enum enum
{ {
IOCTL_NW24_SET_RTC_COUNTER = 0x17, IOCTL_NW24_GET_UNIVERSAL_TIME = 0x14,
IOCTL_NW24_GET_TIME_DIFF = 0x18, IOCTL_NW24_SET_UNIVERSAL_TIME = 0x15,
IOCTL_NW24_UNIMPLEMENTED = 0x16,
IOCTL_NW24_SET_RTC_COUNTER = 0x17,
IOCTL_NW24_GET_TIME_DIFF = 0x18,
}; };
u8 m_RtcCounter[0x20]; u64 rtc;
s64 utcdiff;
// Seconds between 1.1.1970 and 4.1.2008 16:00:38
static const u64 wii_bias = 0x477E5826;
// Returns seconds since wii epoch
// +/- any bias set from IOCTL_NW24_SET_UNIVERSAL_TIME
u64 GetAdjustedUTC() const
{
return Common::Timer::GetTimeSinceJan1970() - wii_bias + utcdiff;
}
// Store the difference between what the wii thinks is UTC and
// what the host OS thinks
void SetAdjustedUTC(u64 wii_utc)
{
utcdiff = Common::Timer::GetTimeSinceJan1970() - wii_bias - wii_utc;
}
}; };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////