Split event_data.c from save.c

This commit is contained in:
GriffinR 2022-01-15 14:44:30 -05:00
parent 4a0b0f67ea
commit 4c04e13962
9 changed files with 76 additions and 63 deletions

View File

@ -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);

View File

@ -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

View File

@ -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,

View File

@ -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 :

View File

@ -1,6 +1,6 @@
#include "global.h"
#include "main.h"
#include "save.h"
#include "berry_fix_save.h"
bool32 BerryFix_IdentifyFlash(void)
{

53
payload/src/event_data.c Normal file
View File

@ -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;
}

View File

@ -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;

View File

@ -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)

View File

@ -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;
}