Skip to content

Commit

Permalink
Merge pull request #543 from red031000/master
Browse files Browse the repository at this point in the history
cleanup and rename event_data -> save_vars_flags
  • Loading branch information
red031000 authored Nov 17, 2023
2 parents 841670d + db56da1 commit 7289710
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 129 deletions.
2 changes: 1 addition & 1 deletion arm9/arm9.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions arm9/asm/unk_02038C78.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

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

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

Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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

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

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

Expand Down
4 changes: 2 additions & 2 deletions arm9/asm/unk_0205F314.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions arm9/global.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion arm9/overlays/52/include/overlay_52.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/encounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
76 changes: 0 additions & 76 deletions arm9/src/event_data.c

This file was deleted.

2 changes: 1 addition & 1 deletion arm9/src/save_arrays.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
59 changes: 59 additions & 0 deletions arm9/src/save_vars_flags.c
Original file line number Diff line number Diff line change
@@ -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];
}
2 changes: 1 addition & 1 deletion arm9/src/scrcmd_13.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/scrcmd_amity_square.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/scrcmd_flags.c
Original file line number Diff line number Diff line change
@@ -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*);
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/scrcmd_names.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/unk_0204B0A0.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions arm9/src/unk_0205EC84.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/unk_0206015C.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion arm9/src/unk_02085338.c
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 5 additions & 0 deletions include/constants/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/constants/save_arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7289710

Please sign in to comment.