Skip to content

Commit b464f34

Browse files
RTC: Automatically detect timezone
1 parent 8fb2940 commit b464f34

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

pcsx2-qt/Settings/EmulationSettingsWidget.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ EmulationSettingsWidget::EmulationSettingsWidget(SettingsWindow* settings_dialog
159159
dialog()->registerWidgetHelp(m_ui.manuallySetRealTimeClock, tr("Manually Set Real-Time Clock"), tr("Unchecked"),
160160
tr("Manually set a real-time clock to use for the virtual PlayStation 2 instead of using your OS' system clock."));
161161
dialog()->registerWidgetHelp(m_ui.rtcDateTime, tr("Real-Time Clock"), tr("Current date and time"),
162-
tr("Real-time clock (RTC) used by the virtual PlayStation 2. Date format is the same as the one used by your OS. "
163-
"This time is only applied upon booting the PS2; changing it while in-game will have no effect. "
164-
"NOTE: This assumes you have your PS2 set to the default timezone of GMT+0 and default DST of Summer Time. "
162+
tr("Real-time clock (RTC) used by the virtual PlayStation 2. Date format is the same as the one used by your OS.<br>"
163+
"This time is only applied upon booting the PS2; changing it while in-game will have no effect.<br>"
165164
"Some games require an RTC date/time set after their release date."));
166165

167166
updateOptimalFramePacing();

pcsx2/CDVD/CDVD.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -920,25 +920,35 @@ void cdvdReset()
920920
cdvd.ReadTime = cdvdBlockReadTime(MODE_DVDROM);
921921
cdvd.RotSpeed = cdvdRotationTime(MODE_DVDROM);
922922

923+
ReadOSDConfigParames();
924+
925+
// Print timezone offset, DST, date format, and time format.
926+
DevCon.WriteLn(Color_StrongGreen, configParams1.timezoneOffset < 0 ? "Timezone Offset: GMT%03d:%02d" : "Timezone Offset: GMT+%02d:%02d",
927+
configParams1.timezoneOffset / 60, std::abs(configParams1.timezoneOffset % 60));
928+
DevCon.WriteLn(Color_StrongGreen, "DST: %s Time", GetDaylightSavings() ? "Summer" : "Winter");
929+
DevCon.WriteLn(Color_StrongGreen, "Date Format: %s", GetDateFormat() ? (GetDateFormat() == 2 ? "DD/MM/YYYY" : "MM/DD/YYYY") : "YYYY/MM/DD");
930+
DevCon.WriteLn(Color_StrongGreen, "Time Format: %s-Hour", GetTimeFormat() ? "12" : "24");
931+
923932
if (EmuConfig.ManuallySetRealTimeClock)
924933
{
925-
// Convert to GMT+9 (assumes GMT+0)
926934
std::tm tm{};
927935
tm.tm_sec = EmuConfig.RtcSecond;
928936
tm.tm_min = EmuConfig.RtcMinute;
929937
tm.tm_hour = EmuConfig.RtcHour;
930938
tm.tm_mday = EmuConfig.RtcDay;
931939
tm.tm_mon = EmuConfig.RtcMonth - 1;
932940
tm.tm_year = EmuConfig.RtcYear + 100; // 2000 - 1900
933-
tm.tm_isdst = 1;
941+
tm.tm_isdst = 0; // unused but necessary filler
934942

935-
// Need this instead of mktime for timezone independence
943+
// Need this instead of mktime for timezone independence.
936944
std::time_t t = 0;
945+
946+
// Account for user timezone, DST, and GMT+9 defaultism.
937947
#if defined(_WIN32)
938-
t = _mkgmtime(&tm) + 32400; //60 * 60 * 9 for GMT+9
948+
t = _mkgmtime(&tm) + 32400 - 60 * (configParams1.timezoneOffset + GetDaylightSavings() * 60);
939949
gmtime_s(&tm, &t);
940950
#else
941-
t = timegm(&tm) + 32400;
951+
t = timegm(&tm) + 32400 - 60 * (configParams1.timezoneOffset + GetDaylightSavings() * 60);
942952
gmtime_r(&t, &tm);
943953
#endif
944954

@@ -983,6 +993,21 @@ void cdvdReset()
983993
cdvd.RTC.year = static_cast<u8>(curtime.tm_year - 100); // offset from 2000
984994
}
985995

996+
// Print system time and system time basis.
997+
if (EmuConfig.ManuallySetRealTimeClock)
998+
{
999+
DevCon.WriteLn(Color_StrongGreen, "System Time Basis: Manual RTC");
1000+
DevCon.WriteLn(Color_StrongGreen, "System Time: 20%02u-%02u-%02u %02u:%02u:%02u",
1001+
EmuConfig.RtcYear, EmuConfig.RtcMonth, EmuConfig.RtcDay,
1002+
EmuConfig.RtcHour, EmuConfig.RtcMinute, EmuConfig.RtcSecond);
1003+
}
1004+
else
1005+
{
1006+
DevCon.WriteLn("System Time Basis: %s", g_InputRecording.isActive() ? "Default Input Recording Time" : "Operating System Time");
1007+
DevCon.WriteLn(Color_StrongGreen, "System Time: 20%02u-%02u-%02u %02u:%02u:%02u",
1008+
cdvd.RTC.year, cdvd.RTC.month, cdvd.RTC.day, cdvd.RTC.hour, cdvd.RTC.minute, cdvd.RTC.second);
1009+
}
1010+
9861011
cdvdCtrlTrayClose();
9871012
}
9881013

pcsx2/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ struct Pcsx2Config
13141314
InhibitScreensaver : 1,
13151315
BackupSavestate : 1,
13161316
McdFolderAutoManage : 1,
1317-
ManuallySetRealTimeClock : 1,
1317+
ManuallySetRealTimeClock : 1, // passes user-set real-time clock information to cdvd at startup
13181318

13191319
HostFs : 1,
13201320

pcsx2/ps2/BiosTools.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,21 @@ void CopyBIOSToMemory()
382382

383383
CurrentBiosInformation.eeThreadListAddr = 0;
384384
}
385+
386+
// Summer = True; Winter = False
387+
bool GetDaylightSavings()
388+
{
389+
return configParams2.UC[1] & 0x10 ? true : false;
390+
}
391+
392+
// 12-Hour = True; 24-Hour = False
393+
bool GetTimeFormat()
394+
{
395+
return configParams2.UC[1] & 0x20 ? true : false;
396+
}
397+
398+
// DD/MM/YYYY = 2; MM/DD/YYYY = 1; YYYY/MM/DD = 0
399+
u8 GetDateFormat()
400+
{
401+
return configParams2.UC[1] & 0x80 ? 2 : (configParams2.UC[1] & 0x40 ? 1 : 0);
402+
}

pcsx2/ps2/BiosTools.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ typedef struct
4343
/** LANGUAGE_??? value */
4444
/*16*/ u32 language : 5;
4545
/** timezone minutes offset from gmt */
46-
/*21*/ u32 timezoneOffset : 11;
46+
/*21*/ s32 timezoneOffset : 11;
4747
};
4848

4949
u8 UC[4];
@@ -117,3 +117,7 @@ extern bool IsBIOSAvailable(const std::string& full_path);
117117

118118
extern bool LoadBIOS();
119119
extern void CopyBIOSToMemory();
120+
121+
extern bool GetDaylightSavings();
122+
extern bool GetTimeFormat();
123+
extern u8 GetDateFormat();

0 commit comments

Comments
 (0)