|
36 | 36 | cdvdStruct cdvd; |
37 | 37 |
|
38 | 38 | s64 PSXCLK = 36864000; |
| 39 | +const s32 GMT9_OFFSET_SECONDS = 32400; // 9 * 60 * 60 |
39 | 40 |
|
40 | 41 | static constexpr u8 monthmap[13] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
41 | 42 |
|
@@ -920,69 +921,86 @@ void cdvdReset() |
920 | 921 | cdvd.ReadTime = cdvdBlockReadTime(MODE_DVDROM); |
921 | 922 | cdvd.RotSpeed = cdvdRotationTime(MODE_DVDROM); |
922 | 923 |
|
| 924 | + ReadOSDConfigParames(); |
| 925 | + |
| 926 | + // Print time zone offset, DST, date format, time format, and system time basis. |
| 927 | + DevCon.WriteLn(Color_StrongGreen, configParams1.timezoneOffset < 0 ? "Time Zone Offset: GMT%03d:%02d" : "Time Zone Offset: GMT+%02d:%02d", |
| 928 | + configParams1.timezoneOffset / 60, std::abs(configParams1.timezoneOffset % 60)); |
| 929 | + DevCon.WriteLn(Color_StrongGreen, "DST: %s Time", GetDaylightSavings() ? "Summer" : "Winter"); |
| 930 | + DevCon.WriteLn(Color_StrongGreen, "Time Format: %s-Hour", GetTimeFormat() ? "12" : "24"); |
| 931 | + DevCon.WriteLn(Color_StrongGreen, "Date Format: %s", GetDateFormat() ? (GetDateFormat() == 2 ? "DD/MM/YYYY" : "MM/DD/YYYY") : "YYYY/MM/DD"); |
| 932 | + DevCon.WriteLn(Color_StrongGreen, "System Time Basis: %s", |
| 933 | + EmuConfig.ManuallySetRealTimeClock ? "Manual RTC" : g_InputRecording.isActive() ? "Default Input Recording Time" : "Operating System Time"); |
| 934 | + |
| 935 | + std::tm input_tm{}; |
| 936 | + std::tm resulting_tm{}; |
| 937 | + |
| 938 | + const int bios_settings_offset_seconds = 60 * (configParams1.timezoneOffset + GetDaylightSavings() * 60); |
| 939 | + |
| 940 | + // CDVD internally uses GMT+9, 1-indexed months, and year offset of 2000 instead of 1900. |
923 | 941 | if (EmuConfig.ManuallySetRealTimeClock) |
924 | 942 | { |
925 | | - // Convert to GMT+9 (assumes GMT+0) |
926 | | - std::tm tm{}; |
927 | | - tm.tm_sec = EmuConfig.RtcSecond; |
928 | | - tm.tm_min = EmuConfig.RtcMinute; |
929 | | - tm.tm_hour = EmuConfig.RtcHour; |
930 | | - tm.tm_mday = EmuConfig.RtcDay; |
931 | | - tm.tm_mon = EmuConfig.RtcMonth - 1; |
932 | | - tm.tm_year = EmuConfig.RtcYear + 100; // 2000 - 1900 |
933 | | - tm.tm_isdst = 1; |
934 | | - |
935 | | - // Need this instead of mktime for timezone independence |
936 | | - std::time_t t = 0; |
937 | | - #if defined(_WIN32) |
938 | | - t = _mkgmtime(&tm) + 32400; //60 * 60 * 9 for GMT+9 |
939 | | - gmtime_s(&tm, &t); |
940 | | - #else |
941 | | - t = timegm(&tm) + 32400; |
942 | | - gmtime_r(&t, &tm); |
943 | | - #endif |
944 | | - |
945 | | - cdvd.RTC.second = tm.tm_sec; |
946 | | - cdvd.RTC.minute = tm.tm_min; |
947 | | - cdvd.RTC.hour = tm.tm_hour; |
948 | | - cdvd.RTC.day = tm.tm_mday; |
949 | | - cdvd.RTC.month = tm.tm_mon + 1; |
950 | | - cdvd.RTC.year = tm.tm_year - 100; |
951 | | - } |
952 | | - // If we are recording, always use the same RTC setting |
953 | | - // for games that use the RTC to seed their RNG -- this is very important to be the same everytime! |
| 943 | + resulting_tm.tm_sec = EmuConfig.RtcSecond; |
| 944 | + resulting_tm.tm_min = EmuConfig.RtcMinute; |
| 945 | + resulting_tm.tm_hour = EmuConfig.RtcHour; |
| 946 | + resulting_tm.tm_mday = EmuConfig.RtcDay; |
| 947 | + resulting_tm.tm_mon = EmuConfig.RtcMonth - 1; |
| 948 | + resulting_tm.tm_year = EmuConfig.RtcYear + 100; |
| 949 | + |
| 950 | + // Work backwards to input time by accounting for BIOS settings and GMT+9 defaultism. |
| 951 | +#if defined(_WIN32) |
| 952 | + const std::time_t input_time = _mkgmtime(&resulting_tm) + GMT9_OFFSET_SECONDS - bios_settings_offset_seconds; |
| 953 | + gmtime_s(&input_tm, &input_time); |
| 954 | +#else |
| 955 | + const std::time_t input_time = timegm(&resulting_tm) + GMT9_OFFSET_SECONDS - bios_settings_offset_seconds; |
| 956 | + gmtime_r(&input_time, &input_tm); |
| 957 | +#endif |
| 958 | + } |
954 | 959 | else if (g_InputRecording.isActive()) |
955 | 960 | { |
956 | | - Console.WriteLn("Input Recording Active - Using Constant RTC of 04-03-2020 (DD-MM-YYYY)"); |
957 | | - // Why not just 0 everything? Some games apparently require the date to be valid in terms of when |
958 | | - // the PS2 / Game actually came out. (MGS3). So set it to a value well beyond any PS2 game's release date. |
959 | | - cdvd.RTC.second = 0; |
960 | | - cdvd.RTC.minute = 0; |
961 | | - cdvd.RTC.hour = 0; |
962 | | - cdvd.RTC.day = 4; |
963 | | - cdvd.RTC.month = 3; |
964 | | - cdvd.RTC.year = 20; |
| 961 | + // Legacy default value if manual RTC is off to preserve compat with old input recordings (RNG seeding). |
| 962 | + // Well beyond any PS2 game's release date because some games require a valid date in terms of when the PS2 / Game actually came out (MGS3). |
| 963 | + input_tm.tm_sec = 0; |
| 964 | + input_tm.tm_min = 0; |
| 965 | + input_tm.tm_hour = 0; |
| 966 | + input_tm.tm_mday = 4; |
| 967 | + input_tm.tm_mon = 2; |
| 968 | + input_tm.tm_year = 120; |
| 969 | + |
| 970 | +#if defined(_WIN32) |
| 971 | + const std::time_t resulting_time = _mkgmtime(&input_tm) - GMT9_OFFSET_SECONDS + bios_settings_offset_seconds; |
| 972 | + gmtime_s(&resulting_tm, &resulting_time); |
| 973 | +#else |
| 974 | + const std::time_t resulting_time = timegm(&input_tm) - GMT9_OFFSET_SECONDS + bios_settings_offset_seconds; |
| 975 | + gmtime_r(&resulting_time, &resulting_tm); |
| 976 | +#endif |
965 | 977 | } |
966 | 978 | else |
967 | 979 | { |
968 | | - // CDVD internally uses GMT+9. If you think the time's wrong, you're wrong. |
969 | | - // Set up your time zone and winter/summer in the BIOS. No PS2 BIOS I know of features automatic DST. |
970 | | - const std::time_t utc_time = std::time(nullptr); |
971 | | - const std::time_t gmt9_time = (utc_time + 32400); //60 * 60 * 9 |
972 | | - struct tm curtime = {}; |
| 980 | + // User must set time zone and winter/summer DST in the BIOS for correct time. |
| 981 | + const std::time_t input_time = std::time(nullptr) + GMT9_OFFSET_SECONDS; |
| 982 | + const std::time_t resulting_time = input_time - GMT9_OFFSET_SECONDS + bios_settings_offset_seconds; |
| 983 | + |
973 | 984 | #ifdef _MSC_VER |
974 | | - gmtime_s(&curtime, &gmt9_time); |
| 985 | + gmtime_s(&input_tm, &input_time); |
| 986 | + gmtime_s(&resulting_tm, &resulting_time); |
975 | 987 | #else |
976 | | - gmtime_r(&gmt9_time, &curtime); |
| 988 | + gmtime_r(&input_time, &input_tm); |
| 989 | + gmtime_r(&resulting_time, &resulting_tm); |
977 | 990 | #endif |
978 | | - cdvd.RTC.second = static_cast<u8>(curtime.tm_sec); |
979 | | - cdvd.RTC.minute = static_cast<u8>(curtime.tm_min); |
980 | | - cdvd.RTC.hour = static_cast<u8>(curtime.tm_hour); |
981 | | - cdvd.RTC.day = static_cast<u8>(curtime.tm_mday); |
982 | | - cdvd.RTC.month = static_cast<u8>(curtime.tm_mon + 1); // WX returns Jan as "0" |
983 | | - cdvd.RTC.year = static_cast<u8>(curtime.tm_year - 100); // offset from 2000 |
984 | 991 | } |
985 | 992 |
|
| 993 | + cdvd.RTC.second = static_cast<u8>(input_tm.tm_sec); |
| 994 | + cdvd.RTC.minute = static_cast<u8>(input_tm.tm_min); |
| 995 | + cdvd.RTC.hour = static_cast<u8>(input_tm.tm_hour); |
| 996 | + cdvd.RTC.day = static_cast<u8>(input_tm.tm_mday); |
| 997 | + cdvd.RTC.month = static_cast<u8>(input_tm.tm_mon + 1); |
| 998 | + cdvd.RTC.year = static_cast<u8>(input_tm.tm_year - 100); // offset from 2000 |
| 999 | + |
| 1000 | + DevCon.WriteLn(Color_StrongGreen, "Resulting System Time: 20%02u-%02u-%02u %02u:%02u:%02u", |
| 1001 | + resulting_tm.tm_year - 100, resulting_tm.tm_mon + 1, resulting_tm.tm_mday, |
| 1002 | + resulting_tm.tm_hour, resulting_tm.tm_min, resulting_tm.tm_sec); |
| 1003 | + |
986 | 1004 | cdvdCtrlTrayClose(); |
987 | 1005 | } |
988 | 1006 |
|
|
0 commit comments