From 072a98ca9aea8bfea7edc65f0a4a230974362b96 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Sat, 25 Apr 2020 18:25:55 -0700 Subject: [PATCH 01/43] Document undefined sprite template behavior --- gflib/sprite.c | 2 ++ gflib/sprite.h | 4 ++++ src/mevent2.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/gflib/sprite.c b/gflib/sprite.c index 2e96acf2c..c7e3d09a3 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -878,12 +878,14 @@ void ResetAllSprites(void) ResetSprite(&gSprites[i]); } +// UB: template pointer may point to freed temporary storage void FreeSpriteTiles(struct Sprite *sprite) { if (sprite->template->tileTag != 0xFFFF) FreeSpriteTilesByTag(sprite->template->tileTag); } +// UB: template pointer may point to freed temporary storage void FreeSpritePalette(struct Sprite *sprite) { FreeSpritePaletteByTag(sprite->template->paletteTag); diff --git a/gflib/sprite.h b/gflib/sprite.h index 9753837fd..c9ba9585d 100644 --- a/gflib/sprite.h +++ b/gflib/sprite.h @@ -182,6 +182,10 @@ struct SpriteTemplate SpriteCallback callback; }; +// UB: template pointer is often used to point to temporary storage, +// then later dereferenced after being freed. Usually this won't +// be visible in-game, but this is (part of) what causes the item +// icon palette to flicker when changing items in the bag. struct Sprite { /*0x00*/ struct OamData oam; diff --git a/src/mevent2.c b/src/mevent2.c index 0bbaf6db8..2991ac27c 100755 --- a/src/mevent2.c +++ b/src/mevent2.c @@ -484,9 +484,13 @@ static void sub_801B7D8(u32 command) } if (dest == NULL) + { AGB_ASSERT(0); + } else if (++(*dest) > 999) + { *dest = 999; + } } } From b057411eea7dc3dc68aed71022c51debd34f3eda Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 29 Apr 2020 16:39:14 -0400 Subject: [PATCH 02/43] Fix -Wmissing-braces clang warning --- tools/gbagfx/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/gbagfx/main.c b/tools/gbagfx/main.c index 9fd72383d..957918505 100644 --- a/tools/gbagfx/main.c +++ b/tools/gbagfx/main.c @@ -210,7 +210,7 @@ void HandlePngToGbaCommand(char *inputPath, char *outputPath, int argc, char **a void HandlePngToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) { - struct Palette palette = {0}; + struct Palette palette = {}; ReadPngPalette(inputPath, &palette); WriteJascPalette(outputPath, &palette); @@ -218,7 +218,7 @@ void HandlePngToJascPaletteCommand(char *inputPath, char *outputPath, int argc U void HandlePngToGbaPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) { - struct Palette palette = {0}; + struct Palette palette = {}; ReadPngPalette(inputPath, &palette); WriteGbaPalette(outputPath, &palette); @@ -226,7 +226,7 @@ void HandlePngToGbaPaletteCommand(char *inputPath, char *outputPath, int argc UN void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED) { - struct Palette palette = {0}; + struct Palette palette = {}; ReadGbaPalette(inputPath, &palette); WriteJascPalette(outputPath, &palette); @@ -259,7 +259,7 @@ void HandleJascToGbaPaletteCommand(char *inputPath, char *outputPath, int argc, } } - struct Palette palette = {0}; + struct Palette palette = {}; ReadJascPalette(inputPath, &palette); From 67e930941509cae20055f51bf14cb88c3617e234 Mon Sep 17 00:00:00 2001 From: SBird Date: Fri, 1 May 2020 20:51:29 +0200 Subject: [PATCH 03/43] gfx: fix hpbar_anim.png visual palette --- graphics/battle_interface/hpbar_anim.png | Bin 205 -> 216 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/graphics/battle_interface/hpbar_anim.png b/graphics/battle_interface/hpbar_anim.png index 9e7564234eb702b3b0ba600ecd4fe1dbeaf87523..5817a6e675ece82306810ed6ab2a7572deba7a71 100644 GIT binary patch delta 200 zcmX@hc!P0*L_G&H0|SHN+O{P?im^Dz-HBn{IhmJ0jzNG=h%1n`w6y&H|Nqsqdz+iP zy&R*0vZDTPss1*l_+D02@&7eZSDXJovplE|8uc$*d5`G`|JAt01boFyt=akR{0Nwdjq5uE@ delta 189 zcmcb?c$RU3L_G^L0|Ud8*zBc1${@fe#1%*b!TrFR9 z?gxD1N!8D7F;GfTPHAT|ligyl>*<203*KjP>+zIF7DTRd>=bgFs^TSNT7K)s=H Date: Sat, 2 May 2020 11:46:12 -0400 Subject: [PATCH 04/43] Document berry yield fix wording --- include/berry.h | 2 ++ src/berry.c | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/berry.h b/include/berry.h index afd1bc499..b583f3eb2 100644 --- a/include/berry.h +++ b/include/berry.h @@ -1,6 +1,8 @@ #ifndef GUARD_BERRY_H #define GUARD_BERRY_H +#define NUM_BERRY_STAGES 4 + void ClearEnigmaBerries(void); void SetEnigmaBerry(u8 *src); bool32 IsEnigmaBerryValid(void); diff --git a/src/berry.c b/src/berry.c index 7a8ab37fa..3f59639ad 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1200,6 +1200,15 @@ static u8 GetNumStagesWateredByBerryTreeId(u8 id) return BerryTreeGetNumStagesWatered(GetBerryTreeInfo(id)); } +// Berries can be watered at 4 stages of growth. This function is likely meant +// to divide the berry yield range equally into quartiles. If you watered the +// tree n times, your yield is a random number in the nth quartile. +// +// However, this function actually skews towards higher berry yields, because +// it rounds `extraYield` to the nearest whole number. +// +// See resulting yields: https://pastebin.com/RLGnP9Ng, and +// bug fix: https://pastebin.com/cDjnUWL0. static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) { u32 randMin; @@ -1215,10 +1224,11 @@ static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) randMax = (max - min) * (water); rand = randMin + Random() % (randMax - randMin + 1); - if ((rand & 3) > 1) - extraYield = rand / 4 + 1; + // Round upwards + if ((rand % NUM_BERRY_STAGES) >= NUM_BERRY_STAGES / 2) + extraYield = rand / NUM_BERRY_STAGES + 1; else - extraYield = rand / 4; + extraYield = rand / NUM_BERRY_STAGES; return extraYield + min; } } From 048d1ffbdbe00e56ee4511d023885a11d018864b Mon Sep 17 00:00:00 2001 From: hondew Date: Sat, 2 May 2020 13:38:25 -0400 Subject: [PATCH 05/43] Clarify stages --- include/berry.h | 2 -- include/constants/berry.h | 7 +++++++ src/berry.c | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/berry.h b/include/berry.h index b583f3eb2..afd1bc499 100644 --- a/include/berry.h +++ b/include/berry.h @@ -1,8 +1,6 @@ #ifndef GUARD_BERRY_H #define GUARD_BERRY_H -#define NUM_BERRY_STAGES 4 - void ClearEnigmaBerries(void); void SetEnigmaBerry(u8 *src); bool32 IsEnigmaBerryValid(void); diff --git a/include/constants/berry.h b/include/constants/berry.h index d413b9947..8f1e7cd82 100644 --- a/include/constants/berry.h +++ b/include/constants/berry.h @@ -25,4 +25,11 @@ #define BERRY_STAGE_BERRIES 5 #define BERRY_STAGE_SPARKLING 255 +// Berries can be watered in the following stages: +// - BERRY_STAGE_PLANTED +// - BERRY_STAGE_SPROUTED +// - BERRY_STAGE_TALLER +// - BERRY_STAGE_FLOWERING +#define NUM_WATER_STAGES 4 + #endif // GUARD_CONSTANTS_BERRY_H diff --git a/src/berry.c b/src/berry.c index 3f59639ad..e548d3c57 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1225,10 +1225,10 @@ static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) rand = randMin + Random() % (randMax - randMin + 1); // Round upwards - if ((rand % NUM_BERRY_STAGES) >= NUM_BERRY_STAGES / 2) - extraYield = rand / NUM_BERRY_STAGES + 1; + if ((rand % NUM_WATER_STAGES) >= NUM_WATER_STAGES / 2) + extraYield = rand / NUM_WATER_STAGES + 1; else - extraYield = rand / NUM_BERRY_STAGES; + extraYield = rand / NUM_WATER_STAGES; return extraYield + min; } } From 84f012fc6e653df33158e494bab95e18557a2161 Mon Sep 17 00:00:00 2001 From: hondew Date: Sat, 2 May 2020 13:59:28 -0400 Subject: [PATCH 06/43] Update external links --- src/berry.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/berry.c b/src/berry.c index e548d3c57..fe4a66af6 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1207,8 +1207,8 @@ static u8 GetNumStagesWateredByBerryTreeId(u8 id) // However, this function actually skews towards higher berry yields, because // it rounds `extraYield` to the nearest whole number. // -// See resulting yields: https://pastebin.com/RLGnP9Ng, and -// bug fix: https://pastebin.com/cDjnUWL0. +// See resulting yields: https://gist.github.com/hondew/2a099dbe54aa91414decdbfaa524327d, +// and bug fix: https://gist.github.com/hondew/0f0164e5b9dadfd72d24f30f2c049a0b. static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) { u32 randMin; From f6932518b0d9cb123943d7a67994ac03d3df8237 Mon Sep 17 00:00:00 2001 From: AsparagusEduardo Date: Sun, 3 May 2020 00:00:01 -0400 Subject: [PATCH 07/43] Ordered OLD_UNOWN in the same way as the other base stats. --- src/data/pokemon/base_stats.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/pokemon/base_stats.h b/src/data/pokemon/base_stats.h index 2f493bc1b..4dedcfdc0 100644 --- a/src/data/pokemon/base_stats.h +++ b/src/data/pokemon/base_stats.h @@ -7,9 +7,9 @@ .baseHP = 50, \ .baseAttack = 150, \ .baseDefense = 50, \ + .baseSpeed = 150, \ .baseSpAttack = 150, \ .baseSpDefense = 50, \ - .baseSpeed = 150, \ .type1 = TYPE_NORMAL, \ .type2 = TYPE_NORMAL, \ .catchRate = 3, \ From a35ce6ecdf4074e8b0b3675b390f9ac63d80757b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 3 May 2020 11:12:05 +0200 Subject: [PATCH 08/43] Give a define for all dex interface sprites for easier editing --- src/pokedex.c | 306 +++++++++++++++++++++++++------------------------- 1 file changed, 154 insertions(+), 152 deletions(-) diff --git a/src/pokedex.c b/src/pokedex.c index 080548553..c3d38681c 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -666,10 +666,12 @@ static const union AnimCmd *const sSpriteAnimTable_DexListStartMenuCursor[] = sSpriteAnim_DexListStartMenuCursor }; +#define TAG_DEX_INTERFACE 4096 // Tile and pal tag used for all interface sprites. + static const struct SpriteTemplate sScrollBarSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_ScrollBar, .anims = sSpriteAnimTable_ScrollBar, .images = NULL, @@ -679,8 +681,8 @@ static const struct SpriteTemplate sScrollBarSpriteTemplate = static const struct SpriteTemplate sScrollArrowSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_ScrollArrow, .anims = sSpriteAnimTable_ScrollArrow, .images = NULL, @@ -690,8 +692,8 @@ static const struct SpriteTemplate sScrollArrowSpriteTemplate = static const struct SpriteTemplate sInterfaceTextSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_InterfaceText, .anims = sSpriteAnimTable_InterfaceText, .images = NULL, @@ -701,8 +703,8 @@ static const struct SpriteTemplate sInterfaceTextSpriteTemplate = static const struct SpriteTemplate sRotatingPokeBallSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_RotatingPokeBall, .anims = sSpriteAnimTable_RotatingPokeBall, .images = NULL, @@ -712,8 +714,8 @@ static const struct SpriteTemplate sRotatingPokeBallSpriteTemplate = static const struct SpriteTemplate sSeenOwnTextSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_SeenOwnText, .anims = sSpriteAnimTable_SeenOwnText, .images = NULL, @@ -723,8 +725,8 @@ static const struct SpriteTemplate sSeenOwnTextSpriteTemplate = static const struct SpriteTemplate sHoennNationalTextSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_InterfaceText, .anims = sSpriteAnimTable_HoennNationalText, .images = NULL, @@ -734,8 +736,8 @@ static const struct SpriteTemplate sHoennNationalTextSpriteTemplate = static const struct SpriteTemplate sHoennDexSeenOwnNumberSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_Dex8x16, .anims = sSpriteAnimTable_HoennSeenOwnNumber, .images = NULL, @@ -745,8 +747,8 @@ static const struct SpriteTemplate sHoennDexSeenOwnNumberSpriteTemplate = static const struct SpriteTemplate sNationalDexSeenOwnNumberSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_Dex8x16, .anims = sSpriteAnimTable_NationalSeenOwnNumber, .images = NULL, @@ -756,8 +758,8 @@ static const struct SpriteTemplate sNationalDexSeenOwnNumberSpriteTemplate = static const struct SpriteTemplate sDexListStartMenuCursorSpriteTemplate = { - .tileTag = 4096, - .paletteTag = 4096, + .tileTag = TAG_DEX_INTERFACE, + .paletteTag = TAG_DEX_INTERFACE, .oam = &sOamData_Dex8x16, .anims = sSpriteAnimTable_DexListStartMenuCursor, .images = NULL, @@ -767,13 +769,13 @@ static const struct SpriteTemplate sDexListStartMenuCursorSpriteTemplate = static const struct CompressedSpriteSheet sInterfaceSpriteSheet[] = { - {gPokedexInterface_Gfx, 0x2000, 4096}, + {gPokedexInterface_Gfx, 0x2000, TAG_DEX_INTERFACE}, {0} }; static const struct SpritePalette sInterfaceSpritePalette[] = { - {gPokedexBgHoenn_Pal, 4096}, + {gPokedexBgHoenn_Pal, TAG_DEX_INTERFACE}, {0} }; @@ -893,7 +895,7 @@ static const struct BgTemplate sInfoScreen_BgTemplate[] = static const struct WindowTemplate sInfoScreen_WindowTemplates[] = { - [WIN_INFO] = + [WIN_INFO] = { .bg = 2, .tilemapLeft = 0, @@ -903,7 +905,7 @@ static const struct WindowTemplate sInfoScreen_WindowTemplates[] = .paletteNum = 0, .baseBlock = 1, }, - [WIN_FOOTPRINT] = + [WIN_FOOTPRINT] = { .bg = 2, .tilemapLeft = 25, @@ -913,7 +915,7 @@ static const struct WindowTemplate sInfoScreen_WindowTemplates[] = .paletteNum = 15, .baseBlock = 641, }, - [WIN_CRY_WAVE] = + [WIN_CRY_WAVE] = { .bg = 0, .tilemapLeft = 0, @@ -923,7 +925,7 @@ static const struct WindowTemplate sInfoScreen_WindowTemplates[] = .paletteNum = 8, .baseBlock = 645, }, - [WIN_VU_METER] = + [WIN_VU_METER] = { .bg = 2, .tilemapLeft = 18, @@ -960,7 +962,7 @@ static const struct BgTemplate sNewEntryInfoScreen_BgTemplate[] = static const struct WindowTemplate sNewEntryInfoScreen_WindowTemplates[] = { - [WIN_INFO] = + [WIN_INFO] = { .bg = 2, .tilemapLeft = 0, @@ -970,7 +972,7 @@ static const struct WindowTemplate sNewEntryInfoScreen_WindowTemplates[] = .paletteNum = 0, .baseBlock = 1, }, - [WIN_FOOTPRINT] = + [WIN_FOOTPRINT] = { .bg = 2, .tilemapLeft = 25, @@ -1012,21 +1014,21 @@ static const u8 sLetterSearchRanges[][4] = static const struct SearchMenuTopBarItem sSearchMenuTopBarItems[SEARCH_TOPBAR_COUNT] = { - [SEARCH_TOPBAR_SEARCH] = + [SEARCH_TOPBAR_SEARCH] = { .description = gText_SearchForPkmnBasedOnParameters, .highlightX = 0, .highlightY = 0, .highlightWidth = 5, }, - [SEARCH_TOPBAR_SHIFT] = + [SEARCH_TOPBAR_SHIFT] = { .description = gText_SwitchPokedexListings, .highlightX = 6, .highlightY = 0, .highlightWidth = 5, }, - [SEARCH_TOPBAR_CANCEL] = + [SEARCH_TOPBAR_CANCEL] = { .description = gText_ReturnToPokedex, .highlightX = 12, @@ -1037,7 +1039,7 @@ static const struct SearchMenuTopBarItem sSearchMenuTopBarItems[SEARCH_TOPBAR_CO static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = { - [SEARCH_NAME] = + [SEARCH_NAME] = { .description = gText_ListByFirstLetter, .titleBgX = 0, @@ -1047,7 +1049,7 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = .selectionBgY = 2, .selectionBgWidth = 12, }, - [SEARCH_COLOR] = + [SEARCH_COLOR] = { .description = gText_ListByBodyColor, .titleBgX = 0, @@ -1057,7 +1059,7 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = .selectionBgY = 4, .selectionBgWidth = 12, }, - [SEARCH_TYPE_LEFT] = + [SEARCH_TYPE_LEFT] = { .description = gText_ListByType, .titleBgX = 0, @@ -1067,7 +1069,7 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = .selectionBgY = 6, .selectionBgWidth = 6, }, - [SEARCH_TYPE_RIGHT] = + [SEARCH_TYPE_RIGHT] = { .description = gText_ListByType, .titleBgX = 0, @@ -1077,7 +1079,7 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = .selectionBgY = 6, .selectionBgWidth = 6, }, - [SEARCH_ORDER] = + [SEARCH_ORDER] = { .description = gText_SelectPokedexListingMode, .titleBgX = 0, @@ -1087,7 +1089,7 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = .selectionBgY = 8, .selectionBgWidth = 12, }, - [SEARCH_MODE] = + [SEARCH_MODE] = { .description = gText_SelectPokedexMode, .titleBgX = 0, @@ -1097,7 +1099,7 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = .selectionBgY = 10, .selectionBgWidth = 12, }, - [SEARCH_OK] = + [SEARCH_OK] = { .description = gText_ExecuteSearchSwitch, .titleBgX = 0, @@ -1112,52 +1114,52 @@ static const struct SearchMenuItem sSearchMenuItems[SEARCH_COUNT] = // Left, Right, Up, Down static const u8 sSearchMovementMap_SearchNatDex[SEARCH_COUNT][4] = { - [SEARCH_NAME] = + [SEARCH_NAME] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, SEARCH_COLOR }, - [SEARCH_COLOR] = + [SEARCH_COLOR] = { - 0xFF, - 0xFF, - SEARCH_NAME, + 0xFF, + 0xFF, + SEARCH_NAME, SEARCH_TYPE_LEFT }, - [SEARCH_TYPE_LEFT] = - { - 0xFF, - SEARCH_TYPE_RIGHT, - SEARCH_COLOR, - SEARCH_ORDER - }, - [SEARCH_TYPE_RIGHT] = - { SEARCH_TYPE_LEFT, - 0xFF, - SEARCH_COLOR, - SEARCH_ORDER - }, - [SEARCH_ORDER] = + [SEARCH_TYPE_LEFT] = { - 0xFF, - 0xFF, - SEARCH_TYPE_LEFT, + 0xFF, + SEARCH_TYPE_RIGHT, + SEARCH_COLOR, + SEARCH_ORDER + }, + [SEARCH_TYPE_RIGHT] = + { SEARCH_TYPE_LEFT, + 0xFF, + SEARCH_COLOR, + SEARCH_ORDER + }, + [SEARCH_ORDER] = + { + 0xFF, + 0xFF, + SEARCH_TYPE_LEFT, SEARCH_MODE }, - [SEARCH_MODE] = + [SEARCH_MODE] = { - 0xFF, - 0xFF, - SEARCH_ORDER, + 0xFF, + 0xFF, + SEARCH_ORDER, SEARCH_OK }, - [SEARCH_OK] = + [SEARCH_OK] = { - 0xFF, - 0xFF, - SEARCH_MODE, + 0xFF, + 0xFF, + SEARCH_MODE, 0xFF }, }; @@ -1165,53 +1167,53 @@ static const u8 sSearchMovementMap_SearchNatDex[SEARCH_COUNT][4] = // Left, Right, Up, Down static const u8 sSearchMovementMap_ShiftNatDex[SEARCH_COUNT][4] = { - [SEARCH_NAME] = + [SEARCH_NAME] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_COLOR] = + [SEARCH_COLOR] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_TYPE_LEFT] = + [SEARCH_TYPE_LEFT] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_TYPE_RIGHT] = + [SEARCH_TYPE_RIGHT] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_ORDER] = + [SEARCH_ORDER] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, SEARCH_MODE }, - [SEARCH_MODE] = + [SEARCH_MODE] = { - 0xFF, - 0xFF, - SEARCH_ORDER, + 0xFF, + 0xFF, + SEARCH_ORDER, SEARCH_OK }, - [SEARCH_OK] = + [SEARCH_OK] = { - 0xFF, - 0xFF, - SEARCH_MODE, + 0xFF, + 0xFF, + SEARCH_MODE, 0xFF }, }; @@ -1219,52 +1221,52 @@ static const u8 sSearchMovementMap_ShiftNatDex[SEARCH_COUNT][4] = // Left, Right, Up, Down static const u8 sSearchMovementMap_SearchHoennDex[SEARCH_COUNT][4] = { - [SEARCH_NAME] = + [SEARCH_NAME] = { 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, SEARCH_COLOR }, - [SEARCH_COLOR] = + [SEARCH_COLOR] = { - 0xFF, - 0xFF, - SEARCH_NAME, + 0xFF, + 0xFF, + SEARCH_NAME, SEARCH_TYPE_LEFT }, - [SEARCH_TYPE_LEFT] = + [SEARCH_TYPE_LEFT] = { - 0xFF, - SEARCH_TYPE_RIGHT, - SEARCH_COLOR, + 0xFF, + SEARCH_TYPE_RIGHT, + SEARCH_COLOR, SEARCH_ORDER }, - [SEARCH_TYPE_RIGHT] = - { SEARCH_TYPE_LEFT, - 0xFF, - SEARCH_COLOR, + [SEARCH_TYPE_RIGHT] = + { SEARCH_TYPE_LEFT, + 0xFF, + SEARCH_COLOR, SEARCH_ORDER }, [SEARCH_ORDER] = { - 0xFF, - 0xFF, - SEARCH_TYPE_LEFT, + 0xFF, + 0xFF, + SEARCH_TYPE_LEFT, SEARCH_OK }, - [SEARCH_MODE] = + [SEARCH_MODE] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_OK] = + [SEARCH_OK] = { - 0xFF, - 0xFF, - SEARCH_ORDER, + 0xFF, + 0xFF, + SEARCH_ORDER, 0xFF }, }; @@ -1272,53 +1274,53 @@ static const u8 sSearchMovementMap_SearchHoennDex[SEARCH_COUNT][4] = // Left, Right, Up, Down static const u8 sSearchMovementMap_ShiftHoennDex[SEARCH_COUNT][4] = { - [SEARCH_NAME] = + [SEARCH_NAME] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, [SEARCH_COLOR] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_TYPE_LEFT] = + [SEARCH_TYPE_LEFT] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_TYPE_RIGHT] = + [SEARCH_TYPE_RIGHT] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_ORDER] = + [SEARCH_ORDER] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, SEARCH_OK }, - [SEARCH_MODE] = + [SEARCH_MODE] = { - 0xFF, - 0xFF, - 0xFF, + 0xFF, + 0xFF, + 0xFF, 0xFF }, - [SEARCH_OK] = + [SEARCH_OK] = { - 0xFF, - 0xFF, - SEARCH_ORDER, + 0xFF, + 0xFF, + SEARCH_ORDER, 0xFF }, }; @@ -2838,7 +2840,7 @@ static void CreateInterfaceSprites(u8 page) spriteId = CreateSprite(&sHoennDexSeenOwnNumberSpriteTemplate, 40, 48, 1); digitNum = (sPokedexView->seenCount % 100) % 10; StartSpriteAnim(&gSprites[spriteId], digitNum); - + // Owned value - 100s drawNextDigit = FALSE; spriteId = CreateSprite(&sHoennDexSeenOwnNumberSpriteTemplate, 24, 80, 1); @@ -3898,7 +3900,7 @@ static void HighlightSubmenuScreenSelectBarItem(u8 a, u16 b) u8 row = i * 7 + 1; u32 newPalette; - do + do { if (i == a || i == 3) newPalette = 0x2000; From 7c4c1d3a5cb193aaff03f93bc7cc98bf3edd04d7 Mon Sep 17 00:00:00 2001 From: SBird Date: Sun, 3 May 2020 15:24:33 +0200 Subject: [PATCH 09/43] gfx: merge battle_interface gfx table --- src/graphics.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/graphics.c b/src/graphics.c index 83fab7dee..daae1d896 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -356,16 +356,16 @@ const u16 gBattleInterface_BallStatusBarPal[] = INCBIN_U16("graphics/battle_inte const u16 gBattleInterface_BallDisplayPal[] = INCBIN_U16("graphics/battle_interface/ball_display.gbapal"); //Originally an array? -const u8 gHealthboxElementsGfxTable[] = INCBIN_U8("graphics/battle_interface/hpbar.4bpp"); -const u8 gHealthboxElementsGfxTable_ExpBar[] = INCBIN_U8("graphics/battle_interface/expbar.4bpp"); -const u8 gHealthboxElementsGfxTable_StatusPsn[] = INCBIN_U8("graphics/battle_interface/status_psn.4bpp"); -const u8 gHealthboxElementsGfxTable_StatusPar[] = INCBIN_U8("graphics/battle_interface/status_par.4bpp"); -const u8 gHealthboxElementsGfxTable_StatusSlp[] = INCBIN_U8("graphics/battle_interface/status_slp.4bpp"); -const u8 gHealthboxElementsGfxTable_StatusFrz[] = INCBIN_U8("graphics/battle_interface/status_frz.4bpp"); -const u8 gHealthboxElementsGfxTable_StatusBrn[] = INCBIN_U8("graphics/battle_interface/status_brn.4bpp"); -const u8 gHealthboxElementsGfxTable_Misc[] = INCBIN_U8("graphics/battle_interface/misc.4bpp"); -const u8 gHealthboxElementsGfxTable_HpBarAnim[] = INCBIN_U8("graphics/battle_interface/hpbar_anim.4bpp"); -const u8 gHealthboxElementsGfxTable_MiscFrameEnd[] = INCBIN_U8("graphics/battle_interface/misc_frameend.4bpp"); +const u8 gHealthboxElementsGfxTable[] = INCBIN_U8("graphics/battle_interface/hpbar.4bpp", + "graphics/battle_interface/expbar.4bpp", + "graphics/battle_interface/status_psn.4bpp", + "graphics/battle_interface/status_par.4bpp", + "graphics/battle_interface/status_slp.4bpp", + "graphics/battle_interface/status_frz.4bpp", + "graphics/battle_interface/status_brn.4bpp", + "graphics/battle_interface/misc.4bpp", + "graphics/battle_interface/hpbar_anim.4bpp", + "graphics/battle_interface/misc_frameend.4bpp"); const u8 gBattleInterface_BallDisplayGfx[] = INCBIN_U8("graphics/battle_interface/ball_display.4bpp"); From c11fb6a3fd417e32306cadebd74352ce4ac6423f Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Tue, 5 May 2020 00:05:37 +0200 Subject: [PATCH 10/43] Fix MODERN=1 for non-devkitARM compilation gcc has this nice option "-print-file-name=" to locate a file in its search path. This is a more portable way to locate libgcc.a and libc.a so there is no longer the need to mess around with devkitARM's path's. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b450c3f7f..bda2bf1ca 100644 --- a/Makefile +++ b/Makefile @@ -59,8 +59,6 @@ MID_BUILDDIR = $(OBJ_DIR)/$(MID_SUBDIR) ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=$(MODERN) -GCC_VER = $(shell $(CC) -dumpversion) - ifeq ($(MODERN),0) CC1 := tools/agbcc/bin/agbcc$(EXE) override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm @@ -72,7 +70,7 @@ CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast ROM := pokeemerald_modern.gba OBJ_DIR := build/modern -LIBPATH := -L $(TOOLCHAIN)/lib/gcc/arm-none-eabi/$(GCC_VER)/thumb -L $(TOOLCHAIN)/arm-none-eabi/lib/thumb +LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" endif CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=$(MODERN) From 1506a1de5184b02a665ac3eae51bc9c550585bf5 Mon Sep 17 00:00:00 2001 From: hondew Date: Sat, 9 May 2020 13:16:43 -0400 Subject: [PATCH 11/43] Initial bug doc entry Minor typo --- docs/bugs_and_glitches.md | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docs/bugs_and_glitches.md diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md new file mode 100644 index 000000000..d9269882e --- /dev/null +++ b/docs/bugs_and_glitches.md @@ -0,0 +1,42 @@ + +# Bugs and Glitches + +These are known bugs and glitches in the original Pokémon Emerald game: code that clearly does not work as intended, or that only works in limited circumstances but has the possibility to fail or crash. + +Fixes are written in the `diff` format. If you've used Git before, this should look familiar: + +```diff + this is some code +-delete red - lines ++add green + lines +``` + +## Contents + +- [RNG does not get seeded](#rng-does-not-get-seeded) + + +## RNG does not get seeded + +**Fix:** Add the following function to [src/main.c](https://github.com/pret/pokeemerald/blob/master/src/main.c): +```diff ++static void SeedRngWithRtc(void) ++{ ++ u32 seed = RtcGetMinuteCount(); ++ seed = (seed >> 16) ^ (seed & 0xFFFF); ++ SeedRng(seed); ++} +``` + +And edit `AgbMain`: + +```diff + ... + RtcInit(); + CheckForFlashMemory(); + InitMainCallbacks(); + InitMapMusic(); ++ SeedRngWithRtc(); + ClearDma3Requests(); + ... +``` \ No newline at end of file From ed0212006202fc21301dc9bd1d4a8e38f8f665cf Mon Sep 17 00:00:00 2001 From: Sierra A <6080951+Sierraffinity@users.noreply.github.com> Date: Tue, 12 May 2020 17:21:16 -0700 Subject: [PATCH 12/43] Update bugs_and_glitches.md Add fix for item image flicker --- docs/bugs_and_glitches.md | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/bugs_and_glitches.md b/docs/bugs_and_glitches.md index d9269882e..e23379cfb 100644 --- a/docs/bugs_and_glitches.md +++ b/docs/bugs_and_glitches.md @@ -14,6 +14,7 @@ Fixes are written in the `diff` format. If you've used Git before, this should l ## Contents - [RNG does not get seeded](#rng-does-not-get-seeded) +- [Scrolling through items in the bag causes the image to flicker](#scrolling-through-items-in-the-bag-causes-the-image-to-flicker) ## RNG does not get seeded @@ -39,4 +40,38 @@ And edit `AgbMain`: + SeedRngWithRtc(); ClearDma3Requests(); ... -``` \ No newline at end of file +``` + +## Scrolling through items in the bag causes the image to flicker + +**Fix:** Add the following function to [src/item_menu_icons.c](https://github.com/pret/pokeemerald/blob/master/src/item_menu_icons.c): +```diff ++void HideBagItemIconSprite(u8 id) ++{ ++ u8 *spriteId = &gBagMenu->spriteId[10]; ++ if (spriteId[id] != 0xFF) ++ { ++ gSprites[spriteId[id]].invisible = TRUE; ++ } ++} + +``` + +and its corresponding declaration in [include/item_menu_icons.h](https://github.com/pret/pokeemerald/blob/master/include/item_menu_icons.h): + +```diff ++void HideBagItemIconSprite(u8 id); + +``` + +Then edit `BagMenu_MoveCursorCallback` in [src/item_menu.c](https://github.com/pret/pokeemerald/blob/master/src/item_menu.c): + +```diff + ... +{ +- RemoveBagItemIconSprite(1 ^ gBagMenu->unk81B_1); ++ HideBagItemIconSprite(gBagMenu->unk81B_1 ^ 1); ++ RemoveBagItemIconSprite(gBagMenu->unk81B_1); + if (a != -2) + ... +``` From 468793e34a7f533db62520f179fa37c2286f524a Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Thu, 14 May 2020 16:33:19 -0400 Subject: [PATCH 13/43] restore SeedRngWithRtc comment and declaration of GF oversight. --- src/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index f488e7f6d..cf19f39b3 100644 --- a/src/main.c +++ b/src/main.c @@ -75,7 +75,7 @@ static EWRAM_DATA u16 gTrainerId = 0; static void UpdateLinkAndCallCallbacks(void); static void InitMainCallbacks(void); static void CallCallbacks(void); -static void SeedRngWithRtc(void); +//static void SeedRngWithRtc(void); static void ReadKeys(void); void InitIntrHandlers(void); static void WaitForVBlank(void); @@ -118,6 +118,7 @@ void AgbMain() CheckForFlashMemory(); InitMainCallbacks(); InitMapMusic(); + //SeedRngWithRtc(); see comment at SeedRngWithRtc declaration below ClearDma3Requests(); ResetBgs(); SetDefaultFontsPointer(); @@ -228,6 +229,14 @@ void EnableVCountIntrAtLine150(void) EnableInterrupts(INTR_FLAG_VCOUNT); } +// oops! FRLG commented this out to remove RTC, however Emerald didnt undo this! +//static void SeedRngWithRtc(void) +//{ +// u32 seed = RtcGetMinuteCount(); +// seed = (seed >> 16) ^ (seed & 0xFFFF); +// SeedRng(seed); +//} + void InitKeys(void) { gKeyRepeatContinueDelay = 5; From 5bb688df3e798c845cfee6c117cea5d3bc6cd178 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 14 May 2020 17:11:18 -0400 Subject: [PATCH 14/43] Label in_connection's field in ObjectEventTemplate --- include/global.fieldmap.h | 2 +- src/event_object_movement.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 837d5da00..59610f9ad 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -54,7 +54,7 @@ struct ObjectEventTemplate { /*0x00*/ u8 localId; /*0x01*/ u8 graphicsId; - /*0x02*/ u8 unk2; + /*0x02*/ u8 inConnection; // Leftover from FRLG /*0x04*/ s16 x; /*0x06*/ s16 y; /*0x08*/ u8 elevation; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index e166f8b95..d6a2fe2ec 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1448,7 +1448,7 @@ u8 SpawnSpecialObjectEventParameterized(u8 graphicsId, u8 movementBehavior, u8 l y -= 7; objectEventTemplate.localId = localId; objectEventTemplate.graphicsId = graphicsId; - objectEventTemplate.unk2 = 0; + objectEventTemplate.inConnection = 0; objectEventTemplate.x = x; objectEventTemplate.y = y; objectEventTemplate.elevation = z; From 4054f16e711beed59f2b4ba7c5ab0f8876ccca16 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 15 May 2020 09:53:06 -0400 Subject: [PATCH 15/43] Fix building modern from clean --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bda2bf1ca..27d77754c 100644 --- a/Makefile +++ b/Makefile @@ -109,13 +109,13 @@ MAKEFLAGS += --no-print-directory # Secondary expansion is required for dependency variables in object rules. .SECONDEXPANSION: -.PHONY: all rom clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall +.PHONY: all rom clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall modern infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line)))) # Build tools when building the rom # Disable dependency scanning for clean/tidy/tools -ifeq (,$(filter-out all compare,$(MAKECMDGOALS))) +ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS))) $(call infoshell, $(MAKE) tools) else NODEP := 1 From 179d84dcd730d3773c93b8501f49a149115e12c6 Mon Sep 17 00:00:00 2001 From: AsparagusEduardo Date: Sat, 16 May 2020 18:08:56 -0400 Subject: [PATCH 16/43] Using ability constants for OLD_UNOWN stats --- src/data/pokemon/base_stats.h | 60 +++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/data/pokemon/base_stats.h b/src/data/pokemon/base_stats.h index 4dedcfdc0..d851dfbe1 100644 --- a/src/data/pokemon/base_stats.h +++ b/src/data/pokemon/base_stats.h @@ -2,36 +2,36 @@ // 255 (MON_GENDERLESS) is reserved for genderless Pokémon. #define PERCENT_FEMALE(percent) min(254, ((percent * 255) / 100)) -#define OLD_UNOWN_BASE_STATS \ - { \ - .baseHP = 50, \ - .baseAttack = 150, \ - .baseDefense = 50, \ - .baseSpeed = 150, \ - .baseSpAttack = 150, \ - .baseSpDefense = 50, \ - .type1 = TYPE_NORMAL, \ - .type2 = TYPE_NORMAL, \ - .catchRate = 3, \ - .expYield = 1, \ - .evYield_HP = 2, \ - .evYield_Attack = 2, \ - .evYield_Defense = 2, \ - .evYield_Speed = 2, \ - .evYield_SpAttack = 2, \ - .evYield_SpDefense = 2, \ - .item1 = ITEM_NONE, \ - .item2 = ITEM_NONE, \ - .genderRatio = MON_GENDERLESS, \ - .eggCycles = 120, \ - .friendship = 0, \ - .growthRate = GROWTH_MEDIUM_FAST, \ - .eggGroup1 = EGG_GROUP_UNDISCOVERED,\ - .eggGroup2 = EGG_GROUP_UNDISCOVERED,\ - .abilities = {0, 0}, \ - .safariZoneFleeRate = 0, \ - .bodyColor = BODY_COLOR_BLACK, \ - .noFlip = FALSE, \ +#define OLD_UNOWN_BASE_STATS \ + { \ + .baseHP = 50, \ + .baseAttack = 150, \ + .baseDefense = 50, \ + .baseSpeed = 150, \ + .baseSpAttack = 150, \ + .baseSpDefense = 50, \ + .type1 = TYPE_NORMAL, \ + .type2 = TYPE_NORMAL, \ + .catchRate = 3, \ + .expYield = 1, \ + .evYield_HP = 2, \ + .evYield_Attack = 2, \ + .evYield_Defense = 2, \ + .evYield_Speed = 2, \ + .evYield_SpAttack = 2, \ + .evYield_SpDefense = 2, \ + .item1 = ITEM_NONE, \ + .item2 = ITEM_NONE, \ + .genderRatio = MON_GENDERLESS, \ + .eggCycles = 120, \ + .friendship = 0, \ + .growthRate = GROWTH_MEDIUM_FAST, \ + .eggGroup1 = EGG_GROUP_UNDISCOVERED, \ + .eggGroup2 = EGG_GROUP_UNDISCOVERED, \ + .abilities = {ABILITY_NONE, ABILITY_NONE}, \ + .safariZoneFleeRate = 0, \ + .bodyColor = BODY_COLOR_BLACK, \ + .noFlip = FALSE, \ } const struct BaseStats gBaseStats[] = From db17f8091caefc81134c3e7681f5971248154230 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 17 May 2020 01:06:17 -0400 Subject: [PATCH 17/43] Fix CreatedHatchedMon typo --- src/egg_hatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 032ae6733..3bc35bc4a 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -293,7 +293,7 @@ static const s16 sEggShardVelocities[][2] = // code -static void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) +static void CreateHatchedMon(struct Pokemon *egg, struct Pokemon *temp) { u16 species; u32 personality, pokerus; @@ -357,7 +357,7 @@ static void AddHatchedMonToParty(u8 id) u8 mapNameID; struct Pokemon* mon = &gPlayerParty[id]; - CreatedHatchedMon(mon, &gEnemyParty[0]); + CreateHatchedMon(mon, &gEnemyParty[0]); SetMonData(mon, MON_DATA_IS_EGG, &isEgg); pokeNum = GetMonData(mon, MON_DATA_SPECIES); From 72c8574780466bdf20fe5e41749210b785634a46 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 18 May 2020 01:41:54 -0400 Subject: [PATCH 18/43] Fix compilation on gcc 10 --- tools/preproc/asm_file.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp index 98805c952..7756cadc5 100644 --- a/tools/preproc/asm_file.cpp +++ b/tools/preproc/asm_file.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "preproc.h" #include "asm_file.h" #include "char_util.h" From bdebab834cdad6b18c7726057ff682dae9ab2a16 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 18 May 2020 14:03:01 +0200 Subject: [PATCH 19/43] Document pokemon summary screen --- ...{unk_tilemap.bin => appealjam_tilemap.bin} | Bin .../{unk_tilemap2.bin => status_tilemap.bin} | Bin include/graphics.h | 6 +- include/pokemon_summary_screen.h | 3 +- src/graphics.c | 9 +- src/party_menu.c | 10 +- src/pokemon_summary_screen.c | 1612 ++++++++--------- src/trade.c | 32 +- 8 files changed, 805 insertions(+), 867 deletions(-) rename graphics/interface/{unk_tilemap.bin => appealjam_tilemap.bin} (100%) rename graphics/interface/{unk_tilemap2.bin => status_tilemap.bin} (100%) diff --git a/graphics/interface/unk_tilemap.bin b/graphics/interface/appealjam_tilemap.bin similarity index 100% rename from graphics/interface/unk_tilemap.bin rename to graphics/interface/appealjam_tilemap.bin diff --git a/graphics/interface/unk_tilemap2.bin b/graphics/interface/status_tilemap.bin similarity index 100% rename from graphics/interface/unk_tilemap2.bin rename to graphics/interface/status_tilemap.bin diff --git a/include/graphics.h b/include/graphics.h index dad8dc1f1..b41a43095 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4048,11 +4048,11 @@ extern const u32 gMoveTypes_Pal[]; extern const u32 gStatusScreenBitmap[]; extern const u16 gSummaryScreenPowAcc_Tilemap[]; -extern const u16 gUnknown_08DC3C34[]; +extern const u16 gSummaryScreenAppealJam_Tilemap[]; extern const u32 gMoveTypes_Gfx[]; -extern const u32 gMoveSelectorBitmap[]; -extern const u32 gUnknown_08D97CF4[]; +extern const u32 gSummaryMoveSelect_Gfx[]; +extern const u32 gSummaryMoveSelect_Pal[]; extern const u32 gStatusGfx_Icons[]; extern const u32 gStatusPal_Icons[]; diff --git a/include/pokemon_summary_screen.h b/include/pokemon_summary_screen.h index 07d541cac..1c7510db6 100755 --- a/include/pokemon_summary_screen.h +++ b/include/pokemon_summary_screen.h @@ -20,7 +20,7 @@ void SummaryScreen_DestroyUnknownTask(void); enum PokemonSummaryScreenMode { PSS_MODE_NORMAL, - PSS_MODE_UNK1, + PSS_MODE_LOCK_MOVES, PSS_MODE_BOX, PSS_MODE_SELECT_MOVE, }; @@ -31,6 +31,7 @@ enum PokemonSummaryScreenPage PSS_PAGE_SKILLS, PSS_PAGE_BATTLE_MOVES, PSS_PAGE_CONTEST_MOVES, + PSS_PAGE_COUNT, }; #endif // GUARD_POKEMON_SUMMARY_SCREEN_H diff --git a/src/graphics.c b/src/graphics.c index daae1d896..d8222cfae 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1144,13 +1144,12 @@ const u32 gStatusPal_Icons[] = INCBIN_U32("graphics/interface/status_icons.gbapa const u32 gMoveTypes_Gfx[] = INCBIN_U32("graphics/types/move_types.4bpp.lz"); const u32 gMoveTypes_Pal[] = INCBIN_U32("graphics/types/move_types.gbapal.lz"); -const u32 gMoveSelectorBitmap[] = INCBIN_U32("graphics/interface/summary_frames.4bpp.lz"); -const u32 gUnknown_08D97CF4[] = INCBIN_U32("graphics/interface/summary_frames.gbapal.lz"); +const u32 gSummaryMoveSelect_Gfx[] = INCBIN_U32("graphics/interface/summary_frames.4bpp.lz"); +const u32 gSummaryMoveSelect_Pal[] = INCBIN_U32("graphics/interface/summary_frames.gbapal.lz"); const u32 gStatusScreenBitmap[] = INCBIN_U32("graphics/interface/status_screen.4bpp.lz"); const u32 gStatusScreenPalette[] = INCBIN_U32("graphics/interface/status_screen.gbapal.lz"); const u32 gPageInfoTilemap[] = INCBIN_U32("graphics/interface/status_screen.bin.lz"); - const u32 gPageSkillsTilemap[] = INCBIN_U32("graphics/interface/status_tilemap1.bin.lz"); const u32 gPageBattleMovesTilemap[] = INCBIN_U32("graphics/interface/status_tilemap2.bin.lz"); const u32 gPageContestMovesTilemap[] = INCBIN_U32("graphics/interface/status_tilemap3.bin.lz"); @@ -1280,9 +1279,7 @@ const u32 gPokedexSearchMenuNational_Tilemap[] = INCBIN_U32("graphics/pokedex/se const u32 gPokedexSearchMenuHoenn_Tilemap[] = INCBIN_U32("graphics/pokedex/search_menu_hoenn.bin.lz"); const u16 gSummaryScreenPowAcc_Tilemap[] = INCBIN_U16("graphics/interface/powacc_tilemap.bin"); - -const u16 gUnknown_08DC3C34[] = INCBIN_U16("graphics/interface/unk_tilemap.bin"); // probably trade summary screen related? - +const u16 gSummaryScreenAppealJam_Tilemap[] = INCBIN_U16("graphics/interface/appealjam_tilemap.bin"); const u16 gSummaryScreenWindow_Tilemap[] = INCBIN_U16("graphics/interface/summary.bin"); const u16 gIntroCopyright_Pal[] = INCBIN_U16("graphics/intro/copyright.gbapal"); diff --git a/src/party_menu.c b/src/party_menu.c index 43bdc46ec..4ed7ab1b2 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -2129,7 +2129,7 @@ static void DrawEmptySlot(u8 windowId) LoadPalette(GetPartyMenuPalBufferPtr(paletteIds[0]), paletteOffsets[0] + palNum, 2); \ LoadPalette(GetPartyMenuPalBufferPtr(paletteIds[1]), paletteOffsets[1] + palNum, 2); \ LoadPalette(GetPartyMenuPalBufferPtr(paletteIds[2]), paletteOffsets[2] + palNum, 2); \ -} +} static void LoadPartyBoxPalette(struct PartyMenuBox *menuBox, u8 palFlags) { @@ -2708,7 +2708,7 @@ static void CB2_ShowPokemonSummaryScreen(void) if (gPartyMenu.menuType == PARTY_MENU_TYPE_IN_BATTLE) { UpdatePartyToBattleOrder(); - ShowPokemonSummaryScreen(PSS_MODE_UNK1, gPlayerParty, gPartyMenu.slotId, gPlayerPartyCount - 1, CB2_ReturnToPartyMenuFromSummaryScreen); + ShowPokemonSummaryScreen(PSS_MODE_LOCK_MOVES, gPlayerParty, gPartyMenu.slotId, gPlayerPartyCount - 1, CB2_ReturnToPartyMenuFromSummaryScreen); } else { @@ -2899,7 +2899,7 @@ static void Task_SlideSelectedSlotsOnscreen(u8 taskId) SlidePartyMenuBoxOneStep(taskId); SlidePartyMenuBoxSpritesOneStep(taskId); - + // Both slots have slid back onscreen if (tSlot1SlideDir == 0 && tSlot2SlideDir == 0) { @@ -3096,7 +3096,7 @@ static void Task_HandleSwitchItemsYesNoInput(u8 taskId) { case 0: // Yes, switch items RemoveBagItem(gSpecialVar_ItemId, 1); - + // No room to return held item to bag if (AddBagItem(sPartyMenuItemId, 1) == FALSE) { @@ -5456,7 +5456,7 @@ static void RemoveItemToGiveFromBag(u16 item) // but there always should be, and the return is ignored in all uses static bool8 ReturnGiveItemToBagOrPC(u16 item) { - if (gPartyMenu.action == PARTY_ACTION_GIVE_ITEM) + if (gPartyMenu.action == PARTY_ACTION_GIVE_ITEM) return AddBagItem(item, 1); else return AddPCItem(item, 1); diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 81befefc5..1cdaf3422 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -99,6 +99,19 @@ #define PSS_DATA_WINDOW_MOVE_PP 1 #define PSS_DATA_WINDOW_MOVE_DESCRIPTION 2 +#define MOVE_SELECTOR_SPRITES_COUNT 10 +// for the spriteIds field in PokemonSummaryScreenData +enum +{ + SPRITE_ARR_ID_MON, + SPRITE_ARR_ID_BALL, + SPRITE_ARR_ID_STATUS, + SPRITE_ARR_ID_TYPE, // 2 for mon types, 5 for move types(4 moves and 1 to learn), used interchangeably, because mon types and move types aren't shown on the same screen + SPRITE_ARR_ID_MOVE_SELECTOR1 = SPRITE_ARR_ID_TYPE + 5, // 10 sprites that make up the selector + SPRITE_ARR_ID_MOVE_SELECTOR2 = SPRITE_ARR_ID_MOVE_SELECTOR1 + MOVE_SELECTOR_SPRITES_COUNT, + SPRITE_ARR_ID_COUNT = SPRITE_ARR_ID_MOVE_SELECTOR2 + MOVE_SELECTOR_SPRITES_COUNT +}; + static EWRAM_DATA struct PokemonSummaryScreenData { /*0x00*/ union { @@ -137,11 +150,10 @@ static EWRAM_DATA struct PokemonSummaryScreenData u8 nature; // 0x33 u8 ppBonuses; // 0x34 u8 sanity; // 0x35 - u8 OTName[8]; // 0x36 - u8 unk3E[9]; // 0x3E + u8 OTName[17]; // 0x36 u32 OTID; // 0x48 } summary; - u16 bgTilemapBuffers[4][2][0x400]; + u16 bgTilemapBuffers[PSS_PAGE_COUNT][2][0x400]; u8 mode; bool8 isBoxMon; u8 curMonIndex; @@ -153,11 +165,11 @@ static EWRAM_DATA struct PokemonSummaryScreenData u16 newMove; u8 firstMoveIndex; u8 secondMoveIndex; - bool8 unk40C8; + bool8 lockMovesFlag; // This is used to prevent the player from changing position of moves in a battle or when trading. u8 bgDisplayOrder; // Determines the order page backgrounds are loaded while scrolling between them u8 filler40CA; u8 windowIds[8]; - u8 spriteIds[28]; + u8 spriteIds[SPRITE_ARR_ID_COUNT]; bool8 unk40EF; s16 switchCounter; // Used for various switch statement cases that decompress/load graphics or pokemon data u8 unk_filler4[6]; @@ -166,60 +178,50 @@ EWRAM_DATA u8 gLastViewedMonIndex = 0; static EWRAM_DATA u8 sMoveSlotToReplace = 0; ALIGNED(4) static EWRAM_DATA u8 sUnknownTaskId = 0; -struct UnkStruct_61CC04 -{ - const u16 *ptr; - u16 field_4; - u8 field_6; - u8 field_7; - u8 field_8; - u8 field_9; -}; - // forward declarations -static bool8 SummaryScreen_LoadGraphics(void); -static void SummaryScreen_LoadingCB2(void); +static bool8 LoadGraphics(void); +static void CB2_InitSummaryScreen(void); static void InitBGs(void); -static bool8 SummaryScreen_DecompressGraphics(void); +static bool8 DecompressGraphics(void); static void CopyMonToSummaryStruct(struct Pokemon* a); static bool8 ExtractMonDataToSummaryStruct(struct Pokemon* a); -static void sub_81C0348(void); +static void SetDefaultTilemaps(void); static void CloseSummaryScreen(u8 taskId); -static void HandleInput(u8 taskId); +static void Task_HandleInput(u8 taskId); static void ChangeSummaryPokemon(u8 taskId, s8 a); -static void sub_81C0704(u8 taskId); -static s8 sub_81C08F8(s8 a); -static s8 sub_81C09B4(s8 a); -static bool8 sub_81C0A50(struct Pokemon* mon); +static void Task_ChangeSummaryMon(u8 taskId); +static s8 AdvanceMonIndex(s8 delta); +static s8 AdvanceMultiBattleMonIndex(s8 delta); +static bool8 IsValidToViewInMulti(struct Pokemon* mon); static void ChangePage(u8 taskId, s8 a); static void PssScrollRight(u8 taskId); static void PssScrollRightEnd(u8 taskId); static void PssScrollLeft(u8 taskId); static void PssScrollLeftEnd(u8 taskId); -static void CheckExperienceProgressBar(void); -static void sub_81C0E48(u8 taskId); -static void HandleInput_MoveSelect(u8 taskId); -static bool8 sub_81C1040(void); -static void sub_81C1070(s16* a, s8 b, u8* c); -static void sub_81C11F4(u8 a); -static void sub_81C129C(u8 a); -static void sub_81C12E4(u8 taskId); -static void sub_81C13B0(u8 taskId, bool8 b); +static void TryDrawExperienceProgressBar(void); +static void SwitchToMoveSelection(u8 taskId); +static void Task_HandleInput_MoveSelect(u8 taskId); +static bool8 HasMoreThanOneMove(void); +static void ChangeSelectedMove(s16 *taskData, s8 direction, u8 *moveIndexPtr); +static void CloseMoveSelectMode(u8 taskId); +static void SwitchToMovePositionSwitchMode(u8 a); +static void Task_HandleInput_MovePositionSwitch(u8 taskId); +static void ExitMovePositionSwitchMode(u8 taskId, bool8 swapMoves); static void SwapMonMoves(struct Pokemon *mon, u8 moveIndex1, u8 moveIndex2); static void SwapBoxMonMoves(struct BoxPokemon *mon, u8 moveIndex1, u8 moveIndex2); -static void sub_81C171C(u8 taskId); -static void HandleReplaceMoveInput(u8 taskId); +static void Task_SetHandleReplaceMoveInput(u8 taskId); +static void Task_HandleReplaceMoveInput(u8 taskId); static bool8 CanReplaceMove(void); -static void ShowHMMovesCantBeForgottenWindow(u8 a); -static void HandleHMMovesCantBeForgottenInput(u8 taskId); +static void ShowCantForgetHMsWindow(u8 taskId); +static void Task_HandleInputCantForgetHMsMoves(u8 taskId); static void DrawPagination(void); -static void sub_81C1DA4(u16 a, s16 b); -static void sub_81C1E20(u8 taskId); -static void sub_81C1EFC(u16 a, s16 b, u16 c); -static void sub_81C1F80(u8 taskId); -static void sub_81C2074(u16 a, s16 b); -static void sub_81C20F0(u8 taskId); -static void sub_81C2194(u16 *a, u16 b, u8 c); +static void HandlePowerAccTilemap(u16 a, s16 b); +static void Task_ShowPowerAccWindow(u8 taskId); +static void HandleAppealJamTilemap(u16 a, s16 b, u16 c); +static void Task_ShowAppealJamWindow(u8 taskId); +static void HandleStatusTilemap(u16 a, s16 b); +static void Task_ShowStatusWindow(u8 taskId); +static void TilemapFiveMovesDisplay(u16 *dst, u16 palette, bool8 remove); static void DrawPokerusCuredSymbol(struct Pokemon* mon); static void DrawExperienceProgressBar(struct Pokemon* mon); static void DrawContestMoveHearts(u16 move); @@ -229,10 +231,10 @@ static void PrintMonInfo(void); static void PrintNotEggInfo(void); static void PrintEggInfo(void); static void PrintGenderSymbol(struct Pokemon *mon, u16 a); -static void PrintPageNamesAndStatsPageToWindows(void); -static void CreatePageWindowTilemaps(u8 a); +static void PrintPageNamesAndStats(void); +static void PutPageWindowTilemaps(u8 a); static void ClearPageWindowTilemaps(u8 a); -static void SummaryScreen_RemoveWindowByIndex(u8 a); +static void RemoveWindowByIndex(u8 a); static void PrintPageSpecificText(u8 a); static void CreateTextPrinterTask(u8 a); static void PrintInfoPageText(void); @@ -269,8 +271,8 @@ static void Task_PrintContestMoves(u8 taskId); static void PrintContestMoveDescription(u8 a); static void PrintMoveDetails(u16 a); static void PrintNewMoveDetailsOrCancelText(void); -static void sub_81C4064(void); -static void sub_81C40A0(u8 a, u8 b); +static void AddAndFillMoveNamesWindow(void); +static void SwapMovesNamesPP(u8 moveIndex1, u8 moveIndex2); static void PrintHMMovesCantBeForgotten(void); static void ResetSpriteIds(void); static void SetSpriteInvisibility(u8 spriteArrayId, bool8 invisible); @@ -281,26 +283,26 @@ static void SetMonTypeIcons(void); static void SetMoveTypeIcons(void); static void SetContestMoveTypeIcons(void); static void SetNewMoveTypeIcon(void); -static void sub_81C4568(u8 a, u8 b); -static u8 CreatePokemonSprite(struct Pokemon *a, s16 *b); -static u8 sub_81C47B4(struct Pokemon *unused); +static void SwapMovesTypeSprites(u8 moveIndex1, u8 moveIndex2); +static u8 LoadMonGfxAndSprite(struct Pokemon *a, s16 *b); +static u8 CreateMonSprite(struct Pokemon *unused); static void SpriteCB_Pokemon(struct Sprite *); static void StopPokemonAnimations(void); static void CreateMonMarkingsSprite(struct Pokemon *mon); static void RemoveAndCreateMonMarkingsSprite(struct Pokemon *mon); static void CreateCaughtBallSprite(struct Pokemon *mon); static void CreateSetStatusSprite(void); -static void sub_81C4AF8(u8 a); -static void sub_81C4BE4(struct Sprite *sprite); -static void sub_81C4C60(u8 a); -static void sub_81C4C84(u8 a); -static void sub_81C4D18(u8 a); +static void CreateMoveSelectorSprites(u8 idArrayStart); +static void SpriteCb_MoveSelector(struct Sprite *sprite); +static void DestroyMoveSelectorSprites(u8 firstArrayId); +static void SetMainMoveSelectorColor(u8 whichColor); +static void MakeMoveSelectorVisible(u8 a); // const rom data #include "data/text/move_descriptions.h" #include "data/text/nature_names.h" -ALIGNED(4) static const struct BgTemplate sUnknown_0861CBB4[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 0, @@ -340,24 +342,34 @@ ALIGNED(4) static const struct BgTemplate sUnknown_0861CBB4[] = }, }; -static const u16 sUnknown_0861CBC4[] = INCBIN_U16("graphics/interface/unk_tilemap2.bin"); -static const struct UnkStruct_61CC04 sUnknown_0861CBEC = +struct TilemapCtrl { - sUnknown_0861CBC4, 1, 10, 2, 0, 18 + const u16 *gfx; + u16 field_4; + u8 field_6; + u8 field_7; + u8 field_8; + u8 field_9; }; -static const struct UnkStruct_61CC04 sUnknown_0861CBF8 = + +static const u16 sStatusTilemap[] = INCBIN_U16("graphics/interface/status_tilemap.bin"); +static const struct TilemapCtrl sStatusTilemapCtrl1 = { - sUnknown_0861CBC4, 1, 10, 2, 0, 50 + sStatusTilemap, 1, 10, 2, 0, 18 }; -static const struct UnkStruct_61CC04 sUnknown_0861CC04 = +static const struct TilemapCtrl sStatusTilemapCtrl2 = +{ + sStatusTilemap, 1, 10, 2, 0, 50 +}; +static const struct TilemapCtrl sBattleMoveTilemapCtrl = { gSummaryScreenPowAcc_Tilemap, 0, 10, 7, 0, 45 }; -static const struct UnkStruct_61CC04 sUnknown_0861CC10 = +static const struct TilemapCtrl sContestMoveTilemapCtrl = { - gUnknown_08DC3C34, 0, 10, 7, 0, 45 + gSummaryScreenAppealJam_Tilemap, 0, 10, 7, 0, 45 }; -static const s8 gUnknown_0861CC1C[] = {0, 2, 3, 1, 4, 5}; +static const s8 sMultiBattleOrder[] = {0, 2, 3, 1, 4, 5}; static const struct WindowTemplate sSummaryTemplate[] = { [PSS_LABEL_WINDOW_POKEMON_INFO_TITLE] = { @@ -659,7 +671,7 @@ static const struct WindowTemplate sPageMovesTemplate[] = // This is used for bo .baseBlock = 599, }, }; -static const u8 sTextColors_861CD2C[][3] = +static const u8 sTextColors[][3] = { {0, 1, 2}, {0, 3, 4}, @@ -681,18 +693,18 @@ static const u8 sSummaryBButtonBitmap[] = INCBIN_U8("graphics/interface/summary_ static void (*const sTextPrinterFunctions[])(void) = { - PrintInfoPageText, - PrintSkillsPageText, - PrintBattleMoves, - PrintContestMoves + [PSS_PAGE_INFO] = PrintInfoPageText, + [PSS_PAGE_SKILLS] = PrintSkillsPageText, + [PSS_PAGE_BATTLE_MOVES] = PrintBattleMoves, + [PSS_PAGE_CONTEST_MOVES] = PrintContestMoves }; static void (*const sTextPrinterTasks[])(u8 taskId) = { - Task_PrintInfoPage, - Task_PrintSkillsPage, - Task_PrintBattleMoves, - Task_PrintContestMoves + [PSS_PAGE_INFO] = Task_PrintInfoPage, + [PSS_PAGE_SKILLS] = Task_PrintSkillsPage, + [PSS_PAGE_BATTLE_MOVES] = Task_PrintBattleMoves, + [PSS_PAGE_CONTEST_MOVES] = Task_PrintContestMoves }; static const u8 sMemoNatureTextColor[] = _("{COLOR LIGHT_RED}{SHADOW GREEN}"); @@ -701,7 +713,10 @@ static const u8 sStatsLeftColumnLayout[] = _("{SPECIAL_F7 0x00}/{SPECIAL_F7 0x01 static const u8 sStatsRightColumnLayout[] = _("{SPECIAL_F7 0x00}\n{SPECIAL_F7 0x01}\n{SPECIAL_F7 0x02}"); static const u8 sMovesPPLayout[] = _("{PP}{SPECIAL_F7 0x00}/{SPECIAL_F7 0x01}"); +#define TAG_MOVE_SELECTOR 30000 +#define TAG_MON_STATUS 30001 #define TAG_MOVE_TYPES 30002 +#define TAG_MON_MARKINGS 30003 static const struct OamData sOamData_MoveTypes = { @@ -879,7 +894,7 @@ static const u8 sMoveTypeToOamPaletteNum[NUMBER_OF_MON_TYPES + CONTEST_CATEGORIE [NUMBER_OF_MON_TYPES + CONTEST_CATEGORY_SMART] = 15, [NUMBER_OF_MON_TYPES + CONTEST_CATEGORY_TOUGH] = 13, }; -static const struct OamData gOamData_861CFF4 = +static const struct OamData sOamData_MoveSelector = { .y = 0, .affineMode = ST_OAM_AFFINE_OFF, @@ -895,75 +910,76 @@ static const struct OamData gOamData_861CFF4 = .paletteNum = 0, .affineParam = 0, }; -static const union AnimCmd sSpriteAnim_861CFFC[] = { +static const union AnimCmd sSpriteAnim_MoveSelector0[] = { ANIMCMD_FRAME(0, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D004[] = { +static const union AnimCmd sSpriteAnim_MoveSelector1[] = { ANIMCMD_FRAME(4, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D00C[] = { +static const union AnimCmd sSpriteAnim_MoveSelector2[] = { ANIMCMD_FRAME(8, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D014[] = { +static const union AnimCmd sSpriteAnim_MoveSelector3[] = { ANIMCMD_FRAME(12, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D01C[] = { +static const union AnimCmd sSpriteAnim_MoveSelectorLeft[] = { ANIMCMD_FRAME(16, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D024[] = { +static const union AnimCmd sSpriteAnim_MoveSelectorRight[] = { ANIMCMD_FRAME(16, 0, TRUE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D02C[] = { +static const union AnimCmd sSpriteAnim_MoveSelectorMiddle[] = { ANIMCMD_FRAME(20, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D034[] = { +static const union AnimCmd sSpriteAnim_MoveSelector7[] = { ANIMCMD_FRAME(24, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D03C[] = { +static const union AnimCmd sSpriteAnim_MoveSelector8[] = { ANIMCMD_FRAME(24, 0, TRUE, FALSE), ANIMCMD_END }; -static const union AnimCmd sSpriteAnim_861D044[] = { +static const union AnimCmd sSpriteAnim_MoveSelector9[] = { ANIMCMD_FRAME(28, 0, FALSE, FALSE), ANIMCMD_END }; -static const union AnimCmd *const sSpriteAnimTable_861D04C[] = { - sSpriteAnim_861CFFC, - sSpriteAnim_861D004, - sSpriteAnim_861D00C, - sSpriteAnim_861D014, - sSpriteAnim_861D01C, - sSpriteAnim_861D024, - sSpriteAnim_861D02C, - sSpriteAnim_861D034, - sSpriteAnim_861D03C, - sSpriteAnim_861D044, +// All except left, middle and right are unused +static const union AnimCmd *const sSpriteAnimTable_MoveSelector[] = { + sSpriteAnim_MoveSelector0, + sSpriteAnim_MoveSelector1, + sSpriteAnim_MoveSelector2, + sSpriteAnim_MoveSelector3, + sSpriteAnim_MoveSelectorLeft, + sSpriteAnim_MoveSelectorRight, + sSpriteAnim_MoveSelectorMiddle, + sSpriteAnim_MoveSelector7, + sSpriteAnim_MoveSelector8, + sSpriteAnim_MoveSelector9, }; static const struct CompressedSpriteSheet sMoveSelectorSpriteSheet = { - .data = gMoveSelectorBitmap, + .data = gSummaryMoveSelect_Gfx, .size = 0x400, - .tag = 30000 + .tag = TAG_MOVE_SELECTOR }; -static const struct CompressedSpritePalette gUnknown_0861D07C = +static const struct CompressedSpritePalette sMoveSelectorSpritePal = { - .data = gUnknown_08D97CF4, - .tag = 30000 + .data = gSummaryMoveSelect_Pal, + .tag = TAG_MOVE_SELECTOR }; -static const struct SpriteTemplate gUnknown_0861D084 = +static const struct SpriteTemplate sMoveSelectorSpriteTemplate = { - .tileTag = 30000, - .paletteTag = 30000, - .oam = &gOamData_861CFF4, - .anims = sSpriteAnimTable_861D04C, + .tileTag = TAG_MOVE_SELECTOR, + .paletteTag = TAG_MOVE_SELECTOR, + .oam = &sOamData_MoveSelector, + .anims = sSpriteAnimTable_MoveSelector, .images = NULL, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy @@ -1025,17 +1041,17 @@ static const struct CompressedSpriteSheet sStatusIconsSpriteSheet = { .data = gStatusGfx_Icons, .size = 0x380, - .tag = 30001 + .tag = TAG_MON_STATUS }; static const struct CompressedSpritePalette sStatusIconsSpritePalette = { .data = gStatusPal_Icons, - .tag = 30001 + .tag = TAG_MON_STATUS }; static const struct SpriteTemplate sSpriteTemplate_StatusCondition = { - .tileTag = 30001, - .paletteTag = 30001, + .tileTag = TAG_MON_STATUS, + .paletteTag = TAG_MON_STATUS, .oam = &sOamData_StatusCondition, .anims = sSpriteAnimTable_StatusCondition, .images = NULL, @@ -1064,16 +1080,16 @@ void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex, case PSS_MODE_NORMAL: case PSS_MODE_BOX: sMonSummaryScreen->minPageIndex = 0; - sMonSummaryScreen->maxPageIndex = 3; + sMonSummaryScreen->maxPageIndex = PSS_PAGE_COUNT - 1; break; - case PSS_MODE_UNK1: + case PSS_MODE_LOCK_MOVES: sMonSummaryScreen->minPageIndex = 0; - sMonSummaryScreen->maxPageIndex = 3; - sMonSummaryScreen->unk40C8 = TRUE; + sMonSummaryScreen->maxPageIndex = PSS_PAGE_COUNT - 1; + sMonSummaryScreen->lockMovesFlag = TRUE; break; case PSS_MODE_SELECT_MOVE: - sMonSummaryScreen->minPageIndex = 2; - sMonSummaryScreen->maxPageIndex = 3; + sMonSummaryScreen->minPageIndex = PSS_PAGE_BATTLE_MOVES; + sMonSummaryScreen->maxPageIndex = PSS_PAGE_COUNT - 1; sMonSummaryScreen->lockMonFlag = TRUE; break; } @@ -1081,10 +1097,10 @@ void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex, sMonSummaryScreen->currPageIndex = sMonSummaryScreen->minPageIndex; SummaryScreen_SetUnknownTaskId(-1); - if (gMonSpritesGfxPtr == 0) + if (gMonSpritesGfxPtr == NULL) sub_806F2AC(0, 0); - SetMainCallback2(SummaryScreen_LoadingCB2); + SetMainCallback2(CB2_InitSummaryScreen); } void ShowSelectMovePokemonSummaryScreen(struct Pokemon *mons, u8 monIndex, u8 maxMonIndex, void (*callback)(void), u16 newMove) @@ -1099,7 +1115,7 @@ void ShowPokemonSummaryScreenSet40EF(u8 mode, struct BoxPokemon *mons, u8 monInd sMonSummaryScreen->unk40EF = TRUE; } -static void SummaryScreen_MainCB2(void) +static void MainCB2(void) { RunTasks(); AnimateSprites(); @@ -1108,19 +1124,19 @@ static void SummaryScreen_MainCB2(void) UpdatePaletteFade(); } -static void SummaryScreen_VBlank(void) +static void VBlank(void) { LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); } -static void SummaryScreen_LoadingCB2(void) +static void CB2_InitSummaryScreen(void) { - while (sub_81221EC() != TRUE && SummaryScreen_LoadGraphics() != TRUE && sub_81221AC() != TRUE); + while (sub_81221EC() != TRUE && LoadGraphics() != TRUE && sub_81221AC() != TRUE); } -static bool8 SummaryScreen_LoadGraphics(void) +static bool8 LoadGraphics(void) { switch (gMain.state) { @@ -1153,7 +1169,7 @@ static bool8 SummaryScreen_LoadGraphics(void) gMain.state++; break; case 6: - if (SummaryScreen_DecompressGraphics() != FALSE) + if (DecompressGraphics() != FALSE) gMain.state++; break; case 7: @@ -1178,7 +1194,7 @@ static bool8 SummaryScreen_LoadGraphics(void) gMain.state++; break; case 12: - PrintPageNamesAndStatsPageToWindows(); + PrintPageNamesAndStats(); gMain.state++; break; case 13: @@ -1186,11 +1202,11 @@ static bool8 SummaryScreen_LoadGraphics(void) gMain.state++; break; case 14: - sub_81C0348(); + SetDefaultTilemaps(); gMain.state++; break; case 15: - CreatePageWindowTilemaps(sMonSummaryScreen->currPageIndex); + PutPageWindowTilemaps(sMonSummaryScreen->currPageIndex); gMain.state++; break; case 16: @@ -1200,8 +1216,8 @@ static bool8 SummaryScreen_LoadGraphics(void) gMain.state++; break; case 17: - sMonSummaryScreen->spriteIds[0] = CreatePokemonSprite(&sMonSummaryScreen->currentMon, &sMonSummaryScreen->switchCounter); - if (sMonSummaryScreen->spriteIds[0] != 0xFF) + sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON] = LoadMonGfxAndSprite(&sMonSummaryScreen->currentMon, &sMonSummaryScreen->switchCounter); + if (sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON] != 0xFF) { sMonSummaryScreen->switchCounter = 0; gMain.state++; @@ -1225,13 +1241,13 @@ static bool8 SummaryScreen_LoadGraphics(void) break; case 22: if (sMonSummaryScreen->mode != PSS_MODE_SELECT_MOVE) - CreateTask(HandleInput, 0); + CreateTask(Task_HandleInput, 0); else - CreateTask(sub_81C171C, 0); + CreateTask(Task_SetHandleReplaceMoveInput, 0); gMain.state++; break; case 23: - BlendPalettes(-1, 16, 0); + BlendPalettes(0xFFFFFFFF, 16, 0); gMain.state++; break; case 24: @@ -1240,8 +1256,8 @@ static bool8 SummaryScreen_LoadGraphics(void) gMain.state++; break; default: - SetVBlankCallback(SummaryScreen_VBlank); - SetMainCallback2(SummaryScreen_MainCB2); + SetVBlankCallback(VBlank); + SetMainCallback2(MainCB2); return TRUE; } return FALSE; @@ -1250,7 +1266,7 @@ static bool8 SummaryScreen_LoadGraphics(void) static void InitBGs(void) { ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, sUnknown_0861CBB4, ARRAY_COUNT(sUnknown_0861CBB4)); + InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates)); SetBgTilemapBuffer(1, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0]); SetBgTilemapBuffer(2, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_SKILLS][0]); SetBgTilemapBuffer(3, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0]); @@ -1258,7 +1274,7 @@ static void InitBGs(void) schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(2); schedule_bg_copy_tilemap_to_vram(3); - SetGpuReg(REG_OFFSET_DISPCNT, 0x1040); + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); SetGpuReg(REG_OFFSET_BLDCNT, 0); ShowBg(0); ShowBg(1); @@ -1266,7 +1282,7 @@ static void InitBGs(void) ShowBg(3); } -static bool8 SummaryScreen_DecompressGraphics(void) +static bool8 DecompressGraphics(void) { switch (sMonSummaryScreen->switchCounter) { @@ -1320,7 +1336,7 @@ static bool8 SummaryScreen_DecompressGraphics(void) sMonSummaryScreen->switchCounter++; break; case 11: - LoadCompressedSpritePalette(&gUnknown_0861D07C); + LoadCompressedSpritePalette(&sMoveSelectorSpritePal); sMonSummaryScreen->switchCounter++; break; case 12: @@ -1402,7 +1418,7 @@ static bool8 ExtractMonDataToSummaryStruct(struct Pokemon *mon) break; case 3: GetMonData(mon, MON_DATA_OT_NAME, sum->OTName); - ConvertInternationalString((u8*)&sum->OTName, GetMonData(mon, MON_DATA_LANGUAGE)); + ConvertInternationalString(sum->OTName, GetMonData(mon, MON_DATA_LANGUAGE)); sum->ailment = GetMonAilment(mon); sum->OTGender = GetMonData(mon, MON_DATA_OT_GENDER); sum->OTID = GetMonData(mon, MON_DATA_OT_ID); @@ -1419,33 +1435,30 @@ static bool8 ExtractMonDataToSummaryStruct(struct Pokemon *mon) return FALSE; } -static void sub_81C0348(void) +static void SetDefaultTilemaps(void) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_BATTLE_MOVES && sMonSummaryScreen->currPageIndex != PSS_PAGE_CONTEST_MOVES) { - sub_81C1DA4(0, 255); - sub_81C1EFC(0, 255, 0); + HandlePowerAccTilemap(0, 0xFF); + HandleAppealJamTilemap(0, 0xFF, 0); } else { DrawContestMoveHearts(sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]); - sub_81C2194(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], 3, 0); - sub_81C2194(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], 1, 0); + TilemapFiveMovesDisplay(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], 3, FALSE); + TilemapFiveMovesDisplay(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], 1, FALSE); SetBgTilemapBuffer(1, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0]); SetBgTilemapBuffer(2, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0]); ChangeBgX(2, 0x10000, 1); ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); } + if (sMonSummaryScreen->summary.ailment == AILMENT_NONE) - { - sub_81C2074(0, 0xFF); - } - else - { - if (sMonSummaryScreen->currPageIndex != PSS_PAGE_BATTLE_MOVES && sMonSummaryScreen->currPageIndex != PSS_PAGE_CONTEST_MOVES) - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); - } + HandleStatusTilemap(0, 0xFF); + else if (sMonSummaryScreen->currPageIndex != PSS_PAGE_BATTLE_MOVES && sMonSummaryScreen->currPageIndex != PSS_PAGE_CONTEST_MOVES) + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); + LimitEggSummaryPageDisplay(); DrawPokerusCuredSymbol(&sMonSummaryScreen->currentMon); } @@ -1473,14 +1486,14 @@ static void CloseSummaryScreen(u8 taskId) FreeAllSpritePalettes(); StopCryAndClearCrySongs(); m4aMPlayVolumeControl(&gMPlayInfo_BGM, 0xFFFF, 0x100); - if (gMonSpritesGfxPtr == 0) + if (gMonSpritesGfxPtr == NULL) sub_806F47C(0); FreeSummaryScreen(); DestroyTask(taskId); } } -static void HandleInput(u8 taskId) +static void Task_HandleInput(u8 taskId) { if (sub_81221EC() != TRUE && !gPaletteFade.active) { @@ -1510,10 +1523,10 @@ static void HandleInput(u8 taskId) PlaySE(SE_SELECT); BeginCloseSummaryScreen(taskId); } - else + else // Contest or Battle Moves { PlaySE(SE_SELECT); - sub_81C0E48(taskId); + SwitchToMoveSelection(taskId); } } } @@ -1528,14 +1541,12 @@ static void HandleInput(u8 taskId) static void ChangeSummaryPokemon(u8 taskId, s8 delta) { - s8 v1; - s8 v2; + s8 monId; if (!sMonSummaryScreen->lockMonFlag) { if (sMonSummaryScreen->isBoxMon == TRUE) { - if (sMonSummaryScreen->currPageIndex != PSS_PAGE_INFO) { if (delta == 1) @@ -1550,35 +1561,35 @@ static void ChangeSummaryPokemon(u8 taskId, s8 delta) else delta = 3; } - v1 = sub_80D214C(sMonSummaryScreen->monList.boxMons, sMonSummaryScreen->curMonIndex, sMonSummaryScreen->maxMonIndex, delta); + monId = sub_80D214C(sMonSummaryScreen->monList.boxMons, sMonSummaryScreen->curMonIndex, sMonSummaryScreen->maxMonIndex, delta); } else if (IsMultiBattle() == TRUE) { - v1 = sub_81C09B4(delta); + monId = AdvanceMultiBattleMonIndex(delta); } else { - v1 = sub_81C08F8(delta); + monId = AdvanceMonIndex(delta); } - if (v1 != -1) + if (monId != -1) { PlaySE(SE_SELECT); if (sMonSummaryScreen->summary.ailment != AILMENT_NONE) { - SetSpriteInvisibility(2, 1); + SetSpriteInvisibility(SPRITE_ARR_ID_STATUS, TRUE); ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); schedule_bg_copy_tilemap_to_vram(0); - sub_81C2074(0, 2); + HandleStatusTilemap(0, 2); } - sMonSummaryScreen->curMonIndex = v1; + sMonSummaryScreen->curMonIndex = monId; gTasks[taskId].data[0] = 0; - gTasks[taskId].func = sub_81C0704; + gTasks[taskId].func = Task_ChangeSummaryMon; } } } -static void sub_81C0704(u8 taskId) +static void Task_ChangeSummaryMon(u8 taskId) { s16 *data = gTasks[taskId].data; @@ -1589,10 +1600,10 @@ static void sub_81C0704(u8 taskId) break; case 1: SummaryScreen_DestroyUnknownTask(); - DestroySpriteAndFreeResources(&gSprites[sMonSummaryScreen->spriteIds[0]]); + DestroySpriteAndFreeResources(&gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]]); break; case 2: - DestroySpriteAndFreeResources(&gSprites[sMonSummaryScreen->spriteIds[1]]); + DestroySpriteAndFreeResources(&gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_BALL]]); break; case 3: CopyMonToSummaryStruct(&sMonSummaryScreen->currentMon); @@ -1610,16 +1621,16 @@ static void sub_81C0704(u8 taskId) break; case 7: if (sMonSummaryScreen->summary.ailment != AILMENT_NONE) - sub_81C2074(10, -2); + HandleStatusTilemap(10, -2); DrawPokerusCuredSymbol(&sMonSummaryScreen->currentMon); data[1] = 0; break; case 8: - sMonSummaryScreen->spriteIds[0] = CreatePokemonSprite(&sMonSummaryScreen->currentMon, &data[1]); - if (sMonSummaryScreen->spriteIds[0] == 0xFF) + sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON] = LoadMonGfxAndSprite(&sMonSummaryScreen->currentMon, &data[1]); + if (sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON] == 0xFF) return; - gSprites[sMonSummaryScreen->spriteIds[0]].data[2] = 1; - CheckExperienceProgressBar(); + gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]].data[2] = 1; + TryDrawExperienceProgressBar(); data[1] = 0; break; case 9: @@ -1633,31 +1644,31 @@ static void sub_81C0704(u8 taskId) LimitEggSummaryPageDisplay(); break; case 12: - gSprites[sMonSummaryScreen->spriteIds[0]].data[2] = 0; + gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]].data[2] = 0; break; default: - if (sub_81221EC() == 0 && FuncIsActiveTask(sub_81C20F0) == 0) + if (sub_81221EC() == 0 && FuncIsActiveTask(Task_ShowStatusWindow) == 0) { data[0] = 0; - gTasks[taskId].func = HandleInput; + gTasks[taskId].func = Task_HandleInput; } return; } data[0]++; } -static s8 sub_81C08F8(s8 a) +static s8 AdvanceMonIndex(s8 delta) { struct Pokemon *mon = sMonSummaryScreen->monList.mons; if (sMonSummaryScreen->currPageIndex == PSS_PAGE_INFO) { - if (a == -1 && sMonSummaryScreen->curMonIndex == 0) + if (delta == -1 && sMonSummaryScreen->curMonIndex == 0) return -1; - else if (a == 1 && sMonSummaryScreen->curMonIndex >= sMonSummaryScreen->maxMonIndex) + else if (delta == 1 && sMonSummaryScreen->curMonIndex >= sMonSummaryScreen->maxMonIndex) return -1; else - return sMonSummaryScreen->curMonIndex + a; + return sMonSummaryScreen->curMonIndex + delta; } else { @@ -1665,48 +1676,47 @@ static s8 sub_81C08F8(s8 a) do { - index += a; + index += delta; if (index < 0 || index > sMonSummaryScreen->maxMonIndex) return -1; - } while (GetMonData(&mon[index], MON_DATA_IS_EGG) != 0); + } while (GetMonData(&mon[index], MON_DATA_IS_EGG)); return index; } } -static s8 sub_81C09B4(s8 a) +static s8 AdvanceMultiBattleMonIndex(s8 delta) { - struct Pokemon *mon = sMonSummaryScreen->monList.mons; - s8 r5 = 0; + struct Pokemon *mons = sMonSummaryScreen->monList.mons; + s8 index, arrId = 0; u8 i; - for (i = 0; i < 6; i++) + for (i = 0; i < PARTY_SIZE; i++) { - if (gUnknown_0861CC1C[i] == sMonSummaryScreen->curMonIndex) + if (sMultiBattleOrder[i] == sMonSummaryScreen->curMonIndex) { - r5 = i; + arrId = i; break; } } while (TRUE) { - int b; - const s8* c = gUnknown_0861CC1C; + const s8 *order = sMultiBattleOrder; - r5 += a; - if (r5 < 0 || r5 >= 6) + arrId += delta; + if (arrId < 0 || arrId >= PARTY_SIZE) return -1; - b = c[r5]; - if (sub_81C0A50(&mon[b]) == TRUE) - return b; + index = order[arrId]; + if (IsValidToViewInMulti(&mons[index]) == TRUE) + return index; } } -static bool8 sub_81C0A50(struct Pokemon* mon) +static bool8 IsValidToViewInMulti(struct Pokemon* mon) { if (GetMonData(mon, MON_DATA_SPECIES) == SPECIES_NONE) return FALSE; - else if (sMonSummaryScreen->curMonIndex != 0 || GetMonData(mon, MON_DATA_IS_EGG) == 0) + else if (sMonSummaryScreen->curMonIndex != 0 || !GetMonData(mon, MON_DATA_IS_EGG)) return TRUE; else return FALSE; @@ -1773,9 +1783,9 @@ static void PssScrollRightEnd(u8 taskId) // display right data[1] = 0; data[0] = 0; DrawPagination(); - CreatePageWindowTilemaps(sMonSummaryScreen->currPageIndex); + PutPageWindowTilemaps(sMonSummaryScreen->currPageIndex); SetTypeIcons(); - CheckExperienceProgressBar(); + TryDrawExperienceProgressBar(); SwitchTaskToFollowupFunc(taskId); } @@ -1813,7 +1823,7 @@ static void PssScrollLeftEnd(u8 taskId) // display left } if (sMonSummaryScreen->currPageIndex > 1) { - SetBgTilemapBuffer(data[1], (u8*)sMonSummaryScreen + ((sMonSummaryScreen->currPageIndex << 12) + 0xFFFFF0BC)); + SetBgTilemapBuffer(data[1], sMonSummaryScreen->bgTilemapBuffers[sMonSummaryScreen->currPageIndex - 1][0]); ChangeBgX(data[1], 0x10000, 0); } ShowBg(1); @@ -1822,48 +1832,48 @@ static void PssScrollLeftEnd(u8 taskId) // display left data[1] = 0; data[0] = 0; DrawPagination(); - CreatePageWindowTilemaps(sMonSummaryScreen->currPageIndex); + PutPageWindowTilemaps(sMonSummaryScreen->currPageIndex); SetTypeIcons(); - CheckExperienceProgressBar(); + TryDrawExperienceProgressBar(); SwitchTaskToFollowupFunc(taskId); } -static void CheckExperienceProgressBar(void) +static void TryDrawExperienceProgressBar(void) { - if (sMonSummaryScreen->currPageIndex == 1) + if (sMonSummaryScreen->currPageIndex == PSS_PAGE_SKILLS) DrawExperienceProgressBar(&sMonSummaryScreen->currentMon); } -static void sub_81C0E48(u8 taskId) +static void SwitchToMoveSelection(u8 taskId) { u16 move; + sMonSummaryScreen->firstMoveIndex = 0; move = sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]; ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); - if (gSprites[sMonSummaryScreen->spriteIds[2]].invisible == 0) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); - sub_81C1DA4(9, -3); - sub_81C1EFC(9, -3, move); - if (!sMonSummaryScreen->unk40C8) + HandlePowerAccTilemap(9, -3); + HandleAppealJamTilemap(9, -3, move); + if (!sMonSummaryScreen->lockMovesFlag) { ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_SWITCH); } - sub_81C2194(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], 3, 0); - sub_81C2194(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], 1, 0); + TilemapFiveMovesDisplay(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], 3, FALSE); + TilemapFiveMovesDisplay(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], 1, FALSE); PrintMoveDetails(move); PrintNewMoveDetailsOrCancelText(); SetNewMoveTypeIcon(); schedule_bg_copy_tilemap_to_vram(0); schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(2); - sub_81C4AF8(8); - gTasks[taskId].func = HandleInput_MoveSelect; + CreateMoveSelectorSprites(SPRITE_ARR_ID_MOVE_SELECTOR1); + gTasks[taskId].func = Task_HandleInput_MoveSelect; } -static void HandleInput_MoveSelect(u8 taskId) +static void Task_HandleInput_MoveSelect(u8 taskId) { - u8 id = taskId; s16 *data = gTasks[taskId].data; if (sub_81221EC() != 1) @@ -1871,25 +1881,25 @@ static void HandleInput_MoveSelect(u8 taskId) if (gMain.newKeys & DPAD_UP) { data[0] = 4; - sub_81C1070(data, -1, &sMonSummaryScreen->firstMoveIndex); + ChangeSelectedMove(data, -1, &sMonSummaryScreen->firstMoveIndex); } else if (gMain.newKeys & DPAD_DOWN) { data[0] = 4; - sub_81C1070(data, 1, &sMonSummaryScreen->firstMoveIndex); + ChangeSelectedMove(data, 1, &sMonSummaryScreen->firstMoveIndex); } else if (gMain.newKeys & A_BUTTON) { - if (sMonSummaryScreen->unk40C8 == TRUE + if (sMonSummaryScreen->lockMovesFlag == TRUE || (sMonSummaryScreen->newMove == MOVE_NONE && sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES)) { PlaySE(SE_SELECT); - sub_81C11F4(taskId); + CloseMoveSelectMode(taskId); } - else if (sub_81C1040() == TRUE) + else if (HasMoreThanOneMove() == TRUE) { PlaySE(SE_SELECT); - sub_81C129C(taskId); + SwitchToMovePositionSwitchMode(taskId); } else { @@ -1899,12 +1909,12 @@ static void HandleInput_MoveSelect(u8 taskId) else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); - sub_81C11F4(id); + CloseMoveSelectMode(taskId); } } } -static bool8 sub_81C1040(void) +static bool8 HasMoreThanOneMove(void) { u8 i; for (i = 1; i < MAX_MON_MOVES; i++) @@ -1915,27 +1925,27 @@ static bool8 sub_81C1040(void) return FALSE; } -static void sub_81C1070(s16 *a, s8 b, u8 *c) +static void ChangeSelectedMove(s16 *taskData, s8 direction, u8 *moveIndexPtr) { - s8 i; - s8 moveIndex; + s8 i, newMoveIndex; u16 move; PlaySE(SE_SELECT); - moveIndex = *c; + newMoveIndex = *moveIndexPtr; for (i = 0; i < MAX_MON_MOVES; i++) { - moveIndex += b; - if (moveIndex > a[0]) - moveIndex = 0; - else if (moveIndex < 0) - moveIndex = a[0]; - if (moveIndex == MAX_MON_MOVES) + newMoveIndex += direction; + if (newMoveIndex > taskData[0]) + newMoveIndex = 0; + else if (newMoveIndex < 0) + newMoveIndex = taskData[0]; + + if (newMoveIndex == MAX_MON_MOVES) { move = sMonSummaryScreen->newMove; break; } - move = sMonSummaryScreen->summary.moves[moveIndex]; + move = sMonSummaryScreen->summary.moves[newMoveIndex]; if (move != 0) break; } @@ -1943,61 +1953,66 @@ static void sub_81C1070(s16 *a, s8 b, u8 *c) schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(2); PrintMoveDetails(move); - if ((*c == 4 && sMonSummaryScreen->newMove == MOVE_NONE) || a[1] == 1) + if ((*moveIndexPtr == MAX_MON_MOVES && sMonSummaryScreen->newMove == MOVE_NONE) + || taskData[1] == 1) { ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); - if (!gSprites[sMonSummaryScreen->spriteIds[2]].invisible) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); schedule_bg_copy_tilemap_to_vram(0); - sub_81C1DA4(9, -3); - sub_81C1EFC(9, -3, move); + HandlePowerAccTilemap(9, -3); + HandleAppealJamTilemap(9, -3, move); } - if (*c != 4 && moveIndex == 4 && sMonSummaryScreen->newMove == MOVE_NONE) + if (*moveIndexPtr != MAX_MON_MOVES + && newMoveIndex == MAX_MON_MOVES + && sMonSummaryScreen->newMove == MOVE_NONE) { ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); schedule_bg_copy_tilemap_to_vram(0); - sub_81C1DA4(0, 3); - sub_81C1EFC(0, 3, 0); + HandlePowerAccTilemap(0, 3); + HandleAppealJamTilemap(0, 3, 0); } - *c = moveIndex; - if (c == &sMonSummaryScreen->firstMoveIndex) - sub_81C4D18(8); + + *moveIndexPtr = newMoveIndex; + // Not sure what the purpose of this function is, seems to have no effect whatsoever. + if (moveIndexPtr == &sMonSummaryScreen->firstMoveIndex) + MakeMoveSelectorVisible(SPRITE_ARR_ID_MOVE_SELECTOR1); else - sub_81C4D18(18); + MakeMoveSelectorVisible(SPRITE_ARR_ID_MOVE_SELECTOR2); } -static void sub_81C11F4(u8 taskId) +static void CloseMoveSelectMode(u8 taskId) { - sub_81C4C60(8); + DestroyMoveSelectorSprites(8); ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_SWITCH); PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); PrintMoveDetails(0); - sub_81C2194(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], 3, 1); - sub_81C2194(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], 1, 1); - sub_81C4064(); + TilemapFiveMovesDisplay(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], 3, TRUE); + TilemapFiveMovesDisplay(sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], 1, TRUE); + AddAndFillMoveNamesWindow(); // This function seems to have no effect. if (sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) { ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); - sub_81C1DA4(0, 3); - sub_81C1EFC(0, 3, 0); + HandlePowerAccTilemap(0, 3); + HandleAppealJamTilemap(0, 3, 0); } schedule_bg_copy_tilemap_to_vram(0); schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(2); - gTasks[taskId].func = HandleInput; + gTasks[taskId].func = Task_HandleInput; } -static void sub_81C129C(u8 taskId) +static void SwitchToMovePositionSwitchMode(u8 taskId) { sMonSummaryScreen->secondMoveIndex = sMonSummaryScreen->firstMoveIndex; - sub_81C4C84(1); - sub_81C4AF8(18); - gTasks[taskId].func = sub_81C12E4; + SetMainMoveSelectorColor(1); + CreateMoveSelectorSprites(SPRITE_ARR_ID_MOVE_SELECTOR2); + gTasks[taskId].func = Task_HandleInput_MovePositionSwitch; } -static void sub_81C12E4(u8 taskId) +static void Task_HandleInput_MovePositionSwitch(u8 taskId) { s16* data = gTasks[taskId].data; @@ -2006,54 +2021,50 @@ static void sub_81C12E4(u8 taskId) if (gMain.newKeys & DPAD_UP) { data[0] = 3; - sub_81C1070(&data[0], -1, &sMonSummaryScreen->secondMoveIndex); + ChangeSelectedMove(&data[0], -1, &sMonSummaryScreen->secondMoveIndex); } else if (gMain.newKeys & DPAD_DOWN) { data[0] = 3; - sub_81C1070(&data[0], 1, &sMonSummaryScreen->secondMoveIndex); + ChangeSelectedMove(&data[0], 1, &sMonSummaryScreen->secondMoveIndex); } else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->firstMoveIndex == sMonSummaryScreen->secondMoveIndex) - { - sub_81C13B0(taskId, 0); - } + ExitMovePositionSwitchMode(taskId, FALSE); else - { - sub_81C13B0(taskId, 1); - } + ExitMovePositionSwitchMode(taskId, TRUE); } else if (gMain.newKeys & B_BUTTON) { - sub_81C13B0(taskId, 0); + ExitMovePositionSwitchMode(taskId, FALSE); } } } -static void sub_81C13B0(u8 taskId, bool8 b) +static void ExitMovePositionSwitchMode(u8 taskId, bool8 swapMoves) { u16 move; PlaySE(SE_SELECT); - sub_81C4C84(0); - sub_81C4C60(18); + SetMainMoveSelectorColor(0); + DestroyMoveSelectorSprites(SPRITE_ARR_ID_MOVE_SELECTOR2); - if (b == TRUE) + if (swapMoves == TRUE) { if (!sMonSummaryScreen->isBoxMon) { - struct Pokemon *why = sMonSummaryScreen->monList.mons; - SwapMonMoves(&why[sMonSummaryScreen->curMonIndex], sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); + struct Pokemon *mon = sMonSummaryScreen->monList.mons; + SwapMonMoves(&mon[sMonSummaryScreen->curMonIndex], sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); } else { - struct BoxPokemon *why = sMonSummaryScreen->monList.boxMons; - SwapBoxMonMoves(&why[sMonSummaryScreen->curMonIndex], sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); + struct BoxPokemon *boxMon = sMonSummaryScreen->monList.boxMons; + SwapBoxMonMoves(&boxMon[sMonSummaryScreen->curMonIndex], sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); } CopyMonToSummaryStruct(&sMonSummaryScreen->currentMon); - sub_81C40A0(sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); - sub_81C4568(sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); + SwapMovesNamesPP(sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); + SwapMovesTypeSprites(sMonSummaryScreen->firstMoveIndex, sMonSummaryScreen->secondMoveIndex); sMonSummaryScreen->firstMoveIndex = sMonSummaryScreen->secondMoveIndex; } @@ -2062,7 +2073,7 @@ static void sub_81C13B0(u8 taskId, bool8 b) DrawContestMoveHearts(move); schedule_bg_copy_tilemap_to_vram(1); schedule_bg_copy_tilemap_to_vram(2); - gTasks[taskId].func = HandleInput_MoveSelect; + gTasks[taskId].func = Task_HandleInput_MoveSelect; } static void SwapMonMoves(struct Pokemon *mon, u8 moveIndex1, u8 moveIndex2) @@ -2135,14 +2146,14 @@ static void SwapBoxMonMoves(struct BoxPokemon *mon, u8 moveIndex1, u8 moveIndex2 summary->ppBonuses = ppBonuses; } -static void sub_81C171C(u8 taskId) +static void Task_SetHandleReplaceMoveInput(u8 taskId) { SetNewMoveTypeIcon(); - sub_81C4AF8(8); - gTasks[taskId].func = HandleReplaceMoveInput; + CreateMoveSelectorSprites(SPRITE_ARR_ID_MOVE_SELECTOR1); + gTasks[taskId].func = Task_HandleReplaceMoveInput; } -static void HandleReplaceMoveInput(u8 taskId) +static void Task_HandleReplaceMoveInput(u8 taskId) { s16* data = gTasks[taskId].data; @@ -2153,12 +2164,12 @@ static void HandleReplaceMoveInput(u8 taskId) if (gMain.newKeys & DPAD_UP) { data[0] = 4; - sub_81C1070(data, -1, &sMonSummaryScreen->firstMoveIndex); + ChangeSelectedMove(data, -1, &sMonSummaryScreen->firstMoveIndex); } else if (gMain.newKeys & DPAD_DOWN) { data[0] = 4; - sub_81C1070(data, 1, &sMonSummaryScreen->firstMoveIndex); + ChangeSelectedMove(data, 1, &sMonSummaryScreen->firstMoveIndex); } else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { @@ -2181,12 +2192,11 @@ static void HandleReplaceMoveInput(u8 taskId) else { PlaySE(SE_HAZURE); - ShowHMMovesCantBeForgottenWindow(taskId); + ShowCantForgetHMsWindow(taskId); } } else if (gMain.newKeys & B_BUTTON) { - u32 var1; StopPokemonAnimations(); PlaySE(SE_SELECT); sMoveSlotToReplace = MAX_MON_MOVES; @@ -2199,85 +2209,87 @@ static void HandleReplaceMoveInput(u8 taskId) static bool8 CanReplaceMove(void) { - if (sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES || sMonSummaryScreen->newMove == MOVE_NONE || IsMoveHm(sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]) != 1) + if (sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES + || sMonSummaryScreen->newMove == MOVE_NONE + || IsMoveHm(sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]) != TRUE) return TRUE; else return FALSE; } -static void ShowHMMovesCantBeForgottenWindow(u8 taskId) +static void ShowCantForgetHMsWindow(u8 taskId) { ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); schedule_bg_copy_tilemap_to_vram(0); - sub_81C1DA4(0, 3); - sub_81C1EFC(0, 3, 0); + HandlePowerAccTilemap(0, 3); + HandleAppealJamTilemap(0, 3, 0); PrintHMMovesCantBeForgotten(); - gTasks[taskId].func = HandleHMMovesCantBeForgottenInput; + gTasks[taskId].func = Task_HandleInputCantForgetHMsMoves; } // This redraws the power/accuracy window when the player scrolls out of the "HM Moves can't be forgotten" message -static void HandleHMMovesCantBeForgottenInput(u8 taskId) +static void Task_HandleInputCantForgetHMsMoves(u8 taskId) { s16* data = gTasks[taskId].data; u16 move; - if (FuncIsActiveTask(sub_81C1E20) != 1) + if (FuncIsActiveTask(Task_ShowPowerAccWindow) != 1) { if (gMain.newKeys & DPAD_UP) { data[1] = 1; data[0] = 4; - sub_81C1070(&data[0], -1, &sMonSummaryScreen->firstMoveIndex); + ChangeSelectedMove(&data[0], -1, &sMonSummaryScreen->firstMoveIndex); data[1] = 0; - gTasks[taskId].func = HandleReplaceMoveInput; + gTasks[taskId].func = Task_HandleReplaceMoveInput; } else if (gMain.newKeys & DPAD_DOWN) { data[1] = 1; data[0] = 4; - sub_81C1070(&data[0], 1, &sMonSummaryScreen->firstMoveIndex); + ChangeSelectedMove(&data[0], 1, &sMonSummaryScreen->firstMoveIndex); data[1] = 0; - gTasks[taskId].func = HandleReplaceMoveInput; + gTasks[taskId].func = Task_HandleReplaceMoveInput; } else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { - if (sMonSummaryScreen->currPageIndex != 2) + if (sMonSummaryScreen->currPageIndex != PSS_PAGE_BATTLE_MOVES) { ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); - if (!gSprites[sMonSummaryScreen->spriteIds[2]].invisible) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); move = sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]; - gTasks[taskId].func = HandleReplaceMoveInput; + gTasks[taskId].func = Task_HandleReplaceMoveInput; ChangePage(taskId, -1); - sub_81C1DA4(9, -2); - sub_81C1EFC(9, -2, move); + HandlePowerAccTilemap(9, -2); + HandleAppealJamTilemap(9, -2, move); } } else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { - if (sMonSummaryScreen->currPageIndex != 3) + if (sMonSummaryScreen->currPageIndex != PSS_PAGE_CONTEST_MOVES) { ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); - if (!gSprites[sMonSummaryScreen->spriteIds[2]].invisible) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); move = sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]; - gTasks[taskId].func = HandleReplaceMoveInput; + gTasks[taskId].func = Task_HandleReplaceMoveInput; ChangePage(taskId, 1); - sub_81C1DA4(9, -2); - sub_81C1EFC(9, -2, move); + HandlePowerAccTilemap(9, -2); + HandleAppealJamTilemap(9, -2, move); } } else if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); - if (!gSprites[sMonSummaryScreen->spriteIds[2]].invisible) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); move = sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]; PrintMoveDetails(move); schedule_bg_copy_tilemap_to_vram(0); - sub_81C1DA4(9, -3); - sub_81C1EFC(9, -3, move); - gTasks[taskId].func = HandleReplaceMoveInput; + HandlePowerAccTilemap(9, -3); + HandleAppealJamTilemap(9, -3, move); + gTasks[taskId].func = Task_HandleReplaceMoveInput; } } } @@ -2354,7 +2366,7 @@ static void DrawPagination(void) // Updates the pagination dots at the top of th Free(alloced); } -static void sub_81C1CB0(const struct UnkStruct_61CC04 *unkStruct, u16 *dest, u8 c, bool8 d) +static void ChangeTilemap(const struct TilemapCtrl *unkStruct, u16 *dest, u8 c, bool8 d) { u16 i; u16 *alloced = Alloc(unkStruct->field_6 * 2 * unkStruct->field_7); @@ -2364,46 +2376,40 @@ static void sub_81C1CB0(const struct UnkStruct_61CC04 *unkStruct, u16 *dest, u8 if (!d) { for (i = 0; i < unkStruct->field_7; i++) - { - CpuCopy16(&unkStruct->ptr[c + unkStruct->field_6 * i], &alloced[unkStruct->field_6 * i], (unkStruct->field_6 - c) * 2); - } + CpuCopy16(&unkStruct->gfx[c + unkStruct->field_6 * i], &alloced[unkStruct->field_6 * i], (unkStruct->field_6 - c) * 2); } else { for (i = 0; i < unkStruct->field_7; i++) - { - CpuCopy16(&unkStruct->ptr[unkStruct->field_6 * i], &alloced[c + unkStruct->field_6 * i], (unkStruct->field_6 - c) * 2); - } + CpuCopy16(&unkStruct->gfx[unkStruct->field_6 * i], &alloced[c + unkStruct->field_6 * i], (unkStruct->field_6 - c) * 2); } } + for (i = 0; i < unkStruct->field_7; i++) - { CpuCopy16(&alloced[unkStruct->field_6 * i], &dest[(unkStruct->field_9 + i) * 32 + unkStruct->field_8], unkStruct->field_6 * 2); - } + Free(alloced); } -static void sub_81C1DA4(u16 a, s16 b) +static void HandlePowerAccTilemap(u16 a, s16 b) { - if (b > sUnknown_0861CC04.field_6) - b = sUnknown_0861CC04.field_6; - if (b == 0 || b == sUnknown_0861CC04.field_6) + if (b > sBattleMoveTilemapCtrl.field_6) + b = sBattleMoveTilemapCtrl.field_6; + if (b == 0 || b == sBattleMoveTilemapCtrl.field_6) { - sub_81C1CB0(&sUnknown_0861CC04, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], b, 1); + ChangeTilemap(&sBattleMoveTilemapCtrl, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], b, TRUE); } else { - u8 taskId = FindTaskIdByFunc(sub_81C1E20); + u8 taskId = FindTaskIdByFunc(Task_ShowPowerAccWindow); if (taskId == 0xFF) - { - taskId = CreateTask(sub_81C1E20, 8); - } + taskId = CreateTask(Task_ShowPowerAccWindow, 8); gTasks[taskId].data[0] = b; gTasks[taskId].data[1] = a; } } -static void sub_81C1E20(u8 taskId) +static void Task_ShowPowerAccWindow(u8 taskId) { s16 *data = gTasks[taskId].data; data[1] += data[0]; @@ -2411,12 +2417,12 @@ static void sub_81C1E20(u8 taskId) { data[1] = 0; } - else if (data[1] > sUnknown_0861CC04.field_6) + else if (data[1] > sBattleMoveTilemapCtrl.field_6) { - data[1] = sUnknown_0861CC04.field_6; + data[1] = sBattleMoveTilemapCtrl.field_6; } - sub_81C1CB0(&sUnknown_0861CC04, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], data[1], 1); - if (data[1] <= 0 || data[1] >= sUnknown_0861CC04.field_6) + ChangeTilemap(&sBattleMoveTilemapCtrl, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_BATTLE_MOVES][0], data[1], TRUE); + if (data[1] <= 0 || data[1] >= sBattleMoveTilemapCtrl.field_6) { if (data[0] < 0) { @@ -2425,7 +2431,7 @@ static void sub_81C1E20(u8 taskId) } else { - if (!gSprites[sMonSummaryScreen->spriteIds[2]].invisible) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); PutWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); } @@ -2436,24 +2442,27 @@ static void sub_81C1E20(u8 taskId) schedule_bg_copy_tilemap_to_vram(2); } -static void sub_81C1EFC(u16 a, s16 b, u16 move) +static void HandleAppealJamTilemap(u16 a, s16 b, u16 move) { - if (b > sUnknown_0861CC10.field_6) - b = sUnknown_0861CC10.field_6; - if (b == 0 || b == sUnknown_0861CC10.field_6) - sub_81C1CB0(&sUnknown_0861CC10, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], b, 1); + if (b > sContestMoveTilemapCtrl.field_6) + b = sContestMoveTilemapCtrl.field_6; + + if (b == 0 || b == sContestMoveTilemapCtrl.field_6) + { + ChangeTilemap(&sContestMoveTilemapCtrl, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], b, TRUE); + } else { - u8 taskId = FindTaskIdByFunc(sub_81C1F80); + u8 taskId = FindTaskIdByFunc(Task_ShowAppealJamWindow); if (taskId == 0xFF) - taskId = CreateTask(sub_81C1F80, 8); + taskId = CreateTask(Task_ShowAppealJamWindow, 8); gTasks[taskId].data[0] = b; gTasks[taskId].data[1] = a; gTasks[taskId].data[2] = move; } } -static void sub_81C1F80(u8 taskId) +static void Task_ShowAppealJamWindow(u8 taskId) { s16 *data = gTasks[taskId].data; data[1] += data[0]; @@ -2461,12 +2470,12 @@ static void sub_81C1F80(u8 taskId) { data[1] = 0; } - else if (data[1] > sUnknown_0861CC10.field_6) + else if (data[1] > sContestMoveTilemapCtrl.field_6) { - data[1] = sUnknown_0861CC10.field_6; + data[1] = sContestMoveTilemapCtrl.field_6; } - sub_81C1CB0(&sUnknown_0861CC10, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], data[1], 1); - if (data[1] <= 0 || data[1] >= sUnknown_0861CC10.field_6) + ChangeTilemap(&sContestMoveTilemapCtrl, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][0], data[1], TRUE); + if (data[1] <= 0 || data[1] >= sContestMoveTilemapCtrl.field_6) { if (data[0] < 0) { @@ -2476,7 +2485,7 @@ static void sub_81C1F80(u8 taskId) } else { - if (!gSprites[sMonSummaryScreen->spriteIds[2]].invisible) + if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) { PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS); } @@ -2489,35 +2498,35 @@ static void sub_81C1F80(u8 taskId) schedule_bg_copy_tilemap_to_vram(2); } -static void sub_81C2074(u16 a, s16 b) +static void HandleStatusTilemap(u16 a, s16 b) { - if (b > sUnknown_0861CBEC.field_6) - b = sUnknown_0861CBEC.field_6; - if (b == 0 || b == sUnknown_0861CBEC.field_6) + if (b > sStatusTilemapCtrl1.field_6) + b = sStatusTilemapCtrl1.field_6; + if (b == 0 || b == sStatusTilemapCtrl1.field_6) { - sub_81C1CB0(&sUnknown_0861CBEC, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], b, 0); - sub_81C1CB0(&sUnknown_0861CBF8, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], b, 0); + ChangeTilemap(&sStatusTilemapCtrl1, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], b, FALSE); + ChangeTilemap(&sStatusTilemapCtrl2, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], b, FALSE); } else { - u8 taskId = CreateTask(sub_81C20F0, 8); + u8 taskId = CreateTask(Task_ShowStatusWindow, 8); gTasks[taskId].data[0] = b; gTasks[taskId].data[1] = a; } } -static void sub_81C20F0(u8 taskId) +static void Task_ShowStatusWindow(u8 taskId) { s16 *data = gTasks[taskId].data; data[1] += data[0]; if (data[1] < 0) data[1] = 0; - else if (data[1] > sUnknown_0861CBEC.field_6) - data[1] = sUnknown_0861CBEC.field_6; - sub_81C1CB0(&sUnknown_0861CBEC, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], data[1], 0); - sub_81C1CB0(&sUnknown_0861CBF8, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], data[1], 0); + else if (data[1] > sStatusTilemapCtrl1.field_6) + data[1] = sStatusTilemapCtrl1.field_6; + ChangeTilemap(&sStatusTilemapCtrl1, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], data[1], FALSE); + ChangeTilemap(&sStatusTilemapCtrl2, sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_INFO][0], data[1], FALSE); schedule_bg_copy_tilemap_to_vram(3); - if (data[1] <= 0 || data[1] >= sUnknown_0861CBEC.field_6) + if (data[1] <= 0 || data[1] >= sStatusTilemapCtrl1.field_6) { if (data[0] < 0) { @@ -2529,30 +2538,28 @@ static void sub_81C20F0(u8 taskId) } } -static void sub_81C2194(u16 *output, u16 palette, bool8 c) +static void TilemapFiveMovesDisplay(u16 *dst, u16 palette, bool8 remove) { - u16 i; - u32 var; + u16 i, id; palette *= 0x1000; - var = 0x56A; - - if (c == 0) + id = 0x56A; + if (!remove) { for (i = 0; i < 20; i++) { - output[var + i] = gSummaryScreenWindow_Tilemap[i] + palette; - output[var + i + 0x20] = gSummaryScreenWindow_Tilemap[i] + palette; - output[var + i + 0x40] = gSummaryScreenWindow_Tilemap[i + 20] + palette; + dst[id + i] = gSummaryScreenWindow_Tilemap[i] + palette; + dst[id + i + 0x20] = gSummaryScreenWindow_Tilemap[i] + palette; + dst[id + i + 0x40] = gSummaryScreenWindow_Tilemap[i + 20] + palette; } } - else + else // Remove { for (i = 0; i < 20; i++) { - output[var + i] = gSummaryScreenWindow_Tilemap[i + 20] + palette; - output[var + i + 0x20] = gSummaryScreenWindow_Tilemap[i + 40] + palette; - output[var + i + 0x40] = gSummaryScreenWindow_Tilemap[i + 40] + palette; + dst[id + i] = gSummaryScreenWindow_Tilemap[i + 20] + palette; + dst[id + i + 0x20] = gSummaryScreenWindow_Tilemap[i + 40] + palette; + dst[id + i + 0x40] = gSummaryScreenWindow_Tilemap[i + 40] + palette; } } } @@ -2585,7 +2592,7 @@ static void DrawExperienceProgressBar(struct Pokemon *unused) { s64 numExpProgressBarTicks; struct PokeSummary *summary = &sMonSummaryScreen->summary; - u16 *r9; + u16 *dst; u8 i; if (summary->level < MAX_LEVEL) @@ -2605,13 +2612,13 @@ static void DrawExperienceProgressBar(struct Pokemon *unused) numExpProgressBarTicks = 0; } - r9 = &sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_SKILLS][1][0x255]; + dst = &sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_SKILLS][1][0x255]; for (i = 0; i < 8; i++) { if (numExpProgressBarTicks > 7) - r9[i] = 0x206A; + dst[i] = 0x206A; else - r9[i] = 0x2062 + (numExpProgressBarTicks % 8); + dst[i] = 0x2062 + (numExpProgressBarTicks % 8); numExpProgressBarTicks -= 8; if (numExpProgressBarTicks < 0) numExpProgressBarTicks = 0; @@ -2627,25 +2634,19 @@ static void DrawContestMoveHearts(u16 move) { u16 *tilemap = sMonSummaryScreen->bgTilemapBuffers[PSS_PAGE_CONTEST_MOVES][1]; u8 i; - u8 effectValue; if (move != MOVE_NONE) { - effectValue = gContestEffects[gContestMoves[move].effect].appeal; - + u8 effectValue = gContestEffects[gContestMoves[move].effect].appeal; if (effectValue != 0xFF) effectValue /= 10; for (i = 0; i < 8; i++) { if (effectValue != 0xFF && i < effectValue) - { tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = 0x103A; - } else - { tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = 0x1039; - } } effectValue = gContestEffects[gContestMoves[move].effect].jam; @@ -2656,13 +2657,9 @@ static void DrawContestMoveHearts(u16 move) for (i = 0; i < 8; i++) { if (effectValue != 0xFF && i < effectValue) - { tilemap[(i / 4 * 32) + (i & 3) + 0x226] = 0x103C; - } else - { tilemap[(i / 4 * 32) + (i & 3) + 0x226] = 0x103D; - } } } } @@ -2678,9 +2675,9 @@ static void LimitEggSummaryPageDisplay(void) // If the pokemon is an egg, limit static void ResetWindows(void) { u8 i; + InitWindows(sSummaryTemplate); DeactivateAllTextPrinters(); - for (i = 0; i < 20; i++) { FillWindowPixelBuffer(i, PIXEL_FILL(0)); @@ -2691,9 +2688,9 @@ static void ResetWindows(void) } } -static void SummaryScreen_PrintTextOnWindow(u8 windowId, const u8 *string, u8 x, u8 y, u8 lineSpacing, u8 colorId) +static void PrintTextOnWindow(u8 windowId, const u8 *string, u8 x, u8 y, u8 lineSpacing, u8 colorId) { - AddTextPrinterParameterized4(windowId, 1, x, y, 0, lineSpacing, sTextColors_861CD2C[colorId], 0, string); + AddTextPrinterParameterized4(windowId, 1, x, y, 0, lineSpacing, sTextColors[colorId], 0, string); } static void PrintMonInfo(void) @@ -2714,6 +2711,7 @@ static void PrintNotEggInfo(void) struct Pokemon *mon = &sMonSummaryScreen->currentMon; struct PokeSummary *summary = &sMonSummaryScreen->summary; u16 dexNum = SpeciesToPokedexNum(summary->species); + if (dexNum != 0xFFFF) { StringCopy(gStringVar1, &gText_NumberClear01[0]); @@ -2721,12 +2719,12 @@ static void PrintNotEggInfo(void) StringAppend(gStringVar1, gStringVar2); if (!IsMonShiny(mon)) { - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_DEX_NUMBER, gStringVar1, 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_DEX_NUMBER, gStringVar1, 0, 1, 0, 1); SetDexNumberColor(FALSE); } else { - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_DEX_NUMBER, gStringVar1, 0, 1, 0, 7); + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_DEX_NUMBER, gStringVar1, 0, 1, 0, 7); SetDexNumberColor(TRUE); } PutWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_DEX_NUMBER); @@ -2739,15 +2737,15 @@ static void PrintNotEggInfo(void) else SetDexNumberColor(TRUE); } - StringCopy(gStringVar1, &gText_LevelSymbol[0]); + StringCopy(gStringVar1, gText_LevelSymbol); ConvertIntToDecimalStringN(gStringVar2, summary->level, STR_CONV_MODE_LEFT_ALIGN, 3); StringAppend(gStringVar1, gStringVar2); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, gStringVar1, 0x18, 17, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, gStringVar1, 24, 17, 0, 1); GetMonNickname(mon, gStringVar1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_NICKNAME, gStringVar1, 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_NICKNAME, gStringVar1, 0, 1, 0, 1); strArray[0] = CHAR_SLASH; StringCopy(&strArray[1], &gSpeciesNames[summary->species2][0]); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, &strArray[0], 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, strArray, 0, 1, 0, 1); PrintGenderSymbol(mon, summary->species2); PutWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_NICKNAME); PutWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); @@ -2756,7 +2754,7 @@ static void PrintNotEggInfo(void) static void PrintEggInfo(void) { GetMonNickname(&sMonSummaryScreen->currentMon, gStringVar1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_NICKNAME, gStringVar1, 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_NICKNAME, gStringVar1, 0, 1, 0, 1); PutWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_NICKNAME); ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_DEX_NUMBER); ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); @@ -2766,15 +2764,14 @@ static void PrintGenderSymbol(struct Pokemon *mon, u16 species) { if (species != SPECIES_NIDORAN_M && species != SPECIES_NIDORAN_F) { - u8 gender = GetMonGender(mon); - switch (gender) + switch (GetMonGender(mon)) { - case MON_MALE: - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, gText_MaleSymbol, 57, 17, 0, 3); - break; - case MON_FEMALE: - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, gText_FemaleSymbol, 57, 17, 0, 4); - break; + case MON_MALE: + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, gText_MaleSymbol, 57, 17, 0, 3); + break; + case MON_FEMALE: + PrintTextOnWindow(PSS_LABEL_WINDOW_PORTRAIT_SPECIES, gText_FemaleSymbol, 57, 17, 0, 4); + break; } } } @@ -2785,62 +2782,62 @@ static void PrintAOrBButtonIcon(u8 windowId, bool8 bButton, u32 x) BlitBitmapToWindow(windowId, (bButton) ? sSummaryBButtonBitmap : sSummaryBButtonBitmap - 0x80, x, 0, 16, 16); } -static void PrintPageNamesAndStatsPageToWindows(void) +static void PrintPageNamesAndStats(void) { int stringXPos; int iconXPos; int statsXPos; - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_INFO_TITLE, gText_PkmnInfo, 2, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_TITLE, gText_PkmnSkills, 2, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_BATTLE_MOVES_TITLE, gText_BattleMoves, 2, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_CONTEST_MOVES_TITLE, gText_ContestMoves, 2, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_INFO_TITLE, gText_PkmnInfo, 2, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_TITLE, gText_PkmnSkills, 2, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_BATTLE_MOVES_TITLE, gText_BattleMoves, 2, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_CONTEST_MOVES_TITLE, gText_ContestMoves, 2, 1, 0, 1); stringXPos = GetStringRightAlignXOffset(1, gText_Cancel2, 62); iconXPos = stringXPos - 16; if (iconXPos < 0) iconXPos = 0; PrintAOrBButtonIcon(PSS_LABEL_WINDOW_PROMPT_CANCEL, FALSE, iconXPos); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PROMPT_CANCEL, gText_Cancel2, stringXPos, 1, 0, 0); + PrintTextOnWindow(PSS_LABEL_WINDOW_PROMPT_CANCEL, gText_Cancel2, stringXPos, 1, 0, 0); - stringXPos = GetStringRightAlignXOffset(1, gText_Info, 0x3E); + stringXPos = GetStringRightAlignXOffset(1, gText_Info, 62); iconXPos = stringXPos - 16; if (iconXPos < 0) iconXPos = 0; PrintAOrBButtonIcon(PSS_LABEL_WINDOW_PROMPT_INFO, FALSE, iconXPos); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PROMPT_INFO, gText_Info, stringXPos, 1, 0, 0); + PrintTextOnWindow(PSS_LABEL_WINDOW_PROMPT_INFO, gText_Info, stringXPos, 1, 0, 0); - stringXPos = GetStringRightAlignXOffset(1, gText_Switch, 0x3E); + stringXPos = GetStringRightAlignXOffset(1, gText_Switch, 62); iconXPos = stringXPos - 16; if (iconXPos < 0) iconXPos = 0; PrintAOrBButtonIcon(PSS_LABEL_WINDOW_PROMPT_SWITCH, FALSE, iconXPos); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_PROMPT_SWITCH, gText_Switch, stringXPos, 1, 0, 0); + PrintTextOnWindow(PSS_LABEL_WINDOW_PROMPT_SWITCH, gText_Switch, stringXPos, 1, 0, 0); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_INFO_RENTAL, gText_RentalPkmn, 0, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_INFO_TYPE, gText_TypeSlash, 0, 1, 0, 0); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_INFO_RENTAL, gText_RentalPkmn, 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_INFO_TYPE, gText_TypeSlash, 0, 1, 0, 0); statsXPos = 6 + GetStringCenterAlignXOffset(1, gText_HP4, 42); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT, gText_HP4, statsXPos, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT, gText_HP4, statsXPos, 1, 0, 1); statsXPos = 6 + GetStringCenterAlignXOffset(1, gText_Attack3, 42); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT, gText_Attack3, statsXPos, 17, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT, gText_Attack3, statsXPos, 17, 0, 1); statsXPos = 6 + GetStringCenterAlignXOffset(1, gText_Defense3, 42); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT, gText_Defense3, statsXPos, 33, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT, gText_Defense3, statsXPos, 33, 0, 1); statsXPos = 2 + GetStringCenterAlignXOffset(1, gText_SpAtk4, 36); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT, gText_SpAtk4, statsXPos, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT, gText_SpAtk4, statsXPos, 1, 0, 1); statsXPos = 2 + GetStringCenterAlignXOffset(1, gText_SpDef4, 36); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT, gText_SpDef4, statsXPos, 17, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT, gText_SpDef4, statsXPos, 17, 0, 1); statsXPos = 2 + GetStringCenterAlignXOffset(1, gText_Speed2, 36); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT, gText_Speed2, statsXPos, 33, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP, gText_ExpPoints, 6, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP, gText_NextLv, 6, 17, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS, gText_Status, 2, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, gText_Power, 0, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, gText_Accuracy2, 0, 17, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM, gText_Appeal, 0, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM, gText_Jam, 0, 17, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT, gText_Speed2, statsXPos, 33, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP, gText_ExpPoints, 6, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP, gText_NextLv, 6, 17, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATUS, gText_Status, 2, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, gText_Power, 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, gText_Accuracy2, 0, 17, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM, gText_Appeal, 0, 1, 0, 1); + PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM, gText_Jam, 0, 17, 0, 1); } -static void CreatePageWindowTilemaps(u8 page) +static void PutPageWindowTilemaps(u8 page) { u8 i; @@ -2851,49 +2848,47 @@ static void CreatePageWindowTilemaps(u8 page) switch (page) { - case PSS_PAGE_INFO: - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_TITLE); - PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_CANCEL); - if (InBattleFactory() == TRUE || InSlateportBattleTent() == TRUE) - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_RENTAL); - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_TYPE); - break; - case PSS_PAGE_SKILLS: - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_TITLE); - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT); - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT); - PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP); - break; - case PSS_PAGE_BATTLE_MOVES: - PutWindowTilemap(PSS_LABEL_WINDOW_BATTLE_MOVES_TITLE); - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) - PutWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); - } - else - { - PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); - } - break; - case PSS_PAGE_CONTEST_MOVES: - PutWindowTilemap(PSS_LABEL_WINDOW_CONTEST_MOVES_TITLE); - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) - PutWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); - } - else - { - PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); - } - break; + case PSS_PAGE_INFO: + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_TITLE); + PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_CANCEL); + if (InBattleFactory() == TRUE || InSlateportBattleTent() == TRUE) + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_RENTAL); + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_TYPE); + break; + case PSS_PAGE_SKILLS: + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_TITLE); + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT); + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT); + PutWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP); + break; + case PSS_PAGE_BATTLE_MOVES: + PutWindowTilemap(PSS_LABEL_WINDOW_BATTLE_MOVES_TITLE); + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) + PutWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); + } + else + { + PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); + } + break; + case PSS_PAGE_CONTEST_MOVES: + PutWindowTilemap(PSS_LABEL_WINDOW_CONTEST_MOVES_TITLE); + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) + PutWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); + } + else + { + PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); + } + break; } for (i = 0; i < ARRAY_COUNT(sMonSummaryScreen->windowIds); i++) - { PutWindowTilemap(sMonSummaryScreen->windowIds[i]); - } schedule_bg_copy_tilemap_to_vram(0); } @@ -2901,54 +2896,53 @@ static void CreatePageWindowTilemaps(u8 page) static void ClearPageWindowTilemaps(u8 page) { u8 i; + switch (page) { - case PSS_PAGE_INFO: - ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_CANCEL); - if (InBattleFactory() == TRUE || InSlateportBattleTent() == TRUE) - ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_RENTAL); - ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_TYPE); - break; - case PSS_PAGE_SKILLS: - ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT); - ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT); - ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP); - break; - case PSS_PAGE_BATTLE_MOVES: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) - ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); - } - else - { - ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); - } - break; - case PSS_PAGE_CONTEST_MOVES: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) - ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); - } - else - { - ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); - } - break; + case PSS_PAGE_INFO: + ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_CANCEL); + if (InBattleFactory() == TRUE || InSlateportBattleTent() == TRUE) + ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_RENTAL); + ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_INFO_TYPE); + break; + case PSS_PAGE_SKILLS: + ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_LEFT); + ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_STATS_RIGHT); + ClearWindowTilemap(PSS_LABEL_WINDOW_POKEMON_SKILLS_EXP); + break; + case PSS_PAGE_BATTLE_MOVES: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) + ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_POWER_ACC); + } + else + { + ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); + } + break; + case PSS_PAGE_CONTEST_MOVES: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) + ClearWindowTilemap(PSS_LABEL_WINDOW_MOVES_APPEAL_JAM); + } + else + { + ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); + } + break; } for (i = 0; i < ARRAY_COUNT(sMonSummaryScreen->windowIds); i++) - { - SummaryScreen_RemoveWindowByIndex(i); - } + RemoveWindowByIndex(i); schedule_bg_copy_tilemap_to_vram(0); } static u8 AddWindowFromTemplateList(const struct WindowTemplate *template, u8 templateId) { - u8 *windowIdPtr = &(sMonSummaryScreen->windowIds[templateId]); + u8 *windowIdPtr = &sMonSummaryScreen->windowIds[templateId]; if (*windowIdPtr == 0xFF) { *windowIdPtr = AddWindow(&template[templateId]); @@ -2957,9 +2951,9 @@ static u8 AddWindowFromTemplateList(const struct WindowTemplate *template, u8 te return *windowIdPtr; } -static void SummaryScreen_RemoveWindowByIndex(u8 windowIndex) +static void RemoveWindowByIndex(u8 windowIndex) { - u8 *windowIdPtr = &(sMonSummaryScreen->windowIds[windowIndex]); + u8 *windowIdPtr = &sMonSummaryScreen->windowIds[windowIndex]; if (*windowIdPtr != 0xFF) { ClearWindowTilemap(*windowIdPtr); @@ -3009,44 +3003,43 @@ static void Task_PrintInfoPage(u8 taskId) s16 *data = gTasks[taskId].data; switch (data[0]) { - case 1: - PrintMonOTName(); - break; - case 2: - PrintMonOTID(); - break; - case 3: - PrintMonAbilityName(); - break; - case 4: - PrintMonAbilityDescription(); - break; - case 5: - BufferMonTrainerMemo(); - break; - case 6: - PrintMonTrainerMemo(); - break; - case 7: - DestroyTask(taskId); - return; + case 1: + PrintMonOTName(); + break; + case 2: + PrintMonOTID(); + break; + case 3: + PrintMonAbilityName(); + break; + case 4: + PrintMonAbilityDescription(); + break; + case 5: + BufferMonTrainerMemo(); + break; + case 6: + PrintMonTrainerMemo(); + break; + case 7: + DestroyTask(taskId); + return; } data[0]++; } static void PrintMonOTName(void) { - u8 windowId; - int x; + int x, windowId; if (InBattleFactory() != TRUE && InSlateportBattleTent() != TRUE) { windowId = AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ORIGINAL_TRAINER); - SummaryScreen_PrintTextOnWindow(windowId, gText_OTSlash, 0, 1, 0, 1); + PrintTextOnWindow(windowId, gText_OTSlash, 0, 1, 0, 1); x = GetStringWidth(1, gText_OTSlash, 0); if (sMonSummaryScreen->summary.OTGender == 0) - SummaryScreen_PrintTextOnWindow(windowId, sMonSummaryScreen->summary.OTName, x, 1, 0, 5); + PrintTextOnWindow(windowId, sMonSummaryScreen->summary.OTName, x, 1, 0, 5); else - SummaryScreen_PrintTextOnWindow(windowId, sMonSummaryScreen->summary.OTName, x, 1, 0, 6); + PrintTextOnWindow(windowId, sMonSummaryScreen->summary.OTName, x, 1, 0, 6); } } @@ -3057,20 +3050,20 @@ static void PrintMonOTID(void) { ConvertIntToDecimalStringN(StringCopy(gStringVar1, gText_IDNumber2), (u16)sMonSummaryScreen->summary.OTID, STR_CONV_MODE_LEADING_ZEROS, 5); xPos = GetStringRightAlignXOffset(1, gStringVar1, 56); - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ID), gStringVar1, xPos, 1, 0, 1); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ID), gStringVar1, xPos, 1, 0, 1); } } static void PrintMonAbilityName(void) { u8 ability = GetAbilityBySpecies(sMonSummaryScreen->summary.species, sMonSummaryScreen->summary.abilityNum); - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ABILITY), gAbilityNames[ability], 0, 1, 0, 1); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ABILITY), gAbilityNames[ability], 0, 1, 0, 1); } static void PrintMonAbilityDescription(void) { u8 ability = GetAbilityBySpecies(sMonSummaryScreen->summary.species, sMonSummaryScreen->summary.abilityNum); - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ABILITY), gAbilityDescriptionPointers[ability], 0, 17, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ABILITY), gAbilityDescriptionPointers[ability], 0, 17, 0, 0); } static void BufferMonTrainerMemo(void) @@ -3127,7 +3120,7 @@ static void BufferMonTrainerMemo(void) static void PrintMonTrainerMemo(void) { - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_MEMO), gStringVar4, 0, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_MEMO), gStringVar4, 0, 1, 0, 0); } static void BufferNatureString(void) @@ -3155,7 +3148,7 @@ static bool8 DoesMonOTMatchOwner(void) if (sMonSummaryScreen->monList.mons == gEnemyParty) { u8 multiID = GetMultiplayerId() ^ 1; - trainerId = (u16)gLinkPlayers[multiID].trainerId; + trainerId = gLinkPlayers[multiID].trainerId & 0xFFFF; gender = gLinkPlayers[multiID].gender; StringCopy(gStringVar1, gLinkPlayers[multiID].name); } @@ -3165,11 +3158,11 @@ static bool8 DoesMonOTMatchOwner(void) gender = gSaveBlock2Ptr->playerGender; StringCopy(gStringVar1, gSaveBlock2Ptr->playerName); } + if (gender != sum->OTGender || trainerId != (sum->OTID & 0xFFFF) || StringCompareWithoutExtCtrlCodes(gStringVar1, sum->OTName)) - { return FALSE; - } - return TRUE; + else + return TRUE; } static bool8 DidMonComeFromGBAGames(void) @@ -3202,8 +3195,8 @@ static void PrintEggOTName(void) { u32 windowId = AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ORIGINAL_TRAINER); u32 width = GetStringWidth(1, gText_OTSlash, 0); - SummaryScreen_PrintTextOnWindow(windowId, gText_OTSlash, 0, 1, 0, 1); - SummaryScreen_PrintTextOnWindow(windowId, gText_FiveMarks, width, 1, 0, 1); + PrintTextOnWindow(windowId, gText_OTSlash, 0, 1, 0, 1); + PrintTextOnWindow(windowId, gText_FiveMarks, width, 1, 0, 1); } static void PrintEggOTID(void) @@ -3212,7 +3205,7 @@ static void PrintEggOTID(void) StringCopy(gStringVar1, gText_IDNumber2); StringAppend(gStringVar1, gText_FiveMarks); x = GetStringRightAlignXOffset(1, gStringVar1, 56); - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ID), gStringVar1, x, 1, 0, 1); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ID), gStringVar1, x, 1, 0, 1); } static void PrintEggState(void) @@ -3231,7 +3224,7 @@ static void PrintEggState(void) else text = gText_EggWillTakeALongTime; - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ABILITY), text, 0, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_ABILITY), text, 0, 1, 0, 0); } static void PrintEggMemo(void) @@ -3255,7 +3248,7 @@ static void PrintEggMemo(void) text = gText_OddEggFoundByCouple; } - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_MEMO), text, 0, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageInfoTemplate, PSS_DATA_WINDOW_INFO_MEMO), text, 0, 1, 0, 0); } static void PrintSkillsPageText(void) @@ -3275,30 +3268,30 @@ static void Task_PrintSkillsPage(u8 taskId) switch (data[0]) { - case 1: - PrintHeldItemName(); - break; - case 2: - PrintRibbonCount(); - break; - case 3: - BufferLeftColumnStats(); - break; - case 4: - PrintLeftColumnStats(); - break; - case 5: - BufferRightColumnStats(); - break; - case 6: - PrintRightColumnStats(); - break; - case 7: - PrintExpPointsNextLevel(); - break; - case 8: - DestroyTask(taskId); - return; + case 1: + PrintHeldItemName(); + break; + case 2: + PrintRibbonCount(); + break; + case 3: + BufferLeftColumnStats(); + break; + case 4: + PrintLeftColumnStats(); + break; + case 5: + BufferRightColumnStats(); + break; + case 6: + PrintRightColumnStats(); + break; + case 7: + PrintExpPointsNextLevel(); + break; + case 8: + DestroyTask(taskId); + return; } data[0]++; } @@ -3308,7 +3301,9 @@ static void PrintHeldItemName(void) const u8 *text; int offset; - if (sMonSummaryScreen->summary.item == ITEM_ENIGMA_BERRY && IsMultiBattle() == TRUE && (sMonSummaryScreen->curMonIndex == 1 || sMonSummaryScreen->curMonIndex == 4 || sMonSummaryScreen->curMonIndex == 5)) + if (sMonSummaryScreen->summary.item == ITEM_ENIGMA_BERRY + && IsMultiBattle() == TRUE + && (sMonSummaryScreen->curMonIndex == 1 || sMonSummaryScreen->curMonIndex == 4 || sMonSummaryScreen->curMonIndex == 5)) { text = ItemId_GetName(ITEM_ENIGMA_BERRY); } @@ -3323,7 +3318,7 @@ static void PrintHeldItemName(void) } offset = GetStringCenterAlignXOffset(1, text, 72) + 6; - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_HELD_ITEM), text, offset, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_HELD_ITEM), text, offset, 1, 0, 0); } static void PrintRibbonCount(void) @@ -3343,7 +3338,7 @@ static void PrintRibbonCount(void) } offset = GetStringCenterAlignXOffset(1, text, 70) + 6; - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_RIBBON_COUNT), text, offset, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_RIBBON_COUNT), text, offset, 1, 0, 0); } static void BufferLeftColumnStats(void) @@ -3373,7 +3368,7 @@ static void BufferLeftColumnStats(void) static void PrintLeftColumnStats(void) { - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_STATS_LEFT), gStringVar4, 4, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_STATS_LEFT), gStringVar4, 4, 1, 0, 0); } static void BufferRightColumnStats(void) @@ -3391,19 +3386,19 @@ static void BufferRightColumnStats(void) static void PrintRightColumnStats(void) { - SummaryScreen_PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_STATS_RIGHT), gStringVar4, 2, 1, 0, 0); + PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_STATS_RIGHT), gStringVar4, 2, 1, 0, 0); } static void PrintExpPointsNextLevel(void) { struct PokeSummary *sum = &sMonSummaryScreen->summary; u8 windowId = AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_EXP); - int offset; + int x; u32 expToNextLevel; ConvertIntToDecimalStringN(gStringVar1, sum->exp, STR_CONV_MODE_RIGHT_ALIGN, 7); - offset = GetStringRightAlignXOffset(1, gStringVar1, 42) + 2; - SummaryScreen_PrintTextOnWindow(windowId, gStringVar1, offset, 1, 0, 0); + x = GetStringRightAlignXOffset(1, gStringVar1, 42) + 2; + PrintTextOnWindow(windowId, gStringVar1, x, 1, 0, 0); if (sum->level < MAX_LEVEL) expToNextLevel = gExperienceTables[gBaseStats[sum->species].growthRate][sum->level + 1] - sum->exp; @@ -3411,8 +3406,8 @@ static void PrintExpPointsNextLevel(void) expToNextLevel = 0; ConvertIntToDecimalStringN(gStringVar1, expToNextLevel, STR_CONV_MODE_RIGHT_ALIGN, 6); - offset = GetStringRightAlignXOffset(1, gStringVar1, 42) + 2; - SummaryScreen_PrintTextOnWindow(windowId, gStringVar1, offset, 17, 0, 0); + x = GetStringRightAlignXOffset(1, gStringVar1, 42) + 2; + PrintTextOnWindow(windowId, gStringVar1, x, 17, 0, 0); } static void PrintBattleMoves(void) @@ -3443,41 +3438,41 @@ static void Task_PrintBattleMoves(u8 taskId) switch (data[0]) { - case 1: - PrintMoveNameAndPP(0); - break; - case 2: - PrintMoveNameAndPP(1); - break; - case 3: - PrintMoveNameAndPP(2); - break; - case 4: - PrintMoveNameAndPP(3); - break; - case 5: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - PrintNewMoveDetailsOrCancelText(); - break; - case 6: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES) - data[1] = sMonSummaryScreen->newMove; - else - data[1] = sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]; - } - break; - case 7: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) - PrintMoveDetails(data[1]); - } - break; - case 8: - DestroyTask(taskId); - return; + case 1: + PrintMoveNameAndPP(0); + break; + case 2: + PrintMoveNameAndPP(1); + break; + case 3: + PrintMoveNameAndPP(2); + break; + case 4: + PrintMoveNameAndPP(3); + break; + case 5: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + PrintNewMoveDetailsOrCancelText(); + break; + case 6: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES) + data[1] = sMonSummaryScreen->newMove; + else + data[1] = sMonSummaryScreen->summary.moves[sMonSummaryScreen->firstMoveIndex]; + } + break; + case 7: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) + PrintMoveDetails(data[1]); + } + break; + case 8: + DestroyTask(taskId); + return; } data[0]++; } @@ -3485,37 +3480,36 @@ static void Task_PrintBattleMoves(u8 taskId) static void PrintMoveNameAndPP(u8 moveIndex) { u8 pp; - u32 ppState; + int ppState, x; const u8 *text; - u32 offset; - struct PokemonSummaryScreenData *summaryStruct = sMonSummaryScreen; + struct PokeSummary *summary = &sMonSummaryScreen->summary; u8 moveNameWindowId = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_NAMES); u8 ppValueWindowId = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_PP); - u16 move = summaryStruct->summary.moves[moveIndex]; + u16 move = summary->moves[moveIndex]; if (move != 0) { - pp = CalculatePPWithBonus(move, summaryStruct->summary.ppBonuses, moveIndex); - SummaryScreen_PrintTextOnWindow(moveNameWindowId, gMoveNames[move], 0, moveIndex * 16 + 1, 0, 1); - ConvertIntToDecimalStringN(gStringVar1, summaryStruct->summary.pp[moveIndex], STR_CONV_MODE_RIGHT_ALIGN, 2); + pp = CalculatePPWithBonus(move, summary->ppBonuses, moveIndex); + PrintTextOnWindow(moveNameWindowId, gMoveNames[move], 0, moveIndex * 16 + 1, 0, 1); + ConvertIntToDecimalStringN(gStringVar1, summary->pp[moveIndex], STR_CONV_MODE_RIGHT_ALIGN, 2); ConvertIntToDecimalStringN(gStringVar2, pp, STR_CONV_MODE_RIGHT_ALIGN, 2); DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStringVar1); DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, gStringVar2); DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar4, sMovesPPLayout); text = gStringVar4; - ppState = GetCurrentPpToMaxPpState(summaryStruct->summary.pp[moveIndex], pp) + 9; - offset = GetStringRightAlignXOffset(1, text, 44); + ppState = GetCurrentPpToMaxPpState(summary->pp[moveIndex], pp) + 9; + x = GetStringRightAlignXOffset(1, text, 44); } else { - SummaryScreen_PrintTextOnWindow(moveNameWindowId, gText_OneDash, 0, moveIndex * 16 + 1, 0, 1); + PrintTextOnWindow(moveNameWindowId, gText_OneDash, 0, moveIndex * 16 + 1, 0, 1); text = gText_TwoDashes; ppState = 12; - offset = GetStringCenterAlignXOffset(1, text, 44); + x = GetStringCenterAlignXOffset(1, text, 44); } - SummaryScreen_PrintTextOnWindow(ppValueWindowId, text, offset, moveIndex * 16 + 1, 0, ppState); + PrintTextOnWindow(ppValueWindowId, text, x, moveIndex * 16 + 1, 0, ppState); } static void PrintMovePowerAndAccuracy(u16 moveIndex) @@ -3535,7 +3529,7 @@ static void PrintMovePowerAndAccuracy(u16 moveIndex) text = gStringVar1; } - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, text, 53, 1, 0, 0); + PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, text, 53, 1, 0, 0); if (gBattleMoves[moveIndex].accuracy == 0) { @@ -3547,7 +3541,7 @@ static void PrintMovePowerAndAccuracy(u16 moveIndex) text = gStringVar1; } - SummaryScreen_PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, text, 53, 17, 0, 0); + PrintTextOnWindow(PSS_LABEL_WINDOW_MOVES_POWER_ACC, text, 53, 17, 0, 0); } } @@ -3568,36 +3562,35 @@ static void PrintContestMoves(void) static void Task_PrintContestMoves(u8 taskId) { s16 *data = gTasks[taskId].data; - s16 dataa = data[0] - 1; - switch (dataa) + switch (data[0]) { - case 0: - PrintMoveNameAndPP(0); - break; - case 1: - PrintMoveNameAndPP(1); - break; - case 2: - PrintMoveNameAndPP(2); - break; - case 3: - PrintMoveNameAndPP(3); - break; - case 4: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - PrintNewMoveDetailsOrCancelText(); - break; - case 5: - if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) - { - if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) - PrintContestMoveDescription(sMonSummaryScreen->firstMoveIndex); - } - break; - case 6: - DestroyTask(taskId); - return; + case 1: + PrintMoveNameAndPP(0); + break; + case 2: + PrintMoveNameAndPP(1); + break; + case 3: + PrintMoveNameAndPP(2); + break; + case 4: + PrintMoveNameAndPP(3); + break; + case 5: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + PrintNewMoveDetailsOrCancelText(); + break; + case 6: + if (sMonSummaryScreen->mode == PSS_MODE_SELECT_MOVE) + { + if (sMonSummaryScreen->newMove != MOVE_NONE || sMonSummaryScreen->firstMoveIndex != MAX_MON_MOVES) + PrintContestMoveDescription(sMonSummaryScreen->firstMoveIndex); + } + break; + case 7: + DestroyTask(taskId); + return; } data[0]++; } @@ -3614,7 +3607,7 @@ static void PrintContestMoveDescription(u8 moveSlot) if (move != MOVE_NONE) { u8 windowId = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_DESCRIPTION); - SummaryScreen_PrintTextOnWindow(windowId, gContestEffectDescriptionPointers[gContestMoves[move].effect], 6, 1, 0, 0); + PrintTextOnWindow(windowId, gContestEffectDescriptionPointers[gContestMoves[move].effect], 6, 1, 0, 0); } } @@ -3627,11 +3620,11 @@ static void PrintMoveDetails(u16 move) if (sMonSummaryScreen->currPageIndex == PSS_MODE_BOX) { PrintMovePowerAndAccuracy(move); - SummaryScreen_PrintTextOnWindow(windowId, gMoveDescriptionPointers[move - 1], 6, 1, 0, 0); + PrintTextOnWindow(windowId, gMoveDescriptionPointers[move - 1], 6, 1, 0, 0); } else { - SummaryScreen_PrintTextOnWindow(windowId, gContestEffectDescriptionPointers[gContestMoves[move].effect], 6, 1, 0, 0); + PrintTextOnWindow(windowId, gContestEffectDescriptionPointers[gContestMoves[move].effect], 6, 1, 0, 0); } PutWindowTilemap(windowId); } @@ -3650,43 +3643,43 @@ static void PrintNewMoveDetailsOrCancelText(void) if (sMonSummaryScreen->newMove == MOVE_NONE) { - SummaryScreen_PrintTextOnWindow(windowId1, gText_Cancel, 0, 65, 0, 1); + PrintTextOnWindow(windowId1, gText_Cancel, 0, 65, 0, 1); } else { u16 move = sMonSummaryScreen->newMove; - if (sMonSummaryScreen->currPageIndex == 2) - SummaryScreen_PrintTextOnWindow(windowId1, gMoveNames[move], 0, 65, 0, 6); + if (sMonSummaryScreen->currPageIndex == PSS_PAGE_BATTLE_MOVES) + PrintTextOnWindow(windowId1, gMoveNames[move], 0, 65, 0, 6); else - SummaryScreen_PrintTextOnWindow(windowId1, gMoveNames[move], 0, 65, 0, 5); + PrintTextOnWindow(windowId1, gMoveNames[move], 0, 65, 0, 5); ConvertIntToDecimalStringN(gStringVar1, gBattleMoves[move].pp, STR_CONV_MODE_RIGHT_ALIGN, 2); DynamicPlaceholderTextUtil_Reset(); DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStringVar1); DynamicPlaceholderTextUtil_SetPlaceholderPtr(1, gStringVar1); DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar4, sMovesPPLayout); - SummaryScreen_PrintTextOnWindow(windowId2, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 0x2C), 0x41, 0, 12); + PrintTextOnWindow(windowId2, gStringVar4, GetStringRightAlignXOffset(1, gStringVar4, 44), 65, 0, 12); } } -static void sub_81C4064(void) +static void AddAndFillMoveNamesWindow(void) { u8 windowId = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_NAMES); FillWindowPixelRect(windowId, PIXEL_FILL(0), 0, 66, 72, 16); CopyWindowToVram(windowId, 2); } -static void sub_81C40A0(u8 moveIndex1, u8 moveIndex2) +static void SwapMovesNamesPP(u8 moveIndex1, u8 moveIndex2) { u8 windowId1 = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_NAMES); u8 windowId2 = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_PP); - FillWindowPixelRect(windowId1, PIXEL_FILL(0), 0, moveIndex1 * 16, 0x48, 0x10); - FillWindowPixelRect(windowId1, PIXEL_FILL(0), 0, moveIndex2 * 16, 0x48, 0x10); + FillWindowPixelRect(windowId1, PIXEL_FILL(0), 0, moveIndex1 * 16, 72, 16); + FillWindowPixelRect(windowId1, PIXEL_FILL(0), 0, moveIndex2 * 16, 72, 16); - FillWindowPixelRect(windowId2, PIXEL_FILL(0), 0, moveIndex1 * 16, 0x30, 0x10); - FillWindowPixelRect(windowId2, PIXEL_FILL(0), 0, moveIndex2 * 16, 0x30, 0x10); + FillWindowPixelRect(windowId2, PIXEL_FILL(0), 0, moveIndex1 * 16, 48, 16); + FillWindowPixelRect(windowId2, PIXEL_FILL(0), 0, moveIndex2 * 16, 48, 16); PrintMoveNameAndPP(moveIndex1); PrintMoveNameAndPP(moveIndex2); @@ -3696,7 +3689,7 @@ static void PrintHMMovesCantBeForgotten(void) { u8 windowId = AddWindowFromTemplateList(sPageMovesTemplate, PSS_DATA_WINDOW_MOVE_DESCRIPTION); FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); - SummaryScreen_PrintTextOnWindow(windowId, gText_HMMovesCantBeForgotten2, 6, 1, 0, 0); + PrintTextOnWindow(windowId, gText_HMMovesCantBeForgotten2, 6, 1, 0, 0); } static void ResetSpriteIds(void) @@ -3704,9 +3697,7 @@ static void ResetSpriteIds(void) u8 i; for (i = 0; i < ARRAY_COUNT(sMonSummaryScreen->spriteIds); i++) - { sMonSummaryScreen->spriteIds[i] = 0xFF; - } } static void DestroySpriteInArray(u8 spriteArrayId) @@ -3725,10 +3716,10 @@ static void SetSpriteInvisibility(u8 spriteArrayId, bool8 invisible) static void HidePageSpecificSprites(void) { -// Keeps Pokémon, caught ball and status sprites visible. + // Keeps Pokémon, caught ball and status sprites visible. u8 i; - for (i = 3; i < ARRAY_COUNT(sMonSummaryScreen->spriteIds); i++) + for (i = SPRITE_ARR_ID_TYPE; i < ARRAY_COUNT(sMonSummaryScreen->spriteIds); i++) { if (sMonSummaryScreen->spriteIds[i] != 0xFF) SetSpriteInvisibility(i, TRUE); @@ -3757,7 +3748,7 @@ static void CreateMoveTypeIcons(void) { u8 i; - for (i = 3; i < 8; i++) + for (i = SPRITE_ARR_ID_TYPE; i < SPRITE_ARR_ID_TYPE + 5; i++) { if (sMonSummaryScreen->spriteIds[i] == 0xFF) sMonSummaryScreen->spriteIds[i] = CreateSprite(&sSpriteTemplate_MoveTypes, 0, 0, 2); @@ -3766,7 +3757,7 @@ static void CreateMoveTypeIcons(void) } } -static void SetMoveTypeSpritePosAndType(u8 typeId, u8 x, u8 y, u8 spriteArrayId) +static void SetTypeSpritePosAndPal(u8 typeId, u8 x, u8 y, u8 spriteArrayId) { struct Sprite *sprite = &gSprites[sMonSummaryScreen->spriteIds[spriteArrayId]]; StartSpriteAnim(sprite, typeId); @@ -3781,20 +3772,20 @@ static void SetMonTypeIcons(void) struct PokeSummary *summary = &sMonSummaryScreen->summary; if (summary->isEgg) { - SetMoveTypeSpritePosAndType(TYPE_MYSTERY, 120, 48, 3); - SetSpriteInvisibility(4, TRUE); + SetTypeSpritePosAndPal(TYPE_MYSTERY, 120, 48, SPRITE_ARR_ID_TYPE); + SetSpriteInvisibility(SPRITE_ARR_ID_TYPE + 1, TRUE); } else { - SetMoveTypeSpritePosAndType(gBaseStats[summary->species].type1, 0x78, 0x30, 3); + SetTypeSpritePosAndPal(gBaseStats[summary->species].type1, 120, 48, SPRITE_ARR_ID_TYPE); if (gBaseStats[summary->species].type1 != gBaseStats[summary->species].type2) { - SetMoveTypeSpritePosAndType(gBaseStats[summary->species].type2, 0xA0, 0x30, 4); - SetSpriteInvisibility(4, FALSE); + SetTypeSpritePosAndPal(gBaseStats[summary->species].type2, 160, 48, SPRITE_ARR_ID_TYPE + 1); + SetSpriteInvisibility(SPRITE_ARR_ID_TYPE + 1, FALSE); } else { - SetSpriteInvisibility(4, TRUE); + SetSpriteInvisibility(SPRITE_ARR_ID_TYPE + 1, TRUE); } } } @@ -3806,7 +3797,7 @@ static void SetMoveTypeIcons(void) for (i = 0; i < MAX_MON_MOVES; i++) { if (summary->moves[i] != MOVE_NONE) - SetMoveTypeSpritePosAndType(gBattleMoves[summary->moves[i]].type, 0x55, 0x20 + (i * 0x10), i + 3); + SetTypeSpritePosAndPal(gBattleMoves[summary->moves[i]].type, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); else SetSpriteInvisibility(i + 3, TRUE); } @@ -3819,7 +3810,7 @@ static void SetContestMoveTypeIcons(void) for (i = 0; i < MAX_MON_MOVES; i++) { if (summary->moves[i] != MOVE_NONE) - SetMoveTypeSpritePosAndType(NUMBER_OF_MON_TYPES + gContestMoves[summary->moves[i]].contestCategory, 0x55, 0x20 + (i * 0x10), i + 3); + SetTypeSpritePosAndPal(NUMBER_OF_MON_TYPES + gContestMoves[summary->moves[i]].contestCategory, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); else SetSpriteInvisibility(i + 3, TRUE); } @@ -3829,21 +3820,21 @@ static void SetNewMoveTypeIcon(void) { if (sMonSummaryScreen->newMove == MOVE_NONE) { - SetSpriteInvisibility(7, TRUE); + SetSpriteInvisibility(SPRITE_ARR_ID_TYPE + 4, TRUE); } else { - if (sMonSummaryScreen->currPageIndex == 2) - SetMoveTypeSpritePosAndType(gBattleMoves[sMonSummaryScreen->newMove].type, 85, 96, 7); + if (sMonSummaryScreen->currPageIndex == PSS_PAGE_BATTLE_MOVES) + SetTypeSpritePosAndPal(gBattleMoves[sMonSummaryScreen->newMove].type, 85, 96, SPRITE_ARR_ID_TYPE + 4); else - SetMoveTypeSpritePosAndType(NUMBER_OF_MON_TYPES + gContestMoves[sMonSummaryScreen->newMove].contestCategory, 85, 96, 7); + SetTypeSpritePosAndPal(NUMBER_OF_MON_TYPES + gContestMoves[sMonSummaryScreen->newMove].contestCategory, 85, 96, SPRITE_ARR_ID_TYPE + 4); } } -static void sub_81C4568(u8 a0, u8 a1) +static void SwapMovesTypeSprites(u8 moveIndex1, u8 moveIndex2) { - struct Sprite *sprite1 = &gSprites[sMonSummaryScreen->spriteIds[a0 + 3]]; - struct Sprite *sprite2 = &gSprites[sMonSummaryScreen->spriteIds[a1 + 3]]; + struct Sprite *sprite1 = &gSprites[sMonSummaryScreen->spriteIds[moveIndex1 + SPRITE_ARR_ID_TYPE]]; + struct Sprite *sprite2 = &gSprites[sMonSummaryScreen->spriteIds[moveIndex2 + SPRITE_ARR_ID_TYPE]]; u8 temp = sprite1->animNum; sprite1->animNum = sprite2->animNum; @@ -3859,60 +3850,48 @@ static void sub_81C4568(u8 a0, u8 a1) sprite2->animEnded = FALSE; } -static u8 CreatePokemonSprite(struct Pokemon *mon, s16 *a1) +static u8 LoadMonGfxAndSprite(struct Pokemon *mon, s16 *state) { const struct CompressedSpritePalette *pal; struct PokeSummary *summary = &sMonSummaryScreen->summary; - switch (*a1) + switch (*state) { - default: - return sub_81C47B4(mon); - case 0: - if (gMain.inBattle) + default: + return CreateMonSprite(mon); + case 0: + if (gMain.inBattle) + { + if (sub_80688F8(3, sMonSummaryScreen->curMonIndex)) + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); + else + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); + } + else + { + if (gMonSpritesGfxPtr != NULL) { - if (sub_80688F8(3, sMonSummaryScreen->curMonIndex)) - { - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); - } - else - { + if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == PSS_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); - } + else + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); } else { - if (gMonSpritesGfxPtr != NULL) - { - if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == PSS_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) - { - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); - } - else - { - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], gMonSpritesGfxPtr->sprites[1], summary->species2, summary->pid); - } - } + if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == PSS_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) + HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], sub_806F4F8(0, 1), summary->species2, summary->pid); else - { - if (sMonSummaryScreen->monList.mons == gPlayerParty || sMonSummaryScreen->mode == PSS_MODE_BOX || sMonSummaryScreen->unk40EF == TRUE) - { - HandleLoadSpecialPokePic_2(&gMonFrontPicTable[summary->species2], sub_806F4F8(0, 1), summary->species2, summary->pid); - } - else - { - HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], sub_806F4F8(0, 1), summary->species2, summary->pid); - } - } + HandleLoadSpecialPokePic_DontHandleDeoxys(&gMonFrontPicTable[summary->species2], sub_806F4F8(0, 1), summary->species2, summary->pid); } - (*a1)++; - return 0xFF; - case 1: - pal = GetMonSpritePalStructFromOtIdPersonality(summary->species2, summary->OTID, summary->pid); - LoadCompressedSpritePalette(pal); - SetMultiuseSpriteTemplateToPokemon(pal->tag, 1); - (*a1)++; - return 0xFF; + } + (*state)++; + return 0xFF; + case 1: + pal = GetMonSpritePalStructFromOtIdPersonality(summary->species2, summary->OTID, summary->pid); + LoadCompressedSpritePalette(pal); + SetMultiuseSpriteTemplateToPokemon(pal->tag, 1); + (*state)++; + return 0xFF; } } @@ -3922,37 +3901,27 @@ static void PlayMonCry(void) if (!summary->isEgg) { if (ShouldPlayNormalMonCry(&sMonSummaryScreen->currentMon) == TRUE) - { PlayCry3(summary->species2, 0, 0); - } else - { PlayCry3(summary->species2, 0, 11); - } } } -static u8 sub_81C47B4(struct Pokemon *unused) +static u8 CreateMonSprite(struct Pokemon *unused) { struct PokeSummary *summary = &sMonSummaryScreen->summary; u8 spriteId = CreateSprite(&gMultiuseSpriteTemplate, 40, 64, 5); - struct Sprite *sprite = &gSprites[spriteId]; - FreeSpriteOamMatrix(sprite); - - sprite->data[0] = summary->species2; - sprite->data[2] = 0; + FreeSpriteOamMatrix(&gSprites[spriteId]); + gSprites[spriteId].data[0] = summary->species2; + gSprites[spriteId].data[2] = 0; gSprites[spriteId].callback = SpriteCB_Pokemon; - sprite->oam.priority = 0; + gSprites[spriteId].oam.priority = 0; if (!IsMonSpriteNotFlipped(summary->species2)) - { - sprite->hFlip = TRUE; - } + gSprites[spriteId].hFlip = TRUE; else - { - sprite->hFlip = FALSE; - } + gSprites[spriteId].hFlip = FALSE; return spriteId; } @@ -3983,16 +3952,13 @@ void SummaryScreen_DestroyUnknownTask(void) } } -static bool32 SummaryScreen_DoesSpriteHaveCallback(void) +// unused +static bool32 IsMonAnimationFinished(void) { - if (gSprites[sMonSummaryScreen->spriteIds[0]].callback == SpriteCallbackDummy) - { + if (gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]].callback == SpriteCallbackDummy) return FALSE; - } else - { return TRUE; - } } static void StopPokemonAnimations(void) // A subtle effect, this function stops pokemon animations when leaving the PSS @@ -4000,24 +3966,24 @@ static void StopPokemonAnimations(void) // A subtle effect, this function stops u16 i; u16 paletteIndex; - gSprites[sMonSummaryScreen->spriteIds[0]].animPaused = TRUE; - gSprites[sMonSummaryScreen->spriteIds[0]].callback = SpriteCallbackDummy; + gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]].animPaused = TRUE; + gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]].callback = SpriteCallbackDummy; StopPokemonAnimationDelayTask(); - paletteIndex = (gSprites[sMonSummaryScreen->spriteIds[0]].oam.paletteNum * 16) | 0x100; + paletteIndex = (gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MON]].oam.paletteNum * 16) | 0x100; for (i = 0; i < 16; i++) { - gPlttBufferUnfaded[(u16)(i + paletteIndex)] = gPlttBufferFaded[(u16)(i + paletteIndex)]; + u16 id = i + paletteIndex; + gPlttBufferUnfaded[id] = gPlttBufferFaded[id]; } } static void CreateMonMarkingsSprite(struct Pokemon *mon) { - struct Sprite *sprite = sub_811FF94(30003, 30003, sSummaryMarkingsPalette); + struct Sprite *sprite = sub_811FF94(TAG_MON_MARKINGS, TAG_MON_MARKINGS, sSummaryMarkingsPalette); sMonSummaryScreen->markingsSprite = sprite; - if (sprite != NULL) { StartSpriteAnim(sprite, GetMonData(mon, MON_DATA_MARKINGS)); @@ -4030,7 +3996,7 @@ static void CreateMonMarkingsSprite(struct Pokemon *mon) static void RemoveAndCreateMonMarkingsSprite(struct Pokemon *mon) { DestroySprite(sMonSummaryScreen->markingsSprite); - FreeSpriteTilesByTag(30003); + FreeSpriteTilesByTag(TAG_MON_MARKINGS); CreateMonMarkingsSprite(mon); } @@ -4039,82 +4005,68 @@ static void CreateCaughtBallSprite(struct Pokemon *mon) u8 ball = ItemIdToBallId(GetMonData(mon, MON_DATA_POKEBALL)); LoadBallGfx(ball); - sMonSummaryScreen->spriteIds[1] = CreateSprite(&gBallSpriteTemplates[ball], 16, 136, 0); - gSprites[sMonSummaryScreen->spriteIds[1]].callback = SpriteCallbackDummy; - gSprites[sMonSummaryScreen->spriteIds[1]].oam.priority = 3; + sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_BALL] = CreateSprite(&gBallSpriteTemplates[ball], 16, 136, 0); + gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_BALL]].callback = SpriteCallbackDummy; + gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_BALL]].oam.priority = 3; } static void CreateSetStatusSprite(void) { - u8 *spriteId = &sMonSummaryScreen->spriteIds[2]; - u8 anim; + u8 *spriteId = &sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]; + u8 statusAnim; if (*spriteId == 0xFF) - { *spriteId = CreateSprite(&sSpriteTemplate_StatusCondition, 64, 152, 0); - } - anim = GetMonAilment(&sMonSummaryScreen->currentMon); - - if (anim != 0) + statusAnim = GetMonAilment(&sMonSummaryScreen->currentMon); + if (statusAnim != 0) { - StartSpriteAnim(&gSprites[*spriteId], anim - 1); - SetSpriteInvisibility(2, FALSE); + StartSpriteAnim(&gSprites[*spriteId], statusAnim - 1); + SetSpriteInvisibility(SPRITE_ARR_ID_STATUS, FALSE); } else { - SetSpriteInvisibility(2, TRUE); + SetSpriteInvisibility(SPRITE_ARR_ID_STATUS, TRUE); } } -static void sub_81C4AF8(u8 a0) +static void CreateMoveSelectorSprites(u8 idArrayStart) { u8 i; - u8 *spriteIds = &sMonSummaryScreen->spriteIds[a0]; + u8 *spriteIds = &sMonSummaryScreen->spriteIds[idArrayStart]; - if (sMonSummaryScreen->currPageIndex > 1) + if (sMonSummaryScreen->currPageIndex >= PSS_PAGE_BATTLE_MOVES) { - u8 subsprite = 0; - if (a0 == 8) - { - subsprite = 1; - } + u8 subpriority = 0; + if (idArrayStart == SPRITE_ARR_ID_MOVE_SELECTOR1) + subpriority = 1; for (i = 0; i < 10; i++) { - spriteIds[i] = CreateSprite(&gUnknown_0861D084, i * 16 + 89, 40, subsprite); + spriteIds[i] = CreateSprite(&sMoveSelectorSpriteTemplate, i * 16 + 89, 40, subpriority); if (i == 0) - { - StartSpriteAnim(&gSprites[spriteIds[0]], 4); - } + StartSpriteAnim(&gSprites[spriteIds[i]], 4); // left else if (i == 9) - { - StartSpriteAnim(&gSprites[spriteIds[9]], 5); - } + StartSpriteAnim(&gSprites[spriteIds[i]], 5); // right, actually the same as left, but flipped else - { - StartSpriteAnim(&gSprites[spriteIds[i]], 6); - } - gSprites[spriteIds[i]].callback = sub_81C4BE4; - gSprites[spriteIds[i]].data[0] = a0; + StartSpriteAnim(&gSprites[spriteIds[i]], 6); // middle + + gSprites[spriteIds[i]].callback = SpriteCb_MoveSelector; + gSprites[spriteIds[i]].data[0] = idArrayStart; gSprites[spriteIds[i]].data[1] = 0; } } } -static void sub_81C4BE4(struct Sprite *sprite) +static void SpriteCb_MoveSelector(struct Sprite *sprite) { if (sprite->animNum > 3 && sprite->animNum < 7) { sprite->data[1] = (sprite->data[1] + 1) & 0x1F; if (sprite->data[1] > 24) - { sprite->invisible = TRUE; - } else - { sprite->invisible = FALSE; - } } else { @@ -4122,54 +4074,42 @@ static void sub_81C4BE4(struct Sprite *sprite) sprite->invisible = FALSE; } - if (sprite->data[0] == 8) - { + if (sprite->data[0] == SPRITE_ARR_ID_MOVE_SELECTOR1) sprite->pos2.y = sMonSummaryScreen->firstMoveIndex * 16; - } else - { sprite->pos2.y = sMonSummaryScreen->secondMoveIndex * 16; - } } -static void sub_81C4C60(u8 a0) +static void DestroyMoveSelectorSprites(u8 firstArrayId) { u8 i; - for (i = 0; i < 10; i++) - { - DestroySpriteInArray(a0 + i); - } + for (i = 0; i < MOVE_SELECTOR_SPRITES_COUNT; i++) + DestroySpriteInArray(firstArrayId + i); } -static void sub_81C4C84(u8 a0) +static void SetMainMoveSelectorColor(u8 which) { u8 i; - u8 *spriteIds = &sMonSummaryScreen->spriteIds[8]; - a0 *= 3; + u8 *spriteIds = &sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_MOVE_SELECTOR1]; - for (i = 0; i < 10; i++) + which *= 3; + for (i = 0; i < MOVE_SELECTOR_SPRITES_COUNT; i++) { if (i == 0) - { - StartSpriteAnim(&gSprites[spriteIds[0]], a0 + 4); - } + StartSpriteAnim(&gSprites[spriteIds[i]], which + 4); else if (i == 9) - { - StartSpriteAnim(&gSprites[spriteIds[9]], a0 + 5); - } + StartSpriteAnim(&gSprites[spriteIds[i]], which + 5); else - { - StartSpriteAnim(&gSprites[spriteIds[i]], a0 + 6); - } + StartSpriteAnim(&gSprites[spriteIds[i]], which + 6); } } -static void sub_81C4D18(u8 firstSpriteId) +static void MakeMoveSelectorVisible(u8 firstSpriteId) { u8 i; u8 *spriteIds = &sMonSummaryScreen->spriteIds[firstSpriteId]; - for (i = 0; i < 10; i++) + for (i = 0; i < MOVE_SELECTOR_SPRITES_COUNT; i++) { gSprites[spriteIds[i]].data[1] = 0; gSprites[spriteIds[i]].invisible = FALSE; diff --git a/src/trade.c b/src/trade.c index 37a63eb4b..e22180ae9 100644 --- a/src/trade.c +++ b/src/trade.c @@ -1199,7 +1199,7 @@ static void QueueLinkTradeData(void) { if (sTradeMenuData->playerLinkFlagChoseAction && sTradeMenuData->partnerLinkFlagChoseAction) { - if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_TRADE + if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_TRADE && sTradeMenuData->partnerLinkFlagChoseAction == WANTS_TO_TRADE) { sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_BOTH_MONS_SELECTED; @@ -1208,7 +1208,7 @@ static void QueueLinkTradeData(void) QueueAction(QUEUE_DELAY_DATA, QUEUE_SEND_DATA); sTradeMenuData->playerLinkFlagChoseAction = sTradeMenuData->partnerLinkFlagChoseAction = 0; } - else if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_TRADE + else if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_TRADE && sTradeMenuData->partnerLinkFlagChoseAction == WANTS_TO_CANCEL) { PrintTradeMessage(TRADE_MSG_CANCELED); @@ -1219,7 +1219,7 @@ static void QueueLinkTradeData(void) sTradeMenuData->playerLinkFlagChoseAction = sTradeMenuData->partnerLinkFlagChoseAction = 0; sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_REDRAW_MAIN_MENU; } - else if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_CANCEL + else if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_CANCEL && sTradeMenuData->partnerLinkFlagChoseAction == WANTS_TO_TRADE) { PrintTradeMessage(TRADE_MSG_FRIEND_WANTS_TO_TRADE); @@ -1230,7 +1230,7 @@ static void QueueLinkTradeData(void) sTradeMenuData->playerLinkFlagChoseAction = sTradeMenuData->partnerLinkFlagChoseAction = 0; sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_REDRAW_MAIN_MENU; } - else if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_CANCEL + else if (sTradeMenuData->playerLinkFlagChoseAction == WANTS_TO_CANCEL && sTradeMenuData->partnerLinkFlagChoseAction == WANTS_TO_CANCEL) { sTradeMenuData->linkData[0] = LINKCMD_CANCEL_TRADE; @@ -1244,7 +1244,7 @@ static void QueueLinkTradeData(void) if (sTradeMenuData->playerLinkFlagStatus && sTradeMenuData->partnerLinkFlagStatus) { - if (sTradeMenuData->playerLinkFlagStatus == INITIATE_TRADE + if (sTradeMenuData->playerLinkFlagStatus == INITIATE_TRADE && sTradeMenuData->partnerLinkFlagStatus == INITIATE_TRADE) { sTradeMenuData->linkData[0] = LINKCMD_START_TRADE; @@ -1255,7 +1255,7 @@ static void QueueLinkTradeData(void) sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_LINK_TRADE_FADE_OUT; } - if (sTradeMenuData->playerLinkFlagStatus == CANCEL_TRADE + if (sTradeMenuData->playerLinkFlagStatus == CANCEL_TRADE || sTradeMenuData->partnerLinkFlagStatus == CANCEL_TRADE) { PrintTradeMessage(TRADE_MSG_CANCELED); @@ -1464,10 +1464,10 @@ static void TradeMenuShowMonSummaryScreen(void) { // Player's party if (sTradeMenuData->cursorPosition < PARTY_SIZE) - ShowPokemonSummaryScreen(PSS_MODE_UNK1, gPlayerParty, sTradeMenuData->cursorPosition, sTradeMenuData->partyCounts[TRADE_PLAYER] - 1, CB2_ReturnToTradeMenu); + ShowPokemonSummaryScreen(PSS_MODE_LOCK_MOVES, gPlayerParty, sTradeMenuData->cursorPosition, sTradeMenuData->partyCounts[TRADE_PLAYER] - 1, CB2_ReturnToTradeMenu); // Partner's party else - ShowPokemonSummaryScreen(PSS_MODE_UNK1, gEnemyParty, sTradeMenuData->cursorPosition - PARTY_SIZE, sTradeMenuData->partyCounts[TRADE_PARTNER] - 1, CB2_ReturnToTradeMenu); + ShowPokemonSummaryScreen(PSS_MODE_LOCK_MOVES, gEnemyParty, sTradeMenuData->cursorPosition - PARTY_SIZE, sTradeMenuData->partyCounts[TRADE_PARTNER] - 1, CB2_ReturnToTradeMenu); FreeAllWindowBuffers(); } } @@ -1504,7 +1504,7 @@ static u8 CheckValidityOfTradeMons(u8 *aliveMons, u8 playerPartyCount, u8 player if (hasLiveMon) hasLiveMon = BOTH_MONS_VALID; - return hasLiveMon; //PLAYER_MON_INVALID or BOTH_MONS_VALID + return hasLiveMon; //PLAYER_MON_INVALID or BOTH_MONS_VALID } // Returns TRUE if the partner's selected mon is invalid, FALSE otherwise @@ -1841,10 +1841,10 @@ static void DrawTradeMenuParty(u8 whichParty) sTradeMenuData->drawPartyState[whichParty]++; break; case 4: - DrawTradeMenuPartyMonInfo(whichParty, partyIdx, - sTradeMenuPartyMonBoxDimensions[whichParty][0] + 4, - sTradeMenuPartyMonBoxDimensions[whichParty][1] + 1, - sTradeMenuPartyMonBoxDimensions[whichParty][0], + DrawTradeMenuPartyMonInfo(whichParty, partyIdx, + sTradeMenuPartyMonBoxDimensions[whichParty][0] + 4, + sTradeMenuPartyMonBoxDimensions[whichParty][1] + 1, + sTradeMenuPartyMonBoxDimensions[whichParty][0], sTradeMenuPartyMonBoxDimensions[whichParty][1]); sTradeMenuData->drawPartyState[whichParty]++; break; @@ -2028,7 +2028,7 @@ static void ResetTradeMenuPartyPositions(u8 whichParty) static void PrintNicknamesForTradeMenu(void) { rbox_fill_rectangle(1); - //PrintPartyNicknamesForTradeMenu(TRADE_PLAYER); ? + //PrintPartyNicknamesForTradeMenu(TRADE_PLAYER); ? PrintPartyNicknamesForTradeMenu(TRADE_PARTNER); } @@ -4539,8 +4539,8 @@ static void CB2_TryFinishTrade(void) else { UpdateTradeFinishFlags(); - if (mpId == 0 - && sTradeData->playerLinkFlagFinishTrade == READY_FINISH_TRADE + if (mpId == 0 + && sTradeData->playerLinkFlagFinishTrade == READY_FINISH_TRADE && sTradeData->partnerLinkFlagFinishTrade == READY_FINISH_TRADE) { sTradeData->linkData[0] = LINKCMD_CONFIRM_FINISH_TRADE; From 65fb2e9957538c168dbc2d414b8501e7633fd380 Mon Sep 17 00:00:00 2001 From: Kurausukun Date: Mon, 18 May 2020 23:42:42 -0400 Subject: [PATCH 20/43] Fix compilation on gcc 10 (for real this time) --- tools/preproc/c_file.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp index 229f568fa..b996a048c 100644 --- a/tools/preproc/c_file.cpp +++ b/tools/preproc/c_file.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include "preproc.h" From 2a1781b2ed0ad12bcdfff3b0501ce6bdcbccfac7 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 19 May 2020 16:13:25 -0400 Subject: [PATCH 21/43] sPrizeListGigaSwap typo fix --- src/trainer_hill.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 8ff9d2eaf..87866b02e 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -165,7 +165,7 @@ static const u16 sPrizeListElixir2[] = {ITEM_ELIXIR, ITEM_ETHER, I static const u16 sPrizeListBrickBreak[] = {ITEM_TM31_BRICK_BREAK, ITEM_ETHER, ITEM_MAX_POTION, ITEM_REVIVE, ITEM_FLUFFY_TAIL, ITEM_GREAT_BALL}; static const u16 sPrizeListTorment[] = {ITEM_TM41_TORMENT, ITEM_ETHER, ITEM_MAX_POTION, ITEM_REVIVE, ITEM_FLUFFY_TAIL, ITEM_GREAT_BALL}; static const u16 sPrizeListSkillSwap[] = {ITEM_TM48_SKILL_SWAP, ITEM_ETHER, ITEM_MAX_POTION, ITEM_REVIVE, ITEM_FLUFFY_TAIL, ITEM_GREAT_BALL}; -static const u16 sPrizeListGigaSwap[] = {ITEM_TM19_GIGA_DRAIN, ITEM_ETHER, ITEM_MAX_POTION, ITEM_REVIVE, ITEM_FLUFFY_TAIL, ITEM_GREAT_BALL}; +static const u16 sPrizeListGigaDrain[] = {ITEM_TM19_GIGA_DRAIN, ITEM_ETHER, ITEM_MAX_POTION, ITEM_REVIVE, ITEM_FLUFFY_TAIL, ITEM_GREAT_BALL}; static const u16 sPrizeListAttract[] = {ITEM_TM45_ATTRACT, ITEM_ETHER, ITEM_MAX_POTION, ITEM_REVIVE, ITEM_FLUFFY_TAIL, ITEM_GREAT_BALL}; static const u16 *const sPrizeLists1[NUM_TRAINER_HILL_PRIZE_LISTS] = @@ -192,7 +192,7 @@ static const u16 *const sPrizeLists2[NUM_TRAINER_HILL_PRIZE_LISTS] = sPrizeListBrickBreak, sPrizeListTorment, sPrizeListSkillSwap, - sPrizeListGigaSwap, + sPrizeListGigaDrain, sPrizeListAttract }; From 1beca515ed8e1ed266d1b0fe68231ece24a61812 Mon Sep 17 00:00:00 2001 From: Missingmew Date: Wed, 20 May 2020 23:58:20 +0200 Subject: [PATCH 22/43] Decompile unused function, as seen in ruby --- src/decompress.c | 481 ++++++++++++++--------------------------------- 1 file changed, 141 insertions(+), 340 deletions(-) diff --git a/src/decompress.c b/src/decompress.c index 5e85e065f..819263eb4 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -114,347 +114,148 @@ void Unused_LZDecompressWramIndirect(const void **src, void *dest) LZ77UnCompWram(*src, dest); } -// This one (unused) function is really challenging, won't even try to decompile it. -NAKED -void sub_803471C() +void sub_803471C(int object_size, int object_count, unsigned char *src_tiles, unsigned char *dest_tiles) { - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - sub sp, 0x24\n\ - mov r9, r0\n\ - str r1, [sp]\n\ - str r2, [sp, 0x4]\n\ - adds r5, r3, 0\n\ - movs r0, 0x1\n\ - mov r1, r9\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - bne _0803473C\n\ - b _080348D4\n\ -_0803473C:\n\ - asrs r0, r1, 1\n\ - adds r0, 0x4\n\ - lsls r0, 24\n\ - lsrs r0, 24\n\ - str r0, [sp, 0x8]\n\ - movs r0, 0\n\ - ldr r2, [sp]\n\ - cmp r0, r2\n\ - blt _08034750\n\ - b _08034964\n\ -_08034750:\n\ - movs r4, 0x8\n\ - subs r1, r4, r1\n\ - str r1, [sp, 0x10]\n\ -_08034756:\n\ - movs r7, 0\n\ - adds r0, 0x1\n\ - str r0, [sp, 0x14]\n\ - ldr r0, [sp, 0x10]\n\ - cmp r7, r0\n\ - bge _080347D2\n\ - ldr r1, [sp, 0x8]\n\ - lsls r1, 8\n\ - str r1, [sp, 0x18]\n\ - movs r2, 0\n\ - mov r10, r2\n\ - mov r0, r9\n\ - movs r4, 0x8\n\ - subs r0, r4, r0\n\ - str r0, [sp, 0xC]\n\ -_08034774:\n\ - movs r3, 0\n\ - asrs r0, r7, 1\n\ - adds r1, r7, 0\n\ - movs r2, 0x1\n\ - ands r1, r2\n\ - str r1, [sp, 0x20]\n\ - lsls r0, 8\n\ - mov r8, r0\n\ - mov r12, r5\n\ -_08034786:\n\ - lsls r1, r3, 5\n\ - ldr r4, [sp, 0x18]\n\ - adds r0, r5, r4\n\ - adds r0, r1\n\ - mov r1, r8\n\ - adds r2, r0, r1\n\ - mov r1, r12\n\ - add r1, r8\n\ - movs r6, 0xF\n\ -_08034798:\n\ - ldr r4, [sp, 0x20]\n\ - cmp r4, 0\n\ - bne _080347A8\n\ - strb r4, [r1]\n\ - add r4, sp, 0x20\n\ - ldrb r4, [r4]\n\ - strb r4, [r2, 0x10]\n\ - b _080347B6\n\ -_080347A8:\n\ - mov r0, r10\n\ - strb r0, [r1, 0x10]\n\ - movs r4, 0x80\n\ - lsls r4, 1\n\ - adds r4, r2, r4\n\ - str r4, [sp, 0x1C]\n\ - strb r0, [r4]\n\ -_080347B6:\n\ - adds r2, 0x1\n\ - adds r1, 0x1\n\ - subs r6, 0x1\n\ - cmp r6, 0\n\ - bge _08034798\n\ - movs r0, 0x20\n\ - add r12, r0\n\ - adds r3, 0x1\n\ - cmp r3, 0x7\n\ - ble _08034786\n\ - adds r7, 0x1\n\ - ldr r1, [sp, 0xC]\n\ - cmp r7, r1\n\ - blt _08034774\n\ -_080347D2:\n\ - movs r7, 0\n\ - movs r2, 0\n\ -_080347D6:\n\ - movs r6, 0\n\ - adds r4, r7, 0x1\n\ - mov r8, r4\n\ - lsls r4, r7, 5\n\ -_080347DE:\n\ - adds r0, r6, 0x1\n\ - mov r10, r0\n\ - lsls r1, r6, 8\n\ - adds r0, r1, 0\n\ - adds r0, 0xC0\n\ - adds r0, r5, r0\n\ - adds r0, r4\n\ - adds r1, r5, r1\n\ - adds r1, r4\n\ - movs r3, 0x1F\n\ -_080347F2:\n\ - strb r2, [r1]\n\ - strb r2, [r0]\n\ - adds r0, 0x1\n\ - adds r1, 0x1\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bge _080347F2\n\ - mov r6, r10\n\ - cmp r6, 0x7\n\ - ble _080347DE\n\ - mov r7, r8\n\ - cmp r7, 0x1\n\ - ble _080347D6\n\ - mov r1, r9\n\ - cmp r1, 0x5\n\ - bne _08034818\n\ - movs r2, 0x90\n\ - lsls r2, 1\n\ - adds r5, r2\n\ -_08034818:\n\ - movs r7, 0\n\ - cmp r7, r9\n\ - bge _080348AE\n\ -_0803481E:\n\ - movs r3, 0\n\ - adds r7, 0x1\n\ - mov r8, r7\n\ - cmp r3, r9\n\ - bge _0803488E\n\ -_08034828:\n\ - adds r3, 0x1\n\ - mov r10, r3\n\ - ldr r4, [sp, 0x4]\n\ - adds r4, 0x20\n\ - adds r7, r5, 0\n\ - adds r7, 0x20\n\ - movs r0, 0x12\n\ - adds r0, r5\n\ - mov r12, r0\n\ - ldr r2, [sp, 0x4]\n\ - adds r3, r5, 0\n\ - movs r6, 0x3\n\ -_08034840:\n\ - ldrb r0, [r2]\n\ - mov r1, r12\n\ - strb r0, [r1]\n\ - ldrb r0, [r2, 0x1]\n\ - strb r0, [r1, 0x1]\n\ - ldrb r0, [r2, 0x2]\n\ - strb r0, [r1, 0x1E]\n\ - ldrb r0, [r2, 0x3]\n\ - strb r0, [r1, 0x1F]\n\ - movs r0, 0x81\n\ - lsls r0, 1\n\ - adds r1, r3, r0\n\ - ldrb r0, [r2, 0x10]\n\ - strb r0, [r1]\n\ - ldr r0, =0x00000103\n\ - adds r1, r3, r0\n\ - ldrb r0, [r2, 0x11]\n\ - strb r0, [r1]\n\ - movs r0, 0x90\n\ - lsls r0, 1\n\ - adds r1, r3, r0\n\ - ldrb r0, [r2, 0x12]\n\ - strb r0, [r1]\n\ - ldr r0, =0x00000121\n\ - adds r1, r3, r0\n\ - ldrb r0, [r2, 0x13]\n\ - strb r0, [r1]\n\ - movs r1, 0x4\n\ - add r12, r1\n\ - adds r2, 0x4\n\ - adds r3, 0x4\n\ - subs r6, 0x1\n\ - cmp r6, 0\n\ - bge _08034840\n\ - str r4, [sp, 0x4]\n\ - adds r5, r7, 0\n\ - mov r3, r10\n\ - cmp r3, r9\n\ - blt _08034828\n\ -_0803488E:\n\ - mov r2, r9\n\ - cmp r2, 0x7\n\ - bne _080348A0\n\ - adds r5, 0x20\n\ - b _080348A8\n\ - .pool\n\ -_080348A0:\n\ - mov r4, r9\n\ - cmp r4, 0x5\n\ - bne _080348A8\n\ - adds r5, 0x60\n\ -_080348A8:\n\ - mov r7, r8\n\ - cmp r7, r9\n\ - blt _0803481E\n\ -_080348AE:\n\ - mov r0, r9\n\ - cmp r0, 0x7\n\ - bne _080348BC\n\ - movs r1, 0x80\n\ - lsls r1, 1\n\ - adds r5, r1\n\ - b _080348C8\n\ -_080348BC:\n\ - mov r2, r9\n\ - cmp r2, 0x5\n\ - bne _080348C8\n\ - movs r4, 0xF0\n\ - lsls r4, 1\n\ - adds r5, r4\n\ -_080348C8:\n\ - ldr r0, [sp, 0x14]\n\ - ldr r1, [sp]\n\ - cmp r0, r1\n\ - bge _080348D2\n\ - b _08034756\n\ -_080348D2:\n\ - b _08034964\n\ -_080348D4:\n\ - movs r6, 0\n\ - ldr r2, [sp]\n\ - cmp r6, r2\n\ - bge _08034964\n\ -_080348DC:\n\ - adds r6, 0x1\n\ - mov r10, r6\n\ - mov r4, r9\n\ - cmp r4, 0x6\n\ - bne _080348F4\n\ - movs r0, 0\n\ - movs r3, 0xFF\n\ -_080348EA:\n\ - strb r0, [r5]\n\ - adds r5, 0x1\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bge _080348EA\n\ -_080348F4:\n\ - movs r7, 0\n\ - cmp r7, r9\n\ - bge _08034948\n\ -_080348FA:\n\ - adds r7, 0x1\n\ - mov r8, r7\n\ - mov r1, r9\n\ - lsls r0, r1, 5\n\ - cmp r1, 0x6\n\ - bne _08034914\n\ - movs r1, 0\n\ - movs r3, 0x1F\n\ -_0803490A:\n\ - strb r1, [r5]\n\ - adds r5, 0x1\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bge _0803490A\n\ -_08034914:\n\ - adds r1, r0, 0\n\ - cmp r1, 0\n\ - ble _0803492E\n\ - adds r3, r1, 0\n\ -_0803491C:\n\ - ldr r2, [sp, 0x4]\n\ - ldrb r0, [r2]\n\ - strb r0, [r5]\n\ - adds r2, 0x1\n\ - str r2, [sp, 0x4]\n\ - adds r5, 0x1\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bne _0803491C\n\ -_0803492E:\n\ - mov r4, r9\n\ - cmp r4, 0x6\n\ - bne _08034942\n\ - movs r0, 0\n\ - movs r3, 0x1F\n\ -_08034938:\n\ - strb r0, [r5]\n\ - adds r5, 0x1\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bge _08034938\n\ -_08034942:\n\ - mov r7, r8\n\ - cmp r7, r9\n\ - blt _080348FA\n\ -_08034948:\n\ - mov r0, r9\n\ - cmp r0, 0x6\n\ - bne _0803495C\n\ - movs r0, 0\n\ - movs r3, 0xFF\n\ -_08034952:\n\ - strb r0, [r5]\n\ - adds r5, 0x1\n\ - subs r3, 0x1\n\ - cmp r3, 0\n\ - bge _08034952\n\ -_0803495C:\n\ - mov r6, r10\n\ - ldr r1, [sp]\n\ - cmp r6, r1\n\ - blt _080348DC\n\ -_08034964:\n\ - add sp, 0x24\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .syntax divided"); + /* + This function appears to emulate behaviour found in the GB(C) versions regarding how the Pokemon images + are stitched together to be displayed on the battle screen. + Given "compacted" tiles, an object count and a bounding box/object size, place the tiles in such a way + that the result will have each object centered in a 8x8 tile canvas. + */ + int i, j, k, l; + unsigned char *src = src_tiles, *dest = dest_tiles; + unsigned char bottom_off; + + if (object_size & 1) + { + // Object size is odd + bottom_off = (object_size >> 1) + 4; + for (l = 0; l < object_count; l++) + { + // Clear all unused rows of tiles plus the half-tile required due to centering + for (j = 0; j < 8-object_size; j++) + { + for (k = 0; k < 8; k++) + { + for (i = 0; i < 16; i++) + { + if (j % 2 == 0) + { + // Clear top half of top tile and bottom half of bottom tile when on even j + ((dest+i) + (k << 5))[((j >> 1) << 8)] = 0; + ((bottom_off << 8) + (dest+i) + (k << 5) + 16)[((j >> 1) << 8)] = 0; + } + else + { + // Clear bottom half of top tile and top half of tile following bottom tile when on odd j + ((dest+i) + (k << 5) + 16)[((j >> 1) << 8)] = 0; + ((bottom_off << 8) + (dest+i) + (k << 5) + 256)[((j >> 1) << 8)] = 0; + } + } + } + } + + // Clear the columns to the left and right that wont be used completely + // Unlike the previous loops, this will clear the later used space as well + for (j = 0; j < 2; j++) + { + for (i = 0; i < 8; i++) + { + for (k = 0; k < 32; k++) + { + // Left side + ((dest+k) + (i << 8))[(j << 5)] = 0; + // Right side + ((dest+k) + (i << 8))[(j << 5)+192] = 0; + } + } + } + + // Skip the top row and first tile on the second row for objects of size 5 + if (object_size == 5) dest += 0x120; + + // Copy tile data + for (j = 0; j < object_size; j++) + { + for (k = 0; k < object_size; k++) + { + for (i = 0; i < 4; i++) + { + // Offset the tile by +4px in both x and y directions + (dest + (i << 2))[18] = (src + (i << 2))[0]; + (dest + (i << 2))[19] = (src + (i << 2))[1]; + (dest + (i << 2))[48] = (src + (i << 2))[2]; + (dest + (i << 2))[49] = (src + (i << 2))[3]; + + (dest + (i << 2))[258] = (src + (i << 2))[16]; + (dest + (i << 2))[259] = (src + (i << 2))[17]; + (dest + (i << 2))[288] = (src + (i << 2))[18]; + (dest + (i << 2))[289] = (src + (i << 2))[19]; + } + src += 32; + dest += 32; + } + + // At the end of a row, skip enough tiles to get to the beginning of the next row + if (object_size == 7) dest += 0x20; + else if (object_size == 5) dest += 0x60; + } + + // Skip remaining unused space to go to the beginning of the next object + if (object_size == 7) dest += 0x100; + else if (object_size == 5) dest += 0x1e0; + } + } + else + { + // Object size is even + for (i = 0; i < object_count; i++) + { + // For objects of size 6, the first and last row and column will be cleared + // While the remaining space will be filled with actual data + if (object_size == 6) + { + for (k = 0; k < 256; k++) { + *dest = 0; + dest++; + } + } + + for (j = 0; j < object_size; j++) + { + if (object_size == 6) + { + for (k = 0; k < 32; k++) { + *dest = 0; + dest++; + } + } + + // Copy tile data + for (k = 0; k < 32 * object_size; k++) { + *dest = *src; + src++; + dest++; + } + + if (object_size == 6) + { + for (k = 0; k < 32; k++) { + *dest = 0; + dest++; + } + } + } + + if (object_size == 6) + { + for (k = 0; k < 256; k++) { + *dest = 0; + dest++; + } + } + } + } } u32 GetDecompressedDataSize(const u32 *ptr) From 9a13be4e7b94a719c8d27381537ad43c37f990c3 Mon Sep 17 00:00:00 2001 From: Missingmew Date: Thu, 21 May 2020 00:25:30 +0200 Subject: [PATCH 23/43] switch to pret short-types and tabs vs spaces --- src/decompress.c | 260 +++++++++++++++++++++++------------------------ 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/src/decompress.c b/src/decompress.c index 819263eb4..c303f214f 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -114,148 +114,148 @@ void Unused_LZDecompressWramIndirect(const void **src, void *dest) LZ77UnCompWram(*src, dest); } -void sub_803471C(int object_size, int object_count, unsigned char *src_tiles, unsigned char *dest_tiles) +void sub_803471C(s32 object_size, s32 object_count, u8 *src_tiles, u8 *dest_tiles) { - /* - This function appears to emulate behaviour found in the GB(C) versions regarding how the Pokemon images - are stitched together to be displayed on the battle screen. - Given "compacted" tiles, an object count and a bounding box/object size, place the tiles in such a way - that the result will have each object centered in a 8x8 tile canvas. - */ - int i, j, k, l; - unsigned char *src = src_tiles, *dest = dest_tiles; - unsigned char bottom_off; + /* + This function appears to emulate behaviour found in the GB(C) versions regarding how the Pokemon images + are stitched together to be displayed on the battle screen. + Given "compacted" tiles, an object count and a bounding box/object size, place the tiles in such a way + that the result will have each object centered in a 8x8 tile canvas. + */ + s32 i, j, k, l; + u8 *src = src_tiles, *dest = dest_tiles; + u8 bottom_off; - if (object_size & 1) - { - // Object size is odd - bottom_off = (object_size >> 1) + 4; - for (l = 0; l < object_count; l++) - { - // Clear all unused rows of tiles plus the half-tile required due to centering - for (j = 0; j < 8-object_size; j++) - { - for (k = 0; k < 8; k++) - { - for (i = 0; i < 16; i++) - { - if (j % 2 == 0) - { - // Clear top half of top tile and bottom half of bottom tile when on even j - ((dest+i) + (k << 5))[((j >> 1) << 8)] = 0; - ((bottom_off << 8) + (dest+i) + (k << 5) + 16)[((j >> 1) << 8)] = 0; - } - else - { - // Clear bottom half of top tile and top half of tile following bottom tile when on odd j - ((dest+i) + (k << 5) + 16)[((j >> 1) << 8)] = 0; - ((bottom_off << 8) + (dest+i) + (k << 5) + 256)[((j >> 1) << 8)] = 0; - } - } - } - } + if (object_size & 1) + { + // Object size is odd + bottom_off = (object_size >> 1) + 4; + for (l = 0; l < object_count; l++) + { + // Clear all unused rows of tiles plus the half-tile required due to centering + for (j = 0; j < 8-object_size; j++) + { + for (k = 0; k < 8; k++) + { + for (i = 0; i < 16; i++) + { + if (j % 2 == 0) + { + // Clear top half of top tile and bottom half of bottom tile when on even j + ((dest+i) + (k << 5))[((j >> 1) << 8)] = 0; + ((bottom_off << 8) + (dest+i) + (k << 5) + 16)[((j >> 1) << 8)] = 0; + } + else + { + // Clear bottom half of top tile and top half of tile following bottom tile when on odd j + ((dest+i) + (k << 5) + 16)[((j >> 1) << 8)] = 0; + ((bottom_off << 8) + (dest+i) + (k << 5) + 256)[((j >> 1) << 8)] = 0; + } + } + } + } - // Clear the columns to the left and right that wont be used completely - // Unlike the previous loops, this will clear the later used space as well - for (j = 0; j < 2; j++) - { - for (i = 0; i < 8; i++) - { - for (k = 0; k < 32; k++) - { - // Left side - ((dest+k) + (i << 8))[(j << 5)] = 0; - // Right side - ((dest+k) + (i << 8))[(j << 5)+192] = 0; - } - } - } + // Clear the columns to the left and right that wont be used completely + // Unlike the previous loops, this will clear the later used space as well + for (j = 0; j < 2; j++) + { + for (i = 0; i < 8; i++) + { + for (k = 0; k < 32; k++) + { + // Left side + ((dest+k) + (i << 8))[(j << 5)] = 0; + // Right side + ((dest+k) + (i << 8))[(j << 5)+192] = 0; + } + } + } - // Skip the top row and first tile on the second row for objects of size 5 - if (object_size == 5) dest += 0x120; + // Skip the top row and first tile on the second row for objects of size 5 + if (object_size == 5) dest += 0x120; - // Copy tile data - for (j = 0; j < object_size; j++) - { - for (k = 0; k < object_size; k++) - { - for (i = 0; i < 4; i++) - { - // Offset the tile by +4px in both x and y directions - (dest + (i << 2))[18] = (src + (i << 2))[0]; - (dest + (i << 2))[19] = (src + (i << 2))[1]; - (dest + (i << 2))[48] = (src + (i << 2))[2]; - (dest + (i << 2))[49] = (src + (i << 2))[3]; + // Copy tile data + for (j = 0; j < object_size; j++) + { + for (k = 0; k < object_size; k++) + { + for (i = 0; i < 4; i++) + { + // Offset the tile by +4px in both x and y directions + (dest + (i << 2))[18] = (src + (i << 2))[0]; + (dest + (i << 2))[19] = (src + (i << 2))[1]; + (dest + (i << 2))[48] = (src + (i << 2))[2]; + (dest + (i << 2))[49] = (src + (i << 2))[3]; - (dest + (i << 2))[258] = (src + (i << 2))[16]; - (dest + (i << 2))[259] = (src + (i << 2))[17]; - (dest + (i << 2))[288] = (src + (i << 2))[18]; - (dest + (i << 2))[289] = (src + (i << 2))[19]; - } - src += 32; - dest += 32; - } + (dest + (i << 2))[258] = (src + (i << 2))[16]; + (dest + (i << 2))[259] = (src + (i << 2))[17]; + (dest + (i << 2))[288] = (src + (i << 2))[18]; + (dest + (i << 2))[289] = (src + (i << 2))[19]; + } + src += 32; + dest += 32; + } - // At the end of a row, skip enough tiles to get to the beginning of the next row - if (object_size == 7) dest += 0x20; - else if (object_size == 5) dest += 0x60; - } + // At the end of a row, skip enough tiles to get to the beginning of the next row + if (object_size == 7) dest += 0x20; + else if (object_size == 5) dest += 0x60; + } - // Skip remaining unused space to go to the beginning of the next object - if (object_size == 7) dest += 0x100; - else if (object_size == 5) dest += 0x1e0; - } - } - else - { - // Object size is even - for (i = 0; i < object_count; i++) - { - // For objects of size 6, the first and last row and column will be cleared - // While the remaining space will be filled with actual data - if (object_size == 6) - { - for (k = 0; k < 256; k++) { - *dest = 0; - dest++; - } - } + // Skip remaining unused space to go to the beginning of the next object + if (object_size == 7) dest += 0x100; + else if (object_size == 5) dest += 0x1e0; + } + } + else + { + // Object size is even + for (i = 0; i < object_count; i++) + { + // For objects of size 6, the first and last row and column will be cleared + // While the remaining space will be filled with actual data + if (object_size == 6) + { + for (k = 0; k < 256; k++) { + *dest = 0; + dest++; + } + } - for (j = 0; j < object_size; j++) - { - if (object_size == 6) - { - for (k = 0; k < 32; k++) { - *dest = 0; - dest++; - } - } + for (j = 0; j < object_size; j++) + { + if (object_size == 6) + { + for (k = 0; k < 32; k++) { + *dest = 0; + dest++; + } + } - // Copy tile data - for (k = 0; k < 32 * object_size; k++) { - *dest = *src; - src++; - dest++; - } + // Copy tile data + for (k = 0; k < 32 * object_size; k++) { + *dest = *src; + src++; + dest++; + } - if (object_size == 6) - { - for (k = 0; k < 32; k++) { - *dest = 0; - dest++; - } - } - } + if (object_size == 6) + { + for (k = 0; k < 32; k++) { + *dest = 0; + dest++; + } + } + } - if (object_size == 6) - { - for (k = 0; k < 256; k++) { - *dest = 0; - dest++; - } - } - } - } + if (object_size == 6) + { + for (k = 0; k < 256; k++) { + *dest = 0; + dest++; + } + } + } + } } u32 GetDecompressedDataSize(const u32 *ptr) From 3617a064d2e4ecb1533e6447c5404fbe7627a884 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Wed, 20 May 2020 19:07:49 -0700 Subject: [PATCH 24/43] Fix TextPrinterDrawDownArrow fakematch --- gflib/text.c | 80 +++++++++++++++++++++++++++------------------------- gflib/text.h | 10 +------ 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/gflib/text.c b/gflib/text.c index f7d71bd00..c5b4dab19 100644 --- a/gflib/text.c +++ b/gflib/text.c @@ -178,7 +178,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi for (i = 0; i < 7; i++) { - gTempTextPrinter.subUnion.fields[i] = 0; + gTempTextPrinter.subStructFields[i] = 0; } gTempTextPrinter.printerTemplate = *printerTemplate; @@ -187,7 +187,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi gTempTextPrinter.japanese = 0; GenerateFontHalfRowLookupTable(printerTemplate->fgColor, printerTemplate->bgColor, printerTemplate->shadowColor); - if (speed != TEXT_SPEED_FF && speed != 0x0) + if (speed != TEXT_SPEED_FF && speed != 0) { --gTempTextPrinter.textSpeed; gTextPrinters[printerTemplate->windowId] = gTempTextPrinter; @@ -1297,11 +1297,11 @@ void ClearTextSpan(struct TextPrinter *textPrinter, u32 width) u16 Font0Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 0; + subStruct->glyphId = 0; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1309,11 +1309,11 @@ u16 Font0Func(struct TextPrinter *textPrinter) u16 Font1Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 1; + subStruct->glyphId = 1; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1321,11 +1321,11 @@ u16 Font1Func(struct TextPrinter *textPrinter) u16 Font2Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 2; + subStruct->glyphId = 2; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1333,11 +1333,11 @@ u16 Font2Func(struct TextPrinter *textPrinter) u16 Font3Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 3; + subStruct->glyphId = 3; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1345,11 +1345,11 @@ u16 Font3Func(struct TextPrinter *textPrinter) u16 Font4Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 4; + subStruct->glyphId = 4; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1357,11 +1357,11 @@ u16 Font4Func(struct TextPrinter *textPrinter) u16 Font5Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 5; + subStruct->glyphId = 5; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1369,11 +1369,11 @@ u16 Font5Func(struct TextPrinter *textPrinter) u16 Font7Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 7; + subStruct->glyphId = 7; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1381,11 +1381,11 @@ u16 Font7Func(struct TextPrinter *textPrinter) u16 Font8Func(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->hasGlyphIdBeenSet == FALSE) { - textPrinter->subUnion.sub.glyphId = 8; + subStruct->glyphId = 8; subStruct->hasGlyphIdBeenSet = TRUE; } return RenderText(textPrinter); @@ -1393,10 +1393,12 @@ u16 Font8Func(struct TextPrinter *textPrinter) void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (gTextFlags.autoScroll == 1) + { subStruct->autoScrollDelay = 0; + } else { subStruct->downArrowYPosIdx = 0; @@ -1406,14 +1408,14 @@ void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter) void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); const u8 *arrowTiles; if (gTextFlags.autoScroll == 0) { if (subStruct->downArrowDelay != 0) { - subStruct->downArrowDelay = ((*(u32*)&textPrinter->subUnion.sub) << 19 >> 27) - 1; // convoluted way of getting downArrowDelay, necessary to match + subStruct->downArrowDelay--; } else { @@ -1422,16 +1424,16 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter) textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY, - 0x8, - 0x10); + 8, + 16); switch (gTextFlags.useAlternateDownArrow) { - case 0: + case FALSE: default: arrowTiles = gDownArrowTiles; break; - case 1: + case TRUE: arrowTiles = gDarkDownArrowTiles; break; } @@ -1440,17 +1442,17 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter) textPrinter->printerTemplate.windowId, arrowTiles, 0, - gDownArrowYCoords[*(u32*)subStruct << 17 >> 30], // subStruct->downArrowYPosIdx but again, stupidly retrieved - 0x8, - 0x10, + gDownArrowYCoords[subStruct->downArrowYPosIdx], + 8, + 16, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY, - 0x8, - 0x10); - CopyWindowToVram(textPrinter->printerTemplate.windowId, 0x2); + 8, + 16); + CopyWindowToVram(textPrinter->printerTemplate.windowId, 2); - subStruct->downArrowDelay = 0x8; - subStruct->downArrowYPosIdx = (*(u32*)subStruct << 17 >> 30) + 1; + subStruct->downArrowDelay = 8; + subStruct->downArrowYPosIdx++; } } } @@ -1462,14 +1464,14 @@ void TextPrinterClearDownArrow(struct TextPrinter *textPrinter) textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY, - 0x8, - 0x10); - CopyWindowToVram(textPrinter->printerTemplate.windowId, 0x2); + 8, + 16); + CopyWindowToVram(textPrinter->printerTemplate.windowId, 2); } bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); if (subStruct->autoScrollDelay == 49) { @@ -1477,7 +1479,7 @@ bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter) } else { - ++subStruct->autoScrollDelay; + subStruct->autoScrollDelay++; return FALSE; } } @@ -1563,7 +1565,7 @@ void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool8 drawArrow, u8 *c u16 RenderText(struct TextPrinter *textPrinter) { - struct TextPrinterSubStruct *subStruct = &textPrinter->subUnion.sub; + struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); u16 currChar; s32 width; s32 widthHelper; diff --git a/gflib/text.h b/gflib/text.h index 51d53bf72..4819eb37b 100644 --- a/gflib/text.h +++ b/gflib/text.h @@ -200,15 +200,7 @@ struct TextPrinter void (*callback)(struct TextPrinterTemplate *, u16); // 0x10 - union -#if !MODERN - __attribute__((packed)) -#endif - { - struct TextPrinterSubStruct sub; - u8 fields[7]; - } subUnion; - + u8 subStructFields[7]; // always cast to struct TextPrinterSubStruct... so why bother u8 active; u8 state; // 0x1C u8 textSpeed; From d301d438c1c48666f6d164ab53753e80cb525575 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Wed, 20 May 2020 19:28:17 -0700 Subject: [PATCH 25/43] Fix the fix --- gflib/text.c | 4 ++-- src/unk_text_util_2.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gflib/text.c b/gflib/text.c index c5b4dab19..6e5af0e12 100644 --- a/gflib/text.c +++ b/gflib/text.c @@ -202,7 +202,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi } if (speed != TEXT_SPEED_FF) - CopyWindowToVram(gTempTextPrinter.printerTemplate.windowId, 2); + CopyWindowToVram(gTempTextPrinter.printerTemplate.windowId, 2); gTextPrinters[printerTemplate->windowId].active = 0; } gUnknown_03002F84 = 0; @@ -215,7 +215,7 @@ void RunTextPrinters(void) if (gUnknown_03002F84 == 0) { - for (i = 0; i < 0x20; ++i) + for (i = 0; i < NUM_TEXT_PRINTERS; ++i) { if (gTextPrinters[i].active) { diff --git a/src/unk_text_util_2.c b/src/unk_text_util_2.c index b1d2264e4..a0b1281a4 100644 --- a/src/unk_text_util_2.c +++ b/src/unk_text_util_2.c @@ -13,13 +13,13 @@ static void DecompressGlyphFont6(u16); u16 Font6Func(struct TextPrinter *textPrinter) { u16 char_; - struct TextPrinterSubStruct *sub; + struct TextPrinterSubStruct *subStruct; + subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - sub = &textPrinter->subUnion.sub; switch (textPrinter->state) { case 0: - if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && sub->hasPrintBeenSpedUp) + if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp) { textPrinter->delayCounter = 0; } @@ -28,7 +28,7 @@ u16 Font6Func(struct TextPrinter *textPrinter) textPrinter->delayCounter --; if (gTextFlags.canABSpeedUpPrint && gMain.newKeys & (A_BUTTON | B_BUTTON)) { - sub->hasPrintBeenSpedUp = TRUE; + subStruct->hasPrintBeenSpedUp = TRUE; textPrinter->delayCounter = 0; } return 3; @@ -81,7 +81,7 @@ u16 Font6Func(struct TextPrinter *textPrinter) textPrinter->printerTemplate.currentChar++; return 2; case 6: - sub->glyphId = *textPrinter->printerTemplate.currentChar; + subStruct->glyphId = *textPrinter->printerTemplate.currentChar; textPrinter->printerTemplate.currentChar++; return 2; case 7: @@ -94,7 +94,7 @@ u16 Font6Func(struct TextPrinter *textPrinter) textPrinter->state = 1; if (gTextFlags.autoScroll) { - sub->autoScrollDelay = 0; + subStruct->autoScrollDelay = 0; } return 3; case 10: From 929e64ad33e29d7951f4836274d0216876bfbc92 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Wed, 20 May 2020 20:31:16 -0700 Subject: [PATCH 26/43] Fix HblankCb_TourneyTree fakematch --- src/battle_dome.c | 126 ++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 59 deletions(-) diff --git a/src/battle_dome.c b/src/battle_dome.c index e4947825d..6f3d111ba 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -5847,66 +5847,74 @@ static void VblankCb_TourneyInfoCard(void) static void HblankCb_TourneyTree(void) { - register u32 vCount asm("r0") = REG_VCOUNT; - register u32 vCount_ asm("r1") = vCount; - if (vCount > 41) - { - if (vCount < 50) - { - REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR - | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; - SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); - return; - } - else if (vCount > 57) - { - if (vCount < 75) - { - REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR - | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; - SET_WIN0H_WIN1H(WIN_RANGE(144, 152), WIN_RANGE(88, 96)); - return; - } - else if (vCount < 82) - { - REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR - | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; - SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); - return; - } - else if (vCount > 94) - { - if (vCount < 103) - { - REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR - | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; - SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); - return; - } - else if (vCount < 119) - { - REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR - | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; - SET_WIN0H_WIN1H(WIN_RANGE(144, 152), WIN_RANGE(88, 96)); - return; - } - else if (vCount > 126) - { - if (vCount_ < 135) - { - REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR - | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; - SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); - return; - } - } - } - } - } + u16 vCount = REG_VCOUNT; - REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ - | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; - SET_WIN0H_WIN1H(0, 0); + if (vCount < 42) + { + REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ + | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; + SET_WIN0H_WIN1H(0, 0); + } + else if (vCount < 50) + { + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR + | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); + } + else if (vCount < 58) + { + REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ + | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; + SET_WIN0H_WIN1H(0, 0); + } + else if (vCount < 75) + { + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR + | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WIN_RANGE(144, 152), WIN_RANGE(88, 96)); + } + else if (vCount < 82) + { + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR + | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); + } + else if (vCount < 95) + { + REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ + | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; + SET_WIN0H_WIN1H(0, 0); + } + else if (vCount < 103) + { + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR + | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); + } + else if (vCount < 119) + { + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR + | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WIN_RANGE(144, 152), WIN_RANGE(88, 96)); + } + else if (vCount < 127) + { + REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ + | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; + SET_WIN0H_WIN1H(0, 0); + } + else if (vCount < 135) + { + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR + | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WIN_RANGE(152, 155), WIN_RANGE(85, 88)); + } + else + { + REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ + | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; + SET_WIN0H_WIN1H(0, 0); + } } static void VblankCb_TourneyTree(void) From ac6bcecdf51531d24143a2afab51572379a0eb24 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Wed, 20 May 2020 21:00:21 -0700 Subject: [PATCH 27/43] Fix mystery gift fakematchings --- src/mystery_gift.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 9da5f060a..06427d2dd 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -1135,9 +1135,9 @@ void task_add_00_mystery_gift(void) void task00_mystery_gift(u8 taskId) { - struct MysteryGiftTaskData * data = (void *)gTasks[taskId].data; - u32 sp0; - const u8 * r1; + struct MysteryGiftTaskData *data = (void *)gTasks[taskId].data; + u32 sp0, flag; + const u8 *r1; switch (data->state) { @@ -1233,12 +1233,10 @@ void task00_mystery_gift(u8 taskId) } break; case 5: - { - register u8 eos asm("r1"); - gStringVar1[0] = (eos = EOS); - gStringVar2[0] = eos; - gStringVar3[0] = eos; - } + *gStringVar1 = EOS; + *gStringVar2 = EOS; + *gStringVar3 = EOS; + switch (data->IsCardOrNews) { case 0: @@ -1306,7 +1304,8 @@ void task00_mystery_gift(u8 taskId) } break; case 9: - switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, mevent_client_get_buffer())) + flag = mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, mevent_client_get_buffer()); + switch (flag) { case 0: mevent_client_set_param(0); @@ -1333,7 +1332,8 @@ void task00_mystery_gift(u8 taskId) } break; case 11: - switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, gText_ThrowAwayWonderCard)) + flag = mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, gText_ThrowAwayWonderCard); + switch (flag) { case 0: if (CheckReceivedGiftFromWonderCard() == TRUE) @@ -1360,7 +1360,8 @@ void task00_mystery_gift(u8 taskId) } break; case 12: - switch ((u32)mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, gText_HaventReceivedCardsGift)) + flag = mevent_message_print_and_prompt_yes_no(&data->textState, &data->curPromptWindowId, FALSE, gText_HaventReceivedCardsGift); + switch (flag) { case 0: mevent_client_set_param(0); @@ -1397,8 +1398,6 @@ void task00_mystery_gift(u8 taskId) } break; case 15: - { - register bool32 flag asm("r1"); r1 = mevent_message(&sp0, data->IsCardOrNews, data->source, data->prevPromptWindowId); if (r1 == NULL) { @@ -1425,7 +1424,7 @@ void task00_mystery_gift(u8 taskId) GenerateRandomNews(2); } } - if (sp0 == 0) + if (!sp0) { data->state = 0; PrintMysteryGiftOrEReaderTopMenu(0, 0); @@ -1436,7 +1435,6 @@ void task00_mystery_gift(u8 taskId) } } break; - } case 16: if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gText_CommunicationError)) { @@ -1624,12 +1622,10 @@ void task00_mystery_gift(u8 taskId) } break; case 31: - { - register u8 eos asm("r1"); - gStringVar1[0] = (eos = EOS); - gStringVar2[0] = eos; - gStringVar3[0] = eos; - } + *gStringVar1 = EOS; + *gStringVar2 = EOS; + *gStringVar3 = EOS; + if (data->IsCardOrNews == 0) { AddTextPrinterToWindow1(gText_SendingWonderCard); From 26a197847acc0a3f01826e84e6704b4782ca66ed Mon Sep 17 00:00:00 2001 From: hondew Date: Wed, 20 May 2020 16:36:00 -0400 Subject: [PATCH 28/43] Rename tag offset functions Fix typo --- include/constants/slot_machine.h | 42 ++++++++ include/slot_machine.h | 15 --- src/field_specials.c | 2 +- src/slot_machine.c | 171 ++++++++++++++----------------- 4 files changed, 119 insertions(+), 111 deletions(-) create mode 100644 include/constants/slot_machine.h diff --git a/include/constants/slot_machine.h b/include/constants/slot_machine.h new file mode 100644 index 000000000..0be0e649b --- /dev/null +++ b/include/constants/slot_machine.h @@ -0,0 +1,42 @@ +#ifndef GUARD_CONSTANTS_SLOT_MACHINE_H +#define GUARD_CONSTANTS_SLOT_MACHINE_H + +#define NUM_REELS 3 +#define REEL_NUM_TAGS 21 +#define REEL_TAG_HEIGHT 24 +#define SLOT_MACHINE_COUNT 12 + +// Lucky Flags +#define LUCKY_BIAS_REPLAY (1 << 0) +#define LUCKY_BIAS_CHERRY (1 << 1) +#define LUCKY_BIAS_LOTAD (1 << 2) +#define LUCKY_BIAS_AZURILL (1 << 3) +#define LUCKY_BIAS_POWER (1 << 4) +#define LUCKY_BIAS_REELTIME (1 << 5) +#define LUCKY_BIAS_MIXED_777 (1 << 6) +#define LUCKY_BIAS_777 (1 << 7) + +#define SLOT_MACHINE_TAG_7_RED 0 +#define SLOT_MACHINE_TAG_7_BLUE 1 +#define SLOT_MACHINE_TAG_AZURILL 2 +#define SLOT_MACHINE_TAG_LOTAD 3 +#define SLOT_MACHINE_TAG_CHERRY 4 +#define SLOT_MACHINE_TAG_POWER 5 +#define SLOT_MACHINE_TAG_REPLAY 6 + +#define SLOT_MACHINE_MATCHED_1CHERRY 0 +#define SLOT_MACHINE_MATCHED_2CHERRY 1 +#define SLOT_MACHINE_MATCHED_REPLAY 2 +#define SLOT_MACHINE_MATCHED_LOTAD 3 +#define SLOT_MACHINE_MATCHED_AZURILL 4 +#define SLOT_MACHINE_MATCHED_POWER 5 +#define SLOT_MACHINE_MATCHED_777_MIXED 6 +#define SLOT_MACHINE_MATCHED_777_RED 7 +#define SLOT_MACHINE_MATCHED_777_BLUE 8 +#define SLOT_MACHINE_MATCHED_NONE 9 + +#define LEFT_REEL 0 +#define MIDDLE_REEL 1 +#define RIGHT_REEL 2 + +#endif // GUARD_CONSTANTS_SLOT_MACHINE_H \ No newline at end of file diff --git a/include/slot_machine.h b/include/slot_machine.h index 1b22e165f..88bbbd91b 100644 --- a/include/slot_machine.h +++ b/include/slot_machine.h @@ -1,21 +1,6 @@ #ifndef GUARD_SLOT_MACHINE_H #define GUARD_SLOT_MACHINE_H -#define NUM_REELS 3 -#define REEL_NUM_TAGS 21 -#define REEL_TAG_HEIGHT 24 -#define SLOT_MACHINE_COUNT 12 - -// Lucky Flags -#define LUCKY_BIAS_REPLAY (1 << 0) -#define LUCKY_BIAS_CHERRY (1 << 1) -#define LUCKY_BIAS_LOTAD (1 << 2) -#define LUCKY_BIAS_AZURILL (1 << 3) -#define LUCKY_BIAS_POWER (1 << 4) -#define LUCKY_BIAS_REELTIME (1 << 5) -#define LUCKY_BIAS_MIXED_777 (1 << 6) -#define LUCKY_BIAS_777 (1 << 7) - void PlaySlotMachine(u8, void (callback)(void)); #endif // GUARD_SLOT_MACHINE_H diff --git a/src/field_specials.c b/src/field_specials.c index 9f1f12a47..64beebcc0 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -35,7 +35,6 @@ #include "rtc.h" #include "script.h" #include "script_menu.h" -#include "slot_machine.h" #include "sound.h" #include "starter_choose.h" #include "string_util.h" @@ -59,6 +58,7 @@ #include "constants/mevent.h" #include "constants/tv.h" #include "constants/script_menu.h" +#include "constants/slot_machine.h" #include "constants/songs.h" #include "constants/species.h" #include "constants/moves.h" diff --git a/src/slot_machine.c b/src/slot_machine.c index 8f117431a..1f3c91989 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -25,6 +25,7 @@ #include "bg.h" #include "window.h" #include "constants/coins.h" +#include "constants/slot_machine.h" // Text extern const u8 gText_YouDontHaveThreeCoins[]; @@ -33,31 +34,6 @@ extern const u8 gText_YouveGot9999Coins[]; extern const u8 gText_YouveRunOutOfCoins[]; extern const u8 gText_ReelTimeHelp[]; -enum -{ - SLOT_MACHINE_TAG_7_RED, - SLOT_MACHINE_TAG_7_BLUE, - SLOT_MACHINE_TAG_AZURILL, - SLOT_MACHINE_TAG_LOTAD, - SLOT_MACHINE_TAG_CHERRY, - SLOT_MACHINE_TAG_POWER, - SLOT_MACHINE_TAG_REPLAY -}; - -enum -{ - SLOT_MACHINE_MATCHED_1CHERRY, - SLOT_MACHINE_MATCHED_2CHERRY, - SLOT_MACHINE_MATCHED_REPLAY, - SLOT_MACHINE_MATCHED_LOTAD, - SLOT_MACHINE_MATCHED_AZURILL, - SLOT_MACHINE_MATCHED_POWER, - SLOT_MACHINE_MATCHED_777_MIXED, - SLOT_MACHINE_MATCHED_777_RED, - SLOT_MACHINE_MATCHED_777_BLUE, - SLOT_MACHINE_MATCHED_NONE -}; - struct SlotMachineEwramStruct { /*0x00*/ u8 state; @@ -81,7 +57,7 @@ struct SlotMachineEwramStruct /*0x1A*/ s16 reelIncrement; // speed of reel /*0x1C*/ s16 reelPixelOffsets[3]; /*0x22*/ u16 reelPixelOffsetsWhileStopping[3]; - /*0x28*/ s16 reelTagOffsets[3]; + /*0x28*/ s16 reelPositions[3]; /*0x2E*/ s16 reelExtraTurns[3]; /*0x34*/ s16 winnerRows[3]; /*0x3A*/ u8 slotReelTasks[3]; @@ -184,7 +160,7 @@ static bool8 IsFinalTask_RunAwardPayoutActions(void); static bool8 AwardPayoutAction0(struct Task *task); static bool8 AwardPayoutAction_GivePayoutToPlayer(struct Task *task); static bool8 AwardPayoutAction_FreeTask(struct Task *task); -static u8 GetNearbyTag_Quantized(u8 x, s16 y); +static u8 GetTagAtRest(u8 x, s16 y); static void GameplayTask_StopSlotReel(void); static void ReelTasks_SetUnkTaskData(u8 a0); static void sub_8102E1C(u8 a0); @@ -890,8 +866,8 @@ static void SlotMachineSetup_0_1(void) for (i = 0; i < NUM_REELS; i++) { sSlotMachine->reelPixelOffsetsWhileStopping[i] = 0; - sSlotMachine->reelTagOffsets[i] = gInitialReelPositions[i][sSlotMachine->luckyGame] % REEL_NUM_TAGS; - sSlotMachine->reelPixelOffsets[i] = REEL_NUM_TAGS * REEL_TAG_HEIGHT - sSlotMachine->reelTagOffsets[i] * REEL_TAG_HEIGHT; + sSlotMachine->reelPositions[i] = gInitialReelPositions[i][sSlotMachine->luckyGame] % REEL_NUM_TAGS; + sSlotMachine->reelPixelOffsets[i] = REEL_NUM_TAGS * REEL_TAG_HEIGHT - sSlotMachine->reelPositions[i] * REEL_TAG_HEIGHT; sSlotMachine->reelPixelOffsets[i] %= REEL_NUM_TAGS * REEL_TAG_HEIGHT; } AlertTVThatPlayerPlayedSlotMachine(GetCoins()); @@ -1598,9 +1574,9 @@ static void CheckMatch_CenterRow(void) { u8 c1, c2, c3, match; - c1 = GetNearbyTag_Quantized(0, 2); - c2 = GetNearbyTag_Quantized(1, 2); - c3 = GetNearbyTag_Quantized(2, 2); + c1 = GetTagAtRest(LEFT_REEL, 2); + c2 = GetTagAtRest(MIDDLE_REEL, 2); + c3 = GetTagAtRest(RIGHT_REEL, 2); match = GetMatchFromSymbolsInRow(c1, c2, c3); if (match != SLOT_MACHINE_MATCHED_NONE) { @@ -1614,9 +1590,9 @@ static void CheckMatch_TopAndBottom(void) { u8 c1, c2, c3, match; - c1 = GetNearbyTag_Quantized(0, 1); - c2 = GetNearbyTag_Quantized(1, 1); - c3 = GetNearbyTag_Quantized(2, 1); + c1 = GetTagAtRest(LEFT_REEL, 1); + c2 = GetTagAtRest(MIDDLE_REEL, 1); + c3 = GetTagAtRest(RIGHT_REEL, 1); match = GetMatchFromSymbolsInRow(c1, c2, c3); if (match != SLOT_MACHINE_MATCHED_NONE) { @@ -1626,9 +1602,9 @@ static void CheckMatch_TopAndBottom(void) sSlotMachine->matchedSymbols |= gSlotMatchFlags[match]; sub_8103E04(1); } - c1 = GetNearbyTag_Quantized(0, 3); - c2 = GetNearbyTag_Quantized(1, 3); - c3 = GetNearbyTag_Quantized(2, 3); + c1 = GetTagAtRest(LEFT_REEL, 3); + c2 = GetTagAtRest(MIDDLE_REEL, 3); + c3 = GetTagAtRest(RIGHT_REEL, 3); match = GetMatchFromSymbolsInRow(c1, c2, c3); if (match != SLOT_MACHINE_MATCHED_NONE) { @@ -1644,9 +1620,9 @@ static void CheckMatch_Diagonals(void) { u8 c1, c2, c3, match; - c1 = GetNearbyTag_Quantized(0, 1); - c2 = GetNearbyTag_Quantized(1, 2); - c3 = GetNearbyTag_Quantized(2, 3); + c1 = GetTagAtRest(LEFT_REEL, 1); + c2 = GetTagAtRest(MIDDLE_REEL, 2); + c3 = GetTagAtRest(RIGHT_REEL, 3); match = GetMatchFromSymbolsInRow(c1, c2, c3); if (match != SLOT_MACHINE_MATCHED_NONE) { @@ -1657,9 +1633,9 @@ static void CheckMatch_Diagonals(void) } sub_8103E04(3); } - c1 = GetNearbyTag_Quantized(0, 3); - c2 = GetNearbyTag_Quantized(1, 2); - c3 = GetNearbyTag_Quantized(2, 1); + c1 = GetTagAtRest(LEFT_REEL, 3); + c2 = GetTagAtRest(MIDDLE_REEL, 2); + c3 = GetTagAtRest(RIGHT_REEL, 1); match = GetMatchFromSymbolsInRow(c1, c2, c3); if (match != SLOT_MACHINE_MATCHED_NONE) { @@ -1751,25 +1727,30 @@ static bool8 AwardPayoutAction_FreeTask(struct Task *task) return FALSE; } - -// Returns the tag that is posOffset below the tag at the top of reelIndex's tape -static u8 GetNearbyTag_Quantized(u8 reelIndex, s16 posOffset) +// Get the tag at position `offset` below the top of the reel window +// .-----------------. +// | 7RD | 7RD | 7RD | <- offset = 0 +// /-----|-----|-----\ +// screen -> | CHY | CHY | POW | <- offset = 1 +// | AZU | REP | 7BL | <- offset = 2 +// | REP | LOT | REP | <- offset = 3 +// \-----|-----|-----/ +static u8 GetTagAtRest(u8 reel, s16 offset) { - s16 tagIndex = (sSlotMachine->reelTagOffsets[reelIndex] + posOffset) % REEL_NUM_TAGS; - if (tagIndex < 0) - tagIndex += REEL_NUM_TAGS; - return gReelSymbols[reelIndex][tagIndex]; + s16 pos = (sSlotMachine->reelPositions[reel] + offset) % REEL_NUM_TAGS; + if (pos < 0) + pos += REEL_NUM_TAGS; + return gReelSymbols[reel][pos]; } - -// Calculates GetNearbyTag_Quantized as if the reel was snapped downwards into place -static u8 GetNearbyTag(u8 reelIndex, s16 posOffset) +// Calculates GetTagAtRest as if the reel were snapped downwards into place. +static u8 GetTag(u8 reel, s16 offset) { - s16 tagOffset = 0; - s16 result = sSlotMachine->reelPixelOffsets[reelIndex] % 24; - if (result != 0) - tagOffset = -1; - return GetNearbyTag_Quantized(reelIndex, posOffset + tagOffset); + s16 inc = 0; + s16 pixelOffset = sSlotMachine->reelPixelOffsets[reel] % REEL_TAG_HEIGHT; + if (pixelOffset != 0) + inc = -1; + return GetTagAtRest(reel, offset + inc); } static u8 GetNearbyReelTimeTag(s16 n) @@ -1784,7 +1765,7 @@ static void AdvanceSlotReel(u8 reelIndex, s16 value) { sSlotMachine->reelPixelOffsets[reelIndex] += value; sSlotMachine->reelPixelOffsets[reelIndex] %= 504; - sSlotMachine->reelTagOffsets[reelIndex] = REEL_NUM_TAGS - sSlotMachine->reelPixelOffsets[reelIndex] / 24; + sSlotMachine->reelPositions[reelIndex] = REEL_NUM_TAGS - sSlotMachine->reelPixelOffsets[reelIndex] / 24; } s16 AdvanceSlotReelToNextTag(u8 reelIndex, s16 value) @@ -1940,7 +1921,7 @@ static bool8 DecideReelTurns_BiasTag_Reel1(void) static bool8 AreTagsAtPosition_Reel1(s16 pos, u8 tag1, u8 tag2) { - u8 tag = GetNearbyTag(0, pos); + u8 tag = GetTag(LEFT_REEL, pos); if (tag == tag1 || tag == tag2) { sSlotMachine->biasTag = tag; @@ -1951,7 +1932,7 @@ static bool8 AreTagsAtPosition_Reel1(s16 pos, u8 tag1, u8 tag2) static bool8 AreCherriesOnScreen_Reel1(s16 offsetFromCenter) { - if (GetNearbyTag(0, 1 - offsetFromCenter) == SLOT_MACHINE_TAG_CHERRY || GetNearbyTag(0, 2 - offsetFromCenter) == SLOT_MACHINE_TAG_CHERRY || GetNearbyTag(0, 3 - offsetFromCenter) == SLOT_MACHINE_TAG_CHERRY) + if (GetTag(LEFT_REEL, 1 - offsetFromCenter) == SLOT_MACHINE_TAG_CHERRY || GetTag(LEFT_REEL, 2 - offsetFromCenter) == SLOT_MACHINE_TAG_CHERRY || GetTag(LEFT_REEL, 3 - offsetFromCenter) == SLOT_MACHINE_TAG_CHERRY) return TRUE; else return FALSE; @@ -2046,7 +2027,7 @@ static bool8 DecideReelTurns_BiasTag_Reel2_Bet1or2(void) for (i = 0; i < 5; i++) { // if biasTag appears in the same row within 4 turns - if (GetNearbyTag(1, biasTagLocation_Reel1 - i) == sSlotMachine->biasTag) + if (GetTag(MIDDLE_REEL, biasTagLocation_Reel1 - i) == sSlotMachine->biasTag) { sSlotMachine->winnerRows[1] = biasTagLocation_Reel1; sSlotMachine->reelExtraTurns[1] = i; @@ -2068,7 +2049,7 @@ static bool8 DecideReelTurns_BiasTag_Reel2_Bet3(void) for (i = 0; i < 5; i++) { //...and if the bias tag will appear in the middle row within 4 turns - if (GetNearbyTag(1, 2 - i) == sSlotMachine->biasTag) + if (GetTag(MIDDLE_REEL, 2 - i) == sSlotMachine->biasTag) { sSlotMachine->winnerRows[1] = 2; sSlotMachine->reelExtraTurns[1] = i; @@ -2084,7 +2065,7 @@ static bool8 DecideReelTurns_BiasTag_Reel2_Bet3(void) for (i = 0; i < 5; i++) { //...and if the biasTag will appear in the center row of reel 2 within 4 turns - if (GetNearbyTag(1, 2 - i) == sSlotMachine->biasTag) + if (GetTag(MIDDLE_REEL, 2 - i) == sSlotMachine->biasTag) { sSlotMachine->winnerRows[1] = 2; sSlotMachine->reelExtraTurns[1] = i; @@ -2117,7 +2098,7 @@ static bool8 DecideReelTurns_BiasTag_Reel3_Bet1or2(u8 biasTag) for (i = 0; i < 5; i++) { // if the biasTag appears in the same row as in reel 2 within 4 turns - if (GetNearbyTag(2, biasTagLocation_Reel2 - i) == biasTag) + if (GetTag(RIGHT_REEL, biasTagLocation_Reel2 - i) == biasTag) { sSlotMachine->winnerRows[2] = biasTagLocation_Reel2; sSlotMachine->reelExtraTurns[2] = i; @@ -2143,7 +2124,7 @@ static bool8 DecideReelTurns_BiasTag_Reel3_Bet3(u8 biasTag) for (i = 0; i < 5; i++) { // if the biasTag lands in that position within 4 turns - if (GetNearbyTag(2, biasTagFinalPos - i) == biasTag) + if (GetTag(RIGHT_REEL, biasTagFinalPos - i) == biasTag) { sSlotMachine->reelExtraTurns[2] = i; sSlotMachine->winnerRows[2] = biasTagFinalPos; @@ -2189,7 +2170,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet1(void) { if (sSlotMachine->winnerRows[0] != 0 && sSlotMachine->luckyFlags & LUCKY_BIAS_777) { - u8 biasTag = GetNearbyTag(0, 2 - sSlotMachine->reelExtraTurns[0]); + u8 biasTag = GetTag(LEFT_REEL, 2 - sSlotMachine->reelExtraTurns[0]); //...and if biasTag is one of the 7's... if (IsBiasTag777_SwitchColor(&biasTag)) //...swap color of biasTag... @@ -2198,7 +2179,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet1(void) for (i = 0; i < 5; i++) { //...and if the biasTag appears within 4 turns - if (biasTag == GetNearbyTag(1, 2 - i)) + if (biasTag == GetTag(MIDDLE_REEL, 2 - i)) { sSlotMachine->winnerRows[1] = 2; sSlotMachine->reelExtraTurns[1] = i; @@ -2213,7 +2194,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet2(void) { if (sSlotMachine->winnerRows[0] != 0 && sSlotMachine->luckyFlags & LUCKY_BIAS_777) { - u8 biasTag = GetNearbyTag(0, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); + u8 biasTag = GetTag(LEFT_REEL, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); //...and if biasTag is one of the 7's... if (IsBiasTag777_SwitchColor(&biasTag)) //...swap color of biasTag... @@ -2222,7 +2203,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet2(void) for (i = 0; i < 5; i++) { //...and if the biasTag appears in same row in reel 2 within 4 turns - if (biasTag == GetNearbyTag(1, sSlotMachine->winnerRows[0] - i)) + if (biasTag == GetTag(MIDDLE_REEL, sSlotMachine->winnerRows[0] - i)) { sSlotMachine->winnerRows[1] = sSlotMachine->winnerRows[0]; sSlotMachine->reelExtraTurns[1] = i; @@ -2247,7 +2228,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet3(void) } else { - u8 biasTag = GetNearbyTag(0, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); + u8 biasTag = GetTag(LEFT_REEL, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); //...and if biasTag is one of the 7's... if (IsBiasTag777_SwitchColor(&biasTag)) //...swap the color of the 7... @@ -2257,7 +2238,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet3(void) j = 3; for (i = 0; i < 2; i++, j--) { - if (biasTag == GetNearbyTag(1, j)) + if (biasTag == GetTag(MIDDLE_REEL, j)) { sSlotMachine->winnerRows[1] = j; sSlotMachine->reelExtraTurns[1] = 0; @@ -2266,7 +2247,7 @@ static void DecideReelTurns_NoBiasTag_Reel2_Bet3(void) } for (j = 1; j < 5; j++) { - if (biasTag == GetNearbyTag(1, sSlotMachine->winnerRows[0] - j)) + if (biasTag == GetTag(MIDDLE_REEL, sSlotMachine->winnerRows[0] - j)) { if (sSlotMachine->winnerRows[0] == 1) { @@ -2340,8 +2321,8 @@ static void DecideReelTurns_NoBiasTag_Reel3(void) static void DecideReelTurns_NoBiasTag_Reel3_Bet1(void) { s16 i = 0; - u8 tag1 = GetNearbyTag(0, 2 - sSlotMachine->reelExtraTurns[0]); - u8 tag2 = GetNearbyTag(1, 2 - sSlotMachine->reelExtraTurns[1]); + u8 tag1 = GetTag(LEFT_REEL, 2 - sSlotMachine->reelExtraTurns[0]); + u8 tag2 = GetTag(MIDDLE_REEL, 2 - sSlotMachine->reelExtraTurns[1]); // if tags match in first 2 reels... if (tag1 == tag2) { @@ -2349,7 +2330,7 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet1(void) while (1) { u8 tag3; - if (!(tag1 == (tag3 = GetNearbyTag(2, 2 - i)) || (tag1 == SLOT_MACHINE_TAG_7_RED && tag3 == SLOT_MACHINE_TAG_7_BLUE) || (tag1 == SLOT_MACHINE_TAG_7_BLUE && tag3 == SLOT_MACHINE_TAG_7_RED))) + if (!(tag1 == (tag3 = GetTag(RIGHT_REEL, 2 - i)) || (tag1 == SLOT_MACHINE_TAG_7_RED && tag3 == SLOT_MACHINE_TAG_7_BLUE) || (tag1 == SLOT_MACHINE_TAG_7_BLUE && tag3 == SLOT_MACHINE_TAG_7_RED))) break; i++; } @@ -2361,7 +2342,7 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet1(void) //...see if you can match with reel 1 within 4 turns for (i = 0; i < 5; i++) { - if (tag1 == GetNearbyTag(2, 2 - i)) + if (tag1 == GetTag(RIGHT_REEL, 2 - i)) { sSlotMachine->reelExtraTurns[2] = i; return; @@ -2372,7 +2353,7 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet1(void) i = 0; while (1) { - if (tag1 != GetNearbyTag(2, 2 - i)) + if (tag1 != GetTag(RIGHT_REEL, 2 - i)) break; i++; } @@ -2389,15 +2370,15 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet2(void) u8 tag3; if (sSlotMachine->winnerRows[1] != 0 && sSlotMachine->winnerRows[0] == sSlotMachine->winnerRows[1] && sSlotMachine->luckyFlags & LUCKY_BIAS_777) { - tag1 = GetNearbyTag(0, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); - tag2 = GetNearbyTag(1, sSlotMachine->winnerRows[1] - sSlotMachine->reelExtraTurns[1]); + tag1 = GetTag(LEFT_REEL, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); + tag2 = GetTag(MIDDLE_REEL, sSlotMachine->winnerRows[1] - sSlotMachine->reelExtraTurns[1]); //...and if tags are mixed 7s... if (AreTagsMixed77(tag1, tag2)) { //...try to match with reel 1 within 4 turns for (i = 0; i < 5; i++) { - tag3 = GetNearbyTag(2, sSlotMachine->winnerRows[1] - i); + tag3 = GetTag(RIGHT_REEL, sSlotMachine->winnerRows[1] - i); if (tag1 == tag3) { extraTurns = i; @@ -2412,9 +2393,9 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet2(void) s16 loopExit; for (i = 1, loopExit = 0; i < 4; i++) { - tag1 = GetNearbyTag(0, i - sSlotMachine->reelExtraTurns[0]); // why does this update with i - tag2 = GetNearbyTag(1, i - sSlotMachine->reelExtraTurns[1]); - tag3 = GetNearbyTag(2, i - extraTurns); + tag1 = GetTag(LEFT_REEL, i - sSlotMachine->reelExtraTurns[0]); // why does this update with i + tag2 = GetTag(MIDDLE_REEL, i - sSlotMachine->reelExtraTurns[1]); + tag3 = GetTag(RIGHT_REEL, i - extraTurns); // if bit 7 of luckyFlags is unset... //...and if all 3 tags match and they're not mixed 7s if (!TagsDontMatchOrHaveAny7s(tag1, tag2, tag3) && (!AreTagsMixed777(tag1, tag2, tag3) || !(sSlotMachine->luckyFlags & LUCKY_BIAS_777))) @@ -2441,8 +2422,8 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet3(void) DecideReelTurns_NoBiasTag_Reel3_Bet2(); if (sSlotMachine->winnerRows[1] != 0 && sSlotMachine->winnerRows[0] != sSlotMachine->winnerRows[1] && sSlotMachine->luckyFlags & LUCKY_BIAS_777) { - tag1 = GetNearbyTag(0, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); - tag2 = GetNearbyTag(1, sSlotMachine->winnerRows[1] - sSlotMachine->reelExtraTurns[1]); + tag1 = GetTag(LEFT_REEL, sSlotMachine->winnerRows[0] - sSlotMachine->reelExtraTurns[0]); + tag2 = GetTag(MIDDLE_REEL, sSlotMachine->winnerRows[1] - sSlotMachine->reelExtraTurns[1]); //..and if tags are mixed 7s... if (AreTagsMixed77(tag1, tag2)) { @@ -2451,7 +2432,7 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet3(void) j = 3; for (i = 0; i < 5; i++) { - tag3 = GetNearbyTag(2, j - (sSlotMachine->reelExtraTurns[2] + i)); + tag3 = GetTag(RIGHT_REEL, j - (sSlotMachine->reelExtraTurns[2] + i)); if (tag1 == tag3) { sSlotMachine->reelExtraTurns[2] += i; @@ -2462,18 +2443,18 @@ static void DecideReelTurns_NoBiasTag_Reel3_Bet3(void) } while (1) { - tag1 = GetNearbyTag(0, 1 - sSlotMachine->reelExtraTurns[0]); - tag2 = GetNearbyTag(1, 2 - sSlotMachine->reelExtraTurns[1]); - tag3 = GetNearbyTag(2, 3 - sSlotMachine->reelExtraTurns[2]); + tag1 = GetTag(LEFT_REEL, 1 - sSlotMachine->reelExtraTurns[0]); + tag2 = GetTag(MIDDLE_REEL, 2 - sSlotMachine->reelExtraTurns[1]); + tag3 = GetTag(RIGHT_REEL, 3 - sSlotMachine->reelExtraTurns[2]); if (TagsDontMatchOrHaveAny7s(tag1, tag2, tag3) || (AreTagsMixed777(tag1, tag2, tag3) && sSlotMachine->luckyFlags & LUCKY_BIAS_777)) break; sSlotMachine->reelExtraTurns[2]++; } while (1) { - tag1 = GetNearbyTag(0, 3 - sSlotMachine->reelExtraTurns[0]); - tag2 = GetNearbyTag(1, 2 - sSlotMachine->reelExtraTurns[1]); - tag3 = GetNearbyTag(2, 1 - sSlotMachine->reelExtraTurns[2]); + tag1 = GetTag(LEFT_REEL, 3 - sSlotMachine->reelExtraTurns[0]); + tag2 = GetTag(MIDDLE_REEL, 2 - sSlotMachine->reelExtraTurns[1]); + tag3 = GetTag(RIGHT_REEL, 1 - sSlotMachine->reelExtraTurns[2]); if (TagsDontMatchOrHaveAny7s(tag1, tag2, tag3) || (AreTagsMixed777(tag1, tag2, tag3) && sSlotMachine->luckyFlags & LUCKY_BIAS_777)) break; sSlotMachine->reelExtraTurns[2]++; @@ -3314,7 +3295,7 @@ static void sub_8104F18(struct Sprite *sprite) sprite->data[2] = sSlotMachine->reelPixelOffsets[sprite->data[0]] + sprite->data[1]; sprite->data[2] %= 120; sprite->pos1.y = sSlotMachine->reelPixelOffsetsWhileStopping[sprite->data[0]] + 28 + sprite->data[2]; - sprite->sheetTileStart = GetSpriteTileStartByTag(GetNearbyTag_Quantized(sprite->data[0], sprite->data[2] / 24)); + sprite->sheetTileStart = GetSpriteTileStartByTag(GetTagAtRest(sprite->data[0], sprite->data[2] / 24)); SetSpriteSheetFrameTileNum(sprite); } From cfc47e642fab396bb05cf8672bc4daf08da196e5 Mon Sep 17 00:00:00 2001 From: hondew Date: Wed, 20 May 2020 17:57:11 -0400 Subject: [PATCH 29/43] Clean up slot drawing Fix typos --- include/constants/slot_machine.h | 2 +- src/slot_machine.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/constants/slot_machine.h b/include/constants/slot_machine.h index 0be0e649b..9ecf46d79 100644 --- a/include/constants/slot_machine.h +++ b/include/constants/slot_machine.h @@ -1,7 +1,7 @@ #ifndef GUARD_CONSTANTS_SLOT_MACHINE_H #define GUARD_CONSTANTS_SLOT_MACHINE_H -#define NUM_REELS 3 +#define NUM_REELS 3 #define REEL_NUM_TAGS 21 #define REEL_TAG_HEIGHT 24 #define SLOT_MACHINE_COUNT 12 diff --git a/src/slot_machine.c b/src/slot_machine.c index 1f3c91989..9e94d11f0 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -1727,14 +1727,18 @@ static bool8 AwardPayoutAction_FreeTask(struct Task *task) return FALSE; } -// Get the tag at position `offset` below the top of the reel window +// Get the tag at position `offset` below the top of the reel's tape. Note that +// if `offset` is negative, it wraps around to the bottom of the tape. // .-----------------. -// | 7RD | 7RD | 7RD | <- offset = 0 +// | [ ] | [ ] | [ ] | <- offset = 0 // /-----|-----|-----\ -// screen -> | CHY | CHY | POW | <- offset = 1 -// | AZU | REP | 7BL | <- offset = 2 -// | REP | LOT | REP | <- offset = 3 +// screen -> | [ ] | [ ] | [ ] | <- offset = 1 +// | [ ] | [ ] | [ ] | <- offset = 2 +// | [ ] | [ ] | [ ] | <- offset = 3 // \-----|-----|-----/ +// | ... | ... | ... | +// | [ ] | [ ] | [ ] | <- offset = 20 +// .-----------------. static u8 GetTagAtRest(u8 reel, s16 offset) { s16 pos = (sSlotMachine->reelPositions[reel] + offset) % REEL_NUM_TAGS; From b29c7554ea9cfc0c2bbb5de969bb6672451f4273 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 21 May 2020 12:47:16 -0400 Subject: [PATCH 30/43] Match sub_8022250 --- src/berry_crush.c | 112 ++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 58 deletions(-) diff --git a/src/berry_crush.c b/src/berry_crush.c index a67d1548e..bb1ccd17c 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -322,7 +322,7 @@ static const u8 sBerryCrushTextColorTable[][3] = }; -static const struct WindowTemplate gUnknown_082F32EC = +static const struct WindowTemplate sWindowTemplate_BerryCrushRankings = { .bg = 0, .tilemapLeft = 3, @@ -421,7 +421,7 @@ static const u8 gUnknown_082F3344[][4] = {12, 14, 15, 16}, }; -static const u32 gUnknown_082F334C[] = +static const u32 sPressingSpeedConversionTable[] = { 50000000 / (1 << 0), 50000000 / (1 << 1), @@ -1388,7 +1388,7 @@ void sub_8021944(struct BerryCrushGame_138 *arg0, u16 arg1) for (i = 0; i < 8; i++) { if ((r3 >> (7 - i)) & 1) - r7 += gUnknown_082F334C[i]; + r7 += sPressingSpeedConversionTable[i]; } arg0->unk8 = r7 / 1000000; @@ -1442,7 +1442,7 @@ void sub_8021A28(struct BerryCrushGame * sp0C, u8 sp10, u8 sp14, u8 sp18) r7 = sp24->as_four_players.unk00.unk0C[sp10][r8] & 15; for (r2 = 0; r2 < 4; ++r2) if ((r7 >> (3 - r2)) & 1) - r3 += gUnknown_082F334C[r2]; + r3 += sPressingSpeedConversionTable[r2]; r7 = r3 / 1000000u; ConvertIntToDecimalStringN(gStringVar2, r7, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(gStringVar4, gUnknown_082F43B4[sp10]); @@ -1499,7 +1499,7 @@ void sub_8021D34(struct BerryCrushGame *r8) AddTextPrinterParameterized3(r8->unk138.unk82, 2, r6, r7, sBerryCrushTextColorTable[0], 0, gText_TimesPerSec); for (; r10 < 8; ++r10) if (((u8)r8->unk16 >> (7 - r10)) & 1) - sp0C += *(r10 + gUnknown_082F334C); // It's accessed in a different way here for unknown reason + sp0C += *(r10 + sPressingSpeedConversionTable); // It's accessed in a different way here for unknown reason ConvertIntToDecimalStringN(gStringVar1, r8->unk16 >> 8, STR_CONV_MODE_RIGHT_ALIGN, 3); ConvertIntToDecimalStringN(gStringVar2, sp0C / 1000000, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(gStringVar4, gText_XDotY3); @@ -1580,93 +1580,89 @@ void sub_802222C(struct BerryCrushGame *r4) sub_8022600(r4); } -void sub_8022250(u8 r4) +static void Task_ShowBerryCrushRankings(u8 taskId) { - u8 r9 = 0, r2, r7, r10; - u32 sp0C = 0; - s16 *r6 = gTasks[r4].data; - const u8 *r10_; // turn r5/sl register swap into r8/sl + u8 i = 0, j, xPos, yPos; + u32 score = 0; + s16 *data = gTasks[taskId].data; + u8 *str; - switch (r6[0]) + switch (data[0]) { case 0: - r6[1] = AddWindow(&gUnknown_082F32EC); - PutWindowTilemap((u8)r6[1]); - FillWindowPixelBuffer((u8)r6[1], PIXEL_FILL(0)); - LoadUserWindowBorderGfx_((u8)r6[1], 541, 208); - DrawStdFrameWithCustomTileAndPalette((u8)r6[1], 0, 541, 13); + data[1] = AddWindow(&sWindowTemplate_BerryCrushRankings); + PutWindowTilemap(data[1]); + FillWindowPixelBuffer(data[1], PIXEL_FILL(0)); + LoadUserWindowBorderGfx_(data[1], 541, 208); + DrawStdFrameWithCustomTileAndPalette(data[1], 0, 541, 13); break; case 1: - r10_ = gText_BerryCrush2; - ++r10_; --r10_; // swap sb/sl - #ifndef NONMATCHING - asm("":::"r8"); // turn r8/sl register swap into sb/sl - #endif - r7 = 96 - GetStringWidth(1, r10_, -1) / 2u; + xPos = 96 - GetStringWidth(1, gText_BerryCrush2, -1) / 2u; AddTextPrinterParameterized3( - (u8)r6[1], + data[1], 1, - r7, + xPos, 1, sBerryCrushTextColorTable[3], 0, - r10_ + gText_BerryCrush2 ); - r10_ = gText_PressingSpeedRankings; - r7 = 96 - GetStringWidth(1, r10_, -1) / 2u; + xPos = 96 - GetStringWidth(1, gText_PressingSpeedRankings, -1) / 2u; AddTextPrinterParameterized3( - (u8)r6[1], + data[1], 1, - r7, + xPos, 17, sBerryCrushTextColorTable[3], 0, - r10_ + gText_PressingSpeedRankings ); - r10 = 41; - for (; r9 < 4; ++r9) + yPos = 41; + for (i = 0; i < 4; ++i) { - ConvertIntToDecimalStringN(gStringVar1, r9 + 2, STR_CONV_MODE_LEFT_ALIGN, 1); + ConvertIntToDecimalStringN(gStringVar1, i + 2, STR_CONV_MODE_LEFT_ALIGN, 1); StringExpandPlaceholders(gStringVar4, gText_Var1Players); AddTextPrinterParameterized3( - (u8)r6[1], + data[1], 1, 0, - r10, + yPos, sBerryCrushTextColorTable[0], 0, gStringVar4 ); - r7 = 192 - (u8)GetStringWidth(1, gText_TimesPerSec, -1); + xPos = 192 - (u8)GetStringWidth(1, gText_TimesPerSec, -1); AddTextPrinterParameterized3( - (u8)r6[1], + data[1], 1, - r7, - r10, + xPos, + yPos, sBerryCrushTextColorTable[0], 0, gText_TimesPerSec ); - for (r2 = 0; r2 < 8; ++r2) - if (((u8)r6[r9 + 2] >> (7 - r2)) & 1) - sp0C += gUnknown_082F334C[r2]; - ConvertIntToDecimalStringN(gStringVar1, (u16)r6[r9 + 2] >> 8, STR_CONV_MODE_RIGHT_ALIGN, 3); - ConvertIntToDecimalStringN(gStringVar2, sp0C / 1000000, STR_CONV_MODE_LEADING_ZEROS, 2); + for (j = 0; j < 8; ++j) + { + if (((data[i + 2] & 0xFF) >> (7 - j)) & 1) + score += sPressingSpeedConversionTable[j]; + } + ConvertIntToDecimalStringN(gStringVar1, (u16)data[i + 2] >> 8, STR_CONV_MODE_RIGHT_ALIGN, 3); + ConvertIntToDecimalStringN(gStringVar2, score / 1000000, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(gStringVar4, gText_XDotY3); - r7 -= GetStringWidth(1, gStringVar4, -1); + xPos -= GetStringWidth(1, gStringVar4, -1); AddTextPrinterParameterized3( - (u8)r6[1], + data[1], 1, - r7, - r10, + xPos, + yPos, sBerryCrushTextColorTable[0], 0, gStringVar4 ); - r10 += 16; - sp0C = 0; + yPos += 16; + score = 0; } - CopyWindowToVram((u8)r6[1], 3); + CopyWindowToVram(data[1], 3); break; case 2: if (gMain.newKeys & (A_BUTTON | B_BUTTON)) @@ -1674,16 +1670,16 @@ void sub_8022250(u8 r4) else return; case 3: - ClearStdWindowAndFrameToTransparent((u8)r6[1], 1); - ClearWindowTilemap((u8)r6[1]); - RemoveWindow((u8)r6[1]); - DestroyTask(r4); + ClearStdWindowAndFrameToTransparent(data[1], 1); + ClearWindowTilemap(data[1]); + RemoveWindow(data[1]); + DestroyTask(taskId); EnableBothScriptContexts(); ScriptContext2_Disable(); - r6[0] = 0; + data[0] = 0; return; } - ++r6[0]; + ++data[0]; } void ShowBerryCrushRankings(void) @@ -1691,7 +1687,7 @@ void ShowBerryCrushRankings(void) u8 taskId; ScriptContext2_Enable(); - taskId = CreateTask(sub_8022250, 0); + taskId = CreateTask(Task_ShowBerryCrushRankings, 0); gTasks[taskId].data[2] = gSaveBlock2Ptr->berryCrush.berryCrushResults[0]; gTasks[taskId].data[3] = gSaveBlock2Ptr->berryCrush.berryCrushResults[1]; gTasks[taskId].data[4] = gSaveBlock2Ptr->berryCrush.berryCrushResults[2]; From 89350cb81aeb58df4d71ad37154f93dbc4208244 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 21 May 2020 12:49:41 -0400 Subject: [PATCH 31/43] Clean up sub_8022C58 --- src/berry_crush.c | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/berry_crush.c b/src/berry_crush.c index bb1ccd17c..d4bdd47dc 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -206,7 +206,7 @@ void sub_8022554(struct BerryCrushGame_138 *r0); void sub_8024578(struct BerryCrushGame *); void sub_8024644(u8 *, u32, u32, u32, u32); static void sub_8022A20(struct Sprite *sprite); -static u32 sub_8022C58(struct BerryCrushGame *r6, u8 *r1); +static u32 BerryCrushCommand_BeginNormalPaletteFade(struct BerryCrushGame *r6, u8 *r1); static u32 sub_8022CB0(struct BerryCrushGame *r4, u8 *r5); static u32 sub_8022D14(struct BerryCrushGame *r7, u8 *r5); static u32 sub_8022E1C(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1); @@ -767,7 +767,7 @@ static const u8 *const gUnknown_082F43B4[] = static u32 (*const gUnknown_082F43CC[])(struct BerryCrushGame *, u8 *) = { NULL, - sub_8022C58, + BerryCrushCommand_BeginNormalPaletteFade, sub_8022CB0, sub_8022D14, sub_8022E1C, @@ -1975,39 +1975,42 @@ void sub_8022BEC(u16 r5, u8 r4, u8 *r7) } } -static u32 sub_8022C58(struct BerryCrushGame *r6, u8 *r1) +static u32 BerryCrushCommand_BeginNormalPaletteFade(struct BerryCrushGame *game, u8 *params) { - u16 r4; - u32 r0; -#ifndef NONMATCHING // fake match, nobody can write such code - register u32 r2 asm("r2"); - register u32 r3 asm("r3"); + // params points to packed values: + // bytes 0-3: selectedPals (bitfield) + // byte 4: delay + // byte 5: startY + // byte 6: stopY + // bytes 7-8: fade color + // byte 9: if TRUE, communicate on fade complete - r2 = r1[0]; - r3 = r1[1]; - r3 <<= 8; - r2 |= r3; - r3 = r1[2]; - r3 <<= 16; - r2 |= r3; - r3 = r1[3]; - r3 <<= 24; - r0 = r2; - r0 |= r3; + u16 color; + u32 selectedPals; + selectedPals = ({ +#ifndef NONMATCHING + register u32 value asm("r2"); + register u32 b asm("r3"); #else - u32 r2; + u32 value; + u32 b; +#endif //NONMATCHING + value = params[0] << 0; + value |= (b = params[1] << 8); + value |= (b = params[2] << 16); + value |= (b = params[3] << 24); + value; + }); + + params[0] = params[9]; + + color = params[8] << 8; + color |= params[7] << 0; - r0 = T1_READ_32(r1); -#endif - r2 = r1[9]; - r1[0] = r2; - r4 = r1[8] << 8; - r2 = r1[7]; - r4 |= r2; gPaletteFade.bufferTransferDisabled = FALSE; - BeginNormalPaletteFade(r0, r1[4], r1[5], r1[6], r4); + BeginNormalPaletteFade(selectedPals, params[4], params[5], params[6], color); UpdatePaletteFade(); - r6->unkE = 2; + game->unkE = 2; return 0; } From 5019381911233c7055f3646c537e16638137ddff Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 21 May 2020 12:55:02 -0400 Subject: [PATCH 32/43] Match sub_8024604 --- src/berry_crush.c | 73 +++++++++-------------------------------------- 1 file changed, 14 insertions(+), 59 deletions(-) diff --git a/src/berry_crush.c b/src/berry_crush.c index d4bdd47dc..0593f53eb 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -193,7 +193,7 @@ static void sub_8020F88(void); static void sub_8020FA0(u8); void sub_8020FC4(struct BerryCrushGame *); void sub_8022BEC(u16, u8, u8 *); -void sub_8024604(u8 *, u32, s32, u32, u32, u32, u32); +static void BerryCrush_SetPaletteFadeParams(u8 *, bool8, u32, s8, u8, u8, u16); static int sub_8021450(struct BerryCrushGame *); void sub_8022588(struct BerryCrushGame *); void sub_8022600(struct BerryCrushGame *); @@ -874,7 +874,7 @@ void sub_8020C70(MainCallback callback) gUnknown_02022C90->unk12 = 1; gUnknown_02022C90->unkE = 1; gUnknown_02022C90->unkF = 6; - sub_8024604(gUnknown_02022C90->unk36, 1, -1, 0, 16, 0, 0); + BerryCrush_SetPaletteFadeParams(gUnknown_02022C90->unk36, 1, -1, 0, 16, 0, 0); sub_8022BEC(4, 1, gUnknown_02022C90->unk36); SetMainCallback2(sub_8020F88); gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); @@ -891,7 +891,7 @@ static void sub_8020D8C(void) gUnknown_02022C90->unk68.as_four_players.others[gUnknown_02022C90->unk8].unk0 = gSpecialVar_ItemId - FIRST_BERRY_INDEX; gUnknown_02022C90->unkE = 1; gUnknown_02022C90->unkF = 9; - sub_8024604(gUnknown_02022C90->unk36, 0, -1, 0, 16, 0, 0); + BerryCrush_SetPaletteFadeParams(gUnknown_02022C90->unk36, 0, -1, 0, 16, 0, 0); sub_8022BEC(4, 1, gUnknown_02022C90->unk36); gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); SetMainCallback2(sub_8020F88); @@ -3250,64 +3250,19 @@ void sub_8024578(struct BerryCrushGame *r4) } } -#ifdef NONMATCHING -void sub_8024604(u8 *r0, u32 r1, s32 r2, u32 r3, u32 r5, u32 r6, u32 r4) +static void BerryCrush_SetPaletteFadeParams(u8 *params, bool8 communicateAfter, u32 selectedPals, s8 delay, u8 startY, u8 targetY, u16 palette) { - u8 sp[8]; - u8 *p; - - 1[(u32 *)sp] = r2; - 0[(u16 *)sp] = r4; - p = &sp[4]; - r0[0] = p[0]; - r0[1] = p[1]; - r0[2] = p[2]; - r0[3] = p[3]; - r0[4] = r3; - r0[5] = r5; - r0[6] = r6; - r0[7] = sp[0]; - r0[8] = sp[1]; - r0[9] = r1; + params[0] = ((u8 *)&selectedPals)[0]; + params[1] = ((u8 *)&selectedPals)[1]; + params[2] = ((u8 *)&selectedPals)[2]; + params[3] = ((u8 *)&selectedPals)[3]; + params[4] = delay; + params[5] = startY; + params[6] = targetY; + params[7] = ((u8 *)&palette)[0]; + params[8] = ((u8 *)&palette)[1]; + params[9] = communicateAfter; } -#else -NAKED -void sub_8024604(u8 *r0, u32 r1, s32 r2, u32 r3, u32 r5, u32 r6, u32 r4) -{ - asm_unified("\n\ - push {r4-r6,lr}\n\ - sub sp, 0x8\n\ - str r2, [sp, 0x4]\n\ - ldr r5, [sp, 0x18]\n\ - ldr r6, [sp, 0x1C]\n\ - ldr r4, [sp, 0x20]\n\ - mov r2, sp\n\ - strh r4, [r2]\n\ - add r4, sp, 0x4\n\ - ldrb r2, [r4]\n\ - strb r2, [r0]\n\ - ldrb r2, [r4, 0x1]\n\ - strb r2, [r0, 0x1]\n\ - ldrb r2, [r4, 0x2]\n\ - strb r2, [r0, 0x2]\n\ - ldrb r2, [r4, 0x3]\n\ - strb r2, [r0, 0x3]\n\ - strb r3, [r0, 0x4]\n\ - strb r5, [r0, 0x5]\n\ - strb r6, [r0, 0x6]\n\ - mov r2, sp\n\ - ldrb r2, [r2]\n\ - strb r2, [r0, 0x7]\n\ - mov r2, sp\n\ - ldrb r2, [r2, 0x1]\n\ - strb r2, [r0, 0x8]\n\ - strb r1, [r0, 0x9]\n\ - add sp, 0x8\n\ - pop {r4-r6}\n\ - pop {r0}\n\ - bx r0"); -} -#endif void sub_8024644(u8 *r0, u32 r1, u32 r2, u32 r3, u32 r5) { From 210862f7b6bb8d6ac338d0a5f64a3d1f3664e1fb Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 21 May 2020 13:04:13 -0400 Subject: [PATCH 33/43] Match InBoxInput_Normal, HandleInput_InParty, HandleInput_OnBox, and HandleInput_OnButtons --- src/pokemon_storage_system.c | 907 ++--------------------------------- 1 file changed, 34 insertions(+), 873 deletions(-) diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 1660316de..ef9afe663 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -6926,21 +6926,20 @@ static u8 HandleInput_InBox(void) } } -// This group of four functions handling input simply CANNOT be matched. -// GF must have written them in a really weird way, a way not a sane person could dream to reproduce. -#ifdef NONMATCHING static u8 InBoxInput_Normal(void) { u8 retVal; - s8 cursorArea = sBoxCursorArea; - s8 cursorPosition = sBoxCursorPosition; - - sPSSData->field_CD2 = 0; - sPSSData->field_CD3 = 0; - sPSSData->field_CD7 = 0; + s8 cursorArea; + s8 cursorPosition; do { + cursorArea = sBoxCursorArea; + cursorPosition = sBoxCursorPosition; + sPSSData->field_CD2 = 0; + sPSSData->field_CD3 = 0; + sPSSData->field_CD7 = 0; + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = TRUE; @@ -7065,310 +7064,6 @@ static u8 InBoxInput_Normal(void) return retVal; } -#else -NAKED -static u8 InBoxInput_Normal(void) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - ldr r0, =sBoxCursorArea\n\ - ldrb r0, [r0]\n\ - mov r8, r0\n\ - ldr r2, =sBoxCursorPosition\n\ - ldrb r4, [r2]\n\ - ldr r5, =sPSSData\n\ - ldr r0, [r5]\n\ - ldr r1, =0x00000cd2\n\ - mov r10, r1\n\ - add r0, r10\n\ - movs r1, 0\n\ - strb r1, [r0]\n\ - ldr r0, [r5]\n\ - ldr r7, =0x00000cd3\n\ - adds r0, r7\n\ - strb r1, [r0]\n\ - ldr r0, [r5]\n\ - ldr r3, =0x00000cd7\n\ - mov r9, r3\n\ - add r0, r9\n\ - strb r1, [r0]\n\ - ldr r6, =gMain\n\ - ldrh r1, [r6, 0x30]\n\ - movs r0, 0x40\n\ - ands r0, r1\n\ - adds r3, r2, 0\n\ - cmp r0, 0\n\ - beq _080CF14C\n\ - b _080CF33C\n\ -_080CF14C:\n\ - movs r0, 0x80\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF1A8\n\ - movs r6, 0x1\n\ - lsls r0, r4, 24\n\ - movs r1, 0xC0\n\ - lsls r1, 19\n\ - adds r0, r1\n\ - lsrs r4, r0, 24\n\ - asrs r0, 24\n\ - cmp r0, 0x1D\n\ - bgt _080CF168\n\ - b _080CF358\n\ -_080CF168:\n\ - movs r2, 0x3\n\ - mov r8, r2\n\ - subs r0, 0x1E\n\ - lsls r0, 24\n\ - asrs r0, 24\n\ - movs r1, 0x3\n\ - bl __divsi3\n\ - lsls r0, 24\n\ - lsrs r4, r0, 24\n\ - ldr r0, [r5]\n\ - add r0, r10\n\ - strb r6, [r0]\n\ - ldr r0, [r5]\n\ - add r0, r9\n\ - strb r6, [r0]\n\ - b _080CF358\n\ - .pool\n\ -_080CF1A8:\n\ - movs r0, 0x20\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF1DE\n\ - movs r6, 0x1\n\ - movs r0, 0\n\ - ldrsb r0, [r3, r0]\n\ - movs r1, 0x6\n\ - bl __modsi3\n\ - lsls r0, 24\n\ - cmp r0, 0\n\ - beq _080CF1CA\n\ - lsls r0, r4, 24\n\ - movs r3, 0xFF\n\ - lsls r3, 24\n\ - b _080CF34C\n\ -_080CF1CA:\n\ - ldr r0, [r5]\n\ - adds r0, r7\n\ - movs r1, 0xFF\n\ - strb r1, [r0]\n\ - lsls r0, r4, 24\n\ - movs r1, 0xA0\n\ - lsls r1, 19\n\ - adds r0, r1\n\ - lsrs r4, r0, 24\n\ - b _080CF358\n\ -_080CF1DE:\n\ - movs r0, 0x10\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF212\n\ - movs r6, 0x1\n\ - movs r0, 0\n\ - ldrsb r0, [r3, r0]\n\ - adds r0, 0x1\n\ - movs r1, 0x6\n\ - bl __modsi3\n\ - cmp r0, 0\n\ - beq _080CF204\n\ - lsls r0, r4, 24\n\ - movs r2, 0x80\n\ - lsls r2, 17\n\ - adds r0, r2\n\ - lsrs r4, r0, 24\n\ - b _080CF358\n\ -_080CF204:\n\ - ldr r0, [r5]\n\ - adds r0, r7\n\ - strb r6, [r0]\n\ - lsls r0, r4, 24\n\ - movs r3, 0xFB\n\ - lsls r3, 24\n\ - b _080CF34C\n\ -_080CF212:\n\ - ldrh r1, [r6, 0x2E]\n\ - movs r0, 0x8\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF220\n\ - movs r6, 0x1\n\ - b _080CF352\n\ -_080CF220:\n\ - movs r4, 0x1\n\ - movs r0, 0x1\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF2E4\n\ - bl sub_80CFA5C\n\ - lsls r0, 24\n\ - cmp r0, 0\n\ - beq _080CF2E4\n\ - ldr r0, =sCanOnlyMove\n\ - ldrb r0, [r0]\n\ - cmp r0, 0\n\ - bne _080CF244\n\ - movs r0, 0x8\n\ - b _080CF366\n\ - .pool\n\ -_080CF244:\n\ - ldr r1, [r5]\n\ - ldrb r0, [r1, 0x1]\n\ - cmp r0, 0x2\n\ - bne _080CF254\n\ - ldr r0, =sIsMonBeingMoved\n\ - ldrb r0, [r0]\n\ - cmp r0, 0x1\n\ - bne _080CF2D4\n\ -_080CF254:\n\ - movs r0, 0\n\ - bl sub_80CFF98\n\ - subs r0, 0x1\n\ - lsls r0, 24\n\ - asrs r0, 24\n\ - cmp r0, 0xE\n\ - bhi _080CF2E4\n\ - lsls r0, 2\n\ - ldr r1, =_080CF278\n\ - adds r0, r1\n\ - ldr r0, [r0]\n\ - mov pc, r0\n\ - .pool\n\ - .align 2, 0\n\ -_080CF278:\n\ - .4byte _080CF2B4\n\ - .4byte _080CF2B8\n\ - .4byte _080CF2BC\n\ - .4byte _080CF2C0\n\ - .4byte _080CF2C4\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2C8\n\ - .4byte _080CF2CC\n\ - .4byte _080CF2E4\n\ - .4byte _080CF2D0\n\ -_080CF2B4:\n\ - movs r0, 0xB\n\ - b _080CF366\n\ -_080CF2B8:\n\ - movs r0, 0xC\n\ - b _080CF366\n\ -_080CF2BC:\n\ - movs r0, 0xD\n\ - b _080CF366\n\ -_080CF2C0:\n\ - movs r0, 0xE\n\ - b _080CF366\n\ -_080CF2C4:\n\ - movs r0, 0xF\n\ - b _080CF366\n\ -_080CF2C8:\n\ - movs r0, 0x10\n\ - b _080CF366\n\ -_080CF2CC:\n\ - movs r0, 0x11\n\ - b _080CF366\n\ -_080CF2D0:\n\ - movs r0, 0x12\n\ - b _080CF366\n\ -_080CF2D4:\n\ - ldr r2, =0x000021ff\n\ - adds r0, r1, r2\n\ - strb r4, [r0]\n\ - movs r0, 0x14\n\ - b _080CF366\n\ - .pool\n\ -_080CF2E4:\n\ - ldr r2, =gMain\n\ - ldrh r1, [r2, 0x2E]\n\ - movs r0, 0x2\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF2F8\n\ - movs r0, 0x13\n\ - b _080CF366\n\ - .pool\n\ -_080CF2F8:\n\ - ldr r0, =gSaveBlock2Ptr\n\ - ldr r0, [r0]\n\ - ldrb r0, [r0, 0x13]\n\ - cmp r0, 0x1\n\ - bne _080CF326\n\ - ldrh r1, [r2, 0x2C]\n\ - movs r0, 0x80\n\ - lsls r0, 2\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF318\n\ - movs r0, 0xA\n\ - b _080CF366\n\ - .pool\n\ -_080CF318:\n\ - movs r0, 0x80\n\ - lsls r0, 1\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF326\n\ - movs r0, 0x9\n\ - b _080CF366\n\ -_080CF326:\n\ - ldrh r1, [r2, 0x2E]\n\ - movs r0, 0x4\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF338\n\ - bl sub_80CFDC4\n\ - movs r0, 0\n\ - b _080CF366\n\ -_080CF338:\n\ - movs r6, 0\n\ - b _080CF364\n\ -_080CF33C:\n\ - movs r6, 0x1\n\ - movs r0, 0\n\ - ldrsb r0, [r2, r0]\n\ - cmp r0, 0x5\n\ - ble _080CF352\n\ - lsls r0, r4, 24\n\ - movs r3, 0xFA\n\ - lsls r3, 24\n\ -_080CF34C:\n\ - adds r0, r3\n\ - lsrs r4, r0, 24\n\ - b _080CF358\n\ -_080CF352:\n\ - movs r0, 0x2\n\ - mov r8, r0\n\ - movs r4, 0\n\ -_080CF358:\n\ - cmp r6, 0\n\ - beq _080CF364\n\ - mov r0, r8\n\ - adds r1, r4, 0\n\ - bl sub_80CD894\n\ -_080CF364:\n\ - adds r0, r6, 0\n\ -_080CF366:\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r1}\n\ - bx r1\n\ - "); -} -#endif static u8 InBoxInput_GrabbingMultiple(void) { @@ -7526,22 +7221,23 @@ static u8 InBoxInput_MovingMultiple(void) } } -#ifdef NONMATCHING static u8 HandleInput_InParty(void) { u8 retVal; bool8 gotoBox; - s8 cursorArea = sBoxCursorArea; - s8 cursorPosition = sBoxCursorPosition; - - sPSSData->field_CD3 = 0; - sPSSData->field_CD2 = 0; - sPSSData->field_CD7 = 0; - gotoBox = FALSE; - retVal = 0; + s8 cursorArea; + s8 cursorPosition; do { + cursorArea = sBoxCursorArea; + cursorPosition = sBoxCursorPosition; + sPSSData->field_CD3 = 0; + sPSSData->field_CD2 = 0; + sPSSData->field_CD7 = 0; + gotoBox = FALSE; + retVal = 0; + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (--cursorPosition < 0) @@ -7647,290 +7343,19 @@ static u8 HandleInput_InParty(void) return retVal; } -#else -NAKED -static u8 HandleInput_InParty(void) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r9\n\ - mov r6, r8\n\ - push {r6,r7}\n\ - ldr r0, =sBoxCursorArea\n\ - ldrb r0, [r0]\n\ - mov r9, r0\n\ - ldr r6, =sBoxCursorPosition\n\ - ldrb r4, [r6]\n\ - ldr r2, =sPSSData\n\ - ldr r0, [r2]\n\ - ldr r1, =0x00000cd3\n\ - adds r0, r1\n\ - movs r1, 0\n\ - strb r1, [r0]\n\ - ldr r0, [r2]\n\ - ldr r3, =0x00000cd2\n\ - adds r0, r3\n\ - strb r1, [r0]\n\ - ldr r0, [r2]\n\ - adds r3, 0x5\n\ - adds r0, r3\n\ - strb r1, [r0]\n\ - mov r8, r1\n\ - movs r7, 0\n\ - ldr r1, =gMain\n\ - ldrh r3, [r1, 0x30]\n\ - movs r0, 0x40\n\ - ands r0, r3\n\ - adds r5, r6, 0\n\ - mov r12, r1\n\ - cmp r0, 0\n\ - beq _080CF608\n\ - b _080CF7A8\n\ -_080CF608:\n\ - movs r0, 0x80\n\ - ands r0, r3\n\ - cmp r0, 0\n\ - beq _080CF64C\n\ - lsls r0, r4, 24\n\ - movs r1, 0x80\n\ - lsls r1, 17\n\ - adds r0, r1\n\ - lsrs r4, r0, 24\n\ - asrs r0, 24\n\ - cmp r0, 0x6\n\ - ble _080CF622\n\ - movs r4, 0\n\ -_080CF622:\n\ - lsls r0, r4, 24\n\ - asrs r0, 24\n\ - movs r1, 0\n\ - ldrsb r1, [r5, r1]\n\ - cmp r0, r1\n\ - bne _080CF630\n\ - b _080CF7C6\n\ -_080CF630:\n\ - movs r7, 0x1\n\ - b _080CF7CA\n\ - .pool\n\ -_080CF64C:\n\ - movs r0, 0x20\n\ - ands r0, r3\n\ - cmp r0, 0\n\ - beq _080CF670\n\ - ldrb r1, [r5]\n\ - movs r0, 0\n\ - ldrsb r0, [r5, r0]\n\ - cmp r0, 0\n\ - beq _080CF670\n\ - movs r7, 0x1\n\ - ldr r0, [r2]\n\ - ldr r2, =0x00000cd6\n\ - adds r0, r2\n\ - strb r1, [r0]\n\ - movs r4, 0\n\ - b _080CF7C6\n\ - .pool\n\ -_080CF670:\n\ - mov r3, r12\n\ - ldrh r1, [r3, 0x30]\n\ - movs r0, 0x10\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF69E\n\ - movs r0, 0\n\ - ldrsb r0, [r5, r0]\n\ - cmp r0, 0\n\ - bne _080CF694\n\ - movs r7, 0x1\n\ - ldr r0, [r2]\n\ - ldr r1, =0x00000cd6\n\ - adds r0, r1\n\ - ldrb r4, [r0]\n\ - b _080CF7C6\n\ - .pool\n\ -_080CF694:\n\ - movs r7, 0x6\n\ - movs r2, 0\n\ - mov r9, r2\n\ - movs r4, 0\n\ - b _080CF7C6\n\ -_080CF69E:\n\ - mov r3, r12\n\ - ldrh r1, [r3, 0x2E]\n\ - movs r0, 0x1\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF75C\n\ - movs r0, 0\n\ - ldrsb r0, [r5, r0]\n\ - cmp r0, 0x6\n\ - bne _080CF6C4\n\ - ldr r0, [r2]\n\ - ldrb r0, [r0, 0x1]\n\ - cmp r0, 0x1\n\ - bne _080CF6BE\n\ - movs r0, 0x4\n\ - b _080CF7D8\n\ -_080CF6BE:\n\ - movs r0, 0x1\n\ - mov r8, r0\n\ - b _080CF75C\n\ -_080CF6C4:\n\ - bl sub_80CFA5C\n\ - lsls r0, 24\n\ - cmp r0, 0\n\ - beq _080CF75C\n\ - ldr r0, =sCanOnlyMove\n\ - ldrb r0, [r0]\n\ - cmp r0, 0\n\ - bne _080CF6E0\n\ - movs r0, 0x8\n\ - b _080CF7D8\n\ - .pool\n\ -_080CF6E0:\n\ - movs r0, 0\n\ - bl sub_80CFF98\n\ - subs r0, 0x1\n\ - lsls r0, 24\n\ - asrs r0, 24\n\ - cmp r0, 0xE\n\ - bhi _080CF75C\n\ - lsls r0, 2\n\ - ldr r1, =_080CF700\n\ - adds r0, r1\n\ - ldr r0, [r0]\n\ - mov pc, r0\n\ - .pool\n\ - .align 2, 0\n\ -_080CF700:\n\ - .4byte _080CF73C\n\ - .4byte _080CF740\n\ - .4byte _080CF744\n\ - .4byte _080CF748\n\ - .4byte _080CF74C\n\ - .4byte _080CF75C\n\ - .4byte _080CF75C\n\ - .4byte _080CF75C\n\ - .4byte _080CF75C\n\ - .4byte _080CF75C\n\ - .4byte _080CF75C\n\ - .4byte _080CF750\n\ - .4byte _080CF754\n\ - .4byte _080CF75C\n\ - .4byte _080CF758\n\ -_080CF73C:\n\ - movs r0, 0xB\n\ - b _080CF7D8\n\ -_080CF740:\n\ - movs r0, 0xC\n\ - b _080CF7D8\n\ -_080CF744:\n\ - movs r0, 0xD\n\ - b _080CF7D8\n\ -_080CF748:\n\ - movs r0, 0xE\n\ - b _080CF7D8\n\ -_080CF74C:\n\ - movs r0, 0xF\n\ - b _080CF7D8\n\ -_080CF750:\n\ - movs r0, 0x10\n\ - b _080CF7D8\n\ -_080CF754:\n\ - movs r0, 0x11\n\ - b _080CF7D8\n\ -_080CF758:\n\ - movs r0, 0x12\n\ - b _080CF7D8\n\ -_080CF75C:\n\ - ldr r2, =gMain\n\ - ldrh r1, [r2, 0x2E]\n\ - movs r0, 0x2\n\ - ands r0, r1\n\ - mov r12, r2\n\ - cmp r0, 0\n\ - beq _080CF784\n\ - ldr r0, =sPSSData\n\ - ldr r0, [r0]\n\ - ldrb r0, [r0, 0x1]\n\ - cmp r0, 0x1\n\ - bne _080CF780\n\ - movs r0, 0x13\n\ - b _080CF7D8\n\ - .pool\n\ -_080CF780:\n\ - movs r1, 0x1\n\ - mov r8, r1\n\ -_080CF784:\n\ - mov r2, r8\n\ - cmp r2, 0\n\ - beq _080CF794\n\ - movs r7, 0x6\n\ - movs r3, 0\n\ - mov r9, r3\n\ - movs r4, 0\n\ - b _080CF7C6\n\ -_080CF794:\n\ - mov r0, r12\n\ - ldrh r1, [r0, 0x2E]\n\ - movs r0, 0x4\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF7C6\n\ - bl sub_80CFDC4\n\ - movs r0, 0\n\ - b _080CF7D8\n\ -_080CF7A8:\n\ - lsls r0, r4, 24\n\ - movs r1, 0xFF\n\ - lsls r1, 24\n\ - adds r0, r1\n\ - lsrs r4, r0, 24\n\ - cmp r0, 0\n\ - bge _080CF7B8\n\ - movs r4, 0x6\n\ -_080CF7B8:\n\ - lsls r0, r4, 24\n\ - asrs r0, 24\n\ - movs r1, 0\n\ - ldrsb r1, [r6, r1]\n\ - cmp r0, r1\n\ - beq _080CF7C6\n\ - movs r7, 0x1\n\ -_080CF7C6:\n\ - cmp r7, 0\n\ - beq _080CF7D6\n\ -_080CF7CA:\n\ - cmp r7, 0x6\n\ - beq _080CF7D6\n\ - mov r0, r9\n\ - adds r1, r4, 0\n\ - bl sub_80CD894\n\ -_080CF7D6:\n\ - adds r0, r7, 0\n\ -_080CF7D8:\n\ - pop {r3,r4}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - pop {r4-r7}\n\ - pop {r1}\n\ - bx r1"); -} -#endif -#ifdef NONMATCHING static u8 HandleInput_OnBox(void) { u8 retVal; s8 cursorArea; s8 cursorPosition; - sPSSData->field_CD3 = 0; - sPSSData->field_CD2 = 0; - sPSSData->field_CD7 = 0; - do { + sPSSData->field_CD3 = 0; + sPSSData->field_CD2 = 0; + sPSSData->field_CD7 = 0; + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = 1; @@ -7989,152 +7414,30 @@ static u8 HandleInput_OnBox(void) return retVal; } -#else -NAKED -static u8 HandleInput_OnBox(void) -{ - asm_unified("\n\ - push {r4-r6,lr}\n\ - ldr r3, =sPSSData\n\ - ldr r0, [r3]\n\ - ldr r1, =0x00000cd3\n\ - adds r0, r1\n\ - movs r1, 0\n\ - strb r1, [r0]\n\ - ldr r0, [r3]\n\ - ldr r2, =0x00000cd2\n\ - adds r0, r2\n\ - strb r1, [r0]\n\ - ldr r0, [r3]\n\ - ldr r5, =0x00000cd7\n\ - adds r0, r5\n\ - strb r1, [r0]\n\ - ldr r1, =gMain\n\ - ldrh r2, [r1, 0x30]\n\ - movs r0, 0x40\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - bne _080CF8AA\n\ - movs r0, 0x80\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _080CF834\n\ - movs r4, 0x1\n\ - movs r1, 0\n\ - movs r6, 0x2\n\ - b _080CF8B6\n\ - .pool\n\ -_080CF834:\n\ - ldrh r2, [r1, 0x2C]\n\ - movs r0, 0x20\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - bne _080CF85A\n\ - movs r0, 0x10\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - bne _080CF86E\n\ - ldr r0, =gSaveBlock2Ptr\n\ - ldr r0, [r0]\n\ - ldrb r0, [r0, 0x13]\n\ - cmp r0, 0x1\n\ - bne _080CF872\n\ - movs r0, 0x80\n\ - lsls r0, 2\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _080CF864\n\ -_080CF85A:\n\ - movs r0, 0xA\n\ - b _080CF8D2\n\ - .pool\n\ -_080CF864:\n\ - movs r0, 0x80\n\ - lsls r0, 1\n\ - ands r0, r2\n\ - cmp r0, 0\n\ - beq _080CF872\n\ -_080CF86E:\n\ - movs r0, 0x9\n\ - b _080CF8D2\n\ -_080CF872:\n\ - ldrh r1, [r1, 0x2E]\n\ - movs r0, 0x1\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF88A\n\ - movs r0, 0\n\ - bl sub_80CD1A8\n\ - bl AddBoxMenu\n\ - movs r0, 0x7\n\ - b _080CF8D2\n\ -_080CF88A:\n\ - movs r0, 0x2\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF896\n\ - movs r0, 0x13\n\ - b _080CF8D2\n\ -_080CF896:\n\ - movs r0, 0x4\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF8A6\n\ - bl sub_80CFDC4\n\ - movs r0, 0\n\ - b _080CF8D2\n\ -_080CF8A6:\n\ - movs r4, 0\n\ - b _080CF8D0\n\ -_080CF8AA:\n\ - movs r4, 0x1\n\ - movs r1, 0x3\n\ - movs r6, 0\n\ - ldr r0, [r3]\n\ - adds r0, r5\n\ - strb r4, [r0]\n\ -_080CF8B6:\n\ - cmp r4, 0\n\ - beq _080CF8D0\n\ - lsls r5, r1, 24\n\ - cmp r1, 0x2\n\ - beq _080CF8C6\n\ - movs r0, 0\n\ - bl sub_80CD1A8\n\ -_080CF8C6:\n\ - lsrs r0, r5, 24\n\ - lsls r1, r6, 24\n\ - lsrs r1, 24\n\ - bl sub_80CD894\n\ -_080CF8D0:\n\ - adds r0, r4, 0\n\ -_080CF8D2:\n\ - pop {r4-r6}\n\ - pop {r1}\n\ - bx r1\n\ - "); -} -#endif -#ifdef NONMATCHING static u8 HandleInput_OnButtons(void) { u8 retVal; - s8 cursorArea = sBoxCursorArea; - s8 cursorPosition = sBoxCursorPosition; - - sPSSData->field_CD3 = 0; - sPSSData->field_CD2 = 0; - sPSSData->field_CD7 = 0; + s8 cursorArea; + s8 cursorPosition; do { + cursorArea = sBoxCursorArea; + cursorPosition = sBoxCursorPosition; + sPSSData->field_CD3 = 0; + sPSSData->field_CD2 = 0; + sPSSData->field_CD7 = 0; + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = 1; cursorArea = CURSOR_AREA_IN_BOX; sPSSData->field_CD2 = -1; - cursorPosition = (sBoxCursorPosition == 0) ? IN_BOX_COUNT - 1 - 5 : IN_BOX_COUNT - 1; + if (sBoxCursorPosition == 0) + cursorPosition = IN_BOX_COUNT - 1 - 5; + else + cursorPosition = IN_BOX_COUNT - 1; sPSSData->field_CD7 = 1; break; } @@ -8181,148 +7484,6 @@ static u8 HandleInput_OnButtons(void) return retVal; } -#else -NAKED -static u8 HandleInput_OnButtons(void) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r8\n\ - push {r7}\n\ - ldr r0, =sBoxCursorArea\n\ - ldrb r0, [r0]\n\ - mov r8, r0\n\ - ldr r0, =sBoxCursorPosition\n\ - mov r12, r0\n\ - ldrb r2, [r0]\n\ - ldr r3, =sPSSData\n\ - ldr r0, [r3]\n\ - ldr r1, =0x00000cd3\n\ - adds r0, r1\n\ - movs r1, 0\n\ - strb r1, [r0]\n\ - ldr r0, [r3]\n\ - ldr r6, =0x00000cd2\n\ - adds r0, r6\n\ - strb r1, [r0]\n\ - ldr r0, [r3]\n\ - ldr r5, =0x00000cd7\n\ - adds r0, r5\n\ - strb r1, [r0]\n\ - ldr r7, =gMain\n\ - ldrh r1, [r7, 0x30]\n\ - movs r0, 0x40\n\ - ands r0, r1\n\ - adds r4, r3, 0\n\ - cmp r0, 0\n\ - bne _080CF9B2\n\ - movs r0, 0x88\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF944\n\ - movs r7, 0x1\n\ - movs r0, 0x2\n\ - mov r8, r0\n\ - movs r2, 0\n\ - ldr r0, [r4]\n\ - b _080CF9D0\n\ - .pool\n\ -_080CF944:\n\ - movs r0, 0x20\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF960\n\ - movs r7, 0x1\n\ - lsls r0, r2, 24\n\ - movs r1, 0xFF\n\ - lsls r1, 24\n\ - adds r0, r1\n\ - lsrs r2, r0, 24\n\ - cmp r0, 0\n\ - bge _080CF9D4\n\ - movs r2, 0x1\n\ - b _080CF9D4\n\ -_080CF960:\n\ - movs r0, 0x10\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF97E\n\ - movs r7, 0x1\n\ - lsls r0, r2, 24\n\ - movs r1, 0x80\n\ - lsls r1, 17\n\ - adds r0, r1\n\ - lsrs r2, r0, 24\n\ - asrs r0, 24\n\ - cmp r0, 0x1\n\ - ble _080CF9D4\n\ - movs r2, 0\n\ - b _080CF9D4\n\ -_080CF97E:\n\ - ldrh r1, [r7, 0x2E]\n\ - movs r0, 0x1\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF992\n\ - movs r0, 0x4\n\ - cmp r2, 0\n\ - bne _080CF9E2\n\ - movs r0, 0x5\n\ - b _080CF9E2\n\ -_080CF992:\n\ - movs r0, 0x2\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF99E\n\ - movs r0, 0x13\n\ - b _080CF9E2\n\ -_080CF99E:\n\ - movs r0, 0x4\n\ - ands r0, r1\n\ - cmp r0, 0\n\ - beq _080CF9AE\n\ - bl sub_80CFDC4\n\ - movs r0, 0\n\ - b _080CF9E2\n\ -_080CF9AE:\n\ - movs r7, 0\n\ - b _080CF9E0\n\ -_080CF9B2:\n\ - movs r7, 0x1\n\ - movs r0, 0\n\ - mov r8, r0\n\ - ldr r0, [r3]\n\ - adds r0, r6\n\ - movs r1, 0xFF\n\ - strb r1, [r0]\n\ - mov r1, r12\n\ - movs r0, 0\n\ - ldrsb r0, [r1, r0]\n\ - movs r2, 0x1D\n\ - cmp r0, 0\n\ - bne _080CF9CE\n\ - movs r2, 0x18\n\ -_080CF9CE:\n\ - ldr r0, [r3]\n\ -_080CF9D0:\n\ - adds r0, r5\n\ - strb r7, [r0]\n\ -_080CF9D4:\n\ - cmp r7, 0\n\ - beq _080CF9E0\n\ - mov r0, r8\n\ - adds r1, r2, 0\n\ - bl sub_80CD894\n\ -_080CF9E0:\n\ - adds r0, r7, 0\n\ -_080CF9E2:\n\ - pop {r3}\n\ - mov r8, r3\n\ - pop {r4-r7}\n\ - pop {r1}\n\ - bx r1"); -} -#endif static u8 HandleInput(void) { From c6205b3df45273af953ec7318834b558a30ed930 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 20 May 2020 14:22:41 -0400 Subject: [PATCH 34/43] Document math_util.c --- include/math_util.h | 18 +++++++-------- src/battle_anim_effects_2.c | 14 +++++------ src/berry_crush.c | 46 ++++++++++++++++++------------------- src/frontier_pass.c | 16 ++++++------- src/math_util.c | 18 +++++++-------- 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/include/math_util.h b/include/math_util.h index 6b0d42460..04013fc03 100755 --- a/include/math_util.h +++ b/include/math_util.h @@ -1,14 +1,14 @@ #ifndef GUARD_MATH_UTIL_H #define GUARD_MATH_UTIL_H -s16 sub_8151534(s16 x, s16 y); -s16 sub_8151550(u8 s, s16 x, s16 y); -s32 sub_8151574(s32 x, s32 y); -s16 sub_81515B0(s16 x, s16 y); -s16 sub_81515D4(u8 s, s16 x, s16 y); -s32 sub_81515FC(s32 x, s32 y); -s16 sub_8151624(s16 y); -s16 sub_815163C(u8 s, s16 y); -s32 sub_815165C(s32 y); +s16 MathUtil_Mul16(s16 x, s16 y); +s16 MathUtil_Mul16Shift(u8 s, s16 x, s16 y); +s32 MathUtil_Mul32(s32 x, s32 y); +s16 MathUtil_Div16(s16 x, s16 y); +s16 MathUtil_Div16Shift(u8 s, s16 x, s16 y); +s32 MathUtil_Div32(s32 x, s32 y); +s16 MathUtil_Inv16(s16 y); +s16 MathUtil_Inv16Shift(u8 s, s16 y); +s32 MathUtil_Inv32(s32 y); #endif // GUARD_MATH_UTIL_H diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index 133742446..f98b65913 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -1578,7 +1578,7 @@ static void AnimAirWaveProjectile(struct Sprite *sprite) { sprite->data[0] = 8; task->data[5] = 4; - a = sub_8151624(0x1000); + a = MathUtil_Inv16(0x1000); sprite->pos1.x += sprite->pos2.x; sprite->pos1.y += sprite->pos2.y; sprite->pos2.y = 0; @@ -1597,8 +1597,8 @@ static void AnimAirWaveProjectile(struct Sprite *sprite) sprite->data[1] = 0; sprite->data[6] = 0; sprite->data[5] = 0; - sprite->data[3] = sub_8151534(sub_8151534(b, a), sub_8151624(0x1C0)); - sprite->data[4] = sub_8151534(sub_8151534(c, a), sub_8151624(0x1C0)); + sprite->data[3] = MathUtil_Mul16(MathUtil_Mul16(b, a), MathUtil_Inv16(0x1C0)); + sprite->data[4] = MathUtil_Mul16(MathUtil_Mul16(c, a), MathUtil_Inv16(0x1C0)); sprite->callback = AnimAirWaveProjectile_Step1; } } @@ -1689,18 +1689,18 @@ void AnimTask_AirCutterProjectile(u8 taskId) else xDiff = attackerX - targetX; - gTasks[taskId].data[5] = sub_8151534(xDiff, sub_8151624(gBattleAnimArgs[2] & ~1)); - gTasks[taskId].data[6] = sub_8151534(gTasks[taskId].data[5], 0x80); + gTasks[taskId].data[5] = MathUtil_Mul16(xDiff, MathUtil_Inv16(gBattleAnimArgs[2] & ~1)); + gTasks[taskId].data[6] = MathUtil_Mul16(gTasks[taskId].data[5], 0x80); gTasks[taskId].data[7] = gBattleAnimArgs[2]; if (targetY >= attackerY) { yDiff = targetY - attackerY; - gTasks[taskId].data[8] = sub_8151534(yDiff, sub_8151624(gTasks[taskId].data[5])) & ~1; + gTasks[taskId].data[8] = MathUtil_Mul16(yDiff, MathUtil_Inv16(gTasks[taskId].data[5])) & ~1; } else { yDiff = attackerY - targetY; - gTasks[taskId].data[8] = sub_8151534(yDiff, sub_8151624(gTasks[taskId].data[5])) | 1; + gTasks[taskId].data[8] = MathUtil_Mul16(yDiff, MathUtil_Inv16(gTasks[taskId].data[5])) | 1; } gTasks[taskId].data[3] = gBattleAnimArgs[3]; diff --git a/src/berry_crush.c b/src/berry_crush.c index 0593f53eb..721fa4729 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -919,10 +919,10 @@ void sub_8020E58(void) var0 = gUnknown_02022C90->unk68.as_four_players.unk00.unk04; var0 <<= 8; - var0 = sub_81515FC(var0, 60 << 8); + var0 = MathUtil_Div32(var0, 60 << 8); var1 = gUnknown_02022C90->unk68.as_four_players.unk00.unk0A; var1 <<= 8; - var1 = sub_81515FC(var1, var0) & 0xFFFF; + var1 = MathUtil_Div32(var1, var0) & 0xFFFF; gUnknown_02022C90->unk16 = var1; switch (gUnknown_02022C90->unk9) { @@ -1232,12 +1232,12 @@ void sub_80214A8(struct BerryCrushGame *arg0, struct BerryCrushGame_138 *arg1) var0 *= 128; var6 = var5 + 32; var6 = var6 / 2; - var1 = sub_81515D4(7, 0x3F80, var6); + var1 = MathUtil_Div16Shift(7, 0x3F80, var6); data[0] = (u16)arg1->unk38[i]->pos1.x * 128; - data[3] = sub_81515D4(7, var0, var1); - var1 = sub_8151550(7, var1, 85); + data[3] = MathUtil_Div16Shift(7, var0, var1); + var1 = MathUtil_Mul16Shift(7, var1, 85); data[4] = 0; - data[5] = sub_81515D4(7, 0x3F80, var1); + data[5] = MathUtil_Div16Shift(7, 0x3F80, var1); data[7] |= 0x8000; if (arg1->unkC[i]->unk8 < 0) StartSpriteAffineAnim(arg1->unk38[i], 1); @@ -1383,7 +1383,7 @@ void sub_8021944(struct BerryCrushGame_138 *arg0, u16 arg1) arg0->unk4 = arg1 / 3600; arg0->unk6 = (arg1 % 3600) / 60; - r3 = sub_8151534((arg1 % 60) << 8, 4); + r3 = MathUtil_Mul16((arg1 % 60) << 8, 4); for (i = 0; i < 8; i++) { @@ -1939,12 +1939,12 @@ void sub_8022B28(struct Sprite *sprite) r7[2] = 32; r7[7] = 168; r4 = sprite->pos2.x * 128; - r5 = sub_81515D4(7, (168 - sprite->pos1.y) << 7, (r2 + 32) >> 1); + r5 = MathUtil_Div16Shift(7, (168 - sprite->pos1.y) << 7, (r2 + 32) >> 1); sprite->data[0] = sprite->pos1.x << 7; - r7[3] = sub_81515D4(7, r4, r5); - r2 = sub_8151550(7, r5, 85); + r7[3] = MathUtil_Div16Shift(7, r4, r5); + r2 = MathUtil_Mul16Shift(7, r5, 85); r7[4] = r8; - r7[5] = sub_81515D4(7, 0x3F80, r2); + r7[5] = MathUtil_Div16Shift(7, 0x3F80, r2); r7[6] = sprite->pos2.x / 4; r7[7] |= 0x8000; sprite->pos2.y = r8; @@ -2194,7 +2194,7 @@ static u32 sub_8022F1C(struct BerryCrushGame *r5, u8 *r2) } r5->unk10 = 0; ResetBlockReceivedFlags(); - r5->unk20 = sub_81515FC(r5->unk18 << 8, 0x2000); + r5->unk20 = MathUtil_Div32(r5->unk18 << 8, 0x2000); break; case 5: ClearDialogWindowAndFrame(0, 1); @@ -2412,7 +2412,7 @@ void sub_802339C(struct BerryCrushGame *r4) if (r0 - r2_ > 0) { r2_ <<= 8; - r2_ = sub_81515FC(r2_, r4->unk20); + r2_ = MathUtil_Div32(r2_, r4->unk20); r2_ >>= 8; r4->unk24 = r2_; } @@ -2800,14 +2800,14 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 ); r7->unk68.as_four_players.unk00.unk04 = r7->unk28; r7->unk68.as_four_players.unk00.unk06 = r7->unk18 / (r7->unk28 / 60); - r2 = sub_8151574(r7->unk30 << 8, 0x3200); - r2 = sub_81515FC(r2, r7->unk32 << 8) + 0x3200; + r2 = MathUtil_Mul32(r7->unk30 << 8, 0x3200); + r2 = MathUtil_Div32(r2, r7->unk32 << 8) + 0x3200; r2 >>= 8; r7->unk68.as_four_players.unk00.unk08 = r2 & 0x7F; r2 <<= 8; - r2 = sub_81515FC(r2, 0x6400); + r2 = MathUtil_Div32(r2, 0x6400); r4 = (r7->unk1C * r7->unk9) << 8; - r4 = sub_8151574(r4, r2); + r4 = MathUtil_Mul32(r4, r2); r7->unk68.as_four_players.unk00.unk00 = r4 >> 8; r7->unk68.as_five_players.unk1C[0].unk4.as_2d_bytes[0][7] = Random() % 3; for (r6 = 0, r8 = 0; r8 < r7->unk9; ++r8) @@ -2823,10 +2823,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[2]; r2 <<= 8; - r2 = sub_8151574(r2, 0x6400); + r2 = MathUtil_Mul32(r2, 0x6400); r4 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[3]; r4 <<= 8; - r4 = sub_81515FC(r2, r4); + r4 = MathUtil_Div32(r2, r4); } else { @@ -2838,10 +2838,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[4]; r2 <<= 8; - r2 = sub_8151574(r2, 0x6400); + r2 = MathUtil_Mul32(r2, 0x6400); r4 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[3]; r4 <<= 8; - r4 = sub_81515FC(r2, r4); + r4 = MathUtil_Div32(r2, r4); } else { @@ -2861,10 +2861,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[5]; r2 <<= 8; - r2 = sub_8151574(r2, 0x6400); + r2 = MathUtil_Mul32(r2, 0x6400); r4 = r7->unk28; r4 <<= 8; - r4 = sub_81515FC(r2, r4); + r4 = MathUtil_Div32(r2, r4); } break; } diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 42a518ed6..75893322f 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -1038,15 +1038,15 @@ static void Task_DoFadeEffect(u8 taskId) BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_WHITE); } sPassGfx->setAffine = TRUE; - sPassGfx->unk2E = sub_8151624(data[1]); - sPassGfx->unk30 = sub_8151624(data[2]); + sPassGfx->unk2E = MathUtil_Inv16(data[1]); + sPassGfx->unk30 = MathUtil_Inv16(data[2]); break; case 1: UpdatePaletteFade(); data[1] += data[3]; data[2] += data[4]; - sPassGfx->unk2E = sub_8151624(data[1]); - sPassGfx->unk30 = sub_8151624(data[2]); + sPassGfx->unk2E = MathUtil_Inv16(data[1]); + sPassGfx->unk30 = MathUtil_Inv16(data[2]); if (!data[0]) { if (data[1] <= 0x1FC) @@ -1154,8 +1154,8 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) gUnknown_085713E0[sPassData->unkE - 1][1] << 8, gUnknown_085713E0[sPassData->unkE - 1][0], gUnknown_085713E0[sPassData->unkE - 1][1], - sub_8151624(0x1FC), - sub_8151624(0x1FC), + MathUtil_Inv16(0x1FC), + MathUtil_Inv16(0x1FC), 0); } else @@ -1165,8 +1165,8 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) gUnknown_085713E0[sPassData->unkE - 1][1] << 8, gUnknown_085713E0[sPassData->unkE - 1][0], gUnknown_085713E0[sPassData->unkE - 1][1], - sub_8151624(0x100), - sub_8151624(0x100), + MathUtil_Inv16(0x100), + MathUtil_Inv16(0x100), 0); } } diff --git a/src/math_util.c b/src/math_util.c index 83935454a..f77c82608 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -1,6 +1,6 @@ #include "global.h" -s16 sub_8151534(s16 x, s16 y) +s16 MathUtil_Mul16(s16 x, s16 y) { s32 result; @@ -10,7 +10,7 @@ s16 sub_8151534(s16 x, s16 y) return result; } -s16 sub_8151550(u8 s, s16 x, s16 y) +s16 MathUtil_Mul16Shift(u8 s, s16 x, s16 y) { s32 result; @@ -20,7 +20,7 @@ s16 sub_8151550(u8 s, s16 x, s16 y) return result; } -s32 sub_8151574(s32 x, s32 y) +s32 MathUtil_Mul32(s32 x, s32 y) { s64 result; @@ -30,7 +30,7 @@ s32 sub_8151574(s32 x, s32 y) return result; } -s16 sub_81515B0(s16 x, s16 y) +s16 MathUtil_Div16(s16 x, s16 y) { if (y == 0) { @@ -39,7 +39,7 @@ s16 sub_81515B0(s16 x, s16 y) return (x << 8) / y; } -s16 sub_81515D4(u8 s, s16 x, s16 y) +s16 MathUtil_Div16Shift(u8 s, s16 x, s16 y) { if (y == 0) { @@ -48,7 +48,7 @@ s16 sub_81515D4(u8 s, s16 x, s16 y) return (x << s) / y; } -s32 sub_81515FC(s32 x, s32 y) +s32 MathUtil_Div32(s32 x, s32 y) { s64 _x; @@ -61,7 +61,7 @@ s32 sub_81515FC(s32 x, s32 y) return _x / y; } -s16 sub_8151624(s16 y) +s16 MathUtil_Inv16(s16 y) { s32 x; @@ -69,7 +69,7 @@ s16 sub_8151624(s16 y) return x / y; } -s16 sub_815163C(u8 s, s16 y) +s16 MathUtil_Inv16Shift(u8 s, s16 y) { s32 x; @@ -77,7 +77,7 @@ s16 sub_815163C(u8 s, s16 y) return x / y; } -s32 sub_815165C(s32 y) +s32 MathUtil_Inv32(s32 y) { s64 x; From f9e6f7540fed38b3ee36db7aad01d65831ca6dd9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 20 May 2020 15:23:21 -0400 Subject: [PATCH 35/43] Use fixed point macros for math util --- data/battle_anim_scripts.s | 2 +- include/global.h | 2 +- src/battle_anim_effects_2.c | 8 +++--- src/berry_crush.c | 50 ++++++++++++++++++------------------- src/frontier_pass.c | 20 +++++++-------- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/data/battle_anim_scripts.s b/data/battle_anim_scripts.s index 23416bde8..cacb1c443 100644 --- a/data/battle_anim_scripts.s +++ b/data/battle_anim_scripts.s @@ -4197,7 +4197,7 @@ Move_AIR_CUTTER: monbg ANIM_DEF_PARTNER setalpha 12, 8 delay 0 - createvisualtask AnimTask_AirCutterProjectile, 2, 32, -24, 1536, 2, 128 + createvisualtask AnimTask_AirCutterProjectile, 2, 32, -24, 6 * 256, 2, 128 @ 6 * 256 == Q_8_8(6) waitforvisualfinish playsewithpan SE_W015, SOUND_PAN_TARGET createsprite gAirCutterSliceSpriteTemplate, ANIM_ATTACKER, 2, 40, -32, 0, 2 diff --git a/include/global.h b/include/global.h index bcf3e6486..2b03ebbe1 100644 --- a/include/global.h +++ b/include/global.h @@ -52,7 +52,7 @@ #define Q_4_12(n) ((s16)((n) * 4096)) // Converts a number to Q24.8 fixed-point format -#define Q_24_8(n) ((s32)((n) * 256)) +#define Q_24_8(n) ((s32)((n) << 8)) // Converts a Q8.8 fixed-point format number to a regular integer #define Q_8_8_TO_INT(n) ((int)((n) / 256)) diff --git a/src/battle_anim_effects_2.c b/src/battle_anim_effects_2.c index f98b65913..f7d1eea10 100755 --- a/src/battle_anim_effects_2.c +++ b/src/battle_anim_effects_2.c @@ -1578,7 +1578,7 @@ static void AnimAirWaveProjectile(struct Sprite *sprite) { sprite->data[0] = 8; task->data[5] = 4; - a = MathUtil_Inv16(0x1000); + a = MathUtil_Inv16(Q_8_8(16)); sprite->pos1.x += sprite->pos2.x; sprite->pos1.y += sprite->pos2.y; sprite->pos2.y = 0; @@ -1597,8 +1597,8 @@ static void AnimAirWaveProjectile(struct Sprite *sprite) sprite->data[1] = 0; sprite->data[6] = 0; sprite->data[5] = 0; - sprite->data[3] = MathUtil_Mul16(MathUtil_Mul16(b, a), MathUtil_Inv16(0x1C0)); - sprite->data[4] = MathUtil_Mul16(MathUtil_Mul16(c, a), MathUtil_Inv16(0x1C0)); + sprite->data[3] = MathUtil_Mul16(MathUtil_Mul16(b, a), MathUtil_Inv16(Q_8_8(1.75))); + sprite->data[4] = MathUtil_Mul16(MathUtil_Mul16(c, a), MathUtil_Inv16(Q_8_8(1.75))); sprite->callback = AnimAirWaveProjectile_Step1; } } @@ -1690,7 +1690,7 @@ void AnimTask_AirCutterProjectile(u8 taskId) xDiff = attackerX - targetX; gTasks[taskId].data[5] = MathUtil_Mul16(xDiff, MathUtil_Inv16(gBattleAnimArgs[2] & ~1)); - gTasks[taskId].data[6] = MathUtil_Mul16(gTasks[taskId].data[5], 0x80); + gTasks[taskId].data[6] = MathUtil_Mul16(gTasks[taskId].data[5], Q_8_8(0.5)); gTasks[taskId].data[7] = gBattleAnimArgs[2]; if (targetY >= attackerY) { diff --git a/src/berry_crush.c b/src/berry_crush.c index 721fa4729..383d273c4 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -918,10 +918,10 @@ void sub_8020E58(void) u32 var0, var1; var0 = gUnknown_02022C90->unk68.as_four_players.unk00.unk04; - var0 <<= 8; - var0 = MathUtil_Div32(var0, 60 << 8); + var0 = Q_24_8(var0); + var0 = MathUtil_Div32(var0, Q_24_8(60)); var1 = gUnknown_02022C90->unk68.as_four_players.unk00.unk0A; - var1 <<= 8; + var1 = Q_24_8(var1); var1 = MathUtil_Div32(var1, var0) & 0xFFFF; gUnknown_02022C90->unk16 = var1; switch (gUnknown_02022C90->unk9) @@ -1232,12 +1232,12 @@ void sub_80214A8(struct BerryCrushGame *arg0, struct BerryCrushGame_138 *arg1) var0 *= 128; var6 = var5 + 32; var6 = var6 / 2; - var1 = MathUtil_Div16Shift(7, 0x3F80, var6); + var1 = MathUtil_Div16Shift(7, Q_8_8(63.5), var6); data[0] = (u16)arg1->unk38[i]->pos1.x * 128; data[3] = MathUtil_Div16Shift(7, var0, var1); var1 = MathUtil_Mul16Shift(7, var1, 85); data[4] = 0; - data[5] = MathUtil_Div16Shift(7, 0x3F80, var1); + data[5] = MathUtil_Div16Shift(7, Q_8_8(63.5), var1); data[7] |= 0x8000; if (arg1->unkC[i]->unk8 < 0) StartSpriteAffineAnim(arg1->unk38[i], 1); @@ -1383,7 +1383,7 @@ void sub_8021944(struct BerryCrushGame_138 *arg0, u16 arg1) arg0->unk4 = arg1 / 3600; arg0->unk6 = (arg1 % 3600) / 60; - r3 = MathUtil_Mul16((arg1 % 60) << 8, 4); + r3 = MathUtil_Mul16(Q_8_8(arg1 % 60), 4); for (i = 0; i < 8; i++) { @@ -1944,7 +1944,7 @@ void sub_8022B28(struct Sprite *sprite) r7[3] = MathUtil_Div16Shift(7, r4, r5); r2 = MathUtil_Mul16Shift(7, r5, 85); r7[4] = r8; - r7[5] = MathUtil_Div16Shift(7, 0x3F80, r2); + r7[5] = MathUtil_Div16Shift(7, Q_8_8(63.5), r2); r7[6] = sprite->pos2.x / 4; r7[7] |= 0x8000; sprite->pos2.y = r8; @@ -2194,7 +2194,7 @@ static u32 sub_8022F1C(struct BerryCrushGame *r5, u8 *r2) } r5->unk10 = 0; ResetBlockReceivedFlags(); - r5->unk20 = MathUtil_Div32(r5->unk18 << 8, 0x2000); + r5->unk20 = MathUtil_Div32(Q_24_8(r5->unk18), Q_24_8(32)); break; case 5: ClearDialogWindowAndFrame(0, 1); @@ -2411,9 +2411,9 @@ void sub_802339C(struct BerryCrushGame *r4) r2_ = r4->unk1A; if (r0 - r2_ > 0) { - r2_ <<= 8; + r2_ = Q_24_8(r2_); r2_ = MathUtil_Div32(r2_, r4->unk20); - r2_ >>= 8; + r2_ = Q_24_8_TO_INT(r2_); r4->unk24 = r2_; } else @@ -2800,13 +2800,13 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 ); r7->unk68.as_four_players.unk00.unk04 = r7->unk28; r7->unk68.as_four_players.unk00.unk06 = r7->unk18 / (r7->unk28 / 60); - r2 = MathUtil_Mul32(r7->unk30 << 8, 0x3200); - r2 = MathUtil_Div32(r2, r7->unk32 << 8) + 0x3200; - r2 >>= 8; + r2 = MathUtil_Mul32(Q_24_8(r7->unk30), Q_24_8(50)); + r2 = MathUtil_Div32(r2, Q_24_8(r7->unk32)) + Q_24_8(50); + r2 = Q_24_8_TO_INT(r2); r7->unk68.as_four_players.unk00.unk08 = r2 & 0x7F; - r2 <<= 8; - r2 = MathUtil_Div32(r2, 0x6400); - r4 = (r7->unk1C * r7->unk9) << 8; + r2 = Q_24_8(r2); + r2 = MathUtil_Div32(r2, Q_24_8(100)); + r4 = Q_24_8(r7->unk1C * r7->unk9); r4 = MathUtil_Mul32(r4, r2); r7->unk68.as_four_players.unk00.unk00 = r4 >> 8; r7->unk68.as_five_players.unk1C[0].unk4.as_2d_bytes[0][7] = Random() % 3; @@ -2822,10 +2822,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 if (r7->unk68.as_four_players.others[r8].unk4.as_hwords[3] != 0) { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[2]; - r2 <<= 8; - r2 = MathUtil_Mul32(r2, 0x6400); + r2 = Q_24_8(r2); + r2 = MathUtil_Mul32(r2, Q_24_8(100)); r4 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[3]; - r4 <<= 8; + r4 = Q_24_8(r4); r4 = MathUtil_Div32(r2, r4); } else @@ -2837,10 +2837,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 if (r7->unk68.as_four_players.others[r8].unk4.as_hwords[3] != 0) { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[4]; - r2 <<= 8; - r2 = MathUtil_Mul32(r2, 0x6400); + r2 = Q_24_8(r2); + r2 = MathUtil_Mul32(r2, Q_24_8(100)); r4 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[3]; - r4 <<= 8; + r4 = Q_24_8(r4); r4 = MathUtil_Div32(r2, r4); } else @@ -2860,10 +2860,10 @@ static u32 sub_8023CAC(struct BerryCrushGame *r7, __attribute__((unused)) u8 *r1 else { r2 = r7->unk68.as_four_players.others[r8].unk4.as_hwords[5]; - r2 <<= 8; - r2 = MathUtil_Mul32(r2, 0x6400); + r2 = Q_24_8(r2); + r2 = MathUtil_Mul32(r2, Q_24_8(100)); r4 = r7->unk28; - r4 <<= 8; + r4 = Q_24_8(r4); r4 = MathUtil_Div32(r2, r4); } break; diff --git a/src/frontier_pass.c b/src/frontier_pass.c index 75893322f..6b38f0607 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -1016,16 +1016,16 @@ static void Task_DoFadeEffect(u8 taskId) if (!data[0]) { sub_80C5F58(TRUE, FALSE); - data[1] = 0x100; - data[2] = 0x100; + data[1] = Q_8_8(1); + data[2] = Q_8_8(1); data[3] = 0x15; data[4] = 0x15; BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_WHITE); } else { - data[1] = 0x1FC; - data[2] = 0x1FC; + data[1] = Q_8_8(1.984375); // 1 and 63/64 + data[2] = Q_8_8(1.984375); data[3] = -0x15; data[4] = -0x15; SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); @@ -1049,12 +1049,12 @@ static void Task_DoFadeEffect(u8 taskId) sPassGfx->unk30 = MathUtil_Inv16(data[2]); if (!data[0]) { - if (data[1] <= 0x1FC) + if (data[1] <= Q_8_8(1.984375)) return; } else { - if (data[1] != 0x100) + if (data[1] != Q_8_8(1)) return; } break; @@ -1154,8 +1154,8 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) gUnknown_085713E0[sPassData->unkE - 1][1] << 8, gUnknown_085713E0[sPassData->unkE - 1][0], gUnknown_085713E0[sPassData->unkE - 1][1], - MathUtil_Inv16(0x1FC), - MathUtil_Inv16(0x1FC), + MathUtil_Inv16(Q_8_8(1.984375)), // 1 and 63/64 + MathUtil_Inv16(Q_8_8(1.984375)), 0); } else @@ -1165,8 +1165,8 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) gUnknown_085713E0[sPassData->unkE - 1][1] << 8, gUnknown_085713E0[sPassData->unkE - 1][0], gUnknown_085713E0[sPassData->unkE - 1][1], - MathUtil_Inv16(0x100), - MathUtil_Inv16(0x100), + MathUtil_Inv16(Q_8_8(1)), + MathUtil_Inv16(Q_8_8(1)), 0); } } From 79a1127122d060a821afb941f53485ae714b5f60 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sun, 24 May 2020 17:22:56 -0500 Subject: [PATCH 36/43] Match sub_817F9F4 --- src/pokemon_animation.c | 79 ++--------------------------------------- 1 file changed, 3 insertions(+), 76 deletions(-) diff --git a/src/pokemon_animation.c b/src/pokemon_animation.c index 622e1d584..1c07b0962 100644 --- a/src/pokemon_animation.c +++ b/src/pokemon_animation.c @@ -1138,11 +1138,9 @@ static void pokemonanimfunc_04(struct Sprite *sprite) sprite->callback = sub_817F978; } -#ifdef NONMATCHING static void sub_817F9F4(struct Sprite *sprite) { s32 counter = sprite->data[2]; - if (counter > 384) { sprite->callback = SpriteCB_SetDummyOnAnimEnd; @@ -1151,8 +1149,7 @@ static void sub_817F9F4(struct Sprite *sprite) } else { - s32 divCounter = counter / 128; - + s16 divCounter = counter / 128; switch (divCounter) { case 0: @@ -1161,7 +1158,8 @@ static void sub_817F9F4(struct Sprite *sprite) break; case 2: case 3: - sprite->pos2.y = -(Sin(counter - 256, sprite->data[0] * 3)); + counter -= 256; + sprite->pos2.y = -(Sin(counter, sprite->data[0] * 3)); break; } } @@ -1169,77 +1167,6 @@ static void sub_817F9F4(struct Sprite *sprite) sprite->data[2] += 12; } -#else -NAKED -static void sub_817F9F4(struct Sprite *sprite) -{ - asm(".syntax unified\n\ - push {r4,lr}\n\ - adds r4, r0, 0\n\ - movs r0, 0x32\n\ - ldrsh r1, [r4, r0]\n\ - movs r0, 0xC0\n\ - lsls r0, 1\n\ - cmp r1, r0\n\ - ble _0817FA14\n\ - ldr r0, =SpriteCB_SetDummyOnAnimEnd\n\ - str r0, [r4, 0x1C]\n\ - movs r0, 0\n\ - strh r0, [r4, 0x24]\n\ - b _0817FA5E\n\ - .pool\n\ -_0817FA14:\n\ - adds r0, r1, 0\n\ - cmp r1, 0\n\ - bge _0817FA1C\n\ - adds r0, 0x7F\n\ -_0817FA1C:\n\ - asrs r2, r0, 7\n\ - lsls r0, r2, 16\n\ - asrs r0, 16\n\ - cmp r0, 0\n\ - blt _0817FA60\n\ - cmp r0, 0x1\n\ - ble _0817FA48\n\ - cmp r0, 0x3\n\ - bgt _0817FA60\n\ - ldr r2, =0xffffff00\n\ - adds r1, r2\n\ - lsls r0, r1, 16\n\ - asrs r0, 16\n\ - movs r1, 0x2E\n\ - ldrsh r2, [r4, r1]\n\ - lsls r1, r2, 1\n\ - adds r1, r2\n\ - lsls r1, 16\n\ - b _0817FA56\n\ - .pool\n\ -_0817FA48:\n\ - lsls r0, r2, 7\n\ - subs r0, r1, r0\n\ - lsls r0, 16\n\ - asrs r0, 16\n\ - movs r2, 0x2E\n\ - ldrsh r1, [r4, r2]\n\ - lsls r1, 17\n\ -_0817FA56:\n\ - asrs r1, 16\n\ - bl Sin\n\ - negs r0, r0\n\ -_0817FA5E:\n\ - strh r0, [r4, 0x26]\n\ -_0817FA60:\n\ - ldrh r0, [r4, 0x32]\n\ - adds r0, 0xC\n\ - strh r0, [r4, 0x32]\n\ - pop {r4}\n\ - pop {r0}\n\ - bx r0\n\ - .syntax divided"); -} - -#endif // NONMATCHING - static void pokemonanimfunc_1E(struct Sprite *sprite) { sprite->data[0] = 4; From 5eeecb56c16b9154690c855e863133a3fcfa4b42 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 25 May 2020 10:19:18 +0200 Subject: [PATCH 37/43] More touches to pokemon summary screen document --- include/pokemon_summary_screen.h | 4 +-- src/pokemon_summary_screen.c | 42 +++++++++++++++----------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/include/pokemon_summary_screen.h b/include/pokemon_summary_screen.h index 1c7510db6..6413dcdec 100755 --- a/include/pokemon_summary_screen.h +++ b/include/pokemon_summary_screen.h @@ -9,10 +9,10 @@ extern const u8 *const gMoveDescriptionPointers[]; extern const u8 *const gNatureNamePointers[]; void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex, void (*callback)(void)); -void ShowSelectMovePokemonSummaryScreen(struct Pokemon *, u8, u8, MainCallback, u16); +void ShowSelectMovePokemonSummaryScreen(struct Pokemon *mons, u8 monIndex, u8 maxMonIndex, void (*callback)(void), u16 newMove); void ShowPokemonSummaryScreenSet40EF(u8 mode, struct BoxPokemon *mons, u8 monIndex, u8 maxMonIndex, void (*callback)(void)); u8 GetMoveSlotToReplace(void); -void SummaryScreen_SetUnknownTaskId(u8 a0); +void SummaryScreen_SetUnknownTaskId(u8 taskId); void SummaryScreen_DestroyUnknownTask(void); // The Pokemon Summary Screen can operate in different modes. Certain features, diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 1cdaf3422..fc0e432bd 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -296,7 +296,7 @@ static void CreateMoveSelectorSprites(u8 idArrayStart); static void SpriteCb_MoveSelector(struct Sprite *sprite); static void DestroyMoveSelectorSprites(u8 firstArrayId); static void SetMainMoveSelectorColor(u8 whichColor); -static void MakeMoveSelectorVisible(u8 a); +static void KeepMoveSelectorVisible(u8 firstSpriteId); // const rom data #include "data/text/move_descriptions.h" @@ -1095,7 +1095,7 @@ void ShowPokemonSummaryScreen(u8 mode, void *mons, u8 monIndex, u8 maxMonIndex, } sMonSummaryScreen->currPageIndex = sMonSummaryScreen->minPageIndex; - SummaryScreen_SetUnknownTaskId(-1); + SummaryScreen_SetUnknownTaskId(0xFF); if (gMonSpritesGfxPtr == NULL) sub_806F2AC(0, 0); @@ -1975,16 +1975,16 @@ static void ChangeSelectedMove(s16 *taskData, s8 direction, u8 *moveIndexPtr) } *moveIndexPtr = newMoveIndex; - // Not sure what the purpose of this function is, seems to have no effect whatsoever. + // Get rid of the 'flicker' effect(while idle) when scrolling. if (moveIndexPtr == &sMonSummaryScreen->firstMoveIndex) - MakeMoveSelectorVisible(SPRITE_ARR_ID_MOVE_SELECTOR1); + KeepMoveSelectorVisible(SPRITE_ARR_ID_MOVE_SELECTOR1); else - MakeMoveSelectorVisible(SPRITE_ARR_ID_MOVE_SELECTOR2); + KeepMoveSelectorVisible(SPRITE_ARR_ID_MOVE_SELECTOR2); } static void CloseMoveSelectMode(u8 taskId) { - DestroyMoveSelectorSprites(8); + DestroyMoveSelectorSprites(SPRITE_ARR_ID_MOVE_SELECTOR1); ClearWindowTilemap(PSS_LABEL_WINDOW_PROMPT_SWITCH); PutWindowTilemap(PSS_LABEL_WINDOW_PROMPT_INFO); PrintMoveDetails(0); @@ -2678,14 +2678,10 @@ static void ResetWindows(void) InitWindows(sSummaryTemplate); DeactivateAllTextPrinters(); - for (i = 0; i < 20; i++) - { + for (i = 0; i < PSS_LABEL_WINDOW_END; i++) FillWindowPixelBuffer(i, PIXEL_FILL(0)); - } for (i = 0; i < ARRAY_COUNT(sMonSummaryScreen->windowIds); i++) - { sMonSummaryScreen->windowIds[i] = 0xFF; - } } static void PrintTextOnWindow(u8 windowId, const u8 *string, u8 x, u8 y, u8 lineSpacing, u8 colorId) @@ -3299,7 +3295,7 @@ static void Task_PrintSkillsPage(u8 taskId) static void PrintHeldItemName(void) { const u8 *text; - int offset; + int x; if (sMonSummaryScreen->summary.item == ITEM_ENIGMA_BERRY && IsMultiBattle() == TRUE @@ -3317,14 +3313,14 @@ static void PrintHeldItemName(void) text = gStringVar1; } - offset = GetStringCenterAlignXOffset(1, text, 72) + 6; - PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_HELD_ITEM), text, offset, 1, 0, 0); + x = GetStringCenterAlignXOffset(1, text, 72) + 6; + PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_HELD_ITEM), text, x, 1, 0, 0); } static void PrintRibbonCount(void) { const u8 *text; - int offset; + int x; if (sMonSummaryScreen->summary.ribbonCount == 0) { @@ -3337,8 +3333,8 @@ static void PrintRibbonCount(void) text = gStringVar4; } - offset = GetStringCenterAlignXOffset(1, text, 70) + 6; - PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_RIBBON_COUNT), text, offset, 1, 0, 0); + x = GetStringCenterAlignXOffset(1, text, 70) + 6; + PrintTextOnWindow(AddWindowFromTemplateList(sPageSkillsTemplate, PSS_DATA_WINDOW_SKILLS_RIBBON_COUNT), text, x, 1, 0, 0); } static void BufferLeftColumnStats(void) @@ -3799,7 +3795,7 @@ static void SetMoveTypeIcons(void) if (summary->moves[i] != MOVE_NONE) SetTypeSpritePosAndPal(gBattleMoves[summary->moves[i]].type, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); else - SetSpriteInvisibility(i + 3, TRUE); + SetSpriteInvisibility(i + SPRITE_ARR_ID_TYPE, TRUE); } } @@ -3812,7 +3808,7 @@ static void SetContestMoveTypeIcons(void) if (summary->moves[i] != MOVE_NONE) SetTypeSpritePosAndPal(NUMBER_OF_MON_TYPES + gContestMoves[summary->moves[i]].contestCategory, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); else - SetSpriteInvisibility(i + 3, TRUE); + SetSpriteInvisibility(i + SPRITE_ARR_ID_TYPE, TRUE); } } @@ -3938,9 +3934,9 @@ static void SpriteCB_Pokemon(struct Sprite *sprite) } } -void SummaryScreen_SetUnknownTaskId(u8 a0) +void SummaryScreen_SetUnknownTaskId(u8 taskId) { - sUnknownTaskId = a0; + sUnknownTaskId = taskId; } void SummaryScreen_DestroyUnknownTask(void) @@ -4041,7 +4037,7 @@ static void CreateMoveSelectorSprites(u8 idArrayStart) if (idArrayStart == SPRITE_ARR_ID_MOVE_SELECTOR1) subpriority = 1; - for (i = 0; i < 10; i++) + for (i = 0; i < MOVE_SELECTOR_SPRITES_COUNT; i++) { spriteIds[i] = CreateSprite(&sMoveSelectorSpriteTemplate, i * 16 + 89, 40, subpriority); if (i == 0) @@ -4104,7 +4100,7 @@ static void SetMainMoveSelectorColor(u8 which) } } -static void MakeMoveSelectorVisible(u8 firstSpriteId) +static void KeepMoveSelectorVisible(u8 firstSpriteId) { u8 i; u8 *spriteIds = &sMonSummaryScreen->spriteIds[firstSpriteId]; From 6964d37db60495bade68e61a88e96d5261a7f1c5 Mon Sep 17 00:00:00 2001 From: MandL27 Date: Tue, 26 May 2020 19:21:21 -0400 Subject: [PATCH 38/43] document UNKNOWN_A special char --- berry_fix/charmap.txt | 2 +- berry_fix/payload/charmap.txt | 2 +- charmap.txt | 2 +- src/battle_message.c | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/berry_fix/charmap.txt b/berry_fix/charmap.txt index a736b40f2..e2b541a7c 100644 --- a/berry_fix/charmap.txt +++ b/berry_fix/charmap.txt @@ -414,7 +414,7 @@ SIZE = FC 06 @ note that anything other than "SMALL" is invalid UNKNOWN_7 = FC 07 PAUSE = FC 08 @ manually print the wait byte after this, havent mapped them PAUSE_UNTIL_PRESS = FC 09 -UNKNOWN_A = FC 0A +WAIT_FOR_SE = FC 0A PLAY_BGM = FC 0B ESCAPE = FC 0C SHIFT_TEXT = FC 0D diff --git a/berry_fix/payload/charmap.txt b/berry_fix/payload/charmap.txt index a736b40f2..e2b541a7c 100644 --- a/berry_fix/payload/charmap.txt +++ b/berry_fix/payload/charmap.txt @@ -414,7 +414,7 @@ SIZE = FC 06 @ note that anything other than "SMALL" is invalid UNKNOWN_7 = FC 07 PAUSE = FC 08 @ manually print the wait byte after this, havent mapped them PAUSE_UNTIL_PRESS = FC 09 -UNKNOWN_A = FC 0A +WAIT_FOR_SE = FC 0A PLAY_BGM = FC 0B ESCAPE = FC 0C SHIFT_TEXT = FC 0D diff --git a/charmap.txt b/charmap.txt index c449d12b0..e3adf765e 100644 --- a/charmap.txt +++ b/charmap.txt @@ -418,7 +418,7 @@ SIZE = FC 06 @ note that anything other than "SMALL" is invalid UNKNOWN_7 = FC 07 PAUSE = FC 08 @ manually print the wait byte after this, havent mapped them PAUSE_UNTIL_PRESS = FC 09 -UNKNOWN_A = FC 0A +WAIT_FOR_SE = FC 0A PLAY_BGM = FC 0B ESCAPE = FC 0C SHIFT_TEXT = FC 0D diff --git a/src/battle_message.c b/src/battle_message.c index f60527d7a..e1a2747bd 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -58,8 +58,8 @@ static const u8 sText_Trainer1LoseText[] = _("{B_TRAINER1_LOSE_TEXT}"); static const u8 sText_PkmnGainedEXP[] = _("{B_BUFF1} gained{B_BUFF2}\n{B_BUFF3} EXP. Points!\p"); static const u8 sText_EmptyString4[] = _(""); static const u8 sText_ABoosted[] = _(" a boosted"); -static const u8 sText_PkmnGrewToLv[] = _("{B_BUFF1} grew to\nLV. {B_BUFF2}!{UNKNOWN_A}\p"); -static const u8 sText_PkmnLearnedMove[] = _("{B_BUFF1} learned\n{B_BUFF2}!{UNKNOWN_A}\p"); +static const u8 sText_PkmnGrewToLv[] = _("{B_BUFF1} grew to\nLV. {B_BUFF2}!{WAIT_FOR_SE}\p"); +static const u8 sText_PkmnLearnedMove[] = _("{B_BUFF1} learned\n{B_BUFF2}!{WAIT_FOR_SE}\p"); static const u8 sText_TryToLearnMove1[] = _("{B_BUFF1} is trying to\nlearn {B_BUFF2}.\p"); static const u8 sText_TryToLearnMove2[] = _("But, {B_BUFF1} can't learn\nmore than four moves.\p"); static const u8 sText_TryToLearnMove3[] = _("Delete a move to make\nroom for {B_BUFF2}?"); @@ -464,8 +464,8 @@ static const u8 sText_PkmnBrokeFree[] = _("Oh, no!\nThe POKéMON broke free!"); static const u8 sText_ItAppearedCaught[] = _("Aww!\nIt appeared to be caught!"); static const u8 sText_AarghAlmostHadIt[] = _("Aargh!\nAlmost had it!"); static const u8 sText_ShootSoClose[] = _("Shoot!\nIt was so close, too!"); -static const u8 sText_GotchaPkmnCaught[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{UNKNOWN_A}{PLAY_BGM MUS_KACHI22}\p"); -static const u8 sText_GotchaPkmnCaught2[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{UNKNOWN_A}{PLAY_BGM MUS_KACHI22}{PAUSE 127}"); +static const u8 sText_GotchaPkmnCaught[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{WAIT_FOR_SE}{PLAY_BGM MUS_KACHI22}\p"); +static const u8 sText_GotchaPkmnCaught2[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{WAIT_FOR_SE}{PLAY_BGM MUS_KACHI22}{PAUSE 127}"); static const u8 sText_GiveNicknameCaptured[] = _("Give a nickname to the\ncaptured {B_OPPONENT_MON1_NAME}?"); static const u8 sText_PkmnSentToPC[] = _("{B_OPPONENT_MON1_NAME} was sent to\n{B_PC_CREATOR_NAME} PC."); static const u8 sText_Someones[] = _("someone's"); @@ -1150,7 +1150,7 @@ const u16 gTrappingMoves[] = }; const u8 gText_PkmnIsEvolving[] = _("What?\n{STR_VAR_1} is evolving!"); -const u8 gText_CongratsPkmnEvolved[] = _("Congratulations! Your {STR_VAR_1}\nevolved into {STR_VAR_2}!{UNKNOWN_A}\p"); +const u8 gText_CongratsPkmnEvolved[] = _("Congratulations! Your {STR_VAR_1}\nevolved into {STR_VAR_2}!{WAIT_FOR_SE}\p"); const u8 gText_PkmnStoppedEvolving[] = _("Huh? {STR_VAR_1}\nstopped evolving!\p"); const u8 gText_EllipsisQuestionMark[] = _("……?\p"); const u8 gText_WhatWillPkmnDo[] = _("What will\n{B_ACTIVE_NAME_WITH_PREFIX} do?"); From c3d690a3805c0703c760cc9779f0c7cf8a714f7e Mon Sep 17 00:00:00 2001 From: MandL27 Date: Tue, 26 May 2020 19:37:46 -0400 Subject: [PATCH 39/43] consistency with pokefirered --- berry_fix/charmap.txt | 2 +- berry_fix/payload/charmap.txt | 2 +- charmap.txt | 2 +- src/battle_message.c | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/berry_fix/charmap.txt b/berry_fix/charmap.txt index e2b541a7c..94eabe8bc 100644 --- a/berry_fix/charmap.txt +++ b/berry_fix/charmap.txt @@ -414,7 +414,7 @@ SIZE = FC 06 @ note that anything other than "SMALL" is invalid UNKNOWN_7 = FC 07 PAUSE = FC 08 @ manually print the wait byte after this, havent mapped them PAUSE_UNTIL_PRESS = FC 09 -WAIT_FOR_SE = FC 0A +WAIT_SE = FC 0A PLAY_BGM = FC 0B ESCAPE = FC 0C SHIFT_TEXT = FC 0D diff --git a/berry_fix/payload/charmap.txt b/berry_fix/payload/charmap.txt index e2b541a7c..94eabe8bc 100644 --- a/berry_fix/payload/charmap.txt +++ b/berry_fix/payload/charmap.txt @@ -414,7 +414,7 @@ SIZE = FC 06 @ note that anything other than "SMALL" is invalid UNKNOWN_7 = FC 07 PAUSE = FC 08 @ manually print the wait byte after this, havent mapped them PAUSE_UNTIL_PRESS = FC 09 -WAIT_FOR_SE = FC 0A +WAIT_SE = FC 0A PLAY_BGM = FC 0B ESCAPE = FC 0C SHIFT_TEXT = FC 0D diff --git a/charmap.txt b/charmap.txt index e3adf765e..3a34bada5 100644 --- a/charmap.txt +++ b/charmap.txt @@ -418,7 +418,7 @@ SIZE = FC 06 @ note that anything other than "SMALL" is invalid UNKNOWN_7 = FC 07 PAUSE = FC 08 @ manually print the wait byte after this, havent mapped them PAUSE_UNTIL_PRESS = FC 09 -WAIT_FOR_SE = FC 0A +WAIT_SE = FC 0A PLAY_BGM = FC 0B ESCAPE = FC 0C SHIFT_TEXT = FC 0D diff --git a/src/battle_message.c b/src/battle_message.c index e1a2747bd..efa4500c8 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -58,8 +58,8 @@ static const u8 sText_Trainer1LoseText[] = _("{B_TRAINER1_LOSE_TEXT}"); static const u8 sText_PkmnGainedEXP[] = _("{B_BUFF1} gained{B_BUFF2}\n{B_BUFF3} EXP. Points!\p"); static const u8 sText_EmptyString4[] = _(""); static const u8 sText_ABoosted[] = _(" a boosted"); -static const u8 sText_PkmnGrewToLv[] = _("{B_BUFF1} grew to\nLV. {B_BUFF2}!{WAIT_FOR_SE}\p"); -static const u8 sText_PkmnLearnedMove[] = _("{B_BUFF1} learned\n{B_BUFF2}!{WAIT_FOR_SE}\p"); +static const u8 sText_PkmnGrewToLv[] = _("{B_BUFF1} grew to\nLV. {B_BUFF2}!{WAIT_SE}\p"); +static const u8 sText_PkmnLearnedMove[] = _("{B_BUFF1} learned\n{B_BUFF2}!{WAIT_SE}\p"); static const u8 sText_TryToLearnMove1[] = _("{B_BUFF1} is trying to\nlearn {B_BUFF2}.\p"); static const u8 sText_TryToLearnMove2[] = _("But, {B_BUFF1} can't learn\nmore than four moves.\p"); static const u8 sText_TryToLearnMove3[] = _("Delete a move to make\nroom for {B_BUFF2}?"); @@ -464,8 +464,8 @@ static const u8 sText_PkmnBrokeFree[] = _("Oh, no!\nThe POKéMON broke free!"); static const u8 sText_ItAppearedCaught[] = _("Aww!\nIt appeared to be caught!"); static const u8 sText_AarghAlmostHadIt[] = _("Aargh!\nAlmost had it!"); static const u8 sText_ShootSoClose[] = _("Shoot!\nIt was so close, too!"); -static const u8 sText_GotchaPkmnCaught[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{WAIT_FOR_SE}{PLAY_BGM MUS_KACHI22}\p"); -static const u8 sText_GotchaPkmnCaught2[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{WAIT_FOR_SE}{PLAY_BGM MUS_KACHI22}{PAUSE 127}"); +static const u8 sText_GotchaPkmnCaught[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{WAIT_SE}{PLAY_BGM MUS_KACHI22}\p"); +static const u8 sText_GotchaPkmnCaught2[] = _("Gotcha!\n{B_OPPONENT_MON1_NAME} was caught!{WAIT_SE}{PLAY_BGM MUS_KACHI22}{PAUSE 127}"); static const u8 sText_GiveNicknameCaptured[] = _("Give a nickname to the\ncaptured {B_OPPONENT_MON1_NAME}?"); static const u8 sText_PkmnSentToPC[] = _("{B_OPPONENT_MON1_NAME} was sent to\n{B_PC_CREATOR_NAME} PC."); static const u8 sText_Someones[] = _("someone's"); @@ -1150,7 +1150,7 @@ const u16 gTrappingMoves[] = }; const u8 gText_PkmnIsEvolving[] = _("What?\n{STR_VAR_1} is evolving!"); -const u8 gText_CongratsPkmnEvolved[] = _("Congratulations! Your {STR_VAR_1}\nevolved into {STR_VAR_2}!{WAIT_FOR_SE}\p"); +const u8 gText_CongratsPkmnEvolved[] = _("Congratulations! Your {STR_VAR_1}\nevolved into {STR_VAR_2}!{WAIT_SE}\p"); const u8 gText_PkmnStoppedEvolving[] = _("Huh? {STR_VAR_1}\nstopped evolving!\p"); const u8 gText_EllipsisQuestionMark[] = _("……?\p"); const u8 gText_WhatWillPkmnDo[] = _("What will\n{B_ACTIVE_NAME_WITH_PREFIX} do?"); From 42747663b545b91fc209d31fb4f787b04bb20a69 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Mon, 25 May 2020 02:11:52 -0700 Subject: [PATCH 40/43] Fix OAM region mislabeling --- src/easy_chat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/easy_chat.c b/src/easy_chat.c index 05e366420..29b1fd936 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -2794,7 +2794,7 @@ static bool8 sub_811BFA4(void) DeactivateAllTextPrinters(); sub_811CF64(); sub_811CF04(); - CpuFastFill(0, (void *)VRAM + 0x1000000, 0x400); + CpuFastFill(0, (void *)OAM, OAM_SIZE); break; case 1: DecompressAndLoadBgGfxUsingHeap(3, gEasyChatWindow_Gfx, 0, 0, 0); From ec92241d8f02d01f19f23fa5f4c92c870e6d9d61 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Mon, 25 May 2020 02:19:45 -0700 Subject: [PATCH 41/43] Fix REG_OFFSET_WININ/OUT mislabeling --- src/easy_chat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/easy_chat.c b/src/easy_chat.c index 29b1fd936..1bdb3fdc0 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -2828,8 +2828,12 @@ static bool8 sub_811BFA4(void) else { sub_811DE5C(0, 0, 0, 0); - SetGpuReg(REG_OFFSET_WININ, WIN_RANGE(0, 63)); - SetGpuReg(REG_OFFSET_WINOUT, WIN_RANGE(0, 59)); + SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR); + SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 + | WINOUT_WIN01_BG1 + | WINOUT_WIN01_BG3 + | WINOUT_WIN01_OBJ + | WINOUT_WIN01_CLR); ShowBg(3); ShowBg(1); ShowBg(2); From 6963c00016b2709101ca07dc9b4f09ec47cd8679 Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Mon, 25 May 2020 18:45:46 -0700 Subject: [PATCH 42/43] battle_anim_mons: Make cast not depend on size of struct --- src/battle_anim_mons.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_anim_mons.c b/src/battle_anim_mons.c index 861c5f6ca..e5a866999 100644 --- a/src/battle_anim_mons.c +++ b/src/battle_anim_mons.c @@ -1743,7 +1743,7 @@ void PrepareAffineAnimInTaskData(struct Task *task, u8 spriteId, const union Aff bool8 RunAffineAnimFromTaskData(struct Task *task) { - gAnimTaskAffineAnim = LoadPointerFromVars(task->data[13], task->data[14]) + (task->data[7] << 3); + gAnimTaskAffineAnim = &((union AffineAnimCmd *)LoadPointerFromVars(task->data[13], task->data[14]))[task->data[7]]; switch (gAnimTaskAffineAnim->type) { default: From d528d75af7ab8b9084e08fed7b4bb8616bc80f9c Mon Sep 17 00:00:00 2001 From: Sierraffinity Date: Tue, 26 May 2020 15:54:07 -0700 Subject: [PATCH 43/43] Connect title screen BG palettes together --- src/graphics.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics.c b/src/graphics.c index d8222cfae..7a3a225c2 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1541,8 +1541,8 @@ const u16 gMonIconPalettes[][16] = INCBIN_U16("graphics/pokemon/icon_palettes/icon_palette_2.gbapal"), }; -const u16 gTitleScreenBgPalettes[] = INCBIN_U16("graphics/title_screen/pokemon_logo.gbapal"); -const u16 gTitleScreenBgPalettes2[] = INCBIN_U16("graphics/title_screen/rayquaza_and_clouds.gbapal"); +const u16 gTitleScreenBgPalettes[] = INCBIN_U16("graphics/title_screen/pokemon_logo.gbapal", + "graphics/title_screen/rayquaza_and_clouds.gbapal"); const u16 gTitleScreenEmeraldVersionPal[] = INCBIN_U16("graphics/title_screen/emerald_version.gbapal");