diff options
Diffstat (limited to 'src')
132 files changed, 3320 insertions, 1906 deletions
diff --git a/src/apprentice.c b/src/apprentice.c index 9cf8cd4b4..27ff8e36e 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -1619,7 +1619,7 @@ static u8 CreateAndShowWindow(u8 left, u8 top, u8 width, u8 height) static void RemoveAndHideWindow(u8 windowId) { - sub_8198070(windowId, TRUE); + ClearStdWindowAndFrameToTransparent(windowId, TRUE); RemoveWindow(windowId); } @@ -1826,7 +1826,7 @@ static void Script_PrintMessage(void) FreezeEventObjects(); sub_808B864(); sub_808BCF4(); - NewMenuHelpers_DrawDialogueFrame(0, 1); + DrawDialogueFrame(0, 1); PrintMessage(); } diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index ee6676e64..80b3258b4 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -16,9 +16,6 @@ #include "constants/rgb.h" #include "constants/songs.h" -extern void sub_8108C94(struct Sprite *); -extern void sub_810310C(u8, struct Sprite *); - void sub_8103448(struct Sprite *); void sub_8103498(struct Sprite *); void sub_810358C(struct Sprite *); diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index 49fb69342..efa2620fd 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -24,9 +24,6 @@ #include "constants/species.h" #include "constants/weather.h" -extern u8 sub_807521C(s16 x, s16 y, u8 a3); -extern void sub_810E2C8(struct Sprite *); - extern const struct SpriteTemplate gUnknown_08593114; extern const union AffineAnimCmd *const gUnknown_082FF6C0[]; extern const union AffineAnimCmd *const gUnknown_082FF694[]; diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index 05da72e16..23d469c27 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -16,6 +16,7 @@ #include "palette.h" #include "pokeball.h" #include "pokemon.h" +#include "recorded_battle.h" #include "reshow_battle_screen.h" #include "sound.h" #include "string_util.h" @@ -26,15 +27,12 @@ #include "constants/battle_anim.h" #include "constants/songs.h" #include "constants/trainers.h" +#include "recorded_battle.h" extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_81851A8(u8 *); -extern u16 sub_8068B48(void); - // this file's functions static void LinkOpponentHandleGetMonData(void); static void LinkOpponentHandleGetRawMonData(void); @@ -92,7 +90,7 @@ static void LinkOpponentHandleBattleAnimation(void); static void LinkOpponentHandleLinkStandbyMsg(void); static void LinkOpponentHandleResetActionMoveSelection(void); static void LinkOpponentHandleCmd55(void); -static void nullsub_92(void); +static void LinkOpponentCmdEnd(void); static void LinkOpponentBufferRunCommand(void); static void LinkOpponentBufferExecCompleted(void); @@ -164,7 +162,7 @@ static void (*const sLinkOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = LinkOpponentHandleLinkStandbyMsg, LinkOpponentHandleResetActionMoveSelection, LinkOpponentHandleCmd55, - nullsub_92 + LinkOpponentCmdEnd }; static void nullsub_28(void) @@ -1857,6 +1855,6 @@ static void LinkOpponentHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_92(void) +static void LinkOpponentCmdEnd(void) { } diff --git a/src/battle_controller_link_partner.c b/src/battle_controller_link_partner.c index 19d39609f..22633c5bc 100644 --- a/src/battle_controller_link_partner.c +++ b/src/battle_controller_link_partner.c @@ -16,6 +16,7 @@ #include "palette.h" #include "pokeball.h" #include "pokemon.h" +#include "recorded_battle.h" #include "reshow_battle_screen.h" #include "sound.h" #include "string_util.h" @@ -26,13 +27,11 @@ #include "constants/battle_anim.h" #include "constants/songs.h" #include "constants/trainers.h" +#include "recorded_battle.h" extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_81851A8(u8 *); - // this file's functions static void LinkPartnerHandleGetMonData(void); static void LinkPartnerHandleGetRawMonData(void); @@ -90,7 +89,7 @@ static void LinkPartnerHandleBattleAnimation(void); static void LinkPartnerHandleLinkStandbyMsg(void); static void LinkPartnerHandleResetActionMoveSelection(void); static void LinkPartnerHandleCmd55(void); -static void nullsub_113(void); +static void LinkPartnerCmdEnd(void); static void LinkPartnerBufferRunCommand(void); static void LinkPartnerBufferExecCompleted(void); @@ -161,10 +160,10 @@ static void (*const sLinkPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = LinkPartnerHandleLinkStandbyMsg, LinkPartnerHandleResetActionMoveSelection, LinkPartnerHandleCmd55, - nullsub_113 + LinkPartnerCmdEnd }; -static void nullsub_112(void) +static void SpriteCB_Null2(void) { } @@ -1564,7 +1563,7 @@ static void LinkPartnerHandleIntroTrainerBallThrow(void) gTasks[gBattlerStatusSummaryTaskId[gActiveBattler]].func = Task_HidePartyStatusSummary; gBattleSpritesDataPtr->animationData->field_9_x1 = 1; - gBattlerControllerFuncs[gActiveBattler] = nullsub_112; + gBattlerControllerFuncs[gActiveBattler] = SpriteCB_Null2; } static void sub_814DCCC(u8 taskId) @@ -1687,6 +1686,6 @@ static void LinkPartnerHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_113(void) +static void LinkPartnerCmdEnd(void) { } diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 99bb0c588..7d940cb89 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -32,14 +32,12 @@ #include "constants/moves.h" #include "constants/songs.h" #include "constants/trainers.h" +#include "trainer_hill.h" extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern u8 GetTrainerHillTrainerFrontSpriteId(u16 trainerId); - // this file's functions static void OpponentHandleGetMonData(void); static void OpponentHandleGetRawMonData(void); @@ -97,7 +95,7 @@ static void OpponentHandleBattleAnimation(void); static void OpponentHandleLinkStandbyMsg(void); static void OpponentHandleResetActionMoveSelection(void); static void OpponentHandleCmd55(void); -static void nullsub_91(void); +static void OpponentCmdEnd(void); static void OpponentBufferRunCommand(void); static void OpponentBufferExecCompleted(void); @@ -169,7 +167,7 @@ static void (*const sOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void) = OpponentHandleLinkStandbyMsg, OpponentHandleResetActionMoveSelection, OpponentHandleCmd55, - nullsub_91 + OpponentCmdEnd }; // unknown unused data @@ -2003,6 +2001,6 @@ static void OpponentHandleCmd55(void) OpponentBufferExecCompleted(); } -static void nullsub_91(void) +static void OpponentCmdEnd(void) { } diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 6bcc97c68..b377ecf64 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -39,10 +39,6 @@ extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern void sub_81AABB0(void); -extern void sub_81851A8(u8 *); - // this file's functions static void PlayerHandleGetMonData(void); static void PlayerHandleSetMonData(void); @@ -99,7 +95,7 @@ static void PlayerHandleBattleAnimation(void); static void PlayerHandleLinkStandbyMsg(void); static void PlayerHandleResetActionMoveSelection(void); static void PlayerHandleCmd55(void); -static void nullsub_22(void); +static void PlayerCmdEnd(void); static void PlayerBufferRunCommand(void); static void HandleInputChooseTarget(void); @@ -186,7 +182,7 @@ static void (*const sPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = PlayerHandleLinkStandbyMsg, PlayerHandleResetActionMoveSelection, PlayerHandleCmd55, - nullsub_22 + PlayerCmdEnd }; static const u8 sTargetIdentities[] = {B_POSITION_PLAYER_LEFT, B_POSITION_PLAYER_RIGHT, B_POSITION_OPPONENT_RIGHT, B_POSITION_OPPONENT_LEFT}; @@ -3105,6 +3101,6 @@ static void PlayerHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_22(void) +static void PlayerCmdEnd(void) { } diff --git a/src/battle_controller_player_partner.c b/src/battle_controller_player_partner.c index a9b0f376b..2c53938c1 100644 --- a/src/battle_controller_player_partner.c +++ b/src/battle_controller_player_partner.c @@ -30,9 +30,6 @@ extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; -extern void sub_81358F4(void); -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); - // this file's functions static void PlayerPartnerHandleGetMonData(void); static void PlayerPartnerHandleGetRawMonData(void); @@ -90,7 +87,7 @@ static void PlayerPartnerHandleBattleAnimation(void); static void PlayerPartnerHandleLinkStandbyMsg(void); static void PlayerPartnerHandleResetActionMoveSelection(void); static void PlayerPartnerHandleCmd55(void); -static void nullsub_128(void); +static void PlayerPartnerCmdEnd(void); static void PlayerPartnerBufferRunCommand(void); static void PlayerPartnerBufferExecCompleted(void); @@ -167,7 +164,7 @@ static void (*const sPlayerPartnerBufferCommands[CONTROLLER_CMDS_COUNT])(void) = PlayerPartnerHandleLinkStandbyMsg, PlayerPartnerHandleResetActionMoveSelection, PlayerPartnerHandleCmd55, - nullsub_128 + PlayerPartnerCmdEnd }; // unknown unused data @@ -1928,6 +1925,6 @@ static void PlayerPartnerHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_128(void) +static void PlayerPartnerCmdEnd(void) { } diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index 911eb6ce5..e43c5f8ae 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -33,9 +33,6 @@ extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); -extern u16 sub_8068B48(void); - // this file's functions static void RecordedOpponentHandleGetMonData(void); static void RecordedOpponentHandleGetRawMonData(void); @@ -93,7 +90,7 @@ static void RecordedOpponentHandleBattleAnimation(void); static void RecordedOpponentHandleLinkStandbyMsg(void); static void RecordedOpponentHandleResetActionMoveSelection(void); static void RecordedOpponentHandleCmd55(void); -static void nullsub_119(void); +static void RecordedOpponentCmdEnd(void); static void RecordedOpponentBufferRunCommand(void); static void RecordedOpponentBufferExecCompleted(void); @@ -165,7 +162,7 @@ static void (*const sRecordedOpponentBufferCommands[CONTROLLER_CMDS_COUNT])(void RecordedOpponentHandleLinkStandbyMsg, RecordedOpponentHandleResetActionMoveSelection, RecordedOpponentHandleCmd55, - nullsub_119 + RecordedOpponentCmdEnd }; static void nullsub_70(void) @@ -1791,6 +1788,6 @@ static void RecordedOpponentHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_119(void) +static void RecordedOpponentCmdEnd(void) { } diff --git a/src/battle_controller_recorded_player.c b/src/battle_controller_recorded_player.c index b2dfca6a0..412c49f17 100644 --- a/src/battle_controller_recorded_player.c +++ b/src/battle_controller_recorded_player.c @@ -30,8 +30,6 @@ extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const struct CompressedSpritePalette gTrainerFrontPicPaletteTable[]; extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); - // this file's functions static void RecordedPlayerHandleGetMonData(void); static void RecordedPlayerHandleGetRawMonData(void); @@ -89,7 +87,7 @@ static void RecordedPlayerHandleBattleAnimation(void); static void RecordedPlayerHandleLinkStandbyMsg(void); static void RecordedPlayerHandleResetActionMoveSelection(void); static void RecordedPlayerHandleCmd55(void); -static void nullsub_121(void); +static void RecordedPlayerCmdEnd(void); static void RecordedPlayerBufferRunCommand(void); static void RecordedPlayerBufferExecCompleted(void); @@ -160,7 +158,7 @@ static void (*const sRecordedPlayerBufferCommands[CONTROLLER_CMDS_COUNT])(void) RecordedPlayerHandleLinkStandbyMsg, RecordedPlayerHandleResetActionMoveSelection, RecordedPlayerHandleCmd55, - nullsub_121 + RecordedPlayerCmdEnd }; static void nullsub_120(void) @@ -1808,6 +1806,6 @@ static void RecordedPlayerHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_121(void) +static void RecordedPlayerCmdEnd(void) { } diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 54ba04ab4..e9da16252 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -25,8 +25,6 @@ extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; -extern void sub_81358F4(void); - // this file's functions static void SafariHandleGetMonData(void); static void SafariHandleGetRawMonData(void); @@ -84,7 +82,7 @@ static void SafariHandleBattleAnimation(void); static void SafariHandleLinkStandbyMsg(void); static void SafariHandleResetActionMoveSelection(void); static void SafariHandleCmd55(void); -static void nullsub_115(void); +static void SafariCmdEnd(void); static void SafariBufferRunCommand(void); static void SafariBufferExecCompleted(void); @@ -148,10 +146,10 @@ static void (*const sSafariBufferCommands[CONTROLLER_CMDS_COUNT])(void) = SafariHandleLinkStandbyMsg, SafariHandleResetActionMoveSelection, SafariHandleCmd55, - nullsub_115 + SafariCmdEnd }; -static void nullsub_114(void) +static void SpriteCB_Null4(void) { } @@ -688,6 +686,6 @@ static void SafariHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_81595E4; } -static void nullsub_115(void) +static void SafariCmdEnd(void) { } diff --git a/src/battle_controller_wally.c b/src/battle_controller_wally.c index d891b96b6..f1b783b21 100644 --- a/src/battle_controller_wally.c +++ b/src/battle_controller_wally.c @@ -33,8 +33,6 @@ extern const struct CompressedSpritePalette gTrainerBackPicPaletteTable[]; -extern void sub_8172EF0(u8 battlerId, struct Pokemon *mon); - // this file's functions static void WallyHandleGetMonData(void); static void WallyHandleGetRawMonData(void); @@ -92,7 +90,7 @@ static void WallyHandleBattleAnimation(void); static void WallyHandleLinkStandbyMsg(void); static void WallyHandleResetActionMoveSelection(void); static void WallyHandleCmd55(void); -static void nullsub_118(void); +static void WallyCmdEnd(void); static void WallyBufferRunCommand(void); static void WallyBufferExecCompleted(void); @@ -161,10 +159,10 @@ static void (*const sWallyBufferCommands[CONTROLLER_CMDS_COUNT])(void) = WallyHandleLinkStandbyMsg, WallyHandleResetActionMoveSelection, WallyHandleCmd55, - nullsub_118 + WallyCmdEnd }; -static void nullsub_117(void) +static void SpriteCB_Null7(void) { } @@ -1559,6 +1557,6 @@ static void WallyHandleCmd55(void) gBattlerControllerFuncs[gActiveBattler] = sub_80587B0; } -static void nullsub_118(void) +static void WallyCmdEnd(void) { } diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 70a53f332..29272c19a 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -767,7 +767,7 @@ static void Task_HandleSendLinkBuffersData(u8 taskId) { if (IsLinkMaster()) { - sub_800A620(); + CheckShouldAdvanceLinkState(); gTasks[taskId].data[11]++; } else diff --git a/src/battle_dome.c b/src/battle_dome.c index bfede1b28..f86faeffb 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -3794,7 +3794,7 @@ static void sub_8190CD4(u8 taskId) for (i = windowId; i < windowId + 9; i++) { CopyWindowToVram(i, 2); - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); } gTasks[taskId].data[0] = 3; break; diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index e48dbd30b..85c0b2808 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -1741,7 +1741,7 @@ static void Select_CopyMonsToPlayerParty(void) { gPlayerParty[i] = sFactorySelectScreen->mons[j].monData; gSaveBlock2Ptr->frontier.rentalMons[i].monId = sFactorySelectScreen->mons[j].monSetId; - gSaveBlock2Ptr->frontier.rentalMons[i].personality = GetMonData(&gPlayerParty[i].box, MON_DATA_PERSONALITY, NULL); + gSaveBlock2Ptr->frontier.rentalMons[i].personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY, NULL); gSaveBlock2Ptr->frontier.rentalMons[i].abilityBit = GetBoxMonData(&gPlayerParty[i].box, MON_DATA_ALT_ABILITY, NULL); gSaveBlock2Ptr->frontier.rentalMons[i].ivs = GetBoxMonData(&gPlayerParty[i].box, MON_DATA_ATK_IV, NULL); break; @@ -1786,14 +1786,14 @@ static void sub_819B958(u8 windowId) { gSprites[sFactorySelectScreen->menuCursor1SpriteId].invisible = TRUE; gSprites[sFactorySelectScreen->menuCursor2SpriteId].invisible = TRUE; - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); CopyWindowToVram(windowId, 2); ClearWindowTilemap(windowId); } static void Select_PrintRentalPkmnString(void) { - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); AddTextPrinterParameterized(0, 1, gText_RentalPkmn2, 2, 1, 0, NULL); CopyWindowToVram(0, 3); } @@ -1804,7 +1804,7 @@ static void Select_PrintMonSpecies(void) u8 x; u8 monId = sFactorySelectScreen->cursorPos; - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); species = GetMonData(&sFactorySelectScreen->mons[monId].monData, MON_DATA_SPECIES, NULL); StringCopy(gStringVar4, gSpeciesNames[species]); x = GetStringRightAlignXOffset(1, gStringVar4, 86); @@ -1816,7 +1816,7 @@ static void Select_PrintSelectMonString(void) { const u8 *str = NULL; - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); if (sFactorySelectScreen->selectingMonsState == 1) str = gText_SelectFirstPkmn; else if (sFactorySelectScreen->selectingMonsState == 2) @@ -1832,7 +1832,7 @@ static void Select_PrintSelectMonString(void) static void Select_PrintCantSelectSameMon(void) { - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized(2, 1, gText_CantSelectSamePkmn, 2, 5, 0, NULL); CopyWindowToVram(2, 2); } @@ -1842,7 +1842,7 @@ static void Select_PrintMenuOptions(void) u8 selectedId = sFactorySelectScreen->mons[sFactorySelectScreen->cursorPos].selectedId; PutWindowTilemap(3); - FillWindowPixelBuffer(3, 0); + FillWindowPixelBuffer(3, PIXEL_FILL(0)); AddTextPrinterParameterized3(3, 1, 7, 1, gUnknown_08610476, 0, gText_Summary); if (selectedId != 0) AddTextPrinterParameterized3(3, 1, 7, 17, gUnknown_08610476, 0, gText_Deselect); @@ -1856,7 +1856,7 @@ static void Select_PrintMenuOptions(void) static void Select_PrintYesNoOptions(void) { PutWindowTilemap(4); - FillWindowPixelBuffer(4, 0); + FillWindowPixelBuffer(4, PIXEL_FILL(0)); AddTextPrinterParameterized3(4, 1, 7, 1, gUnknown_08610476, 0, gText_Yes2); AddTextPrinterParameterized3(4, 1, 7, 17, gUnknown_08610476, 0, gText_No2); CopyWindowToVram(4, 3); @@ -1924,7 +1924,7 @@ static void Select_PrintMonCategory(void) if (monId < SELECTABLE_MONS_COUNT) { PutWindowTilemap(5); - FillWindowPixelBuffer(5, 0); + FillWindowPixelBuffer(5, PIXEL_FILL(0)); species = GetMonData(&sFactorySelectScreen->mons[monId].monData, MON_DATA_SPECIES, NULL); CopyMonCategoryText(SpeciesToNationalPokedexNum(species), text); x = GetStringRightAlignXOffset(1, text, 0x76); @@ -2873,7 +2873,7 @@ static void sub_819D588(u8 taskId) case 3: if (!gPaletteFade.active) { - FillWindowPixelBuffer(5, 0); + FillWindowPixelBuffer(5, PIXEL_FILL(0)); CopyWindowToVram(5, 2); if (sFactorySwapScreen->inEnemyScreen == TRUE) { @@ -3002,7 +3002,7 @@ static void sub_819D770(u8 taskId) gTasks[taskId].data[0]++; break; case 6: - FillWindowPixelBuffer(5, 0); + FillWindowPixelBuffer(5, PIXEL_FILL(0)); CopyWindowToVram(5, 2); gTasks[taskId].data[0]++; break; @@ -3546,7 +3546,7 @@ static void sub_819EA64(u8 windowId) { gSprites[sFactorySwapScreen->menuCursor1SpriteId].invisible = TRUE; gSprites[sFactorySwapScreen->menuCursor2SpriteId].invisible = TRUE; - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); CopyWindowToVram(windowId, 2); ClearWindowTilemap(windowId); } @@ -3554,14 +3554,14 @@ static void sub_819EA64(u8 windowId) static void sub_819EAC0(void) { PutWindowTilemap(1); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); CopyWindowToVram(1, 2); } static void sub_819EADC(void) { PutWindowTilemap(7); - FillWindowPixelBuffer(7, 0); + FillWindowPixelBuffer(7, PIXEL_FILL(0)); CopyWindowToVram(7, 2); } @@ -3569,13 +3569,13 @@ static void sub_819EAF8(void) { sub_819EAC0(); PutWindowTilemap(5); - FillWindowPixelBuffer(5, 0); + FillWindowPixelBuffer(5, PIXEL_FILL(0)); CopyWindowToVram(5, 2); } static void Swap_PrintPkmnSwap(void) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized(0, 1, gText_PkmnSwap, 2, 1, 0, NULL); CopyWindowToVram(0, 3); } @@ -3585,7 +3585,7 @@ static void Swap_PrintMonSpecies(void) u16 species; u8 x; - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); if (sFactorySwapScreen->cursorPos > 2) { CopyWindowToVram(1, 2); @@ -3606,7 +3606,7 @@ static void Swap_PrintMonSpecies(void) static void Swap_PrintOnInfoWindow(const u8 *str) { - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized(2, 1, str, 2, 5, 0, NULL); CopyWindowToVram(2, 2); } @@ -3614,7 +3614,7 @@ static void Swap_PrintOnInfoWindow(const u8 *str) static void Swap_PrintMenuOptions(void) { PutWindowTilemap(3); - FillWindowPixelBuffer(3, 0); + FillWindowPixelBuffer(3, PIXEL_FILL(0)); AddTextPrinterParameterized3(3, 1, 15, 1, gUnknown_08610922, 0, gText_Summary2); AddTextPrinterParameterized3(3, 1, 15, 17, gUnknown_08610922, 0, gText_Swap); AddTextPrinterParameterized3(3, 1, 15, 33, gUnknown_08610922, 0, gText_Rechoose); @@ -3624,7 +3624,7 @@ static void Swap_PrintMenuOptions(void) static void Swap_PrintYesNoOptions(void) { PutWindowTilemap(4); - FillWindowPixelBuffer(4, 0); + FillWindowPixelBuffer(4, PIXEL_FILL(0)); AddTextPrinterParameterized3(4, 1, 7, 1, gUnknown_08610922, 0, gText_Yes3); AddTextPrinterParameterized3(4, 1, 7, 17, gUnknown_08610922, 0, gText_No3); CopyWindowToVram(4, 3); @@ -3638,7 +3638,7 @@ static void Swap_PrintActionString(const u8 *str, u32 y, u32 windowId) static void Swap_PrintActionStrings(void) { - FillWindowPixelBuffer(5, 0); + FillWindowPixelBuffer(5, PIXEL_FILL(0)); switch (sFactorySwapScreen->inEnemyScreen) { case TRUE: @@ -3652,7 +3652,7 @@ static void Swap_PrintActionStrings(void) static void Swap_PrintActionStrings2(void) { - FillWindowPixelBuffer(3, 0); + FillWindowPixelBuffer(3, PIXEL_FILL(0)); switch (sFactorySwapScreen->inEnemyScreen) { case TRUE: @@ -3693,7 +3693,7 @@ static void Swap_PrintMonSpecies2(void) LoadPalette(pal, 0xF0, 0xA); PutWindowTilemap(7); - FillWindowPixelBuffer(7, 0); + FillWindowPixelBuffer(7, PIXEL_FILL(0)); if (sFactorySwapScreen->cursorPos > 2) { CopyWindowToVram(7, 3); @@ -3745,7 +3745,7 @@ static void Swap_PrintMonCategory(void) u8 x; u8 monId = sFactorySwapScreen->cursorPos; - FillWindowPixelBuffer(8, 0); + FillWindowPixelBuffer(8, PIXEL_FILL(0)); if (monId > 2) { CopyWindowToVram(8, 2); @@ -3940,7 +3940,7 @@ static void Task_SwapCantHaveSameMons(u8 taskId) case 2: if (sFactorySwapScreen->unk30 != TRUE) { - FillWindowPixelBuffer(5, 0); + FillWindowPixelBuffer(5, PIXEL_FILL(0)); CopyWindowToVram(5, 2); gTasks[taskId].data[0]++; } diff --git a/src/battle_interface.c b/src/battle_interface.c index 4a6ac67f1..f2916012e 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -2579,7 +2579,7 @@ static u8* AddTextPrinterAndCreateWindowOnHealthbox(const u8 *str, u32 x, u32 y, struct WindowTemplate winTemplate = sHealthboxWindowTemplate; winId = AddWindow(&winTemplate); - FillWindowPixelBuffer(winId, (bgColor << 4) | (bgColor)); + FillWindowPixelBuffer(winId, PIXEL_FILL(bgColor)); color[0] = bgColor; color[1] = 1; diff --git a/src/battle_main.c b/src/battle_main.c index 043e75808..2b0c5980e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -57,6 +57,7 @@ #include "constants/songs.h" #include "constants/species.h" #include "constants/trainers.h" +#include "cable_club.h" extern struct MusicPlayerInfo gMPlayInfo_SE1; extern struct MusicPlayerInfo gMPlayInfo_SE2; @@ -69,9 +70,6 @@ extern const u8 *const gBattlescriptsForRunningByItem[]; extern const u8 *const gBattlescriptsForUsingItem[]; extern const u8 *const gBattlescriptsForSafariActions[]; -// functions -extern void sub_80B3AF8(u8 taskId); // cable club - // this file's functions static void CB2_InitBattleInternal(void); static void CB2_PreInitMultiBattle(void); @@ -3279,7 +3277,7 @@ void FaintClearSetData(void) gProtectStructs[gActiveBattler].targetNotAffected = 0; gProtectStructs[gActiveBattler].chargingTurn = 0; gProtectStructs[gActiveBattler].fleeFlag = 0; - gProtectStructs[gActiveBattler].usedImprisionedMove = 0; + gProtectStructs[gActiveBattler].usedImprisonedMove = 0; gProtectStructs[gActiveBattler].loveImmobility = 0; gProtectStructs[gActiveBattler].usedDisabledMove = 0; gProtectStructs[gActiveBattler].usedTauntedMove = 0; diff --git a/src/battle_message.c b/src/battle_message.c index 164108dec..6762cd416 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1357,7 +1357,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = { // The corresponding WindowTemplate is gStandardBattleWindowTemplates[] within src/battle_bg.c { // 0 Standard battle message - .fillValue = 0xFF, + .fillValue = PIXEL_FILL(0xF), .fontId = 1, .x = 0, .y = 1, @@ -1369,7 +1369,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 6, }, { // 1 "What will (pokemon) do?" - .fillValue = 0xFF, + .fillValue = PIXEL_FILL(0xF), .fontId = 1, .x = 1, .y = 1, @@ -1381,7 +1381,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 6, }, { // 2 "Fight/Pokemon/Bag/Run" - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1393,7 +1393,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 3 Top left move - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1405,7 +1405,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 4 Top right move - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1417,7 +1417,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 5 Bottom left move - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1429,7 +1429,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 6 Bottom right move - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1441,7 +1441,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 7 "PP" - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1453,7 +1453,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 11, }, { // 8 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1465,7 +1465,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 9 PP remaining - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 2, .y = 1, @@ -1477,7 +1477,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 11, }, { // 10 "type" - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1489,7 +1489,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 11 "switch which?" - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1501,7 +1501,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 12 "gText_BattleYesNoChoice" - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1513,7 +1513,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 13 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1525,7 +1525,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 14 - .fillValue = 0x0, + .fillValue = PIXEL_FILL(0), .fontId = 1, .x = 32, .y = 1, @@ -1537,7 +1537,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 2, }, { // 15 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1549,7 +1549,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 16 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1561,7 +1561,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 17 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1573,7 +1573,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 18 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1585,7 +1585,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 19 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1597,7 +1597,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 20 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1609,7 +1609,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 15, }, { // 21 - .fillValue = 0x0, + .fillValue = PIXEL_FILL(0), .fontId = 1, .x = -1, .y = 1, @@ -1621,7 +1621,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 6, }, { // 22 - .fillValue = 0x0, + .fillValue = PIXEL_FILL(0), .fontId = 1, .x = -1, .y = 1, @@ -1633,7 +1633,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = .shadowColor = 6, }, { // 23 - .fillValue = 0x0, + .fillValue = PIXEL_FILL(0x0), .fontId = 1, .x = -1, .y = 1, @@ -1649,7 +1649,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Normal[] = static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = { { // 0 - .fillValue = 0xFF, + .fillValue = PIXEL_FILL(0xF), .fontId = 1, .x = 0, .y = 1, @@ -1661,7 +1661,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 6, }, { // 1 - .fillValue = 0xFF, + .fillValue = PIXEL_FILL(0xF), .fontId = 1, .x = 1, .y = 1, @@ -1673,7 +1673,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 6, }, { // 2 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1685,7 +1685,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 3 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1697,7 +1697,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 4 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1709,7 +1709,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 5 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1721,7 +1721,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 6 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1733,7 +1733,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 7 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1745,7 +1745,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 11, }, { // 8 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1757,7 +1757,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 9 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 2, .y = 1, @@ -1769,7 +1769,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 11, }, { // 10 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1781,7 +1781,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 11 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 7, .x = 0, .y = 1, @@ -1793,7 +1793,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 12 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1805,7 +1805,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 13 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = 0, .y = 1, @@ -1817,7 +1817,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 14 - .fillValue = 0x0, + .fillValue = PIXEL_FILL(0), .fontId = 1, .x = 32, .y = 1, @@ -1829,7 +1829,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 2, }, { // 15 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1841,7 +1841,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 16 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1853,7 +1853,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 17 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1865,7 +1865,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 18 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1877,7 +1877,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 19 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1889,7 +1889,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 20 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1901,7 +1901,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 21 - .fillValue = 0xEE, + .fillValue = PIXEL_FILL(0xE), .fontId = 1, .x = -1, .y = 1, @@ -1913,7 +1913,7 @@ static const struct BattleWindowText sTextOnWindowsInfo_Arena[] = .shadowColor = 15, }, { // 22 - .fillValue = 0x11, + .fillValue = PIXEL_FILL(0x1), .fontId = 1, .x = 0, .y = 1, diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 340c17c59..34da3a25d 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1267,7 +1267,7 @@ static u8 GetPostBattleDirectionHintTextIndex(int *hintType, u8 minDistanceForEx { for (x = 0; x < 32; x++) { - if ((map[x] & 0x3FF) == FLOOR_EXIT_METATILE) + if ((map[x] & METATILE_ID_MASK) == FLOOR_EXIT_METATILE) { x += 7 - gEventObjects[gSelectedEventObject].initialCoords.x; y += 7 - gEventObjects[gSelectedEventObject].initialCoords.y; @@ -1568,7 +1568,7 @@ void GenerateBattlePyramidFloorLayout(u16 *backupMapData, bool8 setPlayerPositio { for (x = 0; x < mapLayout->width; x++) { - if ((layoutMap[x] & 0x3FF) != FLOOR_EXIT_METATILE) + if ((layoutMap[x] & METATILE_ID_MASK) != FLOOR_EXIT_METATILE) { map[x] = layoutMap[x]; } diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 1f0672dcb..2e13ea08b 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -651,7 +651,7 @@ static void PrintItemDescription(s32 listMenuId) StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1); desc = gStringVar4; } - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, desc, 3, 0, 0, 1, 0, 0); } @@ -804,7 +804,7 @@ static void sub_81C5A98(u8 listMenuTaskId, u8 arg1) static void sub_81C5AB8(u8 y, u8 arg1) { if (arg1 == 0xFF) - FillWindowPixelRect(0, 0, 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); + FillWindowPixelRect(0, PIXEL_FILL(0), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); else PrintOnWindow_Font1(0, gText_SelectorArrow2, 0, y, 0, 0, 0, arg1); } @@ -911,7 +911,7 @@ static void sub_81C5D20(u8 taskId) CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); if (gPyramidBagResources->menuActionsCount == 1) sub_81C5EAC(sub_81C6D24(0)); @@ -1048,7 +1048,7 @@ static void BagAction_UseOnField(u8 taskId) else if (ItemId_GetFieldFunc(gSpecialVar_ItemId) != NULL) { sub_81C61A8(); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); schedule_bg_copy_tilemap_to_vram(0); ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId); } @@ -1086,7 +1086,7 @@ static void BagAction_Toss(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_TossHowManyVar1s); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); sub_81C6404(); gTasks[taskId].func = sub_81C64B4; @@ -1100,7 +1100,7 @@ static void sub_81C6350(u8 taskId) CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); sub_81C6DAC(taskId, &sYesNoTossFuncions); } @@ -1146,7 +1146,7 @@ static void sub_81C64B4(u8 taskId) else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - sub_8198070(3, 0); + ClearStdWindowAndFrameToTransparent(3, 0); ClearWindowTilemap(3); schedule_bg_copy_tilemap_to_vram(1); sub_81C6350(taskId); @@ -1154,7 +1154,7 @@ static void sub_81C64B4(u8 taskId) else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_8198070(3, 0); + ClearStdWindowAndFrameToTransparent(3, 0); ClearWindowTilemap(3); schedule_bg_copy_tilemap_to_vram(1); DontTossItem(taskId); @@ -1168,7 +1168,7 @@ static void TossItem(u8 taskId) CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[8], STR_CONV_MODE_LEFT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); gTasks[taskId].func = sub_81C65CC; } @@ -1265,7 +1265,7 @@ static void Task_BeginItemSwap(u8 taskId) ListMenuSetUnkIndicatorsStructField(data[0], 0x10, 1); CopyItemName(gSaveBlock2Ptr->frontier.pyramidBag.itemId[gSaveBlock2Ptr->frontier.lvlMode][data[1]], gStringVar1); StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); PrintOnWindow_Font1(1, gStringVar4, 3, 0, 0, 1, 0, 0); sub_81C5A98(data[0], 1); sub_81C704C(data[1]); @@ -1395,7 +1395,7 @@ static void sub_81C6BD8(void) LoadPalette(gUnknown_0860F074, 0xF0, 0x20); for (i = 0; i < 5; i++) - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); PutWindowTilemap(0); PutWindowTilemap(1); @@ -1415,7 +1415,7 @@ static void PrintOnWindow_Font7(u8 windowId, const u8 *src, u8 x, u8 y, u8 lette static void sub_81C6CEC(u8 windowId) { - SetWindowBorderStyle(windowId, 0, 1, 0xE); + DrawStdFrameWithCustomTileAndPalette(windowId, 0, 1, 0xE); schedule_bg_copy_tilemap_to_vram(1); } @@ -1430,7 +1430,7 @@ static u8 sub_81C6D24(u8 windowArrayId) if (*windowId == 0xFF) { *windowId = AddWindow(&gUnknown_0861F350[windowArrayId]); - SetWindowBorderStyle(*windowId, FALSE, 1, 0xE); + DrawStdFrameWithCustomTileAndPalette(*windowId, FALSE, 1, 0xE); schedule_bg_copy_tilemap_to_vram(1); } return *windowId; @@ -1441,7 +1441,7 @@ static void sub_81C6D6C(u8 windowArrayId) u8 *windowId = &gPyramidBagResources->windowIds[windowArrayId]; if (*windowId != 0xFF) { - sub_8198070(*windowId, FALSE); + ClearStdWindowAndFrameToTransparent(*windowId, FALSE); ClearWindowTilemap(*windowId); RemoveWindow(*windowId); schedule_bg_copy_tilemap_to_vram(1); @@ -1456,14 +1456,15 @@ static void sub_81C6DAC(u8 taskId, const struct YesNoFuncTable *yesNoTable) void DisplayItemMessageInBattlePyramid(u8 taskId, const u8 *str, void (*callback)(u8 taskId)) { - FillWindowPixelBuffer(2, 0x11); + FillWindowPixelBuffer(2, PIXEL_FILL(1)); DisplayMessageAndContinueTask(taskId, 2, 0xA, 0xD, 1, GetPlayerTextSpeedDelay(), str, callback); schedule_bg_copy_tilemap_to_vram(1); } static void sub_81C6E1C(void) { - sub_8197DF8(2, FALSE); + ClearDialogWindowAndFrameToTransparent(2, FALSE); + // This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it. ClearWindowTilemap(2); schedule_bg_copy_tilemap_to_vram(1); } diff --git a/src/battle_records.c b/src/battle_records.c index f9c40d8de..fdd915d07 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -21,8 +21,7 @@ #include "alloc.h" #include "gpu_regs.h" #include "constants/game_stat.h" - -extern void PrintOnTrainerHillRecordsWindow(void); // pokenav.s +#include "trainer_hill.h" // this file's functions static void Task_CloseTrainerHillRecordsOnButton(u8 taskId); @@ -320,8 +319,8 @@ void ShowLinkBattleRecords(void) s32 i, x; gRecordsWindowId = AddWindow(&sLinkBattleRecordsWindow); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); StringExpandPlaceholders(gStringVar4, gText_PlayersBattleResults); x = GetStringCenterAlignXOffset(1, gStringVar4, 208); @@ -342,7 +341,7 @@ void ShowLinkBattleRecords(void) void RemoveRecordsWindow(void) { - sub_819746C(gRecordsWindowId, FALSE); + ClearStdWindowAndFrame(gRecordsWindowId, FALSE); RemoveWindow(gRecordsWindowId); } @@ -383,7 +382,7 @@ static void Task_ExitTrainerHillRecords(u8 taskId) static void RemoveTrainerHillRecordsWindow(u8 windowId) { - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); ClearWindowTilemap(windowId); CopyWindowToVram(windowId, 2); RemoveWindow(windowId); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a53fa30f2..ac9fb3073 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -48,6 +48,7 @@ #include "battle_pyramid.h" #include "field_specials.h" #include "pokemon_summary_screen.h" +#include "pokenav.h" extern struct MusicPlayerInfo gMPlayInfo_BGM; @@ -55,9 +56,6 @@ extern const u8* const gBattleScriptsForMoveEffects[]; // functions extern void sub_81D388C(struct Pokemon* mon, void* statStoreLocation); // pokenav.s -extern void sub_81D3640(u16 arg0, void* statStoreLocation1, void* statStoreLocation2, u8 arg3, u8 arg4, u8 arg5); // pokenav.s -extern void sub_81D3784(u16 arg0, void* statStoreLocation1, u8 arg2, u8 arg3, u8 arg4); // pokenav.s -extern u8 sub_813B21C(void); #define DEFENDER_IS_PROTECTED ((gProtectStructs[gBattlerTarget].protected) && (gBattleMoves[gCurrentMove].flags & FLAG_PROTECT_AFFECTED)) @@ -297,7 +295,7 @@ static void atkD7_setyawn(void); static void atkD8_setdamagetohealthdifference(void); static void atkD9_scaledamagebyhealthratio(void); static void atkDA_tryswapabilities(void); -static void atkDB_tryimprision(void); +static void atkDB_tryimprison(void); static void atkDC_trysetgrudge(void); static void atkDD_weightdamagecalculation(void); static void atkDE_asistattackselect(void); @@ -549,7 +547,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = atkD8_setdamagetohealthdifference, atkD9_scaledamagebyhealthratio, atkDA_tryswapabilities, - atkDB_tryimprision, + atkDB_tryimprison, atkDC_trysetgrudge, atkDD_weightdamagecalculation, atkDE_asistattackselect, @@ -9611,7 +9609,7 @@ static void atkDA_tryswapabilities(void) // skill swap } } -static void atkDB_tryimprision(void) +static void atkDB_tryimprison(void) { if ((gStatuses3[gBattlerAttacker] & STATUS3_IMPRISONED_OTHERS)) { @@ -9622,7 +9620,7 @@ static void atkDB_tryimprision(void) u8 battlerId, sideAttacker; sideAttacker = GetBattlerSide(gBattlerAttacker); - PressurePPLoseOnUsingImprision(gBattlerAttacker); + PressurePPLoseOnUsingImprison(gBattlerAttacker); for (battlerId = 0; battlerId < gBattlersCount; battlerId++) { if (sideAttacker != GetBattlerSide(battlerId)) diff --git a/src/battle_setup.c b/src/battle_setup.c index 7626420e9..347486a0b 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -44,6 +44,7 @@ #include "mirage_tower.h" #include "constants/map_types.h" #include "constants/battle_frontier.h" +#include "field_screen_effect.h" enum { @@ -62,10 +63,6 @@ struct TrainerBattleParameter u8 ptrType; }; -extern void ClearPoisonStepCounter(void); -extern void sub_808BCF4(void); -extern void sub_80AF6F0(void); - // this file's functions static void DoBattlePikeWildBattle(void); static void DoSafariBattle(void); @@ -641,7 +638,7 @@ u8 BattleSetup_GetTerrainId(void) return BATTLE_TERRAIN_BUILDING; case MAP_TYPE_UNDERWATER: return BATTLE_TERRAIN_UNDERWATER; - case MAP_TYPE_6: + case MAP_TYPE_OCEAN_ROUTE: if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior)) return BATTLE_TERRAIN_WATER; return BATTLE_TERRAIN_PLAIN; diff --git a/src/battle_tower.c b/src/battle_tower.c index 06aaef48d..46aab4bac 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -51,7 +51,7 @@ static void AwardBattleTowerRibbons(void); static void SaveBattleTowerProgress(void); static void sub_8163914(void); static void nullsub_61(void); -static void nullsub_116(void); +static void SpriteCB_Null6(void); static void sub_81642A0(void); static void sub_8164828(void); static void sub_8164B74(void); @@ -1061,7 +1061,7 @@ static void (* const gUnknown_085DF96C[])(void) = SaveBattleTowerProgress, sub_8163914, nullsub_61, - nullsub_116, + SpriteCB_Null6, sub_81642A0, sub_8164828, sub_8164B74, @@ -2437,7 +2437,7 @@ static void nullsub_61(void) } -static void nullsub_116(void) +static void SpriteCB_Null6(void) { } diff --git a/src/battle_util.c b/src/battle_util.c index 2f583a9c7..aa88cf952 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -106,10 +106,10 @@ void PressurePPLose(u8 target, u8 attacker, u16 move) } } -void PressurePPLoseOnUsingImprision(u8 attacker) +void PressurePPLoseOnUsingImprison(u8 attacker) { int i, j; - int imprisionPos = 4; + int imprisonPos = 4; u8 atkSide = GetBattlerSide(attacker); for (i = 0; i < gBattlersCount; i++) @@ -123,19 +123,19 @@ void PressurePPLoseOnUsingImprision(u8 attacker) } if (j != MAX_MON_MOVES) { - imprisionPos = j; + imprisonPos = j; if (gBattleMons[attacker].pp[j] != 0) gBattleMons[attacker].pp[j]--; } } } - if (imprisionPos != 4 + if (imprisonPos != 4 && !(gBattleMons[attacker].status2 & STATUS2_TRANSFORMED) - && !(gDisableStructs[attacker].mimickedMoves & gBitTable[imprisionPos])) + && !(gDisableStructs[attacker].mimickedMoves & gBitTable[imprisonPos])) { gActiveBattler = attacker; - BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + imprisionPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisionPos]); + BtlController_EmitSetMonData(0, REQUEST_PPMOVE1_BATTLE + imprisonPos, 0, 1, &gBattleMons[gActiveBattler].pp[imprisonPos]); MarkBattlerForControllerExec(gActiveBattler); } } @@ -224,7 +224,7 @@ bool8 WasUnableToUseMove(u8 battler) { if (gProtectStructs[battler].prlzImmobility || gProtectStructs[battler].targetNotAffected - || gProtectStructs[battler].usedImprisionedMove + || gProtectStructs[battler].usedImprisonedMove || gProtectStructs[battler].loveImmobility || gProtectStructs[battler].usedDisabledMove || gProtectStructs[battler].usedTauntedMove @@ -365,12 +365,12 @@ u8 TrySetCantSelectMoveBattleScript(void) gCurrentMove = move; if (gBattleTypeFlags & BATTLE_TYPE_PALACE) { - gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisionedMoveInPalace; + gPalaceSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisonedMoveInPalace; gProtectStructs[gActiveBattler].palaceUnableToUseMove = 1; } else { - gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisionedMove; + gSelectionBattleScripts[gActiveBattler] = BattleScript_SelectingImprisonedMove; limitations++; } } @@ -438,7 +438,7 @@ u8 CheckMoveLimitations(u8 battlerId, u8 unusableMoves, u8 check) unusableMoves |= gBitTable[i]; if (gDisableStructs[battlerId].tauntTimer && check & MOVE_LIMITATION_TAUNT && gBattleMoves[gBattleMons[battlerId].moves[i]].power == 0) unusableMoves |= gBitTable[i]; - if (GetImprisonedMovesCount(battlerId, gBattleMons[battlerId].moves[i]) && check & MOVE_LIMITATION_IMPRISION) + if (GetImprisonedMovesCount(battlerId, gBattleMons[battlerId].moves[i]) && check & MOVE_LIMITATION_IMPRISON) unusableMoves |= gBitTable[i]; if (gDisableStructs[battlerId].encoreTimer && gDisableStructs[battlerId].encoredMove != gBattleMons[battlerId].moves[i]) unusableMoves |= gBitTable[i]; @@ -469,7 +469,7 @@ bool8 AreAllMovesUnusable(void) u8 GetImprisonedMovesCount(u8 battlerId, u16 move) { s32 i; - u8 imprisionedMoves = 0; + u8 imprisonedMoves = 0; u8 battlerSide = GetBattlerSide(battlerId); for (i = 0; i < gBattlersCount; i++) @@ -483,11 +483,11 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) break; } if (j < MAX_MON_MOVES) - imprisionedMoves++; + imprisonedMoves++; } } - return imprisionedMoves; + return imprisonedMoves; } enum @@ -1466,7 +1466,7 @@ u8 AtkCanceller_UnableToUseMove(void) case CANCELLER_IMPRISONED: // imprisoned if (GetImprisonedMovesCount(gBattlerAttacker, gCurrentMove)) { - gProtectStructs[gBattlerAttacker].usedImprisionedMove = 1; + gProtectStructs[gBattlerAttacker].usedImprisonedMove = 1; CancelMultiTurnMoves(gBattlerAttacker); gBattlescriptCurrInstr = BattleScript_MoveUsedIsImprisoned; gHitMarker |= HITMARKER_UNABLE_TO_USE_MOVE; @@ -1526,7 +1526,7 @@ u8 AtkCanceller_UnableToUseMove(void) } else { - BattleScriptPush(BattleScript_MoveUsedIsParalyzedCantAttack); + BattleScriptPush(BattleScript_MoveUsedIsInLoveCantAttack); gHitMarker |= HITMARKER_UNABLE_TO_USE_MOVE; gProtectStructs[gBattlerAttacker].loveImmobility = 1; CancelMultiTurnMoves(gBattlerAttacker); diff --git a/src/berry.c b/src/berry.c index bd596db7f..cbac06a3d 100644 --- a/src/berry.c +++ b/src/berry.c @@ -11,11 +11,9 @@ #include "text.h" #include "constants/event_object_movement_constants.h" #include "constants/items.h" +#include "event_object_movement.h" + -extern u8 EventObjectGetBerryTreeId(u8 eventObjectId); -extern void sub_8092EF0(u8 mapId, u8 mapNumber, u8 mapGroup); -extern void CB2_ChooseBerry(void); -extern bool8 IsBerryTreeSparkling(u8, u8, u8); extern const u8 BerryTreeScript[]; diff --git a/src/berry_blender.c b/src/berry_blender.c index c85d0e827..450bcae42 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -34,6 +34,8 @@ #include "battle_records.h" #include "graphics.h" #include "new_game.h" +#include "save.h" +#include "link.h" #define BLENDER_SCORE_BEST 0 #define BLENDER_SCORE_GOOD 1 @@ -140,16 +142,6 @@ extern const u8 gText_Space[]; extern const u8 gText_BlenderMaxSpeedRecord[]; extern const u8 gText_234Players[]; -extern void sub_800A418(void); -extern u8 sub_800A9D8(void); -extern void sub_81AABF0(void (*callback)(void)); -extern void sub_800B4C0(void); -extern void ClearLinkCallback(void); -extern void sub_8009F8C(void); -extern void sub_8153430(void); -extern bool8 sub_8153474(void); -extern void sub_80EECEC(void); - // this file's functions static void BerryBlender_SetBackgroundsPos(void); static void sub_8080EA4(u8 taskId); @@ -945,7 +937,7 @@ static void InitBerryBlenderWindows(void) DeactivateAllTextPrinters(); for (i = 0; i < 5; i++) - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x1E, 0x14); sub_81978B0(0xE0); @@ -1251,7 +1243,7 @@ static void sub_8080018(void) case 10: if (++sBerryBlenderData->framesToWait > 20) { - sub_8197DF8(4, TRUE); + ClearDialogWindowAndFrameToTransparent(4, TRUE); if (GetBlockReceivedStatus() == sub_800A9D8()) { for (i = 0; i < GetLinkPlayerCount(); i++) @@ -2600,7 +2592,7 @@ static bool8 LinkPlayAgainHandleSaving(void) } break; case 2: - sub_8153430(); + FullSaveGame(); sBerryBlenderData->field_1A0++; sBerryBlenderData->framesToWait = 0; break; @@ -2614,7 +2606,7 @@ static bool8 LinkPlayAgainHandleSaving(void) case 4: if (IsLinkTaskFinished()) { - if (sub_8153474()) + if (CheckSaveFile()) { sBerryBlenderData->field_1A0 = 5; } @@ -3325,7 +3317,7 @@ static bool8 Blender_PrintBlendingResults(void) sBerryBlenderData->mainState++; break; case 5: - sub_8198070(5, 1); + ClearStdWindowAndFrameToTransparent(5, 1); for (i = 0; i < BLENDER_MAX_PLAYERS; i++) { @@ -3466,7 +3458,7 @@ static bool8 Blender_PrintBlendingRanking(void) } break; case 3: - SetWindowBorderStyle(5, 0, 1, 0xD); + DrawStdFrameWithCustomTileAndPalette(5, 0, 1, 0xD); xPos = GetStringCenterAlignXOffset(1, sText_Ranking, 0xA8); Blender_AddTextPrinter(5, sText_Ranking, xPos, 1, TEXT_SPEED_FF, 0); @@ -3537,8 +3529,8 @@ void ShowBerryBlenderRecordWindow(void) winTemplate = sBlenderRecordWindowTemplate; gRecordsWindowId = AddWindow(&winTemplate); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, 0); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, 0); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); xPos = GetStringCenterAlignXOffset(1, gText_BlenderMaxSpeedRecord, 0x90); AddTextPrinterParameterized(gRecordsWindowId, 1, gText_BlenderMaxSpeedRecord, xPos, 1, 0, NULL); @@ -3647,7 +3639,7 @@ static void Blender_AddTextPrinter(u8 windowId, const u8 *string, u8 x, u8 y, s3 if (caseId != 3) { - FillWindowPixelBuffer(windowId, txtColor[0] | (txtColor[0] << 4)); + FillWindowPixelBuffer(windowId, PIXEL_FILL(txtColor[0])); } AddTextPrinterParameterized4(windowId, 1, x, y, letterSpacing, 1, txtColor, speed, string); @@ -3658,7 +3650,7 @@ static bool32 Blender_PrintText(s16 *textState, const u8 *string, s32 textSpeed) switch (*textState) { case 0: - sub_8197B1C(4, FALSE, 0x14, 0xF); + DrawDialogFrameWithCustomTileAndPalette(4, FALSE, 0x14, 0xF); Blender_AddTextPrinter(4, string, 0, 1, textSpeed, 0); PutWindowTilemap(4); CopyWindowToVram(4, 3); diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c index 3631c083a..37be569f8 100644 --- a/src/berry_fix_program.c +++ b/src/berry_fix_program.c @@ -226,9 +226,9 @@ static void berry_fix_gpu_set(void) DmaCopy32(3, sUnknown_08618138, BG_PLTT + 0x1E0, 0x20); SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP); - FillWindowPixelBuffer(2, 0); - FillWindowPixelBuffer(3, 0); - FillWindowPixelBuffer(0, 0xAA); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); + FillWindowPixelBuffer(3, PIXEL_FILL(0)); + FillWindowPixelBuffer(0, PIXEL_FILL(0xA)); width = GetStringWidth(0, sUnknown_08617E9B, 0); left = (0x78 - width) / 2; @@ -273,7 +273,7 @@ static int berry_fix_text_update(int checkval) static void berry_fix_text_print(int scene) { FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); - FillWindowPixelBuffer(1, 0xAA); + FillWindowPixelBuffer(1, PIXEL_FILL(0xA)); AddTextPrinterParameterized3(1, 1, 0, 0, sUnknown_08618158, -1, gUnknown_08618160[scene]); PutWindowTilemap(1); CopyWindowToVram(1, 2); diff --git a/src/berry_tag_screen.c b/src/berry_tag_screen.c index 6e968fc0a..a7cf4daf2 100644 --- a/src/berry_tag_screen.c +++ b/src/berry_tag_screen.c @@ -381,7 +381,7 @@ static void PrintTextInBerryTagScreen(u8 windowId, const u8 *text, u8 x, u8 y, s static void AddBerryTagTextToBg0(void) { memcpy(GetBgTilemapBuffer(0), sBerryTag->tilemapBuffers[2], sizeof(sBerryTag->tilemapBuffers[2])); - FillWindowPixelBuffer(WIN_BERRY_TAG, 0xFF); + FillWindowPixelBuffer(WIN_BERRY_TAG, PIXEL_FILL(15)); PrintTextInBerryTagScreen(WIN_BERRY_TAG, gText_BerryTag, GetStringCenterAlignXOffset(1, gText_BerryTag, 0x40), 1, 0, 1); PutWindowTilemap(WIN_BERRY_TAG); schedule_bg_copy_tilemap_to_vram(0); @@ -598,7 +598,7 @@ static void Task_DisplayAnotherBerry(u8 taskId) switch (data[0]) { case 0x30: - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); break; case 0x40: PrintBerryNumberAndName(); @@ -608,7 +608,7 @@ static void Task_DisplayAnotherBerry(u8 taskId) CreateBerrySprite(); break; case 0x60: - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); break; case 0x70: PrintBerrySize(); @@ -620,7 +620,7 @@ static void Task_DisplayAnotherBerry(u8 taskId) SetFlavorCirclesVisiblity(); break; case 0xA0: - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); break; case 0xB0: PrintBerryDescription1(); @@ -635,7 +635,7 @@ static void Task_DisplayAnotherBerry(u8 taskId) switch (data[0]) { case 0x30: - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); break; case 0x40: PrintBerryDescription2(); @@ -647,7 +647,7 @@ static void Task_DisplayAnotherBerry(u8 taskId) SetFlavorCirclesVisiblity(); break; case 0x70: - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); break; case 0x80: PrintBerryFirmness(); @@ -660,7 +660,7 @@ static void Task_DisplayAnotherBerry(u8 taskId) CreateBerrySprite(); break; case 0xB0: - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); break; case 0xC0: PrintBerryNumberAndName(); @@ -1056,7 +1056,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt for (x16 = x; x16 < (x + width); x16++) { CopyTileMapEntry(&firstTileNum, &((u16*)sGpuBgConfigs2[bg].tilemap)[(u16)GetTileMapIndexFromCoords(x16, y16, attribute, mode, mode2)], paletteSlot, 0, 0); - firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF); + firstTileNum = (firstTileNum & (METATILE_COLLISION_MASK | METATILE_ELEVATION_MASK)) + ((firstTileNum + tileNumDelta) & METATILE_ID_MASK); } } break; @@ -1067,7 +1067,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt for (x16 = x; x16 < (x + width); x16++) { ((u8*)sGpuBgConfigs2[bg].tilemap)[(y16 * mode3) + x16] = firstTileNum; - firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF); + firstTileNum = (firstTileNum & (METATILE_COLLISION_MASK | METATILE_ELEVATION_MASK)) + ((firstTileNum + tileNumDelta) & METATILE_ID_MASK); } } break; diff --git a/src/bike.c b/src/bike.c index 1e91baab0..530742bdf 100644 --- a/src/bike.c +++ b/src/bike.c @@ -14,12 +14,6 @@ extern bool8 gBikeCyclingChallenge; extern u8 gBikeCollisions; -extern u8 sub_808B980(u8 direction); -extern u8 sub_808B9BC(u8 direction); -extern u8 sub_808B9A4(u8 direction); -extern u8 sub_808C1B4(u8 direction); -extern u8 sub_808B9D4(u8 direction); - // this file's functions static void MovePlayerOnMachBike(u8, u16, u16); static u8 GetMachBikeTransition(u8 *); diff --git a/src/cable_club.c b/src/cable_club.c index 303b0d016..b80e76e99 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -92,7 +92,9 @@ static void sub_80B23B0(u16 windowId, u32 value) static void sub_80B241C(u16 windowId) { - sub_819746C(windowId, FALSE); + // Following this call with a copy-to-vram with mode 3 is identical to + // calling ClearStdWindowAndFrame(windowId, TRUE). + ClearStdWindowAndFrame(windowId, FALSE); CopyWindowToVram(windowId, 3); } @@ -282,7 +284,7 @@ static void sub_80B2804(u8 taskId) if (GetFieldMessageBoxMode() == FIELD_MESSAGE_BOX_HIDDEN) { - if (sub_800AA48() != GetLinkPlayerCount_2()) + if (GetSavedPlayerCount() != GetLinkPlayerCount_2()) { ShowFieldAutoScrollMessage(gText_ConfirmLinkWhenPlayersReady); gTasks[taskId].func = sub_80B270C; @@ -295,7 +297,7 @@ static void sub_80B2804(u8 taskId) else if (gMain.heldKeys & A_BUTTON) { PlaySE(SE_SELECT); - sub_800A620(); + CheckShouldAdvanceLinkState(); gTasks[taskId].func = sub_80B28A8; } } @@ -310,7 +312,7 @@ static void sub_80B28A8(u8 taskId) || sub_80B2D6C(taskId) == TRUE) return; - if (GetLinkPlayerCount_2() != sub_800AA48()) + if (GetLinkPlayerCount_2() != GetSavedPlayerCount()) { gTasks[taskId].func = sub_80B2D2C; } @@ -352,7 +354,7 @@ static void sub_80B2918(u8 taskId) else { gFieldLinkPlayerCount = GetLinkPlayerCount_2(); - gUnknown_03005DB4 = GetMultiplayerId(); + gLocalLinkPlayerId = GetMultiplayerId(); sub_800AA04(gFieldLinkPlayerCount); card = (struct TrainerCard *)gBlockSendBuffer; TrainerCard_GenerateCardForPlayer(card); @@ -399,7 +401,7 @@ static void sub_80B2A08(u8 taskId) else { gFieldLinkPlayerCount = GetLinkPlayerCount_2(); - gUnknown_03005DB4 = GetMultiplayerId(); + gLocalLinkPlayerId = GetMultiplayerId(); sub_800AA04(gFieldLinkPlayerCount); card = (struct TrainerCard *)gBlockSendBuffer; TrainerCard_GenerateCardForPlayer(card); @@ -764,9 +766,9 @@ static void sub_80B3194(u8 taskId) static void sub_80B31E8(u8 taskId) { - if (sub_800AA48() == GetLinkPlayerCount_2()) + if (GetSavedPlayerCount() == GetLinkPlayerCount_2()) { - sub_800A620(); + CheckShouldAdvanceLinkState(); gTasks[taskId].func = sub_80B3220; } } @@ -972,7 +974,7 @@ void sub_80B360C(void) if (gSpecialVar_0x8004 == 1 || gSpecialVar_0x8004 == 2) { - UpdatePlayerLinkBattleRecords(gUnknown_03005DB4 ^ 1); + UpdatePlayerLinkBattleRecords(gLocalLinkPlayerId ^ 1); if (gWirelessCommType) { switch (gBattleOutcome) @@ -993,13 +995,13 @@ void sub_80B360C(void) } else { - gMain.savedCallback = c2_8056854; + gMain.savedCallback = CB2_ReturnToFieldFromMultiplayer; } SetMainCallback2(sub_80A0514); } -void sub_80B36EC(void) +void CleanupLinkRoomState(void) { if (gSpecialVar_0x8004 == 1 || gSpecialVar_0x8004 == 2 || gSpecialVar_0x8004 == 5 || gSpecialVar_0x8004 == 9) { @@ -1009,9 +1011,9 @@ void sub_80B36EC(void) SetWarpDestinationToDynamicWarp(0x7F); } -void sub_80B371C(void) +void ExitLinkRoom(void) { - sub_80872B0(); + QueueExitLinkRoomKey(); } static void sub_80B3728(u8 taskId) @@ -1028,7 +1030,7 @@ static void sub_80B3728(u8 taskId) if (IsFieldMessageBoxHidden()) { sub_8087288(); - sub_8009628(gSpecialVar_0x8005); + SetLocalLinkPlayerId(gSpecialVar_0x8005); task->data[0] = 2; } break; @@ -1130,7 +1132,8 @@ static void sub_80B3894(u8 taskId) } } -void sub_80B3924(void) +// Note: VAR_0x8005 is set to the ID of the trade seat. +void PlayerEnteredTradeSeat(void) { if (gWirelessCommType != 0) { @@ -1152,7 +1155,8 @@ void nullsub_37(void) } -void sub_80B3968(void) +// Note: VAR_0x8005 is set to the ID of the player spot. +void ColosseumPlayerSpotTriggered(void) { gLinkType = 0x2211; @@ -1166,6 +1170,7 @@ void sub_80B3968(void) } } +// This function is never called. static void sub_80B39A4(void) { u8 taskId = CreateTask(sub_80B3728, 80); @@ -1177,14 +1182,16 @@ void sp02A_crash_sound(void) ShowTrainerCardInLink(gSpecialVar_0x8006, CB2_ReturnToFieldContinueScriptPlayMapMusic); } -bool32 sub_80B39D4(u8 linkPlayerIndex) +// Returns FALSE if the player has no stars. Returns TRUE otherwise, and puts the name of the +// color into gStringVar2. +bool32 GetLinkTrainerCardColor(u8 linkPlayerIndex) { u32 trainerCardColorIndex; gSpecialVar_0x8006 = linkPlayerIndex; StringCopy(gStringVar1, gLinkPlayers[linkPlayerIndex].name); - trainerCardColorIndex = sub_80C4904(linkPlayerIndex); + trainerCardColorIndex = GetTrainerCardStars(linkPlayerIndex); if (trainerCardColorIndex == 0) return FALSE; @@ -1263,13 +1270,13 @@ void sub_80B3AF8(u8 taskId) } break; case 2: - if (GetLinkPlayerCount_2() >= sub_800AA48()) + if (GetLinkPlayerCount_2() >= GetSavedPlayerCount()) { if (IsLinkMaster()) { if (++data[1] > 30) { - sub_800A620(); + CheckShouldAdvanceLinkState(); data[0]++; } } diff --git a/src/clear_save_data_screen.c b/src/clear_save_data_screen.c index 5ec90e10c..c1d6930c7 100644 --- a/src/clear_save_data_screen.c +++ b/src/clear_save_data_screen.c @@ -79,7 +79,7 @@ void CB2_InitClearSaveDataScreen(void) static void Task_DoClearSaveDataScreenYesNo(u8 taskId) { - SetWindowBorderStyle(0, 0, 2, 14); + DrawStdFrameWithCustomTileAndPalette(0, 0, 2, 14); AddTextPrinterParameterized(0, 1, gText_ClearAllSaveData, 0, 1, 0, 0); CreateYesNoMenu(sClearSaveYesNo, 2, 14, 1); gTasks[taskId].func = Task_ClearSaveDataScreenYesNoChoice; @@ -90,7 +90,7 @@ static void Task_ClearSaveDataScreenYesNoChoice(u8 taskId) switch (Menu_ProcessInputNoWrapClearOnChoose()) { case 0: - FillWindowPixelBuffer(0, 17); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized(0, 1, gText_ClearingData, 0, 1, 0, 0); gTasks[taskId].func = Task_ClearSaveData; break; @@ -203,7 +203,7 @@ static void InitClearSaveDataScreenWindows(void) { InitWindows(sClearSaveTextWindow); DeactivateAllTextPrinters(); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); LoadWindowGfx(0, 0, 2, 224); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); } diff --git a/src/coins.c b/src/coins.c index 967eb92ac..b838c303e 100644 --- a/src/coins.c +++ b/src/coins.c @@ -27,15 +27,15 @@ void ShowCoinsWindow(u32 coinAmount, u8 x, u8 y) struct WindowTemplate template; SetWindowTemplateFields(&template, 0, x, y, 8, 2, 0xF, 0x141); sCoinsWindowId = AddWindow(&template); - FillWindowPixelBuffer(sCoinsWindowId, 0); + FillWindowPixelBuffer(sCoinsWindowId, PIXEL_FILL(0)); PutWindowTilemap(sCoinsWindowId); - SetWindowBorderStyle(sCoinsWindowId, FALSE, 0x214, 0xE); + DrawStdFrameWithCustomTileAndPalette(sCoinsWindowId, FALSE, 0x214, 0xE); PrintCoinsString(coinAmount); } void HideCoinsWindow(void) { - sub_819746C(sCoinsWindowId, TRUE); + ClearStdWindowAndFrame(sCoinsWindowId, TRUE); RemoveWindow(sCoinsWindowId); } diff --git a/src/contest.c b/src/contest.c index 7be4aa23b..114a1fb69 100644 --- a/src/contest.c +++ b/src/contest.c @@ -45,8 +45,6 @@ #include "constants/rgb.h" #include "contest_ai.h" -extern void sub_80FC9F8(u8); // contest_link_80FC4F4.c - // This file's functions. static void sub_80D782C(void); static void sub_80D7C7C(u8 taskId); @@ -819,7 +817,7 @@ static void sub_80D8490(u8 taskId) } r5 = StringCopy(r5, gMoveNames[move]); - FillWindowPixelBuffer(i + 5, 0); + FillWindowPixelBuffer(i + 5, PIXEL_FILL(0)); Contest_PrintTextToBg0WindowAt(i + 5, sp8, 5, 1, 7); } @@ -941,7 +939,7 @@ static void sub_80D895C(u8 taskId) for (i = 0; i < 4; i++) { - FillWindowPixelBuffer(5 + i, 0); + FillWindowPixelBuffer(5 + i, PIXEL_FILL(0)); PutWindowTilemap(5 + i); CopyWindowToVram(5 + i, 2); } @@ -2258,7 +2256,7 @@ static void sub_80DAEA4(void) for (i = 0; i < 4; i++) { - FillWindowPixelBuffer(gUnknown_02039F26[i], 0); + FillWindowPixelBuffer(gUnknown_02039F26[i], PIXEL_FILL(0)); sub_80DAF04(i); sub_80DAF88(i); } @@ -2478,7 +2476,7 @@ static void prints_contest_move_description(u16 a) ContestBG_FillBoxWithTile(0, 0x5036, 0x15, 0x20, 0x08, 0x01, 0x11); ContestBG_FillBoxWithTile(0, 0x5014, 0x15, 0x20, numHearts, 0x01, 0x11); - FillWindowPixelBuffer(10, 0); + FillWindowPixelBuffer(10, PIXEL_FILL(0)); Contest_PrintTextToBg0WindowStd(10, gContestEffectDescriptionPointers[gContestMoves[a].effect]); Contest_PrintTextToBg0WindowStd(9, gText_Slash); } @@ -2621,7 +2619,7 @@ static void sub_80DB884(void) static void sub_80DB89C(void) { - FillWindowPixelBuffer(4, 0); + FillWindowPixelBuffer(4, PIXEL_FILL(0)); CopyWindowToVram(4, 2); Contest_SetBgCopyFlags(0); } @@ -3456,7 +3454,7 @@ static void sub_80DCD48(void) break; default: for (i = 0; i < 4; i++) - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); for (i = 0; i < 4; i++) { value = sContestantStatus[i].unk4; @@ -5038,7 +5036,7 @@ static void sub_80DF750(void) return; for (i = 0; i < 4; i++) - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); if (gHeap[0x1A000] == 2) { diff --git a/src/contest_link_80F57C4.c b/src/contest_link_80F57C4.c index c0a79af81..a4b88c074 100644 --- a/src/contest_link_80F57C4.c +++ b/src/contest_link_80F57C4.c @@ -39,6 +39,7 @@ #include "constants/rgb.h" #include "constants/songs.h" #include "constants/vars.h" +#include "contest.h" struct ContestLinkUnk0 { @@ -99,8 +100,6 @@ extern const struct SpriteSheet gUnknown_0858D810[]; extern const struct SpritePalette gUnknown_0858D850; extern const struct SpriteTemplate gSpriteTemplate_858D860; -extern void sub_81D9DE4(u8); - static void sub_80F6A9C(void); static void sub_80F71C8(void); u8 sub_80F7310(u8, u8); @@ -935,7 +934,7 @@ static void sub_80F6AE8(void) // windowTemplate.width = 30; // windowTemplate.height = 2; // windowId = AddWindow(&windowTemplate); -// FillWindowPixelBuffer(windowId, 0x11); +// FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); // origWidth = GetStringWidth(1, text, 0) + 9; // strWidth = origWidth; // if (strWidth < 0) diff --git a/src/contest_painting.c b/src/contest_painting.c index 2f0c97764..931deb01b 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -279,7 +279,7 @@ static void InitContestPaintingWindow(void) SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); gContestPaintingWindowId = AddWindow(&gUnknown_085B07EC); DeactivateAllTextPrinters(); - FillWindowPixelBuffer(gContestPaintingWindowId, 0); + FillWindowPixelBuffer(gContestPaintingWindowId, PIXEL_FILL(0)); PutWindowTilemap(gContestPaintingWindowId); CopyWindowToVram(gContestPaintingWindowId, 3); ShowBg(1); diff --git a/src/credits.c b/src/credits.c index aee5332f5..4483e3160 100644 --- a/src/credits.c +++ b/src/credits.c @@ -1592,7 +1592,7 @@ static void sub_8175DA0(u8 taskIdB) case 5: if (!gPaletteFade.active) { - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); CopyWindowToVram(0, 2); gTasks[taskIdB].data[TDB_0] = 2; } diff --git a/src/daycare.c b/src/daycare.c index b75fab292..885ac31a1 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1259,7 +1259,7 @@ static void Task_HandleDaycareLevelMenuInput(u8 taskId) break; } DestroyListMenuTask(gTasks[taskId].tMenuListTaskId, NULL, NULL); - sub_819746C(gTasks[taskId].tWindowId, TRUE); + ClearStdWindowAndFrame(gTasks[taskId].tWindowId, TRUE); RemoveWindow(gTasks[taskId].tWindowId); DestroyTask(taskId); EnableBothScriptContexts(); @@ -1268,7 +1268,7 @@ static void Task_HandleDaycareLevelMenuInput(u8 taskId) { gSpecialVar_Result = 2; DestroyListMenuTask(gTasks[taskId].tMenuListTaskId, NULL, NULL); - sub_819746C(gTasks[taskId].tWindowId, TRUE); + ClearStdWindowAndFrame(gTasks[taskId].tWindowId, TRUE); RemoveWindow(gTasks[taskId].tWindowId); DestroyTask(taskId); EnableBothScriptContexts(); @@ -1283,7 +1283,7 @@ void ShowDaycareLevelMenu(void) u8 daycareMenuTaskId; windowId = AddWindow(&sDaycareLevelMenuWindowTemplate); - NewMenuHelpers_DrawStdWindowFrame(windowId, FALSE); + DrawStdWindowFrame(windowId, FALSE); menuTemplate = sDaycareListMenuLevelTemplate; menuTemplate.windowId = windowId; diff --git a/src/decoration.c b/src/decoration.c index 2ac49b98c..0712b5d32 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -463,14 +463,14 @@ u8 sub_81269D4(u8 idx) { *winidx = AddWindow(&gUnknown_085A6B90[idx]); } - SetWindowBorderStyle(*winidx, 0, 0x214, 0xe); + DrawStdFrameWithCustomTileAndPalette(*winidx, 0, 0x214, 0xe); schedule_bg_copy_tilemap_to_vram(0); return *winidx; } void sub_8126A58(u8 idx) { - sub_8198070(sDecorMenuWindowIndices[idx], FALSE); + ClearStdWindowAndFrameToTransparent(sDecorMenuWindowIndices[idx], FALSE); ClearWindowTilemap(sDecorMenuWindowIndices[idx]); RemoveWindow(sDecorMenuWindowIndices[idx]); schedule_bg_copy_tilemap_to_vram(0); @@ -543,7 +543,7 @@ void sub_8126B80(u8 taskId) void sub_8126C08(void) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, sSecretBasePCMenuItemDescriptions[sSecretBasePCMenuCursorPos], 0, 0, 2, 1, 3); } @@ -572,7 +572,7 @@ void SecretBasePC_PutAway(u8 taskId) else { sub_8126A58(0); - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8129ABC; @@ -617,7 +617,7 @@ void sub_8126DA4(u8 taskId) void SecretBasePC_PrepMenuForSelectingStoredDecors(u8 taskId) { LoadPalette(gUnknown_085A6BB0, 0xd0, 0x20); - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); sub_8126A58(0); sub_8126DFC(taskId); } @@ -634,7 +634,7 @@ void sub_8126DFC(u8 taskId) void sub_8126E44(u8 taskId) { - FillWindowPixelBuffer(sDecorMenuWindowIndices[1], 0x11); + FillWindowPixelBuffer(sDecorMenuWindowIndices[1], PIXEL_FILL(1)); sub_8126E8C(taskId); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sDecorMenuWindowIndices[1], 9, sCurDecorationCategory); gTasks[taskId].func = sub_8127088; @@ -751,7 +751,7 @@ void sub_81270E8(u8 taskId) void sub_8127180(u8 taskId) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); sub_8126DFC(taskId); } @@ -771,7 +771,7 @@ void sub_81271CC(u8 taskId) { sub_8126A58(1); sub_8126A88(); - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); sub_8126C08(); gTasks[taskId].func = sub_8126B80; } @@ -779,7 +779,7 @@ void sub_81271CC(u8 taskId) void sub_8127208(u8 taskId) { LoadPalette(gUnknown_085A6BB0, 0xd0, 0x20); - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); gTasks[taskId].data[11] = 2; sCurDecorationCategory = DECORCAT_DESK; sub_8126DFC(taskId); @@ -968,7 +968,7 @@ void sub_8127744(u32 a0) const u8 *txt; winidx = sDecorMenuWindowIndices[3]; - FillWindowPixelBuffer(winidx, 0x11); + FillWindowPixelBuffer(winidx, PIXEL_FILL(1)); if (a0 >= sCurDecorCatCount) { txt = gText_GoBackPrevMenu; @@ -1095,7 +1095,7 @@ void sub_8127A14(u8 taskId) void sub_8127A30(u8 taskId) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); gTasks[taskId].func = sub_8127A14; } @@ -1103,7 +1103,7 @@ void sub_8127A5C(u8 taskId) { if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); sub_81269D4(1); sub_8127620(taskId); } @@ -1158,7 +1158,7 @@ void sub_8127B90(u16 mapX, u16 mapY, u8 decWidth, u8 decHeight, u16 decor) u16 i; u16 j; u16 behavior; - u16 flags; + u16 impassableFlag; u16 v0; u16 v1; s16 decLeft; @@ -1173,11 +1173,11 @@ void sub_8127B90(u16 mapX, u16 mapY, u8 decWidth, u8 decHeight, u16 decor) behavior = GetBehaviorByMetatileId(0x200 + gDecorations[decor].tiles[i * decWidth + j]); if (MetatileBehavior_IsSecretBaseImpassable(behavior) == TRUE || (gDecorations[decor].permission != DECORPERM_PASS_FLOOR && (behavior >> 12))) { - flags = 0xc00; + impassableFlag = METATILE_COLLISION_MASK; } else { - flags = 0x000; + impassableFlag = 0x000; } if (gDecorations[decor].permission != DECORPERM_NA_WALL && MetatileBehavior_IsSecretBaseNorthWall(MapGridGetMetatileBehaviorAt(decLeft, decBottom)) == TRUE) { @@ -1190,11 +1190,11 @@ void sub_8127B90(u16 mapX, u16 mapY, u8 decWidth, u8 decHeight, u16 decor) v1 = sub_8127B54(gDecorations[decor].id, i * decWidth + j); if (v1 != 0xFFFF) { - MapGridSetMetatileEntryAt(decLeft, decBottom, (gDecorations[decor].tiles[i * decWidth + j] + (0x200 | v0)) | flags | v1); + MapGridSetMetatileEntryAt(decLeft, decBottom, (gDecorations[decor].tiles[i * decWidth + j] + (0x200 | v0)) | impassableFlag | v1); } else { - MapGridSetMetatileIdAt(decLeft, decBottom, (gDecorations[decor].tiles[i * decWidth + j] + (0x200 | v0)) | flags); + MapGridSetMetatileIdAt(decLeft, decBottom, (gDecorations[decor].tiles[i * decWidth + j] + (0x200 | v0)) | impassableFlag); } } } @@ -1254,7 +1254,7 @@ void sub_8127E18(void) break; } } - VarSet(VAR_0x3F20 + gMapHeader.events->eventObjects[j].graphicsId, sPlaceDecorationGraphicsDataBuffer.decoration->tiles[0]); + VarSet(UNKNOWN_VAR_OFFSET_3F20 + gMapHeader.events->eventObjects[j].graphicsId, sPlaceDecorationGraphicsDataBuffer.decoration->tiles[0]); gSpecialVar_0x8005 = gMapHeader.events->eventObjects[j].localId; gSpecialVar_0x8006 = sCurDecorMapX; gSpecialVar_0x8007 = sCurDecorMapY; @@ -1502,7 +1502,7 @@ bool8 sub_812853C(u8 taskId, const struct Decoration *decoration) { curX = gTasks[taskId].data[0] + j; behaviorAt = MapGridGetMetatileBehaviorAt(curX, curY); - behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[(mapY - 1 - i) * mapX + j]) & 0xf000; + behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[(mapY - 1 - i) * mapX + j]) & METATILE_ELEVATION_MASK; if (!sub_81284F4(behaviorAt, decoration)) { return FALSE; @@ -1527,7 +1527,7 @@ bool8 sub_812853C(u8 taskId, const struct Decoration *decoration) { curX = gTasks[taskId].data[0] + j; behaviorAt = MapGridGetMetatileBehaviorAt(curX, curY); - behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[(mapY - 1 - i) * mapX + j]) & 0xf000; + behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[(mapY - 1 - i) * mapX + j]) & METATILE_ELEVATION_MASK; if (!MetatileBehavior_IsNormal(behaviorAt) && !sub_8128484(behaviorAt, behaviorBy)) { return FALSE; @@ -1547,7 +1547,7 @@ bool8 sub_812853C(u8 taskId, const struct Decoration *decoration) { curX = gTasks[taskId].data[0] + j; behaviorAt = MapGridGetMetatileBehaviorAt(curX, curY); - behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[j]) & 0xf000; + behaviorBy = GetBehaviorByMetatileId(0x200 + decoration->tiles[j]) & METATILE_ELEVATION_MASK; if (!MetatileBehavior_IsNormal(behaviorAt) && !MetatileBehavior_IsSecretBaseNorthWall(behaviorAt)) { return FALSE; @@ -1628,13 +1628,13 @@ void sub_8128950(u8 taskId) void sub_81289D0(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(taskId, &gUnknown_085A72C4); } void sub_81289F0(u8 taskId) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); sub_8128AAC(taskId); if (gDecorations[gCurDecorInventoryItems[gCurDecorationIndex]].permission != DECORPERM_SOLID_MAT) { @@ -1693,13 +1693,13 @@ void sub_8128AAC(u8 taskId) void sub_8128B80(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(taskId, &gUnknown_085A72CC); } void sub_8128BA0(u8 taskId) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); sub_8128BBC(taskId); } @@ -1887,7 +1887,7 @@ void sub_8128E18(u8 taskId) void sub_8128FD8(u8 taskId) { - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); gSprites[sDecor_CameraSpriteObjectIdx1].data[7] = 0; gTasks[taskId].data[10] = 0; gTasks[taskId].func = sub_8128E18; @@ -2251,7 +2251,7 @@ void sub_81298EC(u8 taskId) if (!gPaletteFade.active) { DrawWholeMapView(); ScriptContext1_SetupScript(EventScript_275D2E); - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); gTasks[taskId].data[2] = 2; } break; @@ -2343,7 +2343,7 @@ void sub_8129ABC(u8 taskId) void sub_8129B34(u8 taskId) { - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); gSprites[sDecor_CameraSpriteObjectIdx1].data[7] = 0; gSprites[sDecor_CameraSpriteObjectIdx1].invisible = FALSE; gSprites[sDecor_CameraSpriteObjectIdx1].callback = sub_812A36C; @@ -2588,7 +2588,7 @@ void sub_812A0E8(u8 taskId) void sub_812A1A0(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(taskId, &gUnknown_085A7348); } @@ -2601,13 +2601,13 @@ void sub_812A1C0(u8 taskId) void sub_812A1F0(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(taskId, &gUnknown_085A7350); } void sub_812A210(u8 taskId) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); sub_812A22C(taskId); } @@ -2671,7 +2671,7 @@ void sub_812A334(void) u8 taskId; pal_fill_black(); - NewMenuHelpers_DrawDialogueFrame(0, 1); + DrawDialogueFrame(0, 1); sub_8126ABC(); taskId = CreateTask(sub_812A2C4, 8); gTasks[taskId].data[2] = 0; @@ -2725,7 +2725,7 @@ void sub_812A3D4(u8 taskId) void sub_812A458(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(taskId, &gUnknown_085A741C); } diff --git a/src/dewford_trend.c b/src/dewford_trend.c index cad5ef9c2..ee310af04 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -159,7 +159,7 @@ static void sub_8122804(struct EasyChatPair *s, u16 b, u8 c) } } -void ReceiveEasyChatPairsData(void *a, u32 b, u8 unused) +void ReceiveEasyChatPairsData(struct EasyChatPair *a, size_t size, u8 unused) { u16 i, j, r3, players; struct EasyChatPair *buffer1, *buffer2, *src, *dst, *foo_of_buffer2; @@ -176,7 +176,7 @@ void ReceiveEasyChatPairsData(void *a, u32 b, u8 unused) { players = GetLinkPlayerCount(); for (i = 0; i < players; i++) - memcpy(&(buffer1[i * 5]), (u8 *)a + i * b, 40); + memcpy(&(buffer1[i * 5]), (u8 *)a + i * size, 40); src = buffer1; dst = buffer2; r3 = 0; diff --git a/src/diploma.c b/src/diploma.c index b3d5a48fa..2113b09ed 100644 --- a/src/diploma.c +++ b/src/diploma.c @@ -13,8 +13,7 @@ #include "text.h" #include "overworld.h" #include "menu.h" - -extern bool16 sub_80C0944(void); +#include "pokedex.h" extern const u8 gText_DexNational[]; extern const u8 gText_DexHoenn[]; @@ -197,7 +196,7 @@ static void InitDiplomaWindow(void) InitWindows(sDiplomaWinTemplates); DeactivateAllTextPrinters(); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); } diff --git a/src/easy_chat.c b/src/easy_chat.c index aa681eeba..b03058eb9 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1114,7 +1114,7 @@ static void sub_811A2A4(u8 taskId, TaskFunc taskFunc) static void sub_811A2C0(u8 taskId) { - if (!is_c1_link_related_active()) + if (!IsUpdateLinkStateCBActive()) { while (sub_811A428(taskId)); } @@ -3697,7 +3697,7 @@ static void sub_811CFCC(void) return; xOffset = GetStringCenterAlignXOffset(1, titleText, 144); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); sub_811D058(0, 1, titleText, xOffset, 1, 0xFF, 0, 2, 3); PutWindowTilemap(0); CopyWindowToVram(0, 3); @@ -3767,7 +3767,7 @@ static void sub_811D104(u8 arg0) break; } - FillWindowPixelBuffer(1, 0x11); + FillWindowPixelBuffer(1, PIXEL_FILL(1)); if (text1) sub_811D028(1, 1, text1, 0, 1, 0xFF, 0); @@ -3817,7 +3817,7 @@ static void sub_811D2C8(void) if (frameId == 7) var1 = 1; - FillWindowPixelBuffer(sUnknown_0203A11C->windowId, 0x11); + FillWindowPixelBuffer(sUnknown_0203A11C->windowId, PIXEL_FILL(1)); for (i = 0; i < numRows; i++) { memcpy(spC, sText_Clear17, sizeof(sText_Clear17)); @@ -3957,7 +3957,7 @@ static void sub_811D684(void) static void sub_811D698(u32 arg0) { sub_811DD84(); - FillWindowPixelBuffer(2, 0x11); + FillWindowPixelBuffer(2, PIXEL_FILL(1)); switch (arg0) { case 0: @@ -4114,14 +4114,14 @@ static void sub_811D950(u8 arg0, u8 arg1) var1 = 0; } - FillWindowPixelRect(2, 0x11, 0, y, 224, var2); + FillWindowPixelRect(2, PIXEL_FILL(1), 0, y, 224, var2); if (var1) - FillWindowPixelRect(2, 0x11, 0, 0, 224, var1); + FillWindowPixelRect(2, PIXEL_FILL(1), 0, 0, 224, var1); } static void sub_811D9B4(void) { - FillWindowPixelBuffer(2, 0x11); + FillWindowPixelBuffer(2, PIXEL_FILL(1)); CopyWindowToVram(2, 2); } @@ -4791,7 +4791,7 @@ static void sub_811E948(void) template.paletteNum = 11; template.baseBlock = 0x34; windowId = AddWindow(&template); - FillWindowPixelBuffer(windowId, 0x11); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); for (i = 0; i < 4; i++) { const u8 *str = sFooterTextOptions[footerId][i]; diff --git a/src/egg_hatch.c b/src/egg_hatch.c index ba1020669..a9b6001ec 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -606,7 +606,7 @@ static void CB2_EggHatch_1(void) case 1: if (!gPaletteFade.active) { - FillWindowPixelBuffer(sEggHatchData->windowId, 0); + FillWindowPixelBuffer(sEggHatchData->windowId, PIXEL_FILL(0)); sEggHatchData->CB2_PalCounter = 0; sEggHatchData->CB2_state++; } @@ -857,7 +857,7 @@ static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 static void EggHatchPrintMessage(u8 windowId, u8* string, u8 x, u8 y, u8 speed) { - FillWindowPixelBuffer(windowId, 0xFF); + FillWindowPixelBuffer(windowId, PIXEL_FILL(15)); sEggHatchData->textColor[0] = 0; sEggHatchData->textColor[1] = 5; sEggHatchData->textColor[2] = 6; diff --git a/src/electric.c b/src/electric.c index 142a9ca09..5e7729842 100644 --- a/src/electric.c +++ b/src/electric.c @@ -5,9 +5,6 @@ #include "constants/songs.h" #include "sound.h" -extern void sub_810E2C8(struct Sprite *); -extern void TranslateAnimSpriteToTargetMonLocation(struct Sprite *); - static void sub_810A1A8(struct Sprite *); static void sub_810A1F8(struct Sprite *); static void sub_810A214(struct Sprite *); diff --git a/src/event_data.c b/src/event_data.c index e75c37773..50628f984 100644 --- a/src/event_data.c +++ b/src/event_data.c @@ -23,8 +23,8 @@ EWRAM_DATA u16 gSpecialVar_LastTalked = 0; EWRAM_DATA u16 gSpecialVar_Facing = 0; EWRAM_DATA u16 gSpecialVar_MonBoxId = 0; EWRAM_DATA u16 gSpecialVar_MonBoxPos = 0; -EWRAM_DATA u16 gSpecialVar_0x8014 = 0; -EWRAM_DATA static u8 gUnknown_020375FC[16] = {0}; +EWRAM_DATA u16 gSpecialVar_Unused_0x8014 = 0; +EWRAM_DATA static u8 gSpecialFlags[16] = {0}; extern u16 *const gSpecialVars[]; @@ -32,7 +32,7 @@ void InitEventData(void) { memset(gSaveBlock1Ptr->flags, 0, sizeof(gSaveBlock1Ptr->flags)); memset(gSaveBlock1Ptr->vars, 0, sizeof(gSaveBlock1Ptr->vars)); - memset(gUnknown_020375FC, 0, sizeof(gUnknown_020375FC)); + memset(gSpecialFlags, 0, sizeof(gSpecialFlags)); } void ClearTempFieldEventData(void) @@ -131,13 +131,13 @@ void sub_809D4D8(void) void sub_809D570(void) { VarSet(VAR_EVENT_PICHU_SLOT, 0); - VarSet(VAR_0x40DE, 0); - VarSet(VAR_0x40DF, 0); - VarSet(VAR_0x40E0, 0); - VarSet(VAR_0x40E1, 0); - VarSet(VAR_0x40E2, 0); - VarSet(VAR_0x40E3, 0); - VarSet(VAR_0x40E4, 0); + VarSet(VAR_NEVER_READ_0x40DE, 0); + VarSet(VAR_NEVER_READ_0x40DF, 0); + VarSet(VAR_NEVER_READ_0x40E0, 0); + VarSet(VAR_NEVER_READ_0x40E1, 0); + VarSet(VAR_NEVER_READ_0x40E2, 0); + VarSet(VAR_NEVER_READ_0x40E3, 0); + VarSet(VAR_NEVER_READ_0x40E4, 0); } void DisableResetRTC(void) @@ -199,7 +199,7 @@ u8 *GetFlagPointer(u16 id) else if (id < SPECIAL_FLAGS_START) return &gSaveBlock1Ptr->flags[id / 8]; else - return &gUnknown_020375FC[(id - SPECIAL_FLAGS_START) / 8]; + return &gSpecialFlags[(id - SPECIAL_FLAGS_START) / 8]; } u8 FlagSet(u16 id) diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index cffafaf9f..680191bb3 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -32,8 +32,7 @@ #include "constants/map_types.h" #include "constants/maps.h" #include "constants/songs.h" - -extern bool32 TryStartMatchCall(void); +#include "match_call.h" static EWRAM_DATA u8 sWildEncounterImmunitySteps = 0; static EWRAM_DATA u16 sPreviousPlayerMetatileBehavior = 0; @@ -557,9 +556,9 @@ static bool8 TryStartStepCountScript(u16 metatileBehavior) ScriptContext1_SetupScript(EventScript_EggHatch); return TRUE; } - if (sub_813B3B0() == TRUE) + if (UnusualWeatherHasExpired() == TRUE) { - ScriptContext1_SetupScript(gUnknown_08273D1F); + ScriptContext1_SetupScript(UnusualWeather_EventScript_EndEventAndCleanup_1); return TRUE; } if (ShouldDoBrailleRegicePuzzle() == TRUE) @@ -567,27 +566,27 @@ static bool8 TryStartStepCountScript(u16 metatileBehavior) ScriptContext1_SetupScript(IslandCave_EventScript_238EAF); return TRUE; } - if (is_tile_that_overrides_player_control() == TRUE) + if (ShouldDoWallyCall() == TRUE) { ScriptContext1_SetupScript(MauvilleCity_EventScript_1DF7BA); return TRUE; } - if (sub_8138120() == TRUE) + if (ShouldDoWinonaCall() == TRUE) { ScriptContext1_SetupScript(Route119_EventScript_1F49EC); return TRUE; } - if (sub_8138168() == TRUE) + if (ShouldDoScottCall() == TRUE) { ScriptContext1_SetupScript(LittlerootTown_ProfessorBirchsLab_EventScript_1FA4D6); return TRUE; } - if (sub_81381B0() == TRUE) + if (ShouldDoRoxanneCall() == TRUE) { ScriptContext1_SetupScript(RustboroCity_Gym_EventScript_21307B); return TRUE; } - if (sub_81381F8() == TRUE) + if (ShouldDoRivalRayquazaCall() == TRUE) { ScriptContext1_SetupScript(MossdeepCity_SpaceCenter_2F_EventScript_224175); return TRUE; diff --git a/src/field_effect.c b/src/field_effect.c index e7c0b39b9..ee9dcb987 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -240,12 +240,6 @@ static IWRAM_DATA u8 sActiveList[32]; extern u8 *gFieldEffectScriptPointers[]; extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; -extern void sub_81555D8(u8, u8); -extern void pal_fill_for_maplights(void); -extern void sub_80E1558(u8); -extern void sub_80E1570(void); -extern bool8 sub_80E1584(void); -extern void WarpFadeScreen(void); // .rodata const u32 gNewGameBirchPic[] = INCBIN_U32("graphics/birch_speech/birch.4bpp"); @@ -2443,7 +2437,7 @@ static void sub_80B8410(struct Task *task) bool8 FldEff_FieldMoveShowMon(void) { u8 taskId; - if (is_map_type_1_2_3_5_or_6(GetCurrentMapType()) == TRUE) + if (IsMapTypeOutdoors(GetCurrentMapType()) == TRUE) { taskId = CreateTask(sub_80B8554, 0xff); } else @@ -2620,7 +2614,7 @@ static void sub_80B8874(u16 offs) dest = (u16 *)(VRAM + 0x140 + offs); for (i = 0; i < 0x140; i++, dest++) { - *dest = gFieldMoveStreaksTilemap[i] | 0xf000; + *dest = gFieldMoveStreaksTilemap[i] | METATILE_ELEVATION_MASK; } } diff --git a/src/field_message_box.c b/src/field_message_box.c index 299aafaf2..1c554b6c6 100755 --- a/src/field_message_box.c +++ b/src/field_message_box.c @@ -4,9 +4,7 @@ #include "string_util.h" #include "task.h" #include "text.h" - -extern bool32 IsMatchCallTaskActive(void); -extern void StartMatchCallFromScript(u8*); +#include "match_call.h" static EWRAM_DATA u8 sFieldMessageBoxMode = 0; @@ -33,7 +31,7 @@ static void sub_8098154(u8 taskId) task->data[0]++; break; case 1: - NewMenuHelpers_DrawDialogueFrame(0, 1); + DrawDialogueFrame(0, 1); task->data[0]++; break; case 2: @@ -127,7 +125,7 @@ static void textbox_auto_and_task_add(void) void HideFieldMessageBox(void) { task_del_textbox(); - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); sFieldMessageBoxMode = 0; } @@ -146,7 +144,7 @@ bool8 IsFieldMessageBoxHidden(void) void sub_8098358(void) { task_del_textbox(); - NewMenuHelpers_DrawStdWindowFrame(0, 1); + DrawStdWindowFrame(0, 1); sFieldMessageBoxMode = 0; } diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index b1291f0ce..a070fe0e1 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -1918,7 +1918,7 @@ static bool8 Fishing9(struct Task *task) static bool8 Fishing10(struct Task *task) { AlignFishingAnimationFrames(); - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_PokemonOnHook, 1, 0, 2, 1, 3); task->tStep++; task->tFrameCounter = 0; @@ -1944,7 +1944,7 @@ static bool8 Fishing11(struct Task *task) sub_8155604(gEventObjects[gPlayerAvatar.eventObjectId].fieldEffectSpriteId, 0, 0); gSprites[gPlayerAvatar.spriteId].pos2.x = 0; gSprites[gPlayerAvatar.spriteId].pos2.y = 0; - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); task->tFrameCounter++; return FALSE; } @@ -1966,7 +1966,7 @@ static bool8 Fishing12(struct Task *task) { AlignFishingAnimationFrames(); StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection())); - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_NotEvenANibble, 1, 0, 2, 1, 3); task->tStep = FISHING_SHOW_RESULT; return TRUE; @@ -1977,7 +1977,7 @@ static bool8 Fishing13(struct Task *task) { AlignFishingAnimationFrames(); StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFishingNoCatchDirectionAnimNum(GetPlayerFacingDirection())); - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_ItGotAway, 1, 0, 2, 1, 3); task->tStep++; return TRUE; @@ -2017,7 +2017,7 @@ static bool8 Fishing16(struct Task *task) gPlayerAvatar.preventStep = FALSE; ScriptContext2_Disable(); UnfreezeEventObjects(); - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); sub_80ED950(0); DestroyTask(FindTaskIdByFunc(Task_Fishing)); } @@ -2125,7 +2125,7 @@ void sub_808D194(void) sub_808D1FC(CreateTask(sub_808D1FC, 0)); } -bool8 sub_808D1B4(void) +bool32 sub_808D1B4(void) { return FuncIsActiveTask(sub_808D1FC); } @@ -2135,7 +2135,7 @@ void sub_808D1C8(void) sub_808D094(CreateTask(sub_808D094, 0)); } -bool8 sub_808D1E8(void) +bool32 sub_808D1E8(void) { return FuncIsActiveTask(sub_808D094); } diff --git a/src/field_region_map.c b/src/field_region_map.c index d49ce3a4e..1d54333fb 100644 --- a/src/field_region_map.c +++ b/src/field_region_map.c @@ -139,11 +139,11 @@ static void FieldUpdateRegionMap(void) sFieldRegionMapHandler->state++; break; case 1: - SetWindowBorderStyle(1, 0, 0x27, 0xd); + DrawStdFrameWithCustomTileAndPalette(1, 0, 0x27, 0xd); offset = GetStringCenterAlignXOffset(1, gText_Hoenn, 0x38); AddTextPrinterParameterized(1, 1, gText_Hoenn, offset, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); - SetWindowBorderStyle(0, 0, 0x27, 0xd); + DrawStdFrameWithCustomTileAndPalette(0, 0, 0x27, 0xd); PrintRegionMapSecName(); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); sFieldRegionMapHandler->state++; @@ -196,13 +196,13 @@ static void PrintRegionMapSecName(void) { if (sFieldRegionMapHandler->regionMap.iconDrawType != MAPSECTYPE_NONE) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized(0, 1, sFieldRegionMapHandler->regionMap.mapSecName, 0, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); } else { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); CopyWindowToVram(0, 3); } } diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 0a4f3212b..b6dcf212c 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -10,7 +10,6 @@ #include "field_screen_effect.h" #include "field_special_scene.h" #include "field_weather.h" -// #include "fldeff_flash.h" #include "gpu_regs.h" #include "link.h" #include "link_rfu.h" @@ -31,22 +30,9 @@ #include "constants/event_object_movement_constants.h" #include "constants/songs.h" #include "constants/rgb.h" - -extern bool32 sub_81D6534(void); -extern bool8 walkrun_is_standing_still(void); -extern void ScriptUnfreezeEventObjects(void); -extern void sub_80FB768(void); -extern void sub_808D194(void); -extern void sub_808D1C8(void); -extern bool32 sub_808D1B4(void); -extern bool32 sub_808D1E8(void); -extern void sub_80B6B68(void); -extern void sub_80B6E4C(u8, u8); -extern void sub_80B75D8(u8); -extern void sub_80B7A74(u8); -extern void sub_808C0A8(u8); -extern u8 GetMapPairFadeToType(u8, u8); -extern u8 GetMapPairFadeFromType(u8, u8); +#include "trainer_hill.h" +#include "event_obj_lock.h" +#include "fldeff.h" extern const u16 gUnknown_82EC7CC[]; @@ -255,7 +241,7 @@ void sub_80AF2B4(u8 taskId) break; case 2: sub_8009F18(); - sub_8086C2C(); + ResetAllMultiplayerState(); ScriptContext2_Disable(); DestroyTask(taskId); break; @@ -621,7 +607,7 @@ void sub_80AF948(void) CreateTask(sub_80AF8E0, 10); } -static void sub_80AF96C(u8 taskId) +static void Task_ReturnToWorldFromLinkRoom(u8 taskId) { s16 *data = gTasks[taskId].data; @@ -654,7 +640,7 @@ static void sub_80AF96C(u8 taskId) void sub_80AF9F8(void) { - CreateTask(sub_80AF96C, 10); + CreateTask(Task_ReturnToWorldFromLinkRoom, 10); } static void sub_80AFA0C(u8 taskId) diff --git a/src/field_specials.c b/src/field_specials.c index 307f81399..436b06f53 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -55,6 +55,7 @@ #include "constants/vars.h" #include "constants/battle_frontier.h" #include "constants/weather.h" +#include "palette.h" EWRAM_DATA bool8 gBikeCyclingChallenge = FALSE; EWRAM_DATA u8 gBikeCollisions = 0; @@ -80,9 +81,6 @@ extern const u16 gEventObjectPalette17[]; extern const u16 gEventObjectPalette33[]; extern const u16 gEventObjectPalette34[]; -extern void LoadPalette(const void *src, u32 offset, u16 size); // incorrect signature, needed to match -extern void BlendPalettes(u32, u8, u16); -extern void FieldInitRegionMap(MainCallback callback); void UpdateMovedLilycoveFanClubMembers(void); void sub_813BF60(void); @@ -360,17 +358,17 @@ u8 GetSSTidalLocation(s8 *mapGroup, s8 *mapNum, s16 *x, s16 *y) return 0; } -bool32 is_tile_that_overrides_player_control(void) +bool32 ShouldDoWallyCall(void) { if (FlagGet(FLAG_ENABLE_FIRST_WALLY_POKENAV_CALL)) { switch (gMapHeader.mapType) { - case 1: - case 2: - case 3: - case 6: - if (++(*GetVarPointer(VAR_0x40F2)) < 0xFA) + case MAP_TYPE_TOWN: + case MAP_TYPE_CITY: + case MAP_TYPE_ROUTE: + case MAP_TYPE_OCEAN_ROUTE: + if (++(*GetVarPointer(VAR_WALLY_CALL_STEP_COUNTER)) < 250) { return FALSE; } @@ -387,7 +385,7 @@ bool32 is_tile_that_overrides_player_control(void) return TRUE; } -bool32 sub_8138120(void) +bool32 ShouldDoWinonaCall(void) { if (FlagGet(FLAG_REGISTER_WINONA_POKENAV)) { @@ -396,8 +394,8 @@ bool32 sub_8138120(void) case MAP_TYPE_TOWN: case MAP_TYPE_CITY: case MAP_TYPE_ROUTE: - case MAP_TYPE_6: - if (++(*GetVarPointer(VAR_0x40F3)) < 10) + case MAP_TYPE_OCEAN_ROUTE: + if (++(*GetVarPointer(VAR_WINONA_CALL_STEP_COUNTER)) < 10) { return FALSE; } @@ -414,7 +412,7 @@ bool32 sub_8138120(void) return TRUE; } -bool32 sub_8138168(void) +bool32 ShouldDoScottCall(void) { if (FlagGet(FLAG_SCOTT_CALL_NATIONAL_DEX)) { @@ -424,7 +422,7 @@ bool32 sub_8138168(void) case 2: case 3: case 6: - if (++(*GetVarPointer(VAR_0x40F5)) < 0xA) + if (++(*GetVarPointer(VAR_SCOTT_CALL_STEP_COUNTER)) < 10) { return FALSE; } @@ -441,7 +439,7 @@ bool32 sub_8138168(void) return TRUE; } -bool32 sub_81381B0(void) +bool32 ShouldDoRoxanneCall(void) { if (FlagGet(FLAG_ENABLE_ROXANNE_FIRST_CALL)) { @@ -451,7 +449,7 @@ bool32 sub_81381B0(void) case 2: case 3: case 6: - if (++(*GetVarPointer(VAR_0x40F4)) < 0xFA) + if (++(*GetVarPointer(VAR_ROXANNE_CALL_STEP_COUNTER)) < 250) { return FALSE; } @@ -468,7 +466,7 @@ bool32 sub_81381B0(void) return TRUE; } -bool32 sub_81381F8(void) +bool32 ShouldDoRivalRayquazaCall(void) { if (FlagGet(FLAG_DEFEATED_MAGMA_SPACE_CENTER)) { @@ -478,7 +476,7 @@ bool32 sub_81381F8(void) case 2: case 3: case 6: - if (++(*GetVarPointer(VAR_0x40F6)) < 0xFA) + if (++(*GetVarPointer(VAR_RIVAL_RAYQUAZA_CALL_STEP_COUNTER)) < 250) { return FALSE; } @@ -591,7 +589,9 @@ void SpawnLinkPartnerEventObject(void) static void LoadLinkPartnerEventObjectSpritePalette(u8 graphicsId, u8 localEventId, u8 paletteNum) { - paletteNum += 6; + u8 adjustedPaletteNum; + // Note: This temp var is necessary; paletteNum += 6 doesn't match. + adjustedPaletteNum = paletteNum + 6; if (graphicsId == EVENT_OBJ_GFX_LINK_RS_BRENDAN || graphicsId == EVENT_OBJ_GFX_LINK_RS_MAY || graphicsId == EVENT_OBJ_GFX_RIVAL_BRENDAN_NORMAL || @@ -602,21 +602,21 @@ static void LoadLinkPartnerEventObjectSpritePalette(u8 graphicsId, u8 localEvent { u8 spriteId = gEventObjects[obj].spriteId; struct Sprite *sprite = &gSprites[spriteId]; - sprite->oam.paletteNum = paletteNum; + sprite->oam.paletteNum = adjustedPaletteNum; switch (graphicsId) { case EVENT_OBJ_GFX_LINK_RS_BRENDAN: - LoadPalette(gEventObjectPalette33, 0x100 + paletteNum * 16, 0x20); + LoadPalette(gEventObjectPalette33, 0x100 + (adjustedPaletteNum << 4), 0x20); break; case EVENT_OBJ_GFX_LINK_RS_MAY: - LoadPalette(gEventObjectPalette34, 0x100 + paletteNum * 16, 0x20); + LoadPalette(gEventObjectPalette34, 0x100 + (adjustedPaletteNum << 4), 0x20); break; case EVENT_OBJ_GFX_RIVAL_BRENDAN_NORMAL: - LoadPalette(gEventObjectPalette8, 0x100 + paletteNum * 16, 0x20); + LoadPalette(gEventObjectPalette8, 0x100 + (adjustedPaletteNum << 4), 0x20); break; case EVENT_OBJ_GFX_RIVAL_MAY_NORMAL: - LoadPalette(gEventObjectPalette17, 0x100 + paletteNum * 16, 0x20); + LoadPalette(gEventObjectPalette17, 0x100 + (adjustedPaletteNum << 4), 0x20); break; } } @@ -887,8 +887,8 @@ static void PetalburgGymFunc(u8 a0, u16 a1) } for (i = 0; i < nDoors; i++) { - MapGridSetMetatileIdAt(x[i] + 7, y[i] + 7, a1 | 0xc00); - MapGridSetMetatileIdAt(x[i] + 7, y[i] + 8, (a1 + 8) | 0xc00); + MapGridSetMetatileIdAt(x[i] + 7, y[i] + 7, a1 | METATILE_COLLISION_MASK); + MapGridSetMetatileIdAt(x[i] + 7, y[i] + 8, (a1 + 8) | METATILE_COLLISION_MASK); } DrawWholeMapView(); } @@ -1100,7 +1100,7 @@ static void PCTurnOnEffect_1(s16 flag, s8 dx, s8 dy) tileId = 0x27e; } } - MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + 7, gSaveBlock1Ptr->pos.y + dy + 7, tileId | 0xc00); + MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + 7, gSaveBlock1Ptr->pos.y + dy + 7, tileId | METATILE_COLLISION_MASK); } void DoPCTurnOffEffect(void) @@ -1141,7 +1141,7 @@ static void PCTurnOffEffect(void) { tileId = 0x259; } - MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + 7, gSaveBlock1Ptr->pos.y + dy + 7, tileId | 0xc00); + MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + dx + 7, gSaveBlock1Ptr->pos.y + dy + 7, tileId | METATILE_COLLISION_MASK); DrawWholeMapView(); } @@ -1516,7 +1516,7 @@ bool8 FoundBlackGlasses(void) void SetRoute119Weather(void) { - if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType()) != TRUE) + if (IsMapTypeOutdoors(GetLastUsedWarpMapType()) != TRUE) { SetSav1Weather(20); } @@ -1524,7 +1524,7 @@ void SetRoute119Weather(void) void SetRoute123Weather(void) { - if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType()) != TRUE) + if (IsMapTypeOutdoors(GetLastUsedWarpMapType()) != TRUE) { SetSav1Weather(21); } @@ -1860,7 +1860,7 @@ void sub_8139B60(void) void sub_8139C10(void) { - sub_8198070(gUnknown_0203AB5E, TRUE); + ClearStdWindowAndFrameToTransparent(gUnknown_0203AB5E, TRUE); RemoveWindow(gUnknown_0203AB5E); } @@ -1892,7 +1892,7 @@ static void sub_8139C80(u8 taskId) { for (x = 0; x < 3; x++) { - MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2BF4[y][data[0] % 3] | 0xC00); + MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2BF4[y][data[0] % 3] | METATILE_COLLISION_MASK); } } } @@ -1902,7 +1902,7 @@ static void sub_8139C80(u8 taskId) { for (x = 0; x < 3; x++) { - MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2C06[y][data[0] % 3] | 0xC00); + MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2C06[y][data[0] % 3] | METATILE_COLLISION_MASK); } } } @@ -2645,8 +2645,8 @@ static void sub_813A570(u8 taskId) sub_813A738(taskId); DestroyListMenuTask(task->data[14], NULL, NULL); Free(gUnknown_0203AB64); - sub_8198070(task->data[13], 1); - FillWindowPixelBuffer(task->data[13], 0); + ClearStdWindowAndFrameToTransparent(task->data[13], 1); + FillWindowPixelBuffer(task->data[13], PIXEL_FILL(0)); CopyWindowToVram(task->data[13], 2); RemoveWindow(task->data[13]); DestroyTask(taskId); @@ -2890,7 +2890,7 @@ void sub_813A958(void) void sub_813A988(void) { - sub_8198070(gUnknown_0203AB6D, TRUE); + ClearStdWindowAndFrameToTransparent(gUnknown_0203AB6D, TRUE); RemoveWindow(gUnknown_0203AB6D); } @@ -2942,7 +2942,7 @@ void sub_813AA18(void) void sub_813AA44(void) { - sub_8198070(gUnknown_0203AB6E, TRUE); + ClearStdWindowAndFrameToTransparent(gUnknown_0203AB6E, TRUE); RemoveWindow(gUnknown_0203AB6E); } @@ -3001,7 +3001,7 @@ static void sub_813AA60(u16 a0, u16 a1) if (a0 > 2 && a0 < 7) { - FillWindowPixelRect(0, 0x11, 0, 0, 216, 32); + FillWindowPixelRect(0, PIXEL_FILL(1), 0, 0, 216, 32); switch (a0) { case 3: @@ -3140,7 +3140,7 @@ static void sub_813AD34(u8 a0, u16 a1) if (a0 == 9 || a0 == 10) { - FillWindowPixelRect(gUnknown_0203AB5E, 0x11, 0, 0, 96, 48); + FillWindowPixelRect(gUnknown_0203AB5E, PIXEL_FILL(1), 0, 0, 96, 48); if (a0 == 10) { AddTextPrinterParameterized(gUnknown_0203AB5E, 1, gUnknown_085B3254[a1], 0, 1, 0, NULL); @@ -3154,7 +3154,7 @@ static void sub_813AD34(u8 a0, u16 a1) void sub_813ADB8(void) { - sub_8198070(gUnknown_0203AB5E, TRUE); + ClearStdWindowAndFrameToTransparent(gUnknown_0203AB5E, TRUE); RemoveWindow(gUnknown_0203AB5E); } @@ -3226,8 +3226,8 @@ void sub_813AF48(void) struct Task *task = &gTasks[taskId]; DestroyListMenuTask(task->data[14], NULL, NULL); Free(gUnknown_0203AB64); - sub_8198070(task->data[13], TRUE); - FillWindowPixelBuffer(task->data[13], 0); + ClearStdWindowAndFrameToTransparent(task->data[13], TRUE); + FillWindowPixelBuffer(task->data[13], PIXEL_FILL(0)); ClearWindowTilemap(task->data[13]); CopyWindowToVram(task->data[13], 2); RemoveWindow(task->data[13]); @@ -3379,7 +3379,7 @@ u16 get_unknown_box_id(void) return gUnknown_0203AB6F; } -bool32 sub_813B21C(void) +bool8 sub_813B21C(void) { if (FlagGet(FLAG_SYS_STORAGE_UNKNOWN_FLAG) == FALSE) { @@ -3421,40 +3421,59 @@ bool8 sub_813B260(void) return FALSE; } -void sub_813B2E4(void) +void CreateUnusualWeatherEvent(void) { u16 randomValue = Random(); - VarSet(VAR_0x4038, 0); + VarSet(VAR_UNUSUAL_WEATHER_STEP_COUNTER, 0); if (FlagGet(FLAG_DEFEATED_KYOGRE) == TRUE) { - VarSet(VAR_0x4037, (randomValue & 7) + 1); + VarSet(VAR_UNUSUAL_WEATHER_LOCATION, (randomValue % UNUSUAL_WEATHER_COUNT_PER_LEGENDARY) + UNUSUAL_WEATHER_GROUDON_LOCATIONS_START); } else if (FlagGet(FLAG_DEFEATED_GROUDON) == TRUE) { - VarSet(VAR_0x4037, (randomValue & 7) + 9); + VarSet(VAR_UNUSUAL_WEATHER_LOCATION, (randomValue % UNUSUAL_WEATHER_COUNT_PER_LEGENDARY) + UNUSUAL_WEATHER_KYOGRE_LOCATIONS_START); } else if ((randomValue & 1) == 0) { randomValue = Random(); - VarSet(VAR_0x4037, (randomValue & 7) + 1); + VarSet(VAR_UNUSUAL_WEATHER_LOCATION, (randomValue % UNUSUAL_WEATHER_COUNT_PER_LEGENDARY) + UNUSUAL_WEATHER_GROUDON_LOCATIONS_START); } else { randomValue = Random(); - VarSet(VAR_0x4037, (randomValue & 7) + 9); - } -} - -bool32 sub_813B374(void) -{ - static const u8 gUnknown_085B3400[] = { 0x1d, 0x1d, 0x1e, 0x1e, 0x1f, 0x1f, 0x21, 0x21, 0x14, 0x14, 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c }; + VarSet(VAR_UNUSUAL_WEATHER_LOCATION, (randomValue % UNUSUAL_WEATHER_COUNT_PER_LEGENDARY) + UNUSUAL_WEATHER_KYOGRE_LOCATIONS_START); + } +} + +// Saves the map name for the current unusual weather location in gStringVar1, then +// returns TRUE if the weather is for Kyogre, and FALSE if it's for Groudon. +bool32 GetUnusualWeatherMapNameAndType(void) +{ + static const u8 sUnusualWeatherMapNumbers[] = { + MAP_NUM(ROUTE114), + MAP_NUM(ROUTE114), + MAP_NUM(ROUTE115), + MAP_NUM(ROUTE115), + MAP_NUM(ROUTE116), + MAP_NUM(ROUTE116), + MAP_NUM(ROUTE118), + MAP_NUM(ROUTE118), + MAP_NUM(ROUTE105), + MAP_NUM(ROUTE105), + MAP_NUM(ROUTE125), + MAP_NUM(ROUTE125), + MAP_NUM(ROUTE127), + MAP_NUM(ROUTE127), + MAP_NUM(ROUTE129), + MAP_NUM(ROUTE129) + }; - u16 var = VarGet(VAR_0x4037); + u16 unusualWeather = VarGet(VAR_UNUSUAL_WEATHER_LOCATION); - GetMapName(gStringVar1, gUnknown_085B3400[var - 1], 0); + GetMapName(gStringVar1, sUnusualWeatherMapNumbers[unusualWeather - 1], 0); - if (var < 9) + if (unusualWeather < UNUSUAL_WEATHER_KYOGRE_LOCATIONS_START) { return FALSE; } @@ -3464,21 +3483,39 @@ bool32 sub_813B374(void) } } -bool8 sub_813B3B0(void) -{ - static const u8 gUnknown_085B3410[] = { 0x1d, 0x1d, 0x1e, 0x1e, 0x1f, 0x1f, 0x21, 0x21, 0x14, 0x14, 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c }; +bool8 UnusualWeatherHasExpired(void) +{ + // Duplicate array. + static const u8 sUnusualWeatherMapNumbers_2[] = { + MAP_NUM(ROUTE114), + MAP_NUM(ROUTE114), + MAP_NUM(ROUTE115), + MAP_NUM(ROUTE115), + MAP_NUM(ROUTE116), + MAP_NUM(ROUTE116), + MAP_NUM(ROUTE118), + MAP_NUM(ROUTE118), + MAP_NUM(ROUTE105), + MAP_NUM(ROUTE105), + MAP_NUM(ROUTE125), + MAP_NUM(ROUTE125), + MAP_NUM(ROUTE127), + MAP_NUM(ROUTE127), + MAP_NUM(ROUTE129), + MAP_NUM(ROUTE129) + }; - u16 var1 = VarGet(VAR_0x4038); - u16 var2 = VarGet(VAR_0x4037); + u16 steps = VarGet(VAR_UNUSUAL_WEATHER_STEP_COUNTER); + u16 unusualWeather = VarGet(VAR_UNUSUAL_WEATHER_LOCATION); - if (!var2) + if (unusualWeather == UNUSUAL_WEATHER_NONE) { return FALSE; } - if (++var1 > 999) + if (++steps > 999) { - VarSet(VAR_0x4038, 0); + VarSet(VAR_UNUSUAL_WEATHER_STEP_COUNTER, 0); if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(UNDERWATER_MARINE_CAVE)) { switch (gSaveBlock1Ptr->location.mapNum) @@ -3488,7 +3525,7 @@ bool8 sub_813B3B0(void) case MAP_NUM(MARINE_CAVE_END): case MAP_NUM(TERRA_CAVE_ENTRANCE): case MAP_NUM(TERRA_CAVE_END): - VarSet(VAR_0x4039, 1); + VarSet(VAR_SHOULD_END_UNUSUAL_WEATHER, 1); return FALSE; default: break; @@ -3503,27 +3540,27 @@ bool8 sub_813B3B0(void) case MAP_NUM(UNDERWATER5): case MAP_NUM(UNDERWATER6): case MAP_NUM(UNDERWATER7): - VarSet(VAR_0x4039, 1); + VarSet(VAR_SHOULD_END_UNUSUAL_WEATHER, 1); return FALSE; default: break; } } - if (gSaveBlock1Ptr->location.mapNum == gUnknown_085B3410[var2 - 1] && + if (gSaveBlock1Ptr->location.mapNum == sUnusualWeatherMapNumbers_2[unusualWeather - 1] && gSaveBlock1Ptr->location.mapGroup == 0) { return TRUE; } else { - VarSet(VAR_0x4037, 0); + VarSet(VAR_UNUSUAL_WEATHER_LOCATION, UNUSUAL_WEATHER_NONE); return FALSE; } } else { - VarSet(VAR_0x4038, var1); + VarSet(VAR_UNUSUAL_WEATHER_STEP_COUNTER, steps); return FALSE; } } @@ -3577,7 +3614,7 @@ bool32 sub_813B4E0(void) bool32 sub_813B514(void) { - if (!VarGet(VAR_0x403F)) + if (!VarGet(VAR_ALWAYS_ZERO_0x403F)) { return FALSE; } diff --git a/src/fieldmap.c b/src/fieldmap.c index cf5f0356e..a96b71c0f 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -383,15 +383,15 @@ u8 MapGridGetZCoordAt(int x, int y) i = (x + 1) & 1; i += ((y + 1) & 1) * 2; block = gMapHeader.mapLayout->border[i]; - block |= 0xc00; + block |= METATILE_COLLISION_MASK; } - if (block == 0x3ff) + if (block == METATILE_ID_UNDEFINED) { return 0; } - return block >> 12; + return block >> METATILE_ELEVATION_SHIFT; } u8 MapGridIsImpassableAt(int x, int y) @@ -411,13 +411,13 @@ u8 MapGridIsImpassableAt(int x, int y) i = (x + 1) & 1; i += ((y + 1) & 1) * 2; block = gMapHeader.mapLayout->border[i]; - block |= 0xc00; + block |= METATILE_COLLISION_MASK; } - if (block == 0x3ff) + if (block == METATILE_ID_UNDEFINED) { return 1; } - return (block & 0xc00) >> 10; + return (block & METATILE_COLLISION_MASK) >> METATILE_COLLISION_SHIFT; } u32 MapGridGetMetatileIdAt(int x, int y) @@ -439,18 +439,19 @@ u32 MapGridGetMetatileIdAt(int x, int y) mapLayout = gMapHeader.mapLayout; i = (x + 1) & 1; i += ((y + 1) & 1) * 2; - block = mapLayout->border[i] | 0xc00; + block = mapLayout->border[i] | METATILE_COLLISION_MASK; } - if (block == 0x3ff) + if (block == METATILE_ID_UNDEFINED) { border = gMapHeader.mapLayout->border; j = (x + 1) & 1; j += ((y + 1) & 1) * 2; block2 = gMapHeader.mapLayout->border[j]; - block2 |= 0xc00; - return block2 & block; + // This OR is completely pointless. + block2 |= METATILE_COLLISION_MASK; + return block2 & METATILE_ID_MASK; } - return block & 0x3ff; + return block & METATILE_ID_MASK; } u32 MapGridGetMetatileBehaviorAt(int x, int y) @@ -464,7 +465,7 @@ u8 MapGridGetMetatileLayerTypeAt(int x, int y) { u16 metatile; metatile = MapGridGetMetatileIdAt(x, y); - return (GetBehaviorByMetatileId(metatile) & 0xf000) >> 12; + return (GetBehaviorByMetatileId(metatile) & METATILE_ELEVATION_MASK) >> METATILE_ELEVATION_SHIFT; } void MapGridSetMetatileIdAt(int x, int y, u16 metatile) @@ -474,7 +475,7 @@ void MapGridSetMetatileIdAt(int x, int y, u16 metatile) && y >= 0 && y < gBackupMapLayout.height) { i = x + y * gBackupMapLayout.width; - gBackupMapLayout.map[i] = (gBackupMapLayout.map[i] & 0xf000) | (metatile & 0xfff); + gBackupMapLayout.map[i] = (gBackupMapLayout.map[i] & METATILE_ELEVATION_MASK) | (metatile & ~METATILE_ELEVATION_MASK); } } @@ -654,7 +655,7 @@ int GetMapBorderIdAt(int x, int y) i = gBackupMapLayout.width; i *= y; block = gBackupMapLayout.map[x + i]; - if (block == 0x3ff) + if (block == METATILE_ID_UNDEFINED) { goto fail; } @@ -664,8 +665,8 @@ int GetMapBorderIdAt(int x, int y) mapLayout = gMapHeader.mapLayout; j = (x + 1) & 1; j += ((y + 1) & 1) * 2; - block2 = 0xc00 | mapLayout->border[j]; - if (block2 == 0x3ff) + block2 = METATILE_COLLISION_MASK | mapLayout->border[j]; + if (block2 == METATILE_ID_UNDEFINED) { goto fail; } @@ -921,9 +922,9 @@ void sub_8088B94(int x, int y, int a2) if (x >= 0 && x < gBackupMapLayout.width && y >= 0 && y < gBackupMapLayout.height) { if (a2 != 0) - gBackupMapLayout.map[x + gBackupMapLayout.width * y] |= 0xC00; + gBackupMapLayout.map[x + gBackupMapLayout.width * y] |= METATILE_COLLISION_MASK; else - gBackupMapLayout.map[x + gBackupMapLayout.width * y] &= 0xF3FF; + gBackupMapLayout.map[x + gBackupMapLayout.width * y] &= ~METATILE_COLLISION_MASK; } } @@ -937,7 +938,7 @@ static bool8 SkipCopyingMetatileFromSavedMap(u16* mapMetatilePtr, u16 mapWidth, else mapMetatilePtr += mapWidth; - if (sub_80FADE4(*mapMetatilePtr & 0x3FF, yMode) == 1) + if (sub_80FADE4(*mapMetatilePtr & METATILE_ID_MASK, yMode) == 1) return TRUE; return FALSE; } diff --git a/src/fldeff_cut.c b/src/fldeff_cut.c index 348a1f46c..a715608c5 100644 --- a/src/fldeff_cut.c +++ b/src/fldeff_cut.c @@ -20,7 +20,6 @@ #include "constants/field_effects.h" #include "constants/songs.h" -extern void ScriptUnfreezeEventObjects(void); extern bool8 IsMewPlayingHideAndSeek(void); extern struct MapPosition gPlayerFacingPosition; diff --git a/src/fldeff_escalator.c b/src/fldeff_escalator.c index 3d00fb162..7ab2db4db 100644 --- a/src/fldeff_escalator.c +++ b/src/fldeff_escalator.c @@ -7,7 +7,7 @@ static EWRAM_DATA u8 sEscalatorAnim_TaskId = 0; -static void sub_80E12E8(u8 taskId, const s16 *list, u16 c) +static void sub_80E12E8(u8 taskId, const s16 *list, u16 isImpassableFlag) { s16 r5 = gTasks[taskId].data[4] - 1; s16 r3 = gTasks[taskId].data[5] - 1; @@ -26,9 +26,9 @@ static void sub_80E12E8(u8 taskId, const s16 *list, u16 c) if (list[r4] == metatileId) { if (r4 != 2) - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[r4 + 1]); + MapGridSetMetatileIdAt(r5 + x, r3 + y, isImpassableFlag | list[r4 + 1]); else - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[0]); + MapGridSetMetatileIdAt(r5 + x, r3 + y, isImpassableFlag | list[0]); } } } @@ -44,9 +44,9 @@ static void sub_80E12E8(u8 taskId, const s16 *list, u16 c) if (list[2 - r4] == metatileId) { if (r4 != 2) - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[1 - r4]); + MapGridSetMetatileIdAt(r5 + x, r3 + y, isImpassableFlag | list[1 - r4]); else - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[2]); + MapGridSetMetatileIdAt(r5 + x, r3 + y, isImpassableFlag | list[2]); } } } @@ -76,13 +76,13 @@ static void sub_80E1444(u8 taskId) sub_80E12E8(taskId, gUnknown_08589AC0, 0); break; case 2: - sub_80E12E8(taskId, gUnknown_08589AC6, 0xC00); + sub_80E12E8(taskId, gUnknown_08589AC6, METATILE_COLLISION_MASK); break; case 3: sub_80E12E8(taskId, gUnknown_08589ACC, 0); break; case 4: - sub_80E12E8(taskId, gUnknown_08589AD2, 0xC00); + sub_80E12E8(taskId, gUnknown_08589AD2, METATILE_COLLISION_MASK); break; case 5: sub_80E12E8(taskId, gUnknown_08589AD8, 0); diff --git a/src/fldeff_misc.c b/src/fldeff_misc.c index df4576a7f..d4d6075f3 100644 --- a/src/fldeff_misc.c +++ b/src/fldeff_misc.c @@ -1126,7 +1126,7 @@ void GetShieldToyTVDecorationInfo(void) if (!VarGet(VAR_CURRENT_SECRET_BASE)) return; - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x10); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x10); break; case 734: ConvertIntToDecimalStringN(gStringVar1, 50, STR_CONV_MODE_LEFT_ALIGN, 2); @@ -1137,7 +1137,7 @@ void GetShieldToyTVDecorationInfo(void) if (!VarGet(VAR_CURRENT_SECRET_BASE)) return; - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x20); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x20); break; case 756: gSpecialVar_Result = 1; @@ -1145,7 +1145,7 @@ void GetShieldToyTVDecorationInfo(void) if (!VarGet(VAR_CURRENT_SECRET_BASE)) return; - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x80); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x80); break; case 757: gSpecialVar_Result = 2; @@ -1153,7 +1153,7 @@ void GetShieldToyTVDecorationInfo(void) if (!VarGet(VAR_CURRENT_SECRET_BASE)) return; - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x80); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x80); break; case 758: gSpecialVar_Result = 3; @@ -1161,7 +1161,7 @@ void GetShieldToyTVDecorationInfo(void) if (!VarGet(VAR_CURRENT_SECRET_BASE)) return; - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x80); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x80); break; } } diff --git a/src/fldeff_softboiled.c b/src/fldeff_softboiled.c index adec780b3..eca7d045b 100644 --- a/src/fldeff_softboiled.c +++ b/src/fldeff_softboiled.c @@ -86,7 +86,7 @@ static void sub_8161724(u8 taskId) sub_81B0FCC(gUnknown_0203CEC8.unk9, 0); gUnknown_0203CEC8.unk9 = gUnknown_0203CEC8.unkA; sub_81B0FCC(gUnknown_0203CEC8.unkA, 1); - sub_8198070(0x6, FALSE); + ClearStdWindowAndFrameToTransparent(0x6, FALSE); ClearWindowTilemap(0x6); display_pokemon_menu_message(0); gTasks[taskId].func = sub_81B1370; diff --git a/src/flying.c b/src/flying.c index 48df12a06..a157582e9 100644 --- a/src/flying.c +++ b/src/flying.c @@ -4,6 +4,9 @@ #include "trig.h" #include "constants/battle_anim.h" #include "constants/rgb.h" +#include "random.h" + +extern const struct SpriteTemplate gUnknown_085973E8; void sub_810DE70(struct Sprite *); void sub_810DFA8(struct Sprite *); @@ -11,22 +14,29 @@ void sub_810E044(struct Sprite *); void sub_810E13C(struct Sprite *); void sub_810E1C8(struct Sprite *); void sub_810E314(struct Sprite *); -extern void sub_810EA4C(struct Sprite *); -extern void sub_810EAA0(struct Sprite *); -extern void sub_810EC34(struct Sprite *); -extern void sub_810EC94(struct Sprite *); -extern void sub_810ED28(struct Sprite *); -extern void sub_810EE14(struct Sprite *); -extern void sub_810EEF8(struct Sprite *); -extern void sub_810F004(struct Sprite *); -extern void sub_810F084(struct Sprite *); +void sub_810E520(struct Sprite *); +void sub_810EB40(struct Sprite *); +void sub_810EA4C(struct Sprite *); +void sub_810EAA0(struct Sprite *); +void sub_810EC34(struct Sprite *); +void sub_810EC94(struct Sprite *); +void sub_810ED28(struct Sprite *); +void sub_810ED70(struct Sprite *); +void sub_810EDD0(struct Sprite *); +void sub_810EE14(struct Sprite *); +void sub_810EEF8(struct Sprite *); +void sub_810EFA8(struct Sprite *); +void sub_810F004(struct Sprite *); +void sub_810F018(struct Sprite *); +void sub_810F084(struct Sprite *); +void sub_810F140(struct Sprite *); static void sub_810DE98(struct Sprite *); static void sub_810DF18(u8); static void sub_810E028(struct Sprite *); static void sub_810E184(struct Sprite *); static void sub_810E24C(struct Sprite *); -void sub_810E520(struct Sprite *); + const struct SpriteTemplate gUnknown_08596270 = { @@ -98,7 +108,7 @@ const union AffineAnimCmd gUnknown_085962EC[] = const union AffineAnimCmd *const gUnknown_08596314[] = { - gUnknown_085962EC, + gUnknown_085962EC, }; const union AffineAnimCmd gUnknown_08596318[] = @@ -347,7 +357,8 @@ void sub_810DE70(struct Sprite *sprite) sprite->callback(sprite); } -static void sub_810DE98(struct Sprite *sprite) { +static void sub_810DE98(struct Sprite *sprite) +{ sprite->pos2.x = Sin(sprite->data[1], 32); sprite->pos2.y = Cos(sprite->data[1], 8); sprite->data[1] += 5; @@ -382,8 +393,7 @@ static void sub_810DF18(u8 taskId) { gPlttBufferFaded[base + 0x101 + i] = gPlttBufferFaded[base + 0x100 + i]; i--; - } - while (i > 0); + } while (i > 0); gPlttBufferFaded[base + 0x101] = temp; } @@ -514,7 +524,9 @@ static void sub_810E24C(struct Sprite *sprite) sprite->data[3] &= 0xFF; } - if ((u32)(sprite->pos1.x + sprite->pos2.x + 32) > 304 || sprite->pos1.y + sprite->pos2.y > 160) + if (sprite->pos1.x + sprite->pos2.x < -32 + || sprite->pos1.x + sprite->pos2.x > 272 + || sprite->pos1.y + sprite->pos2.y > 160) { gSprites[GetAnimBattlerSpriteId(ANIM_ATTACKER)].invisible = 0; DestroyAnimSprite(sprite); @@ -536,56 +548,62 @@ void sub_810E2C8(struct Sprite *sprite) } } -// FAKEMATCHING +struct FeatherDanceData +{ + u8 unk0_0a:1; + u8 unk0_0b:1; + u8 unk0_0c:1; + u8 unk0_0d:1; + u8 unk0_1:4; + u8 unk1; + u16 unk2; + s16 unk4; + u16 unk6; + u16 unk8; + u16 unkA; + u8 unkC[2]; + u16 unkE_0:1; + u16 unkE_1:15; +}; + void sub_810E314(struct Sprite *sprite) { - s16 *data; - u8 slot; - s16 spriteCoord; - int t1, t2; - u32 arg2; - u32 matrixNum; - u8 sinIndex; - register s16 sinVal asm ("r4"); - register int sinVal2 asm ("r0"); + u8 battler, matrixNum, sinIndex; + s16 spriteCoord, sinVal; - data = sprite->data; + struct FeatherDanceData *data = (struct FeatherDanceData *)sprite->data; if (gBattleAnimArgs[7] & 0x100) - slot = gBattleAnimAttacker; + battler = gBattleAnimAttacker; else - slot = gBattleAnimTarget; + battler = gBattleAnimTarget; - if (GetBattlerSide(slot) == B_SIDE_PLAYER) + if (GetBattlerSide(battler) == B_SIDE_PLAYER) gBattleAnimArgs[0] = -gBattleAnimArgs[0]; - sprite->pos1.x = GetBattlerSpriteCoord(slot, 0) + gBattleAnimArgs[0]; - spriteCoord = GetBattlerSpriteCoord(slot, 1); + sprite->pos1.x = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_HEIGHT) + gBattleAnimArgs[0]; + spriteCoord = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_WIDTH); sprite->pos1.y = spriteCoord + gBattleAnimArgs[1]; - data[4] = sprite->pos1.y << 8; - - t1 = (spriteCoord + (u16) gBattleAnimArgs[6]) << 1; - data[7] = (data[7] & 1) | t1; - ((u8 *) data)[0] |= 4; - arg2 = (u16) gBattleAnimArgs[2]; - data[1] = (u8) gBattleAnimArgs[2]; - arg2 <<= 16; - data[5] = arg2 >> 24; - data[2] = gBattleAnimArgs[3]; - data[3] = gBattleAnimArgs[4]; - data[6] = gBattleAnimArgs[5]; + data->unk8 = sprite->pos1.y << 8; + data->unkE_1 = spriteCoord + gBattleAnimArgs[6]; + data->unk0_0c = 1; + data->unk2 = gBattleAnimArgs[2] & 0xFF; + data->unkA = (gBattleAnimArgs[2] >> 8) & 0xFF; + data->unk4 = gBattleAnimArgs[3]; + data->unk6 = gBattleAnimArgs[4]; + *(u16*)(data->unkC) = gBattleAnimArgs[5]; - if ((u16) (data[1] - 64) <= 0x7f) + if (data->unk2 >= 64 && data->unk2 <= 191) { if (!IsContest()) - sprite->oam.priority = GetBattlerSpriteBGPriority(slot) + 1; + sprite->oam.priority = GetBattlerSpriteBGPriority(battler) + 1; else - sprite->oam.priority = GetBattlerSpriteBGPriority(slot); + sprite->oam.priority = GetBattlerSpriteBGPriority(battler); - ((u8 *) data)[14] = data[7] & -2; + data->unkE_0 = 0; - if (!(data[2] & 0x8000)) + if (!(data->unk4 & 0x8000)) { sprite->hFlip ^= 1; sprite->animNum = sprite->hFlip; @@ -596,10 +614,10 @@ void sub_810E314(struct Sprite *sprite) } else { - sprite->oam.priority = GetBattlerSpriteBGPriority(slot); - ((u8 *) data)[14] |= 1; + sprite->oam.priority = GetBattlerSpriteBGPriority(battler); + data->unkE_0 = 1; - if (data[2] & 0x8000) + if (data->unk4 & 0x8000) { sprite->hFlip ^= 1; sprite->animNum = sprite->hFlip; @@ -609,20 +627,1291 @@ void sub_810E314(struct Sprite *sprite) } } - t2 = (u16) data[1] >> 6 << 4; - ((u8 *) data)[0] = (15 & data[0]) | t2; - - sprite->pos2.x = (gSineTable[(u16) data[1]] * (u8) data[6]) >> 8; - + data->unk0_1 = data->unk2 >> 6; + sprite->pos2.x = (gSineTable[data->unk2] * data->unkC[0]) >> 8; matrixNum = sprite->oam.matrixNum; - sinIndex = (-sprite->pos2.x >> 1) + data[5]; + sinIndex = (-sprite->pos2.x >> 1) + data->unkA; sinVal = gSineTable[sinIndex]; gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; - gOamMatrices[matrixNum].b = sinVal; - sinVal2 = -sinVal; - gOamMatrices[matrixNum].c = sinVal2; + // The comparison below is completely pointless. 'sprite' is sure to be a valid pointer and + // both the 'if' and 'else' parts are exactly the same. + // The only reason for this is making sure the compiler generates the exact ASM. + if (sprite) + { + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; + } + else + { + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; + } sprite->callback = sub_810E520; } + +#ifdef NONMATCHING +/* +Things I can't get to match: +1. data->unk0_1 bitfield behaviour. The way bits are read is different. +2. sprite->oam.priority--; sprite->oam.priority++; Nonmatching version tail-merges these, original does not. +3. sprite->pos2.x = (gSineTable[data->unk2] * var) >> 8; data->unk2 is very weirdly read at seemingly random moments inside the switch. +4. sinVal r6/r7 mismatch. +*/ +void sub_810E520(struct Sprite *sprite) +{ + u8 matrixNum, sinIndex, var; + s16 sinVal = 0; + struct FeatherDanceData *data = (struct FeatherDanceData *)sprite->data; + + if (data->unk0_0a) + { + if (data->unk1-- % 256 == 0) + { + data->unk0_0a = 0; + data->unk1 = 0; + } + } + else + { + switch (data->unk2 >> 6) + { + case 0: + if (data->unk0_1 == 1) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_1 == 3) + { + data->unk0_0b ^= 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = 1; + sprite->animEnded = 0; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + sprite->oam.priority--; + else + sprite->oam.priority++; + } + else + { + if (!data->unkE_0) + sprite->subpriority -= 12; + else + sprite->subpriority += 12; + } + data->unkE_0 ^= 1; + } + data->unk0_0d = 0; + } + data->unk0_1 = 0; + break; + case 1: + if (data->unk0_1 == 0) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_1 == 2) + { + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = 1; + sprite->animEnded = 0; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + sprite->oam.priority--; + else + sprite->oam.priority++; + } + else + { + if (!data->unkE_0) + sprite->subpriority -= 12; + else + sprite->subpriority += 12; + } + data->unkE_0 ^= 1; + } + data->unk0_0d = 0; + } + data->unk0_1 = 1; + break; + case 2: + if (data->unk0_1 == 0) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_1 == 2) + { + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = 1; + sprite->animEnded = 0; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + sprite->oam.priority--; + else + sprite->oam.priority++; + } + else + { + if (!data->unkE_0) + sprite->subpriority -= 12; + else + sprite->subpriority += 12; + } + data->unkE_0 ^= 1; + } + data->unk0_0d = 0; + } + data->unk0_1 = 2; + break; + case 3: + if (data->unk0_1 == 2) + { + data->unk0_0d = 1; + } + else if (data->unk0_1 == 0) + { + data->unk0_0b ^= 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = 1; + sprite->animEnded = 0; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + sprite->oam.priority--; + else + sprite->oam.priority++; + } + else + { + if (!data->unkE_0) + sprite->subpriority -= 12; + else + sprite->subpriority += 12; + } + data->unkE_0 ^= 1; + } + data->unk0_0d = 0; + } + data->unk0_1 = 3; + break; + } + + var = data->unkC[data->unk0_0b]; + sprite->pos2.x = (gSineTable[data->unk2] * var) >> 8; + matrixNum = sprite->oam.matrixNum; + + sinIndex = (-sprite->pos2.x >> 1) + data->unkA; + sinVal = gSineTable[sinIndex]; + + gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; + + data->unk8 += data->unk6; + sprite->pos1.y = data->unk8 >> 8; + if (data->unk4 & 0x8000) + data->unk2 = (data->unk2 - (data->unk4 & 0x7FFF)) & 0xFF; + else + data->unk2 = (data->unk2 + (data->unk4 & 0x7FFF)) & 0xFF; + + if (sprite->pos1.y + sprite->pos2.y > data->unkE_1) + { + sprite->data[0] = 0; + sprite->callback = sub_810E2C8; + } + } +} +#else +NAKED +void sub_810E520(struct Sprite *sprite) +{ + asm_unified("push {r4-r7,lr}\n\ + mov r7, r9\n\ + mov r6, r8\n\ + push {r6,r7}\n\ + adds r5, r0, 0\n\ + movs r6, 0\n\ + adds r4, r5, 0\n\ + adds r4, 0x2E\n\ + ldrb r2, [r4]\n\ + movs r7, 0x1\n\ + movs r0, 0x1\n\ + mov r9, r0\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0810E55A\n\ + ldrb r0, [r4, 0x1]\n\ + adds r1, r0, 0\n\ + adds r1, 0xFF\n\ + strb r1, [r4, 0x1]\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + beq _0810E54E\n\ + b _0810EA36\n\ +_0810E54E:\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + ands r0, r2\n\ + strb r0, [r4]\n\ + strb r6, [r4, 0x1]\n\ + b _0810EA36\n\ +_0810E55A:\n\ + ldrh r0, [r4, 0x2]\n\ + lsrs r1, r0, 6\n\ + mov r12, r0\n\ + cmp r1, 0x1\n\ + bne _0810E566\n\ + b _0810E68A\n\ +_0810E566:\n\ + cmp r1, 0x1\n\ + bgt _0810E570\n\ + cmp r1, 0\n\ + beq _0810E57E\n\ + b _0810E97C\n\ +_0810E570:\n\ + cmp r1, 0x2\n\ + bne _0810E576\n\ + b _0810E77E\n\ +_0810E576:\n\ + cmp r1, 0x3\n\ + bne _0810E57C\n\ + b _0810E872\n\ +_0810E57C:\n\ + b _0810E97C\n\ +_0810E57E:\n\ + lsls r1, r2, 24\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0x1\n\ + bne _0810E592\n\ + movs r0, 0x8\n\ + orrs r0, r2\n\ + orrs r0, r7\n\ + strb r0, [r4]\n\ + strb r6, [r4, 0x1]\n\ + b _0810E680\n\ +_0810E592:\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0x3\n\ + bne _0810E5B4\n\ + lsls r0, r2, 30\n\ + lsrs r0, 31\n\ + movs r1, 0x1\n\ + eors r0, r1\n\ + ands r0, r7\n\ + lsls r0, 1\n\ + movs r1, 0x3\n\ + negs r1, r1\n\ + ands r1, r2\n\ + orrs r1, r0\n\ + orrs r1, r7\n\ + strb r1, [r4]\n\ + strb r6, [r4, 0x1]\n\ + b _0810E680\n\ +_0810E5B4:\n\ + movs r0, 0x8\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0810E680\n\ + adds r3, r5, 0\n\ + adds r3, 0x3F\n\ + ldrb r2, [r3]\n\ + lsls r1, r2, 31\n\ + lsrs r1, 31\n\ + movs r6, 0x1\n\ + eors r1, r6\n\ + ands r1, r7\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + mov r8, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r3]\n\ + lsls r0, 31\n\ + lsrs r0, 31\n\ + adds r1, r5, 0\n\ + adds r1, 0x2A\n\ + strb r0, [r1]\n\ + ldrb r0, [r3]\n\ + movs r1, 0x4\n\ + orrs r0, r1\n\ + movs r1, 0x11\n\ + negs r1, r1\n\ + ands r0, r1\n\ + strb r0, [r3]\n\ + ldrb r1, [r4]\n\ + movs r0, 0x4\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0810E672\n\ + bl IsContest\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _0810E642\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E628\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + subs r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E660\n\ +_0810E628:\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + adds r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E660\n\ +_0810E642:\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E656\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + subs r0, 0xC\n\ + b _0810E65E\n\ +_0810E656:\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + adds r0, 0xC\n\ +_0810E65E:\n\ + strb r0, [r1]\n\ +_0810E660:\n\ + ldrb r2, [r4, 0xE]\n\ + lsls r0, r2, 31\n\ + lsrs r0, 31\n\ + eors r0, r6\n\ + ands r0, r7\n\ + mov r1, r8\n\ + ands r1, r2\n\ + orrs r1, r0\n\ + strb r1, [r4, 0xE]\n\ +_0810E672:\n\ + ldrb r1, [r4]\n\ + movs r0, 0x9\n\ + negs r0, r0\n\ + ands r0, r1\n\ + strb r0, [r4]\n\ + ldrh r1, [r4, 0x2]\n\ + mov r12, r1\n\ +_0810E680:\n\ + ldrb r1, [r4]\n\ + movs r0, 0xF\n\ + ands r0, r1\n\ + strb r0, [r4]\n\ + b _0810E97C\n\ +_0810E68A:\n\ + lsls r1, r2, 24\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0\n\ + bne _0810E698\n\ + movs r0, 0x8\n\ + orrs r0, r2\n\ + b _0810E6A0\n\ +_0810E698:\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0x2\n\ + bne _0810E6A8\n\ + adds r0, r2, 0\n\ +_0810E6A0:\n\ + orrs r0, r7\n\ + strb r0, [r4]\n\ + strb r6, [r4, 0x1]\n\ + b _0810E774\n\ +_0810E6A8:\n\ + movs r0, 0x8\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0810E774\n\ + adds r3, r5, 0\n\ + adds r3, 0x3F\n\ + ldrb r2, [r3]\n\ + lsls r1, r2, 31\n\ + lsrs r1, 31\n\ + movs r6, 0x1\n\ + eors r1, r6\n\ + ands r1, r7\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + mov r8, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r3]\n\ + lsls r0, 31\n\ + lsrs r0, 31\n\ + adds r1, r5, 0\n\ + adds r1, 0x2A\n\ + strb r0, [r1]\n\ + ldrb r0, [r3]\n\ + movs r1, 0x4\n\ + orrs r0, r1\n\ + movs r1, 0x11\n\ + negs r1, r1\n\ + ands r0, r1\n\ + strb r0, [r3]\n\ + ldrb r1, [r4]\n\ + movs r0, 0x4\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0810E766\n\ + bl IsContest\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _0810E736\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E71C\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + subs r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E754\n\ +_0810E71C:\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + adds r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E754\n\ +_0810E736:\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E74A\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + subs r0, 0xC\n\ + b _0810E752\n\ +_0810E74A:\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + adds r0, 0xC\n\ +_0810E752:\n\ + strb r0, [r1]\n\ +_0810E754:\n\ + ldrb r2, [r4, 0xE]\n\ + lsls r0, r2, 31\n\ + lsrs r0, 31\n\ + eors r0, r6\n\ + ands r0, r7\n\ + mov r1, r8\n\ + ands r1, r2\n\ + orrs r1, r0\n\ + strb r1, [r4, 0xE]\n\ +_0810E766:\n\ + ldrb r1, [r4]\n\ + movs r0, 0x9\n\ + negs r0, r0\n\ + ands r0, r1\n\ + strb r0, [r4]\n\ + ldrh r1, [r4, 0x2]\n\ + mov r12, r1\n\ +_0810E774:\n\ + ldrb r0, [r4]\n\ + movs r1, 0xF\n\ + ands r1, r0\n\ + movs r0, 0x10\n\ + b _0810E978\n\ +_0810E77E:\n\ + lsls r1, r2, 24\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0x3\n\ + bne _0810E78C\n\ + movs r0, 0x8\n\ + orrs r0, r2\n\ + b _0810E794\n\ +_0810E78C:\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0x1\n\ + bne _0810E79C\n\ + adds r0, r2, 0\n\ +_0810E794:\n\ + orrs r0, r7\n\ + strb r0, [r4]\n\ + strb r6, [r4, 0x1]\n\ + b _0810E868\n\ +_0810E79C:\n\ + movs r0, 0x8\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0810E868\n\ + adds r3, r5, 0\n\ + adds r3, 0x3F\n\ + ldrb r2, [r3]\n\ + lsls r1, r2, 31\n\ + lsrs r1, 31\n\ + movs r6, 0x1\n\ + eors r1, r6\n\ + ands r1, r7\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + mov r8, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r3]\n\ + lsls r0, 31\n\ + lsrs r0, 31\n\ + adds r1, r5, 0\n\ + adds r1, 0x2A\n\ + strb r0, [r1]\n\ + ldrb r0, [r3]\n\ + movs r1, 0x4\n\ + orrs r0, r1\n\ + movs r1, 0x11\n\ + negs r1, r1\n\ + ands r0, r1\n\ + strb r0, [r3]\n\ + ldrb r1, [r4]\n\ + movs r0, 0x4\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0810E85A\n\ + bl IsContest\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _0810E82A\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E810\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + subs r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E848\n\ +_0810E810:\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + adds r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E848\n\ +_0810E82A:\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E83E\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + subs r0, 0xC\n\ + b _0810E846\n\ +_0810E83E:\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + adds r0, 0xC\n\ +_0810E846:\n\ + strb r0, [r1]\n\ +_0810E848:\n\ + ldrb r2, [r4, 0xE]\n\ + lsls r0, r2, 31\n\ + lsrs r0, 31\n\ + eors r0, r6\n\ + ands r0, r7\n\ + mov r1, r8\n\ + ands r1, r2\n\ + orrs r1, r0\n\ + strb r1, [r4, 0xE]\n\ +_0810E85A:\n\ + ldrb r1, [r4]\n\ + movs r0, 0x9\n\ + negs r0, r0\n\ + ands r0, r1\n\ + strb r0, [r4]\n\ + ldrh r1, [r4, 0x2]\n\ + mov r12, r1\n\ +_0810E868:\n\ + ldrb r0, [r4]\n\ + movs r1, 0xF\n\ + ands r1, r0\n\ + movs r0, 0x20\n\ + b _0810E978\n\ +_0810E872:\n\ + lsls r1, r2, 24\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0x2\n\ + bne _0810E882\n\ + movs r0, 0x8\n\ + orrs r0, r2\n\ + strb r0, [r4]\n\ + b _0810E970\n\ +_0810E882:\n\ + lsrs r0, r1, 28\n\ + cmp r0, 0\n\ + bne _0810E8A4\n\ + lsls r0, r2, 30\n\ + lsrs r0, 31\n\ + movs r1, 0x1\n\ + eors r0, r1\n\ + ands r0, r7\n\ + lsls r0, 1\n\ + movs r1, 0x3\n\ + negs r1, r1\n\ + ands r1, r2\n\ + orrs r1, r0\n\ + orrs r1, r7\n\ + strb r1, [r4]\n\ + strb r6, [r4, 0x1]\n\ + b _0810E970\n\ +_0810E8A4:\n\ + movs r0, 0x8\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0810E970\n\ + adds r3, r5, 0\n\ + adds r3, 0x3F\n\ + ldrb r2, [r3]\n\ + lsls r1, r2, 31\n\ + lsrs r1, 31\n\ + movs r6, 0x1\n\ + eors r1, r6\n\ + ands r1, r7\n\ + movs r0, 0x2\n\ + negs r0, r0\n\ + mov r8, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r3]\n\ + lsls r0, 31\n\ + lsrs r0, 31\n\ + adds r1, r5, 0\n\ + adds r1, 0x2A\n\ + strb r0, [r1]\n\ + ldrb r0, [r3]\n\ + movs r1, 0x4\n\ + orrs r0, r1\n\ + movs r1, 0x11\n\ + negs r1, r1\n\ + ands r0, r1\n\ + strb r0, [r3]\n\ + ldrb r1, [r4]\n\ + movs r0, 0x4\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0810E962\n\ + bl IsContest\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _0810E932\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E918\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + subs r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E950\n\ +_0810E918:\n\ + ldrb r2, [r5, 0x5]\n\ + lsls r1, r2, 28\n\ + lsrs r1, 30\n\ + adds r1, 0x1\n\ + movs r0, 0x3\n\ + ands r1, r0\n\ + lsls r1, 2\n\ + movs r0, 0xD\n\ + negs r0, r0\n\ + ands r0, r2\n\ + orrs r0, r1\n\ + strb r0, [r5, 0x5]\n\ + b _0810E950\n\ +_0810E932:\n\ + ldrb r1, [r4, 0xE]\n\ + mov r0, r9\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0810E946\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + subs r0, 0xC\n\ + b _0810E94E\n\ +_0810E946:\n\ + adds r1, r5, 0\n\ + adds r1, 0x43\n\ + ldrb r0, [r1]\n\ + adds r0, 0xC\n\ +_0810E94E:\n\ + strb r0, [r1]\n\ +_0810E950:\n\ + ldrb r2, [r4, 0xE]\n\ + lsls r0, r2, 31\n\ + lsrs r0, 31\n\ + eors r0, r6\n\ + ands r0, r7\n\ + mov r1, r8\n\ + ands r1, r2\n\ + orrs r1, r0\n\ + strb r1, [r4, 0xE]\n\ +_0810E962:\n\ + ldrb r1, [r4]\n\ + movs r0, 0x9\n\ + negs r0, r0\n\ + ands r0, r1\n\ + strb r0, [r4]\n\ + ldrh r1, [r4, 0x2]\n\ + mov r12, r1\n\ +_0810E970:\n\ + ldrb r0, [r4]\n\ + movs r1, 0xF\n\ + ands r1, r0\n\ + movs r0, 0x30\n\ +_0810E978:\n\ + orrs r1, r0\n\ + strb r1, [r4]\n\ +_0810E97C:\n\ + ldrb r1, [r4]\n\ + lsls r1, 30\n\ + lsrs r1, 31\n\ + adds r0, r4, 0\n\ + adds r0, 0xC\n\ + adds r0, r1\n\ + ldrb r1, [r0]\n\ + ldr r3, =gSineTable\n\ + mov r2, r12\n\ + lsls r0, r2, 1\n\ + adds r0, r3\n\ + movs r2, 0\n\ + ldrsh r0, [r0, r2]\n\ + muls r0, r1\n\ + asrs r0, 8\n\ + strh r0, [r5, 0x24]\n\ + ldrb r2, [r5, 0x3]\n\ + lsls r2, 26\n\ + lsrs r2, 27\n\ + movs r1, 0x24\n\ + ldrsh r0, [r5, r1]\n\ + negs r0, r0\n\ + asrs r0, 1\n\ + ldrb r1, [r4, 0xA]\n\ + adds r0, r1\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + lsls r1, r0, 1\n\ + adds r1, r3\n\ + ldrh r6, [r1]\n\ + ldr r1, =gOamMatrices\n\ + lsls r2, 3\n\ + adds r2, r1\n\ + adds r0, 0x40\n\ + lsls r0, 1\n\ + adds r0, r3\n\ + ldrh r0, [r0]\n\ + strh r0, [r2, 0x6]\n\ + strh r0, [r2]\n\ + strh r6, [r2, 0x2]\n\ + lsls r0, r6, 16\n\ + asrs r0, 16\n\ + negs r0, r0\n\ + strh r0, [r2, 0x4]\n\ + ldrh r0, [r4, 0x6]\n\ + ldrh r2, [r4, 0x8]\n\ + adds r0, r2\n\ + strh r0, [r4, 0x8]\n\ + lsls r0, 16\n\ + lsrs r0, 24\n\ + strh r0, [r5, 0x22]\n\ + movs r1, 0x4\n\ + ldrsh r0, [r4, r1]\n\ + movs r1, 0x80\n\ + lsls r1, 8\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0810EA0C\n\ + ldrh r0, [r4, 0x4]\n\ + subs r1, 0x1\n\ + ands r1, r0\n\ + ldrh r0, [r4, 0x2]\n\ + subs r0, r1\n\ + movs r1, 0xFF\n\ + ands r0, r1\n\ + strh r0, [r4, 0x2]\n\ + b _0810EA1C\n\ + .pool\n\ +_0810EA0C:\n\ + ldrh r0, [r4, 0x4]\n\ + ldr r1, =0x00007fff\n\ + ands r1, r0\n\ + ldrh r2, [r4, 0x2]\n\ + adds r1, r2\n\ + movs r0, 0xFF\n\ + ands r1, r0\n\ + strh r1, [r4, 0x2]\n\ +_0810EA1C:\n\ + movs r0, 0x22\n\ + ldrsh r1, [r5, r0]\n\ + movs r2, 0x26\n\ + ldrsh r0, [r5, r2]\n\ + adds r1, r0\n\ + ldrh r0, [r4, 0xE]\n\ + lsrs r0, 1\n\ + cmp r1, r0\n\ + blt _0810EA36\n\ + movs r0, 0\n\ + strh r0, [r5, 0x2E]\n\ + ldr r0, =sub_810E2C8\n\ + str r0, [r5, 0x1C]\n\ +_0810EA36:\n\ + pop {r3,r4}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + "); +} +#endif + +void sub_810EA4C(struct Sprite *sprite) +{ + sprite->oam.priority = GetBattlerSpriteBGPriority(gBattleAnimTarget); + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 3); + sprite->callback = TranslateAnimSpriteToTargetMonLocation; +} + +void sub_810EAA0(struct Sprite * sprite) +{ + u16 arg; + u8 mult; + + if (!gBattleAnimArgs[2]) + InitSpritePosToAnimAttacker(sprite, 0); + else + InitSpritePosToAnimTarget(sprite, FALSE); + + if ((!gBattleAnimArgs[2] && !GetBattlerSide(gBattleAnimAttacker)) + || (gBattleAnimArgs[2] == 1 && !GetBattlerSide(gBattleAnimTarget))) + { + sprite->pos1.x += 8; + } + + SeekSpriteAnim(sprite, gBattleAnimArgs[4]); + sprite->pos1.x -= 32; + sprite->data[1] = 0x0ccc; + + arg = gBattleAnimArgs[4]; + mult = 12; + sprite->pos2.x += mult * arg; + sprite->data[0] = arg; + sprite->data[7] = gBattleAnimArgs[3]; + sprite->callback = sub_810EB40; +} + +void sub_810EB40(struct Sprite *sprite) +{ + sprite->pos2.x += sprite->data[1] >> 8; + + if (++sprite->data[0] == 6) + { + sprite->data[0] = 0; + sprite->pos2.x = 0; + StartSpriteAnim(sprite, 0); + } + + if (--sprite->data[7] == -1) + DestroyAnimSprite(sprite); +} + +void sub_810EB88(u8 task) +{ + if (!(gTasks[task].data[0] % 32)) + { + gAnimVisualTaskCount++; + + gBattleAnimArgs[0] = Sin(gTasks[task].data[0], -13); + gBattleAnimArgs[1] = Cos(gTasks[task].data[0], -13); + gBattleAnimArgs[2] = 1; + gBattleAnimArgs[3] = 3; + + CreateSpriteAndAnimate(&gUnknown_085973E8, + GetBattlerSpriteCoord(gBattleAnimTarget, 2), + GetBattlerSpriteCoord(gBattleAnimTarget, 3), + 3); + } + + gTasks[task].data[0] += 8; + + if (gTasks[task].data[0] > 255) + DestroyAnimVisualTask(task); +} + +void sub_810EC34(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + InitSpritePosToAnimAttacker(sprite, 1); + gSprites[GetAnimBattlerSpriteId(0)].invisible = 1; + ++sprite->data[0]; + break; + case 1: + if (sprite->affineAnimEnded) + DestroyAnimSprite(sprite); + break; + } +} + +void sub_810EC94(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimTarget, 1); + sprite->pos2.y = -sprite->pos1.y - 32; + sprite->data[0]++; + break; + case 1: + sprite->pos2.y += 10; + if (sprite->pos2.y >= 0) + ++sprite->data[0]; + break; + case 2: + sprite->pos2.y -= 10; + if (sprite->pos1.y + sprite->pos2.y < -32) + { + gSprites[GetAnimBattlerSpriteId(0)].invisible = 0; + DestroyAnimSprite(sprite); + } + break; + } +} + +void sub_810ED28(struct Sprite *sprite) +{ + InitSpritePosToAnimAttacker(sprite, 1); + sprite->data[0] = gBattleAnimArgs[2]; + sprite->data[1] = gBattleAnimArgs[3]; + sprite->callback = sub_810ED70; + gSprites[GetAnimBattlerSpriteId(0)].invisible = 1; +} + +void sub_810ED70(struct Sprite *sprite) +{ + if (sprite->data[0] > 0) + { + sprite->data[0]--; + } + else if (sprite->pos1.y + sprite->pos2.y > -32) + { + sprite->data[2] += sprite->data[1]; + sprite->pos2.y -= (sprite->data[2] >> 8); + } + else + { + sprite->invisible = 1; + if (sprite->data[3]++ > 20) + sprite->callback = sub_810EDD0; + } +} + +void sub_810EDD0(struct Sprite *sprite) +{ + sprite->pos2.y += sprite->data[2] >> 8; + + if (sprite->pos1.y + sprite->pos2.y > -32) + sprite->invisible = 0; + + if (sprite->pos2.y > 0) + DestroyAnimSprite(sprite); +} + +void sub_810EE14(struct Sprite *sprite) +{ + u32 matrixNum; + int t1, t2; + + switch (sprite->data[0]) + { + case 0: + if (!gBattleAnimArgs[0]) + { + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 0); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 1); + } + else + { + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimTarget, 0); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimTarget, 1); + } + + sprite->data[1] = 512; + + TrySetSpriteRotScale(sprite, 0, 256, sprite->data[1], 0); + sprite->data[0]++; + break; + case 1: + if (sprite->data[2] <= 11) + sprite->data[1] -= 40; + else + sprite->data[1] += 40; + + sprite->data[2]++; + + TrySetSpriteRotScale(sprite, 0, 256, sprite->data[1], 0); + + matrixNum = sprite->oam.matrixNum; + + t1 = 15616; + t2 = t1 / gOamMatrices[matrixNum].d + 1; + + if (t2 > 128) + t2 = 128; + + t2 = (64 - t2) / 2; + sprite->pos2.y = t2; + + if (sprite->data[2] == 24) + { + sub_80A749C(sprite); + DestroyAnimSprite(sprite); + } + break; + } +} + +void sub_810EEF8(struct Sprite *sprite) +{ + int v1 = 0x1ff & Random2(); + int v2 = 0x7f & Random2(); + + if (v1 % 2) + sprite->data[0] = 736 + v1; + else + sprite->data[0] = 736 - v1; + + if (v2 % 2) + sprite->data[1] = 896 + v2; + else + sprite->data[1] = 896 - v2; + + sprite->data[2] = gBattleAnimArgs[0]; + + if (sprite->data[2]) + sprite->oam.matrixNum = 8; + + if (gBattleAnimArgs[1] == 0) + { + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 0); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 1) + 32; + } + else + { + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimTarget, 0); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimTarget, 1) + 32; + } + + sprite->callback = sub_810EFA8; +} + +void sub_810EFA8(struct Sprite *sprite) +{ + if (sprite->data[2] == 0) + { + sprite->pos2.x += sprite->data[0] >> 8; + sprite->pos2.y -= sprite->data[1] >> 8; + } + else + { + sprite->pos2.x -= sprite->data[0] >> 8; + sprite->pos2.y -= sprite->data[1] >> 8; + } + + sprite->data[0] = sprite->data[0]; + sprite->data[1] -= 32; + + if (sprite->data[0] < 0) + sprite->data[0] = 0; + + if (++sprite->data[3] == 31) + DestroyAnimSprite(sprite); +} + +void sub_810F004(struct Sprite *sprite) +{ + sprite->data[6] = 0; + sprite->data[7] = 64; + sprite->callback = sub_810F018; +} + +void sub_810F018(struct Sprite *sprite) +{ + switch (sprite->data[0]) + { + case 0: + if (++sprite->data[1] > 8) + { + sprite->data[1] = 0; + sprite->invisible ^= 1; + if (++sprite->data[2] > 5 && sprite->invisible) + sprite->data[0]++; + } + break; + case 1: + DestroyAnimSprite(sprite); + break; + } +} + +void sub_810F084(struct Sprite *sprite) +{ + u16 rotation; + s16 posx = sprite->pos1.x; + s16 posy = sprite->pos1.y; + + sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2); + sprite->pos1.y = GetBattlerSpriteCoord(gBattleAnimAttacker, 3); + + sprite->data[4] = sprite->pos1.x << 4; + sprite->data[5] = sprite->pos1.y << 4; + + sprite->data[6] = ((posx - sprite->pos1.x) << 4) / 12; + sprite->data[7] = ((posy - sprite->pos1.y) << 4) / 12; + + rotation = ArcTan2Neg(posx - sprite->pos1.x, posy - sprite->pos1.y); + rotation += 49152; + + TrySetSpriteRotScale(sprite, 1, 0x100, 0x100, rotation); + + sprite->callback = sub_810F140; +} + +void sub_810F140(struct Sprite *sprite) +{ + sprite->data[4] += sprite->data[6]; + sprite->data[5] += sprite->data[7]; + + sprite->pos1.x = sprite->data[4] >> 4; + sprite->pos1.y = sprite->data[5] >> 4; + + if (sprite->pos1.x > 285 || sprite->pos1.x < -45 + || sprite->pos1.y > 157 || sprite->pos1.y < -45) + DestroySpriteAndMatrix(sprite); +} + +void unref_sub_810F184(u8 taskId) +{ + if (gBattleAnimArgs[0] == 0) + { + u8 spriteId = GetAnimBattlerSpriteId(0); + gSprites[spriteId].invisible = 1; + } + else + { + u8 spriteId = GetAnimBattlerSpriteId(0); + gSprites[spriteId].invisible = 0; + } + DestroyAnimVisualTask(taskId); +} diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 0db546c4d..fff93c3c7 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -1090,7 +1090,7 @@ static void ShowAndPrintWindows(void) for (i = 0; i < WINDOW_COUNT; i++) { PutWindowTilemap(i); - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); } x = GetStringCenterAlignXOffset(1, gText_SymbolsEarned, 96); @@ -1116,7 +1116,7 @@ static void ShowAndPrintWindows(void) static void PrintAreaDescription(u8 cursorArea) { - FillWindowPixelBuffer(WINDOW_DESCRIPTION, 0); + FillWindowPixelBuffer(WINDOW_DESCRIPTION, PIXEL_FILL(0)); if (cursorArea == CURSOR_AREA_RECORD && !sPassData->hasBattleRecord) AddTextPrinterParameterized3(WINDOW_DESCRIPTION, 1, 2, 0, sTextColors[1], 0, sPassAreaDescriptions[0]); else if (cursorArea != CURSOR_AREA_NOTHING) @@ -1656,7 +1656,7 @@ static void PrintOnFrontierMap(void) for (i = 0; i < MAP_WINDOW_COUNT; i++) { PutWindowTilemap(i); - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); } for (i = 0; i < NUM_FRONTIER_FACILITIES; i++) @@ -1698,7 +1698,7 @@ static void HandleFrontierMapCursorMove(u8 direction) StartSpriteAnim(sMapData->mapIndicatorSprite, sMapLandmarks[sMapData->cursorPos].animNum); sMapData->mapIndicatorSprite->pos1.x = sMapLandmarks[sMapData->cursorPos].x; sMapData->mapIndicatorSprite->pos1.y = sMapLandmarks[sMapData->cursorPos].y; - FillWindowPixelBuffer(MAP_WINDOW_DESCRIPTION, 0); + FillWindowPixelBuffer(MAP_WINDOW_DESCRIPTION, PIXEL_FILL(0)); AddTextPrinterParameterized3(MAP_WINDOW_DESCRIPTION, 1, 4, 0, sTextColors[0], 0, sMapLandmarks[sMapData->cursorPos].description); for (i = 0; i < 3; i++) diff --git a/src/frontier_util.c b/src/frontier_util.c index 6fcbd4ffb..bce7b926f 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -35,8 +35,7 @@ #include "constants/moves.h" #include "constants/items.h" #include "constants/event_objects.h" - -extern u8 gSelectedOrderFromParty[]; +#include "party_menu.h" struct FrontierBrainMon { @@ -48,8 +47,6 @@ struct FrontierBrainMon u16 moves[4]; }; -extern void sub_81B8558(void); - // This file's functions. static void sub_81A17A0(void); static void sub_81A1830(void); @@ -1044,8 +1041,8 @@ static void TowerPrintPrevOrCurrentStreak(u8 battleMode, u8 lvlMode, u8 x1, u8 x static void ShowTowerResultsWindow(u8 battleMode) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); if (battleMode == FRONTIER_MODE_SINGLES) StringExpandPlaceholders(gStringVar4, gText_SingleBattleRoomResults); else if (battleMode == FRONTIER_MODE_DOUBLES) @@ -1115,8 +1112,8 @@ static void DomePrintPrevOrCurrentStreak(u8 battleMode, u8 lvlMode, u8 x1, u8 x2 static void ShowDomeResultsWindow(u8 battleMode) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); if (battleMode == FRONTIER_MODE_SINGLES) StringExpandPlaceholders(gStringVar4, gText_SingleBattleTourneyResults); else @@ -1191,8 +1188,8 @@ static void PalacePrintPrevOrCurrentStreak(u8 battleMode, u8 lvlMode, u8 x1, u8 static void ShowPalaceResultsWindow(u8 battleMode) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); if (battleMode == FRONTIER_MODE_SINGLES) StringExpandPlaceholders(gStringVar4, gText_SingleBattleHallResults); else @@ -1247,8 +1244,8 @@ static void PikePrintPrevOrCurrentStreak(u8 lvlMode, u8 x1, u8 x2, u8 y) static void ShowPikeResultsWindow(void) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); StringExpandPlaceholders(gStringVar4, gText_BattleChoiceResults); PrintAligned(gStringVar4, 0); AddTextPrinterParameterized(gRecordsWindowId, 1, gText_Lv502, 8, 33, TEXT_SPEED_FF, NULL); @@ -1309,8 +1306,8 @@ static void ArenaPrintPrevOrCurrentStreak(u8 lvlMode, u8 x1, u8 x2, u8 y) static void ShowArenaResultsWindow(void) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); PrintHyphens(10); StringExpandPlaceholders(gStringVar4, gText_SetKOTourneyResults); PrintAligned(gStringVar4, 2); @@ -1395,8 +1392,8 @@ static void FactoryPrintPrevOrCurrentStreak(u8 battleMode, u8 lvlMode, u8 x1, u8 static void ShowFactoryResultsWindow(u8 battleMode) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); if (battleMode == FRONTIER_MODE_SINGLES) StringExpandPlaceholders(gStringVar4, gText_BattleSwapSingleResults); else @@ -1460,8 +1457,8 @@ static void PyramidPrintPrevOrCurrentStreak(u8 lvlMode, u8 x1, u8 x2, u8 y) static void ShowPyramidResultsWindow(void) { gRecordsWindowId = AddWindow(&gUnknown_08611C74); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); StringExpandPlaceholders(gStringVar4, gText_BattleQuestResults); PrintAligned(gStringVar4, 2); AddTextPrinterParameterized(gRecordsWindowId, 1, gText_Lv502, 8, 49, TEXT_SPEED_FF, NULL); @@ -1483,8 +1480,8 @@ static void ShowLinkContestResultsWindow(void) s32 x; gRecordsWindowId = AddWindow(&gUnknown_08611C7C); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); StringExpandPlaceholders(gStringVar4, gText_LinkContestResults); x = GetStringCenterAlignXOffset(1, gStringVar4, 208); @@ -2353,8 +2350,8 @@ static void PrintHallRecords(s32 hallFacilityId, s32 lvlMode) void ShowRankingHallRecordsWindow(void) { gRecordsWindowId = AddWindow(&gUnknown_08611C84); - NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); PrintHallRecords(gSpecialVar_0x8005, FRONTIER_LVL_50); PutWindowTilemap(gRecordsWindowId); CopyWindowToVram(gRecordsWindowId, 3); @@ -2362,7 +2359,7 @@ void ShowRankingHallRecordsWindow(void) void ScrollRankingHallRecordsWindow(void) { - FillWindowPixelBuffer(gRecordsWindowId, 0x11); + FillWindowPixelBuffer(gRecordsWindowId, PIXEL_FILL(1)); PrintHallRecords(gSpecialVar_0x8005, FRONTIER_LVL_OPEN); CopyWindowToVram(gRecordsWindowId, 2); } diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 3f217b782..2c31dba01 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -66,8 +66,6 @@ extern struct MusicPlayerInfo gMPlayInfo_BGM; #define HALL_OF_FAME_MAX_TEAMS 50 -extern void ReturnFromHallOfFamePC(void); - // this file's functions static void ClearVramOamPltt_LoadHofPal(void); static void sub_8174F70(void); @@ -490,7 +488,7 @@ static void Task_Hof_InitTeamSaveData(u8 taskId) } *lastSavedTeam = *sHofMonPtr; - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized2(0, 1, gText_SavingDontTurnOffPower, 0, NULL, 2, 1, 3); CopyWindowToVram(0, 3); gTasks[taskId].func = Task_Hof_TrySaveData; @@ -570,7 +568,7 @@ static void Task_Hof_DisplayMon(u8 taskId) gSprites[spriteId].tSpecies = currMon->species; gSprites[spriteId].callback = SpriteCB_GetOnScreenAndAnimate; gTasks[taskId].tMonSpriteId(currMonId) = spriteId; - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); gTasks[taskId].func = Task_Hof_PrintMonInfoAfterAnimating; } @@ -649,7 +647,7 @@ static void sub_8173DC0(u8 taskId) gSprites[gTasks[taskId].tMonSpriteId(i)].oam.priority = 1; } BeginNormalPaletteFade(sUnknown_0203BCD4, 0, 12, 12, RGB(16, 29, 24)); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); CopyWindowToVram(0, 3); gTasks[taskId].tFrameCount = 7; gTasks[taskId].func = sub_8173EA4; @@ -697,7 +695,7 @@ static void Task_Hof_WaitAndPrintPlayerInfo(u8 taskId) { FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); HallOfFame_PrintPlayerInfo(1, 2); - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized2(0, 1, gText_LeagueChamp, 0, NULL, 2, 1, 3); CopyWindowToVram(0, 3); gTasks[taskId].func = Task_Hof_ExitOnKeyPressed; @@ -1066,7 +1064,7 @@ static void Task_HofPC_HandleExit(u8 taskId) static void Task_HofPC_PrintDataIsCorrupted(u8 taskId) { sub_8198180(gText_UnkCtrlF800Exit, 8, TRUE); - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized2(0, 1, gText_HOFCorrupted, 0, NULL, 2, 1, 3); CopyWindowToVram(0, 3); gTasks[taskId].func = Task_HofPC_ExitOnButtonPress; @@ -1086,7 +1084,7 @@ static void Task_HofPC_ExitOnButtonPress(u8 taskId) static void HallOfFame_PrintWelcomeText(u8 unusedPossiblyWindowId, u8 unused2) { - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); AddTextPrinterParameterized3(0, 1, GetStringCenterAlignXOffset(1, gText_WelcomeToHOF, 0xD0), 1, sUnknown_085E5388, 0, gText_WelcomeToHOF); CopyWindowToVram(0, 3); @@ -1099,7 +1097,7 @@ static void HallOfFame_PrintMonInfo(struct HallofFameMon* currMon, u8 unused1, u s32 dexNumber; s32 width; - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); // dex number @@ -1180,9 +1178,9 @@ static void HallOfFame_PrintPlayerInfo(u8 unused1, u8 unused2) u32 width; u16 trainerId; - FillWindowPixelBuffer(1, 0x11); + FillWindowPixelBuffer(1, PIXEL_FILL(1)); PutWindowTilemap(1); - SetWindowBorderStyle(1, FALSE, 0x21D, 0xD); + DrawStdFrameWithCustomTileAndPalette(1, FALSE, 0x21D, 0xD); AddTextPrinterParameterized3(1, 1, 0, 1, sUnknown_085E538C, -1, gText_Name); width = GetStringRightAlignXOffset(1, gSaveBlock2Ptr->playerName, 0x70); diff --git a/src/hof_pc.c b/src/hof_pc.c index 2cea5540a..d76f04372 100644 --- a/src/hof_pc.c +++ b/src/hof_pc.c @@ -7,10 +7,6 @@ #include "script_menu.h" #include "task.h" -extern void Overworld_PlaySpecialMapMusic(void); -extern bool16 ScrSpecial_CreatePCMenu(void); -extern void ScriptMenu_DisplayPCStartupPrompt(void); - static void ReshowPCMenuAfterHallOfFamePC(void); static void Task_WaitForPaletteFade(u8); @@ -21,30 +21,29 @@ struct HailStruct { }; static void sub_810B6C4(struct Sprite *); -extern void sub_810B848(struct Sprite *); -extern void AnimIcePunchSwirlingParticle(struct Sprite *); -extern void AnimIceBeamParticle(struct Sprite *); -extern void AnimIceEffectParticle(struct Sprite *); -extern void AnimFlickerIceEffectParticle(struct Sprite *); -extern void AnimSwirlingSnowball_Step1(struct Sprite *); -extern void AnimSwirlingSnowball_Step2(struct Sprite *); -extern void AnimSwirlingSnowball_Step3(struct Sprite *); -extern void AnimSwirlingSnowball_End(struct Sprite *); -extern void AnimMoveParticleBeyondTarget(struct Sprite *); -extern void AnimWiggleParticleTowardsTarget(struct Sprite *); -extern void AnimWaveFromCenterOfTarget(struct Sprite *); -extern void InitSwirlingFogAnim(struct Sprite *); -extern void AnimSwirlingFogAnim(struct Sprite *); -extern void AnimThrowMistBall(struct Sprite *); -extern void InitPoisonGasCloudAnim(struct Sprite *); -extern void MovePoisonGasCloud(struct Sprite *); -extern void AnimHailBegin(struct Sprite *); -extern void AnimHailContinue(struct Sprite *); -extern void sub_80A8EE4(struct Sprite *); -extern void InitIceBallAnim(struct Sprite *); -extern void AnimThrowIceBall(struct Sprite *); -extern void InitIceBallParticle(struct Sprite *); -extern void AnimIceBallParticle(struct Sprite *); +void sub_810B848(struct Sprite *); +void AnimIcePunchSwirlingParticle(struct Sprite *); +void AnimIceBeamParticle(struct Sprite *); +void AnimIceEffectParticle(struct Sprite *); +void AnimFlickerIceEffectParticle(struct Sprite *); +void AnimSwirlingSnowball_Step1(struct Sprite *); +void AnimSwirlingSnowball_Step2(struct Sprite *); +void AnimSwirlingSnowball_Step3(struct Sprite *); +void AnimSwirlingSnowball_End(struct Sprite *); +void AnimMoveParticleBeyondTarget(struct Sprite *); +void AnimWiggleParticleTowardsTarget(struct Sprite *); +void AnimWaveFromCenterOfTarget(struct Sprite *); +void InitSwirlingFogAnim(struct Sprite *); +void AnimSwirlingFogAnim(struct Sprite *); +void AnimThrowMistBall(struct Sprite *); +void InitPoisonGasCloudAnim(struct Sprite *); +void MovePoisonGasCloud(struct Sprite *); +void AnimHailBegin(struct Sprite *); +void AnimHailContinue(struct Sprite *); +void InitIceBallAnim(struct Sprite *); +void AnimThrowIceBall(struct Sprite *); +void InitIceBallParticle(struct Sprite *); +void AnimIceBallParticle(struct Sprite *); void AnimTask_Haze2(u8); void AnimTask_OverlayFogTiles(u8); void AnimTask_Hail2(u8); diff --git a/src/item.c b/src/item.c index 71c2dc0f7..0e13ddf4c 100644 --- a/src/item.c +++ b/src/item.c @@ -539,8 +539,8 @@ bool8 RemoveBagItem(u16 itemId, u16 count) if (CurrentMapIsSecretBase() == TRUE) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x200); - VarSet(VAR_0x40ED, itemId); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x200); + VarSet(VAR_SECRET_BASE_LAST_ITEM_USED, itemId); } var = GetItemListPosition(pocket); diff --git a/src/item_menu.c b/src/item_menu.c index 43f2afce3..5738757bd 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -8,6 +8,7 @@ #include "bg.h" #include "constants/items.h" #include "constants/songs.h" +#include "data2.h" #include "decompress.h" #include "event_data.h" #include "event_object_movement.h" @@ -140,7 +141,6 @@ void unknown_ItemMenu_Confirm2(u8 taskId); void unknown_item_menu_type(u8 taskId); void item_menu_type_2(u8 taskId); void display_sell_item_ask_str(u8 taskId); -void unknown_ItemMenu_Confirm(u8 taskId); void display_deposit_item_ask_str(u8 taskId); void item_menu_type_b(u8 taskId); void BagMenuActuallyToss(u8 taskId); @@ -446,7 +446,6 @@ EWRAM_DATA u16 gSpecialVar_ItemId = 0; static EWRAM_DATA struct TempWallyStruct *gUnknown_0203CE80 = 0; extern u8 *const gPocketNamesStringsTable[]; -extern const u8 gMoveNames[][0xD]; extern u8* gReturnToXStringsTable[]; extern const u8 EventScript_2736B3[]; extern const u16 gUnknown_0860F074[]; @@ -476,7 +475,7 @@ void CB2_ChooseBerry(void) GoToBagMenu(RETURN_LOCATION_FIELD_2, BERRIES_POCKET, CB2_ReturnToFieldContinueScript); } -void sub_81AABF0(void(*callback)(void)) +void sub_81AABF0(void (*callback)(void)) { GoToBagMenu(RETURN_LOCATION_FIELD_3, BERRIES_POCKET, callback); } @@ -884,7 +883,7 @@ void bag_menu_print_description_box_text(int a) StringExpandPlaceholders(gStringVar4, gText_ReturnToVar1); str = gStringVar4; } - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, str, 3, 1, 0, 0, 0, 0); } @@ -896,7 +895,7 @@ void bag_menu_print_cursor_(u8 a, u8 b) void bag_menu_print_cursor(u8 a, u8 b) { if (b == 0xFF) - FillWindowPixelRect(0, 0, 0, a, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); + FillWindowPixelRect(0, PIXEL_FILL(0), 0, a, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); else bag_menu_print(0, 1, gText_SelectorArrow2, 0, a, 0, 0, 0, b); @@ -1028,7 +1027,7 @@ void DisplayItemMessage(u8 taskId, u8 fontId, const u8 *str, void ( *callback)(u s16* data = gTasks[taskId].data; data[10] = AddItemMessageWindow(4); - FillWindowPixelBuffer(data[10], 17); + FillWindowPixelBuffer(data[10], PIXEL_FILL(1)); DisplayMessageAndContinueTask(taskId, data[10], 10, 13, fontId, GetPlayerTextSpeedDelay(), str, callback); schedule_bg_copy_tilemap_to_vram(1); } @@ -1293,7 +1292,7 @@ void bag_menu_swap_items(u8 taskId) gUnknown_0203CE54->unk81A = data[1]; CopyItemName(BagGetItemIdByPocketPosition(gUnknown_0203CE58.pocket + 1, data[1]), gStringVar1); StringExpandPlaceholders(gStringVar4, gText_MoveVar1Where); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); sub_80D4FEC(data[1]); sub_81AB89C(); @@ -1505,7 +1504,7 @@ void sub_81AC644(u8 unused) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_Var1IsSelected); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); } if (gUnknown_0203CE54->unk828 == 1) @@ -1646,7 +1645,7 @@ void ItemMenu_UseOutOfBattle(u8 taskId) bag_menu_print_there_is_no_pokemon(taskId); else { - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); schedule_bg_copy_tilemap_to_vram(0); if (gUnknown_0203CE58.pocket != BERRIES_POCKET) ItemId_GetFieldFunc(gSpecialVar_ItemId)(taskId); @@ -1670,7 +1669,7 @@ void ItemMenu_Toss(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_TossHowManyVar1s); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); sub_81ABC3C(7); gTasks[taskId].func = Task_ChooseHowManyToToss; @@ -1684,7 +1683,7 @@ void BagMenuConfirmToss(u8 taskId) CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[8], 0, 3); StringExpandPlaceholders(gStringVar4, gText_ConfirmTossItems); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); bag_menu_yes_no(taskId, 5, &gUnknown_08614084); } @@ -1727,7 +1726,7 @@ void BagMenuActuallyToss(u8 taskId) CopyItemName(gSpecialVar_ItemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[8], 0, 3); StringExpandPlaceholders(gStringVar4, gText_ThrewAwayVar2Var1s); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); gTasks[taskId].func = Task_ActuallyToss; } @@ -2043,7 +2042,7 @@ void display_deposit_item_ask_str(u8 taskId) { CopyItemName(gSpecialVar_ItemId, gStringVar1); StringExpandPlaceholders(gStringVar4, gText_DepositHowManyVar1); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); bag_menu_print(1, 1, gStringVar4, 3, 1, 0, 0, 0, 0); sub_81ABC3C(7); gTasks[taskId].func = sub_81ADA7C; @@ -2078,7 +2077,7 @@ void sub_81ADB14(u8 taskId) { s16* data = gTasks[taskId].data; - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); if (ItemId_GetImportance(gSpecialVar_ItemId)) { bag_menu_print(1, 1, gText_CantStoreImportantItems, 3, 1, 0, 0, 0, 0); @@ -2244,7 +2243,7 @@ void bag_menu_print_pocket_names(const u8 *pocketName1, const u8 *pocketName2) window.width = 16; window.height = 2; windowId = AddWindow(&window); - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); offset = GetStringCenterAlignXOffset(1, pocketName1, 0x40); bag_menu_print(windowId, 1, pocketName1, offset, 1, 0, 0, -1, 1); if (pocketName2) @@ -2283,7 +2282,7 @@ void setup_bag_menu_textboxes(void) LoadPalette(&gUnknown_0860F074, 0xF0, 0x20); for (i = 0; i < 3; i++) { - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); PutWindowTilemap(i); } schedule_bg_copy_tilemap_to_vram(0); @@ -2306,7 +2305,7 @@ u8 bag_menu_add_window(u8 a) if (*ptr == 0xFF) { *ptr = AddWindow(&gUnknown_086141AC[a]); - SetWindowBorderStyle(*ptr, 0, 1, 14); + DrawStdFrameWithCustomTileAndPalette(*ptr, 0, 1, 14); schedule_bg_copy_tilemap_to_vram(1); } return *ptr; @@ -2317,7 +2316,7 @@ void bag_menu_remove_window(u8 a) u8 *ptr = &gUnknown_0203CE54->windowPointers[a]; if (*ptr != 0xFF) { - sub_8198070(*ptr, 0); + ClearStdWindowAndFrameToTransparent(*ptr, 0); ClearWindowTilemap(*ptr); RemoveWindow(*ptr); schedule_bg_copy_tilemap_to_vram(1); @@ -2338,7 +2337,8 @@ void bag_menu_RemoveBagItem_message_window(u8 a) u8 *ptr = &gUnknown_0203CE54->windowPointers[a]; if (*ptr != 0xFF) { - sub_8197DF8(*ptr, 0); + ClearDialogWindowAndFrameToTransparent(*ptr, FALSE); + // This ClearWindowTilemap call is redundant, since ClearDialogWindowAndFrameToTransparent already calls it. ClearWindowTilemap(*ptr); RemoveWindow(*ptr); schedule_bg_copy_tilemap_to_vram(1); @@ -2366,7 +2366,7 @@ void bag_menu_remove_money_window(void) void bag_menu_prepare_tmhm_move_window(void) { - FillWindowPixelBuffer(3, 0); + FillWindowPixelBuffer(3, PIXEL_FILL(0)); blit_move_info_icon(3, 19, 0, 0); blit_move_info_icon(3, 20, 0, 12); blit_move_info_icon(3, 21, 0, 24); @@ -2380,7 +2380,7 @@ void PrintTMHMMoveData(u16 itemId) u16 moveId; const u8* text; - FillWindowPixelBuffer(4, 0); + FillWindowPixelBuffer(4, PIXEL_FILL(0)); if (itemId == ITEM_NONE) { for (i = 0; i < 4; i++) diff --git a/src/item_use.c b/src/item_use.c index 97d6292c4..e646a18ee 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -8,13 +8,15 @@ #include "coins.h" #include "data2.h" #include "event_data.h" -#include "fieldmap.h" #include "event_object_movement.h" +#include "fieldmap.h" +#include "field_effect.h" #include "field_player_avatar.h" #include "field_screen_effect.h" #include "field_weather.h" #include "item.h" #include "item_menu.h" +#include "item_use.h" #include "mail.h" #include "main.h" #include "menu.h" @@ -37,31 +39,15 @@ #include "constants/items.h" #include "constants/songs.h" #include "constants/vars.h" +#include "event_obj_lock.h" -extern void unknown_ItemMenu_Confirm(u8 taskId); -extern void sub_81C5B14(u8 taskId); -extern void ScriptUnfreezeEventObjects(void); -extern void ItemUseOutOfBattle_TMHM(u8 a); -extern void ItemUseOutOfBattle_EvolutionStone(u8 b); -extern bool8 IsPlayerFacingSurfableFishableWater(void); -extern bool8 sub_81221AC(void); extern u8 Route102_EventScript_274482[]; extern u8 Route102_EventScript_2744C0[]; extern u8 BattleFrontier_OutsideEast_EventScript_242CFC[]; -extern int sub_80247BC(void); -extern struct MapHeader* mapconnection_get_mapheader(struct MapConnection *connection); -extern void SetUpItemUseCallback(u8 taskId); -extern void ItemUseCB_Medicine(u8, TaskFunc); -extern void bag_menu_yes_no(u8, u8, const struct YesNoFuncTable*); -extern void sub_81C5924(void); -extern void sub_81C59BC(void); -extern void sub_81AB9A8(u8); -extern void StartEscapeRopeFieldEffect(void); -extern u8* sub_806CF78(u16); -extern void sub_81B89F0(void); -extern u8 GetItemEffectType(u16); -extern struct MapConnection *sub_8088A8C(s16, s16); +extern s32 sub_80247BC(void); + +void SetUpItemUseCallback(u8 taskId); void MapPostLoadHook_UseItem(void); void sub_80AF6D4(void); void Task_CallItemUseOnFieldCallback(u8 taskId); @@ -188,7 +174,7 @@ void DisplayCannotDismountBikeMessage(u8 taskId, bool8 isUsingRegisteredKeyItemO void CleanUpAfterFailingToUseRegisteredKeyItemOnField(u8 taskId) { - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); DestroyTask(taskId); ScriptUnfreezeEventObjects(); ScriptContext2_Disable(); @@ -350,7 +336,7 @@ void sub_80FD504(u8 taskId) void sub_80FD5CC(u8 taskId) { - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); ScriptUnfreezeEventObjects(); ScriptContext2_Disable(); DestroyTask(taskId); @@ -404,12 +390,12 @@ bool8 sub_80FD6D4(const struct MapEvents *events, s16 x, s16 y) bool8 sub_80FD730(struct MapConnection *connection, int x, int y) { - struct MapHeader *mapHeader; + u16 localX, localY; u32 localOffset; s32 localLength; - mapHeader = mapconnection_get_mapheader(connection); + struct MapHeader const *const mapHeader = mapconnection_get_mapheader(connection); switch (connection->direction) { diff --git a/src/learn_move.c b/src/learn_move.c index 7a6916013..879acff6d 100644 --- a/src/learn_move.c +++ b/src/learn_move.c @@ -498,7 +498,7 @@ static void LearnMoveMain(void) case 27: if (!sub_81D2C3C()) { - FillWindowPixelBuffer(3, 0x11); + FillWindowPixelBuffer(3, PIXEL_FILL(1)); if (sLearnMoveStruct2.showContestInfo == FALSE) { sLearnMoveStruct->state = 3; @@ -631,7 +631,7 @@ static void HideSpritesAndPrintTeachText(bool8 a) if (!a) { StringExpandPlaceholders(gStringVar4, gText_TeachWhichMoveToPkmn); - FillWindowPixelBuffer(3, 0x11); + FillWindowPixelBuffer(3, PIXEL_FILL(1)); AddTextPrinterParameterized(3, 1, gStringVar4, 0, 1, 0, NULL); } } @@ -695,7 +695,7 @@ static void ShowTeachMoveText(bool8 showContest) if (showContest == FALSE) { StringExpandPlaceholders(gStringVar4, gText_TeachWhichMoveToPkmn); - FillWindowPixelBuffer(3, 0x11); + FillWindowPixelBuffer(3, PIXEL_FILL(1)); AddTextPrinterParameterized(3, 1, gStringVar4, 0, 1, 0, NULL); } } diff --git a/src/link.c b/src/link.c index bec9dddc6..525d50d7c 100644 --- a/src/link.c +++ b/src/link.c @@ -28,7 +28,7 @@ #include "link.h" #include "link_rfu.h" -extern u16 gUnknown_03005DA8; +extern u16 gHeldKeyCodeToSend; // Static type declarations @@ -302,9 +302,9 @@ void LinkTestScreen(void) SetMainCallback2(CB2_LinkTest); } -void sub_8009628(u8 a0) +void SetLocalLinkPlayerId(u8 playerId) { - gLocalLinkPlayer.id = a0; + gLocalLinkPlayer.id = playerId; } static void InitLocalLinkPlayer(void) @@ -695,12 +695,12 @@ static void BuildSendCmd(u16 command) gSendCmd[0] = LINKCMD_0x5566; break; case LINKCMD_SEND_HELD_KEYS_2: - if (gUnknown_03005DA8 == 0 || gLinkTransferringData) + if (gHeldKeyCodeToSend == 0 || gLinkTransferringData) { break; } gSendCmd[0] = LINKCMD_SEND_HELD_KEYS_2; - gSendCmd[1] = gUnknown_03005DA8; + gSendCmd[1] = gHeldKeyCodeToSend; break; } } @@ -714,11 +714,11 @@ void sub_8009F18(void) gLinkCallback = sub_8009F70; } -bool32 sub_8009F3C(void) +bool32 IsSendingKeysToLink(void) { if (gWirelessCommType) { - return sub_800F7E4(); + return IsSendingKeysToRfu(); } if (gLinkCallback == sub_8009F70) { @@ -1142,7 +1142,7 @@ void ResetBlockReceivedFlag(u8 who) } } -void sub_800A620(void) +void CheckShouldAdvanceLinkState(void) { if ((gLinkStatus & LINK_STAT_MASTER) && EXTRACT_PLAYER_COUNT(gLinkStatus) > 1) { @@ -1327,7 +1327,9 @@ void sub_800AA04(u8 a0) } } -u8 sub_800AA48(void) +// The number of players when trading began. This is frequently compared against the +// current number of connected players to check if anyone dropped out. +u8 GetSavedPlayerCount(void) { return gSavedLinkPlayerCount; } @@ -1683,8 +1685,8 @@ static void sub_800B080(void) CopyToBgTilemapBuffer(1, gWirelessLinkDisplayTilemap, 0, 0); CopyBgTilemapBufferToVram(1); LoadPalette(gWirelessLinkDisplayPal, 0, 0x20); - FillWindowPixelBuffer(0, 0x00); - FillWindowPixelBuffer(2, 0x00); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized3(0, 3, 2, 6, gUnknown_082ED224, 0, gText_CommErrorEllipsis); AddTextPrinterParameterized3(2, 3, 2, 1, gUnknown_082ED224, 0, gText_MoveCloserToLinkPartner); PutWindowTilemap(0); @@ -1696,8 +1698,8 @@ static void sub_800B080(void) static void sub_800B138(void) { LoadBgTiles(0, g2BlankTilesGfx, 0x20, 0); - FillWindowPixelBuffer(1, 0x00); - FillWindowPixelBuffer(2, 0x00); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized3(1, 3, 2, 0, gUnknown_082ED224, 0, gText_CommErrorCheckConnections); PutWindowTilemap(1); PutWindowTilemap(2); @@ -1849,7 +1851,7 @@ bool8 HandleLinkConnection(void) r5 = sub_8010F1C(); if (sub_808766C() == TRUE) { - if (r4 == TRUE || sub_800F0B8() || r5) + if (r4 == TRUE || IsRfuRecvQueueEmpty() || r5) { return TRUE; } @@ -1882,18 +1884,18 @@ void sub_800B4C0(void) } } -u32 sub_800B4DC(void) +u32 GetLinkRecvQueueLength(void) { if (gWirelessCommType != 0) { - return sub_80124D4(); + return GetRfuRecvQueueLength(); } return gLink.recvQueue.count; } -bool8 sub_800B504(void) +bool32 sub_800B504(void) { - if (sub_800B4DC() > 2) + if (GetLinkRecvQueueLength() > 2) { return TRUE; } diff --git a/src/link_rfu.c b/src/link_rfu.c index 4ad2a5169..d80ff2ae9 100644 --- a/src/link_rfu.c +++ b/src/link_rfu.c @@ -17,9 +17,9 @@ #include "text.h" #include "constants/species.h" #include "save.h" +#include "rom_8011DC0.h" -extern u16 gUnknown_03005DA8; -extern void nullsub_89(u8 taskId); +extern u16 gHeldKeyCodeToSend; struct UnkRfuStruct_1 gUnknown_03004140; struct UnkRfuStruct_2 gUnknown_03005000; @@ -2991,7 +2991,7 @@ static void sub_800F048(void) } } -bool32 sub_800F0B8(void) +bool32 IsRfuRecvQueueEmpty(void) { s32 i; s32 j; @@ -3212,7 +3212,7 @@ bool32 sub_800F4F0(void) for (i = 0; i < CMD_LENGTH - 1; i++) gSendCmd[i] = 0; } - return sub_800F0B8(); + return IsRfuRecvQueueEmpty(); } void sub_800F638(u8 unused, u32 flags) @@ -3272,10 +3272,12 @@ u8 sub_800F74C(const u8 *a0) void rfu_func_080F97B8(void) { - if (gReceivedRemoteLinkPlayers && gUnknown_03005DA8 && gLinkTransferringData != 1) + if (gReceivedRemoteLinkPlayers + && gHeldKeyCodeToSend != LINK_KEY_CODE_NULL + && gLinkTransferringData != TRUE) { gUnknown_03000D78[0]++; - gUnknown_03005DA8 |= (gUnknown_03000D78[0] << 8); + gHeldKeyCodeToSend |= (gUnknown_03000D78[0] << 8); sub_800FD14(0xbe00); } } @@ -3285,7 +3287,7 @@ struct UnkLinkRfuStruct_02022B14 *sub_800F7DC(void) return &gUnknown_02022B14; } -bool32 sub_800F7E4(void) +bool32 IsSendingKeysToRfu(void) { return gUnknown_03005000.unk_00 == rfu_func_080F97B8; } @@ -3509,7 +3511,7 @@ void sub_800FD14(u16 command) gSendCmd[1 + i] = gUnknown_03005000.unk_f2[i]; break; case 0xbe00: - gSendCmd[1] = gUnknown_03005DA8; + gSendCmd[1] = gHeldKeyCodeToSend; break; case 0xee00: break; @@ -3799,10 +3801,10 @@ bool32 sub_8010454(u32 a0) u8 sub_801048C(bool32 a0) { - if (a0 == 0) + if (a0 == FALSE) return sub_800D550(0, 0); sub_800D550(1, 0x258); - return FALSE; + return 0; } void sub_80104B0(void) @@ -5163,7 +5165,7 @@ u32 sub_80124C0(void) return gUnknown_03005000.unk_9e8.unk_232; } -u32 sub_80124D4(void) +u32 GetRfuRecvQueueLength(void) { return gUnknown_03005000.unk_124.unk_8c2; } diff --git a/src/list_menu.c b/src/list_menu.c index 7a9547661..51d7dcb15 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -355,11 +355,11 @@ s32 DoMysteryGiftListMenu(struct WindowTemplate *windowTemplate, struct ListMenu switch (arg2) { case 0: // can never be reached, because of the if statement above - sub_819746C(sMysteryGiftLinkMenu.windowId, FALSE); + ClearStdWindowAndFrame(sMysteryGiftLinkMenu.windowId, FALSE); break; case 2: case 1: - sub_819746C(sMysteryGiftLinkMenu.windowId, FALSE); + ClearStdWindowAndFrame(sMysteryGiftLinkMenu.windowId, FALSE); break; } } @@ -486,7 +486,7 @@ void RedrawListMenu(u8 listTaskId) { struct ListMenu *list = (void*) gTasks[listTaskId].data; - FillWindowPixelBuffer(list->template.windowId, (list->template.fillValue << 4) | (list->template.fillValue)); + FillWindowPixelBuffer(list->template.windowId, PIXEL_FILL(list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset, 0, list->template.maxShowed); ListMenuDrawCursor(list); CopyWindowToVram(list->template.windowId, 2); @@ -584,7 +584,7 @@ static u8 ListMenuInitInternal(struct ListMenuTemplate *listMenuTemplate, u16 sc if (list->template.totalItems < list->template.maxShowed) list->template.maxShowed = list->template.totalItems; - FillWindowPixelBuffer(list->template.windowId, (list->template.fillValue << 4) | (list->template.fillValue)); + FillWindowPixelBuffer(list->template.windowId, PIXEL_FILL(list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset, 0, list->template.maxShowed); ListMenuDrawCursor(list); ListMenuCallSelectionChangedCallback(list, TRUE); @@ -698,7 +698,7 @@ static void ListMenuErasePrintedCursor(struct ListMenu *list, u16 selectedRow) u8 width = GetMenuCursorDimensionByFont(list->template.fontId, 0); u8 height = GetMenuCursorDimensionByFont(list->template.fontId, 1); FillWindowPixelRect(list->template.windowId, - (list->template.fillValue << 4) | (list->template.fillValue), + PIXEL_FILL(list->template.fillValue), list->template.cursor_X, selectedRow * yMultiplier + list->template.upText_Y, width, @@ -795,7 +795,7 @@ static void ListMenuScroll(struct ListMenu *list, u8 count, bool8 movingDown) { if (count >= list->template.maxShowed) { - FillWindowPixelBuffer(list->template.windowId, (list->template.fillValue << 4) | (list->template.fillValue)); + FillWindowPixelBuffer(list->template.windowId, PIXEL_FILL(list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset, 0, list->template.maxShowed); } else @@ -806,26 +806,26 @@ static void ListMenuScroll(struct ListMenu *list, u8 count, bool8 movingDown) { u16 y, width, height; - ScrollWindow(list->template.windowId, 1, count * yMultiplier, (list->template.fillValue << 4) | (list->template.fillValue)); + ScrollWindow(list->template.windowId, 1, count * yMultiplier, PIXEL_FILL(list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset, 0, count); y = (list->template.maxShowed * yMultiplier) + list->template.upText_Y; width = GetWindowAttribute(list->template.windowId, WINDOW_WIDTH) * 8; height = (GetWindowAttribute(list->template.windowId, WINDOW_HEIGHT) * 8) - y; FillWindowPixelRect(list->template.windowId, - (list->template.fillValue << 4) | (list->template.fillValue), + PIXEL_FILL(list->template.fillValue), 0, y, width, height); } else { u16 width; - ScrollWindow(list->template.windowId, 0, count * yMultiplier, (list->template.fillValue << 4) | (list->template.fillValue)); + ScrollWindow(list->template.windowId, 0, count * yMultiplier, PIXEL_FILL(list->template.fillValue)); ListMenuPrintEntries(list, list->scrollOffset + (list->template.maxShowed - count), list->template.maxShowed - count, count); width = GetWindowAttribute(list->template.windowId, WINDOW_WIDTH) * 8; FillWindowPixelRect(list->template.windowId, - (list->template.fillValue << 4) | (list->template.fillValue), + PIXEL_FILL(list->template.fillValue), 0, 0, width, list->template.upText_Y); } } diff --git a/src/load_save.c b/src/load_save.c index 0d19c6dae..d6785254f 100644 --- a/src/load_save.c +++ b/src/load_save.c @@ -11,10 +11,10 @@ #include "trainer_hill.h" #include "gba/flash_internal.h" #include "decoration_inventory.h" +#include "agb_flash.h" static void ApplyNewEncryptionKeyToAllEncryptedData(u32 encryptionKey); -extern bool16 IdentifyFlash(void); extern void ApplyNewEncryptionKeyToBerryPowder(u32 key); #define SAVEBLOCK_MOVE_RANGE 128 @@ -99,7 +99,7 @@ void MoveSaveBlocks_ResetHeap(void) hblankCB = gMain.hblankCallback; gMain.vblankCallback = NULL; gMain.hblankCallback = NULL; - gUnknown_0203CF5C = NULL; + gTrainerHillVBlankCounter = NULL; saveBlock2Copy = (struct SaveBlock2 *)(gHeap); saveBlock1Copy = (struct SaveBlock1 *)(gHeap + sizeof(struct SaveBlock2)); diff --git a/src/lottery_corner.c b/src/lottery_corner.c index bd7d17ef7..bb3bb7a5c 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -27,7 +27,7 @@ void ResetLotteryCorner(void) u16 rand = Random(); SetLotteryNumber((Random() << 16) | rand); - VarSet(VAR_POKELOT_PRIZE, 0); + VarSet(VAR_POKELOT_PRIZE_ITEM, 0); } void SetRandomLotteryNumber(u16 i) diff --git a/src/mail.c b/src/mail.c index aa4ba571f..9cca4492e 100644 --- a/src/mail.c +++ b/src/mail.c @@ -477,8 +477,8 @@ static void sub_8121B1C(void) y = 0; PutWindowTilemap(0); PutWindowTilemap(1); - FillWindowPixelBuffer(0, 0); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); for (i = 0; i < sMailRead->layout->numSubStructs; i ++) { if (sMailRead->strbuf[i][0] == EOS || sMailRead->strbuf[i][0] == CHAR_SPACE) diff --git a/src/main.c b/src/main.c index 61c5e3386..40381bb68 100644 --- a/src/main.c +++ b/src/main.c @@ -24,9 +24,6 @@ #include "main.h" #include "trainer_hill.h" -extern void sub_800B9B8(void); -extern u8 gUnknown_03002748; - static void VBlankIntr(void); static void HBlankIntr(void); static void VCountIntr(void); @@ -163,7 +160,7 @@ static void UpdateLinkAndCallCallbacks(void) static void InitMainCallbacks(void) { gMain.vblankCounter1 = 0; - gUnknown_0203CF5C = NULL; + gTrainerHillVBlankCounter = NULL; gMain.vblankCounter2 = 0; gMain.callback1 = NULL; SetMainCallback2(CB2_InitCopyrightScreenAfterBootup); @@ -313,8 +310,6 @@ void SetSerialCallback(IntrCallback callback) gMain.serialCallback = callback; } -extern void CopyBufferedValuesToGpuRegs(void); - static void VBlankIntr(void) { if (gWirelessCommType != 0) @@ -324,8 +319,8 @@ static void VBlankIntr(void) gMain.vblankCounter1++; - if (gUnknown_0203CF5C && *gUnknown_0203CF5C < 0xFFFFFFFF) - (*gUnknown_0203CF5C)++; + if (gTrainerHillVBlankCounter && *gTrainerHillVBlankCounter < 0xFFFFFFFF) + (*gTrainerHillVBlankCounter)++; if (gMain.vblankCallback) gMain.vblankCallback(); @@ -393,14 +388,14 @@ static void WaitForVBlank(void) ; } -void sub_80008DC(u32 *var) +void SetTrainerHillVBlankCounter(u32 *counter) { - gUnknown_0203CF5C = var; + gTrainerHillVBlankCounter = counter; } -void sub_80008E8(void) +void ClearTrainerHillVBlankCounter(void) { - gUnknown_0203CF5C = NULL; + gTrainerHillVBlankCounter = NULL; } void DoSoftReset(void) diff --git a/src/main_menu.c b/src/main_menu.c index 82a30aa59..e6e29d942 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -39,6 +39,135 @@ #include "title_screen.h" #include "window.h" +/* + * Main menu state machine + * ----------------------- + * + * Entry point: CB2_InitMainMenu + * + * Note: States advance sequentially unless otherwise stated. + * + * CB2_InitMainMenu / CB2_ReinitMainMenu + * - Both of these states call InitMainMenu, which does all the work. + * - In the Reinit case, the init code will check if the user came from + * the options screen. If they did, then the options menu item is + * pre-selected. + * + * Task_MainMenuCheckSaveFile + * - Determines how many menu options to show based on whether + * the save file is Ok, empty, corrupted, etc. + * - If there was an error loading the save file, advance to + * Task_WaitForSaveFileErrorWindow. + * - If there were no errors, advance to Task_MainMenuCheckBattery. + * - Note that the check to enable Mystery Events would normally happen + * here, but this version of Emerald has them disabled. + * + * Task_WaitForSaveFileErrorWindow + * - Wait for the text to finish printing and then for the A button + * to be pressed. + * + * Task_MainMenuCheckBattery + * - If the battery is OK, advance to Task_DisplayMainMenu. + * - If the battery is dry, advance to Task_WaitForBatteryDryErrorWindow. + * + * Task_WaitForBatteryDryErrorWindow + * - Wait for the text to finish printing and then for the A button + * to be pressed. + * + * Task_DisplayMainWindow + * - Display the buttons to the user. If the menu is in HAS_MYSTERY_EVENTS + * mode, there are too many buttons for one screen and a scrollbar is added, + * and the scrollbar task is spawned (Task_ScrollIndicatorArrowPairOnMainMenu). + * + * Task_HighlightSelectedMainMenuItem + * - Update the UI to match the currently selected item. + * + * Task_HandleMainMenuInput + * - If A is pressed, advance to Task_HandleMainMenuAPressed. + * - If B is pressed, return to the title screen via CB2_InitTitleScreen. + * - If Up or Down is pressed, handle scrolling if there is a scroll bar, change + * the selection, then go back to Task_HighlightSelectedMainMenuItem. + * + * Task_HandleMainMenuAPressed + * - If the user selected New Game, advance to Task_NewGameBirchSpeech_Init. + * - If the user selected Continue, advance to CB2_ContinueSavedGame. + * - If the user selected the Options menu, advance to CB2_InitOptionMenu. + * - If the user selected Mystery Gift, advance to CB2_MysteryGift. However, + * if the wireless adapter was removed, instead advance to + * Task_DisplayMainMenuInvalidActionError. + * - Code to start a Mystery Event is present here, but is unreachable in this + * version. + * + * Task_HandleMainMenuBPressed + * - Clean up the main menu and go back to CB2_InitTitleScreen. + * + * Task_DisplayMainMenuInvalidActionError + * - Print one of three different error messages, wait for the text to stop + * printing, and then wait for A or B to be pressed. + * - Then advance to Task_HandleMainMenuBPressed. + * + * Task_NewGameBirchSpeechInit + * - Load the sprites for the intro speech, start playing music + * Task_NewGameBirchSpeech_WaitToShowBirch + * - Spawn Task_NewGameBirchSpeech_FadeInTarget1OutTarget2 + * - Spawn Task_NewGameBirchSpeech_FadePlatformOut + * - Both of these tasks destroy themselves when done. + * Task_NewGameBirchSpeech_WaitForSpriteFadeInWelcome + * Task_NewGameBirchSpeech_ThisIsAPokemon + * - When the text is done printing, spawns Task_NewGameBirchSpeechSub_InitPokeball + * Task_NewGameBirchSpeech_MainSpeech + * Task_NewGameBirchSpeech_AndYouAre + * Task_NewGameBirchSpeech_StartBirchLotadPlatformFade + * Task_NewGameBirchSpeech_StartBirchLotadPlatformFade + * Task_NewGameBirchSpeech_SlidePlatformAway + * Task_NewGameBirchSpeech_StartPlayerFadeIn + * Task_NewGameBirchSpeech_WaitForPlayerFadeIn + * Task_NewGameBirchSpeech_BoyOrGirl + * Task_NewGameBirchSpeech_WaitToShowGenderMenu + * Task_NewGameBirchSpeech_ChooseGender + * - Animates by advancing to Task_NewGameBirchSpeech_SlideOutOldGenderSprite + * whenever the player's selection changes. + * - Advances to Task_NewGameBirchSpeech_WhatsYourName when done. + * + * Task_NewGameBirchSpeech_SlideOutOldGenderSprite + * Task_NewGameBirchSpeech_SlideInNewGenderSprite + * - Returns back to Task_NewGameBirchSpeech_ChooseGender. + * + * Task_NewGameBirchSpeech_WhatsYourName + * Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint + * Task_NewGameBirchSpeech_WaitPressBeforeNameChoice + * Task_NewGameBirchSpeech_StartNamingScreen + * C2_NamingScreen + * - Returns to CB2_NewGameBirchSpeech_ReturnFromNamingScreen when done + * CB2_NewGameBirchSpeech_ReturnFromNamingScreen + * Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox + * Task_NewGameBirchSpeech_SoItsPlayerName + * Task_NewGameBirchSpeech_CreateNameYesNo + * Task_NewGameBirchSpeech_ProcessNameYesNoMenu + * - If confirmed, advance to Task_NewGameBirchSpeech_SlidePlatformAway2. + * - Otherwise, return to Task_NewGameBirchSpeech_BoyOrGirl. + * + * Task_NewGameBirchSpeech_SlidePlatformAway2 + * Task_NewGameBirchSpeech_ReshowBirchLotad + * Task_NewGameBirchSpeech_WaitForSpriteFadeInAndTextPrinter + * Task_NewGameBirchSpeech_AreYouReady + * Task_NewGameBirchSpeech_ShrinkPlayer + * Task_NewGameBirchSpeech_WaitForPlayerShrink + * Task_NewGameBirchSpeech_FadePlayerToWhite + * Task_NewGameBirchSpeech_Cleanup + * - Advances to CB2_NewGame. + * + * Task_NewGameBirchSpeechSub_InitPokeball + * - Advances to Task_NewGameBirchSpeechSub_WaitForLotad + * Task_NewGameBirchSpeechSub_WaitForLotad + * - Destroys itself when done. + */ + +// These two defines are used with the sCurrItemAndOptionsMenuCheck, +// to distinguish between its two parts. +#define OPTION_MENU_FLAG 0x8000 +#define CURRENT_ITEM_MASK 0x7FFF + // Static type declarations // Static RAM declarations @@ -112,7 +241,7 @@ static void SpriteCB_MovePlayerDownWhileShrinking(struct Sprite*); static void Task_NewGameBirchSpeech_WaitForPlayerShrink(u8); static void Task_NewGameBirchSpeech_FadePlayerToWhite(u8); static void Task_NewGameBirchSpeech_Cleanup(u8); -static void nullsub_11(); +static void SpriteCB_Null(); static void Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox(u8); static void MainMenu_FormatSavegamePlayer(void); static void MainMenu_FormatSavegamePokedex(void); @@ -247,7 +376,7 @@ static const struct WindowTemplate sWindowTemplates_MainMenu[] = DUMMY_WIN_TEMPLATE }; -static const struct WindowTemplate gUnknown_082FF080[] = +static const struct WindowTemplate gNewGameBirchSpeechTextWindows[] = { { .bg = 0, @@ -542,7 +671,7 @@ static void Task_MainMenuCheckSaveFile(u8 taskId) gTasks[taskId].func = Task_WaitForSaveFileErrorWindow; break; } - if (sCurrItemAndOptionMenuCheck & 0x8000) // are we returning from the options menu? + if (sCurrItemAndOptionMenuCheck & OPTION_MENU_FLAG) // are we returning from the options menu? { switch (tMenuType) // if so, highlight the OPTIONS item { @@ -558,7 +687,7 @@ static void Task_MainMenuCheckSaveFile(u8 taskId) break; } } - sCurrItemAndOptionMenuCheck &= 0x7FFF; // turn off the "returning from options menu" flag + sCurrItemAndOptionMenuCheck &= CURRENT_ITEM_MASK; // turn off the "returning from options menu" flag tCurrItem = sCurrItemAndOptionMenuCheck; tItemCount = tMenuType + 2; } @@ -637,6 +766,8 @@ static void Task_DisplayMainMenu(u8 taskId) palette = RGB(26, 26, 25); LoadPalette(&palette, 252, 2); + // Note: If there is no save file, the save block is zeroed out, + // so the default gender is MALE. if (gSaveBlock2Ptr->playerGender == MALE) { palette = RGB(4, 16, 31); @@ -652,8 +783,8 @@ static void Task_DisplayMainMenu(u8 taskId) { case HAS_NO_SAVED_GAME: default: - FillWindowPixelBuffer(0, 0xAA); - FillWindowPixelBuffer(1, 0xAA); + FillWindowPixelBuffer(0, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(1, PIXEL_FILL(0xA)); AddTextPrinterParameterized3(0, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuNewGame); AddTextPrinterParameterized3(1, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuOption); PutWindowTilemap(0); @@ -664,9 +795,9 @@ static void Task_DisplayMainMenu(u8 taskId) DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[1], MAIN_MENU_BORDER_TILE); break; case HAS_SAVED_GAME: - FillWindowPixelBuffer(2, 0xAA); - FillWindowPixelBuffer(3, 0xAA); - FillWindowPixelBuffer(4, 0xAA); + FillWindowPixelBuffer(2, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(3, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(4, PIXEL_FILL(0xA)); AddTextPrinterParameterized3(2, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuContinue); AddTextPrinterParameterized3(3, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuNewGame); AddTextPrinterParameterized3(4, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuOption); @@ -682,10 +813,10 @@ static void Task_DisplayMainMenu(u8 taskId) DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[4], MAIN_MENU_BORDER_TILE); break; case HAS_MYSTERY_GIFT: - FillWindowPixelBuffer(2, 0xAA); - FillWindowPixelBuffer(3, 0xAA); - FillWindowPixelBuffer(4, 0xAA); - FillWindowPixelBuffer(5, 0xAA); + FillWindowPixelBuffer(2, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(3, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(4, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(5, PIXEL_FILL(0xA)); AddTextPrinterParameterized3(2, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuContinue); AddTextPrinterParameterized3(3, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuNewGame); AddTextPrinterParameterized3(4, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuMysteryGift); @@ -705,11 +836,11 @@ static void Task_DisplayMainMenu(u8 taskId) DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[5], MAIN_MENU_BORDER_TILE); break; case HAS_MYSTERY_EVENTS: - FillWindowPixelBuffer(2, 0xAA); - FillWindowPixelBuffer(3, 0xAA); - FillWindowPixelBuffer(4, 0xAA); - FillWindowPixelBuffer(5, 0xAA); - FillWindowPixelBuffer(6, 0xAA); + FillWindowPixelBuffer(2, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(3, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(4, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(5, PIXEL_FILL(0xA)); + FillWindowPixelBuffer(6, PIXEL_FILL(0xA)); AddTextPrinterParameterized3(2, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuContinue); AddTextPrinterParameterized3(3, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuNewGame); AddTextPrinterParameterized3(4, 1, 0, 1, sTextColor_Headers, -1, gText_MainMenuMysteryGift2); @@ -813,14 +944,14 @@ static void Task_HandleMainMenuAPressed(u8 taskId) { if (gTasks[taskId].tMenuType == HAS_MYSTERY_EVENTS) RemoveScrollIndicatorArrowPair(gTasks[taskId].tScrollArrowTaskId); - sub_819746C(0, 1); - sub_819746C(1, 1); - sub_819746C(2, 1); - sub_819746C(3, 1); - sub_819746C(4, 1); - sub_819746C(5, 1); - sub_819746C(6, 1); - sub_819746C(7, 1); + ClearStdWindowAndFrame(0, TRUE); + ClearStdWindowAndFrame(1, TRUE); + ClearStdWindowAndFrame(2, TRUE); + ClearStdWindowAndFrame(3, TRUE); + ClearStdWindowAndFrame(4, TRUE); + ClearStdWindowAndFrame(5, TRUE); + ClearStdWindowAndFrame(6, TRUE); + ClearStdWindowAndFrame(7, TRUE); wirelessAdapterConnected = IsWirelessAdapterConnected(); switch (gTasks[taskId].tMenuType) { @@ -973,7 +1104,7 @@ static void Task_HandleMainMenuAPressed(u8 taskId) if (action != ACTION_OPTION) sCurrItemAndOptionMenuCheck = 0; else - sCurrItemAndOptionMenuCheck |= 0x8000; // entering the options menu + sCurrItemAndOptionMenuCheck |= OPTION_MENU_FLAG; // entering the options menu } } @@ -981,7 +1112,7 @@ static void Task_HandleMainMenuBPressed(u8 taskId) { if (!gPaletteFade.active) { - if (gTasks[taskId].tMenuType == 3) + if (gTasks[taskId].tMenuType == HAS_MYSTERY_EVENTS) RemoveScrollIndicatorArrowPair(gTasks[taskId].tScrollArrowTaskId); sCurrItemAndOptionMenuCheck = 0; FreeAllWindowBuffers(); @@ -1199,7 +1330,7 @@ static void Task_NewGameBirchSpeech_WaitForSpriteFadeInWelcome(u8 taskId) } else { - InitWindows(gUnknown_082FF080); + InitWindows(gNewGameBirchSpeechTextWindows); LoadMainMenuWindowFrameTiles(0, 0xF3); LoadMessageBoxGfx(0, 0xFC, 0xF0); NewGameBirchSpeech_ShowDialogueWindow(0, 1); @@ -1642,7 +1773,7 @@ static void Task_NewGameBirchSpeech_FadePlayerToWhite(u8 taskId) if (!gPaletteFade.active) { spriteId = gTasks[taskId].tPlayerSpriteId; - gSprites[spriteId].callback = nullsub_11; + gSprites[spriteId].callback = SpriteCB_Null; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); BeginNormalPaletteFade(0xFFFF0000, 0, 0, 16, RGB_WHITEALPHA); gTasks[taskId].func = Task_NewGameBirchSpeech_Cleanup; @@ -1730,14 +1861,14 @@ static void CB2_NewGameBirchSpeech_ReturnFromNamingScreen(void) REG_IME = savedIme; SetVBlankCallback(VBlankCB_MainMenu); SetMainCallback2(CB2_MainMenu); - InitWindows(gUnknown_082FF080); + InitWindows(gNewGameBirchSpeechTextWindows); LoadMainMenuWindowFrameTiles(0, 0xF3); LoadMessageBoxGfx(0, 0xFC, 0xF0); PutWindowTilemap(0); CopyWindowToVram(0, 3); } -static void nullsub_11(struct Sprite *sprite) +static void SpriteCB_Null(struct Sprite *sprite) { } @@ -1763,22 +1894,22 @@ static void AddBirchSpeechObjects(u8 taskId) u8 maySpriteId; birchSpriteId = AddNewGameBirchObject(0x88, 0x3C, 1); - gSprites[birchSpriteId].callback = nullsub_11; + gSprites[birchSpriteId].callback = SpriteCB_Null; gSprites[birchSpriteId].oam.priority = 0; gSprites[birchSpriteId].invisible = TRUE; gTasks[taskId].tBirchSpriteId = birchSpriteId; lotadSpriteId = NewGameBirchSpeech_CreateLotadSprite(100, 0x4B); - gSprites[lotadSpriteId].callback = nullsub_11; + gSprites[lotadSpriteId].callback = SpriteCB_Null; gSprites[lotadSpriteId].oam.priority = 0; gSprites[lotadSpriteId].invisible = TRUE; gTasks[taskId].tLotadSpriteId = lotadSpriteId; brendanSpriteId = CreateTrainerSprite(FacilityClassToPicIndex(FACILITY_CLASS_BRENDAN), 120, 60, 0, &gDecompressionBuffer[0]); - gSprites[brendanSpriteId].callback = nullsub_11; + gSprites[brendanSpriteId].callback = SpriteCB_Null; gSprites[brendanSpriteId].invisible = TRUE; gSprites[brendanSpriteId].oam.priority = 0; gTasks[taskId].tBrendanSpriteId = brendanSpriteId; maySpriteId = CreateTrainerSprite(FacilityClassToPicIndex(FACILITY_CLASS_MAY), 120, 60, 0, &gDecompressionBuffer[0x800]); - gSprites[maySpriteId].callback = nullsub_11; + gSprites[maySpriteId].callback = SpriteCB_Null; gSprites[maySpriteId].invisible = TRUE; gSprites[maySpriteId].oam.priority = 0; gTasks[taskId].tMaySpriteId = maySpriteId; @@ -1966,8 +2097,8 @@ static void NewGameBirchSpeech_StartFadePlatformOut(u8 taskId, u8 delay) static void NewGameBirchSpeech_ShowGenderMenu(void) { - DrawMainMenuWindowBorder(&gUnknown_082FF080[1], 0xF3); - FillWindowPixelBuffer(1, 17); + DrawMainMenuWindowBorder(&gNewGameBirchSpeechTextWindows[1], 0xF3); + FillWindowPixelBuffer(1, PIXEL_FILL(1)); PrintMenuTable(1, 2, sMenuActions_Gender); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(1, 2, 0); PutWindowTilemap(1); @@ -1995,7 +2126,7 @@ static void NewGameBirchSpeech_SetDefaultPlayerName(u8 nameId) static void CreateMainMenuErrorWindow(const u8* str) { - FillWindowPixelBuffer(7, 17); + FillWindowPixelBuffer(7, PIXEL_FILL(1)); AddTextPrinterParameterized(7, 1, str, 0, 1, 2, 0); PutWindowTilemap(7); CopyWindowToVram(7, 2); @@ -2105,12 +2236,12 @@ static void NewGameBirchSpeech_ClearGenderWindowTilemap(u8 a, u8 b, u8 c, u8 d, FillBgTilemapBufferRect(a, 0, b + 0xFF, c + 0xFF, d + 2, e + 2, 2); } -static void NewGameBirchSpeech_ClearGenderWindow(u8 windowId, u8 a) +static void NewGameBirchSpeech_ClearGenderWindow(u8 windowId, bool8 copyToVram) { CallWindowFunction(windowId, NewGameBirchSpeech_ClearGenderWindowTilemap); - FillWindowPixelBuffer(windowId, 0x11); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); ClearWindowTilemap(windowId); - if (a == 1) + if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } @@ -2146,7 +2277,7 @@ void CreateYesNoMenuParameterized(u8 a, u8 b, u16 c, u16 d, u8 e, u8 f) static void NewGameBirchSpeech_ShowDialogueWindow(u8 windowId, u8 copyToVram) { CallWindowFunction(windowId, NewGameBirchSpeech_CreateDialogueWindowBorder); - FillWindowPixelBuffer(windowId, 17); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); diff --git a/src/map_name_popup.c b/src/map_name_popup.c index cdb4c3330..8936198ae 100644 --- a/src/map_name_popup.c +++ b/src/map_name_popup.c @@ -276,7 +276,7 @@ static void Task_MapNamePopUpWindow(u8 taskId) } break; case 4: - sub_819746C(GetMapNamePopUpWindowId(), TRUE); + ClearStdWindowAndFrame(GetMapNamePopUpWindowId(), TRUE); task->data[0] = 5; break; case 5: @@ -290,7 +290,7 @@ void HideMapNamePopUpWindow(void) { if (FuncIsActiveTask(Task_MapNamePopUpWindow)) { - sub_819746C(GetMapNamePopUpWindowId(), TRUE); + ClearStdWindowAndFrame(GetMapNamePopUpWindowId(), TRUE); RemoveMapNamePopUpWindow(); SetGpuReg_ForcedBlank(REG_OFFSET_BG0VOFS, 0); DestroyTask(sPopupTaskId); diff --git a/src/match_call.c b/src/match_call.c index e7e91969f..641079ba9 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -111,8 +111,6 @@ static void PopulateSpeciesFromTrainerParty(int, u8 *); static void PopulateBattleFrontierFacilityName(int, u8 *); static void PopulateBattleFrontierStreak(int, u8 *); -extern void sub_81973A4(void); - #define TEXT_ID(topic, id) (((topic) << 8) | ((id) & 0xFF)) static const struct MatchCallTrainerTextInfo sMatchCallTrainers[] = @@ -1016,7 +1014,7 @@ static bool32 MapAllowsMatchCall(void) if (gMapHeader.regionMapSectionId == MAPSEC_SOOTOPOLIS_CITY && FlagGet(FLAG_HIDE_SOOTOPOLIS_CITY_RAYQUAZA) == TRUE - && FlagGet(FLAG_UNUSED_0x0DC) == FALSE) + && FlagGet(FLAG_NEVER_SET_0x0DC) == FALSE) return FALSE; if (gMapHeader.regionMapSectionId == MAPSEC_MT_CHIMNEY @@ -1191,7 +1189,7 @@ static bool32 LoadMatchCallWindowGfx(u8 taskId) return FALSE; } - FillWindowPixelBuffer(taskData[2], 0x88); + FillWindowPixelBuffer(taskData[2], PIXEL_FILL(8)); LoadPalette(sUnknown_0860EA4C, 0xE0, 0x20); LoadPalette(sPokeNavIconPalette, 0xF0, 0x20); ChangeBgY(0, -0x2000, 0); @@ -1241,7 +1239,7 @@ static bool32 sub_81962D8(u8 taskId) s16 *taskData = gTasks[taskId].data; if (!ExecuteMatchCallTextPrinter(taskData[2])) { - FillWindowPixelBuffer(taskData[2], 0x88); + FillWindowPixelBuffer(taskData[2], PIXEL_FILL(8)); if (!gMatchCallState.triggeredFromScript) SelectMatchCallMessage(gMatchCallState.trainerId, gStringVar4); @@ -1257,7 +1255,7 @@ static bool32 sub_8196330(u8 taskId) s16 *taskData = gTasks[taskId].data; if (!ExecuteMatchCallTextPrinter(taskData[2]) && !IsSEPlaying() && gMain.newKeys & (A_BUTTON | B_BUTTON)) { - FillWindowPixelBuffer(taskData[2], 0x88); + FillWindowPixelBuffer(taskData[2], PIXEL_FILL(8)); CopyWindowToVram(taskData[2], 2); PlaySE(SE_TOREOFF); return TRUE; diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index fd8e74c0a..ec5cb238b 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -437,7 +437,7 @@ static void BardSong_TextSubPrinter(struct TextPrinterTemplate * printer, u16 a1 static void sub_8120708(const u8 * src) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, src, 0, 1, 1, BardSong_TextSubPrinter); gUnknown_03002F84 = TRUE; CopyWindowToVram(0, 3); diff --git a/src/menu.c b/src/menu.c index ae589dff4..b04572b81 100644 --- a/src/menu.c +++ b/src/menu.c @@ -122,20 +122,18 @@ const struct MoveMenuInfoIcon gMoveMenuInfoIcons[] = { 8, 8, 0xAF }, // Unused (Small dark pokeball) }; + // Forward declarations -extern void sub_81973A4(void); -extern void DrawStandardFrame(u8, u8, u8, u8, u8, u8); -extern void DrawDialogueFrame(u8, u8, u8, u8, u8, u8); -extern void sub_81977BC(u8, u8, u8, u8, u8, u8); -extern void sub_8197804(u8, u8, u8, u8, u8, u8); -extern void sub_8197BB4(u8, u8, u8, u8, u8, u8); -extern void sub_8197E30(u8, u8, u8, u8, u8, u8); -extern void DrawWindowBorder(u8, u8, u8, u8, u8, u8); -extern void sub_81980A8(u8, u8, u8, u8, u8, u8); -extern u8 Menu_MoveCursor(s8); -extern u8 sub_8199134(s8, s8); -extern void sub_8198C78(void); -extern void task_free_buf_after_copying_tile_data_to_vram(u8 taskId); +void WindowFunc_DrawStandardFrame(u8, u8, u8, u8, u8, u8); +void WindowFunc_DrawDialogueFrame(u8, u8, u8, u8, u8, u8); +void WindowFunc_ClearStdWindowAndFrame(u8, u8, u8, u8, u8, u8); +void WindowFunc_ClearDialogWindowAndFrame(u8, u8, u8, u8, u8, u8); +void WindowFunc_DrawDialogFrameWithCustomTileAndPalette(u8, u8, u8, u8, u8, u8); +void WindowFunc_ClearDialogWindowAndFrameNullPalette(u8, u8, u8, u8, u8, u8); +void WindowFunc_DrawStdFrameWithCustomTileAndPalette(u8, u8, u8, u8, u8, u8); +void WindowFunc_ClearStdWindowAndFrameToTransparent(u8, u8, u8, u8, u8, u8); +void sub_8198C78(void); +void task_free_buf_after_copying_tile_data_to_vram(u8 taskId); void InitStandardTextBoxWindows(void) { @@ -210,43 +208,43 @@ void sub_81973A4(void) LoadUserWindowBorderGfx(0, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM * 0x10); } -void NewMenuHelpers_DrawDialogueFrame(u8 windowId, bool8 copyToVram) +void DrawDialogueFrame(u8 windowId, bool8 copyToVram) { - CallWindowFunction(windowId, DrawDialogueFrame); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_DrawDialogueFrame); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void NewMenuHelpers_DrawStdWindowFrame(u8 windowId, bool8 copyToVram) +void DrawStdWindowFrame(u8 windowId, bool8 copyToVram) { - CallWindowFunction(windowId, DrawStandardFrame); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_DrawStandardFrame); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_8197434(u8 windowId, bool8 copyToVram) +void ClearDialogWindowAndFrame(u8 windowId, bool8 copyToVram) { - CallWindowFunction(windowId, sub_8197804); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_ClearDialogWindowAndFrame); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); ClearWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_819746C(u8 windowId, bool8 copyToVram) +void ClearStdWindowAndFrame(u8 windowId, bool8 copyToVram) { - CallWindowFunction(windowId, sub_81977BC); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_ClearStdWindowAndFrame); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); ClearWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void DrawStandardFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_DrawStandardFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { int i; @@ -313,7 +311,7 @@ void DrawStandardFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height STD_WINDOW_PALETTE_NUM); } -void DrawDialogueFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_DrawDialogueFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, DLG_WINDOW_BASE_TILE_NUM + 1, @@ -408,25 +406,25 @@ void DrawDialogueFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height DLG_WINDOW_PALETTE_NUM); } -void sub_81977BC(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_ClearStdWindowAndFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, 0, tilemapLeft - 1, tilemapTop - 1, width + 2, height + 2, STD_WINDOW_PALETTE_NUM); } -void sub_8197804(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_ClearDialogWindowAndFrame(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, 0, tilemapLeft - 3, tilemapTop - 1, width + 6, height + 2, STD_WINDOW_PALETTE_NUM); } void SetStandardWindowBorderStyle(u8 windowId, bool8 copyToVram) { - SetWindowBorderStyle(windowId, copyToVram, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM); + DrawStdFrameWithCustomTileAndPalette(windowId, copyToVram, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM); } void sub_819786C(u8 windowId, bool8 copyToVram) { LoadMessageBoxGfx(windowId, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM * 0x10); - sub_8197B1C(windowId, copyToVram, DLG_WINDOW_BASE_TILE_NUM, 0xF); + DrawDialogFrameWithCustomTileAndPalette(windowId, copyToVram, DLG_WINDOW_BASE_TILE_NUM, 0xF); } void sub_819789C(void) @@ -458,12 +456,12 @@ void DisplayItemMessageOnField(u8 taskId, const u8 *string, TaskFunc callback) CopyWindowToVram(0, 3); } -void DisplayYesNoMenu(void) +void DisplayYesNoMenuDefaultYes(void) { CreateYesNoMenu(&sYesNo_WindowTemplates, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, 0); } -void sub_8197948(u8 initialCursorPos) +void DisplayYesNoMenuWithDefault(u8 initialCursorPos) { CreateYesNoMenu(&sYesNo_WindowTemplates, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM, initialCursorPos); } @@ -549,29 +547,30 @@ void sub_8197AE8(bool8 copyToVram) CopyBgTilemapBufferToVram(0); } -void sub_8197B1C(u8 windowId, bool8 copyToVram, u16 tileNum, u8 paletteNum) +void DrawDialogFrameWithCustomTileAndPalette(u8 windowId, bool8 copyToVram, u16 tileNum, u8 paletteNum) { sTileNum = tileNum; sPaletteNum = paletteNum; - CallWindowFunction(windowId, sub_8197BB4); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_DrawDialogFrameWithCustomTileAndPalette); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_8197B64(u8 windowId, bool8 copyToVram, u16 tileNum) +// Never used. +void DrawDialogFrameWithCustomTile(u8 windowId, bool8 copyToVram, u16 tileNum) { sTileNum = tileNum; sPaletteNum = GetWindowAttribute(windowId, WINDOW_PALETTE_NUM); - CallWindowFunction(windowId, sub_8197BB4); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_DrawDialogFrameWithCustomTileAndPalette); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_8197BB4(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_DrawDialogFrameWithCustomTileAndPalette(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, sTileNum + 1, @@ -666,43 +665,45 @@ void sub_8197BB4(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 p sPaletteNum); } -void sub_8197DF8(u8 windowId, bool8 copyToVram) +void ClearDialogWindowAndFrameToTransparent(u8 windowId, bool8 copyToVram) { - CallWindowFunction(windowId, sub_8197E30); - FillWindowPixelBuffer(windowId, 0); + // The palette slot doesn't matter, since the tiles are transparent. + CallWindowFunction(windowId, WindowFunc_ClearDialogWindowAndFrameNullPalette); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); ClearWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_8197E30(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_ClearDialogWindowAndFrameNullPalette(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, 0, tilemapLeft - 3, tilemapTop - 1, width + 6, height + 2, 0); } -void SetWindowBorderStyle(u8 windowId, bool8 copyToVram, u16 baseTileNum, u8 paletteNum) +void DrawStdFrameWithCustomTileAndPalette(u8 windowId, bool8 copyToVram, u16 baseTileNum, u8 paletteNum) { sTileNum = baseTileNum; sPaletteNum = paletteNum; - CallWindowFunction(windowId, DrawWindowBorder); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_DrawStdFrameWithCustomTileAndPalette); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_8197EC8(u8 windowId, bool8 copyToVram, u16 baseTileNum) +// Never used. +void DrawStdFrameWithCustomTile(u8 windowId, bool8 copyToVram, u16 baseTileNum) { sTileNum = baseTileNum; sPaletteNum = GetWindowAttribute(windowId, WINDOW_PALETTE_NUM); - CallWindowFunction(windowId, DrawWindowBorder); - FillWindowPixelBuffer(windowId, 0x11); + CallWindowFunction(windowId, WindowFunc_DrawStdFrameWithCustomTileAndPalette); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); PutWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void DrawWindowBorder(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_DrawStdFrameWithCustomTileAndPalette(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, sTileNum + 0, @@ -762,16 +763,16 @@ void DrawWindowBorder(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, sPaletteNum); } -void sub_8198070(u8 windowId, bool8 copyToVram) +void ClearStdWindowAndFrameToTransparent(u8 windowId, bool8 copyToVram) { - CallWindowFunction(windowId, sub_81980A8); - FillWindowPixelBuffer(windowId, 0); + CallWindowFunction(windowId, WindowFunc_ClearStdWindowAndFrameToTransparent); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); ClearWindowTilemap(windowId); if (copyToVram == TRUE) CopyWindowToVram(windowId, 3); } -void sub_81980A8(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) +void WindowFunc_ClearStdWindowAndFrameToTransparent(u8 bg, u8 tilemapLeft, u8 tilemapTop, u8 width, u8 height, u8 paletteNum) { FillBgTilemapBufferRect(bg, 0, tilemapLeft - 1, tilemapTop - 1, width + 2, height + 2, 0); } @@ -811,7 +812,7 @@ void sub_8198180(const u8 *string, u8 a2, bool8 copyToVram) if (sWindowId != 0xFF) { PutWindowTilemap(sWindowId); - FillWindowPixelBuffer(sWindowId, 0xFF); + FillWindowPixelBuffer(sWindowId, PIXEL_FILL(15)); width = GetStringWidth(0, string, 0); AddTextPrinterParameterized3(sWindowId, 0, @@ -845,7 +846,7 @@ void sub_8198204(const u8 *string, const u8 *string2, u8 a3, u8 a4, bool8 copyTo color[2] = 2; } PutWindowTilemap(sWindowId); - FillWindowPixelBuffer(sWindowId, 0xFF); + FillWindowPixelBuffer(sWindowId, PIXEL_FILL(15)); if (string2 != NULL) { width = GetStringWidth(0, string2, 0); @@ -873,7 +874,7 @@ void sub_81982F0(void) { if (sWindowId != 0xFF) { - FillWindowPixelBuffer(sWindowId, 0xFF); + FillWindowPixelBuffer(sWindowId, PIXEL_FILL(15)); CopyWindowToVram(sWindowId, 3); } } @@ -882,7 +883,7 @@ void sub_8198314(void) { if (sWindowId != 0xFF) { - FillWindowPixelBuffer(sWindowId, 0); + FillWindowPixelBuffer(sWindowId, PIXEL_FILL(0)); ClearWindowTilemap(sWindowId); CopyWindowToVram(sWindowId, 3); RemoveWindow(sWindowId); @@ -931,7 +932,7 @@ void RedrawMenuCursor(u8 oldPos, u8 newPos) width = GetMenuCursorDimensionByFont(sMenu.fontId, 0); height = GetMenuCursorDimensionByFont(sMenu.fontId, 1); - FillWindowPixelRect(sMenu.windowId, 0x11, sMenu.left, sMenu.optionHeight * oldPos + sMenu.top, width, height); + FillWindowPixelRect(sMenu.windowId, PIXEL_FILL(1), sMenu.left, sMenu.optionHeight * oldPos + sMenu.top, width, height); AddTextPrinterParameterized(sMenu.windowId, sMenu.fontId, gText_SelectorArrow3, sMenu.left, sMenu.optionHeight * newPos + sMenu.top, 0, 0); } @@ -1175,7 +1176,7 @@ void sub_8198AF8(const struct WindowTemplate *window, u8 fontId, u8 left, u8 top struct TextPrinterTemplate printer; sYesNoWindowId = AddWindow(window); - SetWindowBorderStyle(sYesNoWindowId, TRUE, baseTileNum, paletteNum); + DrawStdFrameWithCustomTileAndPalette(sYesNoWindowId, TRUE, baseTileNum, paletteNum); printer.currentChar = gText_YesNo; printer.windowId = sYesNoWindowId; @@ -1211,7 +1212,7 @@ s8 Menu_ProcessInputNoWrapClearOnChoose(void) void sub_8198C78(void) { - sub_8198070(sYesNoWindowId, TRUE); + ClearStdWindowAndFrameToTransparent(sYesNoWindowId, TRUE); RemoveWindow(sYesNoWindowId); } @@ -1310,7 +1311,7 @@ void sub_8199060(u8 oldCursorPos, u8 newCursorPos) u8 xPos = (oldCursorPos % sMenu.horizontalCount) * sMenu.optionWidth + sMenu.left; u8 yPos = (oldCursorPos / sMenu.horizontalCount) * sMenu.optionHeight + sMenu.top; FillWindowPixelRect(sMenu.windowId, - 0x11, + PIXEL_FILL(1), xPos, yPos, cursorWidth, @@ -1640,7 +1641,7 @@ void CreateYesNoMenu(const struct WindowTemplate *window, u16 baseTileNum, u8 pa struct TextPrinterTemplate printer; sYesNoWindowId = AddWindow(window); - SetWindowBorderStyle(sYesNoWindowId, TRUE, baseTileNum, paletteNum); + DrawStdFrameWithCustomTileAndPalette(sYesNoWindowId, TRUE, baseTileNum, paletteNum); printer.currentChar = gText_YesNo; printer.windowId = sYesNoWindowId; diff --git a/src/menu_helpers.c b/src/menu_helpers.c index e6547b300..3fb5ca40d 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -18,8 +18,6 @@ #include "constants/items.h" #include "constants/maps.h" -extern bool32 sub_800B504(void); - // this file's functions static void Task_ContinueTaskAfterMessagePrints(u8 taskId); static void Task_CallYesOrNoCallback(u8 taskId); @@ -129,7 +127,7 @@ void SetVBlankHBlankCallbacksToNull(void) void DisplayMessageAndContinueTask(u8 taskId, u8 windowId, u16 arg2, u8 arg3, u8 fontId, u8 textSpeed, const u8 *string, void *taskFunc) { gUnknown_0203A140 = windowId; - sub_8197B1C(windowId, TRUE, arg2, arg3); + DrawDialogFrameWithCustomTileAndPalette(windowId, TRUE, arg2, arg3); if (string != gStringVar4) StringExpandPlaceholders(gStringVar4, string); @@ -293,7 +291,7 @@ bool8 sub_8122148(u16 itemId) bool8 itemid_80BF6D8_mail_related(u16 itemId) { - if (is_c1_link_related_active() != TRUE && InUnionRoom() != TRUE) + if (IsUpdateLinkStateCBActive() != TRUE && InUnionRoom() != TRUE) return TRUE; else if (ItemIsMail(itemId) != TRUE) return TRUE; @@ -303,7 +301,7 @@ bool8 itemid_80BF6D8_mail_related(u16 itemId) bool8 sub_81221AC(void) { - if (is_c1_link_related_active() == TRUE || gReceivedRemoteLinkPlayers == 1) + if (IsUpdateLinkStateCBActive() == TRUE || gReceivedRemoteLinkPlayers == 1) return TRUE; else return FALSE; diff --git a/src/mirage_tower.c b/src/mirage_tower.c index a8dd5d9de..4f5834db1 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -317,7 +317,7 @@ void SetMirageTowerVisibility(void) u16 rand; bool8 visible; - if (VarGet(VAR_0x40CB)) + if (VarGet(VAR_ROUTE_111_STATE)) { FlagClear(FLAG_MIRAGE_TOWER_VISIBLE); return; diff --git a/src/money.c b/src/money.c index faf830637..4ff8086ea 100644 --- a/src/money.c +++ b/src/money.c @@ -154,7 +154,7 @@ void PrintMoneyAmount(u8 windowId, u8 x, u8 y, int amount, u8 speed) void PrintMoneyAmountInMoneyBoxWithBorder(u8 windowId, u16 tileStart, u8 pallete, int amount) { - SetWindowBorderStyle(windowId, FALSE, tileStart, pallete); + DrawStdFrameWithCustomTileAndPalette(windowId, FALSE, tileStart, pallete); PrintMoneyAmountInMoneyBox(windowId, amount, 0); } @@ -169,7 +169,7 @@ void DrawMoneyBox(int amount, u8 x, u8 y) SetWindowTemplateFields(&template, 0, x + 1, y + 1, 10, 2, 15, 8); sMoneyBoxWindowId = AddWindow(&template); - FillWindowPixelBuffer(sMoneyBoxWindowId, 0); + FillWindowPixelBuffer(sMoneyBoxWindowId, PIXEL_FILL(0)); PutWindowTilemap(sMoneyBoxWindowId); CopyWindowToVram(sMoneyBoxWindowId, 1); PrintMoneyAmountInMoneyBoxWithBorder(sMoneyBoxWindowId, 0x214, 14, amount); @@ -179,7 +179,7 @@ void DrawMoneyBox(int amount, u8 x, u8 y) void HideMoneyBox(void) { RemoveMoneyLabelObject(); - sub_8198070(sMoneyBoxWindowId, FALSE); + ClearStdWindowAndFrameToTransparent(sMoneyBoxWindowId, FALSE); CopyWindowToVram(sMoneyBoxWindowId, 2); RemoveWindow(sMoneyBoxWindowId); } diff --git a/src/mystery_event_menu.c b/src/mystery_event_menu.c index 0de4675d9..ad4a2e692 100644 --- a/src/mystery_event_menu.c +++ b/src/mystery_event_menu.c @@ -90,7 +90,7 @@ void CB2_InitMysteryEventMenu(void) DeactivateAllTextPrinters(); for (i = 0; i < 2; i++) - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x1E, 0x14); LoadUserWindowBorderGfx(0, 1u, 0xD0u); @@ -133,7 +133,7 @@ static void CB2_MysteryEventMenu(void) switch (gMain.state) { case 0: - SetWindowBorderStyle(0, 1, 1, 0xD); + DrawStdFrameWithCustomTileAndPalette(0, 1, 1, 0xD); PutWindowTilemap(0); CopyWindowToVram(0, 3); ShowBg(0); @@ -179,8 +179,8 @@ static void CB2_MysteryEventMenu(void) if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - sub_800A620(); - SetWindowBorderStyle(1, 1, 1, 0xD); + CheckShouldAdvanceLinkState(); + DrawStdFrameWithCustomTileAndPalette(1, 1, 1, 0xD); PrintMysteryMenuText(1, gText_LoadingEvent, 1, 2, 0); PutWindowTilemap(1); CopyWindowToVram(1, 3); @@ -313,6 +313,6 @@ static void PrintMysteryMenuText(u8 windowId, const u8 *text, u8 x, u8 y, s32 sp textColor[1] = 2; textColor[2] = 3; - FillWindowPixelBuffer(windowId, (textColor[0]) | (textColor[0] << 4)); + FillWindowPixelBuffer(windowId, PIXEL_FILL(textColor[0])); AddTextPrinterParameterized4(windowId, 1, x, y, letterSpacing, lineSpacing, textColor, speed, text); } diff --git a/src/mystery_event_script.c b/src/mystery_event_script.c index 4196bb34c..dba914b51 100644 --- a/src/mystery_event_script.c +++ b/src/mystery_event_script.c @@ -17,8 +17,6 @@ #include "mystery_event_msg.h" #include "pokemon_storage_system.h" -extern void sub_811EFC0(u8); - extern ScrCmdFunc gMysteryEventScriptCmdTable[]; extern ScrCmdFunc gMysteryEventScriptCmdTableEnd[]; diff --git a/src/naming_screen.c b/src/naming_screen.c index c310ceb9f..22bbb84d7 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -557,7 +557,7 @@ static void DisplaySentToPCMessage(void) stringToDisplay++; StringExpandPlaceholders(gStringVar4, gUnknown_0858BDB8[stringToDisplay]); - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); gTextFlags.canABSpeedUpPrint = TRUE; AddTextPrinterParameterized2(0, 1, gStringVar4, GetPlayerTextSpeedDelay(), 0, 2, 1, 3); CopyWindowToVram(0, 3); @@ -1474,7 +1474,7 @@ static void HandleDpadMovement(struct Task *task) static void sub_80E4894(void) { - FillWindowPixelBuffer(gNamingScreenData->windows[3], 0x11); + FillWindowPixelBuffer(gNamingScreenData->windows[3], PIXEL_FILL(1)); AddTextPrinterParameterized(gNamingScreenData->windows[3], 1, gNamingScreenData->template->title, 8, 1, 0, 0); PutWindowTilemap(gNamingScreenData->windows[3]); } @@ -1485,7 +1485,7 @@ static void sub_80E48E8(void) StringCopy(buffer, gSpeciesNames[gNamingScreenData->monSpecies]); StringAppendN(buffer, gNamingScreenData->template->title, 15); - FillWindowPixelBuffer(gNamingScreenData->windows[3], 0x11); + FillWindowPixelBuffer(gNamingScreenData->windows[3], PIXEL_FILL(1)); AddTextPrinterParameterized(gNamingScreenData->windows[3], 1, buffer, 8, 1, 0, 0); PutWindowTilemap(gNamingScreenData->windows[3]); } @@ -1672,7 +1672,7 @@ static void sub_80E4D10(void) u8 maxChars = gNamingScreenData->template->maxChars; u16 unk = gNamingScreenData->inputCharBaseXPos - 0x40; - FillWindowPixelBuffer(gNamingScreenData->windows[2], 0x11); + FillWindowPixelBuffer(gNamingScreenData->windows[2], PIXEL_FILL(1)); for (i = 0; i < maxChars; i++) { @@ -1704,7 +1704,9 @@ static const struct TextColorThing sUnkColorStruct = static const u8 sFillValues[3] = { - 0xEE, 0xDD, 0xFF + PIXEL_FILL(0xE), + PIXEL_FILL(0xD), + PIXEL_FILL(0xF) }; static const u8 *const sUnkColors[3] = @@ -1766,7 +1768,7 @@ static void sub_80E4EF0(void) { const u8 color[3] = { 15, 1, 2 }; - FillWindowPixelBuffer(gNamingScreenData->windows[4], 0xFF); + FillWindowPixelBuffer(gNamingScreenData->windows[4], PIXEL_FILL(15)); AddTextPrinterParameterized3(gNamingScreenData->windows[4], 0, 2, 1, color, 0, gText_MoveOkBack); PutWindowTilemap(gNamingScreenData->windows[4]); CopyWindowToVram(gNamingScreenData->windows[4], 3); diff --git a/src/normal.c b/src/normal.c index 87c8792f1..2b592e199 100644 --- a/src/normal.c +++ b/src/normal.c @@ -36,8 +36,6 @@ static void sub_81162F8(u8); static void sub_81163D0(struct Sprite *); static void sub_81165E4(struct Sprite *); -extern void sub_810E2C8(struct Sprite *); - const union AnimCmd gUnknown_0859722C[] = { ANIMCMD_FRAME(0, 8), diff --git a/src/option_menu.c b/src/option_menu.c index 122ba8d8a..2fc0d6f3e 100644 --- a/src/option_menu.c +++ b/src/option_menu.c @@ -13,8 +13,7 @@ #include "text_window.h" #include "international_string_util.h" #include "strings.h" - -extern void SetPokemonCryStereo(u32 val); +#include "gba/m4a_internal.h" // Task data enum @@ -620,7 +619,7 @@ static void ButtonMode_DrawChoices(u8 selection) static void DrawTextOption(void) { - FillWindowPixelBuffer(WIN_TEXT_OPTION, 0x11); + FillWindowPixelBuffer(WIN_TEXT_OPTION, PIXEL_FILL(1)); AddTextPrinterParameterized(WIN_TEXT_OPTION, 1, gText_Option, 8, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(WIN_TEXT_OPTION, 3); } @@ -629,7 +628,7 @@ static void DrawOptionMenuTexts(void) { u8 i; - FillWindowPixelBuffer(WIN_OPTIONS, 0x11); + FillWindowPixelBuffer(WIN_OPTIONS, PIXEL_FILL(1)); for (i = 0; i < MENUITEM_COUNT; i++) { AddTextPrinterParameterized(WIN_OPTIONS, 1, sOptionMenuItemsNames[i], 8, (i * 16) + 1, TEXT_SPEED_FF, NULL); diff --git a/src/overworld.c b/src/overworld.c index a10d1e17a..0ff8d5b7f 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -66,32 +66,47 @@ #include "constants/species.h" #include "constants/weather.h" +#define PLAYER_TRADING_STATE_IDLE 0x80 +#define PLAYER_TRADING_STATE_BUSY 0x81 +#define PLAYER_TRADING_STATE_UNK_2 0x82 +#define PLAYER_TRADING_STATE_EXITING_ROOM 0x83 + +#define FACING_NONE 0 +#define FACING_UP 1 +#define FACING_DOWN 2 +#define FACING_LEFT 3 +#define FACING_RIGHT 4 +#define FACING_FORCED_UP 7 +#define FACING_FORCED_DOWN 8 +#define FACING_FORCED_LEFT 9 +#define FACING_FORCED_RIGHT 10 + // event scripts extern const u8 EventScript_WhiteOut[]; -extern const u8 EventScript_271862[]; -extern const u8 EventScript_277513[]; -extern const u8 EventScript_TradeRoom_TooBusyToNotice[]; -extern const u8 EventScript_TradeRoom_ReadTrainerCard1[]; -extern const u8 EventScript_TradeRoom_ReadTrainerCard2[]; -extern const u8 gUnknown_08277388[]; -extern const u8 gUnknown_082773A3[]; -extern const u8 gUnknown_082773BE[]; -extern const u8 gUnknown_082773D9[]; -extern const u8 gUnknown_0827741D[]; -extern const u8 gUnknown_08277432[]; -extern const u8 gUnknown_08277447[]; -extern const u8 gUnknown_0827745C[]; -extern const u8 gUnknown_08277374[]; -extern const u8 gUnknown_0827737E[]; -extern const u8 gUnknown_082773FF[]; -extern const u8 gUnknown_082773F5[]; -extern const u8 gUnknown_082774EF[]; -extern const u8 gUnknown_08277509[]; +extern const u8 EventScript_ResetMrBriney[]; +extern const u8 EventScript_DoLinkRoomExit[]; +extern const u8 gEventScript_TradeRoom_TooBusyToNotice[]; +extern const u8 gEventScript_TradeRoom_ReadTrainerCard_NoColor[]; +extern const u8 gEventScript_TradeRoom_ReadTrainerCard_Normal[]; +extern const u8 EventScript_DoubleBattleColosseum_PlayerSpot0[]; +extern const u8 EventScript_DoubleBattleColosseum_PlayerSpot1[]; +extern const u8 EventScript_DoubleBattleColosseum_PlayerSpot2[]; +extern const u8 EventScript_DoubleBattleColosseum_PlayerSpot3[]; +extern const u8 EventScript_RecordCenter_Spot0[]; +extern const u8 EventScript_RecordCenter_Spot1[]; +extern const u8 EventScript_RecordCenter_Spot2[]; +extern const u8 EventScript_RecordCenter_Spot3[]; +extern const u8 EventScript_SingleBattleColosseum_PlayerSpot0[]; +extern const u8 EventScript_SingleBattleColosseum_PlayerSpot1[]; +extern const u8 EventScript_TradeCenter_Chair1[]; +extern const u8 EventScript_TradeCenter_Chair0[]; +extern const u8 EventScript_ConfirmLeaveTradeRoom[]; +extern const u8 EventScript_TerminateLink[]; extern const struct MapLayout *const gMapLayouts[]; extern const struct MapHeader *const *const gMapGroups[]; extern const int gMaxFlashLevel; -extern const u16 gUnknown_82EC7C4[]; +extern const u16 gOverworldBackgroundLayerFlags[]; static void Overworld_ResetStateAfterWhiteOut(void); static void c2_80567AC(void); @@ -106,63 +121,63 @@ static bool32 load_map_stuff(u8 *state, u32); static bool32 map_loading_iteration_2_link(u8 *state); static void mli4_mapscripts_and_other(void); static void InitOverworldGraphicsRegisters(void); -static u8 sub_8087858(u8); -static u16 sub_80871C0(u32 a1); +static u8 GetSpriteForLinkedPlayer(u8); +static u16 KeyInterCB_SendNothing(u32 a1); static void sub_80867C8(void); static void sub_80867D8(void); static void sub_8086AE4(void); static void sub_80869DC(void); static void sub_8086B14(void); -static void sub_8086AAC(void); +static void SetCameraToTrackGuestPlayer(void); static void sub_8086988(bool32 arg0); static void sub_8086A80(void); static void sub_8086A68(void); static void sub_8086860(void); -static void sub_8086AC8(void); -static void sub_8086B9C(void); -static void sub_8086C40(void); -static void sub_8086C90(void); -static void sub_8086FA0(u16); -static void sub_8086F38(u16*, s32); -static u8 npc_something3(u8 a1, u8 a2); +static void SetCameraToTrackGuestPlayer_2(void); +static void CreateLinkPlayerSprites(void); +static void ClearAllPlayerKeys(void); +static void ResetAllTradingStates(void); +static void UpdateHeldKeyCode(u16); +static void UpdateAllLinkPlayers(u16*, s32); +static u8 FlipVerticalAndClearForced(u8 a1, u8 a2); static u8 LinkPlayerDetectCollision(u8 selfEventObjId, u8 a2, s16 x, s16 y); static void CreateLinkPlayerSprite(u8 linkPlayerId, u8 gameVersion); -static void sub_8087878(u8 linkPlayerId, u16 *x, u16 *y); -static u8 sub_80878A0(u8 linkPlayerId); -static u8 sub_80878C0(u8 linkPlayerId); +static void GetLinkPlayerCoords(u8 linkPlayerId, u16 *x, u16 *y); +static u8 GetLinkPlayerFacingDirection(u8 linkPlayerId); +static u8 GetLinkPlayerElevation(u8 linkPlayerId); static s32 sub_80878E4(u8 linkPlayerId); static u8 GetLinkPlayerIdAt(s16 x, s16 y); -static void sub_808796C(u8 linkPlayerId, u8 a2); +static void SetPlayerFacingDirection(u8 linkPlayerId, u8 a2); static void ZeroEventObject(struct EventObject *eventObj); static void SpawnLinkPlayerEventObject(u8 linkPlayerId, s16 x, s16 y, u8 a4); static void InitLinkPlayerEventObjectPos(struct EventObject *eventObj, s16 x, s16 y); static void sub_80877DC(u8 linkPlayerId, u8 a2); static void sub_808780C(u8 linkPlayerId); -static u8 sub_8087858(u8 linkPlayerId); +static u8 GetSpriteForLinkedPlayer(u8 linkPlayerId); static void sub_8087584(void); -static u32 sub_8087690(void); +static u32 GetLinkSendQueueLength(void); static void ZeroLinkPlayerEventObject(struct LinkPlayerEventObject *linkPlayerEventObj); -static const u8 *sub_80873B4(struct UnkStruct_8054FF8 *a1); -static u16 sub_8087480(const u8 *script); +static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *a1); +static u16 GetDirectionForEventScript(const u8 *script); static void sub_8087510(void); -static void sub_808751C(void); +static void InitLinkRoomStartMenuScript(void); static void sub_8087530(const u8 *script); -static void sub_808754C(void); -static void sub_8087568(const u8 *script); -static void sub_80872D8(s32 linkPlayerId, s32 a2, struct UnkStruct_8054FF8 *a3); -static bool32 sub_8087340(struct UnkStruct_8054FF8 *a1); -static bool32 sub_8087358(struct UnkStruct_8054FF8 *a1); -static u8 *sub_8087370(struct UnkStruct_8054FF8 *a1); -static bool32 sub_8087388(struct UnkStruct_8054FF8 *a1); -static const u8 *sub_80873B4(struct UnkStruct_8054FF8 *a1); -static u16 sub_808711C(u32); -static u16 sub_8087140(u32); -static void sub_808709C(u16 *a1); -static u16 sub_80870B0(u32 a1); -static u16 sub_80870F8(u32 a1); -static u16 sub_8087068(u16 a1); -static void c1_link_related(void); -static void c1_link_related_func_set(u16 (*func)(u32)); +static void CreateConfirmLeaveTradeRoomPrompt(void); +static void InitMenuBasedScript(const u8 *script); +static void LoadTradeRoomPlayer(s32 linkPlayerId, s32 a2, struct TradeRoomPlayer *a3); +static bool32 sub_8087340(struct TradeRoomPlayer *a1); +static bool32 sub_8087340_2(struct TradeRoomPlayer *a1); +static u8 *TryGetTileEventScript(struct TradeRoomPlayer *a1); +static bool32 PlayerIsAtSouthExit(struct TradeRoomPlayer *a1); +static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *a1); +static u16 KeyInterCB_DeferToRecvQueue(u32); +static u16 KeyInterCB_DeferToSendQueue(u32); +static void ResetPlayerHeldKeys(u16 *a1); +static u16 KeyInterCB_SelfIdle(u32 a1); +static u16 KeyInterCB_DeferToEventScript(u32 a1); +static u16 GetDirectionForDpadKey(u16 a1); +static void CB1_UpdateLinkState(void); +static void SetKeyInterceptCallback(u16 (*func)(u32)); static void SetFieldVBlankCallback(void); static void FieldClearVBlankHBlankCallbacks(void); static void sub_8085810(void); @@ -171,21 +186,24 @@ static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStr static u16 GetCenterScreenMetatileBehavior(void); // IWRAM bss vars -IWRAM_DATA static void *sUnknown_03000E0C; -IWRAM_DATA static u8 sUnknown_03000E10[4]; -IWRAM_DATA static u16 (*sUnknown_03000E14)(u32); -IWRAM_DATA static u8 sUnknown_03000E18; -IWRAM_DATA static u8 sUnknown_03000E19; +IWRAM_DATA static void *sUnusedOverworldCallback; +IWRAM_DATA static u8 sPlayerTradingStates[4]; +// This callback is called with a player's key code. It then returns an +// adjusted key code, effectively intercepting the input before anything +// can process it. +IWRAM_DATA static u16 (*sPlayerKeyInterceptCallback)(u32); +IWRAM_DATA static bool8 sUnknown_03000E18; +IWRAM_DATA static u8 sRfuKeepAliveTimer; IWRAM_DATA static u32 sUnusedVar; // IWRAM common u16 *gBGTilemapBuffers1; u16 *gBGTilemapBuffers2; u16 *gBGTilemapBuffers3; -u16 gUnknown_03005DA8; +u16 gHeldKeyCodeToSend; void (*gFieldCallback)(void); bool8 (*gFieldCallback2)(void); -u8 gUnknown_03005DB4; +u8 gLocalLinkPlayerId; // This is our player id in a multiplayer mode. u8 gFieldLinkPlayerCount; // EWRAM vars @@ -319,43 +337,47 @@ static const struct ScanlineEffectParams sFlashEffectParams = 0, }; -static u8 sub_80879D8(struct LinkPlayerEventObject *, struct EventObject *, u8); -static u8 sub_80879F8(struct LinkPlayerEventObject *, struct EventObject *, u8); -static u8 sub_80879FC(struct LinkPlayerEventObject *, struct EventObject *, u8); +static u8 MovementEventModeCB_Normal(struct LinkPlayerEventObject *, struct EventObject *, u8); +static u8 MovementEventModeCB_Ignored(struct LinkPlayerEventObject *, struct EventObject *, u8); +static u8 MovementEventModeCB_Normal_2(struct LinkPlayerEventObject *, struct EventObject *, u8); -static u8 (*const gUnknown_08339DC8[])(struct LinkPlayerEventObject *, struct EventObject *, u8) = +static u8 (*const gLinkPlayerMovementModes[])(struct LinkPlayerEventObject *, struct EventObject *, u8) = { - sub_80879D8, - sub_80879F8, - sub_80879FC, + MovementEventModeCB_Normal, // MOVEMENT_MODE_FREE + MovementEventModeCB_Ignored, // MOVEMENT_MODE_FROZEN + MovementEventModeCB_Normal_2, // MOVEMENT_MODE_SCRIPTED }; -static u8 sub_8087A1C(struct LinkPlayerEventObject *, struct EventObject *, u8); -static u8 sub_8087A20(struct LinkPlayerEventObject *, struct EventObject *, u8); -static u8 sub_8087A88(struct LinkPlayerEventObject *, struct EventObject *, u8); - -static u8 (*const gUnknown_08339DD4[])(struct LinkPlayerEventObject *, struct EventObject *, u8) = -{ - sub_8087A1C, - sub_8087A20, - sub_8087A20, - sub_8087A20, - sub_8087A20, - sub_8087A1C, - sub_8087A1C, - sub_8087A88, - sub_8087A88, - sub_8087A88, - sub_8087A88, +static u8 FacingHandler_DoNothing(struct LinkPlayerEventObject *, struct EventObject *, u8); +static u8 FacingHandler_DpadMovement(struct LinkPlayerEventObject *, struct EventObject *, u8); +static u8 FacingHandler_ForcedFacingChange(struct LinkPlayerEventObject *, struct EventObject *, u8); + +// These handlers return TRUE if the movement was scripted and successful, and FALSE otherwise. +static bool8 (*const gLinkPlayerFacingHandlers[])(struct LinkPlayerEventObject *, struct EventObject *, u8) = +{ + FacingHandler_DoNothing, + FacingHandler_DpadMovement, + FacingHandler_DpadMovement, + FacingHandler_DpadMovement, + FacingHandler_DpadMovement, + FacingHandler_DoNothing, + FacingHandler_DoNothing, + FacingHandler_ForcedFacingChange, + FacingHandler_ForcedFacingChange, + FacingHandler_ForcedFacingChange, + FacingHandler_ForcedFacingChange, }; -static void sub_8087AA0(struct LinkPlayerEventObject *, struct EventObject *); -static void sub_8087AA8(struct LinkPlayerEventObject *, struct EventObject *); +static void MovementStatusHandler_EnterFreeMode(struct LinkPlayerEventObject *, struct EventObject *); +static void MovementStatusHandler_TryAdvanceScript(struct LinkPlayerEventObject *, struct EventObject *); -static void (*const gUnknown_08339E00[])(struct LinkPlayerEventObject *, struct EventObject *) = +// These handlers are run after an attempted movement. +static void (*const gMovementStatusHandler[])(struct LinkPlayerEventObject *, struct EventObject *) = { - sub_8087AA0, - sub_8087AA8, + // FALSE: + MovementStatusHandler_EnterFreeMode, + // TRUE: + MovementStatusHandler_TryAdvanceScript, }; // code @@ -387,7 +409,7 @@ void Overworld_ResetStateAfterTeleport(void) FlagClear(FLAG_SYS_SAFARI_MODE); FlagClear(FLAG_SYS_USE_STRENGTH); FlagClear(FLAG_SYS_USE_FLASH); - ScriptContext2_RunNewScript(EventScript_271862); + ScriptContext2_RunNewScript(EventScript_ResetMrBriney); } void Overworld_ResetStateAfterDigEscRope(void) @@ -408,10 +430,12 @@ static void Overworld_ResetStateAfterWhiteOut(void) FlagClear(FLAG_SYS_SAFARI_MODE); FlagClear(FLAG_SYS_USE_STRENGTH); FlagClear(FLAG_SYS_USE_FLASH); - if (VarGet(VAR_0x4039) == 1) + // If you were defeated by Kyogre/Groudon and the step counter has + // maxed out, end the unusual weather. + if (VarGet(VAR_SHOULD_END_UNUSUAL_WEATHER) == 1) { - VarSet(VAR_0x4039, 0); - VarSet(VAR_0x4037, 0); + VarSet(VAR_SHOULD_END_UNUSUAL_WEATHER, 0); + VarSet(VAR_UNUSUAL_WEATHER_LOCATION, UNUSUAL_WEATHER_NONE); } } @@ -676,7 +700,7 @@ void UpdateEscapeWarp(s16 x, s16 y) { u8 currMapType = GetCurrentMapType(); u8 destMapType = GetMapTypeByGroupAndId(sWarpDestination.mapGroup, sWarpDestination.mapNum); - if (is_map_type_1_2_3_5_or_6(currMapType) && is_map_type_1_2_3_5_or_6(destMapType) != TRUE) + if (IsMapTypeOutdoors(currMapType) && IsMapTypeOutdoors(destMapType) != TRUE) SetEscapeWarp(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, -1, x - 7, y - 6); } @@ -821,8 +845,8 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) static void mli0_load_map(u32 a1) { - bool8 v2; - bool8 indoors; + bool8 isOutdoors; + bool8 isIndoors; LoadCurrentMapData(); if (!(sUnknown_020322D8 & 1)) @@ -835,8 +859,8 @@ static void mli0_load_map(u32 a1) LoadEventObjTemplatesFromHeader(); } - v2 = is_map_type_1_2_3_5_or_6(gMapHeader.mapType); - indoors = Overworld_MapTypeIsIndoors(gMapHeader.mapType); + isOutdoors = IsMapTypeOutdoors(gMapHeader.mapType); + isIndoors = IsMapTypeIndoors(gMapHeader.mapType); sub_80EB218(); TrySetMapSaveWarpStatus(); @@ -848,7 +872,7 @@ static void mli0_load_map(u32 a1) DoTimeBasedEvents(); SetSav1WeatherFromCurrMapHeader(); ChooseAmbientCrySpecies(); - if (v2) + if (isOutdoors) FlagClear(FLAG_SYS_USE_FLASH); SetDefaultFlashLevel(); Overworld_ClearSavedMusic(); @@ -862,7 +886,7 @@ static void mli0_load_map(u32 a1) else InitMap(); - if (a1 != 1 && indoors) + if (a1 != 1 && isIndoors) { UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height); sub_80E9238(1); @@ -923,7 +947,7 @@ static u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *pla static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStruct, u8 transitionFlags, u16 metatileBehavior, u8 mapType) { - if (FlagGet(FLAG_SYS_CRUISE_MODE) && mapType == MAP_TYPE_6) + if (FlagGet(FLAG_SYS_CRUISE_MODE) && mapType == MAP_TYPE_OCEAN_ROUTE) return DIR_EAST; else if (MetatileBehavior_IsDeepSouthWarp(metatileBehavior) == TRUE) return DIR_NORTH; @@ -1016,7 +1040,7 @@ static bool16 ShouldLegendaryMusicPlayAtLocation(struct WarpData *warp) case MAP_NUM(ROUTE128): return TRUE; default: - if (VarGet(VAR_0x405E) < 4) + if (VarGet(VAR_RAYQUAZA_STATE) < 4) return FALSE; switch (warp->mapNum) { @@ -1032,7 +1056,7 @@ static bool16 ShouldLegendaryMusicPlayAtLocation(struct WarpData *warp) static bool16 NoMusicInSotopolisWithLegendaries(struct WarpData *warp) { - if (VarGet(VAR_0x40CA) != 1) + if (VarGet(VAR_SKY_PILLAR_STATE) != 1) return FALSE; else if (warp->mapGroup != MAP_GROUP(SOOTOPOLIS_CITY)) return FALSE; @@ -1057,9 +1081,9 @@ static bool16 IsInfiltratedWeatherInstitute(struct WarpData *warp) static bool16 IsInflitratedSpaceCenter(struct WarpData *warp) { - if (VarGet(VAR_0x405D) == 0) + if (VarGet(VAR_MOSSDEEP_STATE) == 0) return FALSE; - else if (VarGet(VAR_0x405D) > 2) + else if (VarGet(VAR_MOSSDEEP_STATE) > 2) return FALSE; else if (warp->mapGroup != MAP_GROUP(MOSSDEEP_CITY_SPACE_CENTER_1F)) return FALSE; @@ -1197,7 +1221,7 @@ void Overworld_ChangeMusicTo(u16 newMusic) u8 GetMapMusicFadeoutSpeed(void) { const struct MapHeader *mapHeader = GetDestinationWarpMapHeader(); - if (Overworld_MapTypeIsIndoors(mapHeader->mapType) == TRUE) + if (IsMapTypeIndoors(mapHeader->mapType) == TRUE) return 2; else return 4; @@ -1210,7 +1234,7 @@ void TryFadeOutOldMapMusic(void) if (FlagGet(FLAG_SPECIAL_FLAG_0x4001) != TRUE && warpMusic != GetCurrentMapMusic()) { if (currentMusic == MUS_NAMINORI - && VarGet(VAR_0x40CA) == 2 + && VarGet(VAR_SKY_PILLAR_STATE) == 2 && gSaveBlock1Ptr->location.mapGroup == MAP_GROUP(SOOTOPOLIS_CITY) && gSaveBlock1Ptr->location.mapNum == MAP_NUM(SOOTOPOLIS_CITY) && sWarpDestination.mapGroup == MAP_GROUP(SOOTOPOLIS_CITY) @@ -1328,13 +1352,13 @@ u8 GetLastUsedWarpMapType(void) return GetMapTypeByWarpData(&gLastUsedWarp); } -bool8 is_map_type_1_2_3_5_or_6(u8 mapType) +bool8 IsMapTypeOutdoors(u8 mapType) { if (mapType == MAP_TYPE_ROUTE || mapType == MAP_TYPE_TOWN || mapType == MAP_TYPE_UNDERWATER || mapType == MAP_TYPE_CITY - || mapType == MAP_TYPE_6) + || mapType == MAP_TYPE_OCEAN_ROUTE) return TRUE; else return FALSE; @@ -1344,14 +1368,14 @@ bool8 Overworld_MapTypeAllowsTeleportAndFly(u8 mapType) { if (mapType == MAP_TYPE_ROUTE || mapType == MAP_TYPE_TOWN - || mapType == MAP_TYPE_6 + || mapType == MAP_TYPE_OCEAN_ROUTE || mapType == MAP_TYPE_CITY) return TRUE; else return FALSE; } -bool8 Overworld_MapTypeIsIndoors(u8 mapType) +bool8 IsMapTypeIndoors(u8 mapType) { if (mapType == MAP_TYPE_INDOOR || mapType == MAP_TYPE_SECRET_BASE) @@ -1407,9 +1431,9 @@ static void ResetSafariZoneFlag_(void) ResetSafariZoneFlag(); } -bool32 is_c1_link_related_active(void) +bool32 IsUpdateLinkStateCBActive(void) { - if (gMain.callback1 == c1_link_related) + if (gMain.callback1 == CB1_UpdateLinkState) return TRUE; else return FALSE; @@ -1476,9 +1500,10 @@ void SetMainCallback1(MainCallback cb) gMain.callback1 = cb; } -void sub_8085E94(void *a0) +// This function is never called. +void SetUnusedCallback(void *func) { - sUnknown_03000E0C = a0; + sUnusedOverworldCallback = func; } static bool8 map_post_load_hook_exec(void) @@ -1595,15 +1620,15 @@ static void c2_80567AC(void) if (map_loading_iteration_3(&gMain.state)) { SetFieldVBlankCallback(); - SetMainCallback1(c1_link_related); - sub_8086C2C(); + SetMainCallback1(CB1_UpdateLinkState); + ResetAllMultiplayerState(); SetMainCallback2(CB2_Overworld); } } void CB2_ReturnToField(void) { - if (is_c1_link_related_active() == TRUE) + if (IsUpdateLinkStateCBActive() == TRUE) { SetMainCallback2(CB2_ReturnToFieldLink); } @@ -1629,12 +1654,12 @@ void CB2_ReturnToFieldLink(void) SetMainCallback2(CB2_Overworld); } -void c2_8056854(void) +void CB2_ReturnToFieldFromMultiplayer(void) { FieldClearVBlankHBlankCallbacks(); StopMapMusic(); - SetMainCallback1(c1_link_related); - sub_8086C2C(); + SetMainCallback1(CB1_UpdateLinkState); + ResetAllMultiplayerState(); if (gWirelessCommType != 0) gFieldCallback = sub_80AF314; @@ -1810,7 +1835,7 @@ static bool32 map_loading_iteration_3(u8 *state) sub_8086AE4(); sub_80869DC(); sub_8086B14(); - sub_8086AAC(); + SetCameraToTrackGuestPlayer(); (*state)++; break; case 4: @@ -1980,9 +2005,9 @@ static bool32 map_loading_iteration_2_link(u8 *state) (*state)++; break; case 2: - sub_8086B9C(); + CreateLinkPlayerSprites(); sub_8086A68(); - sub_8086AC8(); + SetCameraToTrackGuestPlayer_2(); (*state)++; break; case 3: @@ -2083,7 +2108,7 @@ static void InitOverworldGraphicsRegisters(void) SetGpuReg(REG_OFFSET_WIN0V, 0xFF); SetGpuReg(REG_OFFSET_WIN1H, 0xFFFF); SetGpuReg(REG_OFFSET_WIN1V, 0xFFFF); - SetGpuReg(REG_OFFSET_BLDCNT, gUnknown_82EC7C4[1] | gUnknown_82EC7C4[2] | gUnknown_82EC7C4[3] + SetGpuReg(REG_OFFSET_BLDCNT, gOverworldBackgroundLayerFlags[1] | gOverworldBackgroundLayerFlags[2] | gOverworldBackgroundLayerFlags[3] | BLDCNT_TGT2_OBJ | BLDCNT_EFFECT_BLEND); SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(13, 7)); InitOverworldBgs(); @@ -2169,21 +2194,25 @@ static void sub_8086A80(void) InitCameraUpdateCallback(gPlayerAvatar.spriteId); } -static void sub_8086AAC(void) +static void SetCameraToTrackGuestPlayer(void) { - InitCameraUpdateCallback(sub_8087858(gUnknown_03005DB4)); + InitCameraUpdateCallback(GetSpriteForLinkedPlayer(gLocalLinkPlayerId)); } -static void sub_8086AC8(void) +// Duplicate function. +static void SetCameraToTrackGuestPlayer_2(void) { - InitCameraUpdateCallback(sub_8087858(gUnknown_03005DB4)); + InitCameraUpdateCallback(GetSpriteForLinkedPlayer(gLocalLinkPlayerId)); } static void sub_8086AE4(void) { u16 x, y; GetCameraFocusCoords(&x, &y); - sub_8088B3C(x + gUnknown_03005DB4, y); + + // This is a hack of some kind; it's undone in sub_8086B14, which is called + // soon after this function. + sub_8088B3C(x + gLocalLinkPlayerId, y); } static void sub_8086B14(void) @@ -2192,7 +2221,7 @@ static void sub_8086B14(void) u16 x, y; GetCameraFocusCoords(&x, &y); - x -= gUnknown_03005DB4; + x -= gLocalLinkPlayerId; for (i = 0; i < gFieldLinkPlayerCount; i++) { @@ -2200,161 +2229,180 @@ static void sub_8086B14(void) CreateLinkPlayerSprite(i, gLinkPlayers[i].version); } - sub_8086C40(); + ClearAllPlayerKeys(); } -static void sub_8086B9C(void) +static void CreateLinkPlayerSprites(void) { u16 i; for (i = 0; i < gFieldLinkPlayerCount; i++) CreateLinkPlayerSprite(i, gLinkPlayers[i].version); } -static void c1_link_related(void) + +static void CB1_UpdateLinkState(void) { - if (gWirelessCommType == 0 || !sub_800F0B8() || !sub_8009F3C()) + if (gWirelessCommType == 0 || !IsRfuRecvQueueEmpty() || !IsSendingKeysToLink()) { - u8 var = gUnknown_03005DB4; - sub_8086F38(gLinkPartnersHeldKeys, var); - sub_8086FA0(sUnknown_03000E14(var)); - sub_8086C40(); + u8 selfId = gLocalLinkPlayerId; + UpdateAllLinkPlayers(gLinkPartnersHeldKeys, selfId); + + // Note: Because guestId is between 0 and 4, while the smallest key code is + // LINK_KEY_CODE_EMPTY, this is functionally equivalent to `sPlayerKeyInterceptCallback(0)`. + // It is expecting the callback to be KeyInterCB_SelfIdle, and that will + // completely ignore any input parameters. + // + // UpdateHeldKeyCode performs a sanity check on its input; if + // sPlayerKeyInterceptCallback echoes back the argument, which is selfId, then + // it'll use LINK_KEY_CODE_EMPTY instead. + // + // Note 2: There are some key intercept callbacks that treat the key as a player + // ID. It's so hacky. + UpdateHeldKeyCode(sPlayerKeyInterceptCallback(selfId)); + ClearAllPlayerKeys(); } } -void sub_8086C2C(void) +void ResetAllMultiplayerState(void) { - sub_8086C90(); - c1_link_related_func_set(sub_80870B0); + ResetAllTradingStates(); + SetKeyInterceptCallback(KeyInterCB_SelfIdle); } -static void sub_8086C40(void) +static void ClearAllPlayerKeys(void) { - sub_808709C(gLinkPartnersHeldKeys); + ResetPlayerHeldKeys(gLinkPartnersHeldKeys); } -static void c1_link_related_func_set(u16 (*func)(u32)) +static void SetKeyInterceptCallback(u16 (*func)(u32)) { - sUnknown_03000E19 = 0; - sUnknown_03000E14 = func; + sRfuKeepAliveTimer = 0; + sPlayerKeyInterceptCallback = func; } -static void sub_8086C64(void) +// Once every ~60 frames, if the link state hasn't changed (timer reset by calls +// to SetKeyInterceptCallback), it does a bunch of sanity checks on the connection. +// I'm not sure if sRfuKeepAliveTimer is reset in the process, though; rfu stuff is +// still undocumented. +static void CheckRfuKeepAliveTimer(void) { - if (gWirelessCommType != 0 && ++sUnknown_03000E19 > 60) + if (gWirelessCommType != 0 && ++sRfuKeepAliveTimer > 60) sub_8010198(); } -static void sub_8086C90(void) +static void ResetAllTradingStates(void) { s32 i; for (i = 0; i < 4; i++) - sUnknown_03000E10[i] = 0x80; + sPlayerTradingStates[i] = PLAYER_TRADING_STATE_IDLE; } -static bool32 sub_8086CA8(u16 a1) +// Returns true if all connected players are in tradingState. +static bool32 AreAllPlayersInTradingState(u16 tradingState) { s32 i; s32 count = gFieldLinkPlayerCount; for (i = 0; i < count; i++) - if (sUnknown_03000E10[i] != a1) + if (sPlayerTradingStates[i] != tradingState) return FALSE; return TRUE; } -static bool32 sub_8086CE0(u16 a1) +static bool32 IsAnyPlayerInTradingState(u16 tradingState) { s32 i; s32 count = gFieldLinkPlayerCount; for (i = 0; i < count; i++) - if (sUnknown_03000E10[i] == a1) + if (sPlayerTradingStates[i] == tradingState) return TRUE; return FALSE; } -static void sub_8086D18(u32 a1, u16 a2, struct UnkStruct_8054FF8 *a3, u16 *a4) +static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlayer *trainer, u16 *forceFacing) { const u8 *script; - if (sUnknown_03000E10[a1] == 0x80) + if (sPlayerTradingStates[playerId] == PLAYER_TRADING_STATE_IDLE) { - script = sub_8087370(a3); + script = TryGetTileEventScript(trainer); if (script) { - *a4 = sub_8087480(script); - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + *forceFacing = GetDirectionForEventScript(script); + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_80870F8); + SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); sub_8087530(script); } return; } - if (sub_8086CE0(0x83) == 1) + if (IsAnyPlayerInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM) == TRUE) { - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_80870F8); + SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); sub_8087584(); } return; } - switch (a2) + + switch (key) { - case 24: - if (sub_8087358(a3)) + case LINK_KEY_CODE_START_BUTTON: + if (sub_8087340_2(trainer)) { - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_80870F8); - sub_808751C(); + SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); + InitLinkRoomStartMenuScript(); } } break; - case 18: - if (sub_8087388(a3) == TRUE) + case LINK_KEY_CODE_DPAD_DOWN: + if (PlayerIsAtSouthExit(trainer) == TRUE) { - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_80870F8); - sub_808754C(); + SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); + CreateConfirmLeaveTradeRoomPrompt(); } } break; - case 25: - script = sub_80873B4(a3); + case LINK_KEY_CODE_A_BUTTON: + script = TryInteractWithPlayer(trainer); if (script) { - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_80870F8); - sub_8087568(script); + SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); + InitMenuBasedScript(script); } } break; - case 27: - if (sub_8087340(a3)) + case LINK_KEY_CODE_HANDLE_RECV_QUEUE: + if (sub_8087340(trainer)) { - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_808711C); + SetKeyInterceptCallback(KeyInterCB_DeferToRecvQueue); sub_8087510(); } } break; - case 28: - if (sub_8087340(a3)) + case LINK_KEY_CODE_HANDLE_SEND_QUEUE: + if (sub_8087340(trainer)) { - sUnknown_03000E10[a1] = 0x81; - if (a3->b) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; + if (trainer->isLocalPlayer) { - c1_link_related_func_set(sub_8087140); + SetKeyInterceptCallback(KeyInterCB_DeferToSendQueue); sub_8087510(); } } @@ -2362,388 +2410,403 @@ static void sub_8086D18(u32 a1, u16 a2, struct UnkStruct_8054FF8 *a3, u16 *a4) } } - switch (a2) + switch (key) { - case 23: - sUnknown_03000E10[a1] = 0x83; + case LINK_KEY_CODE_EXIT_ROOM: + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_EXITING_ROOM; break; - case 22: - sUnknown_03000E10[a1] = 0x82; + case LINK_KEY_CODE_UNK_2: + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_UNK_2; break; - case 26: - sUnknown_03000E10[a1] = 0x80; - if (a3->b) - c1_link_related_func_set(sub_80870B0); + case LINK_KEY_CODE_UNK_4: + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_IDLE; + if (trainer->isLocalPlayer) + SetKeyInterceptCallback(KeyInterCB_SelfIdle); break; - case 29: - if (sUnknown_03000E10[a1] == 0x82) - sUnknown_03000E10[a1] = 0x81; + case LINK_KEY_CODE_UNK_7: + if (sPlayerTradingStates[playerId] == PLAYER_TRADING_STATE_UNK_2) + sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY; break; } } -static void sub_8086F38(u16 *a1, s32 a2) +static void UpdateAllLinkPlayers(u16 *keys, s32 selfId) { - struct UnkStruct_8054FF8 st; + struct TradeRoomPlayer trainer; s32 i; for (i = 0; i < 4; i++) { - u8 v5 = a1[i]; - u16 v8 = 0; - sub_80872D8(i, a2, &st); - sub_8086D18(i, v5, &st, &v8); - if (sUnknown_03000E10[i] == 0x80) - v8 = sub_8087068(v5); - sub_808796C(i, v8); + u8 key = keys[i]; + u16 setFacing = FACING_NONE; + LoadTradeRoomPlayer(i, selfId, &trainer); + HandleLinkPlayerKeyInput(i, key, &trainer, &setFacing); + if (sPlayerTradingStates[i] == PLAYER_TRADING_STATE_IDLE) + setFacing = GetDirectionForDpadKey(key); + SetPlayerFacingDirection(i, setFacing); } } -static void sub_8086FA0(u16 a1) +static void UpdateHeldKeyCode(u16 key) { - if (a1 >= 17 && a1 < 30) - gUnknown_03005DA8 = a1; + if (key >= LINK_KEY_CODE_EMPTY && key < LINK_KEY_CODE_UNK_8) + gHeldKeyCodeToSend = key; else - gUnknown_03005DA8 = 17; + gHeldKeyCodeToSend = LINK_KEY_CODE_EMPTY; if (gWirelessCommType != 0 - && sub_8087690() > 1 - && is_c1_link_related_active() == TRUE - && sub_8009F3C() == TRUE) + && GetLinkSendQueueLength() > 1 + && IsUpdateLinkStateCBActive() == TRUE + && IsSendingKeysToLink() == TRUE) { - switch (a1) + switch (key) { - case 17: - case 18: - case 19: - case 20: - case 21: - case 24: - case 25: - gUnknown_03005DA8 = 0; + case LINK_KEY_CODE_EMPTY: + case LINK_KEY_CODE_DPAD_DOWN: + case LINK_KEY_CODE_DPAD_UP: + case LINK_KEY_CODE_DPAD_LEFT: + case LINK_KEY_CODE_DPAD_RIGHT: + case LINK_KEY_CODE_START_BUTTON: + case LINK_KEY_CODE_A_BUTTON: + gHeldKeyCodeToSend = LINK_KEY_CODE_NULL; break; } } } -static u16 sub_808700C(u32 a1) +static u16 KeyInterCB_ReadButtons(u32 key) { if (gMain.heldKeys & DPAD_UP) - return 19; + return LINK_KEY_CODE_DPAD_UP; else if (gMain.heldKeys & DPAD_DOWN) - return 18; + return LINK_KEY_CODE_DPAD_DOWN; else if (gMain.heldKeys & DPAD_LEFT) - return 20; + return LINK_KEY_CODE_DPAD_LEFT; else if (gMain.heldKeys & DPAD_RIGHT) - return 21; + return LINK_KEY_CODE_DPAD_RIGHT; else if (gMain.newKeys & START_BUTTON) - return 24; + return LINK_KEY_CODE_START_BUTTON; else if (gMain.newKeys & A_BUTTON) - return 25; + return LINK_KEY_CODE_A_BUTTON; else - return 17; + return LINK_KEY_CODE_EMPTY; } -static u16 sub_8087068(u16 a1) +static u16 GetDirectionForDpadKey(u16 a1) { switch (a1) { - case 21: - return 4; - case 20: - return 3; - case 19: - return 1; - case 18: - return 2; + case LINK_KEY_CODE_DPAD_RIGHT: + return FACING_RIGHT; + case LINK_KEY_CODE_DPAD_LEFT: + return FACING_LEFT; + case LINK_KEY_CODE_DPAD_UP: + return FACING_UP; + case LINK_KEY_CODE_DPAD_DOWN: + return FACING_DOWN; default: - return 0; + return FACING_NONE; } } -static void sub_808709C(u16 *a1) +// Overwrites the keys with 0x11 +static void ResetPlayerHeldKeys(u16 *keys) { s32 i; for (i = 0; i < 4; i++) - a1[i] = 17; + keys[i] = LINK_KEY_CODE_EMPTY; } -static u16 sub_80870B0(u32 a1) + +static u16 KeyInterCB_SelfIdle(u32 key) { - if (ScriptContext2_IsEnabled() == 1) - return 17; - if (sub_800B4DC() > 4) - return 27; - if (sub_8087690() <= 4) - return sub_808700C(a1); - return 28; + if (ScriptContext2_IsEnabled() == TRUE) + return LINK_KEY_CODE_EMPTY; + if (GetLinkRecvQueueLength() > 4) + return LINK_KEY_CODE_HANDLE_RECV_QUEUE; + if (GetLinkSendQueueLength() <= 4) + return KeyInterCB_ReadButtons(key); + return LINK_KEY_CODE_HANDLE_SEND_QUEUE; } -static u16 sub_80870EC(u32 a1) +static u16 sub_80870EC(u32 key) { - sub_8086C64(); - return 17; + CheckRfuKeepAliveTimer(); + return LINK_KEY_CODE_EMPTY; } -static u16 sub_80870F8(u32 a1) +// Ignore the player's inputs as long as there is an event script +// in ScriptContext2. +static u16 KeyInterCB_DeferToEventScript(u32 key) { u16 retVal; if (ScriptContext2_IsEnabled() == TRUE) { - retVal = 17; + retVal = LINK_KEY_CODE_EMPTY; } else { - retVal = 26; - c1_link_related_func_set(sub_80870EC); + retVal = LINK_KEY_CODE_UNK_4; + SetKeyInterceptCallback(sub_80870EC); } return retVal; } -static u16 sub_808711C(u32 a1) +// Ignore the player's inputs as long as there are events being recived. +static u16 KeyInterCB_DeferToRecvQueue(u32 key) { u16 retVal; - if (sub_800B4DC() > 2) + if (GetLinkRecvQueueLength() > 2) { - retVal = 17; + retVal = LINK_KEY_CODE_EMPTY; } else { - retVal = 26; + retVal = LINK_KEY_CODE_UNK_4; ScriptContext2_Disable(); - c1_link_related_func_set(sub_80870EC); + SetKeyInterceptCallback(sub_80870EC); } return retVal; } -static u16 sub_8087140(u32 a1) +// Ignore the player's inputs as long as there are events being sent. +static u16 KeyInterCB_DeferToSendQueue(u32 key) { u16 retVal; - if (sub_8087690() > 2) + if (GetLinkSendQueueLength() > 2) { - retVal = 17; + retVal = LINK_KEY_CODE_EMPTY; } else { - retVal = 26; + retVal = LINK_KEY_CODE_UNK_4; ScriptContext2_Disable(); - c1_link_related_func_set(sub_80870EC); + SetKeyInterceptCallback(sub_80870EC); } return retVal; } -static u16 sub_8087164(u32 a1) +static u16 KeyInterCB_DoNothingAndKeepAlive(u32 key) { - sub_8086C64(); - return 17; + CheckRfuKeepAliveTimer(); + return LINK_KEY_CODE_EMPTY; } -static u16 sub_8087170(u32 linkPlayerId) +static u16 sub_8087170(u32 keyOrPlayerId) { - if (sUnknown_03000E10[linkPlayerId] == 0x82) + if (sPlayerTradingStates[keyOrPlayerId] == PLAYER_TRADING_STATE_UNK_2) { if (gMain.newKeys & B_BUTTON) { - c1_link_related_func_set(sub_8087164); - return 29; + SetKeyInterceptCallback(KeyInterCB_DoNothingAndKeepAlive); + return LINK_KEY_CODE_UNK_7; } else { - return 17; + return LINK_KEY_CODE_EMPTY; } } else { - sub_8086C64(); - return 17; + CheckRfuKeepAliveTimer(); + return LINK_KEY_CODE_EMPTY; } } static u16 sub_80871AC(u32 a1) { - c1_link_related_func_set(sub_8087170); - return 22; + SetKeyInterceptCallback(sub_8087170); + return LINK_KEY_CODE_UNK_2; } -static u16 sub_80871C0(u32 a1) +static u16 KeyInterCB_SendNothing(u32 key) { - return 17; + return LINK_KEY_CODE_EMPTY; } -static u16 sub_80871C4(u32 a1) +static u16 KeyInterCB_WaitForPlayersToExit(u32 keyOrPlayerId) { - if (sUnknown_03000E10[a1] != 0x83) - sub_8086C64(); - if (sub_8086CA8(0x83) == TRUE) + // keyOrPlayerId could be any keycode. This callback does no sanity checking + // on the size of the key. It's assuming that it is being called from + // CB1_UpdateLinkState. + if (sPlayerTradingStates[keyOrPlayerId] != PLAYER_TRADING_STATE_EXITING_ROOM) + CheckRfuKeepAliveTimer(); + if (AreAllPlayersInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM) == TRUE) { - ScriptContext1_SetupScript(EventScript_277513); - c1_link_related_func_set(sub_80871C0); + ScriptContext1_SetupScript(EventScript_DoLinkRoomExit); + SetKeyInterceptCallback(KeyInterCB_SendNothing); } - return 17; + return LINK_KEY_CODE_EMPTY; } -static u16 sub_80871FC(u32 a1) +static u16 KeyInterCB_SendExitRoomKey(u32 key) { - c1_link_related_func_set(sub_80871C4); - return 23; + SetKeyInterceptCallback(KeyInterCB_WaitForPlayersToExit); + return LINK_KEY_CODE_EXIT_ROOM; } -static u16 sub_8087210(u32 a1) +// Duplicate function. +static u16 KeyInterCB_SendNothing_2(u32 key) { - return 17; + return LINK_KEY_CODE_EMPTY; } u32 sub_8087214(void) { - if (sub_8086CE0(0x83) == TRUE) + if (IsAnyPlayerInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM) == TRUE) return 2; - if (sUnknown_03000E14 == sub_8087170 && sUnknown_03000E10[gUnknown_03005DB4] != 0x82) + if (sPlayerKeyInterceptCallback == sub_8087170 && sPlayerTradingStates[gLocalLinkPlayerId] != PLAYER_TRADING_STATE_UNK_2) return 0; - if (sUnknown_03000E14 == sub_8087164 && sUnknown_03000E10[gUnknown_03005DB4] == 0x81) + if (sPlayerKeyInterceptCallback == KeyInterCB_DoNothingAndKeepAlive && sPlayerTradingStates[gLocalLinkPlayerId] == PLAYER_TRADING_STATE_BUSY) return 2; - if (sub_8086CA8(0x82) != 0) + if (AreAllPlayersInTradingState(PLAYER_TRADING_STATE_UNK_2) != FALSE) return 1; return 0; } bool32 sub_808727C(void) { - return sub_8086CE0(0x83); + return IsAnyPlayerInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM); } u16 sub_8087288(void) { - c1_link_related_func_set(sub_80871AC); + SetKeyInterceptCallback(sub_80871AC); return 0; } u16 sub_808729C(void) { - c1_link_related_func_set(sub_80870F8); + SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); return 0; } -u16 sub_80872B0(void) +// The exit room key will be sent at the next opportunity. +// The return value is meaningless. +u16 QueueExitLinkRoomKey(void) { - c1_link_related_func_set(sub_80871FC); + SetKeyInterceptCallback(KeyInterCB_SendExitRoomKey); return 0; } u16 sub_80872C4(void) { - c1_link_related_func_set(sub_8087210); + SetKeyInterceptCallback(KeyInterCB_SendNothing_2); return 0; } -static void sub_80872D8(s32 linkPlayerId, s32 a2, struct UnkStruct_8054FF8 *a3) +static void LoadTradeRoomPlayer(s32 linkPlayerId, s32 myPlayerId, struct TradeRoomPlayer *trainer) { s16 x, y; - a3->a = linkPlayerId; - a3->b = (linkPlayerId == a2) ? 1 : 0; - a3->c = gLinkPlayerEventObjects[linkPlayerId].mode; - a3->d = sub_80878A0(linkPlayerId); - sub_8087878(linkPlayerId, &x, &y); - a3->sub.x = x; - a3->sub.y = y; - a3->sub.height = sub_80878C0(linkPlayerId); - a3->field_C = MapGridGetMetatileBehaviorAt(x, y); + trainer->playerId = linkPlayerId; + trainer->isLocalPlayer = (linkPlayerId == myPlayerId) ? 1 : 0; + trainer->c = gLinkPlayerEventObjects[linkPlayerId].movementMode; + trainer->facing = GetLinkPlayerFacingDirection(linkPlayerId); + GetLinkPlayerCoords(linkPlayerId, &x, &y); + trainer->pos.x = x; + trainer->pos.y = y; + trainer->pos.height = GetLinkPlayerElevation(linkPlayerId); + trainer->field_C = MapGridGetMetatileBehaviorAt(x, y); } -static bool32 sub_8087340(struct UnkStruct_8054FF8 *a1) +static bool32 sub_8087340(struct TradeRoomPlayer *player) { - u8 v1 = a1->c; - if (v1 == 2 || v1 == 0) + u8 v1 = player->c; + if (v1 == MOVEMENT_MODE_SCRIPTED || v1 == MOVEMENT_MODE_FREE) return TRUE; else return FALSE; } -static bool32 sub_8087358(struct UnkStruct_8054FF8 *a1) +// Duplicate function. +static bool32 sub_8087340_2(struct TradeRoomPlayer *player) { - u8 v1 = a1->c; - if (v1 == 2 || v1 == 0) + u8 v1 = player->c; + if (v1 == MOVEMENT_MODE_SCRIPTED || v1 == MOVEMENT_MODE_FREE) return TRUE; else return FALSE; } -static u8 *sub_8087370(struct UnkStruct_8054FF8 *a1) +static u8 *TryGetTileEventScript(struct TradeRoomPlayer *player) { - if (a1->c != 2) - return 0; - return GetCoordEventScriptAtMapPosition(&a1->sub); + if (player->c != MOVEMENT_MODE_SCRIPTED) + return FACING_NONE; + return GetCoordEventScriptAtMapPosition(&player->pos); } -static bool32 sub_8087388(struct UnkStruct_8054FF8 *a1) +static bool32 PlayerIsAtSouthExit(struct TradeRoomPlayer *player) { - if (a1->c != 2 && a1->c != 0) + if (player->c != MOVEMENT_MODE_SCRIPTED && player->c != MOVEMENT_MODE_FREE) return FALSE; - else if (!MetatileBehavior_IsSouthArrowWarp(a1->field_C)) + else if (!MetatileBehavior_IsSouthArrowWarp(player->field_C)) return FALSE; - else if (a1->d != 1) + else if (player->facing != 1) return FALSE; else return TRUE; } -static const u8 *sub_80873B4(struct UnkStruct_8054FF8 *a1) +static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *player) { - struct MapPosition unkStruct; + struct MapPosition otherPlayerPos; u8 linkPlayerId; - if (a1->c && a1->c != 2) - return 0; + if (player->c != MOVEMENT_MODE_FREE && player->c != MOVEMENT_MODE_SCRIPTED) + return FACING_NONE; - unkStruct = a1->sub; - unkStruct.x += gDirectionToVectors[a1->d].x; - unkStruct.y += gDirectionToVectors[a1->d].y; - unkStruct.height = 0; - linkPlayerId = GetLinkPlayerIdAt(unkStruct.x, unkStruct.y); + otherPlayerPos = player->pos; + otherPlayerPos.x += gDirectionToVectors[player->facing].x; + otherPlayerPos.y += gDirectionToVectors[player->facing].y; + otherPlayerPos.height = 0; + linkPlayerId = GetLinkPlayerIdAt(otherPlayerPos.x, otherPlayerPos.y); if (linkPlayerId != 4) { - if (!a1->b) - return EventScript_TradeRoom_TooBusyToNotice; - else if (sUnknown_03000E10[linkPlayerId] != 0x80) - return EventScript_TradeRoom_TooBusyToNotice; - else if (!sub_80B39D4(linkPlayerId)) - return EventScript_TradeRoom_ReadTrainerCard1; + if (!player->isLocalPlayer) + return gEventScript_TradeRoom_TooBusyToNotice; + else if (sPlayerTradingStates[linkPlayerId] != PLAYER_TRADING_STATE_IDLE) + return gEventScript_TradeRoom_TooBusyToNotice; + else if (!GetLinkTrainerCardColor(linkPlayerId)) + return gEventScript_TradeRoom_ReadTrainerCard_NoColor; else - return EventScript_TradeRoom_ReadTrainerCard2; - } - - return GetInteractedLinkPlayerScript(&unkStruct, a1->field_C, a1->d); -} - -static u16 sub_8087480(const u8 *script) -{ - if (script == gUnknown_08277388) - return 10; - else if (script == gUnknown_082773A3) - return 9; - else if (script == gUnknown_082773BE) - return 10; - else if (script == gUnknown_082773D9) - return 9; - else if (script == gUnknown_0827741D) - return 10; - else if (script == gUnknown_08277432) - return 9; - else if (script == gUnknown_08277447) - return 10; - else if (script == gUnknown_0827745C) - return 9; - else if (script == gUnknown_08277374) - return 10; - else if (script == gUnknown_0827737E) - return 9; - else if (script == gUnknown_082773F5) - return 10; - else if (script == gUnknown_082773FF) - return 9; + return gEventScript_TradeRoom_ReadTrainerCard_Normal; + } + + return GetInteractedLinkPlayerScript(&otherPlayerPos, player->field_C, player->facing); +} + +// This returns which direction to force the player to look when one of +// these event scripts runs. +static u16 GetDirectionForEventScript(const u8 *script) +{ + if (script == EventScript_DoubleBattleColosseum_PlayerSpot0) + return FACING_FORCED_RIGHT; + else if (script == EventScript_DoubleBattleColosseum_PlayerSpot1) + return FACING_FORCED_LEFT; + else if (script == EventScript_DoubleBattleColosseum_PlayerSpot2) + return FACING_FORCED_RIGHT; + else if (script == EventScript_DoubleBattleColosseum_PlayerSpot3) + return FACING_FORCED_LEFT; + else if (script == EventScript_RecordCenter_Spot0) + return FACING_FORCED_RIGHT; + else if (script == EventScript_RecordCenter_Spot1) + return FACING_FORCED_LEFT; + else if (script == EventScript_RecordCenter_Spot2) + return FACING_FORCED_RIGHT; + else if (script == EventScript_RecordCenter_Spot3) + return FACING_FORCED_LEFT; + else if (script == EventScript_SingleBattleColosseum_PlayerSpot0) + return FACING_FORCED_RIGHT; + else if (script == EventScript_SingleBattleColosseum_PlayerSpot1) + return FACING_FORCED_LEFT; + else if (script == EventScript_TradeCenter_Chair0) + return FACING_FORCED_RIGHT; + else if (script == EventScript_TradeCenter_Chair1) + return FACING_FORCED_LEFT; else - return 0; + return FACING_NONE; } static void sub_8087510(void) @@ -2751,7 +2814,7 @@ static void sub_8087510(void) ScriptContext2_Enable(); } -static void sub_808751C(void) +static void InitLinkRoomStartMenuScript(void) { PlaySE(SE_WIN_OPEN); ShowStartMenu(); @@ -2765,14 +2828,14 @@ static void sub_8087530(const u8 *script) ScriptContext2_Enable(); } -static void sub_808754C(void) +static void CreateConfirmLeaveTradeRoomPrompt(void) { PlaySE(SE_WIN_OPEN); - ScriptContext1_SetupScript(gUnknown_082774EF); + ScriptContext1_SetupScript(EventScript_ConfirmLeaveTradeRoom); ScriptContext2_Enable(); } -static void sub_8087568(const u8 *script) +static void InitMenuBasedScript(const u8 *script) { PlaySE(SE_SELECT); ScriptContext1_SetupScript(script); @@ -2781,18 +2844,18 @@ static void sub_8087568(const u8 *script) static void sub_8087584(void) { - ScriptContext1_SetupScript(gUnknown_08277509); + ScriptContext1_SetupScript(EventScript_TerminateLink); ScriptContext2_Enable(); } bool32 sub_8087598(void) { - if (!is_c1_link_related_active()) - return 0; - if (sub_800B4DC() >= 3) - sUnknown_03000E18 = 1; + if (!IsUpdateLinkStateCBActive()) + return FALSE; + if (GetLinkRecvQueueLength() >= 3) + sUnknown_03000E18 = TRUE; else - sUnknown_03000E18 = 0; + sUnknown_03000E18 = FALSE; return sUnknown_03000E18; } @@ -2800,19 +2863,19 @@ bool32 sub_80875C8(void) { u8 temp; - if (sub_800B4DC() < 2) + if (GetLinkRecvQueueLength() < 2) return FALSE; - else if (is_c1_link_related_active() != TRUE) + else if (IsUpdateLinkStateCBActive() != TRUE) return FALSE; - else if (sub_8009F3C() != TRUE) + else if (IsSendingKeysToLink() != TRUE) return FALSE; - else if (sUnknown_03000E14 == sub_808711C) + else if (sPlayerKeyInterceptCallback == KeyInterCB_DeferToRecvQueue) return TRUE; - else if (sUnknown_03000E14 != sub_80870F8) + else if (sPlayerKeyInterceptCallback != KeyInterCB_DeferToEventScript) return FALSE; temp = sUnknown_03000E18; - sUnknown_03000E18 = 0; + sUnknown_03000E18 = FALSE; if (temp == TRUE) return TRUE; @@ -2824,13 +2887,13 @@ bool32 sub_80875C8(void) bool32 sub_8087634(void) { - if (sub_8087690() < 2) + if (GetLinkSendQueueLength() < 2) return FALSE; - else if (is_c1_link_related_active() != TRUE) + else if (IsUpdateLinkStateCBActive() != TRUE) return FALSE; - else if (sub_8009F3C() != TRUE) + else if (IsSendingKeysToLink() != TRUE) return FALSE; - else if (sUnknown_03000E14 == sub_8087140) + else if (sPlayerKeyInterceptCallback == KeyInterCB_DeferToSendQueue) return TRUE; else return FALSE; @@ -2840,13 +2903,13 @@ bool32 sub_808766C(void) { if (gWirelessCommType != 0) return FALSE; - else if (!sub_8009F3C()) + else if (!IsSendingKeysToLink()) return FALSE; else return TRUE; } -static u32 sub_8087690(void) +static u32 GetLinkSendQueueLength(void) { if (gWirelessCommType != 0) return gUnknown_03005000.unk_9e8.unk_232; @@ -2881,7 +2944,7 @@ static void SpawnLinkPlayerEventObject(u8 linkPlayerId, s16 x, s16 y, u8 a4) linkPlayerEventObj->active = 1; linkPlayerEventObj->linkPlayerId = linkPlayerId; linkPlayerEventObj->eventObjId = eventObjId; - linkPlayerEventObj->mode = 0; + linkPlayerEventObj->movementMode = MOVEMENT_MODE_FREE; eventObj->active = 1; eventObj->singleMovementActive = a4; @@ -2923,14 +2986,15 @@ static void sub_808780C(u8 linkPlayerId) eventObj->active = 0; } -static u8 sub_8087858(u8 linkPlayerId) +// Returns the spriteId corresponding to this player. +static u8 GetSpriteForLinkedPlayer(u8 linkPlayerId) { u8 eventObjId = gLinkPlayerEventObjects[linkPlayerId].eventObjId; struct EventObject *eventObj = &gEventObjects[eventObjId]; return eventObj->spriteId; } -static void sub_8087878(u8 linkPlayerId, u16 *x, u16 *y) +static void GetLinkPlayerCoords(u8 linkPlayerId, u16 *x, u16 *y) { u8 eventObjId = gLinkPlayerEventObjects[linkPlayerId].eventObjId; struct EventObject *eventObj = &gEventObjects[eventObjId]; @@ -2938,14 +3002,14 @@ static void sub_8087878(u8 linkPlayerId, u16 *x, u16 *y) *y = eventObj->currentCoords.y; } -static u8 sub_80878A0(u8 linkPlayerId) +static u8 GetLinkPlayerFacingDirection(u8 linkPlayerId) { u8 eventObjId = gLinkPlayerEventObjects[linkPlayerId].eventObjId; struct EventObject *eventObj = &gEventObjects[eventObjId]; return eventObj->range.as_byte; } -static u8 sub_80878C0(u8 linkPlayerId) +static u8 GetLinkPlayerElevation(u8 linkPlayerId) { u8 eventObjId = gLinkPlayerEventObjects[linkPlayerId].eventObjId; struct EventObject *eventObj = &gEventObjects[eventObjId]; @@ -2965,7 +3029,7 @@ static u8 GetLinkPlayerIdAt(s16 x, s16 y) for (i = 0; i < 4; i++) { if (gLinkPlayerEventObjects[i].active - && (gLinkPlayerEventObjects[i].mode == 0 || gLinkPlayerEventObjects[i].mode == 2)) + && (gLinkPlayerEventObjects[i].movementMode == 0 || gLinkPlayerEventObjects[i].movementMode == 2)) { struct EventObject *eventObj = &gEventObjects[gLinkPlayerEventObjects[i].eventObjId]; if (eventObj->currentCoords.x == x && eventObj->currentCoords.y == y) @@ -2975,7 +3039,7 @@ static u8 GetLinkPlayerIdAt(s16 x, s16 y) return 4; } -static void sub_808796C(u8 linkPlayerId, u8 a2) +static void SetPlayerFacingDirection(u8 linkPlayerId, u8 facing) { struct LinkPlayerEventObject *linkPlayerEventObj = &gLinkPlayerEventObjects[linkPlayerId]; u8 eventObjId = linkPlayerEventObj->eventObjId; @@ -2983,94 +3047,111 @@ static void sub_808796C(u8 linkPlayerId, u8 a2) if (linkPlayerEventObj->active) { - if (a2 > 10) + if (facing > FACING_FORCED_RIGHT) + { eventObj->triggerGroundEffectsOnMove = 1; + } else - gUnknown_08339E00[gUnknown_08339DC8[linkPlayerEventObj->mode](linkPlayerEventObj, eventObj, a2)](linkPlayerEventObj, eventObj); + { + // This is a hack to split this code onto two separate lines, without declaring a local variable. + // C++ style inline variables would be nice here. + #define TEMP gLinkPlayerMovementModes[linkPlayerEventObj->movementMode](linkPlayerEventObj, eventObj, facing) + + gMovementStatusHandler[TEMP](linkPlayerEventObj, eventObj); + + // Clean up the hack. + #undef TEMP + } } } -static u8 sub_80879D8(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) + +static u8 MovementEventModeCB_Normal(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) { - return gUnknown_08339DD4[a3](linkPlayerEventObj, eventObj, a3); + return gLinkPlayerFacingHandlers[a3](linkPlayerEventObj, eventObj, a3); } -static u8 sub_80879F8(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) +static u8 MovementEventModeCB_Ignored(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) { - return 1; + return FACING_UP; } -static u8 sub_80879FC(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) +// Duplicate Function +static u8 MovementEventModeCB_Normal_2(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) { - return gUnknown_08339DD4[a3](linkPlayerEventObj, eventObj, a3); + return gLinkPlayerFacingHandlers[a3](linkPlayerEventObj, eventObj, a3); } -static u8 sub_8087A1C(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) +static bool8 FacingHandler_DoNothing(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) { - return 0; + return FALSE; } -static u8 sub_8087A20(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) +static bool8 FacingHandler_DpadMovement(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) { s16 x, y; - eventObj->range.as_byte = npc_something3(a3, eventObj->range.as_byte); + eventObj->range.as_byte = FlipVerticalAndClearForced(a3, eventObj->range.as_byte); EventObjectMoveDestCoords(eventObj, eventObj->range.as_byte, &x, &y); if (LinkPlayerDetectCollision(linkPlayerEventObj->eventObjId, eventObj->range.as_byte, x, y)) { - return 0; + return FALSE; } else { eventObj->directionSequenceIndex = 16; ShiftEventObjectCoords(eventObj, x, y); EventObjectUpdateZCoord(eventObj); - return 1; + return TRUE; } } -static u8 sub_8087A88(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) +static bool8 FacingHandler_ForcedFacingChange(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj, u8 a3) { - eventObj->range.as_byte = npc_something3(a3, eventObj->range.as_byte); - return 0; + eventObj->range.as_byte = FlipVerticalAndClearForced(a3, eventObj->range.as_byte); + return FALSE; } -static void sub_8087AA0(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj) +// This is called every time a free movement happens. Most of the time it's a No-Op. +static void MovementStatusHandler_EnterFreeMode(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj) { - linkPlayerEventObj->mode = 0; + linkPlayerEventObj->movementMode = MOVEMENT_MODE_FREE; } -static void sub_8087AA8(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj) +static void MovementStatusHandler_TryAdvanceScript(struct LinkPlayerEventObject *linkPlayerEventObj, struct EventObject *eventObj) { eventObj->directionSequenceIndex--; - linkPlayerEventObj->mode = 1; + linkPlayerEventObj->movementMode = MOVEMENT_MODE_FROZEN; MoveCoords(eventObj->range.as_byte, &eventObj->initialCoords.x, &eventObj->initialCoords.y); if (!eventObj->directionSequenceIndex) { ShiftStillEventObjectCoords(eventObj); - linkPlayerEventObj->mode = 2; + linkPlayerEventObj->movementMode = MOVEMENT_MODE_SCRIPTED; } } -static u8 npc_something3(u8 a1, u8 a2) +// Flip Up/Down facing codes. If newFacing doesn't specify a direction, default +// to oldFacing. Note that this clears also the "FORCED" part of the facing code, +// even for Left/Right codes. +static u8 FlipVerticalAndClearForced(u8 newFacing, u8 oldFacing) { - switch (a1 - 1) + switch (newFacing) { - case 0: - case 6: - return 2; - case 1: - case 7: - return 1; - case 2: - case 8: - return 3; - case 3: - case 9: - return 4; + case FACING_UP: + case FACING_FORCED_UP: + return DIR_NORTH; + case FACING_DOWN: + case FACING_FORCED_DOWN: + return DIR_SOUTH; + case FACING_LEFT: + case FACING_FORCED_LEFT: + return DIR_WEST; + case FACING_RIGHT: + case FACING_FORCED_RIGHT: + return DIR_EAST; } - return a2; + return oldFacing; } static u8 LinkPlayerDetectCollision(u8 selfEventObjId, u8 a2, s16 x, s16 y) @@ -3130,7 +3211,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByZCoord(eventObj->previousElevation, sprite, 1); sprite->oam.priority = ZCoordToPriority(eventObj->previousElevation); - if (!linkPlayerEventObj->mode) + if (!linkPlayerEventObj->movementMode != MOVEMENT_MODE_FREE) StartSpriteAnim(sprite, GetFaceDirectionAnimNum(eventObj->range.as_byte)); else StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(eventObj->range.as_byte)); diff --git a/src/party_menu.c b/src/party_menu.c index 4103c212c..525063326 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -2754,7 +2754,7 @@ static void sub_81B1B8C(u8 taskId) { if (gTasks[taskId].data[0] == 0) { - sub_8198070(6, 0); + ClearStdWindowAndFrameToTransparent(6, 0); ClearWindowTilemap(6); } DestroyTask(taskId); @@ -2779,7 +2779,7 @@ static void sub_81B1C1C(u8 taskId) { if (sub_81B1BD4() != TRUE) { - sub_8198070(6, 0); + ClearStdWindowAndFrameToTransparent(6, 0); ClearWindowTilemap(6); if (sub_81221AC() == TRUE) { @@ -3109,7 +3109,7 @@ static void sub_81B239C(u8 a) } DeactivateAllTextPrinters(); for (i = 0; i < PARTY_SIZE; i++) - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); LoadUserWindowBorderGfx(0, 0x4F, 0xD0); LoadPalette(GetOverworldTextboxPalettePtr(), 0xE0, 0x20); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); @@ -3127,7 +3127,7 @@ static void sub_81B2428(bool8 a) if (a == TRUE) { firstWindowId = AddWindow(&gUnknown_08615918); - FillWindowPixelBuffer(firstWindowId, 0); + FillWindowPixelBuffer(firstWindowId, PIXEL_FILL(0)); mainOffset = GetStringCenterAlignXOffset(0, gMenuText_Confirm, 48); AddTextPrinterParameterized4(firstWindowId, 0, mainOffset, 1, 0, 0, gUnknown_086157FC[0], -1, gMenuText_Confirm); PutWindowTilemap(firstWindowId); @@ -3140,7 +3140,7 @@ static void sub_81B2428(bool8 a) windowId = AddWindow(&gUnknown_08615908); offset = 3; } - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); if (gUnknown_0203CEC8.unk8_0 != 10) { mainOffset = GetStringCenterAlignXOffset(0, gText_Cancel, 48); @@ -3480,8 +3480,9 @@ static void DisplayPartyPokemonHPBar(u16 hp, u16 maxhp, struct Struct203CEDC *pt FillWindowPixelRect(ptr->windowId, gUnknown_08615AB8[0], ptr->unk0->unk4[20], ptr->unk0->unk4[21] + 1, hpFraction, 2); if (hpFraction != ptr->unk0->unk4[22]) { - FillWindowPixelRect(ptr->windowId, 13, ptr->unk0->unk4[20] + hpFraction, ptr->unk0->unk4[21], ptr->unk0->unk4[22] - hpFraction, 1); - FillWindowPixelRect(ptr->windowId, 2, ptr->unk0->unk4[20] + hpFraction, ptr->unk0->unk4[21] + 1, ptr->unk0->unk4[22] - hpFraction, 2); + // This appears to be an alternating fill + FillWindowPixelRect(ptr->windowId, 0x0D, ptr->unk0->unk4[20] + hpFraction, ptr->unk0->unk4[21], ptr->unk0->unk4[22] - hpFraction, 1); + FillWindowPixelRect(ptr->windowId, 0x02, ptr->unk0->unk4[20] + hpFraction, ptr->unk0->unk4[21] + 1, ptr->unk0->unk4[22] - hpFraction, 2); } CopyWindowToVram(ptr->windowId, 2); } @@ -3502,7 +3503,7 @@ static void sub_81B302C(u8 *ptr) { if (*ptr != 0xFF) { - sub_8198070(*ptr, 0); + ClearStdWindowAndFrameToTransparent(*ptr, 0); RemoveWindow(*ptr); *ptr = 0xFF; schedule_bg_copy_tilemap_to_vram(2); @@ -3547,7 +3548,7 @@ void display_pokemon_menu_message(u32 stringID) else if (sub_81B314C() == FALSE) stringID = 1; } - SetWindowBorderStyle(*windowPtr, FALSE, 0x4F, 0xD); + DrawStdFrameWithCustomTileAndPalette(*windowPtr, FALSE, 0x4F, 0xD); StringExpandPlaceholders(gStringVar4, gUnknown_08615AF4[stringID]); AddTextPrinterParameterized(*windowPtr, 1, gStringVar4, 0, 1, 0, 0); schedule_bg_copy_tilemap_to_vram(2); @@ -3597,7 +3598,7 @@ static u8 sub_81B31B0(u8 a) } gUnknown_0203CEC4->unkC[0] = AddWindow(&window); - SetWindowBorderStyle(gUnknown_0203CEC4->unkC[0], FALSE, 0x4F, 13); + DrawStdFrameWithCustomTileAndPalette(gUnknown_0203CEC4->unkC[0], FALSE, 0x4F, 13); if (a == 3) return gUnknown_0203CEC4->unkC[0]; cursorDimension = GetMenuCursorDimensionByFont(1, 0); @@ -3617,7 +3618,7 @@ static u8 sub_81B31B0(u8 a) static void sub_81B3300(const u8 *text) { - SetWindowBorderStyle(6, FALSE, 0x4F, 13); + DrawStdFrameWithCustomTileAndPalette(6, FALSE, 0x4F, 13); gTextFlags.canABSpeedUpPrint = TRUE; AddTextPrinterParameterized2(6, 1, text, GetPlayerTextSpeedDelay(), 0, 2, 1, 3); } @@ -3630,7 +3631,7 @@ static void sub_81B334C(void) static u8 sub_81B3364(void) { gUnknown_0203CEC4->unkC[0] = AddWindow(&gUnknown_08615970); - SetWindowBorderStyle(gUnknown_0203CEC4->unkC[0], FALSE, 0x4F, 13); + DrawStdFrameWithCustomTileAndPalette(gUnknown_0203CEC4->unkC[0], FALSE, 0x4F, 13); return gUnknown_0203CEC4->unkC[0]; } @@ -6522,7 +6523,7 @@ static void sub_81B8474(u8 taskId) gTasks[taskId].func = sub_81B8104; } -void sub_81B8518(u8 unused) +void InitChooseHalfPartyForBattle(u8 unused) { sub_81B8558(); InitPartyMenu(4, 0, 0, 0, 0, sub_81B1370, gMain.savedCallback); diff --git a/src/player_pc.c b/src/player_pc.c index 0d08a5e7b..6e78533e7 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -361,14 +361,14 @@ static void PlayerPCProcessMenuInput(u8 taskId) break; case MENU_B_PRESSED: PlaySE(SE_SELECT); - sub_8198070(data[4], FALSE); + ClearStdWindowAndFrameToTransparent(data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); schedule_bg_copy_tilemap_to_vram(0); gTasks[taskId].func = PlayerPC_TurnOff; break; default: - sub_8198070(data[4], FALSE); + ClearStdWindowAndFrameToTransparent(data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); schedule_bg_copy_tilemap_to_vram(0); @@ -403,7 +403,7 @@ static void PlayerPC_Mailbox(u8 taskId) ItemStorage_SetItemAndMailCount(taskId); if (sub_81D1C44(playerPCItemPageInfo.count) == TRUE) { - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); Mailbox_DrawMailboxMenu(taskId); gTasks[taskId].func = Mailbox_ProcessInput; } @@ -451,7 +451,7 @@ static void InitItemStorageMenu(u8 taskId, u8 var) static void ItemStorageMenuPrint(const u8 *textPtr) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, textPtr, 0, 1, 0, 0); } @@ -506,7 +506,7 @@ void sub_816B31C(void) void Mailbox_DoRedrawMailboxMenuAfterReturn(void) { sub_81973A4(); - NewMenuHelpers_DrawDialogueFrame(0, 1); + DrawDialogueFrame(0, 1); InitItemStorageMenu(CreateTask(ItemStorage_HandleReturnToProcessInput, 0), 1); pal_fill_black(); } @@ -560,7 +560,7 @@ static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) FreeAndReserveObjectSpritePalettes(); LoadListMenuArrowsGfx(); sub_8122344(gUnknown_0203BCC4->spriteIds, 7); - sub_8197434(0,0); + ClearDialogWindowAndFrame(0,0); gTasks[taskId].func = ItemStorage_ProcessWithdrawTossInput; } @@ -583,7 +583,7 @@ static void sub_816B4DC(u8 taskId) { u16 *data = gTasks[taskId].data; - sub_8198070(data[4], FALSE); + ClearStdWindowAndFrameToTransparent(data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); schedule_bg_copy_tilemap_to_vram(0); @@ -761,7 +761,7 @@ static void Mailbox_MoveToBag(u8 taskId) static void Mailbox_DrawYesNoBeforeMove(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); gTasks[taskId].func = Mailbox_MoveToBagYesNoPrompt; } @@ -863,7 +863,7 @@ static void Mailbox_NoPokemonForMail(u8 taskId) static void Mailbox_Cancel(u8 taskId) { sub_81D1D04(2); - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); Mailbox_DrawMailboxMenu(taskId); schedule_bg_copy_tilemap_to_vram(0); gTasks[taskId].func = Mailbox_ProcessInput; @@ -892,7 +892,7 @@ static u8 sub_816BC7C(u8 a) if (*windowIdLoc == 0xFF) { *windowIdLoc = AddWindow(&gUnknown_085DFF5C[a]); - SetWindowBorderStyle(*windowIdLoc, FALSE, 0x214, 0xE); + DrawStdFrameWithCustomTileAndPalette(*windowIdLoc, FALSE, 0x214, 0xE); schedule_bg_copy_tilemap_to_vram(0); } return *windowIdLoc; @@ -903,7 +903,7 @@ static void sub_816BCC4(u8 a) u8 *windowIdLoc = &(gUnknown_0203BCC4->windowIds[a]); if (*windowIdLoc != 0xFF) { - sub_8198070(*windowIdLoc, FALSE); + ClearStdWindowAndFrameToTransparent(*windowIdLoc, FALSE); ClearWindowTilemap(*windowIdLoc); schedule_bg_copy_tilemap_to_vram(0); RemoveWindow(*windowIdLoc); @@ -977,7 +977,7 @@ static void sub_816BEF0(s32 id) description = (u8 *)ItemId_GetDescription(gSaveBlock1Ptr->pcItems[id].itemId); else description = ItemStorage_GetItemPcResponse(ITEMPC_GO_BACK_TO_PREV); - FillWindowPixelBuffer(windowId, 17); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); AddTextPrinterParameterized(windowId, 1, description, 0, 1, 0, NULL); } @@ -1005,7 +1005,7 @@ static void sub_816BFE0(u8 y, u8 b, u8 speed) { u8 windowId = gUnknown_0203BCC4->windowIds[0]; if (b == 0xFF) - FillWindowPixelRect(windowId, 17, 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); + FillWindowPixelRect(windowId, PIXEL_FILL(1), 0, y, GetMenuCursorDimensionByFont(1, 0), GetMenuCursorDimensionByFont(1, 1)); else AddTextPrinterParameterized4(windowId, 1, 0, y, 0, 0, gUnknown_085DFF8C, speed, gText_SelectorArrow2); } @@ -1123,7 +1123,7 @@ static const u8* ItemStorage_GetItemPcResponse(u16 itemId) static void ItemStorage_PrintItemPcResponse(const u8 *string) { u8 windowId = gUnknown_0203BCC4->windowIds[1]; - FillWindowPixelBuffer(windowId, 0x11); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); StringExpandPlaceholders(gStringVar4, string); AddTextPrinterParameterized(windowId, 1, gStringVar4, 0, 1, 0, NULL); } @@ -1170,7 +1170,7 @@ static void ItemStorage_GoBackToPlayerPCMenu_InitStorage(u8 taskId) data = gTasks[taskId].data; if (!IsDma3ManagerBusyWithBgCopy()) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); if (!data[3]) InitItemStorageMenu(taskId, ITEMPC_MENU_WITHDRAW); else diff --git a/src/poison.c b/src/poison.c index c86ec2cd8..9af981694 100644 --- a/src/poison.c +++ b/src/poison.c @@ -3,8 +3,6 @@ #include "trig.h" #include "constants/rgb.h" -extern void sub_80A77C8(struct Sprite *); - void sub_810DBAC(struct Sprite *); void sub_810DC2C(struct Sprite *); void sub_810DCD0(struct Sprite *); diff --git a/src/pokeblock.c b/src/pokeblock.c index 3fd4f34df..2682754aa 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -665,7 +665,7 @@ static void HandleInitWindows(void) for (i = 0; i < ARRAY_COUNT(sWindowTemplatesForPokeblockMenu) - 1; i++) { - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); } schedule_bg_copy_tilemap_to_vram(0); @@ -749,7 +749,7 @@ static void sub_8135FCC(s32 pkblId) struct Pokeblock *pokeblock; u16 rectTilemapSrc[2]; - FillWindowPixelBuffer(7, 0); + FillWindowPixelBuffer(7, PIXEL_FILL(0)); if (pkblId != LIST_B_PRESSED) { @@ -1120,7 +1120,7 @@ static void PutPokeblockOptionsWindow(u8 taskId) data[1] = 9; sub_8136418(); - SetWindowBorderStyle(data[1], 0, 1, 0xE); + DrawStdFrameWithCustomTileAndPalette(data[1], 0, 1, 0xE); sub_81995E4(data[1], sPokeblockMenu->optionsNo, sPokeblockMenuActions, sPokeblockMenu->pokeblockOptionsIds); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(data[1], sPokeblockMenu->optionsNo, 0); PutWindowTilemap(data[1]); @@ -1173,7 +1173,7 @@ static void PokeblockAction_Toss(u8 taskId) { s16 *data = gTasks[taskId].data; - sub_8198070(data[1], FALSE); + ClearStdWindowAndFrameToTransparent(data[1], FALSE); StringCopy(gStringVar1, gPokeblockNames[gSaveBlock1Ptr->pokeblocks[gSpecialVar_ItemId].color]); StringExpandPlaceholders(gStringVar4, gText_ThrowAwayVar1); DisplayMessageAndContinueTask(taskId, 10, 10, 13, 1, GetPlayerTextSpeedDelay(), gStringVar4, CreateTossPokeblockYesNoMenu); @@ -1219,7 +1219,7 @@ static void HandleErasePokeblock(u8 taskId) static void TossPokeblockChoice_No(u8 taskId) { - sub_8197DF8(10, FALSE); + ClearDialogWindowAndFrameToTransparent(10, FALSE); schedule_bg_copy_tilemap_to_vram(1); sub_81363BC(); gTasks[taskId].func = Task_HandlePokeblockMenuInput; @@ -1266,7 +1266,7 @@ static void PokeblockAction_Cancel(u8 taskId) { s16 *data = gTasks[taskId].data; - sub_8198070(data[1], FALSE); + ClearStdWindowAndFrameToTransparent(data[1], FALSE); schedule_bg_copy_tilemap_to_vram(1); sub_81363BC(); gTasks[taskId].func = Task_HandlePokeblockMenuInput; diff --git a/src/pokeblock_feed.c b/src/pokeblock_feed.c index b1f182b66..da803f454 100644 --- a/src/pokeblock_feed.c +++ b/src/pokeblock_feed.c @@ -55,8 +55,6 @@ extern struct MusicPlayerInfo gMPlayInfo_BGM; extern const struct CompressedSpriteSheet gMonFrontPicTable[]; extern const u16 gUnknown_0860F074[]; -extern bool8 sub_81221EC(void); - // this file's functions static void HandleInitBackgrounds(void); static void HandleInitWindows(void); @@ -581,7 +579,7 @@ static bool8 TransitionToPokeblockFeedScene(void) gMain.state++; break; case 10: - SetWindowBorderStyle(0, 1, 1, 14); + DrawStdFrameWithCustomTileAndPalette(0, 1, 1, 14); gMain.state++; break; case 11: @@ -704,7 +702,7 @@ static void HandleInitWindows(void) DeactivateAllTextPrinters(); LoadUserWindowBorderGfx(0, 1, 0xE0); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); schedule_bg_copy_tilemap_to_vram(0); } diff --git a/src/pokedex.c b/src/pokedex.c index 805412c85..4bf8dff6d 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -2152,7 +2152,7 @@ static void CreateCaughtBall(u16 a, u8 x, u8 y, u16 unused) if (a) BlitBitmapToWindow(0, gUnknown_0855D2BE, x * 8, y * 8, 8, 16); else - FillWindowPixelRect(0, 0, x * 8, y * 8, 8, 16); + FillWindowPixelRect(0, PIXEL_FILL(0), x * 8, y * 8, 8, 16); } static u8 CreateMonName(u16 num, u8 left, u8 top) @@ -2170,7 +2170,7 @@ static u8 CreateMonName(u16 num, u8 left, u8 top) void sub_80BD28C(u8 x, u8 y, u16 unused) { - FillWindowPixelRect(0, 0, x * 8, y * 8, 0x60, 16); + FillWindowPixelRect(0, PIXEL_FILL(0), x * 8, y * 8, 0x60, 16); } static void CreateInitialPokemonSprites(u16 selectedMon, u16 b) @@ -2927,7 +2927,7 @@ void sub_80BEA24(u8 taskId) case 1: DecompressAndLoadBgGfxUsingHeap(3, gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(3, gPokedexTilemap_DescriptionScreen, 0, 0); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); PutWindowTilemap(1); sub_80C0D30(1, sPokedexListItem->dexNum); @@ -3222,7 +3222,7 @@ void sub_80BF250(u8 taskId) case 1: DecompressAndLoadBgGfxUsingHeap(3, &gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(3, &gPokedexTilemap_CryScreen, 0, 0); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); PutWindowTilemap(3); PutWindowTilemap(2); @@ -3416,7 +3416,7 @@ void sub_80BF82C(u8 taskId) case 1: DecompressAndLoadBgGfxUsingHeap(3, gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(3, gPokedexTilemap_SizeScreen, 0, 0); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); gMain.state++; break; @@ -3766,7 +3766,7 @@ void sub_80BFE38(u8 taskId) case 1: DecompressAndLoadBgGfxUsingHeap(3, gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(3, gPokedexTilemap_DescriptionScreen, 0, 0); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); PutWindowTilemap(0); PutWindowTilemap(1); sub_80C0D30(1, gTasks[taskId].data[1]); @@ -4784,7 +4784,7 @@ void sub_80C1270(const u8 *str, u32 left, u32 top) void sub_80C12B0(u32 x, u32 y, u32 width, u32 height) { - FillWindowPixelRect(0, 0, x, y, width, height); + FillWindowPixelRect(0, PIXEL_FILL(0), x, y, width, height); } void sub_80C12E0(u8 taskId) diff --git a/src/pokemon.c b/src/pokemon.c index a35033d49..a984abbb9 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -10,6 +10,7 @@ #include "battle_tower.h" #include "event_data.h" #include "evolution_scene.h" +#include "field_specials.h" #include "item.h" #include "link.h" #include "main.h" @@ -72,10 +73,6 @@ extern const struct CompressedSpritePalette gMonPaletteTable[]; extern const struct CompressedSpritePalette gMonShinyPaletteTable[]; extern const u8 gTrainerClassNames[][13]; -extern u16 get_unknown_box_id(void); -extern void set_unknown_box_id(u8); -extern bool8 sub_806F104(void); - // this file's functions static u16 CalculateBoxMonChecksum(struct BoxPokemon *boxMon); static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType); diff --git a/src/pokemon_size_record.c b/src/pokemon_size_record.c index b0e14d2b1..98d83d8ce 100644 --- a/src/pokemon_size_record.c +++ b/src/pokemon_size_record.c @@ -1,5 +1,6 @@ #include "global.h" #include "event_data.h" +#include "pokedex.h" #include "pokemon.h" #include "pokemon_size_record.h" #include "string_util.h" @@ -15,9 +16,6 @@ struct UnknownStruct u16 unk4; }; -extern u16 GetPokedexHeightWeight(u16 dexNo, bool8 height); -extern u16 SpeciesToNationalPokedexNum(u16 species); - static const struct UnknownStruct sBigMonSizeTable[] = { { 290, 1, 0 }, diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index cdfc4ba6b..c5d40877b 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -1552,7 +1552,7 @@ void sub_80C6D80(const u8 *string, void *dst, u8 arg2, u8 arg3, s32 arg4) winTemplate.width = 24; winTemplate.height = 2; windowId = AddWindow(&winTemplate); - FillWindowPixelBuffer(windowId, (arg3 << 4) | arg3); + FillWindowPixelBuffer(windowId, PIXEL_FILL(arg3)); tileData1 = (u8*) GetWindowAttribute(windowId, WINDOW_TILE_DATA); tileData2 = (winTemplate.width * 32) + tileData1; @@ -1599,7 +1599,7 @@ void sub_80C6EAC(const u8 *string, void *dst, u16 arg2, u8 arg3, u8 clr2, u8 clr winTemplate.height = 2; var = winTemplate.width * 32; windowId = AddWindow(&winTemplate); - FillWindowPixelBuffer(windowId, (arg3 << 4) | arg3); + FillWindowPixelBuffer(windowId, PIXEL_FILL(arg3)); tileData1 = (u8*) GetWindowAttribute(windowId, WINDOW_TILE_DATA); tileData2 = (winTemplate.width * 32) + tileData1; txtColor[0] = arg3; @@ -1736,8 +1736,8 @@ static void Task_PokemonStorageSystemPC(u8 taskId) case 0: CreatePCMenu(task->data[1], &task->data[15]); sub_81973A4(); - NewMenuHelpers_DrawDialogueFrame(0, 0); - FillWindowPixelBuffer(0, 0x11); + DrawDialogueFrame(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, TEXT_SPEED_FF, NULL, 2, 1, 3); CopyWindowToVram(0, 3); CopyWindowToVram(task->data[15], 3); @@ -1763,13 +1763,13 @@ static void Task_PokemonStorageSystemPC(u8 taskId) if (task->data[1] != task->data[3]) { task->data[1] = task->data[3]; - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); } break; case MENU_B_PRESSED: case 4: - sub_819746C(task->data[15], TRUE); + ClearStdWindowAndFrame(task->data[15], TRUE); ScriptContext2_Disable(); EnableBothScriptContexts(); RemoveWindow(task->data[15]); @@ -1778,13 +1778,13 @@ static void Task_PokemonStorageSystemPC(u8 taskId) default: if (task->data[2] == 0 && CountPartyMons() == PARTY_SIZE) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_PartyFull, 0, NULL, 2, 1, 3); task->data[0] = 3; } else if (task->data[2] == 1 && CountPartyMons() == 1) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_JustOnePkmn, 0, NULL, 2, 1, 3); task->data[0] = 3; } @@ -1799,7 +1799,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) case 3: if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } @@ -1809,7 +1809,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) task->data[1] = 4; Menu_MoveCursor(-1); task->data[1] = Menu_GetCursorPos(); - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } @@ -1819,7 +1819,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) task->data[1] = 0; Menu_MoveCursor(1); task->data[1] = Menu_GetCursorPos(); - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } @@ -1865,7 +1865,7 @@ static void CreatePCMenu(u8 whichMenu, s16 *windowIdPtr) winTemplate.width = GetMaxWidthInMenuTable((void *)gUnknown_085716C0, ARRAY_COUNT(gUnknown_085716C0)); windowId = AddWindow(&winTemplate); - NewMenuHelpers_DrawStdWindowFrame(windowId, FALSE); + DrawStdWindowFrame(windowId, FALSE); PrintMenuTable(windowId, ARRAY_COUNT(gUnknown_085716C0), (void *)gUnknown_085716C0); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(windowId, ARRAY_COUNT(gUnknown_085716C0), whichMenu); *windowIdPtr = windowId; @@ -2103,7 +2103,7 @@ static void sub_80C7BE4(void) winTemplate.height = 4; windowId = AddWindow(&winTemplate); - FillWindowPixelBuffer(windowId, 0x44); + FillWindowPixelBuffer(windowId, PIXEL_FILL(4)); center = GetStringCenterAlignXOffset(1, boxName, 64); AddTextPrinterParameterized3(windowId, 1, center, 1, gUnknown_08571734, TEXT_SPEED_FF, boxName); @@ -4107,7 +4107,7 @@ static void LoadCursorMonGfx(u16 species, u32 pid) static void PrintCursorMonInfo(void) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); if (sPSSData->boxOption != BOX_OPTION_MOVE_ITEMS) { AddTextPrinterParameterized(0, 1, sPSSData->cursorMonNickText, 6, 0, TEXT_SPEED_FF, NULL); @@ -4416,7 +4416,7 @@ static void PrintStorageActionText(u8 id) } DynamicPlaceholderTextUtil_ExpandPlaceholders(sPSSData->field_2190, gPCStorageActionTexts[id].text); - FillWindowPixelBuffer(1, 0x11); + FillWindowPixelBuffer(1, PIXEL_FILL(1)); AddTextPrinterParameterized(1, 1, sPSSData->field_2190, 0, 1, TEXT_SPEED_FF, NULL); sub_8098858(1, 2, 14); PutWindowTilemap(1); @@ -4432,7 +4432,7 @@ static void ShowYesNoWindow(s8 cursorPos) static void ClearBottomWindow(void) { - sub_8198070(1, FALSE); + ClearStdWindowAndFrameToTransparent(1, FALSE); schedule_bg_copy_tilemap_to_vram(0); } @@ -6501,7 +6501,7 @@ static void InitCanRelaseMonVars(void) } sub_80CE350(sPSSData->field_2176); - sPSSData->field_2174 = GetMonData(&sPSSData->field_2108, MON_DATA_KNOWN_MOVES, sPSSData->field_2176); + sPSSData->field_2174 = GetMonData(&sPSSData->field_2108, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176); if (sPSSData->field_2174 != 0) { sPSSData->field_216D = 0; @@ -6559,7 +6559,7 @@ static s8 RunCanReleaseMon(void) { if (sPSSData->field_2170 != TOTAL_BOXES_COUNT || sPSSData->field_2171 != i) { - knownMoves = GetMonData(gPlayerParty + i, MON_DATA_KNOWN_MOVES, sPSSData->field_2176); + knownMoves = GetMonData(gPlayerParty + i, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176); sPSSData->field_2174 &= ~(knownMoves); } } @@ -6578,7 +6578,7 @@ static s8 RunCanReleaseMon(void) case 1: for (i = 0; i < IN_BOX_COUNT; i++) { - knownMoves = GetAndCopyBoxMonDataAt(sPSSData->field_216E, sPSSData->field_216F, MON_DATA_KNOWN_MOVES, sPSSData->field_2176); + knownMoves = GetAndCopyBoxMonDataAt(sPSSData->field_216E, sPSSData->field_216F, MON_DATA_KNOWN_MOVES, (u8*)sPSSData->field_2176); if (knownMoves != 0 && !(sPSSData->field_2170 == sPSSData->field_216E && sPSSData->field_2171 == sPSSData->field_216F)) { @@ -8733,7 +8733,7 @@ static void AddMenu(void) sPSSData->menuWindow.tilemapTop = 15 - sPSSData->menuWindow.height; sPSSData->field_CB0 = AddWindow(&sPSSData->menuWindow); ClearWindowTilemap(sPSSData->field_CB0); - SetWindowBorderStyle(sPSSData->field_CB0, FALSE, 11, 14); + DrawStdFrameWithCustomTileAndPalette(sPSSData->field_CB0, FALSE, 11, 14); PrintMenuTable(sPSSData->field_CB0, sPSSData->menuItemsCount, (void*)sPSSData->menuItems); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(sPSSData->field_CB0, sPSSData->menuItemsCount, 0); schedule_bg_copy_tilemap_to_vram(0); @@ -8787,7 +8787,7 @@ static s16 sub_80D00AC(void) static void sub_80D013C(void) { - sub_8198070(sPSSData->field_CB0, TRUE); + ClearStdWindowAndFrameToTransparent(sPSSData->field_CB0, TRUE); RemoveWindow(sPSSData->field_CB0); } @@ -8835,7 +8835,7 @@ static bool8 sub_80D0164(void) sPSSData->field_2200 = AddWindow8Bit(&gUnknown_0857BB1C); if (sPSSData->field_2200 != 0xFF) { - FillWindowPixelBuffer(sPSSData->field_2200, 0); + FillWindowPixelBuffer(sPSSData->field_2200, PIXEL_FILL(0)); return TRUE; } } @@ -8892,7 +8892,7 @@ static bool8 sub_80D024C(void) ChangeBgX(0, -1024, 0); ChangeBgY(0, -1024, 0); FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 0x20, 0x20); - FillWindowPixelBuffer8Bit(sPSSData->field_2200, 0); + FillWindowPixelBuffer8Bit(sPSSData->field_2200, PIXEL_FILL(0)); sub_80D07B0(sMoveMonsPtr->fromRow, sMoveMonsPtr->fromColumn); SetBgAttribute(0, BG_ATTR_PALETTEMODE, 1); PutWindowTilemap(sPSSData->field_2200); @@ -9194,7 +9194,7 @@ static void sub_80D0834(u8 arg0, u8 arg1) if (species != SPECIES_NONE) { FillWindowPixelRect8Bit(sPSSData->field_2200, - 0, + PIXEL_FILL(0), 24 * arg0, 24 * arg1, 32, @@ -9911,7 +9911,7 @@ static void PrintItemDescription(void) else description = ItemId_GetDescription(sPSSData->cursorMonItem); - FillWindowPixelBuffer(2, 0x11); + FillWindowPixelBuffer(2, PIXEL_FILL(1)); AddTextPrinterParameterized5(2, 1, description, 4, 0, 0, NULL, 0, 1); } @@ -10357,7 +10357,7 @@ bool32 AnyStorageMonWithMove(u16 moveId) { if (GetBoxMonData(&gPokemonStoragePtr->boxes[i][j], MON_DATA_SANITY_HAS_SPECIES) && !GetBoxMonData(&gPokemonStoragePtr->boxes[i][j], MON_DATA_SANITY_IS_EGG) - && GetBoxMonData(&gPokemonStoragePtr->boxes[i][j], MON_DATA_KNOWN_MOVES, moves)) + && GetBoxMonData(&gPokemonStoragePtr->boxes[i][j], MON_DATA_KNOWN_MOVES, (u8*)moves)) return TRUE; } } diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index bd1ae7802..0133e40f1 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -1349,7 +1349,7 @@ static bool8 ExtractMonDataToSummaryStruct(struct Pokemon *a) } break; case 3: - GetMonData(a, MON_DATA_OT_NAME, &sum->OTName); + GetMonData(a, MON_DATA_OT_NAME, sum->OTName); ConvertInternationalString((u8*)&sum->OTName, GetMonData(a, MON_DATA_LANGUAGE)); sum->unk7 = sub_81B205C(a); sum->OTGender = GetMonData(a, MON_DATA_OT_GENDER); @@ -2629,7 +2629,7 @@ static void ResetWindows(void) for (i = 0; i < 20; i++) { - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); } for (i = 0; i < ARRAY_COUNT(pssData->windowIds); i++) { @@ -2644,9 +2644,9 @@ static void SummaryScreen_PrintTextOnWindow(u8 windowId, const u8 *string, u8 x, static void sub_81C25E8(void) { - FillWindowPixelBuffer(17, 0); - FillWindowPixelBuffer(18, 0); - FillWindowPixelBuffer(19, 0); + FillWindowPixelBuffer(17, PIXEL_FILL(0)); + FillWindowPixelBuffer(18, PIXEL_FILL(0)); + FillWindowPixelBuffer(19, PIXEL_FILL(0)); if (!pssData->summary.isEgg) sub_81C2628(); else @@ -2898,7 +2898,7 @@ static u8 AddWindowFromTemplateList(const struct WindowTemplate *template, u8 te if (*windowIdPtr == 0xFF) { *windowIdPtr = AddWindow(&template[templateId]); - FillWindowPixelBuffer(*windowIdPtr, 0); + FillWindowPixelBuffer(*windowIdPtr, PIXEL_FILL(0)); } return *windowIdPtr; } @@ -2920,7 +2920,7 @@ static void PrintPageSpecificText(u8 pageIndex) for (i = 0; i < ARRAY_COUNT(pssData->windowIds); i++) { if (pssData->windowIds[i] != 0xFF) - FillWindowPixelBuffer(pssData->windowIds[i], 0); + FillWindowPixelBuffer(pssData->windowIds[i], PIXEL_FILL(0)); } sTextPrinterFunctions[pageIndex](); } @@ -3469,7 +3469,7 @@ static void PrintMovePowerAndAccuracy(u16 moveIndex) const u8 *text; if (moveIndex != 0) { - FillWindowPixelRect(14, 0, 53, 0, 19, 32); + FillWindowPixelRect(14, PIXEL_FILL(0), 53, 0, 19, 32); if (gBattleMoves[moveIndex].power < 2) { @@ -3567,7 +3567,7 @@ static void PrintContestMoveDescription(u8 moveSlot) static void PrintMoveDetails(u16 move) { u8 windowId = AddWindowFromTemplateList(sPageMovesTemplate, 2); - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); if (move != MOVE_NONE) { if (pssData->currPageIndex == 2) @@ -3619,7 +3619,7 @@ static void PrintNewMoveDetailsOrCancelText(void) static void sub_81C4064(void) { u8 windowId = AddWindowFromTemplateList(sPageMovesTemplate, 0); - FillWindowPixelRect(windowId, 0, 0, 66, 72, 16); + FillWindowPixelRect(windowId, PIXEL_FILL(0), 0, 66, 72, 16); CopyWindowToVram(windowId, 2); } @@ -3628,11 +3628,11 @@ static void sub_81C40A0(u8 moveIndex1, u8 moveIndex2) u8 windowId1 = AddWindowFromTemplateList(sPageMovesTemplate, 0); u8 windowId2 = AddWindowFromTemplateList(sPageMovesTemplate, 1); - FillWindowPixelRect(windowId1, 0, 0, moveIndex1 * 16, 0x48, 0x10); - FillWindowPixelRect(windowId1, 0, 0, moveIndex2 * 16, 0x48, 0x10); + FillWindowPixelRect(windowId1, PIXEL_FILL(0), 0, moveIndex1 * 16, 0x48, 0x10); + FillWindowPixelRect(windowId1, PIXEL_FILL(0), 0, moveIndex2 * 16, 0x48, 0x10); - FillWindowPixelRect(windowId2, 0, 0, moveIndex1 * 16, 0x30, 0x10); - FillWindowPixelRect(windowId2, 0, 0, moveIndex2 * 16, 0x30, 0x10); + FillWindowPixelRect(windowId2, PIXEL_FILL(0), 0, moveIndex1 * 16, 0x30, 0x10); + FillWindowPixelRect(windowId2, PIXEL_FILL(0), 0, moveIndex2 * 16, 0x30, 0x10); PrintMoveNameAndPP(moveIndex1); PrintMoveNameAndPP(moveIndex2); @@ -3641,7 +3641,7 @@ static void sub_81C40A0(u8 moveIndex1, u8 moveIndex2) static void PrintHMMovesCantBeForgotten(void) { u8 windowId = AddWindowFromTemplateList(sPageMovesTemplate, 2); - FillWindowPixelBuffer(windowId, 0); + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); SummaryScreen_PrintTextOnWindow(windowId, gText_HMMovesCantBeForgotten2, 6, 1, 0, 0); } diff --git a/src/pokenav.c b/src/pokenav.c index d09c3da94..42114a4b2 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -141,7 +141,7 @@ void sub_81C7710(void); static void InitKeys_(void); static void FreeVars(void); static void VblankCb_Pokenav(void); -static void Cb2_Pokenav(void); +static void CB2_Pokenav(void); void sub_81C7C28(void); void sub_81C72BC(void); void sub_81C7B74(void); @@ -388,7 +388,7 @@ u32 sub_81C7078(u32 (*func)(s32), u32 priority) { u16 taskId; - if (!is_c1_link_related_active()) + if (!IsUpdateLinkStateCBActive()) taskId = CreateTask(sub_81C7170, priority); else taskId = CreateTask(sub_81C71E4, priority); @@ -485,7 +485,7 @@ void sub_81C71E4(u8 taskId) } } -void CB2_PokeNav(void) +void CB2_InitPokeNav(void) { gUnknown_0203CF40 = Alloc(sizeof(*gUnknown_0203CF40)); if (gUnknown_0203CF40 == NULL) @@ -498,7 +498,7 @@ void CB2_PokeNav(void) ResetTasks(); SetVBlankCallback(NULL); CreateTask(sub_81C742C, 0); - SetMainCallback2(Cb2_Pokenav); + SetMainCallback2(CB2_Pokenav); SetVBlankCallback(VblankCb_Pokenav); } } @@ -529,7 +529,7 @@ void sub_81C72BC(void) FreeAllSpritePalettes(); SetVBlankCallback(NULL); CreateTask(sub_81C742C, 0); - SetMainCallback2(Cb2_Pokenav); + SetMainCallback2(CB2_Pokenav); SetVBlankCallback(VblankCb_Pokenav); } } @@ -588,7 +588,7 @@ static bool32 AnyMonHasRibbon(void) return FALSE; } -static void Cb2_Pokenav(void) +static void CB2_Pokenav(void) { RunTasks(); AnimateSprites(); @@ -1138,8 +1138,8 @@ bool32 IsDma3ManagerBusyWithBgCopy_(void) void sub_81C7BF8(u32 windowId) { - FillWindowPixelBuffer(windowId, 0x44); - FillWindowPixelRect(windowId, 0x55, 0, 0, 0x80, 1); + FillWindowPixelBuffer(windowId, PIXEL_FILL(4)); + FillWindowPixelRect(windowId, PIXEL_FILL(5), 0, 0, 0x80, 1); } void sub_81C7C28(void) diff --git a/src/pokenav_match_call.c b/src/pokenav_match_call.c index 53f9f0548..b775ed10e 100644 --- a/src/pokenav_match_call.c +++ b/src/pokenav_match_call.c @@ -1,13 +1,11 @@ - -// Includes #include "global.h" #include "battle_setup.h" #include "event_data.h" #include "string_util.h" #include "battle.h" #include "gym_leader_rematch.h" +#include "match_call.h" -extern void sub_8197080(u8 *dest); extern const u8 gTrainerClassNames[][13]; // Static type declarations diff --git a/src/record_mixing.c b/src/record_mixing.c index c0ca5f19c..3a16f817e 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -34,9 +34,8 @@ #include "daycare.h" #include "international_string_util.h" #include "constants/battle_frontier.h" +#include "dewford_trend.h" -extern void ReceiveSecretBasesData(struct SecretBaseRecord *, size_t, u8); -extern void ReceiveEasyChatPairsData(struct EasyChatPair *, size_t, u8); // Static type declarations @@ -106,7 +105,7 @@ static EWRAM_DATA union PlayerRecords *sSentRecord = NULL; // Static ROM declarations static void Task_RecordMixing_Main(u8 taskId); -static void sub_80E7324(u8 taskId); +static void Task_MixingRecordsRecv(u8 taskId); static void Task_SendPacket(u8 taskId); static void Task_CopyReceiveBuffer(u8 taskId); static void Task_SendPacket_SwitchToReceive(u8 taskId); @@ -120,7 +119,7 @@ static void ReceiveLilycoveLadyData(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); static void ReceiveGiftItem(u16 *item, u8 which); -static void sub_80E7FF8(u8 taskId); +static void Task_DoRecordMixing(u8 taskId); static void sub_80E8110(struct Apprentice *arg0, struct Apprentice *arg1); static void ReceiveApprenticeData(struct Apprentice *arg0, size_t arg1, u32 arg2); static void ReceiveRankingHallRecords(struct PlayerHallRecords *hallRecords, size_t arg1, u32 arg2); @@ -170,7 +169,8 @@ static const u8 gUnknown_0858CFBE[3][4] = #define BUFFER_CHUNK_SIZE 200 -void sub_80E6BE8(void) +// Note: VAR_0x8005 contains the spotId. +void RecordMixingPlayerSpotTriggered(void) { sub_80B37D4(Task_RecordMixing_Main); } @@ -292,7 +292,7 @@ static void ReceiveExchangePacket(u32 which) static void PrintTextOnRecordMixing(const u8 *src) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, src, 0, 1, 0, NULL); CopyWindowToVram(0, 3); } @@ -313,6 +313,7 @@ static void Task_RecordMixing_SoundEffect(u8 taskId) #define tState data[0] #define tSndEffTaskId data[15] +// Note: Currently, special var 8005 contains the player's spot id. static void Task_RecordMixing_Main(u8 taskId) { s16 *data = gTasks[taskId].data; @@ -322,16 +323,16 @@ static void Task_RecordMixing_Main(u8 taskId) case 0: // init sSentRecord = malloc(sizeof(union PlayerRecords)); sReceivedRecords = malloc(sizeof(union PlayerRecords) * 4); - sub_8009628(gSpecialVar_0x8005); + SetLocalLinkPlayerId(gSpecialVar_0x8005); VarSet(VAR_TEMP_0, 1); gUnknown_03001130 = FALSE; PrepareExchangePacket(); CreateRecordMixingSprite(); tState = 1; - data[10] = CreateTask(sub_80E7324, 80); + data[10] = CreateTask(Task_MixingRecordsRecv, 80); tSndEffTaskId = CreateTask(Task_RecordMixing_SoundEffect, 81); break; - case 1: // wait for sub_80E7324 + case 1: // wait for Task_MixingRecordsRecv if (!gTasks[data[10]].isActive) { tState = 2; @@ -341,11 +342,11 @@ static void Task_RecordMixing_Main(u8 taskId) } break; case 2: - data[10] = CreateTask(sub_80E7FF8, 10); + data[10] = CreateTask(Task_DoRecordMixing, 10); tState = 3; PlaySE(SE_W226); break; - case 3: // wait for sub_80E7FF8 + case 3: // wait for Task_DoRecordMixing if (!gTasks[data[10]].isActive) { tState = 4; @@ -370,7 +371,7 @@ static void Task_RecordMixing_Main(u8 taskId) { CreateTask(sub_80AF2B4, 10); } - sub_8197434(0, 1); + ClearDialogWindowAndFrame(0, 1); DestroyTask(taskId); EnableBothScriptContexts(); } @@ -381,7 +382,7 @@ static void Task_RecordMixing_Main(u8 taskId) #undef tState #undef tSndEffTaskId -static void sub_80E7324(u8 taskId) +static void Task_MixingRecordsRecv(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -405,7 +406,7 @@ static void sub_80E7324(u8 taskId) u8 players = GetLinkPlayerCount_2(); if (IsLinkMaster() == TRUE) { - if (players == sub_800AA48()) + if (players == GetSavedPlayerCount()) { PlaySE(SE_PIN); task->data[0] = 201; @@ -420,14 +421,15 @@ static void sub_80E7324(u8 taskId) } break; case 201: - if (sub_800AA48() == GetLinkPlayerCount_2() && ++task->data[12] > (GetLinkPlayerCount_2() * 30)) + // We're the link master. Delay for 30 frames per connected player. + if (GetSavedPlayerCount() == GetLinkPlayerCount_2() && ++task->data[12] > (GetLinkPlayerCount_2() * 30)) { - sub_800A620(); + CheckShouldAdvanceLinkState(); task->data[0] = 1; } break; case 301: - if (sub_800AA48() == GetLinkPlayerCount_2()) + if (GetSavedPlayerCount() == GetLinkPlayerCount_2()) task->data[0] = 1; break; case 400: // wait 20 frames @@ -470,6 +472,7 @@ static void sub_80E7324(u8 taskId) StorePtrInTaskData(sReceivedRecords, (u16 *)&gTasks[subTaskId].data[5]); sRecordStructSize = sizeof(struct PlayerRecordsEmerald); } + // Note: This task is destroyed by Task_CopyReceiveBuffer when it's done. } break; case 5: // wait 60 frames @@ -938,7 +941,7 @@ static void ReceiveGiftItem(u16 *item, u8 which) } } -static void sub_80E7FF8(u8 taskId) +static void Task_DoRecordMixing(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -953,20 +956,22 @@ static void sub_80E7FF8(u8 taskId) else task->data[0] = 6; break; + + // Mixing Ruby/Sapphire records. case 2: SetContinueGameWarpStatusToDynamicWarp(); - sub_8153430(); + FullSaveGame(); task->data[0] ++; break; case 3: - if (sub_8153474()) + if (CheckSaveFile()) { ClearContinueGameWarpStatus2(); task->data[0] = 4; task->data[1] = 0; } break; - case 4: + case 4: // Wait 10 frames if (++task->data[1] > 10) { sub_800AC34(); @@ -974,22 +979,24 @@ static void sub_80E7FF8(u8 taskId) } break; case 5: - if (gReceivedRemoteLinkPlayers == 0) + if (gReceivedRemoteLinkPlayers == FALSE) DestroyTask(taskId); break; + + // Mixing Emerald records. case 6: - if (!sub_801048C(0)) + if (!sub_801048C(FALSE)) { CreateTask(sub_8153688, 5); task->data[0] ++; } break; - case 7: + case 7: // wait for sub_8153688 to finish. if (!FuncIsActiveTask(sub_8153688)) { if (gWirelessCommType) { - sub_801048C(1); + sub_801048C(TRUE); task->data[0] = 8; } else diff --git a/src/region_map.c b/src/region_map.c index ff0c19167..8dadc78a7 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -883,7 +883,7 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) case MAP_TYPE_CITY: case MAP_TYPE_ROUTE: case MAP_TYPE_UNDERWATER: - case MAP_TYPE_6: + case MAP_TYPE_OCEAN_ROUTE: gRegionMap->mapSecId = gMapHeader.regionMapSectionId; gRegionMap->playerIsInCave = FALSE; mapWidth = gMapHeader.mapLayout->width; @@ -896,7 +896,7 @@ static void RegionMap_InitializeStateBasedOnPlayerLocation(void) } break; case MAP_TYPE_UNDERGROUND: - case MAP_TYPE_7: + case MAP_TYPE_UNUSED_2: if (gMapHeader.flags & 0x02) { mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->escapeWarp.mapGroup, gSaveBlock1Ptr->escapeWarp.mapNum); @@ -1159,7 +1159,7 @@ static u16 RegionMap_GetTerraCaveMapSecId(void) { s16 idx; - idx = VarGet(VAR_0x4037) - 1; + idx = VarGet(VAR_UNUSUAL_WEATHER_LOCATION) - 1; if (idx < 0 || idx > 15) { idx = 0; @@ -1171,7 +1171,7 @@ static void RegionMap_GetMarineCaveCoords(u16 *x, u16 *y) { u16 idx; - idx = VarGet(VAR_0x4037); + idx = VarGet(VAR_UNUSUAL_WEATHER_LOCATION); if (idx < 9 || idx > 16) { idx = 9; @@ -1622,7 +1622,7 @@ void MCB2_FlyMap(void) case 7: LoadPalette(sRegionMapFramePal, 0x10, 0x20); PutWindowTilemap(2); - FillWindowPixelBuffer(2, 0x00); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized(2, 1, gText_FlyToWhere, 0, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); gMain.state++; @@ -1687,8 +1687,8 @@ static void sub_8124904(void) { StringLength(gUnknown_085A1EDC[i].name[sFlyMap->regionMap.posWithinMapSec]); flag = TRUE; - sub_8198070(0, FALSE); - SetWindowBorderStyle(1, FALSE, 0x65, 0x0d); + ClearStdWindowAndFrameToTransparent(0, FALSE); + DrawStdFrameWithCustomTileAndPalette(1, FALSE, 0x65, 0x0d); AddTextPrinterParameterized(1, 1, sFlyMap->regionMap.mapSecName, 0, 1, 0, NULL); name = gUnknown_085A1EDC[i].name[sFlyMap->regionMap.posWithinMapSec]; AddTextPrinterParameterized(1, 1, name, GetStringRightAlignXOffset(1, name, 0x60), 0x11, 0, NULL); @@ -1702,12 +1702,12 @@ static void sub_8124904(void) { if (gUnknown_03001180 == TRUE) { - sub_8198070(1, FALSE); - SetWindowBorderStyle(0, FALSE, 0x65, 0x0d); + ClearStdWindowAndFrameToTransparent(1, FALSE); + DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x65, 0x0d); } else { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); } AddTextPrinterParameterized(0, 1, sFlyMap->regionMap.mapSecName, 0, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); @@ -1718,10 +1718,10 @@ static void sub_8124904(void) { if (gUnknown_03001180 == TRUE) { - sub_8198070(1, FALSE); - SetWindowBorderStyle(0, FALSE, 0x65, 0x0d); + ClearStdWindowAndFrameToTransparent(1, FALSE); + DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x65, 0x0d); } - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); CopyWindowToVram(0, 2); schedule_bg_copy_tilemap_to_vram(0); gUnknown_03001180 = FALSE; diff --git a/src/reset_rtc_screen.c b/src/reset_rtc_screen.c index 34444cbf4..ce9f5b98b 100644 --- a/src/reset_rtc_screen.c +++ b/src/reset_rtc_screen.c @@ -290,7 +290,7 @@ static void FreeCursorPalette(void) static void HideChooseTimeWindow(u8 windowId) { - sub_8198070(windowId, FALSE); + ClearStdWindowAndFrameToTransparent(windowId, FALSE); RemoveWindow(windowId); schedule_bg_copy_tilemap_to_vram(0); } @@ -319,7 +319,7 @@ static void PrintTime(u8 windowId, u8 x, u8 y, u16 days, u8 hours, u8 minutes, u static void ShowChooseTimeWindow(u8 windowId, u16 days, u8 hours, u8 minutes, u8 seconds) { - SetWindowBorderStyle(windowId, FALSE, 0x214, 0xE); + DrawStdFrameWithCustomTileAndPalette(windowId, FALSE, 0x214, 0xE); PrintTime(windowId, 0, 1, days, hours, minutes, seconds); AddTextPrinterParameterized(windowId, 1, gText_Confirm2, 126, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); @@ -495,7 +495,7 @@ static void VBlankCB(void) static void ShowMessage(const u8 *str) { - sub_8197B1C(1, FALSE, 0x200, 0xF); + DrawDialogFrameWithCustomTileAndPalette(1, FALSE, 0x200, 0xF); AddTextPrinterParameterized(1, 1, str, 0, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); } @@ -507,7 +507,7 @@ static void Task_ShowResetRtcPrompt(u8 taskId) switch (data[0]) { case 0: - SetWindowBorderStyle(0, FALSE, 0x214, 0xE); + DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x214, 0xE); AddTextPrinterParameterized(0, 1, gText_PresentTime, 0, 1, TEXT_SPEED_FF, 0); PrintTime( 0, @@ -574,7 +574,7 @@ static void Task_ResetRtcScreen(u8 taskId) case 2: if (gTasks[data[1]].isActive != TRUE) { - sub_8198070(0, FALSE); + ClearStdWindowAndFrameToTransparent(0, FALSE); ShowMessage(gText_PleaseResetTime); gLocalTime = gSaveBlock2Ptr->lastBerryTreeUpdate; data[1] = CreateTask(Task_ResetRtc_0, 80); diff --git a/src/reshow_battle_screen.c b/src/reshow_battle_screen.c index 0926d4569..dd177f884 100644 --- a/src/reshow_battle_screen.c +++ b/src/reshow_battle_screen.c @@ -2,6 +2,7 @@ #include "reshow_battle_screen.h" #include "battle.h" #include "palette.h" +#include "pokemon.h" #include "main.h" #include "scanline_effect.h" #include "text.h" @@ -18,8 +19,6 @@ extern const union AnimCmd * const * const gMonAnimationsSpriteAnimsPtrTable[]; -extern void SetMultiuseSpriteTemplateToTrainerBack(u16 backPicId, u8 battlerPosition); - // this file's functions static void CB2_ReshowBattleScreenAfterMenu(void); static bool8 LoadBattlerSpriteGfx(u8 battlerId); diff --git a/src/rock.c b/src/rock.c index 14ffc63e0..814b1d88b 100644 --- a/src/rock.c +++ b/src/rock.c @@ -12,8 +12,6 @@ extern const union AnimCmd *const gUnknown_085950E0[]; extern const union AnimCmd *const gUnknown_085954D0[]; -extern void AnimMoveTwisterParticle(struct Sprite *); - void sub_81109F0(struct Sprite *); void sub_8110AB4(struct Sprite *); void AnimDirtParticleAcrossScreen(struct Sprite *); diff --git a/src/rom_8011DC0.c b/src/rom_8011DC0.c index c8adfbe0b..3d9eab8d7 100644 --- a/src/rom_8011DC0.c +++ b/src/rom_8011DC0.c @@ -33,8 +33,7 @@ #include "start_menu.h" #include "data2.h" #include "field_screen_effect.h" - -extern void HealPlayerParty(void); +#include "script_pokemon_util_80F87D8.h" struct UnkStruct_Shared { @@ -188,7 +187,7 @@ extern u8 gUnknown_02022C3E; extern u16 gUnknown_02022C3C; extern u8 gUnknown_02022C20[]; extern u8 gFieldLinkPlayerCount; -extern u8 gUnknown_03005DB4; +extern u8 gLocalLinkPlayerId; // IWRAM vars IWRAM_DATA struct UnkStruct_Leader *gUnknown_03000DA0; @@ -387,7 +386,7 @@ void nullsub_89(void) void sub_80124EC(u8 windowId, u8 arg1, u8 stringId) { - FillWindowPixelBuffer(windowId, 0x11); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); switch (arg1 << 8) { case 0x200: @@ -506,17 +505,17 @@ void sub_8012780(u8 taskId) } data->field_11 = AddWindow(&gUnknown_082F012C); - FillWindowPixelBuffer(data->field_10, 0x22); + FillWindowPixelBuffer(data->field_10, PIXEL_FILL(2)); sub_80173E0(data->field_10, 0, gUnknown_082EDBC4, 8, 1, 4); PutWindowTilemap(data->field_10); CopyWindowToVram(data->field_10, 2); - NewMenuHelpers_DrawStdWindowFrame(data->listWindowId, FALSE); + DrawStdWindowFrame(data->listWindowId, FALSE); gMultiuseListMenuTemplate = gUnknown_082F015C; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); - NewMenuHelpers_DrawStdWindowFrame(data->field_11, FALSE); + DrawStdWindowFrame(data->field_11, FALSE); PutWindowTilemap(data->field_11); CopyWindowToVram(data->field_11, 2); @@ -786,10 +785,10 @@ void sub_8012780(u8 taskId) void sub_8012F64(struct UnkStruct_Leader *data) { ClearWindowTilemap(data->field_11); - sub_819746C(data->field_11, FALSE); + ClearStdWindowAndFrame(data->field_11, FALSE); DestroyListMenuTask(data->listTaskId, 0, 0); ClearWindowTilemap(data->field_10); - sub_819746C(data->listWindowId, FALSE); + ClearStdWindowAndFrame(data->listWindowId, FALSE); CopyBgTilemapBufferToVram(0); RemoveWindow(data->field_11); RemoveWindow(data->listWindowId); @@ -1075,17 +1074,17 @@ void sub_80134E8(u8 taskId) data->listWindowId = AddWindow(&gUnknown_082F0174); data->field_D = AddWindow(&gUnknown_082F017C); - FillWindowPixelBuffer(data->field_C, 0x22); + FillWindowPixelBuffer(data->field_C, PIXEL_FILL(2)); sub_80173E0(data->field_C, 0, gUnknown_082EF7DC, 8, 1, 4); PutWindowTilemap(data->field_C); CopyWindowToVram(data->field_C, 2); - NewMenuHelpers_DrawStdWindowFrame(data->listWindowId, FALSE); + DrawStdWindowFrame(data->listWindowId, FALSE); gMultiuseListMenuTemplate = gUnknown_082F0204; gMultiuseListMenuTemplate.windowId = data->listWindowId; data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); - NewMenuHelpers_DrawStdWindowFrame(data->field_D, FALSE); + DrawStdWindowFrame(data->field_D, FALSE); PutWindowTilemap(data->field_D); sub_80125BC(data->field_D); CopyWindowToVram(data->field_D, 2); @@ -1254,10 +1253,10 @@ void sub_80134E8(u8 taskId) case 18: case 20: ClearWindowTilemap(data->field_D); - sub_819746C(data->field_D, FALSE); + ClearStdWindowAndFrame(data->field_D, FALSE); DestroyListMenuTask(data->listTaskId, 0, 0); ClearWindowTilemap(data->field_C); - sub_819746C(data->listWindowId, FALSE); + ClearStdWindowAndFrame(data->listWindowId, FALSE); CopyBgTilemapBufferToVram(0); RemoveWindow(data->field_D); RemoveWindow(data->listWindowId); @@ -1641,7 +1640,7 @@ void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 arg4) gSpecialVar_0x8004 = arg4; VarSet(VAR_CABLE_CLUB_STATE, arg4); gFieldLinkPlayerCount = GetLinkPlayerCount(); - gUnknown_03005DB4 = GetMultiplayerId(); + gLocalLinkPlayerId = GetMultiplayerId(); SetCableClubWarp(); SetWarpDestination(mapGroup, mapNum, -1, x, y); WarpIntoMap(); @@ -1697,7 +1696,7 @@ void sub_801440C(u8 taskId) case 81: CleanupOverworldWindowsAndTilemaps(); gMain.savedCallback = sub_801AC54; - sub_81B8518(3); + InitChooseHalfPartyForBattle(3); break; case 1: CleanupOverworldWindowsAndTilemaps(); @@ -2155,7 +2154,7 @@ void sub_8014F48(u8 taskId) data->listTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); sub_8018784(data->field_D); - FillWindowPixelBuffer(data->field_D, 0x11); + FillWindowPixelBuffer(data->field_D, PIXEL_FILL(1)); PutWindowTilemap(data->field_D); sub_80125BC(data->field_D); CopyWindowToVram(data->field_D, 2); diff --git a/src/roulette.c b/src/roulette.c index 4c20bd0fe..05d5006f0 100644 --- a/src/roulette.c +++ b/src/roulette.c @@ -973,7 +973,7 @@ static void sub_81405CC(void) sub_814372C(6); sub_81436D0(0); sub_81424FC(0); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5B89, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); gSpriteCoordOffsetX = -60; @@ -1043,8 +1043,8 @@ static void sub_81408A8(u8 taskId) static void sub_8140914(u8 taskId) { - DisplayYesNoMenu(); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, 0); + DisplayYesNoMenuDefaultYes(); + DrawStdWindowFrame(gUnknown_0203AB8C, 0); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5C13, 0, 1, TEXT_SPEED_FF, 0); CopyWindowToVram(gUnknown_0203AB8C, 3); DoYesNoFuncWithChoice(taskId, &gUnknown_085B6410); @@ -1052,7 +1052,7 @@ static void sub_8140914(u8 taskId) static void sub_8140968(u8 taskId) { - sub_819746C(0, TRUE); + ClearStdWindowAndFrame(0, TRUE); gTasks[taskId].func = sub_8140BD0; } @@ -1808,14 +1808,14 @@ static void sub_814189C(u8 taskId) if (gTasks[taskId].data[2] == 12) { PlayFanfare(MUS_ME_B_BIG); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5BD7, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); } else { PlayFanfare(MUS_ME_B_SMALL); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5BCB, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); } @@ -1823,7 +1823,7 @@ static void sub_814189C(u8 taskId) case 0: default: m4aSongNumStart(SE_HAZURE); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5BE0, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); break; @@ -1867,7 +1867,7 @@ static void sub_8141A18(u8 taskId) { ConvertIntToDecimalStringN(gStringVar1, (gUnknown_0203AB88->var19 * gTasks[taskId].data[2]), STR_CONV_MODE_LEFT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gUnknown_082A5BEF); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gStringVar4, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); gTasks[taskId].data[1] = (gUnknown_0203AB88->var19 * gTasks[taskId].data[2]); @@ -1900,14 +1900,14 @@ static void sub_8141B58(u8 taskId) { if (gTasks[taskId].data[6] == 6) { - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5C21, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); sub_8141F7C(taskId, dp01t_12_3_battle_menu, 0xFFFF, 3); } else if (gTasks[taskId].data[13] == 9999) { - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5C61, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); sub_8141F7C(taskId, sub_8140914, 0xFFFF, 0x3); @@ -1919,7 +1919,7 @@ static void sub_8141B58(u8 taskId) } else { - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5C04, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); sub_8141F7C(taskId, sub_8140994, 0x3C, 0x3); @@ -1944,7 +1944,7 @@ static void dp01t_12_3_battle_menu(u8 taskId) if (gTasks[taskId].data[13] == 9999) { - NewMenuHelpers_DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); + DrawStdWindowFrame(gUnknown_0203AB8C, FALSE); AddTextPrinterParameterized(gUnknown_0203AB8C, 1, gUnknown_082A5C61, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(gUnknown_0203AB8C, 3); sub_8141F7C(taskId, sub_8140914, 0xFFFF, 3); @@ -3256,7 +3256,7 @@ static const struct SpriteTemplate gUnknown_085B7AEC = static void sub_81428C4(u8 r0) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(r0, &gUnknown_085B6408); } @@ -3272,7 +3272,7 @@ static void sub_81428E4(u8 taskId) static void sub_8142918(u8 taskId) { - sub_819746C(0, TRUE); + ClearStdWindowAndFrame(0, TRUE); HideCoinsWindow(); FreeAllWindowBuffers(); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); @@ -3283,7 +3283,7 @@ static void sub_8142918(u8 taskId) static void sub_814297C(u8 taskId) { - sub_819746C(0, FALSE); + ClearStdWindowAndFrame(0, FALSE); HideCoinsWindow(); ScriptContext2_Disable(); DestroyTask(taskId); @@ -3296,7 +3296,7 @@ static void sub_81429A0(u8 taskId) { gSpecialVar_0x8004 = 1; HideCoinsWindow(); - sub_819746C(0, TRUE); + ClearStdWindowAndFrame(0, TRUE); ScriptContext2_Disable(); DestroyTask(taskId); } @@ -3309,7 +3309,7 @@ static void sub_81429F0(u8 taskId) u32 temp = gUnknown_085B6344[(gSpecialVar_0x8004 & 1) + (gSpecialVar_0x8004 >> 7 << 1)]; ConvertIntToDecimalStringN(gStringVar1, temp, STR_CONV_MODE_LEADING_ZEROS, 1); StringExpandPlaceholders(gStringVar4, gUnknown_082A5B12); - NewMenuHelpers_DrawStdWindowFrame(0, FALSE); + DrawStdWindowFrame(0, FALSE); AddTextPrinterParameterized(0, 1, gStringVar4, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(0, 3); gTasks[taskId].func = sub_81428C4; @@ -3326,7 +3326,7 @@ static void Task_Roulette_0(u8 taskId) { if ((gSpecialVar_0x8004 & 0x80) && (gSpecialVar_0x8004 & 1)) { - NewMenuHelpers_DrawStdWindowFrame(0, FALSE); + DrawStdWindowFrame(0, FALSE); AddTextPrinterParameterized(0, 1, gUnknown_082A5B6B, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(0, 3); gTasks[taskId].func = sub_81429F0; @@ -3334,7 +3334,7 @@ static void Task_Roulette_0(u8 taskId) else { StringExpandPlaceholders(gStringVar4, gUnknown_082A5B12); - NewMenuHelpers_DrawStdWindowFrame(0, FALSE); + DrawStdWindowFrame(0, FALSE); AddTextPrinterParameterized(0, 1, gStringVar4, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(0, 3); gTasks[taskId].func = sub_81428C4; @@ -3343,7 +3343,7 @@ static void Task_Roulette_0(u8 taskId) else { StringExpandPlaceholders(gStringVar4, gUnknown_082A5B4E); - NewMenuHelpers_DrawStdWindowFrame(0, FALSE); + DrawStdWindowFrame(0, FALSE); AddTextPrinterParameterized(0, 1, gStringVar4, 0, 1, TEXT_SPEED_FF, NULL); CopyWindowToVram(0, 3); gTasks[taskId].func = sub_81429A0; diff --git a/src/safari_zone.c b/src/safari_zone.c index accf94981..703c3d0cd 100644 --- a/src/safari_zone.c +++ b/src/safari_zone.c @@ -10,6 +10,7 @@ #include "string_util.h" #include "tv.h" #include "constants/game_stat.h" +#include "field_screen_effect.h" struct PokeblockFeeder { @@ -27,8 +28,6 @@ extern const u8 EventScript_2A4B6F[]; extern const u8 EventScript_2A4B4C[]; extern const u8 EventScript_2A4B9B[]; -extern void sub_80AF6F0(void); - EWRAM_DATA u8 gNumSafariBalls = 0; EWRAM_DATA static u16 sSafariZoneStepCounter = 0; EWRAM_DATA static u8 sSafariZoneCaughtMons = 0; diff --git a/src/save.c b/src/save.c index a22e20f0b..361a88e1e 100644 --- a/src/save.c +++ b/src/save.c @@ -1,5 +1,7 @@ #include "global.h" +#include "agb_flash.h" #include "gba/flash_internal.h" +#include "fieldmap.h" #include "save.h" #include "task.h" #include "decompress.h" @@ -8,6 +10,7 @@ #include "pokemon_storage_system.h" #include "main.h" #include "trainer_hill.h" +#include "link.h" #include "constants/game_stat.h" static u16 CalculateChecksum(void *data, u16 size); @@ -70,12 +73,6 @@ const struct SaveSectionOffsets gSaveSectionOffsets[] = SAVEBLOCK_CHUNK(gPokemonStorage, 8), }; -extern void DoSaveFailedScreen(u8); // save_failed_screen -extern bool32 ProgramFlashSectorAndVerify(u8 sector, u8 *data); -extern void save_serialize_map(void); -extern void sub_800ADF8(void); -extern bool8 IsLinkTaskFinished(void); - // iwram common u16 gLastWrittenSector; u32 gLastSaveCounter; @@ -659,10 +656,10 @@ static void UpdateSaveAddresses(void) u8 HandleSavingData(u8 saveType) { u8 i; - u32 *backupVar = gUnknown_0203CF5C; + u32 *backupVar = gTrainerHillVBlankCounter; u8 *tempAddr; - gUnknown_0203CF5C = NULL; + gTrainerHillVBlankCounter = NULL; UpdateSaveAddresses(); switch (saveType) { @@ -705,7 +702,7 @@ u8 HandleSavingData(u8 saveType) save_write_to_flash(0xFFFF, gRamSaveSectionLocations); break; } - gUnknown_0203CF5C = backupVar; + gTrainerHillVBlankCounter = backupVar; return 0; } @@ -768,7 +765,7 @@ u8 sub_8153408(void) // trade.s save return 0; } -u8 sub_8153430(void) +u8 FullSaveGame(void) { if (gFlashMemoryPresent != TRUE) return 1; @@ -780,7 +777,7 @@ u8 sub_8153430(void) return 0; } -bool8 sub_8153474(void) +bool8 CheckSaveFile(void) { u8 retVal = FALSE; u16 val = ++gUnknown_03006208; diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 2478ebbec..08f193890 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -229,10 +229,10 @@ static void CB2_SaveFailedScreen(void) LoadPalette(sSaveFailedClockPal, 0x100, 0x20); LoadPalette(gTextWindowFrame1_Pal, 0xE0, 0x20); LoadPalette(gUnknown_0860F074, 0xF0, 0x20); - SetWindowBorderStyle(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); - SetWindowBorderStyle(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); - FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], 0x11); // backwards? - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + DrawStdFrameWithCustomTileAndPalette(gSaveFailedWindowIds[TEXT_WIN_ID], FALSE, 0x214, 0xE); + DrawStdFrameWithCustomTileAndPalette(gSaveFailedWindowIds[CLOCK_WIN_ID], FALSE, 0x214, 0xE); + FillWindowPixelBuffer(gSaveFailedWindowIds[CLOCK_WIN_ID], PIXEL_FILL(1)); // backwards? + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); CopyWindowToVram(gSaveFailedWindowIds[CLOCK_WIN_ID], 2); // again? CopyWindowToVram(gSaveFailedWindowIds[TEXT_WIN_ID], 1); SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); @@ -265,19 +265,19 @@ static void CB2_WipeSave(void) { if (WipeSectors(gDamagedSaveSectors) != FALSE) { - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); SetMainCallback2(CB2_GameplayCannotBeContinued); return; } - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_CheckCompleted, 1, 0); HandleSavingData(gSaveFailedType); if (gDamagedSaveSectors != 0) { - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_SaveFailedCheckingBackup, 1, 0); } @@ -286,12 +286,12 @@ static void CB2_WipeSave(void) if (wipeTries == 3) { - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_BackupMemoryDamaged, 1, 0); } else { - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); if (gGameContinueCallback == NULL) SaveFailedScreenTextPrint(gText_SaveCompleteGameCannotContinue, 1, 0); @@ -308,7 +308,7 @@ static void CB2_GameplayCannotBeContinued(void) if (gMain.newKeys & A_BUTTON) { - FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], 0x11); + FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0); SetVBlankCallback(VBlankCB); SetMainCallback2(CB2_FadeAndReturnToTitleScreen); diff --git a/src/scrcmd.c b/src/scrcmd.c index 51d96ff2e..314504600 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1203,7 +1203,7 @@ bool8 ScrCmd_turnvobject(struct ScriptContext *ctx) bool8 ScrCmd_lockall(struct ScriptContext *ctx) { - if (is_c1_link_related_active()) + if (IsUpdateLinkStateCBActive()) { return FALSE; } @@ -1217,7 +1217,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx) bool8 ScrCmd_lock(struct ScriptContext *ctx) { - if (is_c1_link_related_active()) + if (IsUpdateLinkStateCBActive()) { return FALSE; } @@ -1302,7 +1302,7 @@ bool8 ScrCmd_cmdDB(struct ScriptContext *ctx) if (msg == NULL) msg = (const u8 *)ctx->data[0]; sub_81973A4(); - NewMenuHelpers_DrawDialogueFrame(0, 1); + DrawDialogueFrame(0, 1); AddTextPrinterParameterized(0, 1, msg, 0, 1, 0, 0); return FALSE; } @@ -1517,9 +1517,9 @@ bool8 ScrCmd_braillemessage(struct ScriptContext *ctx) winTemplate = CreateWindowTemplate(0, xWindow, yWindow + 1, width, height, 0xF, 0x1); gUnknown_03000F30 = AddWindow(&winTemplate); LoadUserWindowBorderGfx(gUnknown_03000F30, 0x214, 0xE0); - NewMenuHelpers_DrawStdWindowFrame(gUnknown_03000F30, 0); + DrawStdWindowFrame(gUnknown_03000F30, 0); PutWindowTilemap(gUnknown_03000F30); - FillWindowPixelBuffer(gUnknown_03000F30, 0x11); + FillWindowPixelBuffer(gUnknown_03000F30, PIXEL_FILL(1)); AddTextPrinterParameterized(gUnknown_03000F30, 6, gStringVar4, xText, yText, 0xFF, 0x0); CopyWindowToVram(gUnknown_03000F30, 3); return FALSE; @@ -2028,14 +2028,14 @@ bool8 ScrCmd_setmetatile(struct ScriptContext *ctx) u16 x = VarGet(ScriptReadHalfword(ctx)); u16 y = VarGet(ScriptReadHalfword(ctx)); u16 tileId = VarGet(ScriptReadHalfword(ctx)); - u16 v8 = VarGet(ScriptReadHalfword(ctx)); + u16 isImpassable = VarGet(ScriptReadHalfword(ctx)); x += 7; y += 7; - if (!v8) + if (!isImpassable) MapGridSetMetatileIdAt(x, y, tileId); else - MapGridSetMetatileIdAt(x, y, tileId | 0xC00); + MapGridSetMetatileIdAt(x, y, tileId | METATILE_COLLISION_MASK); return FALSE; } @@ -2182,7 +2182,7 @@ bool8 ScrCmd_cmdD8(struct ScriptContext *ctx) bool8 ScrCmd_cmdD9(struct ScriptContext *ctx) { - if (is_c1_link_related_active()) + if (IsUpdateLinkStateCBActive()) { return FALSE; } @@ -2254,7 +2254,7 @@ bool8 ScrCmd_setmonmetlocation(struct ScriptContext *ctx) void sub_809BDB4(void) { - sub_819746C(gUnknown_03000F30, 1); + ClearStdWindowAndFrame(gUnknown_03000F30, 1); RemoveWindow(gUnknown_03000F30); } diff --git a/src/script_menu.c b/src/script_menu.c index 7180bfc60..c7523a370 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -1202,7 +1202,7 @@ bool8 ScriptMenu_YesNo(u8 left, u8 top) else { gSpecialVar_Result = 0xFF; - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); taskId = CreateTask(Task_HandleYesNoInput, 0x50); return TRUE; } @@ -1312,7 +1312,7 @@ static void Task_HandleMultichoiceGridInput(u8 taskId) #undef tWindowId -bool8 ScrSpecial_CreatePCMenu(void) +bool16 ScrSpecial_CreatePCMenu(void) { if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) { @@ -1630,7 +1630,7 @@ u8 CreateWindowFromRect(u8 x, u8 y, u8 width, u8 height) void sub_80E2A78(u8 windowId) { - sub_8198070(windowId, TRUE); + ClearStdWindowAndFrameToTransparent(windowId, TRUE); RemoveWindow(windowId); } @@ -1639,27 +1639,27 @@ static void sub_80E2A94(u8 multichoiceId) switch (multichoiceId) { case 77: - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_0858BBAC[Menu_GetCursorPos()], 0, NULL, 2, 1, 3); break; case 76: - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_0858BB9C[Menu_GetCursorPos()], 0, NULL, 2, 1, 3); break; case 78: - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_0858BBBC[Menu_GetCursorPos()], 0, NULL, 2, 1, 3); break; case 79: - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_0858BBCC[Menu_GetCursorPos()], 0, NULL, 2, 1, 3); break; case 75: - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_0858BBEC[Menu_GetCursorPos()], 0, NULL, 2, 1, 3); break; case 74: - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_0858BBE0[Menu_GetCursorPos()], 0, NULL, 2, 1, 3); break; } diff --git a/src/script_pokemon_util_80F87D8.c b/src/script_pokemon_util_80F87D8.c index cade00b50..7d6020c7a 100755 --- a/src/script_pokemon_util_80F87D8.c +++ b/src/script_pokemon_util_80F87D8.c @@ -29,6 +29,7 @@ #include "constants/items.h" #include "constants/species.h" #include "constants/vars.h" +#include "constants/battle_frontier.h" extern const u16 gEventObjectPalette8[]; extern const u16 gEventObjectPalette17[]; @@ -40,7 +41,7 @@ static const u8 gUnknown_0858D8EC[] = { 3, 4, 5, 14 }; static void sub_80F8EE8(u8 taskId); static void sub_80F9088(u8 taskId); -static void sub_80F9460(void); +static void CB2_ReturnFromChooseHalfParty(void); static void sub_80F94B8(void); void SetContestTrainerGfxIds(void) @@ -640,22 +641,24 @@ void ScriptSetMonMoveSlot(u8 monIndex, u16 move, u8 slot) SetMonMoveSlot(&gPlayerParty[monIndex], move, slot); } -void sub_80F9438(void) +// Note: When control returns to the event script, gSpecialVar_Result will be +// TRUE if the party selection was successful. +void ChooseHalfPartyForBattle(void) { - gMain.savedCallback = sub_80F9460; - VarSet(VAR_FRONTIER_FACILITY, 9); // this isn't a valid frontier facility id (??) - sub_81B8518(0); + gMain.savedCallback = CB2_ReturnFromChooseHalfParty; + VarSet(VAR_FRONTIER_FACILITY, FRONTIER_FACILITY_DOUBLE_COLOSSEUM); + InitChooseHalfPartyForBattle(0); } -static void sub_80F9460(void) +static void CB2_ReturnFromChooseHalfParty(void) { switch (gSelectedOrderFromParty[0]) { case 0: - gSpecialVar_Result = 0; + gSpecialVar_Result = FALSE; break; default: - gSpecialVar_Result = 1; + gSpecialVar_Result = TRUE; break; } @@ -665,7 +668,7 @@ static void sub_80F9460(void) void sub_80F9490(void) { gMain.savedCallback = sub_80F94B8; - sub_81B8518(gSpecialVar_0x8004 + 1); + InitChooseHalfPartyForBattle(gSpecialVar_0x8004 + 1); } static void sub_80F94B8(void) diff --git a/src/secret_base.c b/src/secret_base.c index adcab9cbc..4b270e424 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -43,8 +43,6 @@ #include "constants/species.h" #include "constants/trainers.h" -extern void mapldr_default(void); - // Static type declarations struct SecretBaseListMenuBuffer { @@ -60,7 +58,7 @@ struct SecretBaseRecordMixer { // Static RAM declarations EWRAM_DATA u8 sCurSecretBaseId = 0; -EWRAM_DATA u8 gUnknown_0203A01D = 0; +EWRAM_DATA bool8 gInFriendSecretBase = FALSE; EWRAM_DATA struct SecretBaseListMenuBuffer *gUnknown_0203A020 = NULL; // Static ROM declarations @@ -259,7 +257,7 @@ void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile) { for (x = 0; x < mapLayout->width; x ++) { - if ((mapLayout->map[y * mapLayout->width + x] & 0x3ff) == tile) + if ((mapLayout->map[y * mapLayout->width + x] & METATILE_ID_MASK) == tile) { *xPtr = x; *yPtr = y; @@ -282,7 +280,7 @@ void sub_80E8D4C(void) { if (gUnknown_0858CFCC[i].tile1 == tile) { - MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | 0xC00); + MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | METATILE_COLLISION_MASK); CurrentMapDrawMetatileAt(x, y); return; } @@ -291,7 +289,7 @@ void sub_80E8D4C(void) { if (gUnknown_0858CFCC[i].tile2 == tile) { - MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile1 | 0xC00); + MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile1 | METATILE_COLLISION_MASK); CurrentMapDrawMetatileAt(x, y); return; } @@ -352,7 +350,7 @@ void sub_80E8EE0(struct MapEvents const *events) { if (gUnknown_0858CFCC[i].tile1 == tile_id) { - MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | 0xc00); + MapGridSetMetatileIdAt(x, y, gUnknown_0858CFCC[i].tile2 | METATILE_COLLISION_MASK); break; } } @@ -407,7 +405,7 @@ void sub_80E9068(void) bool8 sub_80E909C(void) { - if (gMapHeader.mapType == MAP_TYPE_SECRET_BASE && VarGet(VAR_0x4097) == 0) + if (gMapHeader.mapType == MAP_TYPE_SECRET_BASE && VarGet(VAR_INIT_SECRET_BASE) == 0) { return FALSE; } @@ -434,7 +432,7 @@ void sub_80E9108(void) sub_80E8CB0(&x, &y, 0x220); x += 7; y += 7; - MapGridSetMetatileIdAt(x, y, 0x220 | 0xC00); + MapGridSetMetatileIdAt(x, y, 0x220 | METATILE_COLLISION_MASK); CurrentMapDrawMetatileAt(x, y); pal_fill_black(); CreateTask(sub_80E90C8, 0); @@ -492,12 +490,12 @@ void sub_80E9238(u8 flagIn) if (curBaseId != 0) { sub_80E8CB0(&x, &y, 0x220); - MapGridSetMetatileIdAt(x + 7, y + 7, 0x221 | 0xc00); + MapGridSetMetatileIdAt(x + 7, y + 7, 0x221 | METATILE_COLLISION_MASK); } - else if (flagIn == 1 && VarGet(VAR_0x4089) == 1) + else if (flagIn == 1 && VarGet(VAR_SECRET_BASE_INITIALIZED) == 1) { sub_80E8CB0(&x, &y, 0x220); - MapGridSetMetatileIdAt(x + 7, y + 7, 0x20a | 0xc00); + MapGridSetMetatileIdAt(x + 7, y + 7, 0x20a | METATILE_COLLISION_MASK); } } } @@ -552,7 +550,7 @@ void sub_80E933C(void) metatile = MapGridGetMetatileBehaviorAt(gSpecialVar_0x8006 + 7, gSpecialVar_0x8007 + 7); if (MetatileBehavior_IsSecretBaseLargeMatEdge(metatile) == TRUE || MetatileBehavior_IsLargeMatCenter(metatile) == TRUE) { - gSpecialVar_Result = gMapHeader.events->eventObjects[objIdx].graphicsId + VAR_0x3F20; + gSpecialVar_Result = gMapHeader.events->eventObjects[objIdx].graphicsId + UNKNOWN_VAR_OFFSET_3F20; VarSet(gSpecialVar_Result, gDecorations[roomDecor[decorIdx]].tiles[0]); gSpecialVar_Result = gMapHeader.events->eventObjects[objIdx].localId; FlagClear(gSpecialVar_0x8004 + 0xAE); @@ -791,7 +789,7 @@ void sub_80E9AD0(void) { if (gUnknown_0858CFCC[j].tile2 == tile) { - MapGridSetMetatileIdAt(events->bgEvents[i].x + 7, events->bgEvents[i].y + 7, gUnknown_0858CFCC[j].tile1 | 0xc00); + MapGridSetMetatileIdAt(events->bgEvents[i].x + 7, events->bgEvents[i].y + 7, gUnknown_0858CFCC[j].tile1 | METATILE_COLLISION_MASK); break; } } @@ -871,7 +869,7 @@ void sub_80E9C9C(u8 taskId) { data[1] = 0; data[2] = 0; - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); gUnknown_0203A020 = calloc(1, sizeof(struct SecretBaseListMenuBuffer)); data[6] = AddWindow(&gUnknown_0858D06C[0]); game_continue(taskId); @@ -963,7 +961,7 @@ void sub_80E9E90(u8 taskId) PlaySE(SE_SELECT); DestroyListMenuTask(data[5], NULL, NULL); RemoveScrollIndicatorArrowPair(data[8]); - sub_819746C(data[6], 0); + ClearStdWindowAndFrame(data[6], 0); ClearWindowTilemap(data[6]); RemoveWindow(data[6]); schedule_bg_copy_tilemap_to_vram(0); @@ -1020,8 +1018,8 @@ void sub_80E9FFC(u8 taskId) s16 *data; data = gTasks[taskId].data; - sub_819746C(data[6], FALSE); - sub_819746C(data[7], FALSE); + ClearStdWindowAndFrame(data[6], FALSE); + ClearStdWindowAndFrame(data[7], FALSE); ClearWindowTilemap(data[6]); ClearWindowTilemap(data[7]); RemoveWindow(data[7]); @@ -1033,7 +1031,7 @@ void sub_80E9FFC(u8 taskId) void sub_80EA06C(u8 taskId) { - DisplayYesNoMenu(); + DisplayYesNoMenuDefaultYes(); DoYesNoFuncWithChoice(taskId, &gUnknown_0858D058); } @@ -1042,7 +1040,7 @@ void sub_80EA08C(u8 taskId) s16 *data; data = gTasks[taskId].data; - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); DestroyListMenuTask(data[5], &data[2], &data[1]); gSaveBlock1Ptr->secretBases[data[4]].sbr_field_1_6 = 0; game_continue(taskId); @@ -1061,7 +1059,7 @@ void sub_80EA13C(u8 taskId) s16 *data; data = gTasks[taskId].data; - sub_8197434(0, 0); + ClearDialogWindowAndFrame(0, 0); DestroyListMenuTask(data[5], &data[2], &data[1]); sub_80E9E00(taskId); gTasks[taskId].func = sub_80E9E90; @@ -1073,7 +1071,7 @@ void sub_80EA18C(u8 taskId) data = gTasks[taskId].data; sub_80E9E44(taskId); - sub_819746C(data[7], 0); + ClearStdWindowAndFrame(data[7], 0); ClearWindowTilemap(data[7]); RemoveWindow(data[7]); schedule_bg_copy_tilemap_to_vram(0); @@ -1186,11 +1184,11 @@ void SecretBasePerStepCallback(u8 taskId) case 0: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - gUnknown_0203A01D = TRUE; + gInFriendSecretBase = TRUE; } else { - gUnknown_0203A01D = FALSE; + gInFriendSecretBase = FALSE; } PlayerGetDestCoords(&data[2], &data[3]); data[1] = 1; @@ -1201,103 +1199,103 @@ void SecretBasePerStepCallback(u8 taskId) { data[2] = x; data[3] = y; - VarSet(VAR_0x40EC, VarGet(VAR_0x40EC) + 1); + VarSet(VAR_SECRET_BASE_STEP_COUNTER, VarGet(VAR_SECRET_BASE_STEP_COUNTER) + 1); behavior = MapGridGetMetatileBehaviorAt(x, y); tileId = MapGridGetMetatileIdAt(x, y); if (tileId == 0x234 || tileId == 0x23C) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x20); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x20); } } else if (tileId == 0x2b8 || tileId == 0x2b9 || tileId == 0x2ba || tileId == 0x2c0 || tileId == 0x2c1 || tileId == 0x2c2 || tileId == 0x2c8 || tileId == 0x2c9 || tileId == 0x2ca) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x01); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x01); } } else if (tileId == 0x239 || tileId == 0x241 || tileId == 0x251 || tileId == 0x259) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x04); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x04); } } else if ((behavior == 0x34 && tileId == 0x26d) || (behavior == 0x35 && MapGridGetMetatileIdAt(x, y) == 0x26a)) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x200); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x200); } } else if (behavior == 0xc1 && tileId == 0x23d) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) ^ 0x1000); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x2000); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) ^ 0x1000); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x2000); } } else if (behavior == 0x47 && tileId == 0x23e) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x1000); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) ^ 0x2000); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x1000); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) ^ 0x2000); } } else if (MetatileBehavior_IsSecretBaseGlitterMat(behavior) == TRUE) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x80); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x80); } } else if (MetatileBehavior_IsSecretBaseBalloon(behavior) == TRUE) { PopSecretBaseBalloon(MapGridGetMetatileIdAt(x, y), x, y); - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { switch ((int)MapGridGetMetatileIdAt(x, y)) { case 0x338: case 0x33c: case 0x340: - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x02); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x02); break; case 0x228: - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x100); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x100); break; } } } else if (MetatileBehavior_IsSecretBaseBreakableDoor(behavior) == TRUE) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x400); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x400); } ShatterSecretBaseBreakableDoor(x, y); } else if (MetatileBehavior_IsSecretBaseSoundMat(behavior) == TRUE){ - if (gUnknown_0203A01D == TRUE) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x8000); + if (gInFriendSecretBase == TRUE) { + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x8000); } } else if (MetatileBehavior_IsSecretBaseJumpMat(behavior) == TRUE) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x4000); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x4000); } } else if (MetatileBehavior_IsSecretBaseSpinMat(behavior) == TRUE) { - if (gUnknown_0203A01D == TRUE) + if (gInFriendSecretBase == TRUE) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x02); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x02); } } } @@ -1780,33 +1778,33 @@ void sub_80EB18C(struct SecretBaseRecord *bases) void sub_80EB1AC(void) { - VarSet(VAR_0x40EC, 0); - VarSet(VAR_0x40ED, 0); - VarSet(VAR_0x40EE, 0); - VarSet(VAR_0x40EF, 0); + VarSet(VAR_SECRET_BASE_STEP_COUNTER, 0); + VarSet(VAR_SECRET_BASE_LAST_ITEM_USED, 0); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, 0); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, 0); if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40F0, TRUE); + VarSet(VAR_SECRET_BASE_IS_NOT_LOCAL, TRUE); } else { - VarSet(VAR_0x40F0, FALSE); + VarSet(VAR_SECRET_BASE_IS_NOT_LOCAL, FALSE); } - gUnknown_0203A01D = FALSE; + gInFriendSecretBase = FALSE; } void sub_80EB218(void) { - if (VarGet(VAR_0x40F0) && gUnknown_0203A01D == TRUE && !CurrentMapIsSecretBase()) + if (VarGet(VAR_SECRET_BASE_IS_NOT_LOCAL) && gInFriendSecretBase == TRUE && !CurrentMapIsSecretBase()) { - VarSet(VAR_0x40F0, FALSE); - gUnknown_0203A01D = FALSE; + VarSet(VAR_SECRET_BASE_IS_NOT_LOCAL, FALSE); + gInFriendSecretBase = FALSE; sub_80EEA70(); - VarSet(VAR_0x40EC, 0); - VarSet(VAR_0x40ED, 0); - VarSet(VAR_0x40EE, 0); - VarSet(VAR_0x40EF, 0); - VarSet(VAR_0x40F0, FALSE); + VarSet(VAR_SECRET_BASE_STEP_COUNTER, 0); + VarSet(VAR_SECRET_BASE_LAST_ITEM_USED, 0); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, 0); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, 0); + VarSet(VAR_SECRET_BASE_IS_NOT_LOCAL, FALSE); } } @@ -1814,7 +1812,7 @@ void sub_80EB290(void) { if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x800); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x800); } } @@ -1822,7 +1820,7 @@ void sub_80EB2C8(void) { if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x400); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x400); } } @@ -1830,9 +1828,9 @@ void sub_80EB300(void) { if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001); - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x2000); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) & ~0x3800); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) & ~0x001); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x2000); } } @@ -1840,9 +1838,9 @@ void sub_80EB368(void) { if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001); - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x800); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) & ~0x3800); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) & ~0x001); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x800); } } @@ -1850,9 +1848,9 @@ void sub_80EB3D0(void) { if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001); - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x1000); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) & ~0x3800); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) & ~0x001); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x1000); } } @@ -1860,9 +1858,9 @@ void sub_80EB438(void) { if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) & ~0x3800); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) & ~0x001); - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x001); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) & ~0x3800); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) & ~0x001); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x001); } } @@ -1891,7 +1889,7 @@ void sub_80EB498(void) case 0x334: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x4000); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x4000); } break; } @@ -1909,7 +1907,7 @@ void sub_80EB56C(void) case 0x28b: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x40); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x40); } break; case 0x2d8: @@ -1932,21 +1930,21 @@ void sub_80EB56C(void) case 0x2fb: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EE, VarGet(VAR_0x40EE) | 0x8); + VarSet(VAR_SECRET_BASE_LOW_TV_FLAGS, VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) | 0x8); } break; case 0x22c: case 0x233: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x40); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x40); } break; case 0x288: case 0x289: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x100); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x100); } break; case 0x22d: @@ -1954,7 +1952,7 @@ void sub_80EB56C(void) case 0x22f: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x10); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x10); } break; case 0x287: @@ -1982,7 +1980,7 @@ void sub_80EB56C(void) case 0x2cf: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x8); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x8); } break; } @@ -2009,7 +2007,7 @@ void sub_80EB9E0(void) case 0x2c6: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x8); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x8); } break; } @@ -2047,14 +2045,14 @@ void sub_80EBB28(void) case 0x2c7: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x8); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x8); } break; case 0x280: case 0x281: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x100); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x100); } break; case 0x225: @@ -2062,7 +2060,7 @@ void sub_80EBB28(void) case 0x227: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x10); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x10); } break; } @@ -2080,7 +2078,7 @@ void sub_80EBE7C(void) case 0x28e: if (VarGet(VAR_CURRENT_SECRET_BASE) != 0) { - VarSet(VAR_0x40EF, VarGet(VAR_0x40EF) | 0x4); + VarSet(VAR_SECRET_BASE_HIGH_TV_FLAGS, VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) | 0x4); } break; } diff --git a/src/shop.c b/src/shop.c index 8eefd5e97..e03e2ab0c 100755 --- a/src/shop.c +++ b/src/shop.c @@ -366,7 +366,7 @@ void CB2_ExitSellMenu(void) static void Task_HandleShopMenuQuit(u8 taskId) { - sub_8198070(gMartInfo.windowId, 2); + ClearStdWindowAndFrameToTransparent(gMartInfo.windowId, 2); RemoveWindow(gMartInfo.windowId); SaveRecordedItemPurchasesForTVShow(); ScriptContext2_Disable(); @@ -545,7 +545,7 @@ static void BuyMenuPrintItemDescriptionAndShowItemIcon(int item, bool8 onInit, s description = gText_QuitShopping; } - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); BuyMenuPrint(2, description, 3, 1, 0, 0); } @@ -981,12 +981,12 @@ static void Task_BuyHowManyDialogueInit(u8 taskId) u16 quantityInBag = CountTotalItemQuantityInBag(tItemId); u16 maxQuantity; - SetWindowBorderStyle(3, FALSE, 1, 13); + DrawStdFrameWithCustomTileAndPalette(3, FALSE, 1, 13); ConvertIntToDecimalStringN(gStringVar1, quantityInBag, STR_CONV_MODE_RIGHT_ALIGN, 4); StringExpandPlaceholders(gStringVar4, gText_InBagVar1); BuyMenuPrint(3, gStringVar4, 0, 1, 0, 0); tItemCount = 1; - SetWindowBorderStyle(4, FALSE, 1, 13); + DrawStdFrameWithCustomTileAndPalette(4, FALSE, 1, 13); BuyMenuPrintItemQuantityAndPrice(taskId); schedule_bg_copy_tilemap_to_vram(0); @@ -1018,8 +1018,8 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - sub_8198070(4, 0); - sub_8198070(3, 0); + ClearStdWindowAndFrameToTransparent(4, 0); + ClearStdWindowAndFrameToTransparent(3, 0); ClearWindowTilemap(4); ClearWindowTilemap(3); PutWindowTilemap(1); @@ -1031,8 +1031,8 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_8198070(4, 0); - sub_8198070(3, 0); + ClearStdWindowAndFrameToTransparent(4, 0); + ClearStdWindowAndFrameToTransparent(3, 0); ClearWindowTilemap(4); ClearWindowTilemap(3); BuyMenuReturnToItemList(taskId); @@ -1131,7 +1131,7 @@ static void BuyMenuReturnToItemList(u8 taskId) { s16 *data = gTasks[taskId].data; - sub_8197DF8(5, 0); + ClearDialogWindowAndFrameToTransparent(5, 0); BuyMenuPrintCursor(tListTaskId, 1); PutWindowTilemap(1); PutWindowTilemap(2); @@ -1144,7 +1144,7 @@ static void BuyMenuPrintItemQuantityAndPrice(u8 taskId) { s16 *data = gTasks[taskId].data; - FillWindowPixelBuffer(4, 0x11); + FillWindowPixelBuffer(4, PIXEL_FILL(1)); PrintMoneyAmount(4, 38, 1, gShopDataPtr->totalCost, TEXT_SPEED_FF); ConvertIntToDecimalStringN(gStringVar1, tItemCount, 2, 2); StringExpandPlaceholders(gStringVar4, gText_xVar1); diff --git a/src/siirtc.c b/src/siirtc.c index f7e85ef4f..5c153a841 100644 --- a/src/siirtc.c +++ b/src/siirtc.c @@ -76,19 +76,19 @@ static void DisableGpioPortRead(); static const char AgbLibRtcVersion[] = "SIIRTC_V001"; -void SiiRtcUnprotect() +void SiiRtcUnprotect(void) { EnableGpioPortRead(); sLocked = FALSE; } -void SiiRtcProtect() +void SiiRtcProtect(void) { DisableGpioPortRead(); sLocked = TRUE; } -u8 SiiRtcProbe() +u8 SiiRtcProbe(void) { u8 errorCode; struct SiiRtcInfo rtc; @@ -129,7 +129,7 @@ u8 SiiRtcProbe() return (errorCode << 4) | 1; } -bool8 SiiRtcReset() +bool8 SiiRtcReset(void) { u8 result; struct SiiRtcInfo rtc; diff --git a/src/slot_machine.c b/src/slot_machine.c index fb1c88097..a2e1f1554 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -1025,7 +1025,7 @@ static bool8 SlotAction_AwaitPlayerInput(struct Task *task) static bool8 SlotAction_PrintYouDontHaveThreeCoins(struct Task *task) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, gText_YouDontHaveThreeCoins, 0, 1, 0, 0); CopyWindowToVram(0, 3); sSlotMachine->state = 7; @@ -1036,7 +1036,7 @@ static bool8 SlotAction_ExitYouDontHaveThreeCoinsMessage(struct Task *task) { if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); sSlotMachine->state = 5; } return FALSE; @@ -1274,7 +1274,7 @@ static bool8 SlotAction_NoMatches(struct Task *task) static bool8 SlotAction_PrintQuitTheGame(struct Task *task) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, gText_QuitTheGame, 0, 1, 0, 0); CopyWindowToVram(0, 3); CreateYesNoMenuParameterized(0x15, 7, 0x214, 0x180, 0xE, 0xF); @@ -1287,7 +1287,7 @@ static bool8 SlotAction_SeeIfPlayerQuits(struct Task *task) s8 input = Menu_ProcessInputNoWrapClearOnChoose(); if (input == 0) // player chooses to quit { - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); sub_8103D8C(0); sub_8103D8C(1); sub_8103D8C(2); @@ -1296,7 +1296,7 @@ static bool8 SlotAction_SeeIfPlayerQuits(struct Task *task) } else if (input == 1 || input == -1) // player chooses not to quit { - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); sSlotMachine->state = 5; } return FALSE; @@ -1304,7 +1304,7 @@ static bool8 SlotAction_SeeIfPlayerQuits(struct Task *task) static bool8 SlotAction_PrintMessage_9999Coins(struct Task *task) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, gText_YouveGot9999Coins, 0, 1, 0, 0); CopyWindowToVram(0, 3); sSlotMachine->state = 24; @@ -1315,7 +1315,7 @@ static bool8 SlotAction_ExitMessage_9999Coins(struct Task *task) { if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); sSlotMachine->state = 5; } return FALSE; @@ -1323,7 +1323,7 @@ static bool8 SlotAction_ExitMessage_9999Coins(struct Task *task) static bool8 SlotAction_PrintMessage_NoMoreCoins(struct Task *task) { - NewMenuHelpers_DrawDialogueFrame(0, 0); + DrawDialogueFrame(0, 0); AddTextPrinterParameterized(0, 1, gText_YouveRunOutOfCoins, 0, 1, 0, 0); CopyWindowToVram(0, 3); sSlotMachine->state = 26; @@ -1334,7 +1334,7 @@ static bool8 SlotAction_ExitMessage_NoMoreCoins(struct Task *task) { if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); sSlotMachine->state = 27; } return FALSE; @@ -3120,7 +3120,7 @@ static void InfoBox_8104B80(struct Task *task) sub_81065DC(); AddWindow(&gUnknown_085A7444); PutWindowTilemap(1); - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); task->data[0]++; } @@ -3136,7 +3136,7 @@ static void InfoBox_AwaitPlayerInput(struct Task *task) { if (gMain.newKeys & (B_BUTTON | SELECT_BUTTON)) { - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); ClearWindowTilemap(1); CopyWindowToVram(1, 1); RemoveWindow(1); diff --git a/src/start_menu.c b/src/start_menu.c index 6efd7a04a..4822c12e6 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -1,44 +1,49 @@ #include "global.h" -#include "start_menu.h" -#include "menu.h" -#include "safari_zone.h" -#include "event_data.h" -#include "window.h" -#include "string_util.h" -#include "text.h" -#include "strings.h" +#include "battle_pike.h" +#include "battle_pyramid.h" +#include "battle_pyramid_bag.h" #include "bg.h" +#include "event_data.h" +#include "event_object_movement.h" +#include "event_obj_lock.h" +#include "event_scripts.h" +#include "fieldmap.h" #include "field_effect.h" -#include "party_menu.h" -#include "frontier_pass.h" -#include "task.h" -#include "overworld.h" -#include "link.h" -#include "frontier_util.h" +#include "field_player_avatar.h" #include "field_specials.h" -#include "event_object_movement.h" -#include "script.h" -#include "main.h" -#include "sound.h" -#include "pokedex.h" #include "field_weather.h" -#include "palette.h" +#include "field_screen_effect.h" +#include "frontier_pass.h" +#include "frontier_util.h" +#include "gpu_regs.h" +#include "international_string_util.h" #include "item_menu.h" +#include "link.h" +#include "load_save.h" +#include "main.h" +#include "menu.h" +#include "new_game.h" #include "option_menu.h" -#include "event_scripts.h" +#include "overworld.h" +#include "palette.h" +#include "party_menu.h" +#include "pokedex.h" +#include "pokenav.h" +#include "safari_zone.h" #include "save.h" -#include "gpu_regs.h" #include "scanline_effect.h" +#include "script.h" +#include "sound.h" +#include "start_menu.h" +#include "strings.h" +#include "string_util.h" +#include "task.h" +#include "text.h" #include "text_window.h" -#include "load_save.h" #include "trainer_card.h" -#include "international_string_util.h" +#include "window.h" #include "constants/songs.h" -#include "field_player_avatar.h" -#include "battle_pyramid.h" -#include "battle_pyramid_bag.h" -#include "battle_pike.h" -#include "new_game.h" +#include "rom_8011DC0.h" // Menu actions enum @@ -83,19 +88,6 @@ EWRAM_DATA static u8 sSaveDialogTimer = 0; EWRAM_DATA static bool8 sSavingComplete = FALSE; EWRAM_DATA static u8 sSaveInfoWindowId = 0; -// Extern variables. -extern u8 gUnknown_03005DB4; - -// Extern functions in not decompiled files. -extern void sub_80AF688(void); -extern void var_800D_set_xB(void); -extern void sub_808B864(void); -extern void CB2_Pokedex(void); -extern void PlayRainStoppingSoundEffect(void); -extern void CB2_PokeNav(void); -extern void ScriptUnfreezeEventObjects(void); -extern void save_serialize_map(void); - // Menu action callbacks static bool8 StartMenuPokedexCallback(void); static bool8 StartMenuPokemonCallback(void); @@ -123,7 +115,7 @@ static u8 SaveConfirmSaveCallback(void); static u8 SaveYesNoCallback(void); static u8 SaveConfirmInputCallback(void); static u8 SaveFileExistsCallback(void); -static u8 SaveConfirmOverwriteNoCallback(void); +static u8 SaveConfirmOverwriteDefaultNoCallback(void); static u8 SaveConfirmOverwriteCallback(void); static u8 SaveOverwriteInputCallback(void); static u8 SaveSavingMessageCallback(void); @@ -244,7 +236,7 @@ static void BuildStartMenuActions(void) { sNumStartMenuActions = 0; - if (is_c1_link_related_active() == TRUE) + if (IsUpdateLinkStateCBActive() == TRUE) { BuildLinkModeStartMenu(); } @@ -376,7 +368,7 @@ static void ShowSafariBallsWindow(void) { sSafariBallsWindowId = AddWindow(&sSafariBallsWindowTemplate); PutWindowTilemap(sSafariBallsWindowId); - NewMenuHelpers_DrawStdWindowFrame(sSafariBallsWindowId, FALSE); + DrawStdWindowFrame(sSafariBallsWindowId, FALSE); ConvertIntToDecimalStringN(gStringVar1, gNumSafariBalls, STR_CONV_MODE_RIGHT_ALIGN, 2); StringExpandPlaceholders(gStringVar4, gText_SafariBallStock); AddTextPrinterParameterized(sSafariBallsWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL); @@ -391,7 +383,7 @@ static void ShowPyramidFloorWindow(void) sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_2); PutWindowTilemap(sBattlePyramidFloorWindowId); - NewMenuHelpers_DrawStdWindowFrame(sBattlePyramidFloorWindowId, FALSE); + DrawStdWindowFrame(sBattlePyramidFloorWindowId, FALSE); StringCopy(gStringVar1, sPyramindFloorNames[gSaveBlock2Ptr->frontier.curChallengeBattleNum]); StringExpandPlaceholders(gStringVar4, gText_BattlePyramidFloor); AddTextPrinterParameterized(sBattlePyramidFloorWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL); @@ -402,13 +394,13 @@ static void RemoveExtraStartMenuWindows(void) { if (GetSafariZoneFlag()) { - sub_8198070(sSafariBallsWindowId, FALSE); + ClearStdWindowAndFrameToTransparent(sSafariBallsWindowId, FALSE); CopyWindowToVram(sSafariBallsWindowId, 2); RemoveWindow(sSafariBallsWindowId); } if (InBattlePyramid()) { - sub_8198070(sBattlePyramidFloorWindowId, FALSE); + ClearStdWindowAndFrameToTransparent(sBattlePyramidFloorWindowId, FALSE); RemoveWindow(sBattlePyramidFloorWindowId); } } @@ -459,7 +451,7 @@ static bool32 InitStartMenuStep(void) break; case 2: sub_81973A4(); - NewMenuHelpers_DrawStdWindowFrame(sub_81979C4(sNumStartMenuActions), FALSE); + DrawStdWindowFrame(sub_81979C4(sNumStartMenuActions), FALSE); sUnknown_02037619[1] = 0; sUnknown_02037619[0]++; break; @@ -547,7 +539,7 @@ void sub_809FA34(u8 taskId) // Referenced in field_screen.s and rom_8011DC0.s void ShowStartMenu(void) // Called from overworld.c and field_control_avatar.s { - if (!is_c1_link_related_active()) + if (!IsUpdateLinkStateCBActive()) { FreezeEventObjects(); sub_808B864(); @@ -656,7 +648,7 @@ static bool8 StartMenuPokeNavCallback(void) PlayRainStoppingSoundEffect(); RemoveExtraStartMenuWindows(); CleanupOverworldWindowsAndTilemaps(); - SetMainCallback2(CB2_PokeNav); // Display PokeNav + SetMainCallback2(CB2_InitPokeNav); // Display PokeNav return TRUE; } @@ -672,7 +664,7 @@ static bool8 StartMenuPlayerNameCallback(void) RemoveExtraStartMenuWindows(); CleanupOverworldWindowsAndTilemaps(); - if (is_c1_link_related_active() || InUnionRoom()) + if (IsUpdateLinkStateCBActive() || InUnionRoom()) ShowPlayerTrainerCard(CB2_ReturnToFieldWithOpenMenu); // Display trainer card else if (FlagGet(FLAG_SYS_FRONTIER_PASS)) ShowFrontierPass(CB2_ReturnToFieldWithOpenMenu); // Display frontier pass @@ -734,7 +726,7 @@ static bool8 StartMenuLinkModePlayerNameCallback(void) { PlayRainStoppingSoundEffect(); CleanupOverworldWindowsAndTilemaps(); - ShowTrainerCardInLink(gUnknown_03005DB4, CB2_ReturnToFieldWithOpenMenu); + ShowTrainerCardInLink(gLocalLinkPlayerId, CB2_ReturnToFieldWithOpenMenu); return TRUE; } @@ -751,7 +743,7 @@ static bool8 StartMenuBattlePyramidRetireCallback(void) void sub_809FDD4(void) { - sub_8197DF8(0, FALSE); + ClearDialogWindowAndFrameToTransparent(0, FALSE); ScriptUnfreezeEventObjects(); CreateStartMenuTask(sub_809FA34); ScriptContext2_Enable(); @@ -787,13 +779,13 @@ static bool8 SaveCallback(void) case SAVE_IN_PROGRESS: return FALSE; case SAVE_CANCELED: // Back to start menu - sub_8197DF8(0, FALSE); + ClearDialogWindowAndFrameToTransparent(0, FALSE); InitStartMenu(); gMenuCallback = HandleStartMenuInput; return FALSE; case SAVE_SUCCESS: case SAVE_ERROR: // Close start menu - sub_8197DF8(0, TRUE); + ClearDialogWindowAndFrameToTransparent(0, TRUE); ScriptUnfreezeEventObjects(); ScriptContext2_Disable(); SoftResetInBattlePyramid(); @@ -830,7 +822,7 @@ static bool8 BattlePyramidRetireCallback(void) case SAVE_IN_PROGRESS: return FALSE; case SAVE_CANCELED: // Yes (Retire from battle pyramid) - sub_8197DF8(0, TRUE); + ClearDialogWindowAndFrameToTransparent(0, TRUE); ScriptUnfreezeEventObjects(); ScriptContext2_Disable(); ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88); @@ -897,7 +889,7 @@ static void SaveGameTask(u8 taskId) static void sub_80A0014(void) { - sub_8197434(0, TRUE); + ClearDialogWindowAndFrame(0, TRUE); } static void HideSaveInfoWindow(void) @@ -943,7 +935,7 @@ static bool8 SaveErrorTimer(void) static u8 SaveConfirmSaveCallback(void) { - sub_819746C(GetStartMenuWindowId(), FALSE); + ClearStdWindowAndFrame(GetStartMenuWindowId(), FALSE); RemoveStartMenuWindow(); ShowSaveInfoWindow(); @@ -961,7 +953,7 @@ static u8 SaveConfirmSaveCallback(void) static u8 SaveYesNoCallback(void) { - DisplayYesNoMenu(); // Show Yes/No menu + DisplayYesNoMenuDefaultYes(); // Show Yes/No menu sSaveDialogCallback = SaveConfirmInputCallback; return SAVE_IN_PROGRESS; } @@ -1002,7 +994,7 @@ static u8 SaveFileExistsCallback(void) { if (gDifferentSaveFile == TRUE) { - ShowSaveMessage(gText_DifferentSaveFile, SaveConfirmOverwriteNoCallback); + ShowSaveMessage(gText_DifferentSaveFile, SaveConfirmOverwriteDefaultNoCallback); } else { @@ -1012,16 +1004,16 @@ static u8 SaveFileExistsCallback(void) return SAVE_IN_PROGRESS; } -static u8 SaveConfirmOverwriteNoCallback(void) +static u8 SaveConfirmOverwriteDefaultNoCallback(void) { - sub_8197948(1); // Show Yes/No menu (No selected as default) + DisplayYesNoMenuWithDefault(1); // Show Yes/No menu (No selected as default) sSaveDialogCallback = SaveOverwriteInputCallback; return SAVE_IN_PROGRESS; } static u8 SaveConfirmOverwriteCallback(void) { - DisplayYesNoMenu(); // Show Yes/No menu + DisplayYesNoMenuDefaultYes(); // Show Yes/No menu sSaveDialogCallback = SaveOverwriteInputCallback; return SAVE_IN_PROGRESS; } @@ -1135,7 +1127,7 @@ static void InitBattlePyramidRetire(void) static u8 BattlePyramidConfirmRetireCallback(void) { - sub_819746C(GetStartMenuWindowId(), FALSE); + ClearStdWindowAndFrame(GetStartMenuWindowId(), FALSE); RemoveStartMenuWindow(); ShowSaveMessage(gText_BattlePyramidConfirmRetire, BattlePyramidRetireYesNoCallback); @@ -1144,7 +1136,7 @@ static u8 BattlePyramidConfirmRetireCallback(void) static u8 BattlePyramidRetireYesNoCallback(void) { - sub_8197948(1); // Show Yes/No menu (No selected as default) + DisplayYesNoMenuWithDefault(1); // Show Yes/No menu (No selected as default) sSaveDialogCallback = BattlePyramidRetireInputCallback; return SAVE_IN_PROGRESS; @@ -1232,7 +1224,7 @@ static void sub_80A0550(u8 taskId) switch (*step) { case 0: - FillWindowPixelBuffer(0, 17); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gText_SavingDontTurnOffPower, @@ -1265,11 +1257,11 @@ static void sub_80A0550(u8 taskId) break; case 1: SetContinueGameWarpStatusToDynamicWarp(); - sub_8153430(); + FullSaveGame(); *step = 2; break; case 2: - if (sub_8153474()) + if (CheckSaveFile()) { ClearContinueGameWarpStatus2(); *step = 3; @@ -1313,7 +1305,7 @@ static void ShowSaveInfoWindow(void) } sSaveInfoWindowId = AddWindow(&saveInfoWindow); - NewMenuHelpers_DrawStdWindowFrame(sSaveInfoWindowId, FALSE); + DrawStdWindowFrame(sSaveInfoWindowId, FALSE); gender = gSaveBlock2Ptr->playerGender; color = TEXT_COLOR_RED; // Red when female, blue when male. @@ -1364,7 +1356,7 @@ static void ShowSaveInfoWindow(void) static void RemoveSaveInfoWindow(void) { - sub_819746C(sSaveInfoWindowId, FALSE); + ClearStdWindowAndFrame(sSaveInfoWindowId, FALSE); RemoveWindow(sSaveInfoWindowId); } @@ -1386,7 +1378,7 @@ void sub_80A08CC(void) // Referenced in data/specials.inc and data/scripts/maps/ static void HideStartMenuWindow(void) { - sub_819746C(GetStartMenuWindowId(), TRUE); + ClearStdWindowAndFrame(GetStartMenuWindowId(), TRUE); RemoveStartMenuWindow(); ScriptUnfreezeEventObjects(); ScriptContext2_Disable(); diff --git a/src/starter_choose.c b/src/starter_choose.c index 5a8de3b4a..4ed53539f 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -469,7 +469,7 @@ static void MainCallback2_StarterChoose(void) static void Task_StarterChoose1(u8 taskId) { CreateStarterPokemonLabel(gTasks[taskId].tStarterSelection); - SetWindowBorderStyle(0, FALSE, 0x2A8, 0xD); + DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x2A8, 0xD); AddTextPrinterParameterized(0, 1, gText_BirchInTrouble, 0, 1, 0, NULL); PutWindowTilemap(0); schedule_bg_copy_tilemap_to_vram(0); @@ -523,7 +523,7 @@ static void Task_StarterChoose3(u8 taskId) static void Task_StarterChoose4(u8 taskId) { PlayCry1(GetStarterPokemon(gTasks[taskId].tStarterSelection), 0); - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized(0, 1, gText_ConfirmStarterChoice, 0, 1, 0, NULL); schedule_bg_copy_tilemap_to_vram(0); CreateYesNoMenu(&gUnknown_085B1DDC, 0x2A8, 0xD, 0); @@ -579,7 +579,7 @@ static void CreateStarterPokemonLabel(u8 selection) winTemplate.tilemapTop = gStarterChoose_LabelCoords[selection][1]; sStarterChooseWindowId = AddWindow(&winTemplate); - FillWindowPixelBuffer(sStarterChooseWindowId, 0); + FillWindowPixelBuffer(sStarterChooseWindowId, PIXEL_FILL(0)); width = GetStringCenterAlignXOffset(7, text, 0x68); AddTextPrinterParameterized3(sStarterChooseWindowId, 7, width, 1, gUnknown_085B1E0C, 0, text); @@ -600,7 +600,7 @@ static void CreateStarterPokemonLabel(u8 selection) static void sub_8134604(void) { - FillWindowPixelBuffer(sStarterChooseWindowId, 0); + FillWindowPixelBuffer(sStarterChooseWindowId, PIXEL_FILL(0)); ClearWindowTilemap(sStarterChooseWindowId); RemoveWindow(sStarterChooseWindowId); sStarterChooseWindowId = 0xFF; diff --git a/src/text.c b/src/text.c index a439d3ced..be4bf2697 100644 --- a/src/text.c +++ b/src/text.c @@ -12,10 +12,6 @@ #include "menu.h" #include "dynamic_placeholder_text_util.h" -extern u8 GetKeypadIconWidth(u8 keypadIconId); -extern u16 Font6Func(struct TextPrinter *textPrinter); -extern u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese); - EWRAM_DATA struct TextPrinter gTempTextPrinter = {0}; EWRAM_DATA struct TextPrinter gTextPrinters[NUM_TEXT_PRINTERS] = {0}; @@ -1581,7 +1577,7 @@ u16 RenderText(struct TextPrinter *textPrinter) textPrinter->printerTemplate.currentChar++; return 2; case 15: - FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, textPrinter->printerTemplate.bgColor | textPrinter->printerTemplate.bgColor << 4); + FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x; textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y; return 2; @@ -1702,7 +1698,7 @@ u16 RenderText(struct TextPrinter *textPrinter) case 2: if (TextPrinterWaitWithDownArrow(textPrinter)) { - FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, (textPrinter->printerTemplate.bgColor << 4) | textPrinter->printerTemplate.bgColor); + FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x; textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y; textPrinter->state = 0; @@ -1724,12 +1720,12 @@ u16 RenderText(struct TextPrinter *textPrinter) int speed = gWindowVerticalScrollSpeeds[scrollSpeed]; if (textPrinter->scrollDistance < speed) { - ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor); + ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->scrollDistance = 0; } else { - ScrollWindow(textPrinter->printerTemplate.windowId, 0, speed, textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor); + ScrollWindow(textPrinter->printerTemplate.windowId, 0, speed, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->scrollDistance -= speed; } CopyWindowToVram(textPrinter->printerTemplate.windowId, 2); diff --git a/src/time_events.c b/src/time_events.c index 9702d321f..bd51f0c2d 100644 --- a/src/time_events.c +++ b/src/time_events.c @@ -81,7 +81,7 @@ void UpdateShoalTideFlag(void) 1, // 23 }; - if (is_map_type_1_2_3_5_or_6(GetLastUsedWarpMapType())) + if (IsMapTypeOutdoors(GetLastUsedWarpMapType())) { RtcCalcLocalTime(); if (tide[gLocalTime.hours]) diff --git a/src/trade.c b/src/trade.c index 6dfb6e2c4..9a9828f34 100644 --- a/src/trade.c +++ b/src/trade.c @@ -1418,7 +1418,7 @@ static void sub_80772A4(void) for (i = 0; i < 18; i++) { ClearWindowTilemap(i); - FillWindowPixelBuffer(i, 0); + FillWindowPixelBuffer(i, PIXEL_FILL(0)); } FillBgTilemapBufferRect(0, 0, 0, 0, 30, 20, 15); @@ -1507,13 +1507,13 @@ static void sub_80773D0(void) } break; case 3: - if (GetLinkPlayerCount_2() >= sub_800AA48()) + if (GetLinkPlayerCount_2() >= GetSavedPlayerCount()) { if (IsLinkMaster()) { if (++gUnknown_0203229C->unk_A8 > 30) { - sub_800A620(); + CheckShouldAdvanceLinkState(); gMain.state++; } } @@ -2461,7 +2461,7 @@ static void sub_8078DBC(void) if (gUnknown_0203229C->tradeMenuCursorPosition < 6) { sub_8098858(1, 1, 14); - FillWindowPixelBuffer(1, 0x11); + FillWindowPixelBuffer(1, PIXEL_FILL(1)); PrintMenuTable(1, 2, gUnknown_0832DEAC); InitMenuInUpperLeftCornerPlaySoundWhenAPressed(1, 2, 0); PutWindowTilemap(1); @@ -2724,7 +2724,7 @@ static void sub_8079408(void) for (i = 0; i < 4; i++) { - FillWindowPixelBuffer(i + 14, 0); + FillWindowPixelBuffer(i + 14, PIXEL_FILL(0)); rbox_fill_rectangle(i + 14); } @@ -2762,7 +2762,7 @@ static void sub_80794CC(void) Free(gUnknown_0203229C); FreeAllWindowBuffers(); sub_800E084(); - SetMainCallback2(c2_8056854); + SetMainCallback2(CB2_ReturnToFieldFromMultiplayer); } } else @@ -2772,7 +2772,7 @@ static void sub_80794CC(void) Free(gUnknown_02032184); Free(gUnknown_0203229C); FreeAllWindowBuffers(); - SetMainCallback2(c2_8056854); + SetMainCallback2(CB2_ReturnToFieldFromMultiplayer); } } } @@ -3256,7 +3256,7 @@ static void sub_807A0C4(void) static void sub_807A19C(u8 a0) { - FillWindowPixelBuffer(0, 0x11); + FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized(0, 1, gUnknown_0832DEBC[a0], 0, 1, TEXT_SPEED_FF, NULL); sub_8098858(0, 20, 12); PutWindowTilemap(0); @@ -4099,11 +4099,11 @@ void sub_807AE50(void) case 3: if (IsLinkMaster()) { - if (GetLinkPlayerCount_2() >= sub_800AA48()) + if (GetLinkPlayerCount_2() >= GetSavedPlayerCount()) { if (++gUnknown_020322A0->timer > 30) { - sub_800A620(); + CheckShouldAdvanceLinkState(); gMain.state++; } } @@ -4185,7 +4185,7 @@ void sub_807B140(void) void sub_807B154(void) { - FillWindowPixelBuffer(0, 0xFF); + FillWindowPixelBuffer(0, PIXEL_FILL(15)); PutWindowTilemap(0); CopyWindowToVram(0, 3); } @@ -4263,7 +4263,7 @@ static void sub_807B270(void) break; case 8: sub_807ACFC(1, 1); - FillWindowPixelBuffer(0, 0xFF); + FillWindowPixelBuffer(0, PIXEL_FILL(15)); PutWindowTilemap(0); CopyWindowToVram(0, 3); gMain.state++; @@ -4654,7 +4654,7 @@ static bool8 sub_807BBEC(void) if (!gPaletteFade.active) { sub_807B62C(4); - FillWindowPixelBuffer(0, 0xFF); + FillWindowPixelBuffer(0, PIXEL_FILL(15)); CopyWindowToVram(0, 3); gUnknown_020322A0->state++; } @@ -5146,7 +5146,7 @@ static bool8 sub_807CFC8(void) if (!gPaletteFade.active) { sub_807B62C(4); - FillWindowPixelBuffer(0, 0xFF); + FillWindowPixelBuffer(0, PIXEL_FILL(15)); CopyWindowToVram(0, 3); gUnknown_020322A0->state++; } @@ -6085,7 +6085,7 @@ void sub_807F19C(void) void sub_807F1A8(u8 windowId, const u8 *str, u8 speed) { - FillWindowPixelBuffer(windowId, 0xFF); + FillWindowPixelBuffer(windowId, PIXEL_FILL(15)); gUnknown_020322A0->unk_F6[0] = 15; gUnknown_020322A0->unk_F6[1] = 1; gUnknown_020322A0->unk_F6[2] = 6; diff --git a/src/trader.c b/src/trader.c index b5c159fb9..97bc4626f 100644 --- a/src/trader.c +++ b/src/trader.c @@ -73,7 +73,7 @@ void CreateAvailableDecorationsMenu(u8 taskId) } windowTemplate.width = convert_pixel_width_to_tile_width(windowWidth); data[3] = AddWindow(&windowTemplate); - SetWindowBorderStyle(data[3], FALSE, 0x214, 14); + DrawStdFrameWithCustomTileAndPalette(data[3], FALSE, 0x214, 14); for (i = 0; i < 4; i++) { if (trader->decorIds[i] > NUM_DECORATIONS) @@ -98,7 +98,7 @@ void sub_8133BE4(u8 taskId, u8 decorationId) gSpecialVar_0x8004 = decorationId; } - sub_8198070(data[3], FALSE); + ClearStdWindowAndFrameToTransparent(data[3], FALSE); ClearWindowTilemap(data[3]); RemoveWindow(data[3]); schedule_bg_copy_tilemap_to_vram(0); diff --git a/src/trainer_card.c b/src/trainer_card.c index 4019ef0bd..01839d598 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -21,6 +21,7 @@ #include "gpu_regs.h" #include "international_string_util.h" #include "pokedex.h" +#include "pokemon_icon.h" #include "graphics.h" #include "pokemon_icon.h" #include "trainer_pokemon_sprites.h" @@ -89,9 +90,6 @@ struct TrainerCardData u8 language; }; -//external functions -extern u8 sub_80D30A0(u16); - // EWRAM EWRAM_DATA struct TrainerCard gTrainerCards[4] = {0}; EWRAM_DATA static struct TrainerCardData *sData = NULL; @@ -350,7 +348,7 @@ static void sub_80C2760(u8 taskId) case 0: if (!IsDma3ManagerBusyWithBgCopy()) { - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); sData->var_0++; } break; @@ -363,7 +361,7 @@ static void sub_80C2760(u8 taskId) sData->var_0++; break; case 3: - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); sub_80C4FF0(); sub_80C438C(2); sData->var_0++; @@ -469,7 +467,7 @@ static void sub_80C2760(u8 taskId) break; case 15: sub_800AC34(); - NewMenuHelpers_DrawDialogueFrame(0, 1); + DrawDialogueFrame(0, 1); AddTextPrinterParameterized(0, 1, gText_WaitingTrainerFinishReading, 0, 1, 255, 0); CopyWindowToVram(0, 3); sData->var_0 = 16; @@ -1103,7 +1101,7 @@ static void PrintTimeOnCard(void) r10 = width + 30; r7 -= r10; - FillWindowPixelRect(1, 0, r7, r4, r10, 15); + FillWindowPixelRect(1, PIXEL_FILL(0), r7, r4, r10, 15); ConvertIntToDecimalStringN(gStringVar4, hours, 1, 3); AddTextPrinterParameterized3(1, 1, r7, r4, gUnknown_0856FB0C, TEXT_SPEED_FF, gStringVar4); r7 += 18; @@ -1536,7 +1534,7 @@ static void sub_80C48C8(void) } } -u8 sub_80C4904(u8 cardId) +u8 GetTrainerCardStars(u8 cardId) { struct TrainerCard* trainerCards = gTrainerCards; return trainerCards[cardId].stars; @@ -1634,7 +1632,7 @@ static bool8 sub_80C4B08(struct Task* task) switch (sData->var_4) { case 0: - FillWindowPixelBuffer(1, 0); + FillWindowPixelBuffer(1, PIXEL_FILL(0)); FillBgTilemapBufferRect_Palette0(3, 0, 0, 0, 0x20, 0x20); break; case 1: @@ -1659,7 +1657,7 @@ static bool8 sub_80C4B08(struct Task* task) if (!sData->var_8) sub_80C474C(); else - FillWindowPixelBuffer(2, 0); + FillWindowPixelBuffer(2, PIXEL_FILL(0)); break; case 4: if (sData->var_8) diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 42b196abd..43b29e26e 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -30,6 +30,7 @@ #include "constants/species.h" #include "constants/trainers.h" #include "constants/easy_chat.h" +#include "constants/trainer_hill.h" extern bool32 sub_81D3B34(void); @@ -92,16 +93,16 @@ struct TrHillStruct2 // EWRAM static EWRAM_DATA struct TrHillStruct2 *sHillData = NULL; static EWRAM_DATA struct TrHillRoomTrainers *sRoomTrainers = NULL; -EWRAM_DATA u32 *gUnknown_0203CF5C = NULL; +EWRAM_DATA u32 *gTrainerHillVBlankCounter = NULL; // This file's functions. -static void sub_81D581C(void); +static void TrainerHillStartChallenge(void); static void sub_81D58D8(void); static void sub_81D5924(void); static void sub_81D59D0(void); -static void sub_81D5A70(void); -static void sub_81D5AB4(void); -static void sub_81D5AD0(void); +static void TrainerHillResumeTimer(void); +static void TrainerHillSetPlayerLost(void); +static void TrainerHillGetChallengeStatus(void); static void sub_81D5B2C(void); static void sub_81D5BBC(void); static void sub_81D5C00(void); @@ -112,7 +113,7 @@ static void sub_81D64DC(void); static void sub_81D64FC(void); static void sub_81D6518(void); static void sub_81D6568(void); -static void sub_81D65A0(void); +static void TrainerHillSetTag(void); static void SetUpDataStruct(void); static void FreeDataStruct(void); static void nullsub_2(void); @@ -263,13 +264,13 @@ static const u8 *const sFloorStrings[] = static void (* const sHillFunctions[])(void) = { - sub_81D581C, + TrainerHillStartChallenge, sub_81D58D8, sub_81D5924, sub_81D59D0, - sub_81D5A70, - sub_81D5AB4, - sub_81D5AD0, + TrainerHillResumeTimer, + TrainerHillSetPlayerLost, + TrainerHillGetChallengeStatus, sub_81D5B2C, sub_81D5BBC, sub_81D5C00, @@ -280,7 +281,7 @@ static void (* const sHillFunctions[])(void) = sub_81D64FC, sub_81D6518, sub_81D6568, - sub_81D65A0, + TrainerHillSetTag, }; static const u8 *const sTagMatchStrings[] = @@ -318,7 +319,7 @@ void ResetTrainerHillResults(void) gSaveBlock2Ptr->frontier.field_EF9_1 = 0; gSaveBlock2Ptr->frontier.field_EF9_0 = 0; - gSaveBlock1Ptr->trainerHill.field_3D68 = 0; + gSaveBlock1Ptr->trainerHill.bestTime = 0; for (i = 0; i < 4; i++) SetTimerValue(&gSaveBlock1Ptr->trainerHillTimes[i], HILL_MAX_TIME); } @@ -371,7 +372,7 @@ void InitTrainerHillBattleStruct(void) } sRoomTrainers->facilityClass[i] = sHillData->tag.floors[sHillData->floorId].trainers[i].facilityClass; } - sub_80008DC(&gSaveBlock1Ptr->trainerHill.field_3D64); + SetTrainerHillVBlankCounter(&gSaveBlock1Ptr->trainerHill.timer); FreeDataStruct(); } @@ -425,7 +426,7 @@ void CopyTrainerHillTrainerText(u8 which, u16 trainerId) FreeDataStruct(); } -static void sub_81D581C(void) +static void TrainerHillStartChallenge(void) { nullsub_2(); if (!sub_81D3B34()) @@ -434,11 +435,11 @@ static void sub_81D581C(void) gSaveBlock1Ptr->trainerHill.field_3D6E_0f = 0; gSaveBlock1Ptr->trainerHill.field_3D6C = 0; - sub_80008DC(&gSaveBlock1Ptr->trainerHill.field_3D64); - gSaveBlock1Ptr->trainerHill.field_3D64 = 0; + SetTrainerHillVBlankCounter(&gSaveBlock1Ptr->trainerHill.timer); + gSaveBlock1Ptr->trainerHill.timer = 0; gSaveBlock1Ptr->trainerHill.field_3D6E_0c = 0; gSaveBlock1Ptr->trainerHill.field_3D6E_0b = 0; - gSaveBlock1Ptr->trainerHill.field_3D6E_0e = 0; + gSaveBlock1Ptr->trainerHill.maybeECardScanDuringChallenge = 0; gSaveBlock2Ptr->frontier.field_EE0 = 0; gBattleOutcome = 0; gSaveBlock1Ptr->trainerHill.field_3D6E_0a = 0; @@ -446,7 +447,7 @@ static void sub_81D581C(void) static void sub_81D58D8(void) { - sub_80008E8(); + ClearTrainerHillVBlankCounter(); gSpecialVar_Result = 0; if (gSaveBlock1Ptr->trainerHill.field_3D6E_0c) gSpecialVar_Result++; @@ -483,10 +484,10 @@ static void sub_81D59D0(void) { gSpecialVar_Result = 2; } - else if (GetTimerValue(&gSaveBlock1Ptr->trainerHill.field_3D68) > gSaveBlock1Ptr->trainerHill.field_3D64) + else if (GetTimerValue(&gSaveBlock1Ptr->trainerHill.bestTime) > gSaveBlock1Ptr->trainerHill.timer) { - SetTimerValue(&gSaveBlock1Ptr->trainerHill.field_3D68, gSaveBlock1Ptr->trainerHill.field_3D64); - gSaveBlock1Ptr->trainerHillTimes[gSaveBlock1Ptr->trainerHill.tag] = gSaveBlock1Ptr->trainerHill.field_3D68; + SetTimerValue(&gSaveBlock1Ptr->trainerHill.bestTime, gSaveBlock1Ptr->trainerHill.timer); + gSaveBlock1Ptr->trainerHillTimes[gSaveBlock1Ptr->trainerHill.tag] = gSaveBlock1Ptr->trainerHill.bestTime; gSpecialVar_Result = 0; } else @@ -497,37 +498,40 @@ static void sub_81D59D0(void) gSaveBlock1Ptr->trainerHill.field_3D6E_0b = 1; } -static void sub_81D5A70(void) +static void TrainerHillResumeTimer(void) { if (!gSaveBlock1Ptr->trainerHill.field_3D6E_0c) { - if (gSaveBlock1Ptr->trainerHill.field_3D64 >= HILL_MAX_TIME) - gSaveBlock1Ptr->trainerHill.field_3D64 = HILL_MAX_TIME; + if (gSaveBlock1Ptr->trainerHill.timer >= HILL_MAX_TIME) + gSaveBlock1Ptr->trainerHill.timer = HILL_MAX_TIME; else - sub_80008DC(&gSaveBlock1Ptr->trainerHill.field_3D64); + SetTrainerHillVBlankCounter(&gSaveBlock1Ptr->trainerHill.timer); } } -static void sub_81D5AB4(void) +static void TrainerHillSetPlayerLost(void) { - gSaveBlock1Ptr->trainerHill.field_3D6E_0d = 1; + gSaveBlock1Ptr->trainerHill.hasLost = 1; } -static void sub_81D5AD0(void) +static void TrainerHillGetChallengeStatus(void) { - if (gSaveBlock1Ptr->trainerHill.field_3D6E_0d) + if (gSaveBlock1Ptr->trainerHill.hasLost) { - gSaveBlock1Ptr->trainerHill.field_3D6E_0d = 0; - gSpecialVar_Result = 0; + // The player lost their last match. + gSaveBlock1Ptr->trainerHill.hasLost = 0; + gSpecialVar_Result = TRAINER_HILL_PLAYER_STATUS_LOST; } - else if (gSaveBlock1Ptr->trainerHill.field_3D6E_0e) + else if (gSaveBlock1Ptr->trainerHill.maybeECardScanDuringChallenge) { - gSaveBlock1Ptr->trainerHill.field_3D6E_0e = 0; - gSpecialVar_Result = 1; + // Unreachable code. Something relating to eCards? + gSaveBlock1Ptr->trainerHill.maybeECardScanDuringChallenge = 0; + gSpecialVar_Result = TRAINER_HILL_PLAYER_STATUS_ECARD_SCANNED; } else { - gSpecialVar_Result = 2; + // Continue playing. + gSpecialVar_Result = TRAINER_HILL_PLAYER_STATUS_NORMAL; } } @@ -535,7 +539,7 @@ static void sub_81D5B2C(void) { s32 total, minutes, secondsWhole, secondsFraction; - total = gSaveBlock1Ptr->trainerHill.field_3D64; + total = gSaveBlock1Ptr->trainerHill.timer; if (total >= HILL_MAX_TIME) total = HILL_MAX_TIME; @@ -575,7 +579,7 @@ static void sub_81D5C00(void) bool8 sub_81D5C18(void) { - if (VarGet(VAR_0x40D6) == 0) + if (VarGet(VAR_TRAINER_HILL_IS_ACTIVE) == 0) return FALSE; else if (gSaveBlock1Ptr->trainerHill.field_3D6E_0c) return FALSE; @@ -609,7 +613,7 @@ void PrintOnTrainerHillRecordsWindow(void) u32 total, minutes, secondsWhole, secondsFraction; SetUpDataStruct(); - FillWindowPixelBuffer(0, 0); + FillWindowPixelBuffer(0, PIXEL_FILL(0)); x = GetStringCenterAlignXOffset(1, gText_TimeBoard, 0xD0); AddTextPrinterParameterized3(0, 1, x, 2, sRecordWinColors, TEXT_SPEED_FF, gText_TimeBoard); @@ -1048,16 +1052,16 @@ bool32 sub_81D6534(void) static void sub_81D6568(void) { - if (gSaveBlock1Ptr->trainerHill.field_3D6E_0d) + if (gSaveBlock1Ptr->trainerHill.hasLost) gSpecialVar_Result = 0; else gSpecialVar_Result = 1; } -static void sub_81D65A0(void) +static void TrainerHillSetTag(void) { gSaveBlock1Ptr->trainerHill.tag = gSpecialVar_0x8005; - gSaveBlock1Ptr->trainerHill.field_3D68 = gSaveBlock1Ptr->trainerHillTimes[gSpecialVar_0x8005]; + gSaveBlock1Ptr->trainerHill.bestTime = gSaveBlock1Ptr->trainerHillTimes[gSpecialVar_0x8005]; } static u8 sub_81D65E8(u8 arg0) @@ -1103,7 +1107,7 @@ static u16 sub_81D6640(void) i = (i + 1) % 10; ptr = gUnknown_0862A5CC[var2][i]; - minutes = (signed)(gSaveBlock1Ptr->trainerHill.field_3D64) / (60 * 60); + minutes = (signed)(gSaveBlock1Ptr->trainerHill.timer) / (60 * 60); if (minutes < 12) id = 0; else if (minutes < 13) diff --git a/src/trainer_see.c b/src/trainer_see.c index bc5d9cbc3..16ea88a45 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -17,8 +17,6 @@ #include "constants/event_object_movement_constants.h" #include "constants/field_effects.h" -extern void sub_809BE48(u16 npcId); - // this file's functions static u8 CheckTrainer(u8 eventObjectId); static u8 GetTrainerApproachDistance(struct EventObject *trainerObj); @@ -39,6 +39,7 @@ #include "tv.h" #include "data2.h" #include "constants/layouts.h" +#include "constants/metatile_behaviors.h" // Static type declarations @@ -853,9 +854,9 @@ void SetTVMetatilesOnMap(int width, int height, u16 tileId) { for (x = 0; x < width; x ++) { - if (MapGridGetMetatileBehaviorAt(x, y) == 0x86) // is this tile a TV? + if (MapGridGetMetatileBehaviorAt(x, y) == MB_TELEVISION) { - MapGridSetMetatileIdAt(x, y, tileId | 0xc00); + MapGridSetMetatileIdAt(x, y, tileId | METATILE_COLLISION_MASK); } } } @@ -2565,13 +2566,13 @@ void sub_80EEA70(void) show->secretBaseSecrets.kind = TVSHOW_SECRET_BASE_SECRETS; show->secretBaseSecrets.active = FALSE; StringCopy(show->secretBaseSecrets.playerName, gSaveBlock2Ptr->playerName); - show->secretBaseSecrets.stepsInBase = VarGet(VAR_0x40EC); + show->secretBaseSecrets.stepsInBase = VarGet(VAR_SECRET_BASE_STEP_COUNTER); sub_80E980C(); StringCopy(strbuf, gStringVar1); StripExtCtrlCodes(strbuf); StringCopy(show->secretBaseSecrets.baseOwnersName, strbuf); - show->secretBaseSecrets.item = VarGet(VAR_0x40ED); - show->secretBaseSecrets.flags = VarGet(VAR_0x40EE) + (VarGet(VAR_0x40EF) << 16); + show->secretBaseSecrets.item = VarGet(VAR_SECRET_BASE_LAST_ITEM_USED); + show->secretBaseSecrets.flags = VarGet(VAR_SECRET_BASE_LOW_TV_FLAGS) + (VarGet(VAR_SECRET_BASE_HIGH_TV_FLAGS) << 16); tv_store_id_3x(show); show->secretBaseSecrets.language = gGameLanguage; if (show->secretBaseSecrets.language == LANGUAGE_JAPANESE || gSaveBlock1Ptr->secretBases[VarGet(VAR_CURRENT_SECRET_BASE)].language == LANGUAGE_JAPANESE) @@ -7350,7 +7351,7 @@ static void DoTVShowWhatsNo1InHoennToday(void) ShowFieldMessage(sTVWhatsNo1InHoennTodayTextGroup[state]); } -u8 sub_80F5180(TVShow *show) +u8 TVShowGetFlagCount(TVShow *show) { u8 i; u8 tot; @@ -7365,7 +7366,7 @@ u8 sub_80F5180(TVShow *show) return tot; } -u8 sub_80F51AC(TVShow *show, u8 a1) +u8 TVShowGetStateForFlagNumber(TVShow *show, u8 a1) { u8 i; u8 tot; @@ -7399,7 +7400,7 @@ static void DoTVShowSecretBaseSecrets(void) case 0: TVShowConvertInternationalString(gStringVar1, show->secretBaseSecrets.baseOwnersName, show->secretBaseSecrets.baseOwnersNameLanguage); TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - bitCount = sub_80F5180(show); + bitCount = TVShowGetFlagCount(show); if (bitCount == 0) { sTVShowState = 8; @@ -7408,12 +7409,12 @@ static void DoTVShowSecretBaseSecrets(void) { show->secretBaseSecrets.savedState = 1; sTVSecretBaseSecretsRandomValues[0] = Random() % bitCount; - sTVShowState = sub_80F51AC(show, sTVSecretBaseSecretsRandomValues[0]); + sTVShowState = TVShowGetStateForFlagNumber(show, sTVSecretBaseSecretsRandomValues[0]); } break; case 1: TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - bitCount = sub_80F5180(show); + bitCount = TVShowGetFlagCount(show); switch (bitCount) { case 1: @@ -7423,11 +7424,11 @@ static void DoTVShowSecretBaseSecrets(void) show->secretBaseSecrets.savedState = 2; if (sTVSecretBaseSecretsRandomValues[0] == 0) { - sTVShowState = sub_80F51AC(show, 1); + sTVShowState = TVShowGetStateForFlagNumber(show, 1); } else { - sTVShowState = sub_80F51AC(show, 0); + sTVShowState = TVShowGetStateForFlagNumber(show, 0); } break; default: @@ -7440,13 +7441,13 @@ static void DoTVShowSecretBaseSecrets(void) } } show->secretBaseSecrets.savedState = 2; - sTVShowState = sub_80F51AC(show, sTVSecretBaseSecretsRandomValues[1]); + sTVShowState = TVShowGetStateForFlagNumber(show, sTVSecretBaseSecretsRandomValues[1]); break; } break; case 2: TVShowConvertInternationalString(gStringVar2, show->secretBaseSecrets.playerName, show->secretBaseSecrets.language); - bitCount = sub_80F5180(show); + bitCount = TVShowGetFlagCount(show); if (bitCount == 2) { sTVShowState = 9; @@ -7462,7 +7463,7 @@ static void DoTVShowSecretBaseSecrets(void) } } show->secretBaseSecrets.savedState = 3; - sTVShowState = sub_80F51AC(show, sTVSecretBaseSecretsRandomValues[2]); + sTVShowState = TVShowGetStateForFlagNumber(show, sTVSecretBaseSecretsRandomValues[2]); } break; case 3: diff --git a/src/unk_text_util_2.c b/src/unk_text_util_2.c index bbc256915..02648bf93 100644 --- a/src/unk_text_util_2.c +++ b/src/unk_text_util_2.c @@ -114,7 +114,7 @@ u16 Font6Func(struct TextPrinter *textPrinter) textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y + *textPrinter->printerTemplate.currentChar++; return 2; case 15: - FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, textPrinter->printerTemplate.bgColor | (textPrinter->printerTemplate.bgColor << 4)); + FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); return 2; } break; @@ -146,7 +146,7 @@ u16 Font6Func(struct TextPrinter *textPrinter) case 2: if (TextPrinterWaitWithDownArrow(textPrinter)) { - FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, textPrinter->printerTemplate.bgColor | (textPrinter->printerTemplate.bgColor << 4)); + FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x; textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y; textPrinter->state = 0; @@ -166,12 +166,12 @@ u16 Font6Func(struct TextPrinter *textPrinter) { if (textPrinter->scrollDistance < sUnknown_08616124[gSaveBlock2Ptr->optionsTextSpeed]) { - ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, textPrinter->printerTemplate.bgColor | (textPrinter->printerTemplate.bgColor << 4)); + ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->scrollDistance = 0; } else { - ScrollWindow(textPrinter->printerTemplate.windowId, 0, sUnknown_08616124[gSaveBlock2Ptr->optionsTextSpeed], textPrinter->printerTemplate.bgColor | (textPrinter->printerTemplate.bgColor << 4)); + ScrollWindow(textPrinter->printerTemplate.windowId, 0, sUnknown_08616124[gSaveBlock2Ptr->optionsTextSpeed], PIXEL_FILL(textPrinter->printerTemplate.bgColor)); textPrinter->scrollDistance -= sUnknown_08616124[gSaveBlock2Ptr->optionsTextSpeed]; } CopyWindowToVram(textPrinter->printerTemplate.windowId, 2); @@ -214,7 +214,7 @@ static void DecompressGlyphFont6(u16 glyph) gUnknown_03002F90.unk81 = 0x10; } -u8 GetGlyphWidthFont6(void) +u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese) { return 0x10; } diff --git a/src/wallclock.c b/src/wallclock.c index 546750ba6..d3bbcf7a2 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -793,7 +793,7 @@ static void Task_SetClock2(u8 taskId) static void Task_SetClock3(u8 taskId) { - SetWindowBorderStyle(0, FALSE, 0x250, 0x0d); + DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x250, 0x0d); AddTextPrinterParameterized(0, 1, gText_IsThisTheCorrectTime, 0, 1, 0, NULL); PutWindowTilemap(0); schedule_bg_copy_tilemap_to_vram(0); @@ -812,7 +812,7 @@ static void Task_SetClock4(u8 taskId) case 1: //B button case -1: //NO PlaySE(SE_SELECT); - sub_8198070(0, FALSE); + ClearStdWindowAndFrameToTransparent(0, FALSE); ClearWindowTilemap(0); gTasks[taskId].func = Task_SetClock2; break; diff --git a/src/water.c b/src/water.c index d13b1378e..20bf2542d 100644 --- a/src/water.c +++ b/src/water.c @@ -13,35 +13,33 @@ #include "constants/battle.h" #include "constants/rgb.h" -extern void sub_810721C(struct Sprite *); -extern void sub_8107228(struct Sprite *); -extern void sub_8107260(struct Sprite *); -extern void sub_8107380(struct Sprite *); -extern void sub_8107408(struct Sprite *); -extern void sub_8107430(struct Sprite *); -extern void sub_810744C(struct Sprite *); -extern void sub_81074E4(struct Sprite *); -extern void sub_81075EC(struct Sprite *); -extern void sub_8107674(struct Sprite *); -extern void sub_8107730(struct Sprite *); -extern void sub_81077A4(struct Sprite *); -extern void sub_81077C0(struct Sprite *); -extern void sub_80A78AC(struct Sprite *); -extern void sub_8107894(struct Sprite *); -extern void sub_81078D0(struct Sprite *); -extern void sub_810790C(struct Sprite *); -extern void sub_8108034(struct Sprite *); -extern void sub_8108098(struct Sprite *); -extern void sub_810851C(struct Sprite *); -extern void sub_81087C0(struct Sprite *); -extern void sub_810886C(struct Sprite *); -extern void sub_8108B2C(struct Sprite *); -extern void sub_8108B94(struct Sprite *); -extern void sub_8108BE0(struct Sprite *); -extern void sub_8108C08(struct Sprite *); -extern void sub_8108C54(struct Sprite *); -extern void sub_8108CDC(struct Sprite *); -extern void sub_80A8EE4(struct Sprite *); +void sub_810721C(struct Sprite *); +void sub_8107228(struct Sprite *); +void sub_8107260(struct Sprite *); +void sub_8107380(struct Sprite *); +void sub_8107408(struct Sprite *); +void sub_8107430(struct Sprite *); +void sub_810744C(struct Sprite *); +void sub_81074E4(struct Sprite *); +void sub_81075EC(struct Sprite *); +void sub_8107674(struct Sprite *); +void sub_8107730(struct Sprite *); +void sub_81077A4(struct Sprite *); +void sub_81077C0(struct Sprite *); +void sub_8107894(struct Sprite *); +void sub_81078D0(struct Sprite *); +void sub_810790C(struct Sprite *); +void sub_8108034(struct Sprite *); +void sub_8108098(struct Sprite *); +void sub_810851C(struct Sprite *); +void sub_81087C0(struct Sprite *); +void sub_810886C(struct Sprite *); +void sub_8108B2C(struct Sprite *); +void sub_8108B94(struct Sprite *); +void sub_8108BE0(struct Sprite *); +void sub_8108C08(struct Sprite *); +void sub_8108C54(struct Sprite *); +void sub_8108CDC(struct Sprite *); void sub_810756C(u8); void sub_81076F4(u8); void sub_8107B84(u8); diff --git a/src/window.c b/src/window.c index 3da529178..fbce57743 100644 --- a/src/window.c +++ b/src/window.c @@ -6,7 +6,8 @@ u32 filler_03002F58; u32 filler_03002F5C; -u8 gUnknown_03002F60; +// This global is set to 0 and never changed. +u8 gTransparentTileNumber; u32 filler_03002F64; void *gUnknown_03002F70[4]; extern u32 gUnneededFireRedVariable; @@ -106,7 +107,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) } } - gUnknown_03002F60 = 0; + gTransparentTileNumber = 0; return TRUE; } @@ -359,13 +360,14 @@ void PutWindowRectTilemapOverridePalette(u8 windowId, u8 x, u8 y, u8 width, u8 h } } +// Fills a window with transparent tiles. void ClearWindowTilemap(u8 windowId) { struct Window windowLocal = gWindows[windowId]; FillBgTilemapBufferRect( windowLocal.window.bg, - gUnknown_03002F60, + gTransparentTileNumber, windowLocal.window.tilemapLeft, windowLocal.window.tilemapTop, windowLocal.window.width, @@ -451,6 +453,7 @@ void CopyToWindowPixelBuffer(u8 windowId, const void *src, u16 size, u16 tileOff LZ77UnCompWram(src, gWindows[windowId].tileData + (0x20 * tileOffset)); } +// Sets all pixels within the window to the fillValue color. void FillWindowPixelBuffer(u8 windowId, u8 fillValue) { int fillSize = gWindows[windowId].window.width * gWindows[windowId].window.height; |