diff --git a/include/code_80972F4.h b/include/code_80972F4.h index 9a5e1aca..b5bd9114 100644 --- a/include/code_80972F4.h +++ b/include/code_80972F4.h @@ -14,13 +14,12 @@ typedef struct MissionText } MissionText; const u8 *GetCurrentMissionText(s16 index); -// TODO: this should probably be bool8 but can't get a match just yet -bool32 IsMazeCompleted(s16 mazeIndex); +bool8 IsMazeCompleted(s16 mazeIndex); bool8 sub_8096F50(WonderMail *mail); void sub_8097418(s16 index, bool32); bool8 sub_8097504(s16 mazeIndex); -const u8 *sub_80975DC(u32); +const u8 *sub_80975DC(s16); // These two are definitely bool8 but can't get them to match with it yet //bool8 sub_8097384(s16); diff --git a/include/pokemon.h b/include/pokemon.h index c48239df..0d10e72a 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -105,7 +105,12 @@ static inline bool8 PokemonFlag1(PokemonStruct1 *mon) static inline bool8 PokemonFlag2(PokemonStruct1 *mon) { - return (((mon->unk0 >> 1) & 1)); + return (((mon->unk0 >> (FLAG_ON_TEAM - 1)) & 1)); +} + +static inline void SetPokemonFlag2(PokemonStruct1 *mon) +{ + mon->unk0 |= FLAG_ON_TEAM; } static inline bool8 IsMonTeamLeader(PokemonStruct1 *pokemon) diff --git a/src/code_8097504.c b/src/code_8097504.c index 022a701f..c8a500bb 100644 --- a/src/code_8097504.c +++ b/src/code_8097504.c @@ -4,29 +4,25 @@ #include "dungeon.h" #include "event_flag.h" #include "code_80A26CC.h" +#include "code_80972F4.h" ALIGNED(4) const char gMeetNinetalesText[] = "Meet Ninetales."; ALIGNED(4) const char gAvoidCaptureText[] = "Avoid capture."; ALIGNED(4) const char gFinalScenarioText[] = _("Defeat the final Pokémon."); +// Needed to match +static inline s16 Self(s16 a) +{ + return a; +} bool8 sub_8097504(s16 mazeIndex) { - s32 mazeIndex_s32; - -#ifndef NONMATCHING - register s32 mazeIndex_s32_1 asm("r1"); -#else - s32 mazeIndex_s32_1; -#endif s32 uVar3; - - mazeIndex_s32 = mazeIndex; - mazeIndex_s32_1 = mazeIndex_s32; - - if(mazeIndex_s32 < 17) + s32 mazeIndex_ = Self(mazeIndex); + if(mazeIndex < 17) { - switch(mazeIndex_s32) { + switch(mazeIndex) { case 2: case 10: case 11: @@ -55,9 +51,9 @@ bool8 sub_8097504(s16 mazeIndex) } else { - if (mazeIndex_s32_1 > 22) return FALSE; - if (mazeIndex_s32_1 == 22) return FALSE; - if (mazeIndex_s32_1 == 21) return FALSE; + if (mazeIndex_ > 22) return FALSE; + if (mazeIndex_ == 22) return FALSE; + if (mazeIndex_ == 21) return FALSE; uVar3 = 6; } @@ -69,16 +65,9 @@ bool8 sub_8097504(s16 mazeIndex) } } -// TODO: this should probably be bool8 but can't get a match just yet -bool32 IsMazeCompleted(s16 mazeIndex) +bool8 IsMazeCompleted(s16 mazeIndex) { - bool32 mazeCompletion; - - mazeCompletion = GetScriptVarArrayValue(NULL, TRAINING_CONQUEST_LIST, mazeIndex); - if (mazeCompletion) { - mazeCompletion = TRUE; - } - return mazeCompletion; + return (GetScriptVarArrayValue(NULL, TRAINING_CONQUEST_LIST, mazeIndex) != 0); } void sub_80975A8(s16 param_1,u8 param_2) @@ -92,15 +81,14 @@ const u8 *sub_80975C4(s16 index) return GetDungeonName1(sub_80A2728(index)); } -const u8 *sub_80975DC(u32 r0) +const u8 *sub_80975DC(s16 r0) { - // TODO: slight hack but matches - r0 <<= 16; - if((0xffe90000 + r0) >> 16 < 2) + if(r0 == 23 || r0 == 24) { if(ScriptVarScenarioEqual(SCENARIO_MAIN, 0xE, -1)) return gMeetNinetalesText; else return gAvoidCaptureText; + } else return gFinalScenarioText; } diff --git a/src/friend_area_action_menu.c b/src/friend_area_action_menu.c index db538e9e..2b2bfebd 100644 --- a/src/friend_area_action_menu.c +++ b/src/friend_area_action_menu.c @@ -416,8 +416,7 @@ void sub_80277FC(void) void sub_80278B4(void) { PokemonStruct1 *playerStruct; - PokemonStruct1 *pokeStruct1; - PokemonStruct1 *pokeStruct2; + PokemonStruct1 *newLeader; u32 menuAction; menuAction = 0; @@ -428,15 +427,7 @@ void sub_80278B4(void) switch(menuAction) { case FRIEND_AREA_ACTION_MENU_ACTION_JOIN_TEAM: if (sub_808D750(sUnknown_203B2BC->targetPoke)) { -#ifdef NONMATCHING - pokeStruct1 = &gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke]; -#else - register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[sUnknown_203B2BC->targetPoke]); - PokemonStruct1* p = gRecruitedPokemonRef->pokemon; - size_t addr = offset + (size_t)p; - pokeStruct1 = (PokemonStruct1*)addr; -#endif - pokeStruct1->unk0 |= FLAG_ON_TEAM; + SetPokemonFlag2(&gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke]); nullsub_104(); } sub_808ED00(); @@ -449,11 +440,11 @@ void sub_80278B4(void) SetFriendAreaActionMenuState(FRIEND_AREA_ACTION_MENU_MAIN_2); break; case FRIEND_AREA_ACTION_MENU_ACTION_MAKE_LEADER: - pokeStruct2 = &gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke]; + newLeader = &gRecruitedPokemonRef->pokemon[sUnknown_203B2BC->targetPoke]; playerStruct = GetPlayerPokemonStruct(); - if (!pokeStruct2->isTeamLeader) { + if (!newLeader->isTeamLeader) { playerStruct->isTeamLeader = FALSE; - pokeStruct2->isTeamLeader = TRUE; + newLeader->isTeamLeader = TRUE; nullsub_104(); } sub_808ED00(); diff --git a/src/iq_skill_list_menu.c b/src/iq_skill_list_menu.c index 0381feba..a424a6b9 100644 --- a/src/iq_skill_list_menu.c +++ b/src/iq_skill_list_menu.c @@ -21,13 +21,7 @@ static void sub_801C440(void); bool8 CreateIQSkillListMenu(s16 species, u32 index, u32 a2) { -#ifndef NONMATCHING - register s32 species_s32 asm("r4"); -#else - s32 species_s32; -#endif - - species_s32 = species; + s32 species_s32 = SpeciesId(species); if (HasNoAvailIQSkills(species)) return FALSE; diff --git a/src/moves.c b/src/moves.c index ba8fc260..342c9a9d 100644 --- a/src/moves.c +++ b/src/moves.c @@ -912,9 +912,7 @@ s32 sub_80935B8(Move *moves, s32 index) } // this is so stupid but it works - #ifndef NONMATCHING - isNonTrivialLinkSequence++; isNonTrivialLinkSequence--; - #endif + ASM_MATCH_TRICK(isNonTrivialLinkSequence); for (i = linkSequenceStart + 1; i < MAX_MON_MOVES; i++) { Move *move = &moves[i]; diff --git a/src/party_list_menu.c b/src/party_list_menu.c index 59af76d3..3af628e8 100644 --- a/src/party_list_menu.c +++ b/src/party_list_menu.c @@ -464,8 +464,7 @@ void PartyListMenu_BuildYesNoMenu(void) { void PartyListMenu_HandleMenu1(void) { PokemonStruct1 *playerPokemon; - PokemonStruct1 *pokeStruct; - PokemonStruct1 *pokeStruct2; + PokemonStruct1 *newLeader; s32 choice; choice = 0; @@ -475,17 +474,7 @@ void PartyListMenu_HandleMenu1(void) switch(choice) { case PARTY_LIST_MENU_JOIN_TEAM: if (sub_808D750(sUnknown_203B2B8->pokeSpecies)) { - -#ifdef NONMATCHING - pokeStruct = &sUnknown_203B2B8->pokeSpecies[gRecruitedPokemonRef->pokemon]; -#else - register size_t offset asm("r1") = offsetof(unkStruct_203B45C, pokemon[sUnknown_203B2B8->pokeSpecies]); - PokemonStruct1* p = gRecruitedPokemonRef->pokemon; - size_t addr = offset + (size_t)p; - pokeStruct = (PokemonStruct1*)addr; -#endif - - pokeStruct->unk0 |= FLAG_ON_TEAM; + SetPokemonFlag2(&sUnknown_203B2B8->pokeSpecies[gRecruitedPokemonRef->pokemon]); nullsub_104(); } sub_808ED00(); @@ -498,12 +487,12 @@ void PartyListMenu_HandleMenu1(void) SetPartyListMenuState(PARTY_LIST_STATE_STANDBY); break; case PARTY_LIST_MENU_MAKE_LEADER: - pokeStruct2 = &gRecruitedPokemonRef->pokemon[sUnknown_203B2B8->pokeSpecies]; + newLeader = &gRecruitedPokemonRef->pokemon[sUnknown_203B2B8->pokeSpecies]; playerPokemon = GetPlayerPokemonStruct(); - if (!pokeStruct2->isTeamLeader) { + if (!newLeader->isTeamLeader) { playerPokemon->isTeamLeader = FALSE; - pokeStruct2->isTeamLeader = TRUE; + newLeader->isTeamLeader = TRUE; nullsub_104(); } sub_808ED00(); diff --git a/src/pokemon_mid.c b/src/pokemon_mid.c index 0a72c8b9..eb2ad96b 100644 --- a/src/pokemon_mid.c +++ b/src/pokemon_mid.c @@ -679,31 +679,21 @@ void GetPokemonLevelData(LevelData* a1, s16 _id, s32 level) *a1 = gLevelCurrentData[level]; } -const u8* DecompressMoveID(const u8* a1, u16* moveID) +const u8* DecompressMoveID(const u8* src, u16* moveID) { - u32 r1 = *a1++; - u32 r3; - if (r1 & 0x80) { - r3 = *a1++; + u32 byte0; + u32 byte1 = *src++; + // If move >= 127 which means it uses 2 bytes and not one + if (byte1 & 0x80) { + byte0 = *src++; } else { - r3 = r1; - r1 = 0; + byte0 = byte1; + byte1 = 0; } -#ifdef NONMATCHING - // wrong order - r1 &= 0x7f; - r3 &= 0x7f; - *moveID = (r1 << 7) | r3; -#else - { - register u32 mask asm("r0") = 0x7f; - r3 &= mask; - r1 &= mask; - *moveID = (r1 << 7) | r3; - } -#endif - return a1; + + *moveID = (byte0 & 0x7F) | ((byte1 & 0x7F) << 7); + return src; } s32 sub_808E0AC(u16* a1, s16 species, s32 a3, s32 IQPoints) @@ -711,9 +701,9 @@ s32 sub_808E0AC(u16* a1, s16 species, s32 a3, s32 IQPoints) const u8* stream; u16 moveID; // moveID s32 count; - register s32 _species asm("r2"); // weird regalloc + s32 _species; - _species = (s16)species; + _species = SpeciesId(species); count = 0; if (species == MONSTER_DECOY) return 0;