diff --git a/configure.py b/configure.py index 55289681..fc6953dd 100644 --- a/configure.py +++ b/configure.py @@ -276,8 +276,8 @@ config.libs = [ Object(NonMatching, "game/THPDraw.c"), Object(NonMatching, "game/thpmain.c"), Object(NonMatching, "game/objsub.c"), - Object(NonMatching, "game/flag.c"), - Object(NonMatching, "game/saveload.c"), + Object(Matching, "game/flag.c"), + Object(Matching, "game/saveload.c"), Object(NonMatching, "game/sreset.c"), Object(NonMatching, "game/board/main.c"), Object(NonMatching, "game/board/board.c"), diff --git a/include/common_structs.h b/include/common_structs.h index e4db9271..190e7251 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -14,8 +14,8 @@ typedef struct player_config { typedef struct system_state { /* 0x00 */ struct { - u16 story : 1; - u16 team : 1; + u8 story : 1; + u8 team : 1; u8 : 7; }; /* 0x02 */ struct { @@ -46,8 +46,9 @@ typedef struct system_state { /* 0x32 */ char unk_32[0x2]; /* 0x34 */ u16 mg_next; /* 0x36 */ s16 mg_next_extra; -/* 0x38 */ u8 flag[3][16]; -/* 0x68 */ u8 unk_68[0x74]; +/* 0x38 */ s16 unk_38; +/* 0x3A */ u8 flag[3][16]; +/* 0x6A */ u8 unk_6A[0x72]; } SystemState; //8018fcf8, sizeof 0xDC typedef struct player_state { diff --git a/include/functions.h b/include/functions.h index bdda3cf9..7a94d857 100644 --- a/include/functions.h +++ b/include/functions.h @@ -43,8 +43,6 @@ void MGSeqKillAll(void); void MGSeqPracticeStart(void); void fn_8004D6F4(s16 arg); -s32 _CheckFlag(u32 flag); - void BoardWinCreate(s16, s32, s32); void BoardWinKill(void); void BoardWinWait(void); diff --git a/include/game/flag.h b/include/game/flag.h new file mode 100644 index 00000000..159a959d --- /dev/null +++ b/include/game/flag.h @@ -0,0 +1,11 @@ +#ifndef _GAME_FLAG_H +#define _GAME_FLAG_H + +#define FLAG_ID_MAKE(group, index) (((group) << 16)|(index)) + +s32 _CheckFlag(u32 flag); +void _SetFlag(u32 flag); +void _ClearFlag(u32 flag); +void _InitFlag(void); + +#endif \ No newline at end of file diff --git a/src/game/flag.c b/src/game/flag.c new file mode 100644 index 00000000..c9b8c8d4 --- /dev/null +++ b/src/game/flag.c @@ -0,0 +1,41 @@ +#include "common.h" + +static u8 _Sys_Flag[16]; + +static u8 *GetFlagPtr(u32 flag) +{ + u8 *ret; + u32 group = flag >> 16; + if((flag & 0xFFFF0000) == 0x30000) { + ret = _Sys_Flag; + } else { + ret = &GWSystem.flag[group][0]; + } + return ret; +} + +u32 _CheckFlag(u32 flag) +{ + u8 *flag_ptr = GetFlagPtr(flag); + u16 index = flag; + return flag_ptr[index/8] & (1 << (index % 8)); +} + +void _SetFlag(u32 flag) +{ + u8 *flag_ptr = GetFlagPtr(flag); + u16 index = flag; + flag_ptr[index/8] |= (1 << (index % 8)); +} + +void _ClearFlag(u32 flag) +{ + u8 *flag_ptr = GetFlagPtr(flag); + u16 index = flag; + flag_ptr[index/8] &= ~(1 << (index % 8)); +} + +void _InitFlag(void) +{ + memset(_Sys_Flag, 0, sizeof(_Sys_Flag)); +} \ No newline at end of file diff --git a/src/game/gamework.c b/src/game/gamework.c index c44d4a05..d0bd669c 100644 --- a/src/game/gamework.c +++ b/src/game/gamework.c @@ -1,6 +1,7 @@ #include "common.h" #include "string.h" #include "game/gamework.h" +#include "game/flag.h" GameStat GWGameStatDefault; GameStat GWGameStat; @@ -144,7 +145,7 @@ s16 GWGetMessSpeed(void) void GWSetMGRecord(int index, s32 value) { - if(!_CheckFlag(0x1000C)) { + if(!_CheckFlag(FLAG_ID_MAKE(1, 12))) { GWGameStat.mg_record[index] = value; } } @@ -297,7 +298,7 @@ s16 GWGetCoins(int player) void GWSetCoins(int player, s16 value) { - if(!_CheckFlag(0x1000C)) { + if(!_CheckFlag(FLAG_ID_MAKE(1, 12))) { if(value < 0) { value = 0; } diff --git a/src/game/objmain.c b/src/game/objmain.c index 6935918b..7be27e96 100644 --- a/src/game/objmain.c +++ b/src/game/objmain.c @@ -2,6 +2,7 @@ #include "game/printfunc.h" #include "game/object.h" #include "game/pad.h" +#include "game/flag.h" #define OM_OVL_HIS_MAX 16 #define OM_MAX_GROUPS 10 @@ -80,7 +81,7 @@ static void omWatchOverlayProc(void) omovlevtno = omnextovlevtno; omovlstat = omnextovlstat; omnextovl = OVL_INVALID; - if(_CheckFlag(0x1000C)) { + if(_CheckFlag(FLAG_ID_MAKE(1, 12))) { MGSeqPracticeStart(); } omSysPauseEnable(TRUE); diff --git a/src/game/saveload.c b/src/game/saveload.c index 0c5c3018..be2eb7ce 100644 --- a/src/game/saveload.c +++ b/src/game/saveload.c @@ -2,6 +2,7 @@ #include "game/data.h" #include "game/pad.h" #include "game/window.h" +#include "game/flag.h" #include "string.h" @@ -18,8 +19,7 @@ s32 HuCardFormat(s16); s32 HuCardWrite(void*, void*, u32, s32); s32 HuCardRead(void*, void*, s32, s32); s32 HuCardClose(void*); -void _ClearFlag(s32); -void _SetFlag(s32); + extern u8 UnMountCnt; @@ -138,7 +138,7 @@ s32 SLFileCreate(char *arg0, u32 arg1, void *arg2) { HuWinExAnimIn(temp_r30); HuWinMesSet(temp_r30, 0x10000B); HuWinMesWait(temp_r30); - _SetFlag(0x30000); + _SetFlag(FLAG_ID_MAKE(3, 0)); temp_r31 = HuCardCreate(curSlotNo, arg0, arg1, curFileInfo); _ClearFlag(0x30000); if (temp_r31 < 0) { @@ -153,9 +153,9 @@ s32 SLFileCreate(char *arg0, u32 arg1, void *arg2) { SLMessOut(1); return -0x80; } - _SetFlag(0x30000); + _SetFlag(FLAG_ID_MAKE(3, 0)); temp_r31 = HuCardWrite(curFileInfo, arg2, arg1, 0); - _ClearFlag(0x30000); + _ClearFlag(FLAG_ID_MAKE(3, 0)); if (temp_r31 < 0) { HuWinExAnimOut(temp_r30); HuWinExCleanup(temp_r30); @@ -168,9 +168,9 @@ s32 SLFileCreate(char *arg0, u32 arg1, void *arg2) { SLMessOut(1); return -0x80; } - _SetFlag(0x30000); + _SetFlag(FLAG_ID_MAKE(3, 0)); temp_r31 = SLStatSet(1); - _ClearFlag(0x30000); + _ClearFlag(FLAG_ID_MAKE(3, 0)); HuWinExAnimOut(temp_r30); HuWinExCleanup(temp_r30); if (temp_r31 < 0) { @@ -194,12 +194,12 @@ s32 SLFileWrite(s32 arg0, void *arg1) { HuWinMesSet(temp_r31, 0x10000B); HuWinMesWait(temp_r31); HuPrcSleep(0x3C); - _SetFlag(0x30000); + _SetFlag(FLAG_ID_MAKE(3, 0)); var_r30 = HuCardWrite(curFileInfo, arg1, arg0, 0); if (var_r30 == 0) { var_r30 = SLStatSet(1); } - _ClearFlag(0x30000); + _ClearFlag(FLAG_ID_MAKE(3, 0)); HuWinExAnimOut(temp_r31); HuWinExCleanup(temp_r31); return var_r30; @@ -661,9 +661,9 @@ s32 SLFormat(s16 arg0) { SLMessOut(0xC); return 0; } - _SetFlag(0x30000); + _SetFlag(FLAG_ID_MAKE(3, 0)); temp_r24 = HuCardFormat(curSlotNo); - _ClearFlag(0x30000); + _ClearFlag(FLAG_ID_MAKE(3, 0)); if (temp_r24 < 0) { HuWinExAnimOut(temp_r3); HuWinExCleanup(temp_r3); diff --git a/src/game/wipe.c b/src/game/wipe.c index 087c1260..99041ebd 100644 --- a/src/game/wipe.c +++ b/src/game/wipe.c @@ -1,6 +1,7 @@ #include "dolphin.h" #include "game/wipe.h" #include "game/memory.h" +#include "game/flag.h" extern s8 lbl_801D429C; @@ -110,7 +111,7 @@ void WipeExecAlways(void) void WipeCreate(s16 mode, s16 type, s16 duration) { WipeState *wipe; - if(_CheckFlag(0x1000B) && lbl_801D429C) { + if(_CheckFlag(FLAG_ID_MAKE(1, 11)) && lbl_801D429C) { return; } wipe = &wipeData;