diff --git a/payload/include/berry_fix_save.h b/payload/include/berry_fix_save.h index b657619..7a2d75b 100644 --- a/payload/include/berry_fix_save.h +++ b/payload/include/berry_fix_save.h @@ -1,6 +1,15 @@ #ifndef GUARD_BERRY_FIX_SAVE_H #define GUARD_BERRY_FIX_SAVE_H +#include "save.h" + +enum +{ + SAVE_NORMAL, // Save full save slot + SAVE_SAVEBLOCKS, // Save just SaveBlock1 and SaveBlock2 + SAVE_SAVEBLOCK2, // Save just SaveBlock2 +}; + bool32 BerryFix_IdentifyFlash(void); u8 BerryFix_TrySave(u8 mode); bool8 BerryFix_LoadSave(u32); diff --git a/payload/include/event_data.h b/payload/include/event_data.h new file mode 100644 index 0000000..db83834 --- /dev/null +++ b/payload/include/event_data.h @@ -0,0 +1,7 @@ +#ifndef GUARD_EVENT_DATA_H +#define GUARD_EVENT_DATA_H + +bool32 BerryFix_ShouldResetPacifidlogTM(void); +bool32 BerryFix_ResetPacifidlogTM(void); + +#endif //GUARD_EVENT_DATA_H diff --git a/payload/include/save.h b/payload/include/save.h index f1fe584..2e731ce 100644 --- a/payload/include/save.h +++ b/payload/include/save.h @@ -42,13 +42,6 @@ enum SECTOR_CHECK, // unused }; -enum -{ - SAVE_NORMAL, // Save full save slot - SAVE_SAVEBLOCKS, // Save just SaveBlock1 and SaveBlock2 - SAVE_SAVEBLOCK2, // Save just SaveBlock2 -}; - enum MsgBoxUpdateMessage { MSGBOX_WILL_NOW_UPDATE = 0, diff --git a/payload/ld_script.txt b/payload/ld_script.txt index 6996c2e..7b3ed26 100644 --- a/payload/ld_script.txt +++ b/payload/ld_script.txt @@ -11,6 +11,7 @@ SECTIONS { src/rtc.o(.text); src/berry_fix_save.o(.text); src/save.o(.text); + src/event_data.o(.text); } =0 lib_text : diff --git a/payload/src/berry_fix_save.c b/payload/src/berry_fix_save.c index ff3fe5f..6f2ba38 100644 --- a/payload/src/berry_fix_save.c +++ b/payload/src/berry_fix_save.c @@ -1,6 +1,6 @@ #include "global.h" #include "main.h" -#include "save.h" +#include "berry_fix_save.h" bool32 BerryFix_IdentifyFlash(void) { diff --git a/payload/src/event_data.c b/payload/src/event_data.c new file mode 100644 index 0000000..f7162a3 --- /dev/null +++ b/payload/src/event_data.c @@ -0,0 +1,53 @@ +#include "global.h" +#include "rtc.h" +#include "berry_fix_save.h" +#include "event_data.h" + +// Unused +static void Dummy1() +{ +} + +// Unused +static void Dummy2() +{ +} + +// Unused +static void Dummy3() +{ +} + +static u16 * GetVarPointer(u16 id) +{ + if (id < VARS_START) + return NULL; + if (id < SPECIAL_VARS_START) + return &gSaveBlock1.vars[id - VARS_START]; + return NULL; +} + +bool32 BerryFix_ShouldResetPacifidlogTM(void) +{ + u8 year; + u16 * var = GetVarPointer(VAR_PACIFIDLOG_TM_RECEIVED_DAY); + rtc_maincb_is_time_since_last_berry_update_positive(&year); + if (*var <= gRtcUTCTime.days) + return TRUE; + else + return FALSE; +} + +bool32 BerryFix_ResetPacifidlogTM(void) +{ + u8 year; + if (BerryFix_ShouldResetPacifidlogTM() == TRUE) + return TRUE; + rtc_maincb_is_time_since_last_berry_update_positive(&year); + if (gRtcUTCTime.days < 0) + return FALSE; + *GetVarPointer(VAR_PACIFIDLOG_TM_RECEIVED_DAY) = 1; + if (BerryFix_TrySave(SAVE_NORMAL) != SAVE_STATUS_OK) + return FALSE; + return TRUE; +} diff --git a/payload/src/main.c b/payload/src/main.c index 3ffff8a..3891502 100644 --- a/payload/src/main.c +++ b/payload/src/main.c @@ -3,7 +3,7 @@ #include "main.h" #include "rtc.h" #include "berry_fix_save.h" -#include "save.h" +#include "event_data.h" static s32 gInitialWaitTimer; IntrFunc gIntrTable[16]; @@ -234,14 +234,14 @@ void main_callback(u32 * state, void * unused1, void * unused2) *state = MAINCB_CHECK_PACIFIDLOG_TM; break; case MAINCB_CHECK_PACIFIDLOG_TM: - if (flash_maincb_check_need_reset_pacifidlog_tm() == TRUE) + if (BerryFix_ShouldResetPacifidlogTM() == TRUE) *state = MAINCB_FINISHED; else *state = MAINCB_FIX_PACIFIDLOG_TM; break; case MAINCB_FIX_PACIFIDLOG_TM: msg_display(MSGBOX_UPDATING); - if (flash_maincb_reset_pacifidlog_tm() == TRUE) + if (BerryFix_ResetPacifidlogTM() == TRUE) { gUpdateSuccessful |= 1; *state = MAINCB_FINISHED; diff --git a/payload/src/rtc.c b/payload/src/rtc.c index e73f522..43980b7 100644 --- a/payload/src/rtc.c +++ b/payload/src/rtc.c @@ -251,10 +251,10 @@ void rtc_set_datetime(struct SiiRtcInfo * info) REG_IME = imeBak; } -bool32 rtc_maincb_is_time_since_last_berry_update_positive(u8 * a0) +bool32 rtc_maincb_is_time_since_last_berry_update_positive(u8 * year) { rtc_get_status_and_datetime(&sRtcInfoWork); - *a0 = bcd_to_hex(sRtcInfoWork.year); + *year = bcd_to_hex(sRtcInfoWork.year); rtc_sub_time_from_datetime(&sRtcInfoWork, &gRtcUTCTime, LocalTimeOffset); rtc_sub_time_from_time(&gTimeSinceBerryUpdate, LastBerryTreeUpdate, &gRtcUTCTime); if (gTimeSinceBerryUpdate.days * 1440 + gTimeSinceBerryUpdate.hours * 60 + gTimeSinceBerryUpdate.minutes >= 0) diff --git a/payload/src/save.c b/payload/src/save.c index b096966..40fd33b 100644 --- a/payload/src/save.c +++ b/payload/src/save.c @@ -672,53 +672,3 @@ static u16 CalculateChecksum(const void *data, u16 size) return ((checksum >> 16) + checksum); } - -// Unused -static void SaveDummy1() -{ -} - -// Unused -static void SaveDummy2() -{ -} - -// Unused -static void SaveDummy3() -{ -} - -static u16 * GetVarPointer(u16 id) -{ - if (id < VARS_START) - return NULL; - if (id < SPECIAL_VARS_START) - return &gSaveBlock1.vars[id - VARS_START]; - return NULL; -} - -bool32 flash_maincb_check_need_reset_pacifidlog_tm(void) -{ - u8 sp0; - u16 * data = GetVarPointer(VAR_PACIFIDLOG_TM_RECEIVED_DAY); - rtc_maincb_is_time_since_last_berry_update_positive(&sp0); - if (*data <= gRtcUTCTime.days) - return TRUE; - else - return FALSE; -} - -extern u8 BerryFix_TrySave(u8 mode); -bool32 flash_maincb_reset_pacifidlog_tm(void) -{ - u8 sp0; - if (flash_maincb_check_need_reset_pacifidlog_tm() == TRUE) - return TRUE; - rtc_maincb_is_time_since_last_berry_update_positive(&sp0); - if (gRtcUTCTime.days < 0) - return FALSE; - *GetVarPointer(VAR_PACIFIDLOG_TM_RECEIVED_DAY) = 1; - if (BerryFix_TrySave(SAVE_NORMAL) != SAVE_STATUS_OK) - return FALSE; - return TRUE; -} \ No newline at end of file