diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index c65b45fba..ac2e21507 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used @@ -66,17 +67,39 @@ void Platform_Log(const char* msg, int len) { _print("%s\n", tmp); } -extern time_t ps2time(time_t* t); +// https://stackoverflow.com/a/42340213 +static CC_INLINE int UnBCD(unsigned char bcd) { + return bcd - 6 * (bcd >> 4); +} + +#define JST_OFFSET -9 * 60 // UTC+9 -> UTC +static time_t CurrentUnixTime(void) { + sceCdCLOCK raw; + struct tm tim; + sceCdReadClock(&raw); + + tim.tm_sec = UnBCD(raw.second); + tim.tm_min = UnBCD(raw.minute); + tim.tm_hour = UnBCD(raw.hour); + tim.tm_mday = UnBCD(raw.day); + // & 0x1F, since a user had issues with upper 3 bits being set to 1 + tim.tm_mon = UnBCD(raw.month & 0x1F) - 1; + tim.tm_year = UnBCD(raw.year) + 100; + + // mktime will normalise the time anyways + tim.tm_min += JST_OFFSET; + return mktime(&tim); +} + TimeMS DateTime_CurrentUTC(void) { - time_t rtc_sec = ps2time(NULL); + time_t rtc_sec = CurrentUnixTime(); return (cc_uint64)rtc_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { - struct timeval cur; + time_t rtc_sec = CurrentUnixTime(); struct tm loc_time; - gettimeofday(&cur, NULL); - localtime_r(&cur.tv_sec, &loc_time); + localtime_r(&rtc_sec, &loc_time); t->year = loc_time.tm_year + 1900; t->month = loc_time.tm_mon + 1; diff --git a/src/Window_WiiU.cpp b/src/Window_WiiU.cpp index 999f533ce..f181bf7a9 100644 --- a/src/Window_WiiU.cpp +++ b/src/Window_WiiU.cpp @@ -142,9 +142,8 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ -extern Rect2D dirty_rect; void Window_ProcessEvents(float delta) { - if (!dirty_rect.width) dirty_rect.width = 1; + LBackend_MarkAllDirty(); if (!WHBProcIsRunning()) { Window_Main.Exists = false;