forked from DizzyEggg/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added OW_USE_FAKE_RTC and OW_ALTERED_TIME_RATIO (#4910)
* Added OW_USE_FAKE_RTC, OW_ALTERED_TIME_RATIO and src/fake_rtc.c * Changed ALTERED_TIME_RATIO to GEN_LATEST * Changed spaces to tabs per https://github.com/rh-hideout/pokeemerald-expansion/pull/4910/files\#r1667111624
- Loading branch information
Showing
6 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef GUARD_FAKE_RTC_UTIL_H | ||
#define GUARD_FAKE_RTC_UTIL_H | ||
|
||
#include "siirtc.h" | ||
|
||
struct Time* FakeRtc_GetCurrentTime(void); | ||
void FakeRtc_GetRawInfo(struct SiiRtcInfo *rtc); | ||
void FakeRtc_AdvanceTimeBy(u32 hours, u32 minutes, u32 seconds); | ||
void FakeRtc_ManuallySetTime(u32 hour, u32 minute, u32 second); | ||
void FakeRtc_TickTimeForward(void); | ||
u32 FakeRtc_GetSecondsRatio(void); | ||
|
||
#endif // GUARD_FAKE_RTC_UTIL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "global.h" | ||
#include "string_util.h" | ||
#include "strings.h" | ||
#include "text.h" | ||
#include "rtc.h" | ||
#include "fake_rtc.h" | ||
|
||
struct Time *FakeRtc_GetCurrentTime(void) | ||
{ | ||
#if OW_USE_FAKE_RTC | ||
return &gSaveBlock3Ptr->fakeRTC; | ||
#else | ||
return NULL; | ||
#endif | ||
} | ||
|
||
void FakeRtc_GetRawInfo(struct SiiRtcInfo *rtc) | ||
{ | ||
struct Time* time = FakeRtc_GetCurrentTime(); | ||
rtc->second = time->seconds; | ||
rtc->minute = time->minutes; | ||
rtc->hour = time->hours; | ||
rtc->day = time->days; | ||
} | ||
|
||
void FakeRtc_TickTimeForward(void) | ||
{ | ||
if (!OW_USE_FAKE_RTC) | ||
return; | ||
|
||
FakeRtc_AdvanceTimeBy(0, 0, FakeRtc_GetSecondsRatio()); | ||
} | ||
|
||
void FakeRtc_AdvanceTimeBy(u32 hours, u32 minutes, u32 seconds) | ||
{ | ||
struct Time* time = FakeRtc_GetCurrentTime(); | ||
seconds += time->seconds; | ||
minutes += time->minutes; | ||
hours += time->hours; | ||
|
||
while(seconds >= SECONDS_PER_MINUTE) | ||
{ | ||
minutes++; | ||
seconds -= SECONDS_PER_MINUTE; | ||
} | ||
|
||
while(minutes >= MINUTES_PER_HOUR) | ||
{ | ||
hours++; | ||
minutes -= MINUTES_PER_HOUR; | ||
} | ||
|
||
while(hours >= HOURS_PER_DAY) | ||
{ | ||
time->days++; | ||
hours -= HOURS_PER_DAY; | ||
} | ||
|
||
time->seconds = seconds; | ||
time->minutes = minutes; | ||
time->hours = hours; | ||
} | ||
|
||
void FakeRtc_ManuallySetTime(u32 hour, u32 minute, u32 second) | ||
{ | ||
struct Time diff, target; | ||
RtcCalcLocalTime(); | ||
|
||
target.hours = hour; | ||
target.minutes = minute; | ||
target.seconds = second; | ||
target.days = gLocalTime.days; | ||
|
||
CalcTimeDifference(&diff, &gLocalTime, &target); | ||
FakeRtc_AdvanceTimeBy(diff.hours, diff.minutes, diff.seconds); | ||
} | ||
|
||
u32 FakeRtc_GetSecondsRatio(void) | ||
{ | ||
return (OW_ALTERED_TIME_RATIO == GEN_8_PLA) ? 60 : | ||
(OW_ALTERED_TIME_RATIO == GEN_9) ? 20 : | ||
1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters