From db56da1092d9ada290ce41f71f0fa189f332faa6 Mon Sep 17 00:00:00 2001 From: red031000 Date: Tue, 7 Nov 2023 16:12:53 +0000 Subject: [PATCH] event_data -> save_vars_flags --- arm9/arm9.lsf | 2 +- arm9/asm/unk_02038C78.s | 20 +++---- arm9/asm/unk_0205F314.s | 4 +- arm9/global.inc | 10 ++-- arm9/overlays/52/include/overlay_52.h | 2 +- arm9/src/encounter.c | 2 +- arm9/src/event_data.c | 76 --------------------------- arm9/src/save_arrays.c | 2 +- arm9/src/save_vars_flags.c | 59 +++++++++++++++++++++ arm9/src/scrcmd_13.c | 2 +- arm9/src/scrcmd_amity_square.c | 2 +- arm9/src/scrcmd_flags.c | 2 +- arm9/src/scrcmd_names.c | 2 +- arm9/src/unk_0204B0A0.c | 2 +- arm9/src/unk_0205EC84.c | 6 +-- arm9/src/unk_0206015C.c | 2 +- arm9/src/unk_02085338.c | 2 +- include/constants/flags.h | 5 ++ include/constants/save_arrays.h | 1 + include/constants/vars.h | 8 +++ include/event_data.h | 21 -------- include/save_vars_flags.h | 22 ++++++++ include/unk_0205EC84.h | 2 +- 23 files changed, 127 insertions(+), 129 deletions(-) delete mode 100644 arm9/src/event_data.c create mode 100644 arm9/src/save_vars_flags.c create mode 100644 include/constants/vars.h delete mode 100644 include/event_data.h create mode 100644 include/save_vars_flags.h diff --git a/arm9/arm9.lsf b/arm9/arm9.lsf index 3bf04500e..5a4f36ba9 100644 --- a/arm9/arm9.lsf +++ b/arm9/arm9.lsf @@ -182,7 +182,7 @@ Static arm9 Object scrcmd_move_relearner.o Object scrcmd_25.o Object unk_02046030.o - Object event_data.o + Object save_vars_flags.o Object task.o Object encounter.o Object unk_02047500.o diff --git a/arm9/asm/unk_02038C78.s b/arm9/asm/unk_02038C78.s index 96139b454..77bdfe3ad 100644 --- a/arm9/asm/unk_02038C78.s +++ b/arm9/asm/unk_02038C78.s @@ -1958,7 +1958,7 @@ _020394D0: cmp r4, r1 bhs _020394DE add r1, r4, #0x0 - bl GetVarAddr + bl Save_VarsFlags_GetVarAddr pop {r3-r5, pc} _020394DE: ldr r1, _020394EC ; =0x00007FD7 @@ -2008,7 +2008,7 @@ FlagCheck: ; 0x02039528 add r4, r1, #0x0 bl Save_VarsFlags_Get add r1, r4, #0x0 - bl CheckFlagInArray + bl Save_VarsFlags_CheckFlagInArray pop {r4, pc} .balign 4 @@ -2019,7 +2019,7 @@ FieldSystem_FlagSet: ; 0x0203953C add r4, r1, #0x0 bl Save_VarsFlags_Get add r1, r4, #0x0 - bl SetFlagInArray + bl Save_VarsFlags_SetFlagInArray pop {r4, pc} .balign 4 @@ -2030,7 +2030,7 @@ FlagClear: ; 0x02039550 add r4, r1, #0x0 bl Save_VarsFlags_Get add r1, r4, #0x0 - bl ClearFlagInArray + bl Save_VarsFlags_ClearFlagInArray pop {r4, pc} .balign 4 @@ -2041,7 +2041,7 @@ ResetTempFlagsAndVars: ; 0x02039564 bl Save_VarsFlags_Get mov r1, #0x1 add r4, r0, #0x0 - bl GetFlagAddr + bl Save_VarsFlags_GetFlagAddr mov r1, #0x0 strb r1, [r0, #0x0] strb r1, [r0, #0x1] @@ -2054,7 +2054,7 @@ ResetTempFlagsAndVars: ; 0x02039564 mov r1, #0x1 add r0, r4, #0x0 lsl r1, r1, #0xe - bl GetVarAddr + bl Save_VarsFlags_GetVarAddr mov r1, #0x0 mov r2, #0x40 bl memset @@ -2068,7 +2068,7 @@ sub_0203959C: ; 0x0203959C bl Save_VarsFlags_Get mov r1, #0xaa lsl r1, r1, #0x4 - bl GetFlagAddr + bl Save_VarsFlags_GetFlagAddr mov r2, #0x18 mov r1, #0x0 _020395B0: @@ -2163,7 +2163,7 @@ TrainerFlagCheck: ; 0x02039640 add r1, r4, r1 lsl r1, r1, #0x10 lsr r1, r1, #0x10 - bl CheckFlagInArray + bl Save_VarsFlags_CheckFlagInArray pop {r4, pc} .balign 4 @@ -2178,7 +2178,7 @@ TrainerFieldSystem_FlagSet: ; 0x0203965C add r1, r4, r1 lsl r1, r1, #0x10 lsr r1, r1, #0x10 - bl SetFlagInArray + bl Save_VarsFlags_SetFlagInArray pop {r4, pc} .balign 4 @@ -2193,7 +2193,7 @@ TrainerFlagClear: ; 0x02039678 add r1, r4, r1 lsl r1, r1, #0x10 lsr r1, r1, #0x10 - bl ClearFlagInArray + bl Save_VarsFlags_ClearFlagInArray pop {r4, pc} .balign 4 diff --git a/arm9/asm/unk_0205F314.s b/arm9/asm/unk_0205F314.s index c5308a25d..b188edd4a 100644 --- a/arm9/asm/unk_0205F314.s +++ b/arm9/asm/unk_0205F314.s @@ -18,7 +18,7 @@ sub_0205F314: ; 0x0205F314 push {r3-r5, lr} add r5, r1, #0x0 add r4, r2, #0x0 - bl GetVarAddr + bl Save_VarsFlags_GetVarAddr mov r1, #0x1 lsl r1, r1, #0xe cmp r5, r1 @@ -44,7 +44,7 @@ _0205F33C: thumb_func_start sub_0205F344 sub_0205F344: ; 0x0205F344 push {r3, lr} - bl GetVarAddr + bl Save_VarsFlags_GetVarAddr cmp r0, #0x0 bne _0205F352 mov r0, #0x0 diff --git a/arm9/global.inc b/arm9/global.inc index 8d4c183c3..e449eb6b2 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -3423,11 +3423,11 @@ .extern Save_VarsFlags_sizeof .extern Save_VarsFlags_Init .extern Save_VarsFlags_Get -.extern CheckFlagInArray -.extern SetFlagInArray -.extern ClearFlagInArray -.extern GetFlagAddr -.extern GetVarAddr +.extern Save_VarsFlags_CheckFlagInArray +.extern Save_VarsFlags_SetFlagInArray +.extern Save_VarsFlags_ClearFlagInArray +.extern Save_VarsFlags_GetFlagAddr +.extern Save_VarsFlags_GetVarAddr .extern FieldSystem_CreateTask .extern TaskManager_Jump .extern TaskManager_Call diff --git a/arm9/overlays/52/include/overlay_52.h b/arm9/overlays/52/include/overlay_52.h index 8f761856a..af54f32c8 100644 --- a/arm9/overlays/52/include/overlay_52.h +++ b/arm9/overlays/52/include/overlay_52.h @@ -2,7 +2,7 @@ #define POKEDIAMOND_OVERLAY_52_H #include "global.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "main.h" #include "math_util.h" #include "options.h" diff --git a/arm9/src/encounter.c b/arm9/src/encounter.c index e1316834e..db43fcaf9 100644 --- a/arm9/src/encounter.c +++ b/arm9/src/encounter.c @@ -2,7 +2,7 @@ #include "encounter.h" #include "constants/battle.h" #include "constants/game_stats.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "field_system.h" #include "igt.h" #include "task.h" diff --git a/arm9/src/event_data.c b/arm9/src/event_data.c deleted file mode 100644 index 763905d79..000000000 --- a/arm9/src/event_data.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "global.h" -#include "save.h" -#include "event_data.h" - -u8 UNK_021C5A14[8]; - -u8 * GetFlagAddr(struct SaveVarsFlags * state, u16 flag_id); - -u32 Save_VarsFlags_sizeof(void) -{ - return sizeof(struct SaveVarsFlags); -} - -void Save_VarsFlags_Init(struct SaveVarsFlags * state) -{ - memset(state, 0, sizeof(struct SaveVarsFlags)); -} - -struct SaveVarsFlags * Save_VarsFlags_Get(struct SaveData * save) -{ - return (struct SaveVarsFlags *)SaveArray_Get(save, 4); -} - -BOOL CheckFlagInArray(struct SaveVarsFlags * state, u16 flag_id) -{ - u8 * ptr = GetFlagAddr(state, flag_id); - if (ptr != NULL) - { - int mask = 1 << (flag_id % 8); - if (*ptr & mask) - return TRUE; - } - return FALSE; -} - -void SetFlagInArray(struct SaveVarsFlags * state, u16 flag_id) -{ - u8 * ptr = GetFlagAddr(state, flag_id); - if (ptr != NULL) - { - int mask = 1 << (flag_id % 8); - *ptr |= mask; - } -} - -void ClearFlagInArray(struct SaveVarsFlags * state, u16 flag_id) -{ - u8 * ptr = GetFlagAddr(state, flag_id); - if (ptr != NULL) - { - int mask = 1 << (flag_id % 8); - *ptr &= 0xFF ^ mask; - } -} - -u8 * GetFlagAddr(struct SaveVarsFlags * state, u16 flag_id) -{ - if (flag_id == 0) - return 0; - if (flag_id < 0x4000) - { - GF_ASSERT((flag_id / 8) < 364); - return &state->flags[flag_id / 8]; - } - else - { - GF_ASSERT(((flag_id - 0x4000) / 8) < 8); - return &UNK_021C5A14[(flag_id - 0x4000) / 8]; - } -} - -u16 * GetVarAddr(struct SaveVarsFlags * state, u16 var_id) -{ - GF_ASSERT((var_id - 0x4000) < 288); - return &state->vars[var_id - 0x4000]; -} diff --git a/arm9/src/save_arrays.c b/arm9/src/save_arrays.c index 721c0faca..1cef02f49 100644 --- a/arm9/src/save_arrays.c +++ b/arm9/src/save_arrays.c @@ -3,7 +3,7 @@ #include "player_data.h" #include "save.h" #include "party.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "pokemon_storage_system.h" #include "save_system_info.h" #include "poketch.h" diff --git a/arm9/src/save_vars_flags.c b/arm9/src/save_vars_flags.c new file mode 100644 index 000000000..c29dea921 --- /dev/null +++ b/arm9/src/save_vars_flags.c @@ -0,0 +1,59 @@ +#include "global.h" +#include "save_vars_flags.h" + +static u8 sTempFlags[NUM_TEMP_FLAGS / 8] = {0}; + +u32 Save_VarsFlags_sizeof(void) { + return sizeof(SaveVarsFlags); +} + +void Save_VarsFlags_Init(SaveVarsFlags *varsFlags) { + memset(varsFlags, 0, sizeof(SaveVarsFlags)); +} + +SaveVarsFlags *Save_VarsFlags_Get(SaveData *save) { + return (SaveVarsFlags *)SaveArray_Get(save, SAVE_FLAGS); +} + +BOOL Save_VarsFlags_CheckFlagInArray(SaveVarsFlags *varsFlags, u16 flagId) { + u8 *flagAddr = Save_VarsFlags_GetFlagAddr(varsFlags, flagId); + if (flagAddr != NULL) { + if (*flagAddr & (1 << (flagId % 8))) { + return TRUE; + } + } + return FALSE; +} + +void Save_VarsFlags_SetFlagInArray(SaveVarsFlags *varsFlags, u16 flagId) { + u8 *flagAddr = Save_VarsFlags_GetFlagAddr(varsFlags, flagId); + if (flagAddr == NULL) { + return; + } + *flagAddr |= 1 << (flagId % 8); +} + +void Save_VarsFlags_ClearFlagInArray(SaveVarsFlags *varsFlags, u16 flagId) { + u8 *flagAddr = Save_VarsFlags_GetFlagAddr(varsFlags, flagId); + if (flagAddr == NULL) { + return; + } + *flagAddr &= 0xFF ^ (1 << (flagId % 8)); +} + +u8 *Save_VarsFlags_GetFlagAddr(SaveVarsFlags *varsFlags, u16 flagId) { + if (flagId == 0) { + return NULL; + } else if (flagId < TEMP_FLAG_BASE) { + GF_ASSERT((flagId / 8) < (NUM_FLAGS / 8)); + return &varsFlags->flags[flagId / 8]; + } else { + GF_ASSERT(((flagId - TEMP_FLAG_BASE) / 8) < (NUM_TEMP_FLAGS / 8)); + return &sTempFlags[(flagId - TEMP_FLAG_BASE) / 8]; + } +} + +u16 *Save_VarsFlags_GetVarAddr(SaveVarsFlags * varsFlags, u16 varId) { + GF_ASSERT((varId - VAR_BASE) < NUM_VARS); + return &varsFlags->vars[varId - VAR_BASE]; +} diff --git a/arm9/src/scrcmd_13.c b/arm9/src/scrcmd_13.c index 5d91c5708..e989ce940 100644 --- a/arm9/src/scrcmd_13.c +++ b/arm9/src/scrcmd_13.c @@ -1,6 +1,6 @@ #include "global.h" #include "scrcmd.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "heap.h" #include "pokedex.h" #include "pokemon_storage_system.h" diff --git a/arm9/src/scrcmd_amity_square.c b/arm9/src/scrcmd_amity_square.c index d5f9d5fd1..daa66e25e 100644 --- a/arm9/src/scrcmd_amity_square.c +++ b/arm9/src/scrcmd_amity_square.c @@ -2,7 +2,7 @@ #include "scrcmd.h" #include "constants/accessories.h" #include "constants/pokemon.h" -#include "event_data.h" +#include "save_vars_flags.h" extern void sub_0205F54C(struct SaveVarsFlags* state); extern u16 sub_0205F55C(struct SaveVarsFlags* state); diff --git a/arm9/src/scrcmd_flags.c b/arm9/src/scrcmd_flags.c index 864ff418e..6d8cd2f21 100644 --- a/arm9/src/scrcmd_flags.c +++ b/arm9/src/scrcmd_flags.c @@ -1,6 +1,6 @@ #include "global.h" #include "scrcmd.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "pokedex.h" extern void* sub_02034E20(void*); diff --git a/arm9/src/scrcmd_names.c b/arm9/src/scrcmd_names.c index 84f6bf4ff..8e4c24e50 100644 --- a/arm9/src/scrcmd_names.c +++ b/arm9/src/scrcmd_names.c @@ -1,5 +1,5 @@ #include "global.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "itemtool.h" #include "message_format.h" #include "msgdata.h" diff --git a/arm9/src/unk_0204B0A0.c b/arm9/src/unk_0204B0A0.c index 635a50f16..21d5878d2 100644 --- a/arm9/src/unk_0204B0A0.c +++ b/arm9/src/unk_0204B0A0.c @@ -1,5 +1,5 @@ #include "global.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "unk_02022504.h" #include "unk_0204B0A0.h" #include "unk_0205FA2C.h" diff --git a/arm9/src/unk_0205EC84.c b/arm9/src/unk_0205EC84.c index 2f1a650fd..fa9ee3062 100644 --- a/arm9/src/unk_0205EC84.c +++ b/arm9/src/unk_0205EC84.c @@ -7,17 +7,17 @@ static void _flag_set(struct SaveVarsFlags * state, u16 flag_id) { - SetFlagInArray(state, flag_id); + Save_VarsFlags_SetFlagInArray(state, flag_id); } static void _flag_clear(struct SaveVarsFlags * state, u16 flag_id) { - ClearFlagInArray(state, flag_id); + Save_VarsFlags_ClearFlagInArray(state, flag_id); } static BOOL _flag_check(struct SaveVarsFlags * state, u16 flag_id) { - return CheckFlagInArray(state, flag_id); + return Save_VarsFlags_CheckFlagInArray(state, flag_id); } static BOOL _flag_op(struct SaveVarsFlags * state, u32 op, u32 flag_id) diff --git a/arm9/src/unk_0206015C.c b/arm9/src/unk_0206015C.c index c743e2a97..173f5df37 100644 --- a/arm9/src/unk_0206015C.c +++ b/arm9/src/unk_0206015C.c @@ -2,7 +2,7 @@ #include "unk_0206015C.h" #include "constants/sndseq.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "heap.h" #include "main.h" #include "unk_020051F4.h" diff --git a/arm9/src/unk_02085338.c b/arm9/src/unk_02085338.c index 00b0866d7..853485322 100644 --- a/arm9/src/unk_02085338.c +++ b/arm9/src/unk_02085338.c @@ -1,6 +1,6 @@ #include "global.h" #include "heap.h" -#include "event_data.h" +#include "save_vars_flags.h" #include "unk_02085338.h" extern BOOL sub_0205ED0C(struct SaveVarsFlags * state); diff --git a/include/constants/flags.h b/include/constants/flags.h index 753bf6c8f..cc83bdd9c 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -3,4 +3,9 @@ #define FLAG_SYS_SAFARI 0x967 +#define NUM_FLAGS 2912 + +#define NUM_TEMP_FLAGS 64 +#define TEMP_FLAG_BASE 0x4000 + #endif //POKEDIAMOND_CONSTANTS_FLAGS_H \ No newline at end of file diff --git a/include/constants/save_arrays.h b/include/constants/save_arrays.h index a2f23d742..a16bba863 100644 --- a/include/constants/save_arrays.h +++ b/include/constants/save_arrays.h @@ -2,6 +2,7 @@ #define POKEDIAMOND_CONSTANTS_SAVE_ARRAYS_H #define SAVE_BAG 3 +#define SAVE_FLAGS 4 #define SAVE_DAYCARE 8 #define SAVE_SAFARI_ZONE 27 #define SAVE_EASY_CHAT 34 diff --git a/include/constants/vars.h b/include/constants/vars.h new file mode 100644 index 000000000..007e6c1c8 --- /dev/null +++ b/include/constants/vars.h @@ -0,0 +1,8 @@ +#ifndef POKEDIAMOND_CONSTANTS_VARS_H +#define POKEDIAMOND_CONSTANTS_VARS_H + +#define VAR_BASE 0x4000 + +#define NUM_VARS 0x120 + +#endif //POKEDIAMOND_CONSTANTS_VARS_H \ No newline at end of file diff --git a/include/event_data.h b/include/event_data.h deleted file mode 100644 index 242675a9a..000000000 --- a/include/event_data.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef GUARD_SAVE_VARS_FLAGS_H -#define GUARD_SAVE_VARS_FLAGS_H - -#include "save.h" - -typedef struct SaveVarsFlags -{ - u16 vars[288]; - u8 flags[364]; -} SaveVarsFlags; - -u32 Save_VarsFlags_sizeof(void); -void Save_VarsFlags_Init(struct SaveVarsFlags * state); -struct SaveVarsFlags * Save_VarsFlags_Get(struct SaveData * save); -BOOL CheckFlagInArray(struct SaveVarsFlags * state, u16 flag_id); -void SetFlagInArray(struct SaveVarsFlags * state, u16 flag_id); -void ClearFlagInArray(struct SaveVarsFlags * state, u16 flag_id); -u8 * GetFlagAddr(struct SaveVarsFlags * state, u16 flag_id); -u16 * GetVarAddr(struct SaveVarsFlags * state, u16 var_id); - -#endif //GUARD_SAVE_VARS_FLAGS_H diff --git a/include/save_vars_flags.h b/include/save_vars_flags.h new file mode 100644 index 000000000..72843ea6b --- /dev/null +++ b/include/save_vars_flags.h @@ -0,0 +1,22 @@ +#ifndef POKEDIAMOND_SAVE_VARS_FLAGS_H +#define POKEDIAMOND_SAVE_VARS_FLAGS_H + +#include "save.h" +#include "constants/flags.h" +#include "constants/vars.h" + +typedef struct SaveVarsFlags { + u16 vars[NUM_VARS]; + u8 flags[NUM_FLAGS / 8]; +} SaveVarsFlags; + +u32 Save_VarsFlags_sizeof(void); +void Save_VarsFlags_Init(SaveVarsFlags *varsFlags); +SaveVarsFlags *Save_VarsFlags_Get(SaveData *saveData); +BOOL Save_VarsFlags_CheckFlagInArray(SaveVarsFlags *varsFlags, u16 flagId); +void Save_VarsFlags_SetFlagInArray(SaveVarsFlags *varsFlags, u16 flagId); +void Save_VarsFlags_ClearFlagInArray(SaveVarsFlags *varsFlags, u16 flagId); +u8 *Save_VarsFlags_GetFlagAddr(SaveVarsFlags *varsFlags, u16 flagId); +u16 *Save_VarsFlags_GetVarAddr(SaveVarsFlags *varsFlags, u16 varId); + +#endif //POKEDIAMOND_SAVE_VARS_FLAGS_H diff --git a/include/unk_0205EC84.h b/include/unk_0205EC84.h index 612692b00..02dbec397 100644 --- a/include/unk_0205EC84.h +++ b/include/unk_0205EC84.h @@ -1,7 +1,7 @@ #ifndef POKEDIAMOND_UNK_0205EC84_H #define POKEDIAMOND_UNK_0205EC84_H -#include "event_data.h" +#include "save_vars_flags.h" void sub_0205ECD4(struct SaveVarsFlags * state); BOOL sub_0205ECE0(struct SaveVarsFlags * state);