diff --git a/include/rtc.h b/include/rtc.h new file mode 100644 index 0000000000..fcc1a38ea2 --- /dev/null +++ b/include/rtc.h @@ -0,0 +1,28 @@ +#ifndef POKEPLATINUM_RTC_H +#define POKEPLATINUM_RTC_H + + +#include + +enum TimeOfDay { + TOD_MORNING = 0, + TOD_DAY = 1, + TOD_TWILIGHT = 2, + TOD_NIGHT = 3, + TOD_LATE_NIGHT = 4, +}; + +void InitRTC(void); +void UpdateRTC(void); +void GetCurrentDateTime(RTCDate * date, RTCTime * time); +void GetCurrentTime(RTCTime * time); +void GetCurrentDate(RTCDate * date); +int GetSecondsSinceMidnight(void); +s64 GetTimestamp(void); +int DayNumberForDate(const RTCDate * date); +BOOL IsNight(void); +enum TimeOfDay GetTimeOfDay(void); +enum TimeOfDay TimeOfDayForHour(int hour); +s64 TimeElapsed(s64 since, s64 until); + +#endif // POKEPLATINUM_RTC_H diff --git a/include/unk_0201378C.h b/include/unk_0201378C.h deleted file mode 100644 index 8e0b9d5070..0000000000 --- a/include/unk_0201378C.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef POKEPLATINUM_UNK_0201378C_H -#define POKEPLATINUM_UNK_0201378C_H - - -#include - -void sub_0201378C(void); -void sub_020137C4(void); -void sub_0201384C(RTCDate * param0, RTCTime * param1); -void sub_02013880(RTCTime * param0); -void sub_020138A4(RTCDate * param0); -int sub_020138C8(void); -s64 sub_020138EC(void); -int sub_02013900(const RTCDate * param0); -BOOL sub_02013948(void); -int sub_02013960(void); -int sub_02013974(int param0); -s64 sub_0201398C(s64 param0, s64 param1); - -#endif // POKEPLATINUM_UNK_0201378C_H diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index b00b762dfe..01ae2f2eff 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -50,7 +50,7 @@ Static main Object main.nef.p/src_unk_02012480.c.o Object main.nef.p/src_unk_02012744.c.o Object main.nef.p/src_unk_020131EC.c.o - Object main.nef.p/src_unk_0201378C.c.o + Object main.nef.p/src_rtc.c.o Object main.nef.p/src_unk_02013A04.c.o Object main.nef.p/src_unk_02013B10.c.o Object main.nef.p/src_unk_02014000.c.o diff --git a/src/main.c b/src/main.c index cd7aa3a202..fa2038fee7 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,7 @@ #include "unk_020067E8.h" #include "unk_0200A9DC.h" #include "unk_0200F174.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02017428.h" #include "unk_02017728.h" #include "unk_0201CCF0.h" @@ -75,7 +75,7 @@ void NitroMain (void) sub_02017B70(0); PM_GetBackLight(&sSavedBacklightState, NULL); sub_0202419C(); - sub_0201378C(); + InitRTC(); sub_02000E3C(); sub_02002B7C(); @@ -144,7 +144,7 @@ void NitroMain (void) } } - sub_020137C4(); + UpdateRTC(); sub_02017458(); sub_020241CC(); sub_0201CDD4(gCoreSys.unk_24); @@ -323,7 +323,7 @@ void InitRNG (void) RTCTime v1; u32 v2; - sub_0201384C(&v0, &v1); + GetCurrentDateTime(&v0, &v1); v2 = v0.year + v0.month * 0x100 * v0.day * 0x10000 + v1.hour * 0x10000 + (v1.minute + v1.second) * 0x1000000 + gCoreSys.frameCounter; diff --git a/src/meson.build b/src/meson.build index a1f8afa532..948132a3f1 100644 --- a/src/meson.build +++ b/src/meson.build @@ -46,7 +46,7 @@ pokeplatinum_c = files( 'unk_02012480.c', 'unk_02012744.c', 'unk_020131EC.c', - 'unk_0201378C.c', + 'rtc.c', 'unk_02013A04.c', 'unk_02013B10.c', 'unk_02014000.c', diff --git a/src/overlay005/ov5_021D521C.c b/src/overlay005/ov5_021D521C.c index f8d82d5761..c110bf8e80 100644 --- a/src/overlay005/ov5_021D521C.c +++ b/src/overlay005/ov5_021D521C.c @@ -5,7 +5,7 @@ #include "overlay005/struct_ov5_021D5894.h" #include "unk_02006E3C.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_0201E0A4.h" #include "overlay005/ov5_021D521C.h" @@ -39,7 +39,7 @@ UnkStruct_ov5_021D538C * ov5_021D521C (UnkStruct_ov5_021D5894 * param0, const u8 v1->unk_00 = ov5_021D53D4(param1, &v1->unk_04); v1->unk_08 = 0; - v2 = sub_020138C8() / 2; + v2 = GetSecondsSinceMidnight() / 2; for (v0 = 0; v0 < v1->unk_00; v0++) { if (v1->unk_04[v0].unk_00 > v2) { @@ -74,7 +74,7 @@ void ov5_021D5298 (UnkStruct_ov5_021D538C * param0) GF_ASSERT(param0); - v4 = sub_020138C8() / 2; + v4 = GetSecondsSinceMidnight() / 2; if (param0->unk_00 > 1) { if ((param0->unk_08 - 1) >= 0) { diff --git a/src/overlay005/ov5_021F134C.c b/src/overlay005/ov5_021F134C.c index 7422454526..9042dff90f 100644 --- a/src/overlay005/ov5_021F134C.c +++ b/src/overlay005/ov5_021F134C.c @@ -12,7 +12,7 @@ #include "overlay101/struct_ov101_021D86B0.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02061804.h" #include "unk_020711EC.h" #include "unk_02073838.h" @@ -138,7 +138,7 @@ static void ov5_021F1424 (SysTask * param0, void * param1) int v0; UnkStruct_ov5_021F1388 * v1 = param1; - v0 = sub_02013960(); + v0 = GetTimeOfDay(); switch (v1->unk_00) { case 0: diff --git a/src/overlay006/ov6_02240C9C.c b/src/overlay006/ov6_02240C9C.c index 1cd0cace76..167a8789eb 100644 --- a/src/overlay006/ov6_02240C9C.c +++ b/src/overlay006/ov6_02240C9C.c @@ -17,7 +17,7 @@ #include "overlay006/struct_ov6_02242634_sub2.h" #include "narc.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_0201D15C.h" #include "unk_02025E08.h" @@ -175,7 +175,7 @@ void ov6_02240C9C (const UnkStruct_ov6_02242634 * param0, int * param1, int * pa { int v0; - v0 = sub_02013960(); + v0 = GetTimeOfDay(); if ((v0 == 1) || (v0 == 2)) { (*param1) = param0->unk_48[0]; diff --git a/src/overlay006/ov6_022465FC.c b/src/overlay006/ov6_022465FC.c index aa9537bb68..89609432e8 100644 --- a/src/overlay006/ov6_022465FC.c +++ b/src/overlay006/ov6_022465FC.c @@ -8,7 +8,7 @@ #include "struct_defs/struct_0203CDB0.h" #include "narc.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_0201D15C.h" #include "savedata/save_table.h" #include "unk_0202E2CC.h" @@ -301,7 +301,7 @@ int ov6_02246978 (UnkStruct_0203CDB0 * param0, int param1) default: GF_ASSERT(0); case 0: - switch (sub_02013960()) { + switch (GetTimeOfDay()) { case 0: return v1->unk_00; case 1: diff --git a/src/overlay006/ov6_02246B74.c b/src/overlay006/ov6_02246B74.c index d063732933..3334ce3da2 100644 --- a/src/overlay006/ov6_02246B74.c +++ b/src/overlay006/ov6_02246B74.c @@ -1,7 +1,7 @@ #include #include -#include "unk_0201378C.h" +#include "rtc.h" #include "overlay006/ov6_02246B74.h" typedef struct { @@ -126,7 +126,7 @@ int ov6_02246B74 (const int param0, const BOOL param1) return 0; } - sub_020138A4(&v2); + GetCurrentDate(&v2); GF_ASSERT(v2.month > 0); GF_ASSERT(v2.month <= 12); diff --git a/src/overlay026/ov26_022561C0.c b/src/overlay026/ov26_022561C0.c index 800ad15b51..aaaebef433 100644 --- a/src/overlay026/ov26_022561C0.c +++ b/src/overlay026/ov26_022561C0.c @@ -12,7 +12,7 @@ #include "overlay026/struct_ov26_02256404_1.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "overlay025/ov25_02253CE0.h" #include "overlay025/ov25_02255ACC.h" @@ -85,7 +85,7 @@ static BOOL ov26_0225621C (UnkStruct_ov26_0225621C * param0, UnkStruct_ov25_0225 param0->unk_07 = 0; param0->unk_14.unk_0C = 0; - sub_02013880(&(param0->unk_14.unk_00)); + GetCurrentTime(&(param0->unk_14.unk_00)); if (param0->unk_14.unk_00.hour >= 24) { param0->unk_14.unk_00.hour %= 24; @@ -203,7 +203,7 @@ static BOOL ov26_02256370 (UnkStruct_ov26_0225621C * param0) if (ov26_022564CC(param0->unk_24, 1)) { param0->unk_06 = param0->unk_14.unk_00.minute; param0->unk_05 = param0->unk_14.unk_00.hour; - sub_02013880(&(param0->unk_14.unk_00)); + GetCurrentTime(&(param0->unk_14.unk_00)); if ((param0->unk_06 != param0->unk_14.unk_00.minute) || (param0->unk_05 != param0->unk_14.unk_00.hour)) { ov26_022564A8(param0->unk_24, 1); diff --git a/src/overlay030/ov30_022561C0.c b/src/overlay030/ov30_022561C0.c index 886ec8a1d1..2b60bd750f 100644 --- a/src/overlay030/ov30_022561C0.c +++ b/src/overlay030/ov30_022561C0.c @@ -12,7 +12,7 @@ #include "overlay030/struct_ov30_022563EC_1.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "overlay025/ov25_02253CE0.h" #include "overlay025/ov25_02255ACC.h" @@ -84,7 +84,7 @@ static BOOL ov30_0225621C (UnkStruct_ov30_0225621C * param0, UnkStruct_ov25_0225 param0->unk_06 = 0; param0->unk_14.unk_0C = 0; - sub_02013880(&(param0->unk_14.unk_00)); + GetCurrentTime(&(param0->unk_14.unk_00)); if (param0->unk_14.unk_00.hour >= 24) { param0->unk_14.unk_00.hour %= 24; @@ -201,7 +201,7 @@ static BOOL ov30_02256364 (UnkStruct_ov30_0225621C * param0) if (ov30_02256488(param0->unk_24, 1)) { param0->unk_05 = param0->unk_14.unk_00.minute; - sub_02013880(&(param0->unk_14.unk_00)); + GetCurrentTime(&(param0->unk_14.unk_00)); if (param0->unk_05 != param0->unk_14.unk_00.minute) { ov30_02256464(param0->unk_24, 1); diff --git a/src/overlay045/ov45_022561C0.c b/src/overlay045/ov45_022561C0.c index a58785a8fe..2e13d3fe68 100644 --- a/src/overlay045/ov45_022561C0.c +++ b/src/overlay045/ov45_022561C0.c @@ -13,7 +13,7 @@ #include "overlay045/struct_ov45_022566EC_1.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_02056720.h" #include "overlay025/ov25_02253CE0.h" @@ -127,7 +127,7 @@ static void ov45_022562C0 (UnkStruct_ov45_022566EC_1 * param0) { RTCTime v0; - sub_02013880(&v0); + GetCurrentTime(&v0); if (v0.hour >= 24) { v0.hour %= 24; @@ -398,7 +398,7 @@ static BOOL ov45_02256664 (UnkStruct_ov45_022561D4 * param0) static void ov45_02256668 (UnkStruct_ov45_022561D4 * param0) { if (param0->unk_2C == 0) { - sub_02013880(&(param0->unk_20)); + GetCurrentTime(&(param0->unk_20)); param0->unk_30 = 1; } } diff --git a/src/overlay050/ov50_022561C0.c b/src/overlay050/ov50_022561C0.c index 876b629f69..1ef5f661b9 100644 --- a/src/overlay050/ov50_022561C0.c +++ b/src/overlay050/ov50_022561C0.c @@ -13,7 +13,7 @@ #include "overlay050/struct_ov50_02256510_1.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_02056720.h" #include "overlay025/ov25_02253CE0.h" @@ -115,7 +115,7 @@ static BOOL ov50_0225621C (UnkStruct_ov50_022561D4 * param0, UnkStruct_ov25_0225 }; RTCDate v1; - sub_020138A4(&v1); + GetCurrentDate(&v1); param0->unk_98 = ov25_02254540(param1); ov50_022562AC(&(param0->unk_04), param0, &v1); diff --git a/src/overlay065/ov65_0222DCE0.c b/src/overlay065/ov65_0222DCE0.c index cb2f51611d..a47f298111 100644 --- a/src/overlay065/ov65_0222DCE0.c +++ b/src/overlay065/ov65_0222DCE0.c @@ -64,7 +64,7 @@ #include "unk_0200DA60.h" #include "unk_0200F174.h" #include "unk_02012744.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02013A04.h" #include "unk_02017728.h" #include "heap.h" @@ -3822,7 +3822,7 @@ static void ov65_02231A0C (void) ov4_021D2584(0); if (ov65_02231A54() == 0) { - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = 1085; } else { v0 = 1086; diff --git a/src/overlay067/ov67_0225C700.c b/src/overlay067/ov67_0225C700.c index a14835e228..d12e8ed92e 100644 --- a/src/overlay067/ov67_0225C700.c +++ b/src/overlay067/ov67_0225C700.c @@ -36,7 +36,7 @@ #include "unk_0200B358.h" #include "unk_0200DA60.h" #include "unk_0200F174.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02017728.h" #include "heap.h" #include "unk_02018340.h" @@ -286,7 +286,7 @@ int ov67_0225C820 (UnkStruct_020067E8 * param0, int * param1) } { - v1->unk_0C->unk_00 = sub_020138EC(); + v1->unk_0C->unk_00 = GetTimestamp(); } v1->unk_10 = 1; diff --git a/src/overlay077/ov77_021D6C70.c b/src/overlay077/ov77_021D6C70.c index 3660536c94..3219d035b6 100644 --- a/src/overlay077/ov77_021D6C70.c +++ b/src/overlay077/ov77_021D6C70.c @@ -11,7 +11,7 @@ #include "spl.h" #include "unk_0200762C.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02014000.h" #include "heap.h" #include "unk_02020020.h" @@ -120,7 +120,7 @@ void ov77_021D6CFC (UnkStruct_ov77_021D6CFC * param0) int v6, v7; RTCTime v8; - sub_02013880(&v8); + GetCurrentTime(&v8); v6 = (v8.hour * v8.minute + v8.second) & 1; v7 = v8.second % 3; diff --git a/src/overlay088/ov88_0223B140.c b/src/overlay088/ov88_0223B140.c index 9c9d07cae6..e1c08eeaf0 100644 --- a/src/overlay088/ov88_0223B140.c +++ b/src/overlay088/ov88_0223B140.c @@ -59,7 +59,7 @@ #include "unk_0200DA60.h" #include "unk_0200F174.h" #include "unk_020131EC.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02013A04.h" #include "unk_02017728.h" #include "heap.h" @@ -336,7 +336,7 @@ int ov88_0223B140 (UnkStruct_020067E8 * param0, int * param1) sub_02038A1C(26, v0->unk_174); sub_02039734(); - if (sub_02013948() == 0) { + if (IsNight() == 0) { sub_02004550(4, 1085, 1); sub_02004A84(1085); } else { diff --git a/src/overlay097/ov97_0222C174.c b/src/overlay097/ov97_0222C174.c index f7d67a27fd..90587c7f48 100644 --- a/src/overlay097/ov97_0222C174.c +++ b/src/overlay097/ov97_0222C174.c @@ -40,7 +40,7 @@ #include "unk_0200B29C.h" #include "unk_0200B358.h" #include "unk_0200DA60.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_02018340.h" #include "unk_0201D670.h" @@ -840,7 +840,7 @@ static void ov97_0222C974 (UnkStruct_ov97_0222C388 * param0) v4->unk_34A[1] = 0; v4->unk_34A[2] = 0; v4->unk_350 = 0; - sub_020138A4(&v0); + GetCurrentDate(&v0); v4->unk_354 = RTC_ConvertDateToDay(&v0); sub_0200B3F0(v2); diff --git a/src/overlay097/ov97_0222D30C.c b/src/overlay097/ov97_0222D30C.c index 31dc13aeaf..9f8ecddb48 100644 --- a/src/overlay097/ov97_0222D30C.c +++ b/src/overlay097/ov97_0222D30C.c @@ -50,7 +50,7 @@ #include "unk_0200D9E8.h" #include "unk_0200DA60.h" #include "unk_0200F174.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02013A04.h" #include "unk_02017728.h" #include "heap.h" @@ -460,7 +460,7 @@ static void ov97_0222D658 (UnkStruct_020067E8 * param0) v4->val2.unk_348 = 0; } - sub_020138A4(&v7); + GetCurrentDate(&v7); v4->val2.unk_354 = RTC_ConvertDateToDay(&v7); } diff --git a/src/pokemon.c b/src/pokemon.c index 736dec94f7..d69eb70705 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -31,7 +31,7 @@ #include "message.h" #include "unk_0200B29C.h" #include "unk_0200C6E4.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02015F84.h" #include "unk_02017038.h" #include "heap.h" @@ -3136,13 +3136,13 @@ u16 sub_02076B94(Party *party, Pokemon *mon, u8 evoTypeList, u16 evoParam, int * } break; case 2: // high friendship && daytime - if (sub_02013948() == 0 && 220 <= monFriendship) { + if (IsNight() == 0 && 220 <= monFriendship) { targetSpecies = monEvolutionData->methods[i].targetSpecies; evoTypeResult[0] = 2; } break; case 3: // high friendship && nighttime - if (sub_02013948() == 1 && 220 <= monFriendship) { + if (IsNight() == 1 && 220 <= monFriendship) { targetSpecies = monEvolutionData->methods[i].targetSpecies; evoTypeResult[0] = 3; } @@ -3209,13 +3209,13 @@ u16 sub_02076B94(Party *party, Pokemon *mon, u8 evoTypeList, u16 evoParam, int * } break; case 18: // happiny evo: hold param && daytime - if (sub_02013948() == 0 && monEvolutionData->methods[i].param == monHeldItem) { + if (IsNight() == 0 && monEvolutionData->methods[i].param == monHeldItem) { targetSpecies = monEvolutionData->methods[i].targetSpecies; evoTypeResult[0] = 18; } break; case 19: // sneasel and gligar evo: hold param && nighttime - if (sub_02013948() == 1 && monEvolutionData->methods[i].param == monHeldItem) { + if (IsNight() == 1 && monEvolutionData->methods[i].param == monHeldItem) { targetSpecies = monEvolutionData->methods[i].targetSpecies; evoTypeResult[0] = 19; } @@ -4033,7 +4033,7 @@ BOOL Pokemon_CanShayminSkyForm(Pokemon *mon) u32 monFatefulEncounter = Pokemon_GetValue(mon, MON_DATA_FATEFUL_ENCOUNTER, NULL); RTCTime rtcTime; - sub_02013880(&rtcTime); + GetCurrentTime(&rtcTime); return (monSpecies == SPECIES_SHAYMIN && monForm == 0 diff --git a/src/rtc.c b/src/rtc.c new file mode 100644 index 0000000000..6b40d23997 --- /dev/null +++ b/src/rtc.c @@ -0,0 +1,192 @@ +#include +#include +#include + +#include "inlines.h" + +#include "rtc.h" + +typedef struct { + BOOL valid; + BOOL readInProgress; + int framesSinceRead; + RTCResult status; + RTCDate date; + RTCTime time; + RTCDate tempDate; + RTCTime tempTime; +} RTCState; + +static void GetTimeCallback(RTCResult param0, void * param1); +static void StartRTCRead(RTCState * param0); + +static RTCState sRTCState; + +void InitRTC (void) +{ + RTC_Init(); + memset(&sRTCState, 0, sizeof(sRTCState)); + sRTCState.valid = 0; + sRTCState.readInProgress = 0; + sRTCState.framesSinceRead = 0; + StartRTCRead(&sRTCState); +} + +void UpdateRTC (void) +{ + if (sRTCState.readInProgress) { + return; + } + + sRTCState.framesSinceRead++; + + if (sRTCState.framesSinceRead > 10) { + sRTCState.framesSinceRead = 0; + StartRTCRead(&sRTCState); + } +} + +static void GetTimeCallback (RTCResult result, void * data) +{ + RTCState * state = data; + + state->status = result; + + GF_ASSERT(result == RTC_RESULT_SUCCESS); + + state->valid = 1; + state->date = state->tempDate; + state->time = state->tempTime; + state->readInProgress = 0; +} + +static void StartRTCRead (RTCState * param0) +{ + param0->readInProgress = 1; + param0->status = RTC_GetDateTimeAsync(¶m0->tempDate, ¶m0->tempTime, GetTimeCallback, param0); + GF_ASSERT(param0->status == RTC_RESULT_SUCCESS); +} + +void GetCurrentDateTime (RTCDate * date, RTCTime * time) +{ + GF_ASSERT(sRTCState.valid == 1); + + *date = sRTCState.date; + *time = sRTCState.time; +} + +void GetCurrentTime (RTCTime * time) +{ + GF_ASSERT(sRTCState.valid == 1); + *time = sRTCState.time; +} + +void GetCurrentDate (RTCDate * date) +{ + GF_ASSERT(sRTCState.valid == 1); + *date = sRTCState.date; +} + +int GetSecondsSinceMidnight (void) +{ + RTCTime * time = &sRTCState.time; + + return time->hour * 60 * 60 + time->minute * 60 + time->second; +} + +s64 GetTimestamp (void) +{ + return RTC_ConvertDateTimeToSecond(&sRTCState.date, &sRTCState.time); +} + +int DayNumberForDate (const RTCDate * date) +{ + int year, days; + static const u16 monthStart[12] = { + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 + }; + + days = date->day; + days += monthStart[date->month - 1]; + + if (date->month >= 3) { + year = date->year; + + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { + days++; + } + } + + return days; +} + +BOOL IsNight (void) +{ + switch (GetTimeOfDay()) { + case TOD_LATE_NIGHT: + case TOD_NIGHT: + return 1; + } + + return 0; +} + +enum TimeOfDay GetTimeOfDay (void) +{ + RTCTime time; + + GetCurrentTime(&time); + return TimeOfDayForHour(time.hour); +} + +enum TimeOfDay TimeOfDayForHour (int hour) +{ + static const u8 lookup[24] = { + TOD_LATE_NIGHT, + TOD_LATE_NIGHT, + TOD_LATE_NIGHT, + TOD_LATE_NIGHT, + TOD_MORNING, + TOD_MORNING, + TOD_MORNING, + TOD_MORNING, + TOD_MORNING, + TOD_MORNING, + TOD_DAY, + TOD_DAY, + TOD_DAY, + TOD_DAY, + TOD_DAY, + TOD_DAY, + TOD_DAY, + TOD_TWILIGHT, + TOD_TWILIGHT, + TOD_TWILIGHT, + TOD_NIGHT, + TOD_NIGHT, + TOD_NIGHT, + TOD_NIGHT, + }; + + GF_ASSERT(0 <= hour && hour < 24); + return lookup[hour]; +} + +#define MAX_TIMESTAMP 3155759999 + +s64 TimeElapsed (s64 since, s64 until) +{ + RTCDate maxDate = {99, 12, 31, 0}; + RTCTime maxTime = {23, 59, 59}; + s64 maxTimestamp = RTC_ConvertDateTimeToSecond(&maxDate, &maxTime); + + GF_ASSERT(maxTimestamp == MAX_TIMESTAMP); + + if (since < until) { + return until - since; + } else { + // BUG: This loses one second when rolling over. + // e.g. TimeElapsed(MAX_TIMESTAMP, 0) == 0 + return until + (MAX_TIMESTAMP - since); + } +} diff --git a/src/unk_0201378C.c b/src/unk_0201378C.c deleted file mode 100644 index a6f9bf90a6..0000000000 --- a/src/unk_0201378C.c +++ /dev/null @@ -1,212 +0,0 @@ -#include -#include -#include - -#include "inlines.h" - -#include "unk_0201378C.h" - -typedef struct { - BOOL unk_00; - BOOL unk_04; - int unk_08; - RTCResult unk_0C; - RTCDate unk_10; - RTCTime unk_20; - RTCDate unk_2C; - RTCTime unk_3C; -} UnkStruct_021BF5C8; - -static void sub_020137EC(RTCResult param0, void * param1); -static void sub_02013824(UnkStruct_021BF5C8 * param0); - -static UnkStruct_021BF5C8 Unk_021BF5C8; - -void sub_0201378C (void) -{ - RTC_Init(); - memset(&Unk_021BF5C8, 0, sizeof(Unk_021BF5C8)); - Unk_021BF5C8.unk_00 = 0; - Unk_021BF5C8.unk_04 = 0; - Unk_021BF5C8.unk_08 = 0; - sub_02013824(&Unk_021BF5C8); -} - -void sub_020137C4 (void) -{ - RTCResult v0; - - if (Unk_021BF5C8.unk_04) { - return; - } - - Unk_021BF5C8.unk_08++; - - if (Unk_021BF5C8.unk_08 > 10) { - Unk_021BF5C8.unk_08 = 0; - sub_02013824(&Unk_021BF5C8); - } -} - -static void sub_020137EC (RTCResult param0, void * param1) -{ - UnkStruct_021BF5C8 * v0 = param1; - - v0->unk_0C = param0; - - GF_ASSERT(param0 == RTC_RESULT_SUCCESS); - - v0->unk_00 = 1; - v0->unk_10 = v0->unk_2C; - v0->unk_20 = v0->unk_3C; - v0->unk_04 = 0; -} - -static void sub_02013824 (UnkStruct_021BF5C8 * param0) -{ - param0->unk_04 = 1; - param0->unk_0C = RTC_GetDateTimeAsync(¶m0->unk_2C, ¶m0->unk_3C, sub_020137EC, param0); - GF_ASSERT(param0->unk_0C == RTC_RESULT_SUCCESS); -} - -static inline RTCDate * inline_0201384C (UnkStruct_021BF5C8 * param0) -{ - return ¶m0->unk_10; -} - -static inline RTCTime * inline_02013880 (UnkStruct_021BF5C8 * param0) -{ - return ¶m0->unk_20; -} - -void sub_0201384C (RTCDate * param0, RTCTime * param1) -{ - GF_ASSERT(Unk_021BF5C8.unk_00 == 1); - - *param0 = *inline_0201384C(&Unk_021BF5C8); - *param1 = *inline_02013880(&Unk_021BF5C8); -} - -void sub_02013880 (RTCTime * param0) -{ - GF_ASSERT(Unk_021BF5C8.unk_00 == 1); - *param0 = *inline_02013880(&Unk_021BF5C8); -} - -void sub_020138A4 (RTCDate * param0) -{ - GF_ASSERT(Unk_021BF5C8.unk_00 == 1); - *param0 = *inline_0201384C(&Unk_021BF5C8); -} - -int sub_020138C8 (void) -{ - RTCTime * v0; - - v0 = inline_02013880(&Unk_021BF5C8); - return v0->hour * 60 * 60 + v0->minute * 60 + v0->second; -} - -s64 sub_020138EC (void) -{ - return RTC_ConvertDateTimeToSecond(inline_0201384C(&Unk_021BF5C8), inline_02013880(&Unk_021BF5C8)); -} - -int sub_02013900 (const RTCDate * param0) -{ - int v0, v1, v2; - static const u16 v3[12] = { - 0x0, - 0x1F, - 0x3B, - 0x5A, - 0x78, - 0x97, - 0xB5, - 0xD4, - 0xF3, - 0x111, - 0x130, - 0x14E - }; - - v1 = param0->day; - v1 += v3[param0->month - 1]; - - if (param0->month >= 3) { - v0 = param0->year; - - if (((v0 % 4 == 0) && (v0 % 100 != 0)) || (v0 % 400 == 0)) { - v1++; - } - } - - return v1; -} - -BOOL sub_02013948 (void) -{ - switch (sub_02013960()) { - case 4: - case 3: - return 1; - } - - return 0; -} - -int sub_02013960 (void) -{ - RTCTime v0; - - sub_02013880(&v0); - return sub_02013974(v0.hour); -} - -int sub_02013974 (int param0) -{ - static const u8 v0[24] = { - 0x4, - 0x4, - 0x4, - 0x4, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x0, - 0x1, - 0x1, - 0x1, - 0x1, - 0x1, - 0x1, - 0x1, - 0x2, - 0x2, - 0x2, - 0x3, - 0x3, - 0x3, - 0x3 - }; - - GF_ASSERT(0 <= param0 && param0 < 24); - return v0[param0]; -} - -s64 sub_0201398C (s64 param0, s64 param1) -{ - RTCDate v0 = {99, 12, 31, 0}; - RTCTime v1 = {23, 59, 59}; - s64 v2 = RTC_ConvertDateTimeToSecond(&v0, &v1); - - GF_ASSERT(v2 == 3155759999); - - if (param0 < param1) { - return param1 - param0; - } - - return param1 + (3155759999 - param0); -} diff --git a/src/unk_02025CB0.c b/src/unk_02025CB0.c index 8d472f3ca4..38e313373d 100644 --- a/src/unk_02025CB0.c +++ b/src/unk_02025CB0.c @@ -4,7 +4,7 @@ #include "struct_decls/struct_021C0794_decl.h" #include "struct_defs/struct_02055BA8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_020244AC.h" #include "unk_02025CB0.h" @@ -113,7 +113,7 @@ void sub_02025D78 (UnkStruct_02025CCC * param0, s32 param1) void sub_02025D84 (UnkStruct_02055BA8 * param0) { param0->unk_00 = 1; - sub_0201384C(¶m0->unk_04, ¶m0->unk_14); + GetCurrentDateTime(¶m0->unk_04, ¶m0->unk_14); param0->unk_20 = RTC_ConvertDateToDay(¶m0->unk_04); param0->unk_24 = RTC_ConvertDateTimeToSecond(¶m0->unk_04, ¶m0->unk_14); param0->unk_2C = 0; @@ -145,6 +145,6 @@ void sub_02025DC8 (UnkStruct_02055BA8 * param0, int param1) void sub_02025DE8 (UnkStruct_02055BA8 * param0) { param0->unk_34 = 60 * 24; - sub_0201384C(¶m0->unk_04, ¶m0->unk_14); + GetCurrentDateTime(¶m0->unk_04, ¶m0->unk_14); param0->unk_20 = RTC_ConvertDateToDay(¶m0->unk_04); } diff --git a/src/unk_0202854C.c b/src/unk_0202854C.c index 49694d7d03..818f42eb62 100644 --- a/src/unk_0202854C.c +++ b/src/unk_0202854C.c @@ -12,7 +12,7 @@ #include "struct_defs/struct_02029894_sub2.h" #include "struct_defs/struct_020298B0.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_0201D15C.h" #include "unk_020244AC.h" @@ -103,7 +103,7 @@ void Underground_Init (UnkStruct_020298B0 * param0) RTCDate v1; RTCTime v2; - sub_0201384C(&v1, &v2); + GetCurrentDateTime(&v1, &v2); v0 = (((((((u32)v1.year * 32ULL + v1.month) * 32ULL) + v1.day) * 32ULL + v2.hour) * 32ULL + v2.minute) * 32ULL + (v2.second + gCoreSys.frameCounter)); MI_CpuFill8(param0, 0, sizeof(UnkStruct_020298B0)); diff --git a/src/unk_0202ACE0.c b/src/unk_0202ACE0.c index 65e81eae0a..a7554f3029 100644 --- a/src/unk_0202ACE0.c +++ b/src/unk_0202ACE0.c @@ -10,7 +10,7 @@ #include "struct_defs/struct_0202B370.h" #include "struct_defs/struct_0202B370_sub1.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "strbuf.h" #include "unk_020244AC.h" #include "unk_0202ACE0.h" @@ -251,7 +251,7 @@ void sub_0202B13C (UnkStruct_0202B370 * param0, int param1) { RTCDate v0; - sub_020138A4(&v0); + GetCurrentDate(&v0); param0->unk_1C0[param1].unk_2A = v0.year + 2000; param0->unk_1C0[param1].unk_2C = v0.month; diff --git a/src/unk_0202B604.c b/src/unk_0202B604.c index c4ee52a541..0494274dc2 100644 --- a/src/unk_0202B604.c +++ b/src/unk_0202B604.c @@ -11,7 +11,7 @@ #include "struct_defs/struct_0202BF4C.h" #include "struct_defs/struct_0202BFCC.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_020244AC.h" #include "trainer_info.h" @@ -146,7 +146,7 @@ UnkStruct_0202B628 * sub_0202B634 (UnkStruct_0202B628 * param0, BOOL param1) return NULL; } - sub_020138A4(&v0); + GetCurrentDate(&v0); if ((param0[0].unk_00.unk_00_7 != 0) && ((param0[0].unk_00.unk_00_0 != v0.year) || (param0[0].unk_00.unk_00_7 != v0.month) || (param0[0].unk_00.unk_00_14 != v0.day) || (param0[0].unk_00.unk_00_11 != v0.week))) { for (v1 = 10 - 1; v1 >= 1; v1--) { @@ -169,14 +169,14 @@ BOOL sub_0202B6A4 (UnkStruct_0202B628 * param0, BOOL param1) return 0; } - sub_020138A4(&v1); + GetCurrentDate(&v1); v0.year = param0[0].unk_00.unk_00_0; v0.month = param0[0].unk_00.unk_00_7; v0.day = param0[0].unk_00.unk_00_14; v0.week = param0[0].unk_00.unk_00_11; - v2 = sub_02013900(&v1) - sub_02013900(&v0); + v2 = DayNumberForDate(&v1) - DayNumberForDate(&v0); if (((v1.month == 12) && (v1.day == 31) && (v0.month == 1) && (v0.day == 1)) || ((v1.month == 1) && (v1.day == 1) && (v0.month == 12) && (v0.day == 31))) { s32 v3 = (s32)v1.year - (s32)v0.year; @@ -580,7 +580,7 @@ void * sub_0202BC58 (u16 param0, u32 param1) RTCDate v1; v0 = Heap_AllocFromHeap(param1, sizeof(UnkStruct_0202BC58)); - sub_020138A4(&v1); + GetCurrentDate(&v1); v0->unk_00_0 = v1.year; v0->unk_00_7 = v1.month; diff --git a/src/unk_0202E2CC.c b/src/unk_0202E2CC.c index 527c546b2b..b70e1c14cf 100644 --- a/src/unk_0202E2CC.c +++ b/src/unk_0202E2CC.c @@ -17,7 +17,7 @@ #include "struct_defs/struct_0202E828.h" #include "struct_defs/struct_0202E834.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_020244AC.h" #include "unk_0202E2CC.h" @@ -144,7 +144,7 @@ static void sub_0202E3F4 (UnkStruct_0202E4D4 * param0, int param1, const u8 * pa { RTCDate v0; - sub_020138A4(&v0); + GetCurrentDate(&v0); param0->unk_04 = inline_0202D4B0(&v0); param0->unk_00 = param1; diff --git a/src/unk_0202EEC0.c b/src/unk_0202EEC0.c index 7301143ba3..253ebf3826 100644 --- a/src/unk_0202EEC0.c +++ b/src/unk_0202EEC0.c @@ -3,7 +3,7 @@ #include "pokemon.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_0202EEC0.h" #include "pokemon.h" @@ -83,7 +83,7 @@ void sub_0202EFB8 (PalParkTransfer * param0, u32 param1) int v0 = sub_0202EF40(param0, param1); param0->unk_288[v0] = param1; - param0->unk_2D8[v0] = sub_020138EC(); + param0->unk_2D8[v0] = GetTimestamp(); param0->unk_378 = OS_GetOwnerRtcOffset(); OS_GetMacAddress(param0->unk_380); @@ -111,7 +111,7 @@ int sub_0202F028 (const PalParkTransfer * param0) int sub_0202F050 (const PalParkTransfer * param0, u32 param1) { int v0; - s64 v1 = sub_020138EC(); + s64 v1 = GetTimestamp(); for (v0 = 0; v0 < 20; v0++) { if (param0->unk_288[v0] == param1) { diff --git a/src/unk_02034198.c b/src/unk_02034198.c index 7ac0bd5e39..8650988c3f 100644 --- a/src/unk_02034198.c +++ b/src/unk_02034198.c @@ -12,7 +12,7 @@ #include "struct_defs/struct_0203233C.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_02030EE0.h" #include "unk_02032188.h" @@ -1876,7 +1876,7 @@ void sub_020361BC (MATHRandContext32 * param0) RTCDate v1; RTCTime v2; - sub_0201384C(&v1, &v2); + GetCurrentDateTime(&v1, &v2); v0 = (((((((u64)v1.year * 16ULL + v1.month) * 32ULL) + v1.day) * 32ULL + v2.hour) * 64ULL + v2.minute) * 64ULL + (v2.second + gCoreSys.frameCounter)); MATH_InitRand32(param0, v0); } diff --git a/src/unk_0203A944.c b/src/unk_0203A944.c index 784e96024d..6b339dc7df 100644 --- a/src/unk_0203A944.c +++ b/src/unk_0203A944.c @@ -6,7 +6,7 @@ #include "struct_defs/struct_0203CDB0.h" #include "struct_defs/struct_02055BA8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02025CB0.h" #include "map_header.h" #include "unk_0203A944.h" @@ -1860,7 +1860,7 @@ int sub_0203A944 (UnkStruct_0203CDB0 * param0, int param1) int v1; UnkStruct_02055BA8 * v2 = sub_02025CD8(param0->unk_0C); - v1 = sub_02013900(&v2->unk_04) - 1; + v1 = DayNumberForDate(&v2->unk_04) - 1; GF_ASSERT(v1 >= 0 && v1 < 366); if ((v2->unk_04.month > 2) && !inline_0203A944(v2->unk_04.year)) { diff --git a/src/unk_0203D1B8.c b/src/unk_0203D1B8.c index f98e101fbf..83dff3b133 100644 --- a/src/unk_0203D1B8.c +++ b/src/unk_0203D1B8.c @@ -67,7 +67,7 @@ #include "overlay088/struct_ov88_0223C370.h" #include "overlay090/struct_ov90_021D0D80.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02017498.h" #include "heap.h" #include "unk_0201D15C.h" @@ -1594,9 +1594,9 @@ static BOOL sub_0203E35C (UnkStruct_020508D4 * param0) case 1: if (sub_020509B4(v0) == 0) { u16 * v5 = sub_02025E50(v0->unk_0C); - s64 v6 = sub_020138EC(); + s64 v6 = GetTimestamp(); - sub_0206DD38(v0, Coins_GetValue(v5), v2->unk_00, sub_0201398C(v2->unk_04, v6) / 60); + sub_0206DD38(v0, Coins_GetValue(v5), v2->unk_00, TimeElapsed(v2->unk_04, v6) / 60); Coins_SetValue(sub_02025E50(v0->unk_0C), v2->unk_00); v4 = sub_0206B394(v1); @@ -1622,7 +1622,7 @@ void sub_0203E414 (UnkStruct_020508D4 * param0, int param1) v2->unk_0C.unk_00 = &v2->unk_00; v2->unk_00 = Coins_GetValue(sub_02025E50(v0->unk_0C)); - v2->unk_04 = sub_020138EC(); + v2->unk_04 = GetTimestamp(); v2->unk_0C.unk_08 = sub_0202CD88(v0->unk_0C); v2->unk_0C.unk_0C = 0; v2->unk_0C.unk_10 = sub_02027B50(v1); diff --git a/src/unk_0203F6C4.c b/src/unk_0203F6C4.c index e963bd8616..59691300b8 100644 --- a/src/unk_0203F6C4.c +++ b/src/unk_0203F6C4.c @@ -77,7 +77,7 @@ #include "unk_0200D9E8.h" #include "unk_0200DA60.h" #include "unk_0200F174.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02014D38.h" #include "heap.h" #include "unk_02018340.h" @@ -6750,7 +6750,7 @@ static BOOL sub_02044EDC (UnkStruct_0203E724 * param0) RTCDate v0; u16 * v1 = inline_0204FCAC(param0); - sub_020138A4(&v0); + GetCurrentDate(&v0); *v1 = v0.week; return 0; @@ -8435,7 +8435,7 @@ static BOOL sub_0204698C (UnkStruct_0203E724 * param0) s64 v2; s64 v3; - v2 = sub_020138EC(); + v2 = GetTimestamp(); v3 = v2 - v0->unk_C4.unk_00; if (v3 >= 120) { diff --git a/src/unk_02051D8C.c b/src/unk_02051D8C.c index dd84a001b5..2ddec6b85d 100644 --- a/src/unk_02051D8C.c +++ b/src/unk_02051D8C.c @@ -28,7 +28,7 @@ #include "unk_020021B0.h" #include "message.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "strbuf.h" #include "savedata/save_table.h" @@ -119,7 +119,7 @@ BattleParams * sub_02051D8C (int param0, u32 param1) RTCDate v2; RTCTime v3; - sub_0201384C(&v2, &v3); + GetCurrentDateTime(&v2, &v3); v1->unk_174 = v2.year + v2.month * 0x100 * v2.day * 0x10000 + v3.hour * 0x10000 + (v3.minute + v3.second) * 0x1000000 + gCoreSys.frameCounter; } @@ -269,7 +269,7 @@ void sub_020521B8 (BattleParams * param0, const UnkStruct_0203CDB0 * param1, Sav { UnkStruct_02055BA8 * v7 = sub_02025CD8(param2); - param0->unk_138 = sub_02013974(v7->unk_14.hour); + param0->unk_138 = TimeOfDayForHour(v7->unk_14.hour); } } diff --git a/src/unk_02052C6C.c b/src/unk_02052C6C.c index 32d14b292d..e45439e02d 100644 --- a/src/unk_02052C6C.c +++ b/src/unk_02052C6C.c @@ -27,7 +27,7 @@ #include "unk_0200B358.h" #include "unk_0200DA60.h" #include "unk_0200F174.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_02018340.h" #include "gx_layers.h" @@ -85,7 +85,7 @@ static void sub_02052C6C (UnkStruct_0203CDB0 * param0, BOOL param1) v1 = Party_GetFromSavedata(param0->unk_0C); - sub_020138A4(&v2); + GetCurrentDate(&v2); sub_0202DFA8(v0, v1, &v2); SaveData_SaveHallOfFame(param0->unk_0C, v0); Heap_FreeToHeap(v0); diff --git a/src/unk_020553DC.c b/src/unk_020553DC.c index 3c22e64821..e80928e273 100644 --- a/src/unk_020553DC.c +++ b/src/unk_020553DC.c @@ -9,7 +9,7 @@ #include "unk_020041CC.h" #include "unk_02005474.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "map_header.h" #include "unk_0203A6DC.h" #include "unk_020507CC.h" @@ -185,7 +185,7 @@ u16 sub_020554A4 (UnkStruct_0203CDB0 * param0, int param1) { u16 v0, v1; - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = MapHeader_GetDayMusicID(param1); } else { v0 = MapHeader_GetNightMusicID(param1); diff --git a/src/unk_020559DC.c b/src/unk_020559DC.c index c787cdbac2..2a5f9b35c9 100644 --- a/src/unk_020559DC.c +++ b/src/unk_020559DC.c @@ -10,7 +10,7 @@ #include "struct_defs/struct_0203CDB0.h" #include "struct_defs/struct_02055BA8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "savedata/save_table.h" #include "unk_02025CB0.h" #include "unk_0202854C.h" @@ -45,7 +45,7 @@ void sub_020559DC (UnkStruct_0203CDB0 * param0) return; } - sub_0201384C(&v0, &v1); + GetCurrentDateTime(&v0, &v1); sub_02055A14(param0, v2, &v0); inline_020559DC(param0, v2, &v0, &v1); @@ -154,7 +154,7 @@ static void sub_02055B64 (UnkStruct_0203CDB0 * param0, s32 param1, const RTCTime int sub_02055BA8 (const UnkStruct_0203CDB0 * param0) { UnkStruct_02055BA8 * v0 = sub_02025CD8(param0->unk_0C); - return sub_02013974(v0->unk_14.hour); + return TimeOfDayForHour(v0->unk_14.hour); } int sub_02055BB8 (const UnkStruct_0203CDB0 * param0) @@ -203,7 +203,7 @@ void sub_02055C2C (const UnkStruct_0203CDB0 * param0) { UnkStruct_02055BA8 * v0 = sub_02025CD8(param0->unk_0C); - v0->unk_2C = sub_020138EC(); + v0->unk_2C = GetTimestamp(); } BOOL sub_02055C40 (UnkStruct_0203CDB0 * param0) diff --git a/src/unk_020562F8.c b/src/unk_020562F8.c index ce45053df2..7518dd18fe 100644 --- a/src/unk_020562F8.c +++ b/src/unk_020562F8.c @@ -12,7 +12,7 @@ #include "overlay006/battle_params.h" #include "narc.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "savedata/save_table.h" #include "unk_0202CD50.h" @@ -64,15 +64,15 @@ void sub_020562F8 (UnkStruct_0203CDB0 * param0) sub_0205642C(param0, v1); sub_020564D0(v1); - v1->unk_40 = sub_020138EC(); + v1->unk_40 = GetTimestamp(); } void sub_02056328 (UnkStruct_0203CDB0 * param0) { UnkStruct_020564B4 * v0 = &Unk_021C07FC; UnkStruct_0202CD88 * v1 = sub_0202CD88(param0->unk_0C); - s64 v2 = sub_020138EC(); - s64 v3 = sub_0201398C(v0->unk_40, v2); + s64 v2 = GetTimestamp(); + s64 v3 = TimeElapsed(v0->unk_40, v2); if (v3 < 1000) { v0->unk_48 = ((1000 - v3) * 2); diff --git a/src/unk_0206A8DC.c b/src/unk_0206A8DC.c index 53590996a1..3023485f05 100644 --- a/src/unk_0206A8DC.c +++ b/src/unk_0206A8DC.c @@ -3,7 +3,7 @@ #include "struct_decls/struct_020507E4_decl.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_020507CC.h" #include "unk_0206A8DC.h" @@ -273,7 +273,7 @@ u16 sub_0206AB68 (UnkStruct_020507E4 * param0, int param1) case 494: case 497: if (sub_0206A8EC(param0, (2400 + 37)) == 1) { - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = 1016; } else { v0 = 1045; @@ -292,7 +292,7 @@ u16 sub_0206AB68 (UnkStruct_020507E4 * param0, int param1) case 74: case 75: if (sub_0206A8EC(param0, (2400 + 39)) == 1) { - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = 1013; } else { v0 = 1042; @@ -301,7 +301,7 @@ u16 sub_0206AB68 (UnkStruct_020507E4 * param0, int param1) break; case 201: if (sub_0206A8EC(param0, (2400 + 40)) == 1) { - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = 1023; } else { v0 = 1052; @@ -310,7 +310,7 @@ u16 sub_0206AB68 (UnkStruct_020507E4 * param0, int param1) break; case 256: if (sub_0206A8EC(param0, (2400 + 41)) == 1) { - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = 1006; } else { v0 = 1035; @@ -319,7 +319,7 @@ u16 sub_0206AB68 (UnkStruct_020507E4 * param0, int param1) break; case 399: if (sub_0206A8EC(param0, (2400 + 42)) == 1) { - if (sub_02013948() == 0) { + if (IsNight() == 0) { v0 = 1006; } else { v0 = 1035; diff --git a/src/unk_02092494.c b/src/unk_02092494.c index ff00950354..7d255f3beb 100644 --- a/src/unk_02092494.c +++ b/src/unk_02092494.c @@ -5,7 +5,7 @@ #include "message.h" #include "unk_0200B358.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "unk_02017038.h" #include "heap.h" #include "strbuf.h" @@ -835,7 +835,7 @@ static void sub_020932F0 (BoxPokemon * param0, int param1, int param2) { RTCDate v0; - sub_020138A4(&v0); + GetCurrentDate(&v0); if (param2 == 0) { BoxPokemon_SetValue(param0, 152, ¶m1); diff --git a/src/unk_020933F8.c b/src/unk_020933F8.c index 69b1f8623a..329da8ec61 100644 --- a/src/unk_020933F8.c +++ b/src/unk_020933F8.c @@ -35,7 +35,7 @@ #include "unk_0200A9DC.h" #include "unk_0200B358.h" #include "unk_0200D9E8.h" -#include "unk_0201378C.h" +#include "rtc.h" #include "heap.h" #include "unk_0201D15C.h" #include "strbuf.h" @@ -1703,7 +1703,7 @@ void sub_02094C44 (UnkStruct_02095C48 * param0, SaveData * param1, u32 param2, U static void sub_02094E7C (UnkStruct_02095C48 * param0) { - LCRNG_SetSeed((sub_020138C8() * (LCRNG_GetSeed() + 10)) & 0xffff); + LCRNG_SetSeed((GetSecondsSinceMidnight() * (LCRNG_GetSeed() + 10)) & 0xffff); } u16 sub_02094E98 (UnkStruct_02095C48 * param0)