diff options
author | Cameron Hall <cameronghall@cox.net> | 2018-01-21 13:53:32 -0600 |
---|---|---|
committer | Cameron Hall <cameronghall@cox.net> | 2018-01-21 13:53:32 -0600 |
commit | 11a9371349e1743a18dce28cc60b69dd6a29b665 (patch) | |
tree | e696d1fda7556af8b5234eae833ea2fd146fc75d /src | |
parent | 7383117626ebb2b3d993e5ad8855da5752c9cce8 (diff) | |
parent | 68a402883f780a61f54c2f0c8740429d0b2b3a81 (diff) |
resolve merge conflicts and make it compile
Diffstat (limited to 'src')
83 files changed, 1629 insertions, 2054 deletions
diff --git a/src/battle/anim/love_bg.c b/src/battle/anim/love_bg.c index bd3d22ca6..c3828c681 100644 --- a/src/battle/anim/love_bg.c +++ b/src/battle/anim/love_bg.c @@ -25,7 +25,7 @@ static void sub_80D21F0(u8 taskId); void sub_80D2100(u8 taskId) { struct Struct_sub_8078914 subStruct; - u8* tempvar; + REG_BLDCNT = 0x3F42; REG_BLDALPHA = 0x1000; REG_BG1CNT_BITFIELD.priority = 3; @@ -38,9 +38,8 @@ void sub_80D2100(u8 taskId) REG_BG1HOFS = 0; REG_BG1VOFS = 0; sub_8078914(&subStruct); - tempvar = subStruct.field_4; - DmaFill32(3, 0x0, tempvar, 0x1000); - LZDecompressVram(&gAttractTilemap, tempvar); + DmaFill32Defvars(3, 0, subStruct.field_4, 0x1000); + LZDecompressVram(&gAttractTilemap, subStruct.field_4); LZDecompressVram(&gAttractGfx, subStruct.field_0); LoadCompressedPalette(&gAttractPal, subStruct.field_8 << 4, 32); if (IsContest()) @@ -90,21 +89,7 @@ void sub_80D21F0(u8 taskId) break; case 3: sub_8078914(&subStruct); - { - u8 *addr = subStruct.field_0; - u32 size = 0x2000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - } + DmaFill32Large(3, 0, subStruct.field_0, 0x2000, 0x1000); DmaClear32(3, subStruct.field_4, 0x800); if (!IsContest()) REG_BG1CNT_BITFIELD.charBaseBlock = 0; diff --git a/src/battle/anim/scary_face.c b/src/battle/anim/scary_face.c index 47776a3cb..8d51521ee 100644 --- a/src/battle/anim/scary_face.c +++ b/src/battle/anim/scary_face.c @@ -27,7 +27,7 @@ static void sub_80D24E0(u8 taskId); void sub_80D23B4(u8 taskId) { struct Struct_sub_8078914 subStruct; - u8* tempvar; + REG_BLDCNT = 0x3F42; REG_BLDALPHA = 0x1000; REG_BG1CNT_BITFIELD.priority = 1; @@ -40,8 +40,7 @@ void sub_80D23B4(u8 taskId) REG_BG1HOFS = 0; REG_BG1VOFS = 0; sub_8078914(&subStruct); - tempvar = subStruct.field_4; - DmaFill32(3, 0x0, tempvar, 0x1000); + DmaFill32Defvars(3, 0, subStruct.field_4, 0x1000); if (IsContest()) LZDecompressVram(&gBattleAnimBackgroundTilemap_ScaryFaceContest, subStruct.field_4); else if (GetBankSide(gAnimBankTarget) == 1) @@ -98,21 +97,7 @@ void sub_80D24E0(u8 taskId) break; case 3: sub_8078914(&subStruct); - { - u8 *addr = subStruct.field_0; - u32 size = 0x2000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - } + DmaFill32Large(3, 0, subStruct.field_0, 0x2000, 0x1000); DmaClear32(3, subStruct.field_4, 0x800); if (!IsContest()) REG_BG1CNT_BITFIELD.charBaseBlock = 0; diff --git a/src/battle/battle_7.c b/src/battle/battle_7.c index 00216ce05..b4c71b9c2 100644 --- a/src/battle/battle_7.c +++ b/src/battle/battle_7.c @@ -624,9 +624,6 @@ void sub_8031FC4(u8 a, u8 b, bool8 c) } else { - const void *src; - void *dst; - if (IsContest()) { r10 = 0; @@ -676,9 +673,7 @@ void sub_8031FC4(u8 a, u8 b, bool8 c) gTransformedPersonalities[a]); } } - src = gUnknown_081FAF4C[r10]; - dst = (void *)(VRAM + 0x10000 + gSprites[gObjectBankIDs[a]].oam.tileNum * 32); - DmaCopy32(3, src, dst, 0x800); + DmaCopy32Defvars(3, gUnknown_081FAF4C[r10], (void *)(VRAM + 0x10000 + gSprites[gObjectBankIDs[a]].oam.tileNum * 32), 0x800); paletteOffset = 0x100 + a * 16; lzPaletteData = GetMonSpritePalFromOtIdPersonality(species, otId, personalityValue); LZDecompressWram(lzPaletteData, gSharedMem); diff --git a/src/battle/battle_anim.c b/src/battle/battle_anim.c index 4549d1fcb..c71c12ce7 100644 --- a/src/battle/battle_anim.c +++ b/src/battle/battle_anim.c @@ -1910,36 +1910,19 @@ bool8 IsAnimBankSpriteVisible(u8 bank) void sub_8076034(u8 a, u8 b) { - volatile u8 pointlessZero; - u16 *addr2; u8 spriteId; if (b == 0) { + volatile u8 pointlessZero; struct UnknownStruct2 s; - u8 *addr; - u32 size; u8 r2; - u16 *addr3; sub_8078914(&s); - addr = s.unk0; - size = 0x2000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - pointlessZero = 0; - pointlessZero = 0; - addr2 = (void *)s.unk4; - DmaFill16(3, 0xFF, addr2, 0x1000); + DmaFill32Large(3, 0, s.unk0, 0x2000, 0x1000); + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + DmaFill16Defvars(3, 0xFF, (void *)s.unk4, 0x1000); REG_BG1CNT_BITFIELD.priority = 2; REG_BG1CNT_BITFIELD.screenSize = 1; @@ -1956,8 +1939,7 @@ void sub_8076034(u8 a, u8 b) REG_BG1VOFS = gBattle_BG1_Y; LoadPalette(gPlttBufferUnfaded + 0x100 + a * 16, s.unk8 * 16, 32); - addr3 = (u16 *)PLTT + s.unk8 * 16; - DmaCopy32(3, gPlttBufferUnfaded + 0x100 + a * 16, addr3, 32); + DmaCopy32Defvars(3, gPlttBufferUnfaded + 0x100 + a * 16, (u16 *)PLTT + s.unk8 * 16, 32); if (IsContest() != 0) r2 = 0; @@ -1969,27 +1951,12 @@ void sub_8076034(u8 a, u8 b) } else { - u8 *addr; - u32 size; - u16 *addr3; + volatile u8 pointlessZero; - addr = (void *)(VRAM + 0x6000); - size = 0x2000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - pointlessZero = 0; - pointlessZero = 0; - addr2 = (void *)(VRAM + 0xF000); - DmaFill32(3, 0, addr2, 0x800); + DmaFill32Large(3, 0, (void *)(VRAM + 0x6000), 0x2000, 0x1000); + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + DmaFill32Defvars(3, 0, (void *)(VRAM + 0xF000), 0x800); REG_BG2CNT_BITFIELD.priority = 2; REG_BG2CNT_BITFIELD.screenSize = 1; @@ -2004,8 +1971,7 @@ void sub_8076034(u8 a, u8 b) REG_BG2VOFS = gBattle_BG2_Y; LoadPalette(gPlttBufferUnfaded + 0x100 + a * 16, 0x90, 32); - addr3 = (void *)(PLTT + 0x120); - DmaCopy32(3, gPlttBufferUnfaded + 0x100 + a * 16, addr3, 32); + DmaCopy32Defvars(3, gPlttBufferUnfaded + 0x100 + a * 16, (void *)(PLTT + 0x120), 32); sub_80E4EF8(0, 0, GetBankIdentity(a), 9, 0x6000, 0x1E, REG_BG2CNT_BITFIELD.charBaseBlock); } @@ -2060,57 +2026,25 @@ void sub_80763FC(u16 a, u16 *b, u32 c, u8 d) void sub_8076464(u8 a) { - u8 *addr; - u32 size; volatile u8 pointlessZero; struct UnknownStruct2 s; sub_8078914(&s); if (a == 0 || IsContest() != 0) { - u16 *addr2; - - addr = s.unk0; - size = 0x2000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - pointlessZero = 0; - pointlessZero = 0; - addr2 = s.unk4; - DmaFill32(3, 0, addr2, 0x800); + DmaFill32Large(3, 0, s.unk0, 0x2000, 0x1000); + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + DmaFill32Defvars(3, 0, s.unk4, 0x800); gBattle_BG1_X = 0; gBattle_BG1_Y = 0; } else { - u16 *addr2; - - addr = (void *)(VRAM + 0x6000); - size = 0x2000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - pointlessZero = 0; - pointlessZero = 0; - addr2 = (void *)(VRAM + 0xF000); - DmaFill32(3, 0, addr2, 0x800); + DmaFill32Large(3, 0, (void *)(VRAM + 0x6000), 0x2000, 0x1000); + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + pointlessZero = 0; // is there a stubbed out Dma macro here that left the 0 load in? + DmaFill32Defvars(3, 0, (void *)(VRAM + 0xF000), 0x800); gBattle_BG2_X = 0; gBattle_BG2_Y = 0; } @@ -2130,25 +2064,15 @@ static void task_pA_ma0A_obj_to_bg_pal(u8 taskId) if (gTasks[taskId].data[5] == 0) { - u16 *src; - u16 *dst; - gBattle_BG1_X = x + gTasks[taskId].data[3]; gBattle_BG1_Y = y + gTasks[taskId].data[4]; - src = gPlttBufferFaded + 0x100 + palIndex * 16; - dst = gPlttBufferFaded + 0x100 + s.unk8 * 16 - 256; - DmaCopy32(3, src, dst, 32); + DmaCopy32Defvars(3, gPlttBufferFaded + 0x100 + palIndex * 16, gPlttBufferFaded + 0x100 + s.unk8 * 16 - 256, 32); } else { - u16 *src; - u16 *dst; - gBattle_BG2_X = x + gTasks[taskId].data[3]; gBattle_BG2_Y = y + gTasks[taskId].data[4]; - src = gPlttBufferFaded + 0x100 + palIndex * 16; - dst = gPlttBufferFaded + 0x100 - 112; - DmaCopy32(3, src, dst, 32); + DmaCopy32Defvars(3, gPlttBufferFaded + 0x100 + palIndex * 16, gPlttBufferFaded + 0x100 - 112, 32); } } @@ -2492,14 +2416,10 @@ static void LoadMoveBg(u16 bgId) if (IsContest()) { void *tilemap = gBattleAnimBackgroundTable[bgId].tilemap; - void *dmaSrc; - void *dmaDest; LZDecompressWram(tilemap, IsContest() ? EWRAM_14800 : EWRAM_18000); sub_80763FC(sub_80789BC(), IsContest() ? EWRAM_14800 : EWRAM_18000, 0x100, 0); - dmaSrc = IsContest() ? EWRAM_14800 : EWRAM_18000; - dmaDest = (void *)(VRAM + 0xD000); - DmaCopy32(3, dmaSrc, dmaDest, 0x800); + DmaCopy32Defvars(3, IsContest() ? EWRAM_14800 : EWRAM_18000, (void *)(VRAM + 0xD000), 0x800); LZDecompressVram(gBattleAnimBackgroundTable[bgId].image, (void *)(VRAM + 0x2000)); LoadCompressedPalette(gBattleAnimBackgroundTable[bgId].palette, sub_80789BC() * 16, 32); } diff --git a/src/battle/battle_controller_player.c b/src/battle/battle_controller_player.c index eaabe9b53..7e3655e4a 100644 --- a/src/battle/battle_controller_player.c +++ b/src/battle/battle_controller_player.c @@ -4151,22 +4151,7 @@ void PlayerHandleDMATransfer(void) | (gBattleBufferA[gActiveBank][4] << 24); u16 val2 = gBattleBufferA[gActiveBank][5] | (gBattleBufferA[gActiveBank][6] << 8); - const u8 *src = &gBattleBufferA[gActiveBank][7]; - u8 *dst = (u8 *)val1; - u32 size = val2; - - while (1) - { - if (size <= 0x1000) - { - DmaCopy16(3, src, dst, size); - break; - } - DmaCopy16(3, src, dst, 0x1000); - src += 0x1000; - dst += 0x1000; - size -= 0x1000; - } + Dma3CopyLarge16_(&gBattleBufferA[gActiveBank][7], (u8 *)val1, val2); PlayerBufferExecCompleted(); } diff --git a/src/battle/battle_message.c b/src/battle/battle_message.c index e9334ef61..ed7ab3a35 100644 --- a/src/battle/battle_message.c +++ b/src/battle/battle_message.c @@ -25,6 +25,8 @@ #include "../data/battle_strings_en.h" #endif +// This is four lists of moves which use a different attack string in Japanese +// to the default. See the documentation for sub_8121D74 for more detail. const u16 gUnknown_084016BC[] = { MOVE_SWORDS_DANCE, @@ -69,7 +71,7 @@ const u16 gUnknown_084016BC[] = MOVE_MUDDY_WATER, MOVE_IRON_DEFENSE, MOVE_BOUNCE, - MOVE_NONE, + 0, MOVE_TELEPORT, MOVE_RECOVER, MOVE_BIDE, @@ -77,7 +79,7 @@ const u16 gUnknown_084016BC[] = MOVE_FLAIL, MOVE_TAUNT, MOVE_BULK_UP, - MOVE_NONE, + 0, MOVE_MEDITATE, MOVE_AGILITY, MOVE_MIMIC, @@ -96,7 +98,7 @@ const u16 gUnknown_084016BC[] = MOVE_FAKE_TEARS, MOVE_WATER_SPORT, MOVE_CALM_MIND, - MOVE_NONE, + 0, MOVE_POUND, MOVE_SCRATCH, MOVE_VICE_GRIP, @@ -144,7 +146,7 @@ const u16 gUnknown_084016BC[] = MOVE_ENDEAVOR, MOVE_TICKLE, MOVE_COVET, - MOVE_NONE, + 0, }; const u8 gUnknown_084017A8[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // empty flags @@ -971,6 +973,10 @@ void StrCpyDecodeBattleTextBuff(u8* src, u8* dst) } } +// Loads one of two text strings into the provided buffer. This is functionally +// unused, since the value loaded into the buffer is not read; it loaded one of +// two particles (either "は" or "の") which works in tandem with sub_8121D74 +// below to effect changes in the meaning of the line. void sub_8121D1C(u8* textBuff) { s32 counter = 0; @@ -993,6 +999,24 @@ void sub_8121D1C(u8* textBuff) } } +// Appends "!" to the text buffer `dst`. In the original Japanese this looked +// into the table of moves at gUnknown_084016BC and varied the line accordingly. +// +// BattleText_Exclamation was a plain "!", used for any attack not on the list. +// It resulted in the translation "<NAME>'s <ATTACK>!". +// +// BattleText_Exclamation2 was "を つかった!". This resulted in the translation +// "<NAME> used <ATTACK>!", which was used for all attacks in English. +// +// BattleText_Exclamation3 was "した!". This was used for those moves whose +// names were verbs, such as Recover, and resulted in translations like "<NAME> +// recovered itself!". +// +// BattleText_Exclamation4 was "を した!" This resulted in a translation of +// "<NAME> did an <ATTACK>!". +// +// BattleText_Exclamation5 was " こうげき!" This resulted in a translation of +// "<NAME>'s <ATTACK> attack!". void sub_8121D74(u8* dst) { s32 counter = 0; diff --git a/src/battle/battle_party_menu.c b/src/battle/battle_party_menu.c index 68a97c536..ed8cf4583 100644 --- a/src/battle/battle_party_menu.c +++ b/src/battle/battle_party_menu.c @@ -40,7 +40,7 @@ extern u8 gUnknown_0202E8F6; extern u8 gUnknown_02038470[3]; extern u8 gUnknown_02038473; extern u8 gUnknown_020384F0; -extern void (*gUnknown_03004AE4)(); //don't know types yet +extern void (*gPokemonItemUseCallback)(); //don't know types yet extern struct PokemonStorage gPokemonStorage; extern void nullsub_14(); @@ -466,7 +466,7 @@ void HandleBattlePartyMenu(u8 taskId) { if (gUnknown_02038473 == 3 && GetItemEffectType(gSpecialVar_ItemId) == 10) { - gUnknown_03004AE4(taskId, gSpecialVar_ItemId, Task_80952E4); + gPokemonItemUseCallback(taskId, gSpecialVar_ItemId, Task_80952E4); return; } @@ -480,7 +480,7 @@ void HandleBattlePartyMenu(u8 taskId) else { sub_806D5A4(); - gUnknown_03004AE4(taskId, gSpecialVar_ItemId, Task_80952E4); + gPokemonItemUseCallback(taskId, gSpecialVar_ItemId, Task_80952E4); } } else diff --git a/src/battle/battle_setup.c b/src/battle/battle_setup.c index b4ff407fc..892be1029 100644 --- a/src/battle/battle_setup.c +++ b/src/battle/battle_setup.c @@ -520,8 +520,8 @@ static void DoStandardWildBattle(void) gMain.savedCallback = CB2_EndWildBattle; gBattleTypeFlags = 0; CreateBattleStartTask(GetWildBattleTransition(), 0); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } void BattleSetup_StartRoamerBattle(void) @@ -532,8 +532,8 @@ void BattleSetup_StartRoamerBattle(void) gMain.savedCallback = CB2_EndWildBattle; gBattleTypeFlags = BATTLE_TYPE_ROAMER; CreateBattleStartTask(GetWildBattleTransition(), 0); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } static void DoSafariBattle(void) @@ -549,8 +549,8 @@ static void DoSafariBattle(void) static void StartTheBattle(void) { CreateBattleStartTask(GetTrainerBattleTransition(), 0); - IncrementGameStat(7); - IncrementGameStat(9); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_TRAINER_BATTLES); } //Initiates battle where Wally catches Ralts @@ -569,8 +569,8 @@ void BattleSetup_StartScriptedWildBattle(void) gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = 0; CreateBattleStartTask(GetWildBattleTransition(), 0); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } void ScrSpecial_StartSouthernIslandBattle(void) @@ -579,8 +579,8 @@ void ScrSpecial_StartSouthernIslandBattle(void) gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY; CreateBattleStartTask(GetWildBattleTransition(), 0); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } void ScrSpecial_StartRayquazaBattle(void) @@ -589,8 +589,8 @@ void ScrSpecial_StartRayquazaBattle(void) gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY; CreateBattleStartTask(B_TRANSITION_BLUR, BGM_BATTLE34); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } void ScrSpecial_StartGroudonKyogreBattle(void) @@ -602,8 +602,8 @@ void ScrSpecial_StartGroudonKyogreBattle(void) CreateBattleStartTask(B_TRANSITION_SHARDS, BGM_BATTLE34); // GROUDON else CreateBattleStartTask(B_TRANSITION_RIPPLE, BGM_BATTLE34); // KYOGRE - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } void ScrSpecial_StartRegiBattle(void) @@ -612,8 +612,8 @@ void ScrSpecial_StartRegiBattle(void) gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_REGI; CreateBattleStartTask(B_TRANSITION_GRID_SQUARES, BGM_BATTLE36); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } static void CB2_EndWildBattle(void) @@ -879,8 +879,8 @@ static void CB2_StartFirstBattle(void) SetMainCallback2(sub_800E7C4); prev_quest_postbuffer_cursor_backup_reset(); overworld_poison_timer_set(); - IncrementGameStat(7); - IncrementGameStat(8); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); } } diff --git a/src/battle/battle_transition.c b/src/battle/battle_transition.c index f7cdc0694..a94974b27 100644 --- a/src/battle/battle_transition.c +++ b/src/battle/battle_transition.c @@ -6,6 +6,7 @@ #include "palette.h" #include "trig.h" #include "field_effect.h" +#include "field_weather.h" #include "random.h" #include "sprite.h" #include "sound.h" @@ -15,7 +16,6 @@ #include "ewram.h" #include "scanline_effect.h" -void sub_807DE10(void); void ScanlineEffect_Clear(void); extern const struct OamData gFieldOamData_32x32; @@ -567,7 +567,7 @@ static void Task_BattleTransitionMain(u8 taskID) static bool8 Transition_Phase1(struct Task* task) { - sub_807DE10(); + SetWeatherScreenFadeOut(); CpuCopy32(gPlttBufferFaded, gPlttBufferUnfaded, 0x400); if (sPhase1_Tasks[task->tTransitionID] != NULL) { diff --git a/src/battle/battle_util.c b/src/battle/battle_util.c index 3bb99f845..8dae98b66 100644 --- a/src/battle/battle_util.c +++ b/src/battle/battle_util.c @@ -4,6 +4,7 @@ #include "data2.h" #include "event_data.h" #include "ewram.h" +#include "field_weather.h" #include "item.h" #include "link.h" #include "pokemon.h" @@ -85,7 +86,6 @@ u8 CountTrailingZeroBits(u32 a); u8 GetMoveTarget(u16 move, u8 useMoveTarget); u8 sub_803FC34(u8 bank); u16 sub_803FBFC(u8 a); -u8 weather_get_current(void); void RecordAbilityBattle(u8 bank, u8 ability); void RecordItemBattle(u8 bank, u8 holdEffect); s8 GetPokeFlavourRelation(u32 pid, u8 flavor); @@ -1987,7 +1987,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) beq ._789 @cond_branch\n\ bl ._1534\n\ ._789:\n\ - bl weather_get_current\n\ + bl GetCurrentWeather\n\ lsl r0, r0, #0x18\n\ lsr r0, r0, #0x18\n\ sub r0, r0, #0x3\n\ @@ -2084,7 +2084,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) bne ._815 @cond_branch\n\ bl ._1540\n\ ._815:\n\ - bl weather_get_current\n\ + bl GetCurrentWeather\n\ ldr r1, ._818 + 16\n\ strb r0, [r1, #0x5]\n\ ldr r0, ._818 + 20\n\ @@ -5807,7 +5807,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) { case 0xFF: //weather from overworld //_08018586 - switch (weather_get_current()) + switch (GetCurrentWeather()) { case WEATHER_RAIN_LIGHT: case WEATHER_RAIN_MED: @@ -5841,7 +5841,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 bank, u8 ability, u8 special, u16 moveArg) } if (effect) { - gBattleCommunication[MULTISTRING_CHOOSER] = weather_get_current(); + gBattleCommunication[MULTISTRING_CHOOSER] = GetCurrentWeather(); BattleScriptPushCursorAndCallback(BattleScript_OverworldWeatherStarts); } break; diff --git a/src/battle/post_battle_event_funcs.c b/src/battle/post_battle_event_funcs.c index 0617763f6..a44cf028b 100644 --- a/src/battle/post_battle_event_funcs.c +++ b/src/battle/post_battle_event_funcs.c @@ -26,8 +26,8 @@ int GameClear(void) FlagSet(FLAG_SYS_GAME_CLEAR); } - if (!GetGameStat(1)) - SetGameStat(1, (gSaveBlock2.playTimeHours << 16) | (gSaveBlock2.playTimeMinutes << 8) | gSaveBlock2.playTimeSeconds); + if (!GetGameStat(GAME_STAT_FIRST_HOF_PLAY_TIME)) + SetGameStat(GAME_STAT_FIRST_HOF_PLAY_TIME, (gSaveBlock2.playTimeHours << 16) | (gSaveBlock2.playTimeMinutes << 8) | gSaveBlock2.playTimeSeconds); SetSecretBase2Field_9(); @@ -54,7 +54,7 @@ int GameClear(void) if (ribbonGet == TRUE) { - IncrementGameStat(42); + IncrementGameStat(GAME_STAT_RECEIVED_RIBBONS); FlagSet(FLAG_SYS_RIBBON_GET); } diff --git a/src/contest.c b/src/contest.c index d559ca81f..20e202d80 100644 --- a/src/contest.c +++ b/src/contest.c @@ -4513,12 +4513,8 @@ void sub_80B0748(u8 taskId) { // What the hell? These aren't pointers. // This code would crash if run. - { - void *src = (void *)(u32)gPlttBufferFaded[(r4 + 5) * 16 + 1]; - void *dest = (void *)(u32)gPlttBufferUnfaded[(r4 + 5) * 16 + 1]; - u32 size = 6; - DmaCopy16(3, src, dest, size); - } + DmaCopy16Defvars(3, (void *)(u32)gPlttBufferFaded[(r4 + 5) * 16 + 1], + (void *)(u32)gPlttBufferUnfaded[(r4 + 5) * 16 + 1], 6); gTasks[taskId].data[r1 + 0] = 0; } } @@ -4888,21 +4884,13 @@ u8 sub_80B09E4(u8 a) CopySpriteTiles(0, 3, (void *)VRAM, (u16 *)(VRAM + 0xE000 + gUnknown_02038696[a] * 5 * 64 + 0x26), (u8 *)(VRAM + 0x10000 + gSprites[r8].oam.tileNum * 32)); CopySpriteTiles(0, 3, (void *)VRAM, (u16 *)(VRAM + 0xE000 + gUnknown_02038696[a] * 5 * 64 + 0x36), (u8 *)(VRAM + 0x10000 + gSprites[r6].oam.tileNum * 32)); - { - void *dest = (void *)(VRAM + 0x10000 + (0x28 + gSprites[r8].oam.tileNum) * 32); - u32 size = 0x300; - DmaFill32(3, 0, dest, size); - } + DmaFill32Defvars(3, 0, (void *)(VRAM + 0x10000 + (0x28 + gSprites[r8].oam.tileNum) * 32), 0x300); // What is this? zero = 0; zero = 0; - { - void *dest = (void *)(VRAM + 0x10000 + (0x28 + gSprites[r6].oam.tileNum) * 32); - u32 size = 0x300; - DmaFill32(3, 0, dest, size); - } + DmaFill32Defvars(3, 0, (void *)(VRAM + 0x10000 + (0x28 + gSprites[r6].oam.tileNum) * 32), 0x300); gSprites[r8].data[0] = r6; gSprites[r6].data[0] = r8; diff --git a/src/debug/crash.c b/src/debug/crash.c new file mode 100644 index 000000000..85058d285 --- /dev/null +++ b/src/debug/crash.c @@ -0,0 +1,55 @@ +#include "global.h" +#include "main.h" +#include "task.h" +#include "text.h" +#include "palette.h" + +extern struct Window gUnknown_03004210; + +static void CB2_CrashIdle(void); + +// unused exception handler. Takes a string input describing the exception +// and halts on a black screen. Used in German Debug Ruby. +void Crash(u8 *text) +{ + u16 savedIme; + + REG_BG0HOFS = 0; + REG_BG0VOFS = 0; + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + REG_BG2HOFS = 0; + REG_BG2VOFS = 0; + REG_BG3HOFS = 0; + REG_BG3VOFS = 0; + REG_WIN0H = 0; + REG_WIN0V = 0; + REG_WIN1H = 0; + REG_WIN1V = 0; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON; + savedIme = REG_IME; + REG_IME = 0; + REG_IE |= INTR_FLAG_VBLANK; + REG_IME = savedIme; + REG_DISPSTAT = 8; + ResetTasks(); + ResetSpriteData(); + SetMainCallback2(CB2_CrashIdle); + DmaFill32Large(3, 0, (void *)VRAM, 0x18000, 0x1000); + Text_LoadWindowTemplate(&gWindowTemplate_81E6FD8); + Text_InitWindowWithTemplate(&gUnknown_03004210, &gWindowTemplate_81E6FD8); + LoadFontDefaultPalette(&gWindowTemplate_81E6FD8); + Text_InitWindowAndPrintText(&gUnknown_03004210, text, 1, 9, 7); +} + +static void CB2_CrashIdle(void) +{ + REG_BG0HOFS = 0; + REG_BG0VOFS = 0; + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + REG_BG2HOFS = 0; + REG_BG2VOFS = 0; + REG_BG3HOFS = 0; + REG_BG3VOFS = 0; +} diff --git a/src/debug/kagaya_debug_menu.c b/src/debug/kagaya_debug_menu.c index 321627a10..53e3fac1a 100644 --- a/src/debug/kagaya_debug_menu.c +++ b/src/debug/kagaya_debug_menu.c @@ -65,7 +65,7 @@ void InitKagayaDebugMenu_B() " .align 2, 0\n" "._1:\n" " .word _83EBB64\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_80B061C+1\n" "\n" ); @@ -102,7 +102,7 @@ void debug_sub_80B061C() "._8:\n" " .align 2, 0\n" "._7:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word _83EBB64\n" "._5:\n" " bl CloseMenu\n" @@ -137,7 +137,7 @@ u8 KagayaDebugMenu_TrainerCard() "._10:\n" " .align 2, 0\n" "._9:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_80B068C+1\n" "\n" ); @@ -194,7 +194,7 @@ u8 KagayaDebugMenu_CardToExchange() "._16:\n" " .align 2, 0\n" "._15:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_80B06E0+1\n" "\n" ); @@ -251,7 +251,7 @@ u8 KagayaDebugMenu_SlotMachine() "._22:\n" " .align 2, 0\n" "._21:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word Kagaya_80B0734+1\n" "\n" ); @@ -354,7 +354,7 @@ void debug_sub_80B07B0() "._33:\n" " .align 2, 0\n" "._32:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_80B07DC+1\n" "\n" ); diff --git a/src/debug/matsuda_debug_menu.c b/src/debug/matsuda_debug_menu.c index 1da337b04..da1937adb 100644 --- a/src/debug/matsuda_debug_menu.c +++ b/src/debug/matsuda_debug_menu.c @@ -37,8 +37,8 @@ extern u16 gBattle_BG2_X; extern u16 gBattle_BG2_Y; extern u16 gBattle_BG3_X; extern u16 gBattle_BG3_Y; -extern struct Window gUnknown_03004210; -extern u8 (*gCallback_03004AE8)(void); + +extern u8 (*gMenuCallback)(void); extern bool8 gReceivedRemoteLinkPlayers; @@ -251,7 +251,7 @@ u8 unref_sub_80A9B28(void) Menu_DrawStdWindowFrame(0, 0, 17, 18); Menu_PrintItems(1, 1, 7, gMatsudaDebugMenuActions); InitMenu(0, 1, 1, 7, 0, 16); - gCallback_03004AE8 = sub_80A9B78; + gMenuCallback = sub_80A9B78; return 0; } @@ -264,7 +264,7 @@ static bool8 sub_80A9B78(void) case -2: return FALSE; default: - gCallback_03004AE8 = gMatsudaDebugMenuActions[choice].func; + gMenuCallback = gMatsudaDebugMenuActions[choice].func; return FALSE; case -1: CloseMenu(); @@ -469,26 +469,10 @@ static void sub_80A9F50(void) static void sub_80A9FE4(void) { - u8 *addr; - u32 i; u8 ptr[5]; memcpy(ptr, gMatsudaDebugMenu_UnknownByteArray, 5); - - addr = (void *)VRAM; - i = VRAM_SIZE; - - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - i -= 0x1000; - if (i <= 0x1000) - { - DmaFill32(3, 0, addr, i); - break; - } - } + DmaFill32Large(3, 0, (void *)VRAM, VRAM_SIZE, 0x1000); sub_80034D4((void *)VRAM, ptr); LoadFontDefaultPalette(&gWindowTemplate_81E6C3C); } @@ -1032,63 +1016,3 @@ u8 MatsudaDebugMenu_SetArtMuseumItems(void) CloseMenu(); return 1; } - -void unref_sub_80AB084(u8 *text) -{ - u16 savedIme; - u8 *addr; - size_t size; - - REG_BG0HOFS = 0; - REG_BG0VOFS = 0; - REG_BG1HOFS = 0; - REG_BG1VOFS = 0; - REG_BG2HOFS = 0; - REG_BG2VOFS = 0; - REG_BG3HOFS = 0; - REG_BG3VOFS = 0; - REG_WIN0H = 0; - REG_WIN0V = 0; - REG_WIN1H = 0; - REG_WIN1V = 0; - REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON; - - savedIme = REG_IME; - REG_IME = 0; - REG_IE |= INTR_FLAG_VBLANK; - REG_IME = savedIme; - REG_DISPSTAT = 8; - ResetTasks(); - ResetSpriteData(); - SetMainCallback2(sub_80AB184); - - addr = (void *)VRAM; - size = 0x18000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } - Text_LoadWindowTemplate(&gWindowTemplate_81E6FD8); - Text_InitWindowWithTemplate(&gUnknown_03004210, &gWindowTemplate_81E6FD8); - LoadFontDefaultPalette(&gWindowTemplate_81E6FD8); - Text_InitWindowAndPrintText(&gUnknown_03004210, text, 1, 9, 7); -} - -void sub_80AB184(void) -{ - REG_BG0HOFS = 0; - REG_BG0VOFS = 0; - REG_BG1HOFS = 0; - REG_BG1VOFS = 0; - REG_BG2HOFS = 0; - REG_BG2VOFS = 0; - REG_BG3HOFS = 0; - REG_BG3VOFS = 0; -} diff --git a/src/debug/mori_debug_menu.c b/src/debug/mori_debug_menu.c index 7b9a579a7..767f4cda0 100644 --- a/src/debug/mori_debug_menu.c +++ b/src/debug/mori_debug_menu.c @@ -12,7 +12,7 @@ #define SIO_MULTI_CNT ((struct SioMultiCnt *)REG_ADDR_SIOCNT) -extern u8 (*gCallback_03004AE8)(void); +extern u8 (*gMenuCallback)(void); u8 gUnknown_03004DA0[0x20]; @@ -98,7 +98,7 @@ u8 MoriDebugMenu_SearchChild(u8 a1, u8 a2, u8 *ptr) Menu_EraseScreen(); Menu_DrawStdWindowFrame(0, 14, 30, 19); Menu_PrintText(localPtr, 1, 15); - gCallback_03004AE8 = sub_8083D4C; + gMenuCallback = sub_8083D4C; return 0; } @@ -184,7 +184,7 @@ bool8 MoriDebugMenuProcessInput(void) switch (choice) { default: - gCallback_03004AE8 = gMoriDebugMenuActions[choice].func; + gMenuCallback = gMoriDebugMenuActions[choice].func; return FALSE; case -2: return FALSE; @@ -200,6 +200,6 @@ s8 InitMoriDebugMenu(void) Menu_DrawStdWindowFrame(0, 0, 10, 19); Menu_PrintItems(1, 1, 9, gMoriDebugMenuActions); InitMenu(0, 1, 1, 9, 0, 9); - gCallback_03004AE8 = MoriDebugMenuProcessInput; + gMenuCallback = MoriDebugMenuProcessInput; return 0; } diff --git a/src/debug/nakamura_debug_menu.c b/src/debug/nakamura_debug_menu.c index b86fa0abf..67f4a1af7 100644 --- a/src/debug/nakamura_debug_menu.c +++ b/src/debug/nakamura_debug_menu.c @@ -224,7 +224,7 @@ void InitNakamuraDebugMenu() "._4:\n" " .align 2, 0\n" "._3:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815F214+1\n" "\n" ); @@ -825,7 +825,7 @@ u8 debug_sub_815F62C() " .align 2, 0\n" "._59:\n" " .word _nakamuraData\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815F5C4+1\n" "\n" ); @@ -1367,7 +1367,7 @@ void debug_sub_815F930() "._134:\n" " .align 2, 0\n" "._133:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815FA38+1\n" "._131:\n" " mov r0, #0x2\n" @@ -1500,7 +1500,7 @@ void debug_sub_815FA38() " .word 0x1a08\n" " .word _nakamuraData+0x1\n" " .word _nakamuraData+0x2\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815F930+1\n" "._155:\n" " mov r0, #0x2\n" @@ -1560,7 +1560,7 @@ u8 debug_sub_815FB1C() "._162:\n" " .word _nakamuraData\n" " .word _nakamuraData+0x3\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815FA38+1\n" "\n" ); @@ -1680,7 +1680,7 @@ u8 debug_sub_815FBE8() "._179:\n" " .align 2, 0\n" "._178:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815FB78+1\n" " .word gStringVar1\n" " .word Str_843E580\n" @@ -2154,7 +2154,7 @@ u8 debug_sub_815FE1C() " .word gStringVar1\n" " .word gSaveBlock1\n" " .word 0x2dd6\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_815FDE4+1\n" "\n" ); @@ -2250,7 +2250,7 @@ void debug_sub_815FFDC() " .align 2, 0\n" "._217:\n" " .word _nakamuraData+0x4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8160498+1\n" "\n" ); @@ -4142,7 +4142,7 @@ u8 debug_sub_8160D98() "._486:\n" " .align 2, 0\n" "._485:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8160CF4+1\n" "\n" ); @@ -4602,7 +4602,7 @@ void DebugMenu_EffortValues() "._519:\n" " .word _nakamuraData+0x5\n" " .word gPlayerParty\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_81610BC+1\n" "\n" ); @@ -5022,7 +5022,7 @@ void DebugMenu_RandomNumberTest() " .word _nakamuraData+0x8\n" " .word _nakamuraData+0xc\n" " .word _nakamuraData+0xa\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_81612EC+1\n" "\n" ); diff --git a/src/debug/nohara_debug_menu.c b/src/debug/nohara_debug_menu.c index 629b7b9eb..a932fee8d 100644 --- a/src/debug/nohara_debug_menu.c +++ b/src/debug/nohara_debug_menu.c @@ -42,7 +42,7 @@ void InitNoharaDebugMenu() " .align 2, 0\n" "._1:\n" " .word gUnknown_Debug_083C4938\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808F414+1\n" "\n" ); @@ -76,7 +76,7 @@ void debug_sub_808F414() "._7:\n" " .align 2, 0\n" "._6:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C4938\n" "._4:\n" " bl CloseMenu\n" @@ -129,7 +129,7 @@ void NoharaDebugMenu_TV() "._8:\n" " .word gDebug_03000724+0x2\n" " .word gUnknown_Debug_083C4B8C\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808F4AC+1\n" "\n" ); @@ -163,7 +163,7 @@ void debug_sub_808F4AC() "._14:\n" " .align 2, 0\n" "._13:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C4B8C\n" "._11:\n" " bl CloseMenu\n" @@ -196,7 +196,7 @@ void debug_sub_808F4EC() " .align 2, 0\n" "._15:\n" " .word gUnknown_Debug_083C4980\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808F648+1\n" "\n" ); @@ -379,7 +379,7 @@ void debug_sub_808F5D8() " .word gStringVar1\n" " .word gUnknown_Debug_083C4BD4\n" " .word gSpecialVar_0x8004\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090278+1\n" "\n" ); @@ -779,7 +779,7 @@ void debug_sub_808F8CC() " .word gUnknown_Debug_083C49CA\n" " .word gUnknown_Debug_083C4ABD+0xf\n" " .word gStringVar1\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808F93C+1\n" "\n" ); @@ -1517,7 +1517,7 @@ void debug_sub_808FECC() " .word gUnknown_Debug_083C49CA\n" " .word gUnknown_Debug_083C4B20+0x4\n" " .word gStringVar1\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808FF3C+1\n" "\n" ); @@ -1847,7 +1847,7 @@ void NoharaDebugMenu_Fan() " .align 2, 0\n" "._204:\n" " .word gUnknown_Debug_083C4D28\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_80901A4+1\n" "\n" ); @@ -1881,7 +1881,7 @@ void debug_sub_80901A4() "._210:\n" " .align 2, 0\n" "._209:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C4D28\n" "._207:\n" " bl CloseMenu\n" @@ -1938,7 +1938,7 @@ void debug_sub_80901F8() "._211:\n" " .word gUnknown_Debug_083C4CA8\n" " .word gUnknown_083F8408\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090278+1\n" "\n" ); @@ -1974,7 +1974,7 @@ void debug_sub_8090238() "._213:\n" " .word gUnknown_Debug_083C4CA8\n" " .word gUnknown_083F8410\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090278+1\n" "\n" ); @@ -2040,7 +2040,7 @@ void debug_sub_809029C() " .word gStringVar1\n" " .word gSaveBlock1\n" " .word 0x13c2\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090278+1\n" "\n" ); diff --git a/src/debug/start_menu_debug.c b/src/debug/start_menu_debug.c index b376a4076..f8e10baa2 100644 --- a/src/debug/start_menu_debug.c +++ b/src/debug/start_menu_debug.c @@ -900,7 +900,7 @@ void DebugMenu_8077020() "._110:\n" " .align 2, 0\n" "._109:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" "\n" ); } @@ -922,7 +922,7 @@ void DebugMenu_8077048() "._112:\n" " .align 2, 0\n" "._111:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_807706C+1\n" " .word DebugMenu_8077020+1\n" "\n" @@ -950,7 +950,7 @@ void DebugMenu_807706C() " .align 2, 0\n" "._113:\n" " .word gWindowTemplate_81E6CE4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_807709C+1\n" "\n" ); @@ -1639,7 +1639,7 @@ void DebugMenu_SetRamBerry() " .align 2, 0\n" "._172:\n" " .word gUnknown_Debug_0839BBC1+0x263\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_807750C+1\n" "\n" ); @@ -2154,7 +2154,7 @@ void DebugMenu_SwitchBG() "._204:\n" " .align 2, 0\n" "._203:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077760+1\n" "\n" ); @@ -2264,7 +2264,7 @@ void DebugMenu_ControlEncounter() " .align 2, 0\n" "._213:\n" " .word sWildEncountersDisabled\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_80778A8+1\n" "\n" ); @@ -2282,7 +2282,7 @@ void DebugMenu_UseHM() "._216:\n" " .align 2, 0\n" "._215:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077C14+1\n" "\n" ); @@ -2418,7 +2418,7 @@ void DebugMenu_8077974() " .word gStringVar2\n" " .word gUnknown_Debug_0839BBC1+0x2cf\n" " .word gUnknown_Debug_0839BBC1+0x2aa\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077DB4+1\n" "\n" ); @@ -2509,7 +2509,7 @@ void DebugMenu_RematchTrainers() " .align 2, 0\n" "._240:\n" " .word gUnknown_Debug_0839BBC1+0x323\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077A60+1\n" "\n" ); @@ -2627,7 +2627,7 @@ void DebugMenu_8077B00() " .align 2, 0\n" "._254:\n" " .word gUnknown_Debug_0839BBC1+0x35e\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077DB4+1\n" "\n" ); @@ -2686,7 +2686,7 @@ void DebugMenu_Safari() " .word gStringVar1\n" " .word gSafariZoneStepCounter\n" " .word gUnknown_Debug_0839BBC1+0x34b\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077B3C+1\n" "._258:\n" " bl CloseMenu\n" @@ -2818,7 +2818,7 @@ void DebugMenu_8077C14() " .align 2, 0\n" "._264:\n" " .word gUnknown_Debug_0839BBC1+0x3d3\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077C00+1\n" "\n" ); @@ -3031,7 +3031,7 @@ void DebugMenu_8077D78() "._279:\n" " .align 2, 0\n" "._278:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" "._276:\n" " bl CloseMenu\n" " mov r0, #0x1\n" @@ -4038,7 +4038,7 @@ void DebugMenu_ToggleClearFlag() " .align 2, 0\n" "._390:\n" " .word 0x804\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_80783C8+1\n" "\n" ); @@ -4120,7 +4120,7 @@ void DebugMenu_OpenWeatherEvents() " .align 2, 0\n" "._404:\n" " .word 0x82a\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078464+1\n" "\n" ); @@ -4188,7 +4188,7 @@ void DebugMenu_OpenMysteryEvent() "._417:\n" " .align 2, 0\n" "._416:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_80784E8+1\n" "\n" ); @@ -4604,7 +4604,7 @@ void DebugMenu_OpenLegendsRecord() " .align 2, 0\n" "._464:\n" " .word gDebug0x839C008+0x3f4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_80787B0+1\n" "\n" ); @@ -4804,7 +4804,7 @@ void DebugMenu_OpenBerryInfo() "._488:\n" " .align 2, 0\n" "._487:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8077DB4+1\n" "\n" ); @@ -5329,7 +5329,7 @@ void DebugMenu_8078C80() " .align 2, 0\n" "._548:\n" " .word gDebug0x839C574+0x30\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078CA8+1\n" "\n" ); @@ -5355,7 +5355,7 @@ void DebugMenu_8078CA8() " .align 2, 0\n" "._552:\n" " .word gMain\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078CE4+1\n" "._550:\n" " mov r0, #0x2\n" @@ -5412,7 +5412,7 @@ void DebugMenu_8078CE4() "._560:\n" " .word gStringVar4\n" " .word gDebug0x839C574+0x6b\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078D7C+1\n" "\n" ); @@ -5454,7 +5454,7 @@ void DebugMenu_8078D30() " .word +0x2000000\n" " .word gStringVar4\n" " .word gDebug0x839C574+0x62\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078D7C+1\n" "\n" ); @@ -5480,7 +5480,7 @@ void DebugMenu_8078D7C() " .align 2, 0\n" "._565:\n" " .word gStringVar4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078DA4+1\n" "\n" ); @@ -5533,7 +5533,7 @@ void DebugMenu_MeTooBackupMan() " .align 2, 0\n" "._571:\n" " .word gDebug0x839C574+0x20\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word DebugMenu_8078DF0+1\n" "\n" ); diff --git a/src/debug/taya_debug_window.c b/src/debug/taya_debug_window.c index 8b586deb2..954974e50 100644 --- a/src/debug/taya_debug_window.c +++ b/src/debug/taya_debug_window.c @@ -112,7 +112,7 @@ void TayaDebugMenu_Trend() " .align 2, 0\n" "._3:\n" " .word gSaveBlock1+0x2dd4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090808+1\n" "\n" ); @@ -273,7 +273,7 @@ void debug_sub_809089C() "._27:\n" " mov r0, #0x1\n" " mov r1, #0x0\n" - " bl fade_screen\n" + " bl FadeScreen\n" " ldr r1, ._30 + 8\n" " ldr r0, ._30 + 12\n" " str r0, [r1]\n" @@ -287,7 +287,7 @@ void debug_sub_809089C() "._30:\n" " .word gSpecialVar_0x8005\n" " .word gSpecialVar_0x8006\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090880+1\n" "\n" ); @@ -329,7 +329,7 @@ void TayaDebugMenu_SimpleText() " .align 2, 0\n" "._32:\n" " .word gUnknown_Debug_083C4EC0\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_809089C+1\n" "\n" ); @@ -460,7 +460,7 @@ void TayaDebugMenu_OldMan() " .align 2, 0\n" "._48:\n" " .word gUnknown_Debug_083C4F54\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090984+1\n" "\n" ); @@ -894,7 +894,7 @@ void TayaDebugMenu_PKMNLottery() "._83:\n" " .word +0x2000000\n" " .word gSpecialVar_Result\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_8090C88+1\n" "\n" ); @@ -1328,7 +1328,7 @@ void TayaDebugMenu_8091190() "._100:\n" " .align 2, 0\n" "._99:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_83C5068\n" " .word unk_2030224\n" "._96:\n" @@ -1460,7 +1460,7 @@ void InitTayaDebugWindow() "._109:\n" " .word unk_2030224\n" " .word gUnknown_Debug_83C5068\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word TayaDebugMenu_8091190+1\n" "\n" ); @@ -1505,7 +1505,7 @@ void debug_sub_8091300() " push {lr}\n" " mov r0, #0x1\n" " mov r1, #0x0\n" - " bl fade_screen\n" + " bl FadeScreen\n" " ldr r1, ._117\n" " ldr r0, ._117 + 4\n" " str r0, [r1]\n" @@ -1515,7 +1515,7 @@ void debug_sub_8091300() "._118:\n" " .align 2, 0\n" "._117:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_80912D8+1\n" "\n" ); diff --git a/src/debug/tomomichi_debug_menu.c b/src/debug/tomomichi_debug_menu.c index 28bb2717d..0549cb5c0 100644 --- a/src/debug/tomomichi_debug_menu.c +++ b/src/debug/tomomichi_debug_menu.c @@ -69,7 +69,7 @@ void debug_sub_808B874() "._1:\n" " .word gUnknown_Debug_083C0CBA\n" " .word gDebug_03000700+0x1d\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808B8C8+1\n" "\n" ); @@ -201,7 +201,7 @@ void TomomichiDebugMenu_ContestGraphics() "._11:\n" " .word gUnknown_Debug_083C0CF4\n" " .word gUnknown_Debug_083C0D2C\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BC48+1\n" " .word gDebug_03000700\n" " .word gDebug_03000700+0x4\n" @@ -265,7 +265,7 @@ void TomomichiDebugMenu_ArtMusGraphics() "._13:\n" " .word gUnknown_Debug_083C0D4C\n" " .word gUnknown_Debug_083C0D83\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BCBC+1\n" " .word gDebug_03000700\n" " .word gDebug_03000700+0x4\n" @@ -329,7 +329,7 @@ void TomomichiDebugMenu_PreviewData() "._15:\n" " .word gUnknown_Debug_083C0DA4\n" " .word gUnknown_Debug_083C0DD4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BD30+1\n" " .word gDebug_03000700\n" " .word gDebug_03000700+0x4\n" @@ -384,7 +384,7 @@ void TomomichiDebugMenu_TrickHouse() " .word gUnknown_Debug_083C0DF4\n" " .word gUnknown_Debug_083C0E15\n" " .word gDebug_03000700+0x1e\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BDA4+1\n" "\n" ); @@ -429,7 +429,7 @@ void TomomichiDebugMenu_ControlEvents() "._19:\n" " .word gUnknown_Debug_083C0E32\n" " .word gDebug_03000700+0x1f\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BE2C+1\n" "\n" ); @@ -474,7 +474,7 @@ void TomomichiDebugMenu_ControlFlags() "._21:\n" " .word gUnknown_Debug_083C0E7F\n" " .word gDebug_03000700+0x20\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BEB4+1\n" "\n" ); @@ -519,7 +519,7 @@ void TomomichiDebugMenu_ControlWorks() "._23:\n" " .word gUnknown_Debug_083C0EF1\n" " .word gDebug_03000700+0x21\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808BF3C+1\n" "\n" ); @@ -587,7 +587,7 @@ void debug_sub_808BC48() "._38:\n" " .align 2, 0\n" "._37:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C0D2C\n" "\n" ); @@ -655,7 +655,7 @@ void debug_sub_808BCBC() "._52:\n" " .align 2, 0\n" "._51:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C0D83\n" "\n" ); @@ -723,7 +723,7 @@ void debug_sub_808BD30() "._66:\n" " .align 2, 0\n" "._65:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C0DD4\n" "\n" ); @@ -1058,7 +1058,7 @@ void debug_sub_808BFC4() " .align 2, 0\n" "._99:\n" " .word gUnknown_Debug_083C0F79\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C064+1\n" "\n" ); @@ -1101,7 +1101,7 @@ void debug_sub_808C014() " .align 2, 0\n" "._101:\n" " .word gUnknown_Debug_083C0FFC\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C0A8+1\n" "\n" ); @@ -1138,7 +1138,7 @@ void debug_sub_808C064() "._108:\n" " .align 2, 0\n" "._107:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C0F79\n" "._105:\n" " bl CloseMenu\n" @@ -1181,7 +1181,7 @@ void debug_sub_808C0A8() "._114:\n" " .align 2, 0\n" "._113:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C0FFC\n" "._111:\n" " bl CloseMenu\n" @@ -1501,7 +1501,7 @@ void TomomichiDebugMenu_ContestGraphics_Show() "._146:\n" " .align 2, 0\n" "._145:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C280+1\n" "\n" ); @@ -1564,7 +1564,7 @@ void TomomichiDebugMenu_MuseumGraphics_Show() "._152:\n" " .align 2, 0\n" "._151:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C2E4+1\n" "\n" ); @@ -1641,7 +1641,7 @@ void debug_sub_808C31C() " .align 2, 0\n" "._157:\n" " .word gUnknown_Debug_083C2828\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C36C+1\n" "\n" ); @@ -1678,7 +1678,7 @@ void debug_sub_808C36C() "._164:\n" " .align 2, 0\n" "._163:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C2828\n" "._161:\n" " bl CloseMenu\n" @@ -1731,7 +1731,7 @@ void debug_sub_808C3B0() "._165:\n" " .word gUnknown_Debug_083C2938\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -1778,7 +1778,7 @@ void debug_sub_808C408() "._167:\n" " .word gUnknown_Debug_083C2A48\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -1825,7 +1825,7 @@ void debug_sub_808C460() "._169:\n" " .word gUnknown_Debug_083C2B4C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -1872,7 +1872,7 @@ void debug_sub_808C4B8() "._171:\n" " .word gUnknown_Debug_083C2C80\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -1919,7 +1919,7 @@ void debug_sub_808C510() "._173:\n" " .word gUnknown_Debug_083C2D8C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -1966,7 +1966,7 @@ void debug_sub_808C568() "._175:\n" " .word gUnknown_Debug_083C2EB0\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -2013,7 +2013,7 @@ void debug_sub_808C5C0() "._177:\n" " .word gUnknown_Debug_083C2FE0\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -2060,7 +2060,7 @@ void debug_sub_808C618() "._179:\n" " .word gUnknown_Debug_083C3100\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -2107,7 +2107,7 @@ void debug_sub_808C670() "._181:\n" " .word gUnknown_Debug_083C3194\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C6C8+1\n" "\n" ); @@ -2301,7 +2301,7 @@ void debug_sub_808C7C8() " .align 2, 0\n" "._197:\n" " .word gUnknown_Debug_083C1CE8\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808C818+1\n" "\n" ); @@ -2338,7 +2338,7 @@ void debug_sub_808C818() "._204:\n" " .align 2, 0\n" "._203:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C1CE8\n" "._201:\n" " bl CloseMenu\n" @@ -2391,7 +2391,7 @@ void debug_sub_808C85C() "._205:\n" " .word gUnknown_Debug_083C1E0C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2438,7 +2438,7 @@ void debug_sub_808C8B4() "._207:\n" " .word gUnknown_Debug_083C1F38\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2485,7 +2485,7 @@ void debug_sub_808C90C() "._209:\n" " .word gUnknown_Debug_083C206C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2532,7 +2532,7 @@ void debug_sub_808C964() "._211:\n" " .word gUnknown_Debug_083C2190\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2579,7 +2579,7 @@ void debug_sub_808C9BC() "._213:\n" " .word gUnknown_Debug_083C2264\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2626,7 +2626,7 @@ void debug_sub_808CA14() "._215:\n" " .word gUnknown_Debug_083C2370\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2673,7 +2673,7 @@ void debug_sub_808CA6C() "._217:\n" " .word gUnknown_Debug_083C248C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2720,7 +2720,7 @@ void debug_sub_808CAC4() "._219:\n" " .word gUnknown_Debug_083C259C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2767,7 +2767,7 @@ void debug_sub_808CB1C() "._221:\n" " .word gUnknown_Debug_083C26C8\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CB74+1\n" "\n" ); @@ -2961,7 +2961,7 @@ void debug_sub_808CC74() " .align 2, 0\n" "._237:\n" " .word gUnknown_Debug_083C1ADC\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CCC4+1\n" "\n" ); @@ -2998,7 +2998,7 @@ void debug_sub_808CCC4() "._244:\n" " .align 2, 0\n" "._243:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C1ADC\n" "._241:\n" " bl CloseMenu\n" @@ -3051,7 +3051,7 @@ void debug_sub_808CD08() "._245:\n" " .word gUnknown_Debug_083C1B7C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CE10+1\n" "\n" ); @@ -3098,7 +3098,7 @@ void debug_sub_808CD60() "._247:\n" " .word gUnknown_Debug_083C1BF0\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CE10+1\n" "\n" ); @@ -3145,7 +3145,7 @@ void debug_sub_808CDB8() "._249:\n" " .word gUnknown_Debug_083C1C2C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CE10+1\n" "\n" ); @@ -3339,7 +3339,7 @@ void debug_sub_808CF10() " .align 2, 0\n" "._265:\n" " .word gUnknown_Debug_083C1330\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808CF60+1\n" "\n" ); @@ -3376,7 +3376,7 @@ void debug_sub_808CF60() "._272:\n" " .align 2, 0\n" "._271:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C1330\n" "._269:\n" " bl CloseMenu\n" @@ -3429,7 +3429,7 @@ void debug_sub_808CFA4() "._273:\n" " .word gUnknown_Debug_083C13D8\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3476,7 +3476,7 @@ void debug_sub_808CFFC() "._275:\n" " .word gUnknown_Debug_083C1465\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3523,7 +3523,7 @@ void debug_sub_808D054() "._277:\n" " .word gUnknown_Debug_083C1503\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3570,7 +3570,7 @@ void debug_sub_808D0AC() "._279:\n" " .word gUnknown_Debug_083C158A\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3617,7 +3617,7 @@ void debug_sub_808D104() "._281:\n" " .word gUnknown_Debug_083C1647\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3664,7 +3664,7 @@ void debug_sub_808D15C() "._283:\n" " .word gUnknown_Debug_083C1712\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3711,7 +3711,7 @@ void debug_sub_808D1B4() "._285:\n" " .word gUnknown_Debug_083C17F8\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3758,7 +3758,7 @@ void debug_sub_808D20C() "._287:\n" " .word gUnknown_Debug_083C18B8\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3805,7 +3805,7 @@ void debug_sub_808D264() "._289:\n" " .word gDebug_0x83C1974\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D2BC+1\n" "\n" ); @@ -3999,7 +3999,7 @@ void debug_sub_808D3BC() " .align 2, 0\n" "._305:\n" " .word gUnknown_Debug_083C105C\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D40C+1\n" "\n" ); @@ -4036,7 +4036,7 @@ void debug_sub_808D40C() "._312:\n" " .align 2, 0\n" "._311:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C105C\n" "._309:\n" " bl CloseMenu\n" @@ -4089,7 +4089,7 @@ void debug_sub_808D450() "._313:\n" " .word gUnknown_Debug_083C10BD\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D500+1\n" "\n" ); @@ -4136,7 +4136,7 @@ void debug_sub_808D4A8() "._315:\n" " .word gUnknown_Debug_083C1149\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D500+1\n" "\n" ); @@ -4330,7 +4330,7 @@ void debug_sub_808D600() " .align 2, 0\n" "._331:\n" " .word gUnknown_Debug_083C11CC\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D650+1\n" "\n" ); @@ -4367,7 +4367,7 @@ void debug_sub_808D650() "._338:\n" " .align 2, 0\n" "._337:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C11CC\n" "._335:\n" " bl CloseMenu\n" @@ -4420,7 +4420,7 @@ void debug_sub_808D694() "._339:\n" " .word gUnknown_Debug_083C1212\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D744+1\n" "\n" ); @@ -4467,7 +4467,7 @@ void debug_sub_808D6EC() "._341:\n" " .word gUnknown_Debug_083C1288\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D744+1\n" "\n" ); @@ -4661,7 +4661,7 @@ void debug_sub_808D844() " .align 2, 0\n" "._357:\n" " .word gUnknown_Debug_083C1A78\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D894+1\n" "\n" ); @@ -4697,7 +4697,7 @@ void debug_sub_808D894() "._364:\n" " .align 2, 0\n" "._363:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C1A78\n" "._361:\n" " bl CloseMenu\n" @@ -4750,7 +4750,7 @@ void debug_sub_808D8D8() "._365:\n" " .word gUnknown_Debug_083C1A9C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808D930+1\n" "\n" ); @@ -4944,7 +4944,7 @@ void debug_sub_808DA30() " .align 2, 0\n" "._381:\n" " .word gUnknown_Debug_083C103A\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DA80+1\n" "\n" ); @@ -5085,7 +5085,7 @@ void debug_sub_808DB0C() " .align 2, 0\n" "._395:\n" " .word gUnknown_Debug_083C3D08\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DB5C+1\n" "\n" ); @@ -5122,7 +5122,7 @@ void debug_sub_808DB5C() "._402:\n" " .align 2, 0\n" "._401:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C3D08\n" "._399:\n" " bl CloseMenu\n" @@ -5175,7 +5175,7 @@ void debug_sub_808DBA0() "._403:\n" " .word gUnknown_Debug_083C432C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5222,7 +5222,7 @@ void debug_sub_808DBF8() "._405:\n" " .word gUnknown_Debug_083C436C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5269,7 +5269,7 @@ void debug_sub_808DC50() "._407:\n" " .word gUnknown_Debug_083C43B4\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5316,7 +5316,7 @@ void debug_sub_808DCA8() "._409:\n" " .word gUnknown_Debug_083C43FC\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5363,7 +5363,7 @@ void debug_sub_808DD00() "._411:\n" " .word gUnknown_Debug_083C4444\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5410,7 +5410,7 @@ void debug_sub_808DD58() "._413:\n" " .word gUnknown_Debug_083C448C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5457,7 +5457,7 @@ void debug_sub_808DDB0() "._415:\n" " .word gUnknown_Debug_83C44C4\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5504,7 +5504,7 @@ void debug_sub_808DE08() "._417:\n" " .word gUnknown_Debug_83C44EC\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5551,7 +5551,7 @@ void debug_sub_808DE60() "._419:\n" " .word gUnknown_Debug_083C4534\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808DEB8+1\n" "\n" ); @@ -5754,7 +5754,7 @@ void debug_sub_808DFC0() " .align 2, 0\n" "._437:\n" " .word gUnknown_Debug_083C377C\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E010+1\n" "\n" ); @@ -5791,7 +5791,7 @@ void debug_sub_808E010() "._444:\n" " .align 2, 0\n" "._443:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C377C\n" "._441:\n" " bl CloseMenu\n" @@ -5844,7 +5844,7 @@ void debug_sub_808E054() "._445:\n" " .word gUnknown_Debug_083C3AA0\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E264+1\n" "\n" ); @@ -5891,7 +5891,7 @@ void debug_sub_808E0AC() "._447:\n" " .word gUnknown_Debug_83C3AE0\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E264+1\n" "\n" ); @@ -5938,7 +5938,7 @@ void debug_sub_808E104() "._449:\n" " .word gUnknown_Debug_83C3B28\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E264+1\n" "\n" ); @@ -5985,7 +5985,7 @@ void debug_sub_808E15C() "._451:\n" " .word gUnknown_Debug_83C3B70\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E264+1\n" "\n" ); @@ -6032,7 +6032,7 @@ void debug_sub_808E1B4() "._453:\n" " .word gUnknown_Debug_83C3BB8\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E264+1\n" "\n" ); @@ -6079,7 +6079,7 @@ void debug_sub_808E20C() "._455:\n" " .word gUnknown_Debug_83C3C00\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E264+1\n" "\n" ); @@ -6282,7 +6282,7 @@ void debug_sub_808E36C() " .align 2, 0\n" "._473:\n" " .word gUnknown_Debug_083C32AC\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E3BC+1\n" "\n" ); @@ -6319,7 +6319,7 @@ void debug_sub_808E3BC() "._480:\n" " .align 2, 0\n" "._479:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C32AC\n" "._477:\n" " bl CloseMenu\n" @@ -6372,7 +6372,7 @@ void debug_sub_808E400() "._481:\n" " .word gUnknown_Debug_083C347C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E5B8+1\n" "\n" ); @@ -6419,7 +6419,7 @@ void debug_sub_808E458() "._483:\n" " .word gUnknown_Debug_083C3494\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E5B8+1\n" "\n" ); @@ -6466,7 +6466,7 @@ void debug_sub_808E4B0() "._485:\n" " .word gUnknown_Debug_083C34A4\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E5B8+1\n" "\n" ); @@ -6513,7 +6513,7 @@ void debug_sub_808E508() "._487:\n" " .word gUnknown_Debug_083C34D4\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E5B8+1\n" "\n" ); @@ -6560,7 +6560,7 @@ void debug_sub_808E560() "._489:\n" " .word gUnknown_Debug_083C351C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E5B8+1\n" "\n" ); @@ -6763,7 +6763,7 @@ void debug_sub_808E6C0() " .align 2, 0\n" "._507:\n" " .word gUnknown_Debug_083C4644\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E710+1\n" "\n" ); @@ -6800,7 +6800,7 @@ void debug_sub_808E710() "._514:\n" " .align 2, 0\n" "._513:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C4644\n" "._511:\n" " bl CloseMenu\n" @@ -6853,7 +6853,7 @@ void debug_sub_808E754() "._515:\n" " .word gUnknown_Debug_083C470C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E804+1\n" "\n" ); @@ -6900,7 +6900,7 @@ void debug_sub_808E7AC() "._517:\n" " .word gUnknown_Debug_083C4754C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E804+1\n" "\n" ); @@ -7103,7 +7103,7 @@ void debug_sub_808E90C() " .align 2, 0\n" "._535:\n" " .word gUnknown_Debug_083C35C4\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808E95C+1\n" "\n" ); @@ -7140,7 +7140,7 @@ void debug_sub_808E95C() "._542:\n" " .align 2, 0\n" "._541:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word gUnknown_Debug_083C35C4\n" "._539:\n" " bl CloseMenu\n" @@ -7193,7 +7193,7 @@ void debug_sub_808E9A0() "._543:\n" " .word gUnknown_Debug_083C369C\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808EA50+1\n" "\n" ); @@ -7240,7 +7240,7 @@ void debug_sub_808E9F8() "._545:\n" " .word gUnknown_Debug_083C36E4\n" " .word gDebug_03000700+0xf\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808EA50+1\n" "\n" ); @@ -7448,7 +7448,7 @@ void debug_sub_808EB58() "._563:\n" " .word gUnknown_Debug_083C47B2\n" " .word gUnknown_Debug_083C47F0\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808EC10+1\n" "\n" ); @@ -7496,7 +7496,7 @@ void debug_sub_808EBB4() "._565:\n" " .word gUnknown_Debug_083C4830\n" " .word gUnknown_Debug_083C4888\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808EC5C+1\n" "\n" ); @@ -7615,7 +7615,7 @@ void debug_sub_808ECA4() "._578:\n" " .align 2, 0\n" "._577:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_808ECD0+1\n" "\n" ); diff --git a/src/debug/unknown_debug_menu.c b/src/debug/unknown_debug_menu.c index 9cece924d..ef3e0e66c 100644 --- a/src/debug/unknown_debug_menu.c +++ b/src/debug/unknown_debug_menu.c @@ -4,7 +4,7 @@ extern u8 gBattleCommunication[]; -extern u8 (*gCallback_03004AE8)(void); +extern u8 (*gMenuCallback)(void); static u8 sub_814A4B8(void); static u8 sub_814A464(void); @@ -36,7 +36,7 @@ int unref_sub_814A414(void) Menu_DrawStdWindowFrame(0, 0, 16, 18); Menu_PrintItems(2, 1, 8, gUnknown_0842C29C); InitMenu(0, 1, 1, 8, 0, 15); - gCallback_03004AE8 = sub_814A464; + gMenuCallback = sub_814A464; return 0; } @@ -55,7 +55,7 @@ static u8 sub_814A464(void) else { gBattleCommunication[0] = result; - gCallback_03004AE8 = gUnknown_0842C29C[result].func; + gMenuCallback = gUnknown_0842C29C[result].func; return 0; } } diff --git a/src/engine/cable_club.c b/src/engine/cable_club.c index d40c31b1b..ed6929638 100644 --- a/src/engine/cable_club.c +++ b/src/engine/cable_club.c @@ -1057,7 +1057,7 @@ static void sub_808382C(u8 taskId) switch (task->data[0]) { case 0: - fade_screen(1, 0); + FadeScreen(1, 0); gLinkType = 0x2211; ClearLinkCallback_2(); task->data[0]++; @@ -1193,7 +1193,7 @@ static void sub_8083AAC(u8 taskId) { case 0: ScriptContext2_Enable(); - fade_screen(1, 0); + FadeScreen(1, 0); ClearLinkCallback_2(); task->data[0]++; break; diff --git a/src/engine/naming_screen.c b/src/engine/naming_screen.c index eddfdeda5..97819322c 100644 --- a/src/engine/naming_screen.c +++ b/src/engine/naming_screen.c @@ -258,20 +258,7 @@ static void NamingScreen_InitDisplayMode(void) static void NamingScreen_ClearVram(void) { - u8 *addr = (void *)VRAM; - u32 size = 0x10000; - - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } + DmaFill16Large(3, 0, (void *)VRAM, 0x10000, 0x1000); } static void NamingScreen_ClearOam(void) @@ -1629,16 +1616,8 @@ static void sub_80B7558(void) static void sub_80B7568(void) { - const void *src; - void *dst; - - src = gNamingScreenMenu_Gfx; - dst = (void *)(VRAM + gMenuMessageBoxContentTileOffset * 32); - DmaCopy16(3, src, dst, 0x800); - - src = gNamingScreenMenu_Gfx; - dst = (void *)(VRAM + 0x8000 + gMenuMessageBoxContentTileOffset * 32); - DmaCopy16(3, src, dst, 0x800); + DmaCopy16Defvars(3, gNamingScreenMenu_Gfx, (void *)(VRAM + gMenuMessageBoxContentTileOffset * 32), 0x800); + DmaCopy16Defvars(3, gNamingScreenMenu_Gfx, (void *)(VRAM + 0x8000 + gMenuMessageBoxContentTileOffset * 32), 0x800); } static void sub_80B75B0(void) diff --git a/src/engine/option_menu.c b/src/engine/option_menu.c index 1fc78efaa..d4e921a0e 100644 --- a/src/engine/option_menu.c +++ b/src/engine/option_menu.c @@ -76,9 +76,6 @@ void CB2_InitOptionMenu(void) default: case 0: { - u8 *addr; - u32 size; - SetVBlankCallback(NULL); REG_DISPCNT = 0; REG_BG2CNT = 0; @@ -90,19 +87,7 @@ void CB2_InitOptionMenu(void) REG_BG1VOFS = 0; REG_BG0HOFS = 0; REG_BG0VOFS = 0; - addr = (u8 *)VRAM; - size = 0x18000; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } + DmaFill16Large(3, 0, (u8 *)VRAM, 0x18000, 0x1000); DmaClear32(3, OAM, OAM_SIZE); DmaClear16(3, PLTT, PLTT_SIZE); gMain.state++; diff --git a/src/engine/palette.c b/src/engine/palette.c index 17e9ca178..2a6602503 100644 --- a/src/engine/palette.c +++ b/src/engine/palette.c @@ -827,8 +827,6 @@ void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color) void BlendPalettesUnfaded(u32 selectedPalettes, u8 coeff, u16 color) { - void *src = gPlttBufferUnfaded; - void *dest = gPlttBufferFaded; - DmaCopy32(3, src, dest, PLTT_SIZE); + DmaCopy32Defvars(3, gPlttBufferUnfaded, gPlttBufferFaded, PLTT_SIZE); BlendPalettes(selectedPalettes, coeff, color); } diff --git a/src/engine/reset_rtc_screen.c b/src/engine/reset_rtc_screen.c index cda73f96b..45cde2cc0 100644 --- a/src/engine/reset_rtc_screen.c +++ b/src/engine/reset_rtc_screen.c @@ -421,28 +421,10 @@ void Task_ResetRtc_0(u8 taskId) void CB2_InitResetRtcScreen(void) { - u8 *addr; - u32 size; - REG_DISPCNT = 0; SetVBlankCallback(NULL); - DmaClear16(3, PLTT, PLTT_SIZE); - - addr = (u8 *)VRAM; - size = 0x18000; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } - + DmaFill16Large(3, 0, (u8 *)VRAM, 0x18000, 0x1000); ResetOamRange(0, 128); LoadOam(); ScanlineEffect_Stop(); diff --git a/src/engine/save.c b/src/engine/save.c index de5fd2846..8217652f9 100644 --- a/src/engine/save.c +++ b/src/engine/save.c @@ -751,8 +751,8 @@ u8 Save_WriteDataInternal(u8 saveType) EraseFlashSector(i); // fall through case SAVE_HALL_OF_FAME: // hall of fame. - if (GetGameStat(10) < 999) - IncrementGameStat(10); + if (GetGameStat(GAME_STAT_ENTERED_HOF) < 999) + IncrementGameStat(GAME_STAT_ENTERED_HOF); for (i = 0; i < NUM_HALL_OF_FAME_SECTORS; i++) HandleWriteSectorNBytes(HALL_OF_FAME_SECTOR + i, sHallOfFameChunks[i].data, sHallOfFameChunks[i].size); SaveSerializedGame(); diff --git a/src/engine/sprite.c b/src/engine/sprite.c index eaffedfdc..df8c66750 100644 --- a/src/engine/sprite.c +++ b/src/engine/sprite.c @@ -827,7 +827,7 @@ void ProcessSpriteCopyRequests(void) #if DEBUG else { - unref_sub_80AB084(sDmaOverErrorMsg); + Crash(sDmaOverErrorMsg); } #endif } @@ -844,7 +844,7 @@ void RequestSpriteCopy(const void *src, u8 *dest, u16 size) #if DEBUG else { - unref_sub_80AB084(sDmaOverErrorMsg); + Crash(sDmaOverErrorMsg); } #endif } diff --git a/src/engine/task.c b/src/engine/task.c index d1f2cb5df..3e8a5588c 100644 --- a/src/engine/task.c +++ b/src/engine/task.c @@ -52,7 +52,7 @@ u8 CreateTask(TaskFunc func, u8 priority) } #if DEBUG - unref_sub_80AB084(gError_NoTasksLeft); + Crash(gError_NoTasksLeft); #endif return 0; diff --git a/src/engine/time_events.c b/src/engine/time_events.c index 3e3054aa3..4bd732788 100644 --- a/src/engine/time_events.c +++ b/src/engine/time_events.c @@ -93,7 +93,7 @@ void UpdateShoalTideFlag(void) static void Task_WaitWeather(u8 taskId) { - if (sub_807DDFC()) + if (IsWeatherChangeComplete()) { EnableBothScriptContexts(); DestroyTask(taskId); diff --git a/src/engine/trade.c b/src/engine/trade.c index 715cc0377..c878f62db 100644 --- a/src/engine/trade.c +++ b/src/engine/trade.c @@ -1455,9 +1455,7 @@ static void sub_8048AB4(void) static void sub_8048B0C(u8 a0) { int i; - u16 *dest; - const u16 *src; - u32 size; + switch (a0) { case 0: @@ -1466,30 +1464,13 @@ static void sub_8048B0C(u8 a0) gPlttBufferUnfaded[i] = *(gUnknown_08EA02C8 + i); gPlttBufferFaded[i] = *(gUnknown_08EA02C8 + i); } - src = gUnknown_08EA0348; - dest = (u16 *)BG_VRAM; - size = 0x1280; - while (1) - { - DmaCopy16(3, src, dest, BLOCKSIZE * sizeof(u16)); - src += BLOCKSIZE; - dest += BLOCKSIZE; - size -= BLOCKSIZE * sizeof(u16); - if (size <= BLOCKSIZE * sizeof(u16)) - { - DmaCopy16(3, src, dest, size); - break; - } - } + DmaCopyLarge16(3, gUnknown_08EA0348, (void *)BG_VRAM, 0x1280, 0x1000); for (i = 0; i < 0x400; i ++) gUnknown_03004824->unk_00c8.unk_12[i] = gUnknown_08EA15C8[i]; - dest = BG_SCREEN_ADDR(6); - DmaCopy16(3, gTradeStripesBG2Tilemap, dest, 0x800); + DmaCopy16Defvars(3, gTradeStripesBG2Tilemap, BG_SCREEN_ADDR(6), 0x800); break; case 1: - src = gTradeStripesBG3Tilemap; - dest = BG_SCREEN_ADDR(7); - DmaCopy16(3, src, dest, 0x800); + DmaCopy16Defvars(3, gTradeStripesBG3Tilemap, BG_SCREEN_ADDR(7), 0x800); sub_804A6DC(0); sub_804A6DC(1); sub_804A938(&gUnknown_03004824->unk_00c8); @@ -5703,13 +5684,9 @@ static void sub_804E1DC(void) void sub_804E22C(void) { - const u16 *src; - u16 *dest; LZDecompressVram(gUnknown_08D00000, (void *)VRAM); CpuCopy16(gUnknown_08D00524, gSharedMem, 0x1000); - src = (const u16 *)gSharedMem; - dest = BG_SCREEN_ADDR(5); - DmaCopy16(3, src, dest, 0x500) + DmaCopy16Defvars(3, gSharedMem, BG_SCREEN_ADDR(5), 0x500); LoadCompressedPalette(gUnknown_08D004E0, 0, 32); REG_BG1CNT = BGCNT_PRIORITY(2) | BGCNT_SCREENBASE(5); } diff --git a/src/engine/trainer_card.c b/src/engine/trainer_card.c index f9adc5777..998c4697e 100644 --- a/src/engine/trainer_card.c +++ b/src/engine/trainer_card.c @@ -506,27 +506,12 @@ static void sub_8093550(void) void sub_8093598(void) { - u8 *addr = (void *)VRAM; - u32 size = 0x10000; - - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } + DmaFill16Large(3, 0, (void *)VRAM, 0x10000, 0x1000); } void sub_80935EC(void) { - void *addr = (void *)OAM; - - DmaFill16(3, 0, addr, 0x400); + DmaFill16Defvars(3, 0, (void *)OAM, 0x400); } void sub_8093610(void) @@ -1252,33 +1237,10 @@ static void TrainerCard_ResetOffsetRegisters(void) static void TrainerCard_CopyGraphics(void) { - const u8 *src; - u8 *dst; - u32 size; - TrainerCard_LoadPalettes(); LoadPalette(gUnknown_083B5F6C, 0xE0, 32); - src = gMenuTrainerCard_Gfx; - dst = (void *)VRAM; - size = 0x1480; - while (1) - { - DmaCopy16(3, src, dst, 0x1000); - src += 0x1000; - dst += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaCopy16(3, src, dst, size); - break; - } - } - { - const void *src = gBadgesTiles; - void *dst = (void *)(VRAM + 0x1480); - - DmaCopy16(3, src, dst, 0x400); - } + DmaCopyLarge16(3, gMenuTrainerCard_Gfx, (void *)VRAM, 0x1480, 0x1000); + DmaCopy16Defvars(3, gBadgesTiles, (void *)(VRAM + 0x1480), 0x400); } extern const u16 *const gTrainerCardPalettes[]; diff --git a/src/field/berry_tag_screen.c b/src/field/berry_tag_screen.c index 56d578464..ed0ab86ae 100644 --- a/src/field/berry_tag_screen.c +++ b/src/field/berry_tag_screen.c @@ -93,7 +93,7 @@ static bool8 sub_8146058(void) switch (gMain.state) { case 0: - sub_80F9438(); + ClearVideoCallbacks(); sub_80F9368(); sub_8146288(); REG_BLDCNT = 0; @@ -189,7 +189,6 @@ static void sub_8146288(void) bool8 sub_81462B8(void) { u16 i; - void *addr; switch (gSharedMem.var_1FFFF) { @@ -213,8 +212,7 @@ bool8 sub_81462B8(void) else gBGTilemapBuffers[2][i] = 0x5042; } - addr = (void *)(VRAM + 0x3800); - DmaCopy16(3, gBGTilemapBuffers[2], addr, 0x800); + DmaCopy16Defvars(3, gBGTilemapBuffers[2], (void *)(VRAM + 0x3800), 0x800); gSharedMem.var_1FFFF += 1; break; case 4: diff --git a/src/field/choose_party.c b/src/field/choose_party.c index b108ede5a..fd5808fc3 100644 --- a/src/field/choose_party.c +++ b/src/field/choose_party.c @@ -1031,7 +1031,7 @@ void sub_81231AC(void) static void sub_81231C4(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { DestroyTask(taskId); ScriptContext2_Disable(); diff --git a/src/field/coord_event_weather.c b/src/field/coord_event_weather.c index db4e9c161..60b87fa30 100644 --- a/src/field/coord_event_weather.c +++ b/src/field/coord_event_weather.c @@ -34,7 +34,7 @@ static const struct CoordEventWeather sCoordEventWeatherFuncs[] = { COORD_EVENT_WEATHER_FOG_2, CoordEventWeather_DiagonalFog }, { COORD_EVENT_WEATHER_ASH, CoordEventWeather_Ash }, { COORD_EVENT_WEATHER_SANDSTORM, CoordEventWeather_Sandstorm }, - { COORD_EVENT_WEATHER_DARK, CoordEventWeather_Dark }, + { COORD_EVENT_WEATHER_SHADE, CoordEventWeather_Dark }, { COORD_EVENT_WEATHER_DROUGHT, CoordEventWeather_Drought }, { COORD_EVENT_WEATHER_ROUTE119_CYCLE, CoordEventWeather_Route119Cycle }, { COORD_EVENT_WEATHER_ROUTE123_CYCLE, CoordEventWeather_Route123Cycle }, @@ -87,7 +87,7 @@ static void CoordEventWeather_Sandstorm(void) static void CoordEventWeather_Dark(void) { - SetWeather(WEATHER_DARK); + SetWeather(WEATHER_SHADE); } static void CoordEventWeather_Drought(void) diff --git a/src/field/decoration.c b/src/field/decoration.c index a6c0bd21f..0e7fa5f41 100644 --- a/src/field/decoration.c +++ b/src/field/decoration.c @@ -19,6 +19,7 @@ #include "event_data.h" #include "field_weather.h" #include "decoration.h" +#include "shop.h" #include "ewram.h" EWRAM_DATA u8 *gUnknown_020388D0 = NULL; @@ -1614,7 +1615,7 @@ void sub_80FE604(u8 taskId) sub_8134104(gUnknown_020388F6); gUnknown_020388D0 = gDecorationInventories[gUnknown_020388F6].items; sub_80FEF50(taskId); - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); sub_80F9480(gUnknown_020388F7, 8); LoadScrollIndicatorPalette(); gTasks[taskId].func = sub_80FE868; @@ -1659,7 +1660,7 @@ void sub_80FE758(u8 taskId) gTasks[taskId].func = Task_DecorationPCProcessMenuInput; } else { - sub_80B3068(taskId); + Shop_RunExitSellMenuTask(taskId); } } @@ -1783,17 +1784,17 @@ void sub_80FEABC(u8 taskId, u8 dummy1) u16 i; u16 j; u8 ni; - if (gUnknown_020388F4 != 0 || (DestroyVerticalScrollIndicator(0), gUnknown_020388F4 != 0)) + if (gUnknown_020388F4 != 0 || (DestroyVerticalScrollIndicator(TOP_ARROW), gUnknown_020388F4 != 0)) { - CreateVerticalScrollIndicators(0, 0x3c, 0x08); + CreateVerticalScrollIndicators(TOP_ARROW, 0x3c, 0x08); } if (gUnknown_020388F4 + 7 == gUnknown_020388D5) { - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } if (gUnknown_020388F4 + 7 < gUnknown_020388D5) { - CreateVerticalScrollIndicators(1, 0x3c, 0x98); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0x3c, 0x98); } for (i=gUnknown_020388F4; i<gUnknown_020388F4+8; i++) { @@ -2003,8 +2004,8 @@ void sub_80FEF50(u8 taskId) void sub_80FEF74(void) { sub_80F9520(gUnknown_020388F7, 8); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); Menu_DestroyCursor(); Menu_EraseWindowRect(0, 0, 14, 19); } @@ -2043,8 +2044,8 @@ void sub_80FF034(u8 taskId) void sub_80FF058(u8 taskId) { sub_80F9520(gUnknown_020388F7, 8); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); BuyMenuFreeMemory(); gTasks[taskId].func = sub_80FF034; } @@ -2238,7 +2239,7 @@ void sub_80FF5BC(u8 taskId) { if (sub_80FF58C() == TRUE) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_80FF6AC; } else @@ -2271,8 +2272,8 @@ void sub_80FF6AC(u8 taskId) if (!gPaletteFade.active) { sub_80FF0E0(taskId); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); sub_80F9520(gUnknown_020388F7, 8); BuyMenuFreeMemory(); gTasks[taskId].data[2] = 1; @@ -2288,7 +2289,7 @@ void sub_80FF6AC(u8 taskId) gTasks[taskId].data[2] = 2; break; case 2: - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].data[12] = 0; sub_810065C(taskId); @@ -3192,7 +3193,7 @@ void sub_810026C(u8 taskId) void sub_810028C(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = c1_overworld_prev_quest; } @@ -3221,7 +3222,7 @@ void c1_overworld_prev_quest(u8 taskId) void sub_8100334(u8 taskId) { - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].func = sub_80FE948; } @@ -3628,7 +3629,7 @@ void sub_8100A0C(u8 taskId) { if (sub_8100D38(taskId) == 1) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8100E70; } else @@ -3734,7 +3735,7 @@ void sub_8100C88(u8 taskId) gTasks[taskId].data[2] = 3; break; case 3: - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].data[13] = -1; DisplayItemMessageOnField(taskId, gSecretBaseText_DecorReturned, sub_81010F0, 0); @@ -3799,7 +3800,7 @@ void sub_8100E70(u8 taskId) data[2] = 2; break; case 2: - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { data[12] = 1; sub_8100EEC(taskId); @@ -4137,7 +4138,7 @@ void sub_8101518(u8 taskId) void sub_810153C(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_8100C88; } @@ -4156,7 +4157,7 @@ void sub_8101590(u8 taskId) void sub_81015B0(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); gTasks[taskId].data[2] = 0; gTasks[taskId].func = sub_81015E0; } @@ -4183,7 +4184,7 @@ void sub_81015E0(u8 taskId) void sub_8101648(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { gTasks[taskId].func = Task_DecorationPCProcessMenuInput; } diff --git a/src/field/diploma.c b/src/field/diploma.c index 978eca7eb..b31fc7dec 100644 --- a/src/field/diploma.c +++ b/src/field/diploma.c @@ -125,7 +125,7 @@ static void Task_DiplomaFadeOut(u8 taskId) static void DisplayDiplomaText(void) { - if (sub_8090FF4()) + if (CompletedNationalPokedex()) { REG_BG3HOFS = 256; StringCopy(gStringVar1, gOtherText_NationalDex); diff --git a/src/field/field_control_avatar.c b/src/field/field_control_avatar.c index dad2fb1d2..9ac5ae11d 100644 --- a/src/field/field_control_avatar.c +++ b/src/field/field_control_avatar.c @@ -620,7 +620,7 @@ int sub_8068024(struct FieldInput *input) return TRUE; if (input->input_field_0_6) { - IncrementGameStat(5); + IncrementGameStat(GAME_STAT_STEPS); if (sub_80687E4(&position, r4, r6) == 1) return TRUE; } @@ -1207,20 +1207,19 @@ static u8 *trigger_activate(struct CoordEvent *coordEvent) return NULL; } -static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 x, u16 y, u8 d) +static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 x, u16 y, u8 elevation) { s32 i; struct CoordEvent *coordEvents = mapHeader->events->coordEvents; u8 coordEventCount = mapHeader->events->coordEventCount; - u8 *script; for (i = 0; i < coordEventCount; i++) { if ((u16)coordEvents[i].x == x && (u16)coordEvents[i].y == y) { - if (coordEvents[i].unk4 == d || coordEvents[i].unk4 == 0) + if (coordEvents[i].elevation == elevation || coordEvents[i].elevation == 0) { - script = trigger_activate(&coordEvents[i]); + u8 *script = trigger_activate(&coordEvents[i]); if (script != NULL) return script; } diff --git a/src/field/field_effect.c b/src/field/field_effect.c index 5ff89574b..ad570cf7f 100644 --- a/src/field/field_effect.c +++ b/src/field/field_effect.c @@ -407,7 +407,7 @@ void FieldEffectScript_LoadFadedPalette(u8 **script) { struct SpritePalette *palette = (struct SpritePalette *)FieldEffectScript_ReadWord(script); LoadSpritePalette(palette); - sub_807D78C(IndexOfSpritePaletteTag(palette->tag)); + UpdateSpritePaletteWithWeather(IndexOfSpritePaletteTag(palette->tag)); (*script) += 4; } @@ -543,7 +543,7 @@ u8 CreateMonSprite_PicBox(u16 species, s16 x, s16 y, u8 subpriority) LoadCompressedObjectPalette(&gMonPaletteTable[species]); GetMonSpriteTemplate_803C56C(species, 3); gUnknown_02024E8C.paletteTag = gMonPaletteTable[0].tag; - sub_807DE38(IndexOfSpritePaletteTag(gMonPaletteTable[0].tag) + 0x10); + PreservePaletteInWeather(IndexOfSpritePaletteTag(gMonPaletteTable[0].tag) + 0x10); return CreateSprite(&gUnknown_02024E8C, x, y, subpriority); } @@ -556,13 +556,13 @@ u8 CreateMonSprite_FieldMove(u16 species, u32 d, u32 g, s16 x, s16 y, u8 subprio LoadCompressedObjectPalette(spritePalette); GetMonSpriteTemplate_803C56C(species, 3); gUnknown_02024E8C.paletteTag = spritePalette->tag; - sub_807DE38(IndexOfSpritePaletteTag(spritePalette->tag) + 0x10); + PreservePaletteInWeather(IndexOfSpritePaletteTag(spritePalette->tag) + 0x10); return CreateSprite(&gUnknown_02024E8C, x, y, subpriority); } void FreeResourcesAndDestroySprite(struct Sprite *sprite) { - sub_807DE68(); + ResetPreservedPalettesInWeather(); FreeSpritePaletteByTag(GetSpritePaletteTagByPaletteNum(sprite->oam.paletteNum)); if (sprite->oam.affineMode != 0) { @@ -1091,7 +1091,7 @@ void task00_8084310(u8 taskId) task = &gTasks[taskId]; if (!task->data[0]) { - if (!sub_807D770()) + if (!IsWeatherNotFadingIn()) { return; } @@ -1191,7 +1191,7 @@ bool8 sub_80867AC(struct Task *task) // gUnknown_0839F2CC[0] bool8 sub_8086854(struct Task *task) // gUnknown_0839F2CC[1] { - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { task->data[0]++; } @@ -1813,7 +1813,7 @@ bool8 sub_80874CC(struct Task *task, struct MapObject *mapObject, struct Sprite bool8 sub_80874FC(struct Task *task, struct MapObject *mapObject, struct Sprite *sprite) { - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { gFieldEffectArguments[0] = mapObject->coords2.x; gFieldEffectArguments[1] = mapObject->coords2.y; @@ -2046,7 +2046,7 @@ void sub_8087A74(u8 taskId) void sub_8087AA4(struct Task *task) { - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { task->data[0]++; task->data[15] = player_get_direction_lower_nybble(); @@ -2199,7 +2199,7 @@ void sub_8087E4C(struct Task *task) { struct Sprite *sprite; s16 centerToCornerVecY; - if (sub_807D770()) + if (IsWeatherNotFadingIn()) { sprite = &gSprites[gPlayerAvatar.spriteId]; centerToCornerVecY = -(sprite->centerToCornerVecY << 1); diff --git a/src/field/field_effect_helpers.c b/src/field/field_effect_helpers.c index e2514df90..c9d337de1 100644 --- a/src/field/field_effect_helpers.c +++ b/src/field/field_effect_helpers.c @@ -93,7 +93,7 @@ static void npc_pal_op_B(struct MapObject *mapObject, u8 paletteNum) { pal_patch_for_npc(npc_paltag_by_palslot(paletteNum), paletteNum); } - sub_807D78C(paletteNum); + UpdateSpritePaletteWithWeather(paletteNum); } } @@ -105,7 +105,7 @@ static void npc_pal_op_A(struct MapObject *mapObject, u8 paletteNum) if (graphicsInfo->paletteTag2 != 0x11ff) { pal_patch_for_npc(graphicsInfo->paletteTag2, paletteNum); - sub_807D78C(paletteNum); + UpdateSpritePaletteWithWeather(paletteNum); } } diff --git a/src/field/field_fadetransition.c b/src/field/field_fadetransition.c index 6d40c53aa..16ba50e4b 100644 --- a/src/field/field_fadetransition.c +++ b/src/field/field_fadetransition.c @@ -44,18 +44,18 @@ void pal_fill_for_map_transition(void) switch (fade_type_for_given_maplight_pair(map_light, Overworld_GetMapTypeOfSaveblockLocation())) { case 0: - fade_screen(0, 0); + FadeScreen(0, 0); palette_bg_fill_black(); break; case 1: - fade_screen(2, 0); + FadeScreen(2, 0); palette_bg_fill_white(); } } void pal_fill_black(void) { - fade_screen(0, 0); + FadeScreen(0, 0); palette_bg_fill_black(); } @@ -65,10 +65,10 @@ void fade_8080918(void) switch (sub_810CDB8(light_level, warp1_get_mapheader()->mapType)) { case 0: - fade_screen(1, 0); + FadeScreen(1, 0); break; case 1: - fade_screen(3, 0); + FadeScreen(3, 0); } } @@ -366,7 +366,7 @@ bool32 sub_8080E64(void) bool32 sub_8080E70(void) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) return TRUE; else return FALSE; @@ -483,7 +483,7 @@ void sub_8081050(u8 taskId) { case 0: ClearLinkCallback_2(); - fade_screen(1, 0); + FadeScreen(1, 0); sub_8053FF8(); PlaySE(SE_KAIDAN); data[0]++; diff --git a/src/field/field_player_avatar.c b/src/field/field_player_avatar.c index 795a53d0b..85cfdb829 100644 --- a/src/field/field_player_avatar.c +++ b/src/field/field_player_avatar.c @@ -615,7 +615,7 @@ u8 CheckForFieldObjectCollision(struct MapObject *a, s16 x, s16 y, u8 direction, return 5; if (ShouldJumpLedge(x, y, direction)) { - IncrementGameStat(0x2B); + IncrementGameStat(GAME_STAT_JUMPED_DOWN_LEDGES); return COLLISION_LEDGE_JUMP; } if (collision == 4 && sub_8058F6C(x, y, direction)) diff --git a/src/field/field_specials.c b/src/field/field_specials.c index aade7cffd..e56d9ddbb 100644 --- a/src/field/field_specials.c +++ b/src/field/field_specials.c @@ -1061,7 +1061,7 @@ static void sub_810E874(void) Menu_DrawStdWindowFrame(0, 0, 8, 11); InitMenu(0, 1, 1, 5, 0, 7); gUnknown_0203925C = 0; - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); sub_810ECD4(); } @@ -1283,7 +1283,7 @@ void sub_810EB90(u8 newPos, u8 maxItems) if (newPos == 0) { gUnknown_0203925C ^= 0x02; - DestroyVerticalScrollIndicator(0); + DestroyVerticalScrollIndicator(TOP_ARROW); } else { @@ -1296,7 +1296,7 @@ void sub_810EB90(u8 newPos, u8 maxItems) else if (newPos + maxItems == gUnknown_0203925A) { gUnknown_0203925C ^= 0x01; - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } } @@ -1347,7 +1347,7 @@ void sub_810ECB0(void) if (gUnknown_0203925C >> 1 != 1) { gUnknown_0203925C |= 0x2; - CreateVerticalScrollIndicators(0, 0x24, 0x08); + CreateVerticalScrollIndicators(TOP_ARROW, 0x24, 0x08); } } @@ -1356,7 +1356,7 @@ void sub_810ECD4(void) if ((gUnknown_0203925C & 1) == 0) { gUnknown_0203925C |= 0x1; - CreateVerticalScrollIndicators(1, 0x24, 0x48); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0x24, 0x48); } } @@ -1428,11 +1428,11 @@ void sub_810EEDC(void) { if ((gUnknown_0203925C & 1) != 0) { - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } if ((gUnknown_0203925C >> 1) == 1) { - DestroyVerticalScrollIndicator(0); + DestroyVerticalScrollIndicator(TOP_ARROW); } BuyMenuFreeMemory(); } @@ -1542,7 +1542,7 @@ void ShowGlassWorkshopMenu(void) Menu_DrawStdWindowFrame(0, 0, 10, 11); InitMenu(0, 1, 1, 5, 0, 9); gUnknown_0203925C = 0; - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); sub_810F2B4(); for (i=0; i<5; i++) @@ -1721,7 +1721,7 @@ void sub_810F290(void) if (gUnknown_0203925C >> 1 != 1) { gUnknown_0203925C |= 0x02; - CreateVerticalScrollIndicators(0, 0x2c, 0x08); + CreateVerticalScrollIndicators(TOP_ARROW, 0x2c, 0x08); } } @@ -1730,7 +1730,7 @@ void sub_810F2B4(void) if (!(gUnknown_0203925C & 0x01)) { gUnknown_0203925C |= 0x01; - CreateVerticalScrollIndicators(1, 0x2c, 0x58); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0x2c, 0x58); } } @@ -1739,7 +1739,7 @@ void GlassWorkshopUpdateScrollIndicators(u8 newPos, u8 maxItems) if (newPos == 0) { gUnknown_0203925C ^= 0x02; - DestroyVerticalScrollIndicator(0); + DestroyVerticalScrollIndicator(TOP_ARROW); } else { @@ -1752,7 +1752,7 @@ void GlassWorkshopUpdateScrollIndicators(u8 newPos, u8 maxItems) else if (newPos + maxItems == gUnknown_0203925A) { gUnknown_0203925C ^= 0x01; - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } } diff --git a/src/field/field_weather.c b/src/field/field_weather.c index 4a03322d5..cf96b2e87 100644 --- a/src/field/field_weather.c +++ b/src/field/field_weather.c @@ -13,7 +13,13 @@ #include "trig.h" #include "ewram.h" -#define MACRO1(a) ((((a) >> 1) & 0xF) | (((a) >> 2) & 0xF0) | (((a) >> 3) & 0xF00)) +#define MACRO1(color) ((((color) >> 1) & 0xF) | (((color) >> 2) & 0xF0) | (((color) >> 3) & 0xF00)) + +enum { + GAMMA_NONE, + GAMMA_NORMAL, + GAMMA_ALT, +}; struct RGBColor { @@ -24,7 +30,7 @@ struct RGBColor struct WeatherPaletteData { - u16 data[0][0x1000]; // unknown length + u16 gammaShiftColors[8][0x1000]; // 0x1000 is the number of bytes that make up all palettes. }; struct WeatherCallbacks @@ -36,10 +42,10 @@ struct WeatherCallbacks }; EWRAM_DATA struct Weather gWeather = {0}; -EWRAM_DATA u8 gUnknown_0202FF38[32] = {0}; +EWRAM_DATA u8 gFieldEffectPaletteGammaTypes[32] = {0}; EWRAM_DATA u16 gUnknown_0202FF58 = {0}; -static const u8 *gUnknown_030006DC; +static const u8 *sPaletteGammaTypes; const u8 DroughtPaletteData_0[] = INCBIN_U8("graphics/weather/drought0.bin.lz"); const u8 DroughtPaletteData_1[] = INCBIN_U8("graphics/weather/drought1.bin.lz"); @@ -56,7 +62,7 @@ static const u8 *const sCompressedDroughtPalettes[] = DroughtPaletteData_3, DroughtPaletteData_4, DroughtPaletteData_5, - gSharedMem, + (u8*)eDroughtPaletteData.gammaShiftColors, }; // This is a pointer to gWeather. All code in this file accesses gWeather directly, @@ -65,6 +71,18 @@ static const u8 *const sCompressedDroughtPalettes[] = // this file produces the same result as accessing gWeather directly. struct Weather *const gWeatherPtr = &gWeather; +static bool8 LightenSpritePaletteInFog(u8); +static void BuildGammaShiftTables(void); +static void UpdateWeatherGammaShift(void); +static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex); +static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor); +static void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor); +static void ApplyFogBlend(u8 blendCoeff, u16 blendColor); +static bool8 FadeInScreen_RainShowShade(void); +static bool8 FadeInScreen_Drought(void); +static bool8 FadeInScreen_Fog1(void); +static void FadeInScreenWithWeather(void); +static void DoNothing(void); void None_Init(void); void None_Main(void); bool8 None_Finish(void); @@ -108,10 +126,10 @@ void Fog1_InitVars(void); void Fog1_Main(void); void Fog1_InitAll(void); bool8 Fog1_Finish(void); -void Weather11_InitVars(void); -void Weather11_Main(void); -void Weather11_InitAll(void); -bool8 Weather11_Finish(void); +void Shade_InitVars(void); +void Shade_Main(void); +void Shade_InitAll(void); +bool8 Shade_Finish(void); void Drought_InitVars(void); void Drought_Main(void); void Drought_InitAll(void); @@ -130,7 +148,7 @@ static const struct WeatherCallbacks sWeatherFuncs[] = {None_Init, None_Main, None_Init, None_Finish}, {Clouds_InitVars, Clouds_Main, Clouds_InitAll, Clouds_Finish}, {Weather2_InitVars, Weather2_Main, Weather2_InitAll, Weather2_Finish}, - {LightRain_InitVars, LightRain_Main, LightRain_InitAll, LightRain_Finish}, // light rain + {LightRain_InitVars, LightRain_Main, LightRain_InitAll, LightRain_Finish}, {Snow_InitVars, Snow_Main, Snow_InitAll, Snow_Finish}, {MedRain_InitVars, Rain_Main, MedRain_InitAll, Rain_Finish}, {Fog1_InitVars, Fog1_Main, Fog1_InitAll, Fog1_Finish}, @@ -138,54 +156,58 @@ static const struct WeatherCallbacks sWeatherFuncs[] = {Sandstorm_InitVars, Sandstorm_Main, Sandstorm_InitAll, Sandstorm_Finish}, {Fog2_InitVars, Fog2_Main, Fog2_InitAll, Fog2_Finish}, {Fog1_InitVars, Fog1_Main, Fog1_InitAll, Fog1_Finish}, - {Weather11_InitVars, Weather11_Main, Weather11_InitAll, Weather11_Finish}, + {Shade_InitVars, Shade_Main, Shade_InitAll, Shade_Finish}, {Drought_InitVars, Drought_Main, Drought_InitAll, Drought_Finish}, {HeavyRain_InitVars, Rain_Main, HeavyRain_InitAll, Rain_Finish}, {Bubbles_InitVars, Bubbles_Main, Bubbles_InitAll, Bubbles_Finish}, }; -void (*const gUnknown_083970B8[])(void) = +void (*const gWeatherPalStateFuncs[])(void) = { - sub_807CC24, - sub_807CCAC, - nullsub_39, - nullsub_39, + UpdateWeatherGammaShift, // WEATHER_PAL_STATE_CHANGING_WEATHER + FadeInScreenWithWeather, // WEATHER_PAL_STATE_SCREEN_FADING_IN + DoNothing, // WEATHER_PAL_STATE_SCREEN_FADING_OUT + DoNothing, // WEATHER_PAL_STATE_IDLE }; -const u8 gUnknown_083970C8[] = +// This table specifies which of the gamma shift tables should be +// applied to each of the background and sprite palettes. +static const u8 sBasePaletteGammaTypes[32] = { - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 0, - 0, - 2, - 1, - 2, - 2, - 2, - 2, - 1, - 1, - 1, - 1, - 2, - 1, - 1, - 1, - 1, - 1, + // background palettes + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NONE, + GAMMA_NONE, + // sprite palettes + GAMMA_ALT, + GAMMA_NORMAL, + GAMMA_ALT, + GAMMA_ALT, + GAMMA_ALT, + GAMMA_ALT, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_ALT, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, + GAMMA_NORMAL, }; #if DEBUG @@ -232,13 +254,14 @@ const u16 gUnknown_083970E8[] = INCBIN_U16("graphics/weather/0.gbapal"); void StartWeather(void) { u8 index; + if (!FuncIsActiveTask(Task_WeatherMain)) { index = AllocSpritePalette(0x1200); CpuCopy32(gUnknown_083970E8, &gPlttBufferUnfaded[0x100 + index * 16], 32); - sub_807CB10(); - gWeatherPtr->unknown_6D5 = index; - gWeatherPtr->unknown_6D4 = AllocSpritePalette(0x1201); + BuildGammaShiftTables(); + gWeatherPtr->altGammaSpritePalIndex = index; + gWeatherPtr->weatherPicSpritePalIndex = AllocSpritePalette(0x1201); gWeatherPtr->rainSpriteCount = 0; gWeatherPtr->unknown_6D8 = 0; gWeatherPtr->cloudSpritesCreated = 0; @@ -249,49 +272,53 @@ void StartWeather(void) gWeatherPtr->sandstormSprites1Created = 0; gWeatherPtr->sandstormSprites2Created = 0; gWeatherPtr->unknown_72E = 0; - gWeatherPtr->unknown_6FA = 0; + gWeatherPtr->lightenedFogSpritePalsCount = 0; Weather_SetBlendCoeffs(16, 0); gWeatherPtr->currWeather = 0; - gWeatherPtr->unknown_6C6 = 3; - gWeatherPtr->unknown_6C8 = 0; - gWeatherPtr->unknown_6D3 = 1; - gWeatherPtr->unknown_6C9 = CreateTask(Task_WeatherInit, 80); + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; + gWeatherPtr->readyForInit = FALSE; + gWeatherPtr->weatherChangeComplete = TRUE; + gWeatherPtr->taskId = CreateTask(Task_WeatherInit, 80); } } -void DoWeatherEffect(u8 effect) +void ChangeWeather(u8 weather) { - if (effect != WEATHER_RAIN_LIGHT && effect != WEATHER_RAIN_MED && effect != WEATHER_RAIN_HEAVY) + if (weather != WEATHER_RAIN_LIGHT && weather != WEATHER_RAIN_MED && weather != WEATHER_RAIN_HEAVY) { PlayRainSoundEffect(); } - if (gWeatherPtr->nextWeather != effect && gWeatherPtr->currWeather == effect) + + if (gWeatherPtr->nextWeather != weather && gWeatherPtr->currWeather == weather) { - sWeatherFuncs[effect].initVars(); + sWeatherFuncs[weather].initVars(); } - gWeatherPtr->unknown_6D3 = 0; - gWeatherPtr->nextWeather = effect; + + gWeatherPtr->weatherChangeComplete = FALSE; + gWeatherPtr->nextWeather = weather; gWeatherPtr->finishStep = 0; } -void sub_807C988(u8 effect) +void sub_807C988(u8 weather) { PlayRainSoundEffect(); - gWeatherPtr->currWeather = effect; - gWeatherPtr->nextWeather = effect; + gWeatherPtr->currWeather = weather; + gWeatherPtr->nextWeather = weather; } -void sub_807C9B4(u8 effect) +void sub_807C9B4(u8 weather) { PlayRainSoundEffect(); - gWeatherPtr->currWeather = effect; - gWeatherPtr->nextWeather = effect; - gWeatherPtr->unknown_6C8 = 1; + gWeatherPtr->currWeather = weather; + gWeatherPtr->nextWeather = weather; + gWeatherPtr->readyForInit = TRUE; } void Task_WeatherInit(u8 taskId) { - if (gWeatherPtr->unknown_6C8) + // Waits until it's ok to initialize weather. + // When the screen fades in, this is set to TRUE. + if (gWeatherPtr->readyForInit) { sWeatherFuncs[gWeatherPtr->currWeather].initAll(); gTasks[taskId].func = Task_WeatherMain; @@ -304,24 +331,26 @@ void Task_WeatherMain(u8 taskId) { if (!sWeatherFuncs[gWeatherPtr->currWeather].finish()) { + // Finished cleaning up previous weather. Now transition to next weather. sWeatherFuncs[gWeatherPtr->nextWeather].initVars(); - gWeatherPtr->unknown_6C3 = 0; - gWeatherPtr->unknown_6C6 = 0; + gWeatherPtr->gammaStepFrameCounter = 0; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER; gWeatherPtr->currWeather = gWeatherPtr->nextWeather; - gWeatherPtr->unknown_6D3 = 1; + gWeatherPtr->weatherChangeComplete = TRUE; } } else { sWeatherFuncs[gWeatherPtr->currWeather].main(); } - gUnknown_083970B8[gWeatherPtr->unknown_6C6](); + + gWeatherPalStateFuncs[gWeatherPtr->palProcessingState](); } void None_Init(void) { - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 0; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 0; } void None_Main(void) @@ -333,7 +362,10 @@ u8 None_Finish(void) return 0; } -void sub_807CB10(void) +// Builds two tables that contain gamma shifts for palette colors. +// It's unclear why the two tables aren't declared as const arrays, since +// this function always builds the same two tables. +static void BuildGammaShiftTables(void) { u16 v0; u8 (*v1)[32]; @@ -346,15 +378,15 @@ void sub_807CB10(void) u16 v11; s16 dunno; - gUnknown_030006DC = gUnknown_083970C8; + sPaletteGammaTypes = sBasePaletteGammaTypes; for (v0 = 0; v0 <= 1; v0++) { if (v0 == 0) - v1 = gWeatherPtr->unknown_200; + v1 = gWeatherPtr->gammaShifts; else - v1 = gWeatherPtr->unk460; + v1 = gWeatherPtr->altGammaShifts; - for (v2 = 0; (u16)v2 <= 0x1f; v2++) + for (v2 = 0; v2 < 32; v2++) { v4 = v2 << 8; if (v0 == 0) @@ -373,88 +405,86 @@ void sub_807CB10(void) v10 += 0xf; } v11 = v10 >> 4; - if (v2 <= 0xb) + if (v2 < 12) { - for (; v6 <= 0x12; v6++) + for (; v6 < 19; v6++) { v4 += v11; dunno = v4 - v9; if (dunno > 0) - { v4 -= (dunno + ((u16)dunno >> 15)) >> 1; - } v1[v6][v2] = v4 >> 8; if (v1[v6][v2] > 0x1f) - { v1[v6][v2] = 0x1f; - } } } else { - for (; v6 <= 0x12; v6++) + for (; v6 < 19; v6++) { v4 += v11; v1[v6][v2] = v4 >> 8; if (v1[v6][v2] > 0x1f) - { v1[v6][v2] = 0x1f; - } } } } } } -void sub_807CC24(void) +// When the weather is changing, it gradually updates the palettes +// towards the desired gamma shift. +static void UpdateWeatherGammaShift(void) { - if (gWeatherPtr->unknown_6C0 == gWeatherPtr->unknown_6C1) + if (gWeatherPtr->gammaIndex == gWeatherPtr->gammaTargetIndex) { - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } else { - if (++gWeatherPtr->unknown_6C3 >= gWeatherPtr->unknown_6C2) + if (++gWeatherPtr->gammaStepFrameCounter >= gWeatherPtr->gammaStepDelay) { - gWeatherPtr->unknown_6C3 = 0; - if (gWeatherPtr->unknown_6C0 < gWeatherPtr->unknown_6C1) - gWeatherPtr->unknown_6C0++; + gWeatherPtr->gammaStepFrameCounter = 0; + if (gWeatherPtr->gammaIndex < gWeatherPtr->gammaTargetIndex) + gWeatherPtr->gammaIndex++; else - gWeatherPtr->unknown_6C0--; - sub_807CEBC(0, 0x20, gWeatherPtr->unknown_6C0); + gWeatherPtr->gammaIndex--; + + ApplyGammaShift(0, 32, gWeatherPtr->gammaIndex); } } } -void sub_807CCAC(void) +static void FadeInScreenWithWeather(void) { if (++gWeatherPtr->unknown_6CB > 1) gWeatherPtr->unknown_6CA = 0; + switch (gWeatherPtr->currWeather) { case WEATHER_RAIN_LIGHT: case WEATHER_RAIN_MED: case WEATHER_RAIN_HEAVY: case WEATHER_SNOW: - case WEATHER_DARK: - if (sub_807CDC4() == 0) + case WEATHER_SHADE: + if (FadeInScreen_RainShowShade() == FALSE) { - gWeatherPtr->unknown_6C0 = 3; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = 3; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; case WEATHER_DROUGHT: - if (sub_807CE24() == 0) + if (FadeInScreen_Drought() == FALSE) { - gWeatherPtr->unknown_6C0 = -6; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = -6; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; case WEATHER_FOG_1: - if (sub_807CE7C() == 0) + if (FadeInScreen_Fog1() == FALSE) { - gWeatherPtr->unknown_6C0 = 0; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = 0; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; case WEATHER_ASH: @@ -464,71 +494,78 @@ void sub_807CCAC(void) default: if (!gPaletteFade.active) { - gWeatherPtr->unknown_6C0 = gWeatherPtr->unknown_6C1; - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->gammaIndex = gWeatherPtr->gammaTargetIndex; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } break; } } -u8 sub_807CDC4(void) +bool8 FadeInScreen_RainShowShade(void) { - if (gWeatherPtr->unknown_6C7 == 0x10) - return 0; - if (++gWeatherPtr->unknown_6C7 >= 0x10) + if (gWeatherPtr->fadeScreenCounter == 16) + return FALSE; + + if (++gWeatherPtr->fadeScreenCounter >= 16) { - sub_807CEBC(0, 0x20, 3); - gWeatherPtr->unknown_6C7 = 0x10; - return 0; + ApplyGammaShift(0, 32, 3); + gWeatherPtr->fadeScreenCounter = 16; + return FALSE; } - sub_807D1BC(0, 0x20, 3, 0x10 - gWeatherPtr->unknown_6C7, gWeatherPtr->unknown_6C4); - return 1; + + ApplyGammaShiftWithBlend(0, 32, 3, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); + return TRUE; } -u8 sub_807CE24(void) +bool8 FadeInScreen_Drought(void) { - if (gWeatherPtr->unknown_6C7 == 0x10) - return 0; - if (++gWeatherPtr->unknown_6C7 >= 0x10) + if (gWeatherPtr->fadeScreenCounter == 16) + return FALSE; + + if (++gWeatherPtr->fadeScreenCounter >= 16) { - sub_807CEBC(0, 0x20, -6); - gWeatherPtr->unknown_6C7 = 0x10; - return 0; + ApplyGammaShift(0, 32, -6); + gWeatherPtr->fadeScreenCounter = 16; + return FALSE; } - sub_807D304(-6, 0x10 - gWeatherPtr->unknown_6C7, gWeatherPtr->unknown_6C4); - return 1; -} -u8 sub_807CE7C(void) -{ - if (gWeatherPtr->unknown_6C7 == 0x10) - return 0; - ++gWeatherPtr->unknown_6C7; - sub_807D424(0x10 - gWeatherPtr->unknown_6C7, gWeatherPtr->unknown_6C4); - return 1; + ApplyDroughtGammaShiftWithBlend(-6, 16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); + return TRUE; } -void nullsub_39(void) +bool8 FadeInScreen_Fog1(void) { + if (gWeatherPtr->fadeScreenCounter == 16) + return FALSE; + + gWeatherPtr->fadeScreenCounter++; + ApplyFogBlend(16 - gWeatherPtr->fadeScreenCounter, gWeatherPtr->fadeDestColor); + return TRUE; } -void sub_807CEBC(u8 a, u8 b, s8 c) +static void DoNothing(void) +{ } + +static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex) { - u16 r4; + u16 curPalIndex; u16 palOffset; - u8 *r6; + u8 *gammaTable; u16 i; - if (c > 0) + if (gammaIndex > 0) { - c = c - 1; - palOffset = a * 16; - b += a; - r4 = a; - while (r4 < b) + gammaIndex--; + palOffset = startPalIndex * 16; + numPalettes += startPalIndex; + curPalIndex = startPalIndex; + + // Loop through the speficied palette range and apply necessary gamma shifts to the colors. + while (curPalIndex < numPalettes) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { + // No palette change. CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); palOffset += 16; } @@ -536,25 +573,27 @@ void sub_807CEBC(u8 a, u8 b, s8 c) { u8 r, g, b; - if (gUnknown_030006DC[r4] == 2 || r4 - 16 == gWeatherPtr->unknown_6D5) - r6 = gWeatherPtr->unk460[c]; + if (sPaletteGammaTypes[curPalIndex] == GAMMA_ALT || curPalIndex - 16 == gWeatherPtr->altGammaSpritePalIndex) + gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; else - r6 = gWeatherPtr->unknown_200[c]; - if (r4 == 16 || r4 > 0x1B) + gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; + + if (curPalIndex == 16 || curPalIndex > 27) { for (i = 0; i < 16; i++) { - if (gPlttBufferUnfaded[palOffset] == 0x2D9F) + if (gPlttBufferUnfaded[palOffset] == RGB(31, 12, 11)) { + // Skip gamma shift for this specific color. (Why?) palOffset++; } else { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; - - r = r6[color.r]; - g = r6[color.g]; - b = r6[color.b]; + // Apply gamma shift to the original color. + struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; + r = gammaTable[baseColor.r]; + g = gammaTable[baseColor.g]; + b = gammaTable[baseColor.b]; gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; } } @@ -563,39 +602,45 @@ void sub_807CEBC(u8 a, u8 b, s8 c) { for (i = 0; i < 16; i++) { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; - - r = r6[color.r]; - g = r6[color.g]; - b = r6[color.b]; + // Apply gamma shift to the original color. + struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; + r = gammaTable[baseColor.r]; + g = gammaTable[baseColor.g]; + b = gammaTable[baseColor.b]; gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; } } } - r4++; + + curPalIndex++; } } - else if (c < 0) + else if (gammaIndex < 0) { - c = -c - 1; - palOffset = a * 16; - b += a; - r4 = a; - while (r4 < b) + // A negative gammIndex value means that the blending will come from the special Drought weather's palette tables. + gammaIndex = -gammaIndex - 1; + palOffset = startPalIndex * 16; + numPalettes += startPalIndex; + curPalIndex = startPalIndex; + + while (curPalIndex < numPalettes) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { + // No palette change. CpuFastCopy(gPlttBufferUnfaded + palOffset, gPlttBufferFaded + palOffset, 16 * sizeof(u16)); palOffset += 16; } else { - if (r4 == 16 || r4 > 0x1B) + if (curPalIndex == 16 || curPalIndex > 27) { for (i = 0; i < 16; i++) { - if (gPlttBufferUnfaded[palOffset] != 0x2D9F) - gPlttBufferFaded[palOffset] = eWeatherPaletteData.data[c][MACRO1(gPlttBufferUnfaded[palOffset])]; + // Skip gamma shift for this specific color. (Why?) + if (gPlttBufferUnfaded[palOffset] != RGB(31, 12, 11)) + gPlttBufferFaded[palOffset] = eDroughtPaletteData.gammaShiftColors[gammaIndex][MACRO1(gPlttBufferUnfaded[palOffset])]; + palOffset++; } } @@ -603,93 +648,100 @@ void sub_807CEBC(u8 a, u8 b, s8 c) { for (i = 0; i < 16; i++) { - gPlttBufferFaded[palOffset] = eWeatherPaletteData.data[c][MACRO1(gPlttBufferUnfaded[palOffset])]; + gPlttBufferFaded[palOffset] = eDroughtPaletteData.gammaShiftColors[gammaIndex][MACRO1(gPlttBufferUnfaded[palOffset])]; palOffset++; } } } - r4++; + + curPalIndex++; } } else { - CpuFastCopy(gPlttBufferUnfaded + a * 16, gPlttBufferFaded + a * 16, b * 16 * sizeof(u16)); + // No palette blending. + CpuFastCopy(gPlttBufferUnfaded + startPalIndex * 16, gPlttBufferFaded + startPalIndex * 16, numPalettes * 16 * sizeof(u16)); } } -void sub_807D1BC(u8 a1, u8 a2, s8 c, u8 d, u16 e) +static void ApplyGammaShiftWithBlend(u8 startPalIndex, u8 numPalettes, s8 gammaIndex, u8 blendCoeff, u16 blendColor) { u16 palOffset; - u16 r4; + u16 curPalIndex; u16 i; - struct RGBColor color = *(struct RGBColor *)&e; - u8 r_ = color.r; - u8 g_ = color.g; - u8 b_ = color.b; - - palOffset = a1 * 16; - a2 += a1; - c = c - 1; - r4 = a1; - while (r4 < a2) + struct RGBColor color = *(struct RGBColor *)&blendColor; + u8 rBlend = color.r; + u8 gBlend = color.g; + u8 bBlend = color.b; + + palOffset = startPalIndex * 16; + numPalettes += startPalIndex; + gammaIndex--; + curPalIndex = startPalIndex; + + while (curPalIndex < numPalettes) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { - BlendPalette(palOffset, 16, d, e); + // No gamma shift. Simply blend the colors. + BlendPalette(palOffset, 16, blendCoeff, blendColor); palOffset += 16; } else { - u8 *r5; + u8 *gammaTable; - if (gUnknown_030006DC[r4] == 1) - r5 = gWeatherPtr->unknown_200[c]; + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NORMAL) + gammaTable = gWeatherPtr->gammaShifts[gammaIndex]; else - r5 = gWeatherPtr->unk460[c]; + gammaTable = gWeatherPtr->altGammaShifts[gammaIndex]; for (i = 0; i < 16; i++) { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; - u8 r = r5[color.r]; - u8 g = r5[color.g]; - u8 b = r5[color.b]; - - r += ((r_ - r) * d) >> 4; - g += ((g_ - g) * d) >> 4; - b += ((b_ - b) * d) >> 4; + struct RGBColor baseColor = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; + u8 r = gammaTable[baseColor.r]; + u8 g = gammaTable[baseColor.g]; + u8 b = gammaTable[baseColor.b]; + + // Apply gamma shift and target blend color to the original color. + r += ((rBlend - r) * blendCoeff) >> 4; + g += ((gBlend - g) * blendCoeff) >> 4; + b += ((bBlend - b) * blendCoeff) >> 4; gPlttBufferFaded[palOffset++] = (b << 10) | (g << 5) | r; } } - r4++; + + curPalIndex++; } } -void sub_807D304(s8 a, u8 coeff, u16 c) +void ApplyDroughtGammaShiftWithBlend(s8 gammaIndex, u8 blendCoeff, u16 blendColor) { struct RGBColor color; - u8 r_; - u8 g_; - u8 b_; - u16 r4; + u8 rBlend; + u8 gBlend; + u8 bBlend; + u16 curPalIndex; u16 palOffset; - u16 r12; + u16 i; - a = -a - 1; - color = *(struct RGBColor *)&c; - r_ = color.r; - g_ = color.g; - b_ = color.b; + gammaIndex = -gammaIndex - 1; + color = *(struct RGBColor *)&blendColor; + rBlend = color.r; + gBlend = color.g; + bBlend = color.b; palOffset = 0; - for (r4 = 0; r4 < 32; r4++) + for (curPalIndex = 0; curPalIndex < 32; curPalIndex++) { - if (gUnknown_030006DC[r4] == 0) + if (sPaletteGammaTypes[curPalIndex] == GAMMA_NONE) { - BlendPalette(palOffset, 16, coeff, c); + // No gamma shift. Simply blend the colors. + BlendPalette(palOffset, 16, blendCoeff, blendColor); palOffset += 16; } else { - for (r12 = 0; r12 < 16; r12++) + for (i = 0; i < 16; i++) { u32 offset; struct RGBColor color1; @@ -703,14 +755,14 @@ void sub_807D304(s8 a, u8 coeff, u16 c) b1 = color1.b; offset = ((b1 & 0x1E) << 7) | ((g1 & 0x1E) << 3) | ((r1 & 0x1E) >> 1); - color2 = *(struct RGBColor *)&eWeatherPaletteData.data[a][offset]; + color2 = *(struct RGBColor *)&eDroughtPaletteData.gammaShiftColors[gammaIndex][offset]; r2 = color2.r; g2 = color2.g; b2 = color2.b; - r2 += ((r_ - r2) * coeff) >> 4; - g2 += ((g_ - g2) * coeff) >> 4; - b2 += ((b_ - b2) * coeff) >> 4; + r2 += ((rBlend - r2) * blendCoeff) >> 4; + g2 += ((gBlend - g2) * blendCoeff) >> 4; + b2 += ((bBlend - b2) * blendCoeff) >> 4; gPlttBufferFaded[palOffset++] = (b2 << 10) | (g2 << 5) | r2; } @@ -718,33 +770,30 @@ void sub_807D304(s8 a, u8 coeff, u16 c) } } -bool8 sub_807D574(u8); - -void sub_807D424(u8 a, u16 b) +void ApplyFogBlend(u8 blendCoeff, u16 blendColor) { struct RGBColor color; - u8 r_; - u8 g_; - u8 b_; - u16 r4; - - BlendPalette(0, 0x100, a, b); - color = *(struct RGBColor *)&b; - r_ = color.r; - g_ = color.g; - b_ = color.b; - - r4 = 16; - while (r4 < 32) + u8 rBlend; + u8 gBlend; + u8 bBlend; + u16 curPalIndex; + + BlendPalette(0, 0x100, blendCoeff, blendColor); + color = *(struct RGBColor *)&blendColor; + rBlend = color.r; + gBlend = color.g; + bBlend = color.b; + + for (curPalIndex = 16; curPalIndex < 32; curPalIndex++) { - if (sub_807D574(r4)) + if (LightenSpritePaletteInFog(curPalIndex)) { - u16 r12 = (r4 + 1) * 16; - u16 r6 = r4 * 16; + u16 palEnd = (curPalIndex + 1) * 16; + u16 palOffset = curPalIndex * 16; - while (r6 < r12) + while (palOffset < palEnd) { - struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[r6]; + struct RGBColor color = *(struct RGBColor *)&gPlttBufferUnfaded[palOffset]; u8 r = color.r; u8 g = color.g; u8 b = color.b; @@ -753,88 +802,88 @@ void sub_807D424(u8 a, u16 b) g += ((31 - g) * 3) >> 2; b += ((28 - b) * 3) >> 2; - r += ((r_ - r) * a) >> 4; - g += ((g_ - g) * a) >> 4; - b += ((b_ - b) * a) >> 4; + r += ((rBlend - r) * blendCoeff) >> 4; + g += ((gBlend - g) * blendCoeff) >> 4; + b += ((bBlend - b) * blendCoeff) >> 4; - gPlttBufferFaded[r6] = (b << 10) | (g << 5) | r; - r6++; + gPlttBufferFaded[palOffset] = (b << 10) | (g << 5) | r; + palOffset++; } } else { - BlendPalette(r4 * 16, 16, a, b); + BlendPalette(curPalIndex * 16, 16, blendCoeff, blendColor); } - r4++; } } -void sub_807D540(u8 a) +static void MarkFogSpritePalToLighten(u8 paletteIndex) { - if (gWeatherPtr->unknown_6FA < 6) + if (gWeatherPtr->lightenedFogSpritePalsCount < 6) { - gWeatherPtr->unknown_6F4[gWeatherPtr->unknown_6FA] = a; - gWeatherPtr->unknown_6FA++; + gWeatherPtr->lightenedFogSpritePals[gWeatherPtr->lightenedFogSpritePalsCount] = paletteIndex; + gWeatherPtr->lightenedFogSpritePalsCount++; } } -bool8 sub_807D574(u8 a) +static bool8 LightenSpritePaletteInFog(u8 paletteIndex) { u16 i; - for (i = 0; i < gWeatherPtr->unknown_6FA; i++) + for (i = 0; i < gWeatherPtr->lightenedFogSpritePalsCount; i++) { - if (gWeatherPtr->unknown_6F4[i] == a) + if (gWeatherPtr->lightenedFogSpritePals[i] == paletteIndex) return TRUE; } + return FALSE; } -void sub_807D5BC(s8 a) +void sub_807D5BC(s8 gammaIndex) { - if (gWeatherPtr->unknown_6C6 == 3) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) { - sub_807CEBC(0, 32, a); - gWeatherPtr->unknown_6C0 = a; + ApplyGammaShift(0, 32, gammaIndex); + gWeatherPtr->gammaIndex = gammaIndex; } } -void sub_807D5F0(u8 a, u8 b, u8 c) +void sub_807D5F0(u8 gammaIndex, u8 gammaTargetIndex, u8 gammaStepDelay) { - if (gWeatherPtr->unknown_6C6 == 3) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_IDLE) { - gWeatherPtr->unknown_6C6 = 0; - gWeatherPtr->unknown_6C0 = a; - gWeatherPtr->unknown_6C1 = b; - gWeatherPtr->unknown_6C3 = 0; - gWeatherPtr->unknown_6C2 = c; - sub_807D5BC(a); + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_CHANGING_WEATHER; + gWeatherPtr->gammaIndex = gammaIndex; + gWeatherPtr->gammaTargetIndex = gammaTargetIndex; + gWeatherPtr->gammaStepFrameCounter = 0; + gWeatherPtr->gammaStepDelay = gammaStepDelay; + sub_807D5BC(gammaIndex); } } -void fade_screen(u8 a, u8 delay) +void FadeScreen(u8 mode, u8 delay) { u32 fadeColor; - u32 r1; - u32 r2; + bool8 fadeOut; + bool8 useWeatherPal; - switch (a) + switch (mode) { - case 0: + case FADE_FROM_BLACK: fadeColor = 0; - r1 = 0; + fadeOut = FALSE; break; - case 2: + case FADE_FROM_WHITE: fadeColor = 0xFFFF; - r1 = 0; + fadeOut = FALSE; break; - case 1: + case FADE_TO_BLACK: fadeColor = 0; - r1 = 1; + fadeOut = TRUE; break; - case 3: + case FADE_TO_WHITE: fadeColor = 0xFFFF; - r1 = 1; + fadeOut = TRUE; break; default: return; @@ -847,145 +896,149 @@ void fade_screen(u8 a, u8 delay) case WEATHER_RAIN_HEAVY: case WEATHER_SNOW: case WEATHER_FOG_1: - case WEATHER_DARK: + case WEATHER_SHADE: case WEATHER_DROUGHT: - r2 = 1; + useWeatherPal = TRUE; break; default: - r2 = 0; + useWeatherPal = FALSE; break; } - if (r1 != 0) + if (fadeOut) { - if (r2 != 0) + if (useWeatherPal) CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, 0x400); + BeginNormalPaletteFade(0xFFFFFFFF, delay, 0, 16, fadeColor); - gWeatherPtr->unknown_6C6 = 2; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_OUT; } else { - gWeatherPtr->unknown_6C4 = fadeColor; - if (r2 != 0) - gWeatherPtr->unknown_6C7 = 0; + gWeatherPtr->fadeDestColor = fadeColor; + if (useWeatherPal) + gWeatherPtr->fadeScreenCounter = 0; else BeginNormalPaletteFade(0xFFFFFFFF, delay, 16, 0, fadeColor); - gWeatherPtr->unknown_6C6 = 1; + + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_IN; gWeatherPtr->unknown_6CA = 1; gWeatherPtr->unknown_6CB = 0; Weather_SetBlendCoeffs(gWeatherPtr->currBlendEVA, gWeatherPtr->currBlendEVB); - gWeatherPtr->unknown_6C8 = 1; + gWeatherPtr->readyForInit = TRUE; } } -bool8 sub_807D770(void) +bool8 IsWeatherNotFadingIn(void) { - return (gWeatherPtr->unknown_6C6 != 1); + return (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_IN); } -void sub_807D78C(u8 a) +void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex) { - u16 r4 = 16 + a; + u16 paletteIndex = 16 + spritePaletteIndex; u16 i; - switch (gWeatherPtr->unknown_6C6) + switch (gWeatherPtr->palProcessingState) { - case 1: + case WEATHER_PAL_STATE_SCREEN_FADING_IN: if (gWeatherPtr->unknown_6CA != 0) { if (gWeatherPtr->currWeather == WEATHER_FOG_1) - sub_807D540(r4); - r4 *= 16; + MarkFogSpritePalToLighten(paletteIndex); + paletteIndex *= 16; for (i = 0; i < 16; i++) - gPlttBufferFaded[r4 + i] = gWeatherPtr->unknown_6C4; + gPlttBufferFaded[paletteIndex + i] = gWeatherPtr->fadeDestColor; } break; - case 2: - r4 *= 16; - CpuFastCopy(gPlttBufferFaded + r4, gPlttBufferUnfaded + r4, 32); - BlendPalette(r4, 16, gPaletteFade.y, gPaletteFade.blendColor); + case WEATHER_PAL_STATE_SCREEN_FADING_OUT: + paletteIndex *= 16; + CpuFastCopy(gPlttBufferFaded + paletteIndex, gPlttBufferUnfaded + paletteIndex, 32); + BlendPalette(paletteIndex, 16, gPaletteFade.y, gPaletteFade.blendColor); break; + // WEATHER_PAL_STATE_CHANGING_WEATHER + // WEATHER_PAL_STATE_CHANGING_IDLE default: if (gWeatherPtr->currWeather != WEATHER_FOG_1) { - sub_807CEBC(r4, 1, gWeatherPtr->unknown_6C0); + ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); } else { - r4 *= 16; - BlendPalette(r4, 16, 12, 0x73FC); + paletteIndex *= 16; + BlendPalette(paletteIndex, 16, 12, 0x73FC); } break; } } -void sub_807D874(u8 a) +void ApplyWeatherGammaShiftToPal(u8 paletteIndex) { - sub_807CEBC(a, 1, gWeatherPtr->unknown_6C0); + ApplyGammaShift(paletteIndex, 1, gWeatherPtr->gammaIndex); } u8 unref_sub_807D894(void) { - if (gWeatherPtr->unknown_6C6 == 1) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_SCREEN_FADING_IN) return gWeatherPtr->unknown_6CA; else return 0; } -void sub_807D8C0(const u16 *palette) +void LoadCustomWeatherSpritePalette(const u16 *palette) { - LoadPalette(palette, 0x100 + gWeatherPtr->unknown_6D4 * 16, 32); - sub_807D78C(gWeatherPtr->unknown_6D4); + LoadPalette(palette, 0x100 + gWeatherPtr->weatherPicSpritePalIndex * 16, 32); + UpdateSpritePaletteWithWeather(gWeatherPtr->weatherPicSpritePalIndex); } -void sub_807D8F0(u8 *a, u8 *b) +static void LoadDroughtWeatherPalette(u8 *gammaIndexPtr, u8 *b) { - u8 r4 = *a; + u8 gammaIndex = *gammaIndexPtr; u16 i; - if (r4 < 7) + if (gammaIndex < 7) { - r4--; - LZ77UnCompWram(sCompressedDroughtPalettes[r4], eWeatherPaletteData.data[r4]); - if (r4 == 0) + gammaIndex--; + LZ77UnCompWram(sCompressedDroughtPalettes[gammaIndex], eDroughtPaletteData.gammaShiftColors[gammaIndex]); + if (gammaIndex == 0) { - eWeatherPaletteData.data[r4][0] = 0x421; + eDroughtPaletteData.gammaShiftColors[gammaIndex][0] = RGB(1, 1, 1); for (i = 1; i < 0x1000; i++) - eWeatherPaletteData.data[r4][i] += eWeatherPaletteData.data[r4][i - 1]; + eDroughtPaletteData.gammaShiftColors[gammaIndex][i] += eDroughtPaletteData.gammaShiftColors[gammaIndex][i - 1]; } else { for (i = 0; i < 0x1000; i++) - eWeatherPaletteData.data[r4][i] += eWeatherPaletteData.data[r4 - 1][i]; + eDroughtPaletteData.gammaShiftColors[gammaIndex][i] += eDroughtPaletteData.gammaShiftColors[gammaIndex - 1][i]; } - if (++(*a) == 7) + if (++(*gammaIndexPtr) == 7) { - *a = 32; + *gammaIndexPtr = 32; *b = 32; } } } -void sub_807D9A8(void) +void ResetDroughtWeatherPaletteLoading(void) { - gWeatherPtr->unknown_74D = 1; - gWeatherPtr->unknown_74E = 1; + gWeatherPtr->loadDroughtPalsIndex = 1; + gWeatherPtr->loadDroughtPalsOffset = 1; } -bool8 sub_807D9C8(void) +bool8 LoadDroughtWeatherPalettes(void) { - if (gWeatherPtr->unknown_74D < 32) + if (gWeatherPtr->loadDroughtPalsIndex < 32) { - sub_807D8F0(&gWeatherPtr->unknown_74D, &gWeatherPtr->unknown_74E); - if (gWeatherPtr->unknown_74D < 32) + LoadDroughtWeatherPalette(&gWeatherPtr->loadDroughtPalsIndex, &gWeatherPtr->loadDroughtPalsOffset); + if (gWeatherPtr->loadDroughtPalsIndex < 32) return TRUE; } return FALSE; } -void sub_807DA04(s8 a) +void sub_807DA04(s8 gammaIndex) { - sub_807D5BC(-a - 1); + sub_807D5BC(-gammaIndex - 1); } void sub_807DA14(void) @@ -1047,8 +1100,8 @@ void Weather_SetTargetBlendCoeffs(u8 eva, u8 evb, int delay) gWeatherPtr->targetBlendEVA = eva; gWeatherPtr->targetBlendEVB = evb; gWeatherPtr->blendDelay = delay; - gWeatherPtr->unknown_739 = 0; - gWeatherPtr->unknown_738 = 0; + gWeatherPtr->blendFrameCounter = 0; + gWeatherPtr->blendUpdateCounter = 0; } bool8 Weather_UpdateBlend(void) @@ -1057,13 +1110,13 @@ bool8 Weather_UpdateBlend(void) && gWeatherPtr->currBlendEVB == gWeatherPtr->targetBlendEVB) return TRUE; - if (++gWeatherPtr->unknown_739 > gWeatherPtr->blendDelay) + if (++gWeatherPtr->blendFrameCounter > gWeatherPtr->blendDelay) { - gWeatherPtr->unknown_739 = 0; - gWeatherPtr->unknown_738++; + gWeatherPtr->blendFrameCounter = 0; + gWeatherPtr->blendUpdateCounter++; // Update currBlendEVA and currBlendEVB on alternate frames - if (gWeatherPtr->unknown_738 & 1) + if (gWeatherPtr->blendUpdateCounter & 1) { if (gWeatherPtr->currBlendEVA < gWeatherPtr->targetBlendEVA) gWeatherPtr->currBlendEVA++; @@ -1093,48 +1146,48 @@ void unref_sub_807DCB4(u8 a) switch (a) { case 1: - SetWeather(1); + SetWeather(WEATHER_CLOUDS); break; case 2: - SetWeather(2); + SetWeather(WEATHER_SUNNY); break; case 3: - SetWeather(3); + SetWeather(WEATHER_RAIN_LIGHT); break; case 4: - SetWeather(4); + SetWeather(WEATHER_SNOW); break; case 5: - SetWeather(5); + SetWeather(WEATHER_RAIN_MED); break; case 6: - SetWeather(6); + SetWeather(WEATHER_FOG_1); break; case 7: - SetWeather(9); + SetWeather(WEATHER_FOG_2); break; case 8: - SetWeather(7); + SetWeather(WEATHER_ASH); break; case 9: - SetWeather(8); + SetWeather(WEATHER_SANDSTORM); break; case 10: - SetWeather(11); + SetWeather(WEATHER_SHADE); break; } } -u8 weather_get_current(void) +u8 GetCurrentWeather(void) { return gWeatherPtr->currWeather; } -void SetRainStrengthFromSoundEffect(u16 sndEff) +void SetRainStrengthFromSoundEffect(u16 soundEffect) { - if (gWeatherPtr->unknown_6C6 != 2) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_SCREEN_FADING_OUT) { - switch (sndEff) + switch (soundEffect) { case SE_T_KOAME: gWeatherPtr->rainStrength = 0; @@ -1148,7 +1201,8 @@ void SetRainStrengthFromSoundEffect(u16 sndEff) default: return; } - PlaySE(sndEff); + + PlaySE(soundEffect); } } @@ -1172,31 +1226,31 @@ void PlayRainSoundEffect(void) } } -u8 sub_807DDFC(void) +u8 IsWeatherChangeComplete(void) { - return gWeatherPtr->unknown_6D3; + return gWeatherPtr->weatherChangeComplete; } -void sub_807DE10(void) +void SetWeatherScreenFadeOut(void) { - gWeatherPtr->unknown_6C6 = 2; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_OUT; } void unref_sub_807DE24(void) { - gWeatherPtr->unknown_6C6 = 3; + gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_IDLE; } -void sub_807DE38(u8 a) +void PreservePaletteInWeather(u8 preservedPalIndex) { - CpuCopy16(gUnknown_083970C8, gUnknown_0202FF38, 32); - gUnknown_0202FF38[a] = 0; - gUnknown_030006DC = gUnknown_0202FF38; + CpuCopy16(sBasePaletteGammaTypes, gFieldEffectPaletteGammaTypes, 32); + gFieldEffectPaletteGammaTypes[preservedPalIndex] = GAMMA_NONE; + sPaletteGammaTypes = gFieldEffectPaletteGammaTypes; } -void sub_807DE68(void) +void ResetPreservedPalettesInWeather(void) { - gUnknown_030006DC = gUnknown_083970C8; + sPaletteGammaTypes = sBasePaletteGammaTypes; } #if DEBUG @@ -1284,7 +1338,7 @@ u8 debug_sub_8085564(void) ._378:\n\ ldr r0, ._382\n\ ldrb r0, [r0]\n\ - bl DoWeatherEffect\n\ + bl ChangeWeather\n\ bl CloseMenu\n\ mov r0, #0x1\n\ ._379:\n\ @@ -1335,7 +1389,7 @@ u8 debug_sub_808560C(void) .word gUnknown_0202FF58+0x2\n\ .word gWeather\n\ .word gDebugText_Weather\n\ - .word gCallback_03004AE8\n\ + .word gMenuCallback\n\ .word debug_sub_8085564+1"); } diff --git a/src/field/field_weather_effects.c b/src/field/field_weather_effects.c index 5a59d6c2a..eff702f8c 100644 --- a/src/field/field_weather_effects.c +++ b/src/field/field_weather_effects.c @@ -74,10 +74,7 @@ static const struct SpriteTemplate sCloudSpriteTemplate = .callback = sub_807E0F4, }; -extern void sub_807D5BC(s8 a); -extern void sub_807D8C0(const u16 *palette); -extern void sub_807D9A8(void); -extern bool8 sub_807D9C8(void); +extern void sub_807D5BC(s8 gammaIndex); extern void sub_807DA14(void); extern void sub_807DA4C(void); extern void Weather_SetTargetBlendCoeffs(u8 a, u8 b, int c); @@ -91,8 +88,8 @@ extern void sub_807D5F0(u8 a, u8 b, u8 c); void Clouds_InitVars(void) { - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; gWeatherPtr->initStep = 0; if (gWeatherPtr->cloudSpritesCreated == FALSE) @@ -159,8 +156,8 @@ bool8 Clouds_Finish(void) void Weather2_InitVars(void) { - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; } void Weather2_InitAll(void) @@ -184,7 +181,7 @@ void CreateCloudSprites(void) if (gWeatherPtr->cloudSpritesCreated == TRUE) return; LoadSpriteSheet(&sCloudSpriteSheet); - sub_807D8C0(gUnknown_08397108); + LoadCustomWeatherSpritePalette(gUnknown_08397108); for (i = 0; i < 3; i++) { u8 spriteId = CreateSprite(&sCloudSpriteTemplate, 0, 0, 0xFF); @@ -236,8 +233,8 @@ void Drought_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 0; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 0; } void Drought_Main(void); @@ -254,15 +251,15 @@ void Drought_Main(void) switch (gWeatherPtr->initStep) { case 0: - if (gWeatherPtr->unknown_6C6 != 0) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_CHANGING_WEATHER) gWeatherPtr->initStep++; break; case 1: - sub_807D9A8(); + ResetDroughtWeatherPaletteLoading(); gWeatherPtr->initStep++; break; case 2: - if (sub_807D9C8() == FALSE) + if (LoadDroughtWeatherPalettes() == FALSE) gWeatherPtr->initStep++; break; case 3: @@ -368,8 +365,8 @@ void LightRain_InitVars(void) gWeatherPtr->unknown_6DB = 8; gWeatherPtr->unknown_6DC = 0; gWeatherPtr->unknown_6D9 = 10; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; SetRainStrengthFromSoundEffect(SE_T_KOAME); } @@ -885,8 +882,8 @@ void Snow_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->unknown_6E5 = 16; gWeatherPtr->unknown_6E0 = 0; } @@ -1074,8 +1071,8 @@ void MedRain_InitVars(void) gWeatherPtr->unknown_6DB = 4; gWeatherPtr->unknown_6DC = 0; gWeatherPtr->unknown_6D9 = 16; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment gWeatherPtr->unknown_6ED = 0; SetRainStrengthFromSoundEffect(SE_T_AME); @@ -1102,8 +1099,8 @@ void HeavyRain_InitVars(void) gWeatherPtr->unknown_6DB = 4; gWeatherPtr->unknown_6DC = 1; gWeatherPtr->unknown_6D9 = 24; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->weatherGfxLoaded = FALSE; // duplicate assignment SetRainStrengthFromSoundEffect(SE_T_OOAME); } @@ -1139,7 +1136,7 @@ void Rain_Main(void) gWeatherPtr->initStep++; break; case 3: - if (gWeatherPtr->unknown_6C6 == 0) + if (gWeatherPtr->palProcessingState == WEATHER_PAL_STATE_CHANGING_WEATHER) break; gWeatherPtr->initStep = 6; break; @@ -1213,7 +1210,7 @@ void Rain_Main(void) gWeatherPtr->initStep++; break; case 14: - if (gWeatherPtr->unknown_6C6 != 3) + if (gWeatherPtr->palProcessingState != WEATHER_PAL_STATE_IDLE) break; gWeatherPtr->unknown_6EA = 1; gWeatherPtr->initStep = 4; @@ -1296,8 +1293,8 @@ void Fog1_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; if (gWeatherPtr->fog1SpritesCreated == 0) { gWeatherPtr->unknown_6F0 = 0; @@ -1446,8 +1443,8 @@ void Ash_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = FALSE; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->unknown_6FE = 20; if (!gWeatherPtr->ashSpritesCreated) { @@ -1634,8 +1631,8 @@ void Fog2_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = 0; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; gWeatherPtr->unknown_6F0 = 0; gWeatherPtr->unknown_6F2 = 1; if (gWeatherPtr->fog2SpritesCreated == 0) @@ -1835,8 +1832,8 @@ void Sandstorm_InitVars(void) { gWeatherPtr->initStep = 0; gWeatherPtr->weatherGfxLoaded = 0; - gWeatherPtr->unknown_6C1 = 0; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 0; + gWeatherPtr->gammaStepDelay = 20; if (gWeatherPtr->sandstormSprites1Created == 0) { gWeatherPtr->unknown_704 = gWeatherPtr->unknown_708 = 0; @@ -2015,7 +2012,7 @@ void CreateSandstormSprites_1(void) if (!gWeatherPtr->sandstormSprites1Created) { LoadSpriteSheet(&sSandstormSpriteSheet); - sub_807D8C0(gUnknown_08397128); + LoadCustomWeatherSpritePalette(gUnknown_08397128); for (i = 0; i < 20; i++) { u8 spriteId = CreateSpriteAtEnd(&sSandstormSpriteTemplate, 0, (i / 5) * 64, 1); @@ -2113,26 +2110,26 @@ void SandstormSpriteCallback3(struct Sprite *sprite) } //------------------------------------------------------------------------------ -// Weather 11 +// Shade //------------------------------------------------------------------------------ -void Weather11_InitVars(void) +void Shade_InitVars(void) { gWeatherPtr->initStep = 0; - gWeatherPtr->unknown_6C1 = 3; - gWeatherPtr->unknown_6C2 = 20; + gWeatherPtr->gammaTargetIndex = 3; + gWeatherPtr->gammaStepDelay = 20; } -void Weather11_InitAll(void) +void Shade_InitAll(void) { - Weather11_InitVars(); + Shade_InitVars(); } -void Weather11_Main(void) +void Shade_Main(void) { } -bool8 Weather11_Finish(void) +bool8 Shade_Finish(void) { return FALSE; } @@ -2322,7 +2319,7 @@ void SetSav1WeatherFromCurrMapHeader(void) void SetWeather(u32 weather) { SetSav1Weather(weather); - DoWeatherEffect(GetSav1Weather()); + ChangeWeather(GetSav1Weather()); } void SetWeather_Unused(u32 weather) @@ -2333,7 +2330,7 @@ void SetWeather_Unused(u32 weather) void DoCurrentWeather(void) { - DoWeatherEffect(GetSav1Weather()); + ChangeWeather(GetSav1Weather()); } void sub_8080750(void) @@ -2380,5 +2377,5 @@ void UpdateRainCounter(u8 newWeather, u8 oldWeather) { if (newWeather != oldWeather && (newWeather == WEATHER_RAIN_LIGHT || newWeather == WEATHER_RAIN_MED)) - IncrementGameStat(0x28); + IncrementGameStat(GAME_STAT_GOT_RAINED_ON); } diff --git a/src/field/fldeff_cut.c b/src/field/fldeff_cut.c index 7d90b9f4d..522fb01d6 100644 --- a/src/field/fldeff_cut.c +++ b/src/field/fldeff_cut.c @@ -231,7 +231,7 @@ bool8 FldEff_UseCutOnGrass(void) gTasks[taskId].data[8] = (u32)sub_80A2684 >> 16; gTasks[taskId].data[9] = (u32)sub_80A2684; - IncrementGameStat(0x12); + IncrementGameStat(GAME_STAT_USED_CUT); return FALSE; } @@ -247,7 +247,7 @@ bool8 FldEff_UseCutOnTree(void) gTasks[taskId].data[8] = (u32)sub_80A2B00 >> 16; gTasks[taskId].data[9] = (u32)sub_80A2B00; - IncrementGameStat(0x12); + IncrementGameStat(GAME_STAT_USED_CUT); return FALSE; } diff --git a/src/field/fldeff_escalator.c b/src/field/fldeff_escalator.c new file mode 100644 index 000000000..981233480 --- /dev/null +++ b/src/field/fldeff_escalator.c @@ -0,0 +1,132 @@ +#include "global.h" +#include "task.h" +#include "fieldmap.h" +#include "field_camera.h" +#include "field_player_avatar.h" + +extern u8 gUnknown_02038731; + +void sub_80B45B4(u8 taskId, const s16 *list, u16 c) +{ + s16 r5 = gTasks[taskId].data[4] - 1; + s16 r3 = gTasks[taskId].data[5] - 1; + s16 r4 = gTasks[taskId].data[1]; + s16 y; + s16 x; + + if (gTasks[taskId].data[2] == 0) + { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { + s16 metatileId = MapGridGetMetatileIdAt(r5 + x, r3 + y); + + if (list[r4] == metatileId) + { + if (r4 != 2) + MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[r4 + 1]); + else + MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[0]); + } + } + } + } + else + { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { + s16 metatileId = MapGridGetMetatileIdAt(r5 + x, r3 + y); + + if (list[2 - r4] == metatileId) + { + if (r4 != 2) + MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[1 - r4]); + else + MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[2]); + } + } + } + } +} + +const u16 gUnknown_083CC714[] = {0x284, 0x282, 0x280}; +const u16 gUnknown_083CC71A[] = {0x285, 0x283, 0x281}; +const u16 gUnknown_083CC720[] = {0x28C, 0x28A, 0x288}; +const u16 gUnknown_083CC726[] = {0x28D, 0x28B, 0x289}; +const u16 gUnknown_083CC72C[] = {0x2A0, 0x2A2, 0x2A4}; +const u16 gUnknown_083CC732[] = {0x2A1, 0x2A3, 0x2A5}; +const u16 gUnknown_083CC738[] = {0x2A8, 0x2AA, 0x2AC}; + +void sub_80B4710(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + + data[3] = 1; + + switch (data[0]) + { + case 0: + sub_80B45B4(taskId, gUnknown_083CC714, 0); + break; + case 1: + sub_80B45B4(taskId, gUnknown_083CC71A, 0); + break; + case 2: + sub_80B45B4(taskId, gUnknown_083CC720, 0xC00); + break; + case 3: + sub_80B45B4(taskId, gUnknown_083CC726, 0); + break; + case 4: + sub_80B45B4(taskId, gUnknown_083CC72C, 0xC00); + break; + case 5: + sub_80B45B4(taskId, gUnknown_083CC732, 0); + break; + case 6: + sub_80B45B4(taskId, gUnknown_083CC738, 0); + break; + } + + data[0] = (data[0] + 1) & 7; + if (!data[0]) + { + DrawWholeMapView(); + data[1] = (data[1] + 1) % 3; + data[3] = 0; + } +} + +u8 sub_80B47D8(u16 var) +{ + u8 taskId = CreateTask(sub_80B4710, 0); + s16 *data = gTasks[taskId].data; + + PlayerGetDestCoords(&data[4], &data[5]); + data[0] = 0; + data[1] = 0; + data[2] = var; + sub_80B4710(taskId); + return taskId; +} + +void sub_80B4824(u8 var) +{ + gUnknown_02038731 = sub_80B47D8(var); +} + +void sub_80B483C(void) +{ + DestroyTask(gUnknown_02038731); +} + +bool8 sub_80B4850(void) +{ + if (gTasks[gUnknown_02038731].data[3] == 0 && gTasks[gUnknown_02038731].data[1] == 2) + return FALSE; + else + return TRUE; +} diff --git a/src/field/item_menu.c b/src/field/item_menu.c index 7922bf69d..cf3c7ca4b 100644 --- a/src/field/item_menu.c +++ b/src/field/item_menu.c @@ -34,12 +34,12 @@ #include "task.h" #include "text.h" #include "scanline_effect.h" +#include "menu_helpers.h" #include "ewram.h" // External stuff extern void gpu_pal_allocator_reset__manage_upper_four(void); -extern void sub_80F9020(void); -extern void sub_80F9988(); +extern void SetVerticalScrollIndicatorPriority(); extern void sub_809D104(u16 *, u16, u16, const u8 *, u16, u16, u16, u16); extern void PauseVerticalScrollIndicator(); extern u8 sub_80F9284(void); @@ -47,10 +47,10 @@ extern void sub_808B5B4(); extern u8 sub_80F92F4(); extern void sub_80C9C7C(u8); extern void pal_fill_black(void); -extern bool8 sub_807D770(void); +extern bool8 IsWeatherNotFadingIn(void); extern u8 sub_80F931C(); extern void sub_808A3F8(u8); -extern void sub_80B3050(void); +extern void Shop_FadeReturnToMartMenu(void); extern void sub_80546B8(u8); extern void sub_804E990(u8); extern void sub_802E424(u8); @@ -389,20 +389,8 @@ static void sub_80A3134(void) LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); - - { - const void *src = gBGTilemapBuffers[1]; - void *dst = (void *)(VRAM + 0x2000); - - DmaCopy16(3, src, dst, 0x800); - } - - { - const void *src = gBGTilemapBuffers[2]; - void *dst = (void *)(VRAM + 0x6000); - - DmaCopy16(3, src, dst, 0x800); - } + DmaCopy16Defvars(3, gBGTilemapBuffers[1], (void *)(VRAM + 0x2000), 0x800); + DmaCopy16Defvars(3, gBGTilemapBuffers[2], (void *)(VRAM + 0x6000), 0x800); } #if DEBUG @@ -450,7 +438,7 @@ static bool8 SetupBagMultistep(void) .word ._23\n\ .word ._24\n\ ._8:\n\ - bl sub_80F9438\n\ + bl ClearVideoCallbacks\n\ bl sub_80A34E8\n\ b ._61\n\ ._9:\n\ @@ -468,7 +456,7 @@ static bool8 SetupBagMultistep(void) bl gpu_pal_allocator_reset__manage_upper_four\n\ b ._61\n\ ._11:\n\ - bl sub_80F9020\n\ + bl ClearBGTilemapBuffers\n\ ldr r0, ._31\n\ ldr r1, ._31 + 4\n\ add r0, r0, r1\n\ @@ -545,7 +533,7 @@ static bool8 SetupBagMultistep(void) ._48:\n\ b ._61\n\ ._18:\n\ - bl sub_80F944C\n\ + bl ClearVerticalScrollIndicatorPalettes\n\ bl LoadScrollIndicatorPalette\n\ mov r0, #0x0\n\ mov r1, #0xac\n\ @@ -565,16 +553,16 @@ static bool8 SetupBagMultistep(void) bl CreateVerticalScrollIndicators\n\ mov r0, #0x0\n\ mov r1, #0x2\n\ - bl sub_80F9988\n\ + bl SetVerticalScrollIndicatorPriority\n\ mov r0, #0x1\n\ mov r1, #0x2\n\ - bl sub_80F9988\n\ + bl SetVerticalScrollIndicatorPriority\n\ mov r0, #0x2\n\ mov r1, #0x2\n\ - bl sub_80F9988\n\ + bl SetVerticalScrollIndicatorPriority\n\ mov r0, #0x3\n\ mov r1, #0x2\n\ - bl sub_80F9988\n\ + bl SetVerticalScrollIndicatorPriority\n\ ldr r0, ._53\n\ ldrb r0, [r0]\n\ sub r0, r0, #0x4\n\ @@ -584,10 +572,10 @@ static bool8 SetupBagMultistep(void) bhi ._51 @cond_branch\n\ mov r0, #0x2\n\ mov r1, #0x1\n\ - bl sub_80F979C\n\ + bl SetVerticalScrollIndicators\n\ mov r0, #0x3\n\ mov r1, #0x1\n\ - bl sub_80F979C\n\ + bl SetVerticalScrollIndicators\n\ ._51:\n\ ldr r1, ._53 + 4\n\ ldr r0, ._53 + 8\n\ @@ -797,7 +785,7 @@ static bool8 SetupBagMultistep(void) switch (gMain.state) { case 0: - sub_80F9438(); + ClearVideoCallbacks(); sub_80A34E8(); gMain.state++; break; @@ -810,7 +798,7 @@ static bool8 SetupBagMultistep(void) gMain.state++; break; case 3: - sub_80F9020(); + ClearBGTilemapBuffers(); ewramBagSetupStep = 0; gMain.state++; break; @@ -842,20 +830,20 @@ static bool8 SetupBagMultistep(void) gMain.state++; break; case 10: - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); - CreateVerticalScrollIndicators(0, 172, 12); - CreateVerticalScrollIndicators(1, 172, 148); - CreateVerticalScrollIndicators(2, 28, 88); - CreateVerticalScrollIndicators(3, 100, 88); - sub_80F9988(0, 2); - sub_80F9988(1, 2); - sub_80F9988(2, 2); - sub_80F9988(3, 2); + CreateVerticalScrollIndicators(TOP_ARROW, 172, 12); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 172, 148); + CreateVerticalScrollIndicators(LEFT_ARROW, 28, 88); + CreateVerticalScrollIndicators(RIGHT_ARROW, 100, 88); + SetVerticalScrollIndicatorPriority(TOP_ARROW, 2); + SetVerticalScrollIndicatorPriority(BOTTOM_ARROW, 2); + SetVerticalScrollIndicatorPriority(LEFT_ARROW, 2); + SetVerticalScrollIndicatorPriority(RIGHT_ARROW, 2); if (sReturnLocation == RETURN_TO_FIELD_4 || sReturnLocation == RETURN_TO_FIELD_5) { - sub_80F979C(2, 1); - sub_80F979C(3, 1); + SetVerticalScrollIndicators(LEFT_ARROW, INVISIBLE); + SetVerticalScrollIndicators(RIGHT_ARROW, INVISIBLE); } gMain.state++; break; @@ -1136,10 +1124,10 @@ static void sub_80A3770(void) static void sub_80A37C0(u8 taskId) { gTasks[taskId].func = sub_80A50C8; - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); - StartVerticalScrollIndicators(2); - StartVerticalScrollIndicators(3); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); + StartVerticalScrollIndicators(LEFT_ARROW); + StartVerticalScrollIndicators(RIGHT_ARROW); } static void sub_80A37F8(u8 taskId) @@ -1181,8 +1169,8 @@ static void sub_80A37F8(u8 taskId) sub_80A37C0(FindTaskIdByFunc(sub_80A4F68)); DestroyTask(taskId); ItemListMenu_InitMenu(); - sub_80F979C(2, 0); - sub_80F979C(3, 0); + SetVerticalScrollIndicators(LEFT_ARROW, VISIBLE); + SetVerticalScrollIndicators(RIGHT_ARROW, VISIBLE); } } @@ -1984,14 +1972,14 @@ static void sub_80A47E8(u16 a, int b, int c, int d) break; } if (gBagPocketScrollStates[sCurrentBagPocket].scrollTop != 0) - sub_80F979C(0, 0); + SetVerticalScrollIndicators(TOP_ARROW, VISIBLE); else - sub_80F979C(0, 1); + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); if ((sReturnLocation != RETURN_TO_FIELD_5 && gBagPocketScrollStates[sCurrentBagPocket].scrollTop + 8 < gBagPocketScrollStates[sCurrentBagPocket].numSlots + 1) || (sReturnLocation == RETURN_TO_FIELD_5 && gBagPocketScrollStates[sCurrentBagPocket].scrollTop + 8 < gBagPocketScrollStates[sCurrentBagPocket].numSlots)) - sub_80F979C(1, 0); + SetVerticalScrollIndicators(BOTTOM_ARROW, VISIBLE); else - sub_80F979C(1, 1); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); } static void sub_80A48E8(u16 taskId, int b, int c) @@ -2186,14 +2174,14 @@ static void sub_80A4DD8(u8 taskId, u8 b, u8 c, u8 d, u8 e, u8 digits) static void sub_80A4E8C(s8 delta, u8 b) { PlaySE(SE_SELECT); - sub_80F979C(0, 1); - sub_80F979C(1, 1); - sub_80F979C(2, 1); - sub_80F979C(3, 1); - PauseVerticalScrollIndicator(0); - PauseVerticalScrollIndicator(1); - PauseVerticalScrollIndicator(2); - PauseVerticalScrollIndicator(3); + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); + SetVerticalScrollIndicators(LEFT_ARROW, INVISIBLE); + SetVerticalScrollIndicators(RIGHT_ARROW, INVISIBLE); + PauseVerticalScrollIndicator(TOP_ARROW); + PauseVerticalScrollIndicator(BOTTOM_ARROW); + PauseVerticalScrollIndicator(LEFT_ARROW); + PauseVerticalScrollIndicator(RIGHT_ARROW); ChangePocket(gBGTilemapBuffers[2], delta); DrawPocketIndicatorDots(gBGTilemapBuffers[2], sCurrentBagPocket); sub_80A3770(); @@ -2345,10 +2333,10 @@ static void sub_80A50C8(u8 taskId) gUnknown_02038560 = gBagPocketScrollStates[sCurrentBagPocket].scrollTop + gBagPocketScrollStates[sCurrentBagPocket].cursorPos; gSpecialVar_ItemId = gCurrentBagPocketItemSlots[gUnknown_02038560].itemId; gUnknown_083C16BC[sReturnLocation].onItemSelect(taskId); - sub_80F98A4(0); - sub_80F98A4(1); - sub_80F98A4(2); - sub_80F98A4(3); + StopVerticalScrollIndicators(TOP_ARROW); + StopVerticalScrollIndicators(BOTTOM_ARROW); + StopVerticalScrollIndicators(LEFT_ARROW); + StopVerticalScrollIndicators(RIGHT_ARROW); sub_80A797C(); } else @@ -2380,7 +2368,7 @@ static void sub_80A50C8(u8 taskId) } } -bool8 sub_80A52C4(u8 taskId, u16 b) +bool8 SellMenu_QuantityRoller(u8 taskId, u16 b) { s16 *taskData = gTasks[taskId].data; @@ -2427,7 +2415,7 @@ static bool8 sub_80A5350(u8 taskId) { s16 *taskData = gTasks[taskId].data; - if (sub_80A52C4(taskId, gCurrentBagPocketItemSlots[gUnknown_02038560].quantity) == TRUE) + if (SellMenu_QuantityRoller(taskId, gCurrentBagPocketItemSlots[gUnknown_02038560].quantity) == TRUE) { // if (sCurrentBagPocket == BAG_POCKET_BERRIES) Can't get it to match this way if (sCurrentBagPocket + 1 == BAG_POCKET_BERRIES + 1) @@ -3190,7 +3178,7 @@ void ExecuteItemUseFromBlackPalette(void) static void Task_CallItemUseOnFieldCallback(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) gFieldItemUseCallback(taskId); } @@ -3442,7 +3430,7 @@ static void sub_80A62D8(void) gUnknown_02038563 = CreateTask(sub_80A50C8, 0); } -void sub_80A6300(void) +void ItemMenu_LoadSellMenu(void) { sReturnLocation = RETURN_TO_SHOP; SetMainCallback2(sub_80A62D8); @@ -3450,7 +3438,7 @@ void sub_80A6300(void) static void OnBagClose_Shop(u8 taskId) { - gFieldCallback = sub_80B3050; + gFieldCallback = Shop_FadeReturnToMartMenu; gTasks[taskId].data[8] = (u32)c2_exit_to_overworld_2_switch >> 16; gTasks[taskId].data[9] = (u32)c2_exit_to_overworld_2_switch; sub_80A5AE4(taskId); @@ -4002,8 +3990,8 @@ static void sub_80A7230(u8 taskId) break; case 204: PlaySE(SE_SELECT); - sub_80F98A4(2); - sub_80F98A4(3); + StopVerticalScrollIndicators(LEFT_ARROW); + StopVerticalScrollIndicators(RIGHT_ARROW); gSpecialVar_ItemId = ITEM_POKE_BALL; sPopupMenuActionList = gUnknown_083C1708; gUnknown_02038564 = 2; diff --git a/src/field/item_use.c b/src/field/item_use.c index 55fb21814..219ef5080 100644 --- a/src/field/item_use.c +++ b/src/field/item_use.c @@ -40,7 +40,7 @@ extern void (*gFieldItemUseCallback)(u8); extern void (*gFieldCallback)(void); extern void (*gUnknown_0300485C)(void); -extern void (*gUnknown_03004AE4)(u8, u16, TaskFunc); +extern void (*gPokemonItemUseCallback)(u8, u16, TaskFunc); extern u8 gUnknown_02038561; extern u8 gLastFieldPokeMenuOpened; @@ -100,7 +100,7 @@ void ItemMenu_ConfirmNormalFade(u8 var) void ItemMenu_ConfirmComplexFade(u8 var) { ExecuteSwitchToOverworldFromItemUse(var); - fade_screen(1, 0); + FadeScreen(1, 0); } void SetUpItemUseOnFieldCallback(u8 taskId) @@ -259,7 +259,7 @@ void ItemUseOnFieldCB_Rod(u8 taskId) void ItemUseOutOfBattle_Itemfinder(u8 var) { - IncrementGameStat(0x27); + IncrementGameStat(GAME_STAT_USED_ITEMFINDER); gFieldItemUseCallback = (void *)ItemUseOnFieldCB_Itemfinder; SetUpItemUseOnFieldCallback(var); } @@ -832,7 +832,7 @@ void sub_80C9D98(u8 taskId) void ItemUseOutOfBattle_Medicine(u8 taskId) { - gUnknown_03004AE4 = UseMedicine; + gPokemonItemUseCallback = UseMedicine; sub_80C9D98(taskId); } @@ -850,26 +850,26 @@ void ItemUseOutOfBattle_SacredAsh(u8 taskId) break; } } - gUnknown_03004AE4 = sub_8070048; + gPokemonItemUseCallback = sub_8070048; gUnknown_02038561 = 4; ItemMenu_ConfirmNormalFade(taskId); } void ItemUseOutOfBattle_PPRecovery(u8 taskId) { - gUnknown_03004AE4 = DoPPRecoveryItemEffect; + gPokemonItemUseCallback = DoPPRecoveryItemEffect; sub_80C9D98(taskId); } void ItemUseOutOfBattle_PPUp(u8 taskId) { - gUnknown_03004AE4 = DoPPUpItemEffect; + gPokemonItemUseCallback = DoPPUpItemEffect; sub_80C9D98(taskId); } void ItemUseOutOfBattle_RareCandy(u8 taskId) { - gUnknown_03004AE4 = DoRareCandyItemEffect; + gPokemonItemUseCallback = DoRareCandyItemEffect; sub_80C9D98(taskId); } @@ -908,7 +908,7 @@ void sub_80C9F80(u8 var) void sub_80C9FC0(u8 var) { - gUnknown_03004AE4 = TeachMonTMMove; + gPokemonItemUseCallback = TeachMonTMMove; sub_80C9D98(var); } @@ -1009,7 +1009,7 @@ void ItemUseOutOfBattle_EscapeRope(u8 taskId) void ItemUseOutOfBattle_EvolutionStone(u8 var) { - gUnknown_03004AE4 = DoEvolutionStoneItemEffect; + gPokemonItemUseCallback = DoEvolutionStoneItemEffect; sub_80C9D98(var); } @@ -1078,19 +1078,19 @@ void sub_80CA3C0(u8 taskId) void ItemUseInBattle_Medicine(u8 var) { - gUnknown_03004AE4 = UseMedicine; + gPokemonItemUseCallback = UseMedicine; sub_80CA3C0(var); } void unref_sub_80CA410(u8 var) { - gUnknown_03004AE4 = sub_8070048; + gPokemonItemUseCallback = sub_8070048; sub_80CA3C0(var); } void ItemUseInBattle_PPRecovery(u8 var) { - gUnknown_03004AE4 = DoPPRecoveryItemEffect; + gPokemonItemUseCallback = DoPPRecoveryItemEffect; sub_80CA3C0(var); } diff --git a/src/field/menu_helpers.c b/src/field/menu_helpers.c index 76f0d367e..388d98ec7 100644 --- a/src/field/menu_helpers.c +++ b/src/field/menu_helpers.c @@ -18,7 +18,7 @@ static void sub_80F9834(struct Sprite *sprite); -static EWRAM_DATA u8 gUnknown_020388C0[4] = {0}; +static EWRAM_DATA u8 gVerticalScrollIndicatorIds[4] = {0}; static EWRAM_DATA struct YesNoFuncTable gUnknown_020388C4 = {0}; static TaskFunc gUnknown_0300074C; @@ -125,7 +125,7 @@ static const struct SpriteTemplate gSpriteTemplate_83E5A00 = .callback = SpriteCallbackDummy, }; -void sub_80F9020(void) +void ClearBGTilemapBuffers(void) { memset(&gBGTilemapBuffers[1], 0, 0x800); memset(&gBGTilemapBuffers[2], 0, 0x800); @@ -296,9 +296,6 @@ bool8 sub_80F9344(void) void sub_80F9368(void) { - u8 *addr; - u32 size; - REG_DISPCNT = 0; REG_BG3CNT = 0; REG_BG2CNT = 0; @@ -312,38 +309,24 @@ void sub_80F9368(void) REG_BG1VOFS = 0; REG_BG0HOFS = 0; REG_BG0VOFS = 0; - - addr = (u8 *)VRAM; - size = 0x18000; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } - + DmaFill16Large(3, 0, (u8 *)VRAM, 0x18000, 0x1000); DmaClear32(3, OAM, OAM_SIZE); DmaClear16(3, PLTT, PLTT_SIZE); } -void sub_80F9438(void) +void ClearVideoCallbacks(void) { SetVBlankCallback(NULL); SetHBlankCallback(NULL); } -void sub_80F944C(void) +void ClearVerticalScrollIndicatorPalettes(void) { u8 i; for (i = 0; i < 4; i++) { - gUnknown_020388C0[i] = 0xFF; + gVerticalScrollIndicatorIds[i] = 0xFF; } FreeSpritePaletteByTag(SCROLL_INDICATOR_PAL_TAG); @@ -401,92 +384,92 @@ void CreateVerticalScrollIndicators(u8 id, u16 x, u16 y) switch (id) { - case 0: - if (gUnknown_020388C0[0] == 0xFF) + case TOP_ARROW: + if (gVerticalScrollIndicatorIds[TOP_ARROW] == 0xFF) { - gUnknown_020388C0[0] = CreateSprite(&gSpriteTemplate_83E59D0, x, y, 0); - gSprites[gUnknown_020388C0[0]].data[2] = -1; - if (gUnknown_020388C0[1] != 0xFF) + gVerticalScrollIndicatorIds[TOP_ARROW] = CreateSprite(&gSpriteTemplate_83E59D0, x, y, 0); + gSprites[gVerticalScrollIndicatorIds[TOP_ARROW]].data[2] = -1; + if (gVerticalScrollIndicatorIds[BOTTOM_ARROW] != 0xFF) { - gSprites[gUnknown_020388C0[0]].pos2.y = gSprites[gUnknown_020388C0[1]].pos2.y * -1; - gSprites[gUnknown_020388C0[0]].data[3] = gSprites[gUnknown_020388C0[1]].data[3]; + gSprites[gVerticalScrollIndicatorIds[TOP_ARROW]].pos2.y = gSprites[gVerticalScrollIndicatorIds[BOTTOM_ARROW]].pos2.y * -1; + gSprites[gVerticalScrollIndicatorIds[TOP_ARROW]].data[3] = gSprites[gVerticalScrollIndicatorIds[BOTTOM_ARROW]].data[3]; } else { - gSprites[gUnknown_020388C0[0]].data[3] = 0; + gSprites[gVerticalScrollIndicatorIds[TOP_ARROW]].data[3] = 0; } } break; - case 1: - if (gUnknown_020388C0[1] == 0xFF) + case BOTTOM_ARROW: + if (gVerticalScrollIndicatorIds[BOTTOM_ARROW] == 0xFF) { - gUnknown_020388C0[1] = CreateSprite(&gSpriteTemplate_83E59D0, x, y, 0); - gSprites[gUnknown_020388C0[1]].data[2] = 1; - if (gUnknown_020388C0[0] != 0xFF) + gVerticalScrollIndicatorIds[BOTTOM_ARROW] = CreateSprite(&gSpriteTemplate_83E59D0, x, y, 0); + gSprites[gVerticalScrollIndicatorIds[BOTTOM_ARROW]].data[2] = 1; + if (gVerticalScrollIndicatorIds[TOP_ARROW] != 0xFF) { - gSprites[gUnknown_020388C0[1]].pos2.y = gSprites[gUnknown_020388C0[0]].pos2.y * -1; - gSprites[gUnknown_020388C0[1]].data[3] = gSprites[gUnknown_020388C0[0]].data[3]; + gSprites[gVerticalScrollIndicatorIds[BOTTOM_ARROW]].pos2.y = gSprites[gVerticalScrollIndicatorIds[TOP_ARROW]].pos2.y * -1; + gSprites[gVerticalScrollIndicatorIds[BOTTOM_ARROW]].data[3] = gSprites[gVerticalScrollIndicatorIds[TOP_ARROW]].data[3]; } else { - gSprites[gUnknown_020388C0[1]].data[3] = 0; + gSprites[gVerticalScrollIndicatorIds[BOTTOM_ARROW]].data[3] = 0; } } break; - case 2: - if (gUnknown_020388C0[2] == 0xFF) + case LEFT_ARROW: + if (gVerticalScrollIndicatorIds[LEFT_ARROW] == 0xFF) { - gUnknown_020388C0[2] = CreateSprite(&gSpriteTemplate_83E59E8, x, y, 0); - gSprites[gUnknown_020388C0[2]].data[0] = -1; - if (gUnknown_020388C0[3] != 0xFF) + gVerticalScrollIndicatorIds[LEFT_ARROW] = CreateSprite(&gSpriteTemplate_83E59E8, x, y, 0); + gSprites[gVerticalScrollIndicatorIds[LEFT_ARROW]].data[0] = -1; + if (gVerticalScrollIndicatorIds[RIGHT_ARROW] != 0xFF) { - gSprites[gUnknown_020388C0[2]].pos2.x = gSprites[gUnknown_020388C0[3]].pos2.x * -1; - gSprites[gUnknown_020388C0[2]].data[1] = gSprites[gUnknown_020388C0[3]].data[1]; + gSprites[gVerticalScrollIndicatorIds[LEFT_ARROW]].pos2.x = gSprites[gVerticalScrollIndicatorIds[RIGHT_ARROW]].pos2.x * -1; + gSprites[gVerticalScrollIndicatorIds[LEFT_ARROW]].data[1] = gSprites[gVerticalScrollIndicatorIds[RIGHT_ARROW]].data[1]; } else { - gSprites[gUnknown_020388C0[2]].data[1] = 0; + gSprites[gVerticalScrollIndicatorIds[LEFT_ARROW]].data[1] = 0; } } break; - case 3: - if (gUnknown_020388C0[3] == 0xFF) + case RIGHT_ARROW: + if (gVerticalScrollIndicatorIds[RIGHT_ARROW] == 0xFF) { - gUnknown_020388C0[3] = CreateSprite(&gSpriteTemplate_83E59E8, x, y, 0); - gSprites[gUnknown_020388C0[3]].data[0] = 1; - if (gUnknown_020388C0[2] != 0xFF) + gVerticalScrollIndicatorIds[RIGHT_ARROW] = CreateSprite(&gSpriteTemplate_83E59E8, x, y, 0); + gSprites[gVerticalScrollIndicatorIds[RIGHT_ARROW]].data[0] = 1; + if (gVerticalScrollIndicatorIds[LEFT_ARROW] != 0xFF) { - gSprites[gUnknown_020388C0[3]].pos2.x = gSprites[gUnknown_020388C0[2]].pos2.x * -1; - gSprites[gUnknown_020388C0[3]].data[1] = gSprites[gUnknown_020388C0[2]].data[1]; + gSprites[gVerticalScrollIndicatorIds[RIGHT_ARROW]].pos2.x = gSprites[gVerticalScrollIndicatorIds[LEFT_ARROW]].pos2.x * -1; + gSprites[gVerticalScrollIndicatorIds[RIGHT_ARROW]].data[1] = gSprites[gVerticalScrollIndicatorIds[LEFT_ARROW]].data[1]; } else { - gSprites[gUnknown_020388C0[3]].data[1] = 0; + gSprites[gVerticalScrollIndicatorIds[RIGHT_ARROW]].data[1] = 0; } } break; } - StartSpriteAnim(&gSprites[gUnknown_020388C0[id]], id & 1); + StartSpriteAnim(&gSprites[gVerticalScrollIndicatorIds[id]], id & 1); } -void sub_80F979C(u8 id, bool8 invisible) +void SetVerticalScrollIndicators(u8 id, bool8 invisible) { - if (id < 4 && gUnknown_020388C0[id] != 0xFF) + if (id < 4 && gVerticalScrollIndicatorIds[id] != 0xFF) { - gSprites[gUnknown_020388C0[id]].invisible = invisible; + gSprites[gVerticalScrollIndicatorIds[id]].invisible = invisible; } } void DestroyVerticalScrollIndicator(u8 id) { - if (id < 4 && gUnknown_020388C0[id] != 0xFF) + if (id < 4 && gVerticalScrollIndicatorIds[id] != 0xFF) { - DestroySprite(&gSprites[gUnknown_020388C0[id]]); - gUnknown_020388C0[id] = 0xFF; + DestroySprite(&gSprites[gVerticalScrollIndicatorIds[id]]); + gVerticalScrollIndicatorIds[id] = 0xFF; } } @@ -530,43 +513,43 @@ static void sub_80F9834(struct Sprite *sprite) } } -void sub_80F98A4(u8 id) +void StopVerticalScrollIndicators(u8 id) { - if (gUnknown_020388C0[id] != 0xFF && id < 4) + if (gVerticalScrollIndicatorIds[id] != 0xFF && id < 4) { - gSprites[gUnknown_020388C0[id]].callback = SpriteCallbackDummy; + gSprites[gVerticalScrollIndicatorIds[id]].callback = SpriteCallbackDummy; } } void StartVerticalScrollIndicators(u8 id) { - if (gUnknown_020388C0[id] != 0xFF && id < 4) + if (gVerticalScrollIndicatorIds[id] != 0xFF && id < 4) { - gSprites[gUnknown_020388C0[id]].callback = sub_80F9834; + gSprites[gVerticalScrollIndicatorIds[id]].callback = sub_80F9834; } } -static void sub_80F9914(u8 id) +static void ResetVerticalScrollIndicators(u8 id) { - if (gUnknown_020388C0[id] != 0xFF && id < 4) + if (gVerticalScrollIndicatorIds[id] != 0xFF && id < 4) { - gSprites[gUnknown_020388C0[id]].pos2.x = 0; - gSprites[gUnknown_020388C0[id]].pos2.y = 0; - gSprites[gUnknown_020388C0[id]].data[1] = 0; - gSprites[gUnknown_020388C0[id]].data[3] = 0; + gSprites[gVerticalScrollIndicatorIds[id]].pos2.x = 0; + gSprites[gVerticalScrollIndicatorIds[id]].pos2.y = 0; + gSprites[gVerticalScrollIndicatorIds[id]].data[1] = 0; + gSprites[gVerticalScrollIndicatorIds[id]].data[3] = 0; } } void PauseVerticalScrollIndicator(u8 id) { - sub_80F98A4(id); - sub_80F9914(id); + StopVerticalScrollIndicators(id); + ResetVerticalScrollIndicators(id); } -void sub_80F9988(u8 id, u8 priority) +void SetVerticalScrollIndicatorPriority(u8 id, u8 priority) { - if (gUnknown_020388C0[id] != 0xFF && id < 4) + if (gVerticalScrollIndicatorIds[id] != 0xFF && id < 4) { - gSprites[gUnknown_020388C0[id]].oam.priority = priority; + gSprites[gVerticalScrollIndicatorIds[id]].oam.priority = priority; } } diff --git a/src/field/money.c b/src/field/money.c index b85ed8009..3b7268dbc 100644 --- a/src/field/money.c +++ b/src/field/money.c @@ -100,6 +100,8 @@ void GetMoneyAmountText(u8 *buffer, u32 amount, u8 arg2) width = 7; else if (amount > 99999) width = 6; + // A special sprite is used for 10000 in the decoration + // shop, so be sure to account for this. else if (amount > 10000) width = 5; else if (amount > 999) @@ -175,7 +177,7 @@ void sub_80B7AEC(u32 arg0, u8 left, u8 top) } __attribute__((naked)) -void sub_80B7B34(u8 var1, u8 var2, int var3) +void Draw10000Sprite(u8 var1, u8 var2, int var3) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ diff --git a/src/field/overworld.c b/src/field/overworld.c index 8346ce3f9..07135080e 100644 --- a/src/field/overworld.c +++ b/src/field/overworld.c @@ -592,7 +592,7 @@ bool8 sub_80538D0(u16 x, u16 y) void sub_80538F0(u8 mapGroup, u8 mapNum) { - s32 i; + s32 paletteIndex; Overworld_SetWarpDestination(mapGroup, mapNum, -1, -1, -1); sub_8053F0C(); @@ -613,8 +613,8 @@ void sub_80538F0(u8 mapGroup, u8 mapNum) sub_8056D38(gMapHeader.mapData); apply_map_tileset2_palette(gMapHeader.mapData); - for (i = 6; i < 12; i++) - sub_807D874(i); + for (paletteIndex = 6; paletteIndex < 12; paletteIndex++) + ApplyWeatherGammaShiftToPal(paletteIndex); sub_8072ED0(); UpdateLocationHistoryForRoamer(); @@ -1759,29 +1759,12 @@ void do_load_map_stuff_loop(u8 *a1) void sub_8054BA8(void) { - u8 *addr; - u32 size; - REG_DISPCNT = 0; ScanlineEffect_Stop(); DmaClear16(3, PLTT + 2, PLTT_SIZE - 2); - - addr = (void *)VRAM; - size = 0x18000; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } - + DmaFill16Large(3, 0, (void *)(VRAM + 0x0), 0x18000, 0x1000); ResetOamRange(0, 128); LoadOam(); } diff --git a/src/field/party_menu.c b/src/field/party_menu.c index e26b801bc..4fdb17786 100644 --- a/src/field/party_menu.c +++ b/src/field/party_menu.c @@ -1108,27 +1108,11 @@ bool8 InitPartyMenu(void) #else bool8 InitPartyMenu(void) { - u8 *addr; - u32 size; - switch (gMain.state) { case 0: SetVBlankCallback(NULL); - addr = (u8 *)VRAM; - size = VRAM_SIZE; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } - + DmaFill16Large(3, 0, (void *)(VRAM + 0x0), VRAM_SIZE, 0x1000); DmaClear32(3, OAM, OAM_SIZE); DmaClear16(3, PLTT, PLTT_SIZE); @@ -1282,9 +1266,7 @@ void ReDrawPartyMonBackgrounds(void) { if (ewram1B000.unk261) { - const void *src = gBGTilemapBuffers[2]; - void *dest = (void *)(BG_VRAM + 0x3000); - DmaCopy16(3, src, dest, 0x800); + DmaCopy16Defvars(3, gBGTilemapBuffers[2], (void *)(BG_VRAM + 0x3000), 0x800); if (ewram1B000.unk261 == 2) { diff --git a/src/field/player_pc.c b/src/field/player_pc.c index 1d504586c..27427ecaa 100644 --- a/src/field/player_pc.c +++ b/src/field/player_pc.c @@ -29,9 +29,9 @@ extern void DestroyVerticalScrollIndicator(u8); extern void PauseVerticalScrollIndicator(u8); extern void LoadScrollIndicatorPalette(void); extern void ClearMailStruct(struct MailStruct *); -extern u8 sub_807D770(void); +extern u8 IsWeatherNotFadingIn(void); extern void sub_808B020(void); -extern void sub_80F944C(void); +extern void ClearVerticalScrollIndicatorPalettes(void); static EWRAM_DATA const u8 *gPcItemMenuOptionOrder = NULL; @@ -357,12 +357,12 @@ static void Task_ItemStorage_Deposit(u8 taskId) static void ItemStorage_Deposit(u8 taskId) { TASK.FUNC = Task_ItemStorage_Deposit; - fade_screen(1, 0); + FadeScreen(1, 0); } static void ItemStorage_HandleReturnToProcessInput(u8 taskId) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) TASK.FUNC = ItemStorageMenuProcessInput; } @@ -563,8 +563,8 @@ static void ItemStorage_ProcessInput(u8 taskId) static void ItemStorage_GoBackToPlayerPCMenu(u8 taskId) { BuyMenuFreeMemory(); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); Menu_EraseWindowRect(0, 0, 29, 19); Menu_DisplayDialogueFrame(); InitItemStorageMenu(TASK.CURRENT_ITEM_STORAGE_MENU); @@ -576,8 +576,8 @@ static void ItemStorage_DoItemAction(u8 taskId) s16 *data = TASK.data; u8 trueIndex = PAGE_INDEX + ITEMS_ABOVE_TOP; - PauseVerticalScrollIndicator(0); - PauseVerticalScrollIndicator(1); // PauseVerticalScrollIndicator + PauseVerticalScrollIndicator(TOP_ARROW); + PauseVerticalScrollIndicator(BOTTOM_ARROW); if(CURRENT_ITEM_STORAGE_MENU == ITEMPC_MENU_WITHDRAW) { @@ -663,8 +663,8 @@ static void ItemStorage_HandleQuantityRolling(u8 taskId) { PlaySE(SE_SELECT); Menu_EraseWindowRect(6, 6, 0xD, 0xB); - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); ItemStorage_PrintItemPcResponse(gSaveBlock1.pcItems[ITEMS_ABOVE_TOP + PAGE_INDEX].itemId); // why not use trueIndex? TASK.FUNC = ItemStorage_ProcessInput; } @@ -724,8 +724,8 @@ static void ItemStorage_ResumeInputFromNoToss(u8 taskId) Menu_EraseWindowRect(0x6, 0x6, 0xD, 0xB); InitMenu(0, 16, 2, NUM_PAGE_ITEMS, PAGE_INDEX, 0xD); - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); ItemStorage_PrintItemPcResponse(gSaveBlock1.pcItems[ITEMS_ABOVE_TOP + PAGE_INDEX].itemId); TASK.FUNC = ItemStorage_ProcessInput; } @@ -757,8 +757,8 @@ static void ItemStorage_WaitPressHandleResumeProcessInput(u8 taskId) if(gMain.newKeys & A_BUTTON || gMain.newKeys == B_BUTTON) { ItemStorage_PrintItemPcResponse(gSaveBlock1.pcItems[ITEMS_ABOVE_TOP + PAGE_INDEX].itemId); - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); TASK.FUNC = ItemStorage_ProcessInput; } } @@ -766,8 +766,8 @@ static void ItemStorage_WaitPressHandleResumeProcessInput(u8 taskId) static void ItemStorage_HandleResumeProcessInput(u8 taskId) { Menu_EraseWindowRect(0x6, 0x6, 0xD, 0xB); - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); ItemStorage_DrawBothListAndDescription(taskId); TASK.FUNC = ItemStorage_ProcessInput; } @@ -903,14 +903,14 @@ static void ItemStorage_DrawItemList(u8 taskId) Menu_BlankWindowRect(16, yCoord + 4, 0x1C, 0x12); if (ITEMS_ABOVE_TOP != 0) - CreateVerticalScrollIndicators(0, 0xB8, 8); + CreateVerticalScrollIndicators(TOP_ARROW, 0xB8, 8); else - DestroyVerticalScrollIndicator(0); + DestroyVerticalScrollIndicator(TOP_ARROW); if (ITEMS_ABOVE_TOP + NUM_PAGE_ITEMS <= NUM_ITEMS) - CreateVerticalScrollIndicators(1, 0xB8, 0x98); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0xB8, 0x98); else - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } static void ItemStorage_PrintItemPcResponse(u16 itemId) @@ -974,7 +974,7 @@ static void ItemStorage_GoBackToItemPCMenu(u8 taskId, u8 var) { s16 *data = TASK.data; - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); ItemStorage_LoadPalette(); Menu_DrawStdWindowFrame(0xF, 0, 0x1D, 0x13); @@ -1055,19 +1055,19 @@ static void Mailbox_DrawMailList(u8 taskId) // taskId is unused Menu_BlankWindowRect(0x15, yCoord + 4, 0x1C, 0x12); if (eMailboxInfo.itemsAbove != 0) - CreateVerticalScrollIndicators(0, 0xC8, 8); + CreateVerticalScrollIndicators(TOP_ARROW, 0xC8, 8); else - DestroyVerticalScrollIndicator(0); + DestroyVerticalScrollIndicator(TOP_ARROW); if (eMailboxInfo.itemsAbove + eMailboxInfo.pageItems <= eMailboxInfo.count) - CreateVerticalScrollIndicators(1, 0xC8, 0x98); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0xC8, 0x98); else - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } static void Mailbox_DrawMailboxMenu(u8 taskId) { - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); Menu_EraseWindowRect(0, 0, 0x1D, 0x13); Menu_DrawStdWindowFrame(0, 0, 0x8, 0x3); @@ -1137,8 +1137,8 @@ static void Mailbox_ProcessInput(u8 taskId) static void Mailbox_CloseScrollIndicators(void) { BuyMenuFreeMemory(); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); } static void Mailbox_PrintWhatToDoWithPlayerMailText(u8 taskId) @@ -1196,7 +1196,7 @@ static void Mailbox_MailOptionsProcessInput(u8 taskId) static void Mailbox_DoMailRead(u8 taskId) { - fade_screen(1, 0); + FadeScreen(1, 0); TASK.FUNC = Mailbox_FadeAndReadMail; } @@ -1211,7 +1211,7 @@ static void Mailbox_FadeAndReadMail(u8 taskId) static void Mailbox_HandleReturnToProcessInput(u8 taskId) // Mailbox_HandleReturnToProcessInput { - if(sub_807D770() == TRUE) // is black fade finished? why not gPaletteFade.active? + if (IsWeatherNotFadingIn() == TRUE) // is black fade finished? why not gPaletteFade.active? TASK.FUNC = Mailbox_ProcessInput; } @@ -1280,7 +1280,7 @@ static void Mailbox_Give(u8 taskId) Mailbox_NoPokemonForMail(taskId); // cannot be reached normally else { - fade_screen(1, 0); + FadeScreen(1, 0); TASK.FUNC = Mailbox_DoGiveMailPokeMenu; } } diff --git a/src/field/pokeblock.c b/src/field/pokeblock.c index b69d8ac06..43684dfec 100644 --- a/src/field/pokeblock.c +++ b/src/field/pokeblock.c @@ -1,7 +1,3 @@ -// - -// - #include "global.h" #include "overworld.h" #include "sprite.h" @@ -250,14 +246,10 @@ static void sub_810B674(void) static void sub_810B68C(void) { - u16 *src; - vu16 *dest; LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); - src = gBGTilemapBuffers[2]; - dest = (vu16 *)(VRAM + 0x7800); - DmaCopy16(3, src, dest, sizeof gBGTilemapBuffers[2]); + DmaCopy16Defvars(3, gBGTilemapBuffers[2], (void *)(VRAM + 0x7800), sizeof gBGTilemapBuffers[2]); } static bool8 sub_810B6C0(void) @@ -266,7 +258,7 @@ static bool8 sub_810B6C0(void) switch (gMain.state) { case 0: - sub_80F9438(); + ClearVideoCallbacks(); sub_80F9368(); REG_BG2CNT = BGCNT_SCREENBASE(15) | BGCNT_CHARBASE(2) | BGCNT_PRIORITY(2); REG_BLDCNT = 0; @@ -328,10 +320,10 @@ static bool8 sub_810B6C0(void) } break; case 12: - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); - CreateVerticalScrollIndicators(0, 0xb0, 0x08); - CreateVerticalScrollIndicators(1, 0xb0, 0x98); + CreateVerticalScrollIndicators(TOP_ARROW, 0xb0, 0x08); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0xb0, 0x98); gMain.state++; break; case 13: @@ -577,19 +569,19 @@ static void sub_810BDAC(bool8 flag) } if (gUnknown_02039248.unk1) { - sub_80F979C(0, 0); + SetVerticalScrollIndicators(TOP_ARROW, VISIBLE); } else { - sub_80F979C(0, 1); + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); } if (gUnknown_02039248.unk2 > gUnknown_02039248.unk3 && gUnknown_02039248.unk1 + gUnknown_02039248.unk3 != gUnknown_02039248.unk2) { - sub_80F979C(1, 0); + SetVerticalScrollIndicators(BOTTOM_ARROW, VISIBLE); } else { - sub_80F979C(1, 1); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); } for (i=0; i<5; i++) { @@ -793,8 +785,8 @@ static void sub_810C23C(u8 taskId) static void sub_810C2B0(void) { - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); BuyMenuFreeMemory(); } @@ -827,8 +819,8 @@ static void sub_810C368(u8 taskId) int v0 = 0; if (gUnknown_02039244 > 1) v0 = 2; - sub_80F98A4(0); - sub_80F98A4(1); + StopVerticalScrollIndicators(TOP_ARROW); + StopVerticalScrollIndicators(BOTTOM_ARROW); BasicInitMenuWindow(&gWindowTemplate_81E6E50); Menu_DrawStdWindowFrame(7, v0 + 4, 13, 11); Menu_PrintItemsReordered(8, v0 + 5, gUnknown_0203924C, gUnknown_083F7EF4, gUnknown_03000758); @@ -895,7 +887,7 @@ static void sub_810C540(u8 taskId) static void sub_810C5C0(u8 taskId) { - sub_80F979C(1, 1); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); gTasks[taskId].func = sub_810C540; } @@ -917,11 +909,11 @@ static void sub_810C610(u8 taskId) static void sub_810C668(u8 taskId) { - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); if (gUnknown_02039248.unk2 > gUnknown_02039248.unk3 && gUnknown_02039248.unk1 + gUnknown_02039248.unk3 != gUnknown_02039248.unk2) { - sub_80F979C(1, 0); + SetVerticalScrollIndicators(BOTTOM_ARROW, VISIBLE); } BasicInitMenuWindow(&gWindowTemplate_81E6E50); Menu_EraseWindowRect(7, 6, 13, 11); @@ -941,14 +933,14 @@ static void sub_810C704(u8 taskId) { BasicInitMenuWindow(&gWindowTemplate_81E6E34); sub_810BC84(gUnknown_02039248.unk1); - sub_80F979C(1, 1); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); gTasks[taskId].func = sub_810C6DC; } static void sub_810C748(u8 taskId) { - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); Menu_DestroyCursor(); Menu_EraseWindowRect(7, 4, 13, 11); gTasks[taskId].func = sub_810BF7C; diff --git a/src/field/region_map.c b/src/field/region_map.c index 9194e791d..7bfda1a81 100644 --- a/src/field/region_map.c +++ b/src/field/region_map.c @@ -1608,8 +1608,8 @@ static void PrintFlyTargetName(void) { if (ewram0_3.regionMap.unk16 == 2 || ewram0_3.regionMap.unk16 == 4) { - u16 i = 0; - int zero; + u16 i; + bool32 drawFrameDisabled = FALSE; for (i = 0; i < ARRAY_COUNT(gUnknown_083E79C0); i++) { @@ -1627,9 +1627,8 @@ static void PrintFlyTargetName(void) break; } } - // This check is always true, but somehow the compiler still performed it. - asm("mov %0, #0\n":"=r"(zero)); // zero = 0 - if (zero == 0) + + if (!drawFrameDisabled) { Menu_DrawStdWindowFrame(16, 16, 29, 19); Menu_PrintText(ewram0_3.regionMap.mapSectionName, 17, 17); diff --git a/src/field/safari_zone.c b/src/field/safari_zone.c index 2829001f6..f371b08b3 100644 --- a/src/field/safari_zone.c +++ b/src/field/safari_zone.c @@ -56,7 +56,7 @@ void ResetSafariZoneFlag(void) void EnterSafariMode(void) { - IncrementGameStat(0x11); + IncrementGameStat(GAME_STAT_ENTERED_SAFARI_ZONE); SetSafariZoneFlag(); ClearAllPokeblockFeeders(); gNumSafariBalls = 30; diff --git a/src/field/scrcmd.c b/src/field/scrcmd.c index e795fd8ed..bc5cd0b1d 100644 --- a/src/field/scrcmd.c +++ b/src/field/scrcmd.c @@ -626,7 +626,7 @@ bool8 IsPaletteNotActive(void) bool8 ScrCmd_fadescreen(struct ScriptContext *ctx) { - fade_screen(ScriptReadByte(ctx), 0); + FadeScreen(ScriptReadByte(ctx), 0); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } @@ -636,7 +636,7 @@ bool8 ScrCmd_fadescreenspeed(struct ScriptContext *ctx) u8 duration = ScriptReadByte(ctx); u8 delay = ScriptReadByte(ctx); - fade_screen(duration, delay); + FadeScreen(duration, delay); SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } @@ -1755,7 +1755,7 @@ bool8 ScrCmd_pokemart(struct ScriptContext *ctx) { void *ptr = (void *)ScriptReadWord(ctx); - CreatePokemartMenu(ptr); + Shop_CreatePokemartMenu(ptr); ScriptContext1_Stop(); return TRUE; } @@ -1764,7 +1764,7 @@ bool8 ScrCmd_pokemartdecoration(struct ScriptContext *ctx) { void *ptr = (void *)ScriptReadWord(ctx); - CreateDecorationShop1Menu(ptr); + Shop_CreateDecorationShop1Menu(ptr); ScriptContext1_Stop(); return TRUE; } @@ -1773,7 +1773,7 @@ bool8 ScrCmd_pokemartdecoration2(struct ScriptContext *ctx) { void *ptr = (void *)ScriptReadWord(ctx); - CreateDecorationShop2Menu(ptr); + Shop_CreateDecorationShop2Menu(ptr); ScriptContext1_Stop(); return TRUE; } diff --git a/src/field/secret_base.c b/src/field/secret_base.c index 1bdc76b23..082e8ebc6 100644 --- a/src/field/secret_base.c +++ b/src/field/secret_base.c @@ -348,7 +348,7 @@ void sub_80BBA48(u8 taskid) void sub_80BBAF0(void) { CreateTask(sub_80BBA48, 0); - fade_screen(1, 0); + FadeScreen(1, 0); saved_warp2_set(0, gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1); } @@ -362,7 +362,7 @@ bool8 sub_80BBB24(void) void sub_80BBB50(u8 taskid) { FieldObjectTurn(&(gMapObjects[gPlayerAvatar.mapObjectId]), 2); - if (sub_807D770() == 1) { + if (IsWeatherNotFadingIn() == 1) { EnableBothScriptContexts(); DestroyTask(taskid); } @@ -397,7 +397,7 @@ void sub_80BBC78(void) { u8 taskid = CreateTask(sub_80BBBEC, 0); gTasks[taskid].data[0] = 0; - fade_screen(1, 0); + FadeScreen(1, 0); } bool8 CurrentMapIsSecretBase(void) @@ -534,7 +534,7 @@ void sub_80BC074(u8 taskid) void sub_80BC0F8(void) { CreateTask(sub_80BC074, 0); - fade_screen(1, 0); + FadeScreen(1, 0); } void sub_80BC114(void) { @@ -895,7 +895,7 @@ void Task_SecretBasePC_Registry(u8 taskId) s16 *taskData; ScriptContext2_Enable(); - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); LoadScrollIndicatorPalette(); taskData = gTasks[taskId].data; @@ -959,17 +959,17 @@ void sub_80BC6B0(u8 taskId) { Menu_BlankWindowRect(18, 2 * n + 2, 28, 2 * n + 3); Menu_PrintText(gUnknownText_Exit, 18, 2 * n + 2); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); if (n != 7) Menu_BlankWindowRect(18, ((n << 25) + (1 << 26)) >> 24, 28, 18); // the shifts are needed to match } else - CreateVerticalScrollIndicators(1, 0xbc, 0x98); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 0xbc, 0x98); if (taskData[2] == 0) - DestroyVerticalScrollIndicator(0); + DestroyVerticalScrollIndicator(TOP_ARROW); else - CreateVerticalScrollIndicators(0, 0xbc, 0x08); + CreateVerticalScrollIndicators(TOP_ARROW, 0xbc, 0x08); } void sub_80BC7D8(u8 taskId) @@ -1064,8 +1064,8 @@ u8 sub_80BC948(u8 a) void sub_80BC980(u8 taskId) { - PauseVerticalScrollIndicator(0); - PauseVerticalScrollIndicator(1); + PauseVerticalScrollIndicator(TOP_ARROW); + PauseVerticalScrollIndicator(BOTTOM_ARROW); Menu_DrawStdWindowFrame(1, 0, 12, 5); Menu_PrintItems(2, 1, 2, (const struct MenuAction *)gUnknown_083D13D4); InitMenu(0, 2, 1, 2, 0, 10); @@ -1106,8 +1106,8 @@ void sub_80BCA84(u8 taskId) { s16 *taskData = gTasks[taskId].data; - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); Menu_DestroyCursor(); Menu_EraseWindowRect(0, 0, 29, 19); @@ -1165,8 +1165,8 @@ void sub_80BCBF8(u8 taskId) InitMenu(0, 18, 2, taskData[3] + 1, taskData[1], 11); Menu_EraseWindowRect(1, 0, 12, 5); - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); gTasks[taskId].func = sub_80BC824; } @@ -1176,8 +1176,8 @@ void sub_80BCC54(u8 taskId) u16 curBaseIndex = VarGet(VAR_CURRENT_SECRET_BASE); BuyMenuFreeMemory(); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); if (curBaseIndex == 0) { diff --git a/src/field/shop.c b/src/field/shop.c index df271743d..852ccddda 100644 --- a/src/field/shop.c +++ b/src/field/shop.c @@ -28,54 +28,66 @@ #include "field_camera.h" #include "ewram.h" -extern bool8 sub_80A52C4(u8, u8); +extern bool8 SellMenu_QuantityRoller(u8, u8); extern u8 gBuyMenuFrame_Gfx[]; extern u16 gBuyMenuFrame_Tilemap[]; extern u16 gMenuMoneyPal[16]; -void sub_80B39D0(int var1, int var2, bool32 hasControlCode); -void sub_80B3A70(void); -void sub_80B4378(u8); -void sub_80B43F0(u8); -void Task_ExitBuyMenu(u8); -void sub_80B4470(u8); -void sub_80B2EFC(u8 taskId); -void sub_80B2F30(u8 taskId); -void HandleShopMenuQuit(u8 taskId); -void sub_80B3BF4(u8 taskId); -void sub_80B3D7C(u8 taskId); +static void Shop_DisplayPriceInList(int firstItemId, int lastItemId, bool32 hasControlCode); +static void Shop_PrintItemDescText(void); +static void Task_ReturnToBuyMenu(u8); +static void Task_ExitBuyMenu(u8); +static void Task_ExitBuyMenuDoFade(u8); +static void Task_UpdatePurchaseHistory(u8); +static void Task_HandleShopMenuBuy(u8 taskId); +static void Task_HandleShopMenuSell(u8 taskId); +static void Task_HandleShopMenuQuit(u8 taskId); +static void Task_DoItemPurchase(u8 taskId); +static void Task_CancelItemPurchase(u8 taskId); +static void Task_DoBuySellMenu(u8); +static void Shop_FadeAndRunBuySellCallback(u8); +static void BuyMenuDrawGraphics(void); +static void sub_80B3240(void); +static void DrawFirstMartScrollIndicators(void); +static void Shop_DrawViewport(void); +static void Shop_InitMenus(int, int); +static void Shop_PrintItemDesc(void); +static void Shop_DoCursorAction(u8); +static void Shop_LoadViewportObjects(void); +static void Shop_AnimViewportObjects(void); // iwram static struct MartInfo gMartInfo; // ewram EWRAM_DATA u32 gMartTotalCost = 0; -EWRAM_DATA s16 gUnknown_020386A4[16][4] = {0}; -EWRAM_DATA struct ItemSlot gUnknown_02038724[3] = {0}; // tv.c uses this, so it cant be static -EWRAM_DATA u8 gUnknown_02038730 = 0; -EWRAM_DATA u8 gUnknown_02038731 = 0; +EWRAM_DATA s16 gMartViewportObjects[16][4] = {0}; +EWRAM_DATA struct ItemSlot gMartPurchaseHistory[3] = {0}; +EWRAM_DATA u8 gMartPurchaseHistoryId = 0; + +EWRAM_DATA u8 gUnknown_02038731 = 0; // This really should be in fldeff_escalator, but being in a new file aligns the ewram, which doesnt match the ROM. // rodata static const struct MenuAction2 sBuySellQuitMenuActions[] = { - { MartText_Buy, sub_80B2EFC }, - { MartText_Sell, sub_80B2F30 }, - { MartText_Quit2, HandleShopMenuQuit }, + { MartText_Buy, Task_HandleShopMenuBuy }, + { MartText_Sell, Task_HandleShopMenuSell }, + { MartText_Quit2, Task_HandleShopMenuQuit }, }; -static const u8 gUnknown_083CC6E8[] = {0, 1, 2}; // BUY SELL EXIT -static const u8 gUnknown_083CC6EB[] = {0, 2}; // BUY EXIT +static const u8 gMartBuySellOptionList[] = {SHOP_BUY, SHOP_SELL, SHOP_EXIT}; +static const u8 gMartBuyNoSellOptionList[] = {SHOP_BUY, SHOP_EXIT}; static const u16 gUnusedMartArray[] = {0x2, 0x3, 0x4, 0xD, 0x121, 0xE, 0xE, 0xE, 0xE, 0xE, 0xE, 0x0, 0x0}; -static const struct YesNoFuncTable gUnknown_083CC708[] = +static const struct YesNoFuncTable sShopPurchaseYesNoFuncs[] = { - sub_80B3BF4, - sub_80B3D7C + Task_DoItemPurchase, + Task_CancelItemPurchase }; -u8 CreateShopMenu(u8 martType) +static u8 CreateShopMenu(u8 martType) { ScriptContext2_Enable(); gMartInfo.martType = martType; @@ -85,25 +97,25 @@ u8 CreateShopMenu(u8 martType) { gMartInfo.numChoices = 2; Menu_DrawStdWindowFrame(0, 0, 10, 7); - Menu_PrintItemsReordered(1, 1, 3, sBuySellQuitMenuActions, gUnknown_083CC6E8); + Menu_PrintItemsReordered(1, 1, 3, sBuySellQuitMenuActions, gMartBuySellOptionList); } else { gMartInfo.numChoices = 1; Menu_DrawStdWindowFrame(0, 0, 10, 5); - Menu_PrintItemsReordered(1, 1, 2, sBuySellQuitMenuActions, gUnknown_083CC6EB); + Menu_PrintItemsReordered(1, 1, 2, sBuySellQuitMenuActions, gMartBuyNoSellOptionList); } InitMenu(0, 1, 1, gMartInfo.numChoices + 1, 0, 9); // add 1 for cancel - return CreateTask(sub_80B2E38, 8); + return CreateTask(Task_DoBuySellMenu, 8); } -void SetShopMenuCallback(void *callbackPtr) +static void SetShopMenuCallback(void *callbackPtr) { gMartInfo.callback = callbackPtr; } -void SetShopItemsForSale(u16 *items) +static void SetShopItemsForSale(u16 *items) { u16 i = 0; @@ -117,9 +129,9 @@ void SetShopItemsForSale(u16 *items) } } -void sub_80B2E38(u8 var) +static void Task_DoBuySellMenu(u8 taskId) { - const u8 local = var; + const u8 taskIdConst = taskId; // why is a local const needed to match? if (gMain.newAndRepeatedKeys & DPAD_UP) { @@ -142,37 +154,37 @@ void sub_80B2E38(u8 var) PlaySE(SE_SELECT); if (gMartInfo.martType == MART_TYPE_0) { - sBuySellQuitMenuActions[gUnknown_083CC6E8[gMartInfo.cursor]].func(local); + sBuySellQuitMenuActions[gMartBuySellOptionList[gMartInfo.cursor]].func(taskIdConst); } else { - sBuySellQuitMenuActions[gUnknown_083CC6EB[gMartInfo.cursor]].func(local); + sBuySellQuitMenuActions[gMartBuyNoSellOptionList[gMartInfo.cursor]].func(taskIdConst); } } else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - HandleShopMenuQuit(local); + Task_HandleShopMenuQuit(taskIdConst); } } -void sub_80B2EFC(u8 taskId) +static void Task_HandleShopMenuBuy(u8 taskId) { gTasks[taskId].data[8] = (u32)BuyMenuDrawGraphics >> 16; gTasks[taskId].data[9] = (u32)BuyMenuDrawGraphics; - gTasks[taskId].func = sub_80B2FA0; - fade_screen(1, 0); + gTasks[taskId].func = Shop_FadeAndRunBuySellCallback; + FadeScreen(1, 0); } -void sub_80B2F30(u8 taskId) +static void Task_HandleShopMenuSell(u8 taskId) { - gTasks[taskId].data[8] = (u32)sub_80A6300 >> 16; - gTasks[taskId].data[9] = (u32)sub_80A6300; - gTasks[taskId].func = sub_80B2FA0; - fade_screen(1, 0); + gTasks[taskId].data[8] = (u32)ItemMenu_LoadSellMenu >> 16; + gTasks[taskId].data[9] = (u32)ItemMenu_LoadSellMenu; + gTasks[taskId].func = Shop_FadeAndRunBuySellCallback; + FadeScreen(1, 0); } -void HandleShopMenuQuit(u8 taskId) +static void Task_HandleShopMenuQuit(u8 taskId) { Menu_DestroyCursor(); Menu_EraseWindowRect(0, 0, 11, 8); @@ -184,7 +196,7 @@ void HandleShopMenuQuit(u8 taskId) gMartInfo.callback(); // run the callback if it exists. } -void sub_80B2FA0(u8 taskId) +static void Shop_FadeAndRunBuySellCallback(u8 taskId) { if (!gPaletteFade.active) { @@ -193,15 +205,15 @@ void sub_80B2FA0(u8 taskId) } } -void ReturnToShopMenuAfterExitingSellMenu(u8 taskId) +static void ReturnToShopMenuAfterExitingSellMenu(u8 taskId) { CreateShopMenu(gMartInfo.martType); DestroyTask(taskId); } -void Task_ExitSellMenu(u8 taskId) +static void Task_ReturnToMartMenu(u8 taskId) { - if (sub_807D770() == 1) + if (IsWeatherNotFadingIn() == 1) { if (gMartInfo.martType == MART_TYPE_2) DisplayItemMessageOnField(taskId, gOtherText_CanIHelpYou, ReturnToShopMenuAfterExitingSellMenu, 0); @@ -210,23 +222,24 @@ void Task_ExitSellMenu(u8 taskId) } } -void sub_80B3050(void) +void Shop_FadeReturnToMartMenu(void) { pal_fill_black(); - CreateTask(Task_ExitSellMenu, 0x8); + CreateTask(Task_ReturnToMartMenu, 0x8); } -void sub_80B3068(u8 taskId) +void Shop_RunExitSellMenuTask(u8 taskId) { - Task_ExitSellMenu(taskId); + Task_ReturnToMartMenu(taskId); } -void unref_sub_80B3078(u8 taskId) +// unused +void Shop_LoadExitSellMenuTask(u8 taskId) { - gTasks[taskId].func = Task_ExitSellMenu; + gTasks[taskId].func = Task_ReturnToMartMenu; } -void sub_80B3094(void) +static void MainCB2(void) { AnimateSprites(); BuildOamBuffer(); @@ -234,50 +247,43 @@ void sub_80B3094(void) UpdatePaletteFade(); } -void sub_80B30AC(void) +static void VBlankCB(void) { - void *addr; - void *addr2; - void *addr3; - u16 *tempArr; - u16 *tempArr2; - u16 *tempArr3; - LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); - - // temp vars needed to match for some dumb reason - tempArr = gBGTilemapBuffers[1]; - addr = (void *)(VRAM + 0xE800); - DmaCopy16(3, tempArr, addr, 0x800); - tempArr2 = gBGTilemapBuffers[2]; - addr2 = (void *)(VRAM + 0xE000); - DmaCopy16(3, tempArr2, addr2, 0x800); - tempArr3 = gBGTilemapBuffers[3]; - addr3 = (void *)(VRAM + 0xF000); - DmaCopy16(3, tempArr3, addr3, 0x800); + DmaCopy16Defvars(3, gBGTilemapBuffers[1], (void *)(VRAM + 0xE800), 0x800); + DmaCopy16Defvars(3, gBGTilemapBuffers[2], (void *)(VRAM + 0xE000), 0x800); + DmaCopy16Defvars(3, gBGTilemapBuffers[3], (void *)(VRAM + 0xF000), 0x800); } -// this function is fugly. pls fix -void BuyMenuDrawGraphics(void) +static void BuyMenuDrawGraphics(void) { - void *addr; - register u16 zero2 asm("r5"); - - sub_80F9438(); + ClearVideoCallbacks(); ScanlineEffect_Stop(); - REG_BG1HOFS = (zero2 = 0); - REG_BG1VOFS = zero2; - REG_BG2HOFS = zero2; - REG_BG2VOFS = zero2; - REG_BG3HOFS = zero2; - REG_BG3VOFS = zero2; + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + REG_BG2HOFS = 0; + REG_BG2VOFS = 0; + REG_BG3HOFS = 0; + REG_BG3VOFS = 0; gPaletteFade.bufferTransferDisabled = 1; - addr = (void*)OAM; - { - register const u32 zero asm("r6") = 0; - DmaFill32(3, zero, addr, OAM_SIZE); + + /* + THEORY: This seemingly useless loop is required in order to match this + function without hacks. The reason is because it alters the 0 optimization + of a later assignment into using 2 different 0s instead of the same register. + It is speculated that at some point Game Freak insert an artificial + breakpoint here in order to look at the contents of OAM before it is cleared, + possibly because a programmer made a mistake in shop.c which corrupted its + contents. There may have been a macro here which at one point idled on the + while(1) but was changed to 0 for release due to a define somewhere. A + while(0) also matches, but it is more correct to use do {} while(0) as it + was a fix to prevent compiler warnings on older compilers. + */ + do {} while(0); + + DmaFill32Defvars(3, 0, (void*)OAM, OAM_SIZE); LZDecompressVram(gBuyMenuFrame_Gfx, (void*)(VRAM + 0x7C00)); LZDecompressWram(gBuyMenuFrame_Tilemap, ewram18000_2); LoadCompressedPalette(gMenuMoneyPal, 0xC0, sizeof(gMenuMoneyPal)); @@ -287,72 +293,72 @@ void BuyMenuDrawGraphics(void) ResetTasks(); Text_LoadWindowTemplate(&gWindowTemplate_81E6DFC); InitMenuWindow(&gWindowTemplate_81E6DFC); - BuyMenuDrawMapGraphics(); - gMartInfo.cursor = zero; - gMartInfo.choicesAbove = zero2; + Shop_DrawViewport(); + gMartInfo.cursor = 0; + gMartInfo.choicesAbove = 0; Menu_EraseWindowRect(0, 0, 0x20, 0x20); OpenMoneyWindow(gSaveBlock1.money, 0, 0); - sub_80B3764(0, 7); - sub_80B37EC(); - sub_80B3270(); - CreateTask(sub_80B40E8, 0x8); + Shop_InitMenus(0, 7); + Shop_PrintItemDesc(); + DrawFirstMartScrollIndicators(); + CreateTask(Shop_DoCursorAction, 0x8); sub_80B3240(); - asm("":::"r4"); // what?? - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, zero); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); gPaletteFade.bufferTransferDisabled = 0; - SetVBlankCallback(sub_80B30AC); - SetMainCallback2(sub_80B3094); - } + SetVBlankCallback(VBlankCB); + SetMainCallback2(MainCB2); } -void sub_80B3240(void) +static void sub_80B3240(void) { - u16 tempArr[2] = {0x41EE, 0x7FFF}; + u16 colors[2] = {RGB(14, 15, 16), RGB_WHITE}; - LoadPalette(&tempArr[1], 0xD1, 2); - LoadPalette(&tempArr[0], 0xD8, 2); + LoadPalette(&colors[1], 0xD1, sizeof colors[1]); + LoadPalette(&colors[0], 0xD8, sizeof colors[0]); } -void sub_80B3270(void) +static void DrawFirstMartScrollIndicators(void) { - sub_80F944C(); + ClearVerticalScrollIndicatorPalettes(); if (gMartInfo.itemCount > 7) { - CreateVerticalScrollIndicators(0, 172, 12); - CreateVerticalScrollIndicators(1, 172, 148); - sub_80F979C(0, 1); + CreateVerticalScrollIndicators(TOP_ARROW, 172, 12); + CreateVerticalScrollIndicators(BOTTOM_ARROW, 172, 148); + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); } } -void sub_80B32A4(void) +static void Shop_TryDrawVerticalScrollIndicators(void) { if (gMartInfo.choicesAbove == 0) - sub_80F979C(0, 1); + SetVerticalScrollIndicators(TOP_ARROW, INVISIBLE); else - sub_80F979C(0, 0); + SetVerticalScrollIndicators(TOP_ARROW, VISIBLE); if (gMartInfo.choicesAbove + 7 >= gMartInfo.itemCount) - sub_80F979C(1, 1); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); else - sub_80F979C(1, 0); + SetVerticalScrollIndicators(BOTTOM_ARROW, VISIBLE); } -void sub_80B32EC(u16 *array, s16 offset1, s16 offset2) +// what is the point of this function? the tiles always get overwritten by BuyMenuDrawTextboxBG. +static void BuyMenuDrawTextboxBG_Old(u16 *array, s16 offset1, s16 offset2) { array[offset1 + offset2] = 0xC3E1; array[offset1 + offset2 + 1] = 0xC3E1; } -void BuyMenuDrawMapMetatileLayer(u16 *array, s16 offset1, s16 offset2, u16 *array2) +static void BuyMenuDrawMapMetatileLayer(u16 *array, s16 offset1, s16 offset2, u16 *array2) { - array[offset1 + offset2] = array2[0]; - array[offset1 + offset2 + 1] = array2[1]; - array[offset1 + offset2 + 32] = array2[2]; - array[offset1 + offset2 + 33] = array2[3]; + // This function draws a whole 2x2 metatile. + array[offset1 + offset2] = array2[0]; // top left + array[offset1 + offset2 + 1] = array2[1]; // top right + array[offset1 + offset2 + 32] = array2[2]; // bottom left + array[offset1 + offset2 + 33] = array2[3]; // bottom right } -void BuyMenuDrawMapMetatile(int var1, int var2, u16 *var3, s32 var4) +static void BuyMenuDrawMapMetatile(int var1, int var2, u16 *var3, s32 var4) { u8 tempVar4 = var4; s16 offset1 = var1 * 2; @@ -375,7 +381,8 @@ void BuyMenuDrawMapMetatile(int var1, int var2, u16 *var3, s32 var4) } } -void sub_80B33D0(s16 var1, int var2, u16 *var3) +// used to draw the border tiles around the viewport. +static void BuyMenuDrawMapPartialMetatile(s16 var1, int var2, u16 *var3) { s16 offset1 = var1 * 2; s16 offset2 = (var2 * 0x40) + 0x40; @@ -384,7 +391,7 @@ void sub_80B33D0(s16 var1, int var2, u16 *var3) BuyMenuDrawMapMetatileLayer(gBGTilemapBuffers[2], offset1, offset2, var3 + 4); } -void sub_80B3420(void) +static void Shop_DrawViewportTiles(void) { s16 facingX; s16 facingY; @@ -413,26 +420,26 @@ void sub_80B3420(void) else { if (metatileId < 512) - sub_80B33D0(x, y, (u16 *)gMapHeader.mapData->primaryTileset->metatiles + metatileId * 8); + BuyMenuDrawMapPartialMetatile(x, y, (u16 *)gMapHeader.mapData->primaryTileset->metatiles + metatileId * 8); else - sub_80B33D0(x, y, (u16 *)gMapHeader.mapData->secondaryTileset->metatiles + (metatileId - 512) * 8); + BuyMenuDrawMapPartialMetatile(x, y, (u16 *)gMapHeader.mapData->secondaryTileset->metatiles + (metatileId - 512) * 8); } if (y == 0 && x != 0 && x != 6) - sub_80B32EC(gBGTilemapBuffers[1], x * 2, 64); + BuyMenuDrawTextboxBG_Old(gBGTilemapBuffers[1], x * 2, 64); } } } -void BuyMenuDrawMapGraphics(void) +static void Shop_DrawViewport(void) { - sub_80F9020(); - sub_80B356C(); - sub_80B368C(); - sub_80B3420(); + ClearBGTilemapBuffers(); + Shop_LoadViewportObjects(); + Shop_AnimViewportObjects(); + Shop_DrawViewportTiles(); } -void sub_80B356C(void) +static void Shop_LoadViewportObjects(void) { s16 facingX; s16 facingY; @@ -444,7 +451,7 @@ void sub_80B356C(void) GetXYCoordsOneStepInFrontOfPlayer(&facingX, &facingY); playerHeight = PlayerGetZCoord(); for (y = 0; y < 16; y++) - gUnknown_020386A4[y][MAP_OBJ_ID] = 16; + gMartViewportObjects[y][MAP_OBJ_ID] = 16; for (y = 0; y < 5; y++) { for (x = 0; x < 7; x++) @@ -453,43 +460,43 @@ void sub_80B356C(void) if (mapObjId != 16) { - gUnknown_020386A4[r8][MAP_OBJ_ID] = mapObjId; - gUnknown_020386A4[r8][X_COORD] = x; - gUnknown_020386A4[r8][Y_COORD] = y; + gMartViewportObjects[r8][MAP_OBJ_ID] = mapObjId; + gMartViewportObjects[r8][X_COORD] = x; + gMartViewportObjects[r8][Y_COORD] = y; if (gMapObjects[mapObjId].mapobj_unk_18 == 1) - gUnknown_020386A4[r8][ANIM_NUM] = 0; + gMartViewportObjects[r8][ANIM_NUM] = 0; if (gMapObjects[mapObjId].mapobj_unk_18 == 2) - gUnknown_020386A4[r8][ANIM_NUM] = 1; + gMartViewportObjects[r8][ANIM_NUM] = 1; if (gMapObjects[mapObjId].mapobj_unk_18 == 3) - gUnknown_020386A4[r8][ANIM_NUM] = 2; + gMartViewportObjects[r8][ANIM_NUM] = 2; if (gMapObjects[mapObjId].mapobj_unk_18 == 4) - gUnknown_020386A4[r8][ANIM_NUM] = 3; + gMartViewportObjects[r8][ANIM_NUM] = 3; r8++; } } } } -void sub_80B368C(void) +static void Shop_AnimViewportObjects(void) { u8 i; for (i = 0; i < 16; i++) // max objects? { - if (gUnknown_020386A4[i][MAP_OBJ_ID] == 16) + if (gMartViewportObjects[i][MAP_OBJ_ID] == 16) continue; StartSpriteAnim(&gSprites[AddPseudoFieldObject( - gMapObjects[gUnknown_020386A4[i][MAP_OBJ_ID]].graphicsId, + gMapObjects[gMartViewportObjects[i][MAP_OBJ_ID]].graphicsId, SpriteCallbackDummy, - (u16)gUnknown_020386A4[i][X_COORD] * 16 + 8, - (u16)gUnknown_020386A4[i][Y_COORD] * 16 + 32, + (u16)gMartViewportObjects[i][X_COORD] * 16 + 8, + (u16)gMartViewportObjects[i][Y_COORD] * 16 + 32, 2)], - gUnknown_020386A4[i][ANIM_NUM]); + gMartViewportObjects[i][ANIM_NUM]); } } -void sub_80B3720(void) +static void BuyMenuDrawTextboxBG(void) { s16 i; @@ -500,14 +507,15 @@ void sub_80B3720(void) } } -void sub_80B3764(int var1, int var2) +static void Shop_InitMenus(int firstItemId, int lastItemId) { - sub_80B3720(); - sub_80B39D0(var1, var2, 0); + BuyMenuDrawTextboxBG(); + Shop_DisplayPriceInList(firstItemId, lastItemId, 0); InitMenu(0, 0xE, 0x2, 0x8, gMartInfo.cursor, 0xF); } -void sub_80B379C(void) +// after printing the item quantity and price, restore the textbox tiles before the Yes/No prompt. +static void BuyMenuDrawTextboxBG_Restore(void) { u16 i, j; @@ -516,27 +524,29 @@ void sub_80B379C(void) gBGTilemapBuffers[1][32 * (i + 12) + j] = ewram18300[32 * i + j] + 0xC3E0; } -void sub_80B37EC(void) +static void Shop_PrintItemDesc(void) { - sub_80B3A70(); + Shop_PrintItemDescText(); } -void sub_80B37F8(u8 taskId) +#define tItemCount data[1] + +static void Shop_DisplayPriceInCheckoutWindow(u8 taskId) { u16 itemListIndex = gMartInfo.choicesAbove + gMartInfo.cursor; u16 itemId = gMartInfo.itemList[itemListIndex]; u32 price = (ItemId_GetPrice(itemId) >> GetPriceReduction(1)); - PrintMoneyAmount(gTasks[taskId].data[1] * price, 6, 6, 11); + PrintMoneyAmount(gTasks[taskId].tItemCount * price, 6, 6, 11); gStringVar1[0] = EXT_CTRL_CODE_BEGIN; gStringVar1[1] = 0x14; gStringVar1[2] = 0x6; - ConvertIntToDecimalStringN(&gStringVar1[3], gTasks[taskId].data[1], 1, 2); + ConvertIntToDecimalStringN(&gStringVar1[3], gTasks[taskId].tItemCount, 1, 2); Menu_PrintText(gOtherText_xString1, 1, 11); sub_80A3FA0(gBGTilemapBuffers[1], 1, 11, 12, 2, 0xC3E1); } -void sub_80B389C(u16 itemId, u8 var2, bool32 hasControlCode) +static void Shop_DisplayNormalPriceInList(u16 itemId, u8 var2, bool32 hasControlCode) { u8 *stringPtr = gStringVar1; @@ -560,7 +570,7 @@ void sub_80B389C(u16 itemId, u8 var2, bool32 hasControlCode) Menu_PrintTextPixelCoords(&gStringVar1[0], 0xCA, var2 << 3, 1); } -void sub_80B3930(u16 itemId, u8 var2, bool32 hasControlCode) +static void Shop_DisplayDecorationPriceInList(u16 itemId, u8 var2, bool32 hasControlCode) { u8 *stringPtr = gStringVar1; @@ -579,9 +589,12 @@ void sub_80B3930(u16 itemId, u8 var2, bool32 hasControlCode) if (hasControlCode != FALSE) stringPtr = &gStringVar1[3]; + // some names are the maximum string length for a shop item. Because there is no room for + // a 6 character price (including the currency), a sprite is instead used for anything that + // is the maximum decoration price in order to fit it on screen. if (gDecorations[itemId].price == 10000) { - sub_80B7B34(0x19, var2, hasControlCode); // huh??? + Draw10000Sprite(0x19, var2, hasControlCode); } else { @@ -590,16 +603,16 @@ void sub_80B3930(u16 itemId, u8 var2, bool32 hasControlCode) } } -void sub_80B39D0(int var1, int var2, bool32 hasControlCode) +static void Shop_DisplayPriceInList(int firstItemId, int lastItemId, bool32 hasControlCode) { u8 i; - for (i = var1; i <= var2 && gMartInfo.choicesAbove + i < gMartInfo.itemCount; i++) + for (i = firstItemId; i <= lastItemId && gMartInfo.choicesAbove + i < gMartInfo.itemCount; i++) { if (gMartInfo.martType == MART_TYPE_0) - sub_80B389C(gMartInfo.itemList[gMartInfo.choicesAbove + i], (i << 1) + 2, hasControlCode); + Shop_DisplayNormalPriceInList(gMartInfo.itemList[gMartInfo.choicesAbove + i], (i << 1) + 2, hasControlCode); else - sub_80B3930(gMartInfo.itemList[gMartInfo.choicesAbove + i], (i << 1) + 2, hasControlCode); + Shop_DisplayDecorationPriceInList(gMartInfo.itemList[gMartInfo.choicesAbove + i], (i << 1) + 2, hasControlCode); } if (i != 8 && gMartInfo.choicesAbove + i == gMartInfo.itemCount) @@ -609,7 +622,7 @@ void sub_80B39D0(int var1, int var2, bool32 hasControlCode) } } -void sub_80B3A70(void) +static void Shop_PrintItemDescText(void) { if (gMartInfo.choicesAbove + gMartInfo.cursor != gMartInfo.itemCount) { @@ -628,121 +641,122 @@ void sub_80B3A70(void) } } -void sub_80B3AEC(u8 taskId) +static void Shop_DoPremierBallCheck(u8 taskId) { if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { - sub_80B39D0(gMartInfo.cursor, gMartInfo.cursor, 0); // huh??? + Shop_DisplayPriceInList(gMartInfo.cursor, gMartInfo.cursor, 0); PlaySE(SE_SELECT); - if (gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor] == ITEM_POKE_BALL && gTasks[taskId].data[1] >= 10 && AddBagItem(ITEM_PREMIER_BALL, 1) == TRUE) - DisplayItemMessageOnField(taskId, gOtherText_FreePremierBall, sub_80B4378, 0xC3E1); + if (gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor] == ITEM_POKE_BALL && gTasks[taskId].tItemCount >= 10 && AddBagItem(ITEM_PREMIER_BALL, 1) == TRUE) + DisplayItemMessageOnField(taskId, gOtherText_FreePremierBall, Task_ReturnToBuyMenu, 0xC3E1); else - sub_80B4378(taskId); + Task_ReturnToBuyMenu(taskId); } } -void sub_80B3B80(u8 taskId) +static void Shop_DoItemTransaction(u8 taskId) { - IncrementGameStat(0x26); + IncrementGameStat(GAME_STAT_SHOPPED); RemoveMoney(&gSaveBlock1.money, gMartTotalCost); PlaySE(SE_REGI); UpdateMoneyWindow(gSaveBlock1.money, 0, 0); - gTasks[taskId].func = sub_80B3AEC; + gTasks[taskId].func = Shop_DoPremierBallCheck; } -void sub_80B3BD0(u8 taskId) +static void Shop_DoPricePrintAndReturnToBuyMenu(u8 taskId) { - sub_80B39D0(gMartInfo.cursor, gMartInfo.cursor, 0); // same thing as above? - sub_80B4378(taskId); + Shop_DisplayPriceInList(gMartInfo.cursor, gMartInfo.cursor, 0); + Task_ReturnToBuyMenu(taskId); } -void sub_80B3BF4(u8 taskId) +static void Task_DoItemPurchase(u8 taskId) { Menu_EraseWindowRect(0x7, 0x8, 0xD, 0xD); sub_80A3FA0(gBGTilemapBuffers[1], 8, 9, 4, 4, 0); - sub_80B379C(); - sub_80B3420(); + BuyMenuDrawTextboxBG_Restore(); + Shop_DrawViewportTiles(); if (IsEnoughMoney(gSaveBlock1.money, gMartTotalCost)) { if (gMartInfo.martType == MART_TYPE_0) { - if (AddBagItem(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor], gTasks[taskId].data[1])) + if (AddBagItem(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor], gTasks[taskId].tItemCount)) { - DisplayItemMessageOnField(taskId, gOtherText_HereYouGo, sub_80B3B80, 0xC3E1); - sub_80B4470(taskId); + DisplayItemMessageOnField(taskId, gOtherText_HereYouGo, Shop_DoItemTransaction, 0xC3E1); + Task_UpdatePurchaseHistory(taskId); } else - DisplayItemMessageOnField(taskId, gOtherText_NoRoomFor, sub_80B3BD0, 0xC3E1); + DisplayItemMessageOnField(taskId, gOtherText_NoRoomFor, Shop_DoPricePrintAndReturnToBuyMenu, 0xC3E1); } else // a normal mart is only type 0, so types 1 and 2 are decoration marts. { if (IsThereStorageSpaceForDecoration(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor])) { if (gMartInfo.martType == MART_TYPE_1) - DisplayItemMessageOnField(taskId, gOtherText_HereYouGo2, sub_80B3B80, 0xC3E1); + DisplayItemMessageOnField(taskId, gOtherText_HereYouGo2, Shop_DoItemTransaction, 0xC3E1); else - DisplayItemMessageOnField(taskId, gOtherText_HereYouGo3, sub_80B3B80, 0xC3E1); + DisplayItemMessageOnField(taskId, gOtherText_HereYouGo3, Shop_DoItemTransaction, 0xC3E1); } else { StringExpandPlaceholders(gStringVar4, gOtherText_SpaceForIsFull); - DisplayItemMessageOnField(taskId, gStringVar4, sub_80B3BD0, 0xC3E1); + DisplayItemMessageOnField(taskId, gStringVar4, Shop_DoPricePrintAndReturnToBuyMenu, 0xC3E1); } } } else - DisplayItemMessageOnField(taskId, gOtherText_NotEnoughMoney, sub_80B3BD0, 0xC3E1); + DisplayItemMessageOnField(taskId, gOtherText_NotEnoughMoney, Shop_DoPricePrintAndReturnToBuyMenu, 0xC3E1); } -void sub_80B3D38(u8 taskId) +static void Shop_DoYesNoPurchase(u8 taskId) { DisplayYesNoMenu(7, 8, 1); sub_80A3FA0(gBGTilemapBuffers[1], 8, 9, 4, 4, 0xC3E1); - DoYesNoFuncWithChoice(taskId, gUnknown_083CC708); + DoYesNoFuncWithChoice(taskId, sShopPurchaseYesNoFuncs); } -void sub_80B3D7C(u8 taskId) +static void Task_CancelItemPurchase(u8 taskId) { - sub_80B39D0(gMartInfo.cursor, gMartInfo.cursor, 0); + Shop_DisplayPriceInList(gMartInfo.cursor, gMartInfo.cursor, 0); Menu_EraseWindowRect(0x7, 0x8, 0xD, 0xD); sub_80A3FA0(gBGTilemapBuffers[1], 0x8, 0x9, 0x4, 0x4, 0); - sub_80B4378(taskId); + Task_ReturnToBuyMenu(taskId); } -void sub_80B3DC8(u8 taskId) +static void Shop_PrintPrice(u8 taskId) { - if (sub_80A52C4(taskId, gMartInfo.curItemCount) == TRUE) - sub_80B37F8(taskId); + if (SellMenu_QuantityRoller(taskId, gMartInfo.curItemCount) == TRUE) + Shop_DisplayPriceInCheckoutWindow(taskId); if (gMain.newKeys & A_BUTTON) { - gMartTotalCost = (ItemId_GetPrice(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor]) >> GetPriceReduction(1)) * gTasks[taskId].data[1]; // set total cost of your purchase. + gMartTotalCost = (ItemId_GetPrice(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor]) >> GetPriceReduction(1)) * gTasks[taskId].tItemCount; // set total cost of your purchase. Menu_EraseWindowRect(0, 0xA, 0xD, 0xD); sub_80A3FA0(gBGTilemapBuffers[1], 0x1, 0xB, 0xC, 0x2, 0); - sub_80B379C(); - sub_80B3420(); + BuyMenuDrawTextboxBG_Restore(); + Shop_DrawViewportTiles(); CopyItemName(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor], gStringVar1); - ConvertIntToDecimalStringN(gStringVar2, gTasks[taskId].data[1], 0, 0x2); + ConvertIntToDecimalStringN(gStringVar2, gTasks[taskId].tItemCount, 0, 0x2); ConvertIntToDecimalStringN(gStringVar3, gMartTotalCost, 0, 0x8); StringExpandPlaceholders(gStringVar4, gOtherText_ThatWillBe); - DisplayItemMessageOnField(taskId, gStringVar4, sub_80B3D38, 0xC3E1); + DisplayItemMessageOnField(taskId, gStringVar4, Shop_DoYesNoPurchase, 0xC3E1); } else if (gMain.newKeys & B_BUTTON) { - sub_80B39D0(gMartInfo.cursor, gMartInfo.cursor, 0); - sub_80B4378(taskId); + Shop_DisplayPriceInList(gMartInfo.cursor, gMartInfo.cursor, 0); + Task_ReturnToBuyMenu(taskId); } } -void sub_80B3EFC(u8 taskId) +// set the item count in the mart info to the maximum allowed by the player's budget. +static void Shop_UpdateCurItemCountToMax(u8 taskId) { u16 var; - gTasks[taskId].data[1] = 1; + gTasks[taskId].tItemCount = 1; Menu_DrawStdWindowFrame(0, 0xA, 0xD, 0xD); - sub_80B37F8(taskId); + Shop_DisplayPriceInCheckoutWindow(taskId); var = gSaveBlock1.money / (ItemId_GetPrice(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor]) >> GetPriceReduction(1)); if (var > 99) @@ -750,11 +764,11 @@ void sub_80B3EFC(u8 taskId) else gMartInfo.curItemCount = var; - gTasks[taskId].func = sub_80B3DC8; + gTasks[taskId].func = Shop_PrintPrice; } #ifdef NONMATCHING -void sub_80B3F88(void) +static void Shop_MoveItemListUp(void) { u16 *r1; u16 *r2; @@ -796,7 +810,7 @@ void sub_80B3F88(void) } #else __attribute__((naked)) -void sub_80B3F88(void) +static void Shop_MoveItemListUp(void) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ @@ -891,7 +905,7 @@ _080B4038: .4byte 0xfffffc40\n\ #endif #ifdef NONMATCHING -void sub_80B403C(void) +static void Shop_MoveItemListDown(void) { u16 *r1; u16 *r2; @@ -935,7 +949,7 @@ void sub_80B403C(void) } #else __attribute__((naked)) -void sub_80B403C(void) +static void Shop_MoveItemListDown(void) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ @@ -1028,7 +1042,7 @@ _080B40E4: .4byte 0x800000f0\n\ } #endif -void sub_80B40E8(u8 taskId) // Mart_DoCursorAction +static void Shop_DoCursorAction(u8 taskId) { if (!gPaletteFade.active) { @@ -1041,16 +1055,16 @@ void sub_80B40E8(u8 taskId) // Mart_DoCursorAction PlaySE(SE_SELECT); gMartInfo.choicesAbove--; // since cursor is at the top and there are choices above the top, scroll the menu up by updating choicesAbove. - sub_80B3F88(); - sub_80B39D0(0, 0, 0); - sub_80B3A70(); - sub_80B32A4(); + Shop_MoveItemListUp(); + Shop_DisplayPriceInList(0, 0, 0); + Shop_PrintItemDescText(); + Shop_TryDrawVerticalScrollIndicators(); } else // if the cursor is not 0, choicesAbove cannot be updated yet since the cursor is at the top of the menu, so update cursor. { PlaySE(SE_SELECT); gMartInfo.cursor = Menu_MoveCursor(-1); // move cursor up - sub_80B3A70(); + Shop_PrintItemDescText(); } } else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) // only down can be pressed @@ -1062,16 +1076,16 @@ void sub_80B40E8(u8 taskId) // Mart_DoCursorAction PlaySE(SE_SELECT); gMartInfo.choicesAbove++; - sub_80B403C(); - sub_80B39D0(7, 7, 0); - sub_80B3A70(); - sub_80B32A4(); + Shop_MoveItemListDown(); + Shop_DisplayPriceInList(7, 7, 0); + Shop_PrintItemDescText(); + Shop_TryDrawVerticalScrollIndicators(); } else if (gMartInfo.cursor != gMartInfo.itemCount) { PlaySE(SE_SELECT); gMartInfo.cursor = Menu_MoveCursor(1); - sub_80B3A70(); + Shop_PrintItemDescText(); } } else if (gMain.newKeys & A_BUTTON) @@ -1080,10 +1094,10 @@ void sub_80B40E8(u8 taskId) // Mart_DoCursorAction if (gMartInfo.choicesAbove + gMartInfo.cursor != gMartInfo.itemCount) // did you not hit CANCEL? { - PauseVerticalScrollIndicator(0); - PauseVerticalScrollIndicator(1); - sub_80F979C(1, 1); - sub_80B39D0(gMartInfo.cursor, gMartInfo.cursor, 1); + PauseVerticalScrollIndicator(TOP_ARROW); + PauseVerticalScrollIndicator(BOTTOM_ARROW); + SetVerticalScrollIndicators(BOTTOM_ARROW, INVISIBLE); + Shop_DisplayPriceInList(gMartInfo.cursor, gMartInfo.cursor, 1); Menu_DestroyCursor(); Menu_EraseWindowRect(0, 0xC, 0xD, 0x13); @@ -1092,13 +1106,13 @@ void sub_80B40E8(u8 taskId) // Mart_DoCursorAction gMartTotalCost = (ItemId_GetPrice(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor]) >> GetPriceReduction(1)); // set 1x price if (!IsEnoughMoney(gSaveBlock1.money, gMartTotalCost)) { - DisplayItemMessageOnField(taskId, gOtherText_NotEnoughMoney, sub_80B3BD0, 0xC3E1); // tail merge + DisplayItemMessageOnField(taskId, gOtherText_NotEnoughMoney, Shop_DoPricePrintAndReturnToBuyMenu, 0xC3E1); // tail merge } else // _080B42BA { CopyItemName(gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor], gStringVar1); StringExpandPlaceholders(gStringVar4, gOtherText_HowManyYouWant); - DisplayItemMessageOnField(taskId, gStringVar4, sub_80B3EFC, 0xC3E1); + DisplayItemMessageOnField(taskId, gStringVar4, Shop_UpdateCurItemCountToMax, 0xC3E1); } } else // _080B428C @@ -1107,7 +1121,7 @@ void sub_80B40E8(u8 taskId) // Mart_DoCursorAction if (!IsEnoughMoney(gSaveBlock1.money, gMartTotalCost)) { - DisplayItemMessageOnField(taskId, gOtherText_NotEnoughMoney, sub_80B3BD0, 0xC3E1); // tail merge + DisplayItemMessageOnField(taskId, gOtherText_NotEnoughMoney, Shop_DoPricePrintAndReturnToBuyMenu, 0xC3E1); // tail merge } else { @@ -1122,43 +1136,43 @@ void sub_80B40E8(u8 taskId) // Mart_DoCursorAction { StringExpandPlaceholders(gStringVar4, gOtherText_ThatWillBe3); } - DisplayItemMessageOnField(taskId, gStringVar4, sub_80B3D38, 0xC3E1); + DisplayItemMessageOnField(taskId, gStringVar4, Shop_DoYesNoPurchase, 0xC3E1); } } } else - sub_80B43F0(taskId); + Task_ExitBuyMenu(taskId); } else if (gMain.newKeys & B_BUTTON) // go back to buy/sell/exit menu { PlaySE(SE_SELECT); - sub_80B43F0(taskId); + Task_ExitBuyMenu(taskId); } } } -void sub_80B4378(u8 taskId) +static void Task_ReturnToBuyMenu(u8 taskId) { Menu_EraseWindowRect(0, 0xE, 0x1D, 0x13); Menu_EraseWindowRect(0, 0xA, 0xD, 0xD); sub_80A3FA0(gBGTilemapBuffers[1], 0x1, 0xB, 0xC, 0x2, 0); - sub_80B3420(); - sub_80B3764(6, 7); - sub_80B37EC(); - StartVerticalScrollIndicators(0); - StartVerticalScrollIndicators(1); - sub_80B32A4(); - gTasks[taskId].func = sub_80B40E8; + Shop_DrawViewportTiles(); + Shop_InitMenus(6, 7); + Shop_PrintItemDesc(); + StartVerticalScrollIndicators(TOP_ARROW); + StartVerticalScrollIndicators(BOTTOM_ARROW); + Shop_TryDrawVerticalScrollIndicators(); + gTasks[taskId].func = Shop_DoCursorAction; } -void sub_80B43F0(u8 taskId) +static void Task_ExitBuyMenu(u8 taskId) { - gFieldCallback = sub_80B3050; + gFieldCallback = Shop_FadeReturnToMartMenu; BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); - gTasks[taskId].func = Task_ExitBuyMenu; + gTasks[taskId].func = Task_ExitBuyMenuDoFade; } -void Task_ExitBuyMenu(u8 taskId) +static void Task_ExitBuyMenuDoFade(u8 taskId) { if (!gPaletteFade.active) { @@ -1169,38 +1183,41 @@ void Task_ExitBuyMenu(u8 taskId) } } -void sub_80B4470(u8 taskId) +// Task_UpdatePurchaseHistory +static void Task_UpdatePurchaseHistory(u8 taskId) { u16 i; for (i = 0; i < 3; i++) { - if (gUnknown_02038724[i].itemId == gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor] - && gUnknown_02038724[i].quantity != 0) + if (gMartPurchaseHistory[i].itemId == gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor] + && gMartPurchaseHistory[i].quantity != 0) { - if (gUnknown_02038724[i].quantity + gTasks[taskId].data[1] > 255) - gUnknown_02038724[i].quantity = 255; + if (gMartPurchaseHistory[i].quantity + gTasks[taskId].tItemCount > 255) + gMartPurchaseHistory[i].quantity = 255; else - gUnknown_02038724[i].quantity += gTasks[taskId].data[1]; + gMartPurchaseHistory[i].quantity += gTasks[taskId].tItemCount; return; } } - if (gUnknown_02038730 < 3) + if (gMartPurchaseHistoryId < 3) { - gUnknown_02038724[gUnknown_02038730].itemId = gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor]; - gUnknown_02038724[gUnknown_02038730].quantity = gTasks[taskId].data[1]; - gUnknown_02038730++; + gMartPurchaseHistory[gMartPurchaseHistoryId].itemId = gMartInfo.itemList[gMartInfo.choicesAbove + gMartInfo.cursor]; + gMartPurchaseHistory[gMartPurchaseHistoryId].quantity = gTasks[taskId].tItemCount; + gMartPurchaseHistoryId++; } } -void ClearItemPurchases(void) +#undef tItemCount + +static void ClearItemPurchases(void) { - gUnknown_02038730 = 0; - ClearItemSlots(gUnknown_02038724, 3); + gMartPurchaseHistoryId = 0; + ClearItemSlots(gMartPurchaseHistory, 3); } -void CreatePokemartMenu(u16 *itemList) +void Shop_CreatePokemartMenu(u16 *itemList) { CreateShopMenu(MART_TYPE_0); SetShopItemsForSale(itemList); @@ -1208,14 +1225,14 @@ void CreatePokemartMenu(u16 *itemList) SetShopMenuCallback(EnableBothScriptContexts); } -void CreateDecorationShop1Menu(u16 *itemList) +void Shop_CreateDecorationShop1Menu(u16 *itemList) { CreateShopMenu(MART_TYPE_1); SetShopItemsForSale(itemList); SetShopMenuCallback(EnableBothScriptContexts); } -void CreateDecorationShop2Menu(u16 *itemList) +void Shop_CreateDecorationShop2Menu(u16 *itemList) { CreateShopMenu(MART_TYPE_2); SetShopItemsForSale(itemList); @@ -1239,131 +1256,6 @@ void debug_sub_80C2818(void) ._291:\n\ .align 2, 0\n\ ._290:\n\ - .word gUnknown_083CC6EB+0x3"); + .word gMartBuyNoSellOptionList+0x3"); } #endif - -void sub_80B45B4(u8 taskId, const s16 *list, u16 c) -{ - s16 r5 = gTasks[taskId].data[4] - 1; - s16 r3 = gTasks[taskId].data[5] - 1; - s16 r4 = gTasks[taskId].data[1]; - s16 y; - s16 x; - - if (gTasks[taskId].data[2] == 0) - { - for (y = 0; y < 3; y++) - { - for (x = 0; x < 3; x++) - { - s16 metatileId = MapGridGetMetatileIdAt(r5 + x, r3 + y); - - if (list[r4] == metatileId) - { - if (r4 != 2) - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[r4 + 1]); - else - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[0]); - } - } - } - } - else - { - for (y = 0; y < 3; y++) - { - for (x = 0; x < 3; x++) - { - s16 metatileId = MapGridGetMetatileIdAt(r5 + x, r3 + y); - - if (list[2 - r4] == metatileId) - { - if (r4 != 2) - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[1 - r4]); - else - MapGridSetMetatileIdAt(r5 + x, r3 + y, c | list[2]); - } - } - } - } -} - -static const u16 gUnknown_083CC714[] = {0x284, 0x282, 0x280}; -static const u16 gUnknown_083CC71A[] = {0x285, 0x283, 0x281}; -static const u16 gUnknown_083CC720[] = {0x28C, 0x28A, 0x288}; -static const u16 gUnknown_083CC726[] = {0x28D, 0x28B, 0x289}; -static const u16 gUnknown_083CC72C[] = {0x2A0, 0x2A2, 0x2A4}; -static const u16 gUnknown_083CC732[] = {0x2A1, 0x2A3, 0x2A5}; -static const u16 gUnknown_083CC738[] = {0x2A8, 0x2AA, 0x2AC}; - -void sub_80B4710(u8 taskId) -{ - s16 *data = gTasks[taskId].data; - - data[3] = 1; - - switch (data[0]) - { - case 0: - sub_80B45B4(taskId, gUnknown_083CC714, 0); - break; - case 1: - sub_80B45B4(taskId, gUnknown_083CC71A, 0); - break; - case 2: - sub_80B45B4(taskId, gUnknown_083CC720, 0xC00); - break; - case 3: - sub_80B45B4(taskId, gUnknown_083CC726, 0); - break; - case 4: - sub_80B45B4(taskId, gUnknown_083CC72C, 0xC00); - break; - case 5: - sub_80B45B4(taskId, gUnknown_083CC732, 0); - break; - case 6: - sub_80B45B4(taskId, gUnknown_083CC738, 0); - break; - } - - data[0] = (data[0] + 1) & 7; - if (!data[0]) - { - DrawWholeMapView(); - data[1] = (data[1] + 1) % 3; - data[3] = 0; - } -} - -u8 sub_80B47D8(u16 var) -{ - u8 taskId = CreateTask(sub_80B4710, 0); - s16 *data = gTasks[taskId].data; - - PlayerGetDestCoords(&data[4], &data[5]); - data[0] = 0; - data[1] = 0; - data[2] = var; - sub_80B4710(taskId); - return taskId; -} - -void sub_80B4824(u8 var) -{ - gUnknown_02038731 = sub_80B47D8(var); -} - -void sub_80B483C(void) -{ - DestroyTask(gUnknown_02038731); -} - -bool8 sub_80B4850(void) -{ - if (gTasks[gUnknown_02038731].data[3] == 0 && gTasks[gUnknown_02038731].data[1] == 2) - return FALSE; - else - return TRUE; -} diff --git a/src/field/slot_machine.c b/src/field/slot_machine.c index c4a4128b3..b5b13c533 100644 --- a/src/field/slot_machine.c +++ b/src/field/slot_machine.c @@ -5098,26 +5098,9 @@ static void sub_8106404(void) } static void sub_8106448(void) { - u32 offsetRead, offsetWrite; - u32 size; - LZDecompressWram(gSlotMachine_Gfx, eSlotMachineGfxBuffer); - offsetRead = (u32)eSlotMachineGfxBuffer; - offsetWrite = BG_VRAM; - size = SLOTMACHINE_GFX_TILES * 32; - while (TRUE) - { - DmaCopy16(3, offsetRead, (void *) (offsetWrite), 0x1000); - offsetRead += 0x1000; - offsetWrite += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaCopy16(3, offsetRead, (void *) (offsetWrite), size); - break; - } - } + DmaCopyLarge16(3, eSlotMachineGfxBuffer, BG_VRAM, SLOTMACHINE_GFX_TILES * 32, 0x1000); LoadPalette(gUnknown_08E95A18, 0, 160); LoadPalette(gPalette_83EDE24, 208, 32); diff --git a/src/field/start_menu.c b/src/field/start_menu.c index 47c7fca05..1b01bf7a8 100644 --- a/src/field/start_menu.c +++ b/src/field/start_menu.c @@ -59,7 +59,7 @@ extern u16 gSpecialVar_Result; extern u8 gUnknown_03004860; -u8 (*gCallback_03004AE8)(void); +u8 (*gMenuCallback)(void); EWRAM_DATA static u8 sStartMenuCursorPos = 0; EWRAM_DATA static u8 sNumStartMenuActions = 0; @@ -586,11 +586,11 @@ void sub_80712B4(u8 taskId) switch (task->data[0]) { case 0: - gCallback_03004AE8 = StartMenu_InputProcessCallback; + gMenuCallback = StartMenu_InputProcessCallback; task->data[0]++; break; case 1: - if (gCallback_03004AE8() == 1) + if (gMenuCallback() == 1) DestroyTask(taskId); break; } @@ -628,11 +628,11 @@ static u8 StartMenu_InputProcessCallback(void) if (GetNationalPokedexCount(0) == 0) return 0; } - gCallback_03004AE8 = sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func; - if (gCallback_03004AE8 != StartMenu_SaveCallback && - gCallback_03004AE8 != StartMenu_ExitCallback && - gCallback_03004AE8 != StartMenu_RetireCallback) - fade_screen(1, 0); + gMenuCallback = sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func; + if (gMenuCallback != StartMenu_SaveCallback && + gMenuCallback != StartMenu_ExitCallback && + gMenuCallback != StartMenu_RetireCallback) + FadeScreen(1, 0); return 0; } if (gMain.newKeys & (START_BUTTON | B_BUTTON)) @@ -648,7 +648,7 @@ static u8 StartMenu_PokedexCallback(void) { if (!gPaletteFade.active) { - IncrementGameStat(0x29); + IncrementGameStat(GAME_STAT_CHECKED_POKEDEX); PlayRainSoundEffect(); SetMainCallback2(CB2_InitPokedex); return 1; @@ -708,7 +708,7 @@ static u8 StartMenu_PlayerCallback(void) static u8 StartMenu_SaveCallback(void) { Menu_DestroyCursor(); - gCallback_03004AE8 = SaveCallback1; + gMenuCallback = SaveCallback1; return 0; } @@ -764,7 +764,7 @@ enum static u8 SaveCallback1(void) { sub_807160C(); - gCallback_03004AE8 = SaveCallback2; + gMenuCallback = SaveCallback2; return FALSE; } @@ -778,7 +778,7 @@ static u8 SaveCallback2(void) //Go back to start menu Menu_EraseScreen(); InitStartMenu(); - gCallback_03004AE8 = StartMenu_InputProcessCallback; + gMenuCallback = StartMenu_InputProcessCallback; return FALSE; case SAVE_SUCCESS: case SAVE_ERROR: @@ -969,7 +969,7 @@ static u8 SaveDialogCB_DoSave(void) { u8 saveStatus; - IncrementGameStat(0); + IncrementGameStat(GAME_STAT_SAVED_GAME); if (gDifferentSaveFile == TRUE) { saveStatus = Save_WriteData(SAVE_OVERWRITE_DIFFERENT_FILE); @@ -1047,29 +1047,12 @@ static bool32 sub_80719FC(u8 *step) switch (*step) { case 0: - { - u8 *addr; - u32 size; - REG_DISPCNT = 0; SetVBlankCallback(NULL); ScanlineEffect_Stop(); DmaClear16(3, PLTT, PLTT_SIZE); - addr = (void *)VRAM; - size = 0x18000; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } + DmaFill16Large(3, 0, (void *)(VRAM + 0x0), 0x18000, 0x1000); break; - } case 1: ResetSpriteData(); ResetTasks(); diff --git a/src/field/trader.c b/src/field/trader.c index 2801df322..885557d5a 100644 --- a/src/field/trader.c +++ b/src/field/trader.c @@ -217,8 +217,8 @@ void sub_8109D04(u8 taskId) { Menu_DestroyCursor(); Menu_EraseWindowRect(0, 0, 29, 19); - DestroyVerticalScrollIndicator(0); - DestroyVerticalScrollIndicator(1); + DestroyVerticalScrollIndicator(TOP_ARROW); + DestroyVerticalScrollIndicator(BOTTOM_ARROW); sub_80F9520(gUnknown_020388F7, 8); BuyMenuFreeMemory(); if (sub_80FEFA4() == TRUE) diff --git a/src/field/tv.c b/src/field/tv.c index e1eade130..8bd36bb9c 100644 --- a/src/field/tv.c +++ b/src/field/tv.c @@ -47,8 +47,6 @@ struct UnkTvStruct s8 var0; }; -extern u8 gUnknown_0300430A[11]; - struct OutbreakPokemon { /*0x00*/ u16 species; @@ -64,7 +62,7 @@ struct TVSaleItem { extern u8 gUnknown_02038694; -extern struct TVSaleItem gUnknown_02038724[3]; +extern struct TVSaleItem gMartPurchaseHistory[3]; struct UnkTvStruct gUnknown_03005D38; @@ -1032,7 +1030,7 @@ void sub_80BE3BC(void) if (gUnknown_03005D38.var0 != -1 && sub_80BF1B4(TVSHOW_SMART_SHOPPER) != 1) { sub_80BF20C(); - if (gUnknown_02038724[0].item_amount >= 20) + if (gMartPurchaseHistory[0].item_amount >= 20) { struct TVShowSmartShopper *smartShopper = &gSaveBlock1.tvShows[gUnknown_03005D38.var0].smartshopperShow; @@ -1041,8 +1039,8 @@ void sub_80BE3BC(void) smartShopper->shopLocation = gMapHeader.regionMapSectionId; for (i=0; i<3; i++) { - smartShopper->itemIds[i] = gUnknown_02038724[i].item_id; - smartShopper->itemAmounts[i] = gUnknown_02038724[i].item_amount; + smartShopper->itemIds[i] = gMartPurchaseHistory[i].item_id; + smartShopper->itemAmounts[i] = gMartPurchaseHistory[i].item_amount; } smartShopper->priceReduced = GetPriceReduction(1); StringCopy(smartShopper->playerName, gSaveBlock2.playerName); @@ -1646,14 +1644,14 @@ void sub_80BF20C(void) { for (j = i + 1; j < 3; j++) { - if (gUnknown_02038724[i].item_amount < gUnknown_02038724[j].item_amount) + if (gMartPurchaseHistory[i].item_amount < gMartPurchaseHistory[j].item_amount) { - tmpId = gUnknown_02038724[i].item_id; - tmpAmount = gUnknown_02038724[i].item_amount; - gUnknown_02038724[i].item_id = gUnknown_02038724[j].item_id; - gUnknown_02038724[i].item_amount = gUnknown_02038724[j].item_amount; - gUnknown_02038724[j].item_id = tmpId; - gUnknown_02038724[j].item_amount = tmpAmount; + tmpId = gMartPurchaseHistory[i].item_id; + tmpAmount = gMartPurchaseHistory[i].item_amount; + gMartPurchaseHistory[i].item_id = gMartPurchaseHistory[j].item_id; + gMartPurchaseHistory[i].item_amount = gMartPurchaseHistory[j].item_amount; + gMartPurchaseHistory[j].item_id = tmpId; + gMartPurchaseHistory[j].item_amount = tmpAmount; } } } diff --git a/src/field/wallclock.c b/src/field/wallclock.c index aaa7f9ae8..1f743a61a 100644 --- a/src/field/wallclock.c +++ b/src/field/wallclock.c @@ -190,10 +190,7 @@ static void WallClockVblankCallback(void) static void LoadWallClockGraphics(void) { - u8 *addr; - u32 size; - - SetVBlankCallback(0); + SetVBlankCallback(NULL); REG_DISPCNT = 0; REG_BG3CNT = 0; REG_BG2CNT = 0; @@ -208,19 +205,7 @@ static void LoadWallClockGraphics(void) REG_BG0HOFS = 0; REG_BG0VOFS = 0; - addr = (void *)VRAM; - size = 0x18000; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } + DmaFill16Large(3, 0, (void *)(VRAM + 0x0), 0x18000, 0x1000); DmaClear32(3, OAM, OAM_SIZE); DmaClear16(3, PLTT, PLTT_SIZE); diff --git a/src/field/wild_encounter.c b/src/field/wild_encounter.c index 10391348d..19778e29b 100644 --- a/src/field/wild_encounter.c +++ b/src/field/wild_encounter.c @@ -4285,7 +4285,7 @@ void FishingWildEncounter(u8 rod) gWildMonHeaders[GetCurrentMapWildMonHeader()].fishingMonsInfo, rod); } - IncrementGameStat(12); + IncrementGameStat(GAME_STAT_FISHING_CAPTURES); sub_80BEA50(species); BattleSetup_StartWildBattle(); } diff --git a/src/pokemon/mail.c b/src/pokemon/mail.c index 160bce913..db0c96938 100644 --- a/src/pokemon/mail.c +++ b/src/pokemon/mail.c @@ -1600,7 +1600,7 @@ void debug_sub_810CE1C() "._197:\n" " .align 2, 0\n" "._196:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" "\n" ); } @@ -1774,7 +1774,7 @@ void debug_sub_810CED0() " .word 0xffff\n" " .word gSaveBlock2\n" " .word 0x2b66\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_810CEA4+1\n" "._214:\n" " bl Menu_EraseScreen\n" @@ -2185,7 +2185,7 @@ void debug_sub_810D174() "._260:\n" " .align 2, 0\n" "._259:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_810CE48+1\n" "._249:\n" " ldr r1, ._262\n" @@ -2194,7 +2194,7 @@ void debug_sub_810D174() "._263:\n" " .align 2, 0\n" "._262:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_810CED0+1\n" "._255:\n" " ldr r1, ._265\n" @@ -2203,7 +2203,7 @@ void debug_sub_810D174() "._266:\n" " .align 2, 0\n" "._265:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_810CFA4+1\n" "._256:\n" " ldr r1, ._267\n" @@ -2222,7 +2222,7 @@ void debug_sub_810D174() "._268:\n" " .align 2, 0\n" "._267:\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_810D030+1\n" "\n" ); @@ -2313,7 +2313,7 @@ void debug_sub_810D340() " .align 2, 0\n" "._281:\n" " .word _84116BC\n" - " .word gCallback_03004AE8\n" + " .word gMenuCallback\n" " .word debug_sub_810D2F4+1\n" "\n" ); diff --git a/src/pokemon/mon_markings.c b/src/pokemon/mon_markings.c index 3734856b8..66c82a706 100644 --- a/src/pokemon/mon_markings.c +++ b/src/pokemon/mon_markings.c @@ -631,6 +631,5 @@ struct Sprite *sub_80F7960(u16 tileTag, u16 paletteTag, const u16 *palette, u16 void sub_80F7A10(u8 markings, void *dest) { - const void *src = gUnknown_083E4A14 + markings * 0x80; - DmaCopy16(3, src, dest, 0x80); + DmaCopy16Defvars(3, gUnknown_083E4A14 + markings * 0x80, dest, 0x80); } diff --git a/src/pokemon/pokeblock_feed.c b/src/pokemon/pokeblock_feed.c index 194636e4d..2f2ce2f8f 100644 --- a/src/pokemon/pokeblock_feed.c +++ b/src/pokemon/pokeblock_feed.c @@ -511,7 +511,7 @@ static bool8 TransitionToPokeblockFeedScene(void) switch (gMain.state) { case 0: - sub_80F9438(); + ClearVideoCallbacks(); sub_80F9368(); sub_8147B04(); gMain.state++; diff --git a/src/pokemon/pokedex.c b/src/pokemon/pokedex.c index 4f656a910..090873f9d 100644 --- a/src/pokemon/pokedex.c +++ b/src/pokemon/pokedex.c @@ -1394,29 +1394,12 @@ void CB2_InitPokedex(void) { case 0: default: - { - u8 *addr; - u32 size; - - SetVBlankCallback(NULL); - sub_8091060(0); - addr = (u8 *)VRAM; - size = VRAM_SIZE; - while (1) - { - DmaFill16(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, addr, size); - break; - } - } - DmaClear32(3, OAM, OAM_SIZE); - DmaClear16(3, PLTT, PLTT_SIZE); - gMain.state = 1; - } + SetVBlankCallback(NULL); + sub_8091060(0); + DmaFill16Large(3, 0, (void *)(VRAM + 0x0), VRAM_SIZE, 0x1000); + DmaClear32(3, OAM, OAM_SIZE); + DmaClear16(3, PLTT, PLTT_SIZE); + gMain.state = 1; break; case 1: ScanlineEffect_Stop(); @@ -4121,26 +4104,35 @@ bool8 CompletedHoennPokedex(void) return TRUE; } -u16 sub_8090FF4(void) +bool16 CompletedNationalPokedex(void) { u16 i; + // BUG: This function indexes pokemon checks by 0, but adds + // 1 before passing to GetSetPokedexFlag. Normally, this is + // fine, because GetSetPokedexFlag subtracts by 1 to get the + // array index value, but since the array is 0 indexed + // starting with Bulbasaur, values passed actually means that + // dex entries 152 (Chikorita) and 252 (Treecko) are skipped. + // Because an earlier Hoenn Dex check prevented Treecko from + // being skippable, it means that Chikorita is not required + // to obtain the National Diploma. This was fixed in Emerald. for (i = 0; i < 150; i++) { if (GetSetPokedexFlag(i + 1, 1) == 0) - return 0; + return FALSE; } for (i = 152; i < 250; i++) { if (GetSetPokedexFlag(i + 1, 1) == 0) - return 0; + return FALSE; } for (i = 252; i < 384; i++) { if (GetSetPokedexFlag(i + 1, 1) == 0) - return 0; + return FALSE; } - return 1; + return TRUE; } static void sub_8091060(u16 a) diff --git a/src/pokemon/pokemon_menu.c b/src/pokemon/pokemon_menu.c index 34d816387..8e1bd1671 100644 --- a/src/pokemon/pokemon_menu.c +++ b/src/pokemon/pokemon_menu.c @@ -51,7 +51,7 @@ extern u8 gUnknown_0202E8F5; extern u8 gUnknown_0202E8F6; extern u8 gUnknown_02038561; extern u16 gUnknown_0202E8F8; -extern void (*gUnknown_03004AE4)(u8 taskID, u16 itemID, TaskFunc func); +extern void (*gPokemonItemUseCallback)(u8 taskID, u16 itemID, TaskFunc func); extern TaskFunc gUnknown_03005CF0; void sub_808A520(void); @@ -786,7 +786,7 @@ void FieldCallback_Teleport(void) static void sub_808ABA8(u8 taskID) { - if (sub_807D770() == TRUE) + if (IsWeatherNotFadingIn() == TRUE) { gFieldEffectArguments[0] = GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_SPECIES); gUnknown_03005CE4(); @@ -1147,7 +1147,7 @@ void sub_808B0C0(u8 taskID) { sub_806D5A4(); if (gUnknown_02038561 == 0) - gUnknown_03004AE4(taskID, gSpecialVar_ItemId, sub_808B224); + gPokemonItemUseCallback(taskID, gSpecialVar_ItemId, sub_808B224); if (gUnknown_02038561 == 1) { PlaySE(SE_SELECT); @@ -1176,7 +1176,7 @@ void sub_808B0C0(u8 taskID) static void sub_808B1EC(u8 taskID) { if (!gPaletteFade.active) - gUnknown_03004AE4(taskID, gSpecialVar_ItemId, sub_808B224); + gPokemonItemUseCallback(taskID, gSpecialVar_ItemId, sub_808B224); } static void sub_808B224(u8 taskID) diff --git a/src/pokemon/pokemon_summary_screen.c b/src/pokemon/pokemon_summary_screen.c index 8f7c8728d..29973fd99 100644 --- a/src/pokemon/pokemon_summary_screen.c +++ b/src/pokemon/pokemon_summary_screen.c @@ -1213,9 +1213,6 @@ bool8 sub_809DA84(void) #else bool8 sub_809DA84(void) { - const u16 *src; - void *dest; - switch (gMain.state) { case 0: @@ -1232,8 +1229,7 @@ bool8 sub_809DA84(void) gMain.state++; break; case 3: - dest = (void *)VRAM; - DmaClearLarge(3, dest, 0x10000, 0x1000, 32); + DmaClearLarge(3, (void *)(VRAM + 0x0), 0x10000, 0x1000, 32); gMain.state++; break; case 4: @@ -1259,14 +1255,8 @@ bool8 sub_809DA84(void) gMain.state++; break; case 9: - src = gSummaryScreenTextTiles; - dest = (void *)VRAM + 0xD000; - DmaCopy16(3, src, dest, 320); - - src = sSummaryScreenButtonTiles; - dest = (void *)VRAM + 0xD140; - DmaCopy16(3, src, dest, 256); - + DmaCopy16Defvars(3, gSummaryScreenTextTiles, (void *)(VRAM + 0xD000), 320); + DmaCopy16Defvars(3, sSummaryScreenButtonTiles, (void *)(VRAM + 0xD140), 256); pssData.loadGfxState = 0; gMain.state++; break; @@ -4147,16 +4137,14 @@ static void DrawSummaryScreenNavigationDots(void) } } - dest = (void *)(VRAM + 0xE016); - DmaCopy16(3, arr, dest, 16); + DmaCopy16Defvars(3, arr, (void *)(VRAM + 0xE016), 16); for (i = 0; i < 8; i++) { arr[i] += 0x10; } - dest = (void *)(VRAM + 0xE056); - DmaCopy16(3, arr, dest, 16); + DmaCopy16Defvars(3, arr, (void *)(VRAM + 0xE056), 16); } #else __attribute__((naked)) diff --git a/src/rom6.c b/src/rom6.c index b23f1c15a..06e84cc0f 100644 --- a/src/rom6.c +++ b/src/rom6.c @@ -158,7 +158,7 @@ int FldEff_RockSmash(void) gTasks[taskId].data[8] = (u32)sub_810B58C >> 16; gTasks[taskId].data[9] = (u32)sub_810B58C; - IncrementGameStat(0x13); + IncrementGameStat(GAME_STAT_USED_ROCK_SMASH); return 0; } diff --git a/src/rom_8077ABC.c b/src/rom_8077ABC.c index 2b5a3c036..11a71155d 100644 --- a/src/rom_8077ABC.c +++ b/src/rom_8077ABC.c @@ -151,6 +151,7 @@ const struct SpriteSheet gUnknown_0837F5E0[] = { gMiscBlank_Gfx, 0x800, 55126, }, }; +// pkmn_form.c u8 GetBankPosition(u8 slot, u8 a2) { @@ -2149,6 +2150,8 @@ u8 sub_807A4A0(int a1, u8 sprite, int a3) return new_sprite; } +// unused_orb + void sub_807A544(struct Sprite *sprite) { sub_8078650(sprite); @@ -2192,6 +2195,8 @@ void sub_807A5C4(struct Sprite *sprite) sprite->callback = sub_8078504; } +// file_2 + void sub_807A63C(struct Sprite *sprite) { sub_8078650(sprite); @@ -2204,6 +2209,8 @@ void sub_807A63C(struct Sprite *sprite) StoreSpriteCallbackInData(sprite, DestroyAnimSprite); } +// file_3 (punch effect?) + void sub_807A69C(u8 taskId) { u16 src; @@ -2287,6 +2294,8 @@ void sub_807A8D4(struct Sprite *sprite) } } +// file_4 + void sub_807A908(struct Sprite *sprite) { sprite->pos1.x = GetBankPosition(gAnimBankAttacker, 2); sprite->pos1.y = GetBankPosition(gAnimBankAttacker, 3); diff --git a/src/roulette.c b/src/roulette.c index 240ca11fa..e01f085a2 100644 --- a/src/roulette.c +++ b/src/roulette.c @@ -624,7 +624,7 @@ void sub_8115384(void) mov r0, #0x0\n\ bl SetVBlankCallback\n\ bl ScanlineEffect_Stop\n\ - bl sub_80F9438\n\ + bl ClearVideoCallbacks\n\ bl sub_80F9368\n\ ldr r1, ._47\n\ ldr r3, ._47 + 4\n\ @@ -703,7 +703,7 @@ void sub_8115384(void) .word 0x43c\n\ ._41:\n\ bl sub_8115238\n\ - bl sub_80F9020\n\ + bl ClearBGTilemapBuffers\n\ ldr r0, ._56\n\ ldr r1, ._56 + 4\n\ bl gMysteryEventScriptCmdTableEnd+0x3cbc\n\ @@ -887,7 +887,7 @@ void sub_8115384(void) case 0x0: SetVBlankCallback(NULL); ScanlineEffect_Stop(); - sub_80F9438(); + ClearVideoCallbacks(); sub_80F9368(); REG_BG2CNT = 0x4686; REG_BG1CNT = 0x4401; @@ -911,7 +911,7 @@ void sub_8115384(void) break; case 0x3: sub_8115238(); - sub_80F9020(); + ClearBGTilemapBuffers(); LZ77UnCompWram(&gUnknown_083F88BC, (void *)(ewram18800)); LZ77UnCompVram(&gUnknown_083F8A60, (void *)(VRAM + 0x3000)); gMain.state++; @@ -2044,7 +2044,7 @@ void sub_8116B40(u8 taskid) // end roulette ? bl FreeAllSpritePalettes\n\ bl ResetPaletteFade\n\ bl ResetSpriteData\n\ - bl sub_80F9020\n\ + bl ClearBGTilemapBuffers\n\ ldr r0, ._381 + 12\n\ strh r5, [r0]\n\ add r0, r0, #0x2\n\ @@ -2088,7 +2088,7 @@ void sub_8116B40(u8 taskid) // end roulette ? FreeAllSpritePalettes(); ResetPaletteFade(); ResetSpriteData(); - sub_80F9020(); + ClearBGTilemapBuffers(); REG_BLDCNT = 0x0; REG_BLDALPHA = 0x0; REG_BLDY = 0x0; diff --git a/src/scene/berry_blender.c b/src/scene/berry_blender.c index a93313e37..2535f02a6 100644 --- a/src/scene/berry_blender.c +++ b/src/scene/berry_blender.c @@ -832,34 +832,13 @@ static bool8 sub_804E2EC(void) gBerryBlenderData->field_1++; break; case 1: - { - const void* offsetRead = sBlenderCenterMap; - void* offsetWrite = (void*)(VRAM + 0x4000); - - DmaCopy16(3, offsetRead, offsetWrite, 0x400); - LoadPalette(sBlenderCenterPal, 0, 0x100); - gBerryBlenderData->field_1++; - } + DmaCopy16Defvars(3, sBlenderCenterMap, (void *)(VRAM + 0x4000), 0x400); + LoadPalette(sBlenderCenterPal, 0, 0x100); + gBerryBlenderData->field_1++; break; case 2: - { - void* offsetRead = ewram10000; - void* offsetWrite = (void*)(VRAM); - u32 size = 0x2000; - while (TRUE) - { - DmaCopy16(3, offsetRead, offsetWrite, 0x1000); - offsetRead += 0x1000; - offsetWrite += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaCopy16(3, offsetRead, offsetWrite, size); - break; - } - } - gBerryBlenderData->field_1++; - } + DmaCopyLarge16(3, ewram10000, (void *)(VRAM + 0x0), 0x2000, 0x1000); + gBerryBlenderData->field_1++; break; case 3: LZDecompressWram(gUnknown_08E6C920, ewram10000); @@ -870,37 +849,23 @@ static bool8 sub_804E2EC(void) gBerryBlenderData->field_1++; break; case 5: - { - void* offsetRead = ewram10000; - void* offsetWrite = (void*)(VRAM + 0xE000); - - DmaCopy16(3, offsetRead, offsetWrite, 0x1000); - gBerryBlenderData->field_1++; - } + DmaCopy16Defvars(3, ewram10000, (void *)(VRAM + 0xE000), 0x1000); + gBerryBlenderData->field_1++; break; case 6: - { - void* offsetRead = ewram11000; - void* offsetWrite = (void*)(VRAM + 0xF000); - - DmaCopy16(3, offsetRead, offsetWrite, 0x1000); - gBerryBlenderData->field_1++; - } + DmaCopy16Defvars(3, ewram11000, (void *)(VRAM + 0xF000), 0x1000); + gBerryBlenderData->field_1++; break; case 7: { u16 i; u16* palStore = (u16*)(ewram13000); - void* offsetRead; - void* offsetWrite; for (i = 0; i < 640; i++) { *(palStore + i) |= 0x100; } - offsetRead = ewram13000; - offsetWrite = (void*)(VRAM + 0x6000); - DmaCopy16(3, offsetRead, offsetWrite, 0x500); + DmaCopy16Defvars(3, ewram13000, (void *)(VRAM + 0x6000), 0x500); LoadPalette(sBlenderOuterPal, 0x80, 0x20); gBerryBlenderData->field_1++; } @@ -2567,9 +2532,9 @@ static void sub_8050954(void) if (Blender_PrintBlendingResults()) { if (gInGameOpponentsNo == 0) - IncrementGameStat(34); + IncrementGameStat(GAME_STAT_POKEBLOCKS_WITH_FRIENDS); else - IncrementGameStat(33); + IncrementGameStat(GAME_STAT_POKEBLOCKS); gBerryBlenderData->field_6F++; } break; diff --git a/src/scene/cable_car.c b/src/scene/cable_car.c index 4bf0cef09..d81263f87 100644 --- a/src/scene/cable_car.c +++ b/src/scene/cable_car.c @@ -19,6 +19,7 @@ #include "event_data.h" #include "cable_car_util.h" #include "constants/map_objects.h" +#include "constants/weather.h" // Static type declarations @@ -354,7 +355,7 @@ u8 debug_sub_8138CC4(void) ._14:\n\ .word gSpecialVar_0x8004\n\ .word gUnkDebug4Menu\n\ - .word gCallback_03004AE8\n\ + .word gMenuCallback\n\ .word debug_sub_8138C54+1"); } @@ -546,7 +547,7 @@ static void sub_8123740(void) i = 0; sub_8123FBC(0); gSpriteCoordOffsetX = 0; - sub_807C9B4(0); + sub_807C9B4(WEATHER_NONE); for (; i < 20; i++) { gWeatherPtr->sprites.s2.ashSprites[i] = NULL; @@ -575,7 +576,7 @@ static void sub_8123878(u8 taskId) case 0: if (sCableCarPtr->unk_0006 == sCableCarPtr->unk_0004) { - DoWeatherEffect(sCableCarPtr->unk_0002); + ChangeWeather(sCableCarPtr->unk_0002); sCableCarPtr->unk_0001 = 1; } break; @@ -987,7 +988,7 @@ static void LoadSprites(void) gSprites[spriteId].data[1] = 0x63; sCableCarPtr->unk_0002 = 7; sCableCarPtr->unk_0004 = 0x15e; - sub_807C9B4(2); + sub_807C9B4(WEATHER_SUNNY); break; case 1: CableCarUtil_CopyWrapped(sCableCarPtr->unk_00fc, eCableCar2->mtChimneyTilemap + 0x24, 0x18, 0x1a, 0x0c, 0x03); @@ -1011,7 +1012,7 @@ static void LoadSprites(void) gSprites[spriteId].data[1] = 0x41; sCableCarPtr->unk_0002 = 2; sCableCarPtr->unk_0004 = 0x109; - sub_807C9B4(7); + sub_807C9B4(WEATHER_ASH); break; } for (i = 0; i < 9; i++) diff --git a/src/scene/contest_painting.c b/src/scene/contest_painting.c index 3aa898b03..0aa02312f 100644 --- a/src/scene/contest_painting.c +++ b/src/scene/contest_painting.c @@ -156,23 +156,8 @@ static void ShowContestPainting(void) break; case 1: { - u8 *addr; - size_t size; - ResetPaletteFade(); - addr = (void *)VRAM; - size = 0x18000; - while (1) - { - DmaFill32(3, 0, addr, 0x1000); - addr += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill32(3, 0, addr, size); - break; - } - } + DmaFill32Large(3, 0, (void *)(VRAM + 0x0), 0x18000, 0x1000); ResetSpriteData(); gMain.state++; break; diff --git a/src/scene/egg_hatch.c b/src/scene/egg_hatch.c index e0b798aea..282ad31fb 100644 --- a/src/scene/egg_hatch.c +++ b/src/scene/egg_hatch.c @@ -504,35 +504,11 @@ static void CB2_EggHatch_0(void) gMain.state++; break; case 7: - { - u32 offsetRead, offsetWrite; - u32 offsetRead2, offsetWrite2; - u32 size; - - REG_BG2CNT = 0x4C06; - LoadPalette(gUnknown_0820C9F8, 0x10, 0xA0); - - offsetRead = (u32)(&gUnknown_0820CA98); - offsetWrite = (VRAM + 0x4000); - size = 0x1300; - while (TRUE) - { - DmaCopy16(3, offsetRead, (void *) (offsetWrite), 0x1000); - offsetRead += 0x1000; - offsetWrite += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaCopy16(3, offsetRead, (void *) (offsetWrite), size); - break; - } - } - - offsetRead2 = (u32)(&gUnknown_0820F798); - offsetWrite2 = (u32)(VRAM + 0x6000); - DmaCopy16(3, offsetRead2, (void*)(offsetWrite2), 0x1000); - gMain.state++; - } + REG_BG2CNT = 0x4C06; + LoadPalette(gUnknown_0820C9F8, 0x10, 0xA0); + DmaCopyLarge16(3, gUnknown_0820CA98, (void *)(VRAM + 0x4000), 0x1300, 0x1000); + DmaCopy16Defvars(3, gUnknown_0820F798, (void *)(VRAM + 0x6000), 0x1000); + gMain.state++; break; case 8: REG_BG1CNT = 0x501; diff --git a/src/scene/evolution_scene.c b/src/scene/evolution_scene.c index 931ec0d4d..3ba325574 100644 --- a/src/scene/evolution_scene.c +++ b/src/scene/evolution_scene.c @@ -649,7 +649,7 @@ static void Task_EvolutionScene(u8 taskID) EvolutionRenameMon(mon, gTasks[taskID].tPreEvoSpecies, gTasks[taskID].tPostEvoSpecies); GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskID].tPostEvoSpecies), 2); GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskID].tPostEvoSpecies), 3); - IncrementGameStat(14); + IncrementGameStat(GAME_STAT_EVOLVED_POKEMON); } break; case 14: // check if it wants to learn a new move @@ -991,7 +991,7 @@ static void Task_TradeEvolutionScene(u8 taskID) EvolutionRenameMon(mon, gTasks[taskID].tPreEvoSpecies, gTasks[taskID].tPostEvoSpecies); GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskID].tPostEvoSpecies), 2); GetSetPokedexFlag(SpeciesToNationalPokedexNum(gTasks[taskID].tPostEvoSpecies), 3); - IncrementGameStat(14); + IncrementGameStat(GAME_STAT_EVOLVED_POKEMON); } break; case 13: diff --git a/src/scene/hall_of_fame.c b/src/scene/hall_of_fame.c index a9532fd09..e486c65a3 100644 --- a/src/scene/hall_of_fame.c +++ b/src/scene/hall_of_fame.c @@ -1199,8 +1199,6 @@ static void HallOfFame_PrintPlayerInfo(u8 a0, u8 a1) static void sub_81433E0(void) { - u32 offsetWrite, offsetWrite2, offsetWrite3, offsetWrite4; - u32 size, size2, size3, size4; u16 i; REG_DISPCNT = 0; @@ -1221,27 +1219,9 @@ static void sub_81433E0(void) REG_BG3HOFS = 0; REG_BG3VOFS = 0; - offsetWrite = (VRAM); - size = 0x18000; - while (TRUE) - { - DmaFill16(3, 0, offsetWrite, 0x1000); - offsetWrite += 0x1000; - size -= 0x1000; - if (size <= 0x1000) - { - DmaFill16(3, 0, offsetWrite, size); - break; - } - } - - offsetWrite2 = OAM; - size2 = OAM_SIZE; - DmaFill32(3, 0, offsetWrite2, size2); - - offsetWrite3 = PLTT; - size3 = PLTT_SIZE; - DmaFill16(3, 0, offsetWrite3, size3); + DmaFill16Large(3, 0, VRAM, 0x18000, 0x1000); + DmaFill32Defvars(3, 0, OAM, OAM_SIZE); + DmaFill16Defvars(3, 0, PLTT, PLTT_SIZE); LZ77UnCompVram(gHallOfFame_Gfx, (void*)(VRAM)); @@ -1258,20 +1238,7 @@ static void sub_81433E0(void) *((u16*)(VRAM + 0x3000) + i) = 2; } - offsetWrite4 = ewram0_6; - size4 = 0x4000; - while (TRUE) - { - DmaFill16(3, 0, offsetWrite4, 0x1000); - offsetWrite4 += 0x1000; - size4 -= 0x1000; - if (size4 <= 0x1000) - { - DmaFill16(3, 0, offsetWrite4, size4); - break; - } - } - + DmaFill16Large(3, 0, ewram0_6, 0x4000, 0x1000); ResetPaletteFade(); LoadPalette(gHallOfFame_Pal, 0, 0x20); } diff --git a/src/scene/intro.c b/src/scene/intro.c index f7e196133..4da341744 100644 --- a/src/scene/intro.c +++ b/src/scene/intro.c @@ -1217,7 +1217,6 @@ static void Task_IntroWaitToSetupPart3DoubleFight(u8 taskId) static void Task_IntroLoadPart3Streaks(u8 taskId) { u16 i; - void *vram; intro_reset_and_hide_bgs(); for (i = 0; i < 32; i++) @@ -1226,8 +1225,7 @@ static void Task_IntroLoadPart3Streaks(u8 taskId) ewram0arr[1][i] = 17; ewram0arr[2][i] = 34; } - vram = (void *)VRAM; - DmaCopy16(3, gSharedMem, vram, 0x60); + DmaCopy16Defvars(3, gSharedMem, (void *)(VRAM + 0x0), 0x60); for (i = 0; i < 0x280; i++) ((u16 *)(VRAM + 0x3000))[i] = 0xF001; for (i = 0; i < 0x80; i++) |