From e059c4fdfa0fe36aceac4b283176825ad759fe5d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 17 Feb 2021 14:11:45 -0500 Subject: [PATCH 1/6] Use new gift ribbons size, label unused ribbons --- include/constants/global.h | 1 + include/constants/pokemon.h | 2 +- include/global.h | 6 +++--- include/pokemon.h | 2 +- src/evolution_scene.c | 20 ++++++++++---------- src/pokemon.c | 8 ++++---- src/pokemon_size_record.c | 5 +++-- src/trade.c | 2 +- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/constants/global.h b/include/constants/global.h index ee2fd3abc..d8dad0f45 100644 --- a/include/constants/global.h +++ b/include/constants/global.h @@ -51,6 +51,7 @@ #define MAX_REMATCH_ENTRIES 100 // only REMATCH_TABLE_ENTRIES (78) are used #define NUM_CONTEST_WINNERS 13 #define UNION_ROOM_KB_ROW_COUNT 10 +#define GIFT_RIBBONS_COUNT 11 #define PYRAMID_BAG_ITEMS_COUNT 10 #define HALL_FACILITIES_COUNT 9 // 7 facilities for single mode + tower double mode + tower multi mode. diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index e32ddf496..3d757bed1 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -171,7 +171,7 @@ #define MON_DATA_NATIONAL_RIBBON 76 #define MON_DATA_EARTH_RIBBON 77 #define MON_DATA_WORLD_RIBBON 78 -#define MON_DATA_FILLER 79 +#define MON_DATA_UNUSED_RIBBONS 79 #define MON_DATA_EVENT_LEGAL 80 #define MON_DATA_KNOWN_MOVES 81 #define MON_DATA_RIBBON_COUNT 82 diff --git a/include/global.h b/include/global.h index 38850d6fa..44df26a9b 100644 --- a/include/global.h +++ b/include/global.h @@ -905,7 +905,7 @@ struct ExternalEventData u8 unknownExternalDataFields1[7]; // if actually used, may be broken up into different fields. u32 unknownExternalDataFields2:8; u32 currentPokeCoupons:24; // PokéCoupons stored by Pokémon Colosseum and XD from Mt. Battle runs. Earned PokéCoupons are also added to totalEarnedPokeCoupons. Colosseum/XD caps this at 9,999,999, but will read up to 16,777,215. - u32 gotGoldPokeCouponTitleReward:1; // Master Ball from Jp Colosseum Bonus Disc; for reaching 30,000 totalEarnedPokeCoupons + u32 gotGoldPokeCouponTitleReward:1; // Master Ball from JP Colosseum Bonus Disc; for reaching 30,000 totalEarnedPokeCoupons u32 gotSilverPokeCouponTitleReward:1; // Light Ball Pikachu from JP Colosseum Bonus Disc; for reaching 5000 totalEarnedPokeCoupons u32 gotBronzePokeCouponTitleReward:1; // PP Max from JP Colosseum Bonus Disc; for reaching 2500 totalEarnedPokeCoupons u32 receivedAgetoCelebi:1; // from JP Colosseum Bonus Disc @@ -919,7 +919,7 @@ struct ExternalEventData struct ExternalEventFlags { u8 usedBoxRS:1; // Set by Pokémon Box: Ruby & Sapphire; denotes whether this save has connected to it and triggered the free False Swipe Swablu Egg giveaway. - u8 boxRSEggsUnlocked:2; // Set by Pokémon Box: Ruby & Sapphire; denotes the number of Eggs unlocked from deposits; 1 for ExtremeSpeed Zigzagoon (at 100 deposited), 2 for Pay Day Skitty (at 500 deposited), 3 for Surf Pichu (at 1500 deposited) + u8 boxRSEggsUnlocked:2; // Set by Pokémon Box: Ruby & Sapphire; denotes the number of Eggs unlocked from deposits; 1 for ExtremeSpeed Zigzagoon (at 100 deposited), 2 for Pay Day Skitty (at 500 deposited), 3 for Surf Pichu (at 1499 deposited) u8 padding:5; u8 unknownFlag1; u8 receivedGCNJirachi; // Both the US Colosseum Bonus Disc and PAL/AUS Pokémon Channel use this field. One cannot receive a WISHMKR Jirachi and CHANNEL Jirachi with the same savefile. @@ -1017,7 +1017,7 @@ struct SaveBlock1 /*0x2e90*/ struct ContestWinner contestWinners[NUM_CONTEST_WINNERS]; // see CONTEST_WINNER_* /*0x3030*/ struct DayCare daycare; /*0x3150*/ struct LinkBattleRecords linkBattleRecords; - /*0x31A8*/ u8 giftRibbons[11]; + /*0x31A8*/ u8 giftRibbons[GIFT_RIBBONS_COUNT]; /*0x31B3*/ struct ExternalEventData externalEventData; /*0x31C7*/ struct ExternalEventFlags externalEventFlags; /*0x31DC*/ struct Roamer roamer; diff --git a/include/pokemon.h b/include/pokemon.h index 7d6e960d7..82cdefeac 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -72,7 +72,7 @@ struct PokemonSubstruct3 /* 0x0B */ u32 nationalRibbon:1; /* 0x0B */ u32 earthRibbon:1; /* 0x0B */ u32 worldRibbon:1; // distributed during Pokémon Festa '04 and '05 to tournament winners - /* 0x0B */ u32 filler:4; + /* 0x0B */ u32 unusedRibbons:4; // discarded in Gen 4 /* 0x0B */ u32 eventLegal:1; // controls Mew & Deoxys obedience; if set, Pokémon is a fateful encounter in Gen 4+; set for in-game event island legendaries, some distributed events, and Pokémon from XD: Gale of Darkness. }; diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 6f5a4dce7..7b25754db 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -553,20 +553,20 @@ static void CreateShedinja(u16 preEvoSpecies, struct Pokemon* mon) const struct Evolution *evos2; CopyMon(&gPlayerParty[gPlayerPartyCount], mon, sizeof(struct Pokemon)); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, (&gEvolutionTable[preEvoSpecies][1].targetSpecies)); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_NICKNAME, (gSpeciesNames[gEvolutionTable[preEvoSpecies][1].targetSpecies])); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_HELD_ITEM, (&data)); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_MARKINGS, (&data)); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_ENCRYPT_SEPARATOR, (&data)); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, &gEvolutionTable[preEvoSpecies][1].targetSpecies); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_NICKNAME, gSpeciesNames[gEvolutionTable[preEvoSpecies][1].targetSpecies]); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_HELD_ITEM, &data); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_MARKINGS, &data); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_ENCRYPT_SEPARATOR, &data); for (i = MON_DATA_COOL_RIBBON; i < MON_DATA_COOL_RIBBON + CONTEST_CATEGORIES_COUNT; i++) - SetMonData(&gPlayerParty[gPlayerPartyCount], i, (&data)); - for (i = MON_DATA_CHAMPION_RIBBON; i <= MON_DATA_FILLER; i++) - SetMonData(&gPlayerParty[gPlayerPartyCount], i, (&data)); + SetMonData(&gPlayerParty[gPlayerPartyCount], i, &data); + for (i = MON_DATA_CHAMPION_RIBBON; i <= MON_DATA_UNUSED_RIBBONS; i++) + SetMonData(&gPlayerParty[gPlayerPartyCount], i, &data); - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_STATUS, (&data)); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_STATUS, &data); data = 0xFF; - SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_MAIL, (&data)); + SetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_MAIL, &data); CalculateMonStats(&gPlayerParty[gPlayerPartyCount]); CalculatePlayerPartyCount(); diff --git a/src/pokemon.c b/src/pokemon.c index 5812e987a..c263cacc6 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3928,8 +3928,8 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data) case MON_DATA_WORLD_RIBBON: retVal = substruct3->worldRibbon; break; - case MON_DATA_FILLER: - retVal = substruct3->filler; + case MON_DATA_UNUSED_RIBBONS: + retVal = substruct3->unusedRibbons; break; case MON_DATA_EVENT_LEGAL: retVal = substruct3->eventLegal; @@ -4307,8 +4307,8 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg) case MON_DATA_WORLD_RIBBON: SET8(substruct3->worldRibbon); break; - case MON_DATA_FILLER: - SET8(substruct3->filler); + case MON_DATA_UNUSED_RIBBONS: + SET8(substruct3->unusedRibbons); break; case MON_DATA_EVENT_LEGAL: SET8(substruct3->eventLegal); diff --git a/src/pokemon_size_record.c b/src/pokemon_size_record.c index 5b80fd428..2f76c5d69 100644 --- a/src/pokemon_size_record.c +++ b/src/pokemon_size_record.c @@ -36,7 +36,8 @@ static const struct UnknownStruct sBigMonSizeTable[] = { 1700, 1, -26 }, }; -static const u8 sGiftRibbonsMonDataIds[] = +// - 4 for unused gift ribbon bits in MON_DATA_UNUSED_RIBBONS +static const u8 sGiftRibbonsMonDataIds[GIFT_RIBBONS_COUNT - 4] = { MON_DATA_MARINE_RIBBON, MON_DATA_LAND_RIBBON, MON_DATA_SKY_RIBBON, MON_DATA_COUNTRY_RIBBON, MON_DATA_NATIONAL_RIBBON, MON_DATA_EARTH_RIBBON, @@ -200,7 +201,7 @@ void GiveGiftRibbonToParty(u8 index, u8 ribbonId) u8 array[8]; memcpy(array, sGiftRibbonsMonDataIds, sizeof(sGiftRibbonsMonDataIds)); - if (index < 11 && ribbonId < 65) + if (index < GIFT_RIBBONS_COUNT && ribbonId < 65) { gSaveBlock1Ptr->giftRibbons[index] = ribbonId; for (i = 0; i < PARTY_SIZE; i++) diff --git a/src/trade.c b/src/trade.c index afefce93c..29279985e 100644 --- a/src/trade.c +++ b/src/trade.c @@ -110,7 +110,7 @@ static EWRAM_DATA struct { /*0x007F*/ u8 unused_7F; /*0x0080*/ u16 linkData[20]; /*0x00A8*/ u8 timer; - /*0x00A9*/ u8 giftRibbons[11]; + /*0x00A9*/ u8 giftRibbons[GIFT_RIBBONS_COUNT]; /*0x00B4*/ u8 filler_B4[0x8D0-0xB4]; /*0x08D0*/ struct { bool8 queued; From 642ae8295e6617652cbd5592e98d08dc81602bcc Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 17 Feb 2021 14:11:59 -0500 Subject: [PATCH 2/6] Some constant use in pokemon_icon.c --- src/pokemon_icon.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pokemon_icon.c b/src/pokemon_icon.c index 065b8e22e..2a606f6fb 100644 --- a/src/pokemon_icon.c +++ b/src/pokemon_icon.c @@ -7,6 +7,8 @@ #define POKE_ICON_BASE_PAL_TAG 56000 +#define INVALID_ICON_SPECIES SPECIES_OLD_UNOWN_J // Oddly specific, used when an icon should be a ?. Any of the 'old unown' would work + struct MonIconSpriteTemplate { const struct OamData *oam; @@ -1086,7 +1088,7 @@ u16 GetIconSpecies(u16 species, u32 personality) else { if (species > NUM_SPECIES) - result = 260; + result = INVALID_ICON_SPECIES; else result = species; } @@ -1117,7 +1119,7 @@ u16 sub_80D2E84(u16 species) else { if (species > (SPECIES_UNOWN_B - 1)) - species = SPECIES_OLD_UNOWN_J; // That's an oddly specific species. + species = INVALID_ICON_SPECIES; return GetIconSpecies(species, 0); } } @@ -1144,7 +1146,7 @@ void SafeLoadMonIconPalette(u16 species) { u8 palIndex; if (species > NUM_SPECIES) - species = 260; + species = INVALID_ICON_SPECIES; palIndex = gMonIconPaletteIndices[species]; if (IndexOfSpritePaletteTag(gMonIconPaletteTable[palIndex].tag) == 0xFF) LoadSpritePalette(&gMonIconPaletteTable[palIndex]); @@ -1160,7 +1162,7 @@ void LoadMonIconPalette(u16 species) void FreeMonIconPalettes(void) { u8 i; - for (i = 0; i < 6; i++) + for (i = 0; i < ARRAY_COUNT(gMonIconPaletteTable); i++) FreeSpritePaletteByTag(gMonIconPaletteTable[i].tag); } @@ -1169,7 +1171,7 @@ void SafeFreeMonIconPalette(u16 species) { u8 palIndex; if (species > NUM_SPECIES) - species = 260; + species = INVALID_ICON_SPECIES; palIndex = gMonIconPaletteIndices[species]; FreeSpritePaletteByTag(gMonIconPaletteTable[palIndex].tag); } @@ -1216,7 +1218,7 @@ void sub_80D304C(u16 offset) u8 GetValidMonIconPalIndex(u16 species) { if (species > NUM_SPECIES) - species = 260; + species = INVALID_ICON_SPECIES; return gMonIconPaletteIndices[species]; } @@ -1228,7 +1230,7 @@ u8 GetMonIconPaletteIndexFromSpecies(u16 species) const u16* GetValidMonIconPalettePtr(u16 species) { if (species > NUM_SPECIES) - species = 260; + species = INVALID_ICON_SPECIES; return gMonIconPaletteTable[gMonIconPaletteIndices[species]].data; } From 02c1fbd733da15e82687ec2d346b8151ca00ccf8 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 18 Feb 2021 09:59:24 -0500 Subject: [PATCH 3/6] Document ribbon TV show, add new ribbon IDs/size --- data/text/tv.inc | 32 +++--- include/constants/pokemon.h | 49 ++++++++ include/constants/tv.h | 18 +++ include/event_scripts.h | 32 +++--- src/battle_tower.c | 4 + src/field_specials.c | 2 +- src/pokemon_size_record.c | 4 +- src/tv.c | 220 ++++++++++++++++++------------------ 8 files changed, 217 insertions(+), 144 deletions(-) diff --git a/data/text/tv.inc b/data/text/tv.inc index 6f678d824..444b37f17 100644 --- a/data/text/tv.inc +++ b/data/text/tv.inc @@ -1736,7 +1736,7 @@ gTVTrainerFanClubText11:: @ 08286B4F .string "FANS: {STR_VAR_2}!\p" .string "FANS: {STR_VAR_3}!$" -gTVCutiesText00:: @ 08286D8F +TVSpotTheCuties_Text_Intro:: @ 08286D8F .string "SPOT THE CUTIES!\n" .string "POKéMON IN RIBBONS!\p" .string "Hello, my sweet viewers!\p" @@ -1748,29 +1748,29 @@ gTVCutiesText00:: @ 08286D8F .string "Today's featured pretty POKéMON\n" .string "is {STR_VAR_1}'s {STR_VAR_2}.$" -gTVCutiesText01:: @ 08286E9D +TVSpotTheCuties_Text_RibbonsLow:: @ 08286E9D .string "The number of RIBBONS that\n" .string "{STR_VAR_2} wears is {STR_VAR_3}.\p" .string "It says a lot about how much\n" .string "{STR_VAR_1} adores the POKéMON.$" -gTVCutiesText02:: @ 08286EFC +TVSpotTheCuties_Text_RibbonsMid:: @ 08286EFC .string "{STR_VAR_2} wears an amazing\n" .string "{STR_VAR_3} RIBBONS!\p" .string "It speaks volumes about {STR_VAR_1}'s\n" .string "commitment to the POKéMON!$" -gTVCutiesText03:: @ 08286F54 +TVSpotTheCuties_Text_RibbonsHigh:: @ 08286F54 .string "{STR_VAR_2} wears an incredible\n" .string "{STR_VAR_3} RIBBONS!\p" .string "It shows you {STR_VAR_1}'s total\n" .string "dedication as a collector!$" -gTVCutiesText04:: @ 08286FAA +TVSpotTheCuties_Text_RibbonIntro:: @ 08286FAA .string "Let us take a closer look at the many\n" .string "RIBBONS worn by {STR_VAR_2}.$" -gTVCutiesText05:: @ 08286FE4 +TVSpotTheCuties_Text_RibbonChampion:: @ 08286FE4 .string "The CHAMPION RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it upon entering\n" @@ -1780,7 +1780,7 @@ gTVCutiesText05:: @ 08286FE4 .string "{STR_VAR_2} and the CHAMP RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText06:: @ 082870A3 +TVSpotTheCuties_Text_RibbonCool:: @ 082870A3 .string "The COOL RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for winning\n" @@ -1790,7 +1790,7 @@ gTVCutiesText06:: @ 082870A3 .string "{STR_VAR_2} and the COOL RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText07:: @ 0828715A +TVSpotTheCuties_Text_RibbonBeauty:: @ 0828715A .string "The BEAUTY RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for winning\n" @@ -1800,7 +1800,7 @@ gTVCutiesText07:: @ 0828715A .string "{STR_VAR_2} and the BEAUTY RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText08:: @ 08287215 +TVSpotTheCuties_Text_RibbonCute:: @ 08287215 .string "The CUTE RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for winning\n" @@ -1810,7 +1810,7 @@ gTVCutiesText08:: @ 08287215 .string "{STR_VAR_2} and the CUTE RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText09:: @ 082872CC +TVSpotTheCuties_Text_RibbonSmart:: @ 082872CC .string "The SMART RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for winning\n" @@ -1820,7 +1820,7 @@ gTVCutiesText09:: @ 082872CC .string "{STR_VAR_2} and the SMART RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText10:: @ 08287387 +TVSpotTheCuties_Text_RibbonTough:: @ 08287387 .string "The TOUGH RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for winning\n" @@ -1830,7 +1830,7 @@ gTVCutiesText10:: @ 08287387 .string "{STR_VAR_2} and the TOUGH RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText11:: @ 08287442 +TVSpotTheCuties_Text_RibbonWinning:: @ 08287442 .string "The WINNING RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for its feats\n" @@ -1840,7 +1840,7 @@ gTVCutiesText11:: @ 08287442 .string "{STR_VAR_2} and the WINNING RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText12:: @ 08287508 +TVSpotTheCuties_Text_RibbonVictory:: @ 08287508 .string "The VICTORY RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for its feats\n" @@ -1850,7 +1850,7 @@ gTVCutiesText12:: @ 08287508 .string "{STR_VAR_2} and the VICTORY RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText13:: @ 082875D9 +TVSpotTheCuties_Text_RibbonArtist:: @ 082875D9 .string "The ARTIST RIBBON is especially\n" .string "fetching.\p" .string "{STR_VAR_2} received it for being\n" @@ -1860,7 +1860,7 @@ gTVCutiesText13:: @ 082875D9 .string "{STR_VAR_2} and the ARTIST RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText14:: @ 082876A1 +TVSpotTheCuties_Text_RibbonEffort:: @ 082876A1 .string "The Hard Worker RIBBON is\n" .string "especially fetching.\p" .string "{STR_VAR_2} received it for being\n" @@ -1870,7 +1870,7 @@ gTVCutiesText14:: @ 082876A1 .string "{STR_VAR_2} and the Hard Worker RIBBON!\n" .string "The combination is super effective!$" -gTVCutiesText15:: @ 08287779 +TVSpotTheCuties_Text_Outro:: @ 08287779 .string "…Sigh…\p" .string "RIBBONS and POKéMON…\n" .string "They go so wonderfully together!\p" diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 3d757bed1..af603d789 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -182,6 +182,55 @@ #define MON_DATA_SPATK2 87 #define MON_DATA_SPDEF2 88 +// Ribbon IDs used by TV and Pokénav +#define CHAMPION_RIBBON 0 +#define COOL_RIBBON_NORMAL 1 +#define COOL_RIBBON_SUPER 2 +#define COOL_RIBBON_HYPER 3 +#define COOL_RIBBON_MASTER 4 +#define BEAUTY_RIBBON_NORMAL 5 +#define BEAUTY_RIBBON_SUPER 6 +#define BEAUTY_RIBBON_HYPER 7 +#define BEAUTY_RIBBON_MASTER 8 +#define CUTE_RIBBON_NORMAL 9 +#define CUTE_RIBBON_SUPER 10 +#define CUTE_RIBBON_HYPER 11 +#define CUTE_RIBBON_MASTER 12 +#define SMART_RIBBON_NORMAL 13 +#define SMART_RIBBON_SUPER 14 +#define SMART_RIBBON_HYPER 15 +#define SMART_RIBBON_MASTER 16 +#define TOUGH_RIBBON_NORMAL 17 +#define TOUGH_RIBBON_SUPER 18 +#define TOUGH_RIBBON_HYPER 19 +#define TOUGH_RIBBON_MASTER 20 +#define WINNING_RIBBON 21 +#define VICTORY_RIBBON 22 +#define ARTIST_RIBBON 23 +#define EFFORT_RIBBON 24 +#define MARINE_RIBBON 25 +#define LAND_RIBBON 26 +#define SKY_RIBBON 27 +#define COUNTRY_RIBBON 28 +#define NATIONAL_RIBBON 29 +#define EARTH_RIBBON 30 +#define WORLD_RIBBON 31 + +#define FIRST_GIFT_RIBBON MARINE_RIBBON +#define LAST_GIFT_RIBBON WORLD_RIBBON +#define NUM_GIFT_RIBBONS (1 + LAST_GIFT_RIBBON - FIRST_GIFT_RIBBON) + +// The above gift ribbons (Marine - World) are +// special distribution ribbons that correspond to +// 1 bit each in the Pokémon struct. Gen 4 hard-codes +// each of these to the given name. In Gen 3 they're +// used to get an index into giftRibbons in the save block, +// which can have a value 0-64 (0 is 'no ribbon') that +// corresponds to one of the special ribbons listed +// in gGiftRibbonDescriptionPointers. Most of these were +// never distributed +#define MAX_GIFT_RIBBON 64 + #define MIN_LEVEL 1 #define MAX_LEVEL 100 diff --git a/include/constants/tv.h b/include/constants/tv.h index 4b5f9115b..72eae3f1c 100644 --- a/include/constants/tv.h +++ b/include/constants/tv.h @@ -188,4 +188,22 @@ #define CONTESTLIVE_FLAG_LAST_BOTH_ROUNDS (1 << 6) #define CONTESTLIVE_FLAG_NO_APPEALS (1 << 7) +// TV Show states for Spot the Cuties +#define SPOTCUTIES_STATE_INTRO 0 +#define SPOTCUTIES_STATE_RIBBONS_LOW 1 +#define SPOTCUTIES_STATE_RIBBONS_MID 2 +#define SPOTCUTIES_STATE_RIBBONS_HIGH 3 +#define SPOTCUTIES_STATE_RIBBON_INTRO 4 +#define SPOTCUTIES_STATE_RIBBON_CHAMPION 5 +#define SPOTCUTIES_STATE_RIBBON_COOL 6 +#define SPOTCUTIES_STATE_RIBBON_BEAUTY 7 +#define SPOTCUTIES_STATE_RIBBON_CUTE 8 +#define SPOTCUTIES_STATE_RIBBON_SMART 9 +#define SPOTCUTIES_STATE_RIBBON_TOUGH 10 +#define SPOTCUTIES_STATE_RIBBON_WINNING 11 +#define SPOTCUTIES_STATE_RIBBON_VICTORY 12 +#define SPOTCUTIES_STATE_RIBBON_ARTIST 13 +#define SPOTCUTIES_STATE_RIBBON_EFFORT 14 +#define SPOTCUTIES_STATE_OUTRO 15 + #endif //GUARD_CONSTANTS_TV_H diff --git a/include/event_scripts.h b/include/event_scripts.h index 199686655..79ef0ea14 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -196,22 +196,22 @@ extern const u8 gTVTrainerFanClubText08[]; extern const u8 gTVTrainerFanClubText09[]; extern const u8 gTVTrainerFanClubText10[]; extern const u8 gTVTrainerFanClubText11[]; -extern const u8 gTVCutiesText00[]; -extern const u8 gTVCutiesText01[]; -extern const u8 gTVCutiesText02[]; -extern const u8 gTVCutiesText03[]; -extern const u8 gTVCutiesText04[]; -extern const u8 gTVCutiesText05[]; -extern const u8 gTVCutiesText06[]; -extern const u8 gTVCutiesText07[]; -extern const u8 gTVCutiesText08[]; -extern const u8 gTVCutiesText09[]; -extern const u8 gTVCutiesText10[]; -extern const u8 gTVCutiesText11[]; -extern const u8 gTVCutiesText12[]; -extern const u8 gTVCutiesText13[]; -extern const u8 gTVCutiesText14[]; -extern const u8 gTVCutiesText15[]; +extern const u8 TVSpotTheCuties_Text_Intro[]; +extern const u8 TVSpotTheCuties_Text_RibbonsLow[]; +extern const u8 TVSpotTheCuties_Text_RibbonsMid[]; +extern const u8 TVSpotTheCuties_Text_RibbonsHigh[]; +extern const u8 TVSpotTheCuties_Text_RibbonIntro[]; +extern const u8 TVSpotTheCuties_Text_RibbonChampion[]; +extern const u8 TVSpotTheCuties_Text_RibbonCool[]; +extern const u8 TVSpotTheCuties_Text_RibbonBeauty[]; +extern const u8 TVSpotTheCuties_Text_RibbonCute[]; +extern const u8 TVSpotTheCuties_Text_RibbonSmart[]; +extern const u8 TVSpotTheCuties_Text_RibbonTough[]; +extern const u8 TVSpotTheCuties_Text_RibbonWinning[]; +extern const u8 TVSpotTheCuties_Text_RibbonVictory[]; +extern const u8 TVSpotTheCuties_Text_RibbonArtist[]; +extern const u8 TVSpotTheCuties_Text_RibbonEffort[]; +extern const u8 TVSpotTheCuties_Text_Outro[]; extern const u8 gTVPokemonNewsBattleFrontierText00[]; extern const u8 gTVPokemonNewsBattleFrontierText01[]; extern const u8 gTVPokemonNewsBattleFrontierText02[]; diff --git a/src/battle_tower.c b/src/battle_tower.c index 51d695f9b..1bf4b737c 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -2765,7 +2765,11 @@ static void AwardBattleTowerRibbons(void) { s32 i; u32 partyIndex; +#ifdef BUGFIX + struct RibbonCounter ribbons[MAX_FRONTIER_PARTY_SIZE]; +#else struct RibbonCounter ribbons[3]; // BUG: 4 Pokemon can receive ribbons in a double battle mode. +#endif u8 ribbonType = 0; u8 lvlMode = gSaveBlock2Ptr->frontier.lvlMode; u8 battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); diff --git a/src/field_specials.c b/src/field_specials.c index a6831ec5b..b40889773 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -1408,7 +1408,7 @@ void GiveLeadMonEffortRibbon(void) SetMonData(leadMon, MON_DATA_EFFORT_RIBBON, &ribbonSet); if (GetRibbonCount(leadMon) > NUM_CUTIES_RIBBONS) { - TryPutSpotTheCutiesOnAir(leadMon, 0x47); + TryPutSpotTheCutiesOnAir(leadMon, MON_DATA_EFFORT_RIBBON); } } diff --git a/src/pokemon_size_record.c b/src/pokemon_size_record.c index 2f76c5d69..4beb9c83f 100644 --- a/src/pokemon_size_record.c +++ b/src/pokemon_size_record.c @@ -198,10 +198,10 @@ void GiveGiftRibbonToParty(u8 index, u8 ribbonId) s32 i; bool32 gotRibbon = FALSE; u8 data = 1; - u8 array[8]; + u8 array[ARRAY_COUNT(sGiftRibbonsMonDataIds)]; memcpy(array, sGiftRibbonsMonDataIds, sizeof(sGiftRibbonsMonDataIds)); - if (index < GIFT_RIBBONS_COUNT && ribbonId < 65) + if (index < GIFT_RIBBONS_COUNT && ribbonId <= MAX_GIFT_RIBBON) { gSaveBlock1Ptr->giftRibbons[index] = ribbonId; for (i = 0; i < PARTY_SIZE; i++) diff --git a/src/tv.c b/src/tv.c index 99bd609e4..a1743fd2d 100644 --- a/src/tv.c +++ b/src/tv.c @@ -139,7 +139,7 @@ static void sub_80EF120(u16 days); static void sub_80EDA48(u16 days); static void sub_80EEB98(u16 days); void PutFishingAdviceShowOnTheAir(void); -u8 TV_MonDataIdxToRibbon(u8 monDataIdx); +static u8 MonDataIdxToRibbon(u8 monDataIdx); static void sub_80EEBF4(u8 actionIdx); bool8 IsPriceDiscounted(u8 newsKind); static void InterviewBefore_FanClubLetter(void); @@ -592,22 +592,22 @@ static const u8 *const sTVTrainerFanClubTextGroup[] = { }; static const u8 *const sTVCutiesTextGroup[] = { - gTVCutiesText00, - gTVCutiesText01, - gTVCutiesText02, - gTVCutiesText03, - gTVCutiesText04, - gTVCutiesText05, - gTVCutiesText06, - gTVCutiesText07, - gTVCutiesText08, - gTVCutiesText09, - gTVCutiesText10, - gTVCutiesText11, - gTVCutiesText12, - gTVCutiesText13, - gTVCutiesText14, - gTVCutiesText15 + [SPOTCUTIES_STATE_INTRO] = TVSpotTheCuties_Text_Intro, + [SPOTCUTIES_STATE_RIBBONS_LOW] = TVSpotTheCuties_Text_RibbonsLow, + [SPOTCUTIES_STATE_RIBBONS_MID] = TVSpotTheCuties_Text_RibbonsMid, + [SPOTCUTIES_STATE_RIBBONS_HIGH] = TVSpotTheCuties_Text_RibbonsHigh, + [SPOTCUTIES_STATE_RIBBON_INTRO] = TVSpotTheCuties_Text_RibbonIntro, + [SPOTCUTIES_STATE_RIBBON_CHAMPION] = TVSpotTheCuties_Text_RibbonChampion, + [SPOTCUTIES_STATE_RIBBON_COOL] = TVSpotTheCuties_Text_RibbonCool, + [SPOTCUTIES_STATE_RIBBON_BEAUTY] = TVSpotTheCuties_Text_RibbonBeauty, + [SPOTCUTIES_STATE_RIBBON_CUTE] = TVSpotTheCuties_Text_RibbonCute, + [SPOTCUTIES_STATE_RIBBON_SMART] = TVSpotTheCuties_Text_RibbonSmart, + [SPOTCUTIES_STATE_RIBBON_TOUGH] = TVSpotTheCuties_Text_RibbonTough, + [SPOTCUTIES_STATE_RIBBON_WINNING] = TVSpotTheCuties_Text_RibbonWinning, + [SPOTCUTIES_STATE_RIBBON_VICTORY] = TVSpotTheCuties_Text_RibbonVictory, + [SPOTCUTIES_STATE_RIBBON_ARTIST] = TVSpotTheCuties_Text_RibbonArtist, + [SPOTCUTIES_STATE_RIBBON_EFFORT] = TVSpotTheCuties_Text_RibbonEffort, + [SPOTCUTIES_STATE_OUTRO] = TVSpotTheCuties_Text_Outro }; static const u8 *const sTVPokemonNewsBattleFrontierTextGroup[] = { @@ -2369,7 +2369,7 @@ void TryPutSpotTheCutiesOnAir(struct Pokemon *pokemon, u8 ribbonMonDataIdx) GetMonData(pokemon, MON_DATA_NICKNAME, show->cuties.nickname); StripExtCtrlCodes(show->cuties.nickname); show->cuties.nRibbons = GetRibbonCount(pokemon); - show->cuties.selectedRibbon = TV_MonDataIdxToRibbon(ribbonMonDataIdx); + show->cuties.selectedRibbon = MonDataIdxToRibbon(ribbonMonDataIdx); tv_store_id_3x(show); show->cuties.language = gGameLanguage; if (show->cuties.language == LANGUAGE_JAPANESE || GetMonData(pokemon, MON_DATA_LANGUAGE) == LANGUAGE_JAPANESE) @@ -2408,26 +2408,26 @@ u8 GetRibbonCount(struct Pokemon *pokemon) return nRibbons; } -u8 TV_MonDataIdxToRibbon(u8 monDataIdx) +static u8 MonDataIdxToRibbon(u8 monDataIdx) { - if (monDataIdx == MON_DATA_CHAMPION_RIBBON) return 0; - if (monDataIdx == MON_DATA_COOL_RIBBON) return 1; - if (monDataIdx == MON_DATA_BEAUTY_RIBBON) return 5; - if (monDataIdx == MON_DATA_CUTE_RIBBON) return 9; - if (monDataIdx == MON_DATA_SMART_RIBBON) return 13; - if (monDataIdx == MON_DATA_TOUGH_RIBBON) return 17; - if (monDataIdx == MON_DATA_WINNING_RIBBON) return 21; - if (monDataIdx == MON_DATA_VICTORY_RIBBON) return 22; - if (monDataIdx == MON_DATA_ARTIST_RIBBON) return 23; - if (monDataIdx == MON_DATA_EFFORT_RIBBON) return 24; - if (monDataIdx == MON_DATA_MARINE_RIBBON) return 25; - if (monDataIdx == MON_DATA_LAND_RIBBON) return 26; - if (monDataIdx == MON_DATA_SKY_RIBBON) return 27; - if (monDataIdx == MON_DATA_COUNTRY_RIBBON) return 28; - if (monDataIdx == MON_DATA_NATIONAL_RIBBON) return 29; - if (monDataIdx == MON_DATA_EARTH_RIBBON) return 30; - if (monDataIdx == MON_DATA_WORLD_RIBBON) return 31; - return 0; + if (monDataIdx == MON_DATA_CHAMPION_RIBBON) return CHAMPION_RIBBON; + if (monDataIdx == MON_DATA_COOL_RIBBON) return COOL_RIBBON_NORMAL; + if (monDataIdx == MON_DATA_BEAUTY_RIBBON) return BEAUTY_RIBBON_NORMAL; + if (monDataIdx == MON_DATA_CUTE_RIBBON) return CUTE_RIBBON_NORMAL; + if (monDataIdx == MON_DATA_SMART_RIBBON) return SMART_RIBBON_NORMAL; + if (monDataIdx == MON_DATA_TOUGH_RIBBON) return TOUGH_RIBBON_NORMAL; + if (monDataIdx == MON_DATA_WINNING_RIBBON) return WINNING_RIBBON; + if (monDataIdx == MON_DATA_VICTORY_RIBBON) return VICTORY_RIBBON; + if (monDataIdx == MON_DATA_ARTIST_RIBBON) return ARTIST_RIBBON; + if (monDataIdx == MON_DATA_EFFORT_RIBBON) return EFFORT_RIBBON; + if (monDataIdx == MON_DATA_MARINE_RIBBON) return MARINE_RIBBON; + if (monDataIdx == MON_DATA_LAND_RIBBON) return LAND_RIBBON; + if (monDataIdx == MON_DATA_SKY_RIBBON) return SKY_RIBBON; + if (monDataIdx == MON_DATA_COUNTRY_RIBBON) return COUNTRY_RIBBON; + if (monDataIdx == MON_DATA_NATIONAL_RIBBON) return NATIONAL_RIBBON; + if (monDataIdx == MON_DATA_EARTH_RIBBON) return EARTH_RIBBON; + if (monDataIdx == MON_DATA_WORLD_RIBBON) return WORLD_RIBBON; + return CHAMPION_RIBBON; } void TrySetUpTrainerFanClubSpecial(void) @@ -6603,98 +6603,100 @@ static void DoTVShowSpotTheCuties(void) show = &gSaveBlock1Ptr->tvShows[gSpecialVar_0x8004]; gSpecialVar_Result = FALSE; + + // For each state, in addition to the switch a message + // is printed from the table at the bottom state = sTVShowState; switch (state) { - case 0: + case SPOTCUTIES_STATE_INTRO: TVShowConvertInternationalString(gStringVar1, show->cuties.playerName, show->cuties.language); TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); + + // Comments following the intro depend on how many ribbons the pokemon has if (show->cuties.nRibbons < 10) - { - sTVShowState = 1; - } + sTVShowState = SPOTCUTIES_STATE_RIBBONS_LOW; else if (show->cuties.nRibbons < 20) - { - sTVShowState = 2; - } + sTVShowState = SPOTCUTIES_STATE_RIBBONS_MID; else - { - sTVShowState = 3; - } + sTVShowState = SPOTCUTIES_STATE_RIBBONS_HIGH; break; - case 1: - case 2: - case 3: + case SPOTCUTIES_STATE_RIBBONS_LOW: + case SPOTCUTIES_STATE_RIBBONS_MID: + case SPOTCUTIES_STATE_RIBBONS_HIGH: TVShowConvertInternationalString(gStringVar1, show->cuties.playerName, show->cuties.language); TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); TV_PrintIntToStringVar(2, show->cuties.nRibbons); - sTVShowState = 4; + sTVShowState = SPOTCUTIES_STATE_RIBBON_INTRO; break; - case 4: + case SPOTCUTIES_STATE_RIBBON_INTRO: TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); switch (show->cuties.selectedRibbon) { - case 0: - sTVShowState = 5; - break; - case 1: - case 2: - case 3: - case 4: - sTVShowState = 6; - break; - case 5: - case 6: - case 7: - case 8: - sTVShowState = 7; - break; - case 9: - case 10: - case 11: - case 12: - sTVShowState = 8; - break; - case 13: - case 14: - case 15: - case 16: - sTVShowState = 9; - break; - case 17: - case 18: - case 19: - case 20: - sTVShowState = 10; - break; - case 21: - sTVShowState = 11; - break; - case 22: - sTVShowState = 12; - break; - case 23: - sTVShowState = 13; - break; - case 24: - sTVShowState = 14; - break; + case CHAMPION_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_CHAMPION; + break; + case COOL_RIBBON_NORMAL: + case COOL_RIBBON_SUPER: + case COOL_RIBBON_HYPER: + case COOL_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_COOL; + break; + case BEAUTY_RIBBON_NORMAL: + case BEAUTY_RIBBON_SUPER: + case BEAUTY_RIBBON_HYPER: + case BEAUTY_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_BEAUTY; + break; + case CUTE_RIBBON_NORMAL: + case CUTE_RIBBON_SUPER: + case CUTE_RIBBON_HYPER: + case CUTE_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_CUTE; + break; + case SMART_RIBBON_NORMAL: + case SMART_RIBBON_SUPER: + case SMART_RIBBON_HYPER: + case SMART_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_SMART; + break; + case TOUGH_RIBBON_NORMAL: + case TOUGH_RIBBON_SUPER: + case TOUGH_RIBBON_HYPER: + case TOUGH_RIBBON_MASTER: + sTVShowState = SPOTCUTIES_STATE_RIBBON_TOUGH; + break; + case WINNING_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_WINNING; + break; + case VICTORY_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_VICTORY; + break; + case ARTIST_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_ARTIST; + break; + case EFFORT_RIBBON: + sTVShowState = SPOTCUTIES_STATE_RIBBON_EFFORT; + break; + // No comment is made for any of the gift ribbons. + // If the show is created for a gift ribbon + // then this state will repeat indefinitely } break; - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: + case SPOTCUTIES_STATE_RIBBON_CHAMPION: + case SPOTCUTIES_STATE_RIBBON_COOL: + case SPOTCUTIES_STATE_RIBBON_BEAUTY: + case SPOTCUTIES_STATE_RIBBON_CUTE: + case SPOTCUTIES_STATE_RIBBON_SMART: + case SPOTCUTIES_STATE_RIBBON_TOUGH: + case SPOTCUTIES_STATE_RIBBON_WINNING: + case SPOTCUTIES_STATE_RIBBON_VICTORY: + case SPOTCUTIES_STATE_RIBBON_ARTIST: + case SPOTCUTIES_STATE_RIBBON_EFFORT: TVShowConvertInternationalString(gStringVar2, show->cuties.nickname, show->cuties.pokemonNameLanguage); - sTVShowState = 15; + sTVShowState = SPOTCUTIES_STATE_OUTRO; break; - case 15: + case SPOTCUTIES_STATE_OUTRO: TVShowDone(); } ShowFieldMessage(sTVCutiesTextGroup[state]); From d62f89b20cb0f503f7063a4cd81459b9dac7166d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 18 Feb 2021 10:00:07 -0500 Subject: [PATCH 4/6] Minor window/bg cleanup --- common_syms/window.txt | 8 ++--- gflib/bg.c | 20 ++++++------ gflib/window.c | 70 +++++++++++++++++++++--------------------- gflib/window.h | 8 ++--- include/gba/defines.h | 2 ++ sym_common.txt | 2 +- 6 files changed, 56 insertions(+), 54 deletions(-) diff --git a/common_syms/window.txt b/common_syms/window.txt index 87a1679d1..416d9d732 100644 --- a/common_syms/window.txt +++ b/common_syms/window.txt @@ -1,5 +1,5 @@ -filler_03002F58 -filler_03002F5C +gUnusedWindowVar1 +gUnusedWindowVar2 gTransparentTileNumber -filler_03002F64 -gUnknown_03002F70 +gUnusedWindowVar3 +gWindowBgTilemapBuffers diff --git a/gflib/bg.c b/gflib/bg.c index 66dd81a25..1ca8a44a1 100644 --- a/gflib/bg.c +++ b/gflib/bg.c @@ -22,7 +22,7 @@ struct BgControl u8 unknown_2; u8 unknown_3; - } configs[4]; + } configs[NUM_BACKGROUNDS]; u16 bgVisibilityAndMode; }; @@ -39,8 +39,8 @@ struct BgConfig2 }; static struct BgControl sGpuBgConfigs; -static struct BgConfig2 sGpuBgConfigs2[4]; -static u32 sDmaBusyBitfield[4]; +static struct BgConfig2 sGpuBgConfigs2[NUM_BACKGROUNDS]; +static u32 sDmaBusyBitfield[NUM_BACKGROUNDS]; u32 gUnneededFireRedVariable; @@ -70,7 +70,7 @@ void ResetBgControlStructs(void) struct BgConfig zeroedConfig = sZeroedBgControlStruct; int i; - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BACKGROUNDS; i++) { bgConfigs[i] = zeroedConfig; } @@ -259,7 +259,7 @@ static void SetBgAffineInternal(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispC return; break; case 2: - if (bg < 2 || bg > 3) + if (bg < 2 || bg >= NUM_BACKGROUNDS) return; break; case 0: @@ -290,7 +290,7 @@ static void SetBgAffineInternal(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispC bool8 IsInvalidBg(u8 bg) { - if (bg > 3) + if (bg >= NUM_BACKGROUNDS) return TRUE; else return FALSE; @@ -306,7 +306,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable) int i; ResetBgs(); - for (i = 0; i < 4; i++) + for (i = 0; i < NUM_BACKGROUNDS; i++) { sDmaBusyBitfield[i] = 0; } @@ -325,7 +325,7 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT for (i = 0; i < numTemplates; i++) { bg = templates[i].bg; - if (bg < 4) + if (bg < NUM_BACKGROUNDS) { SetBgControlAttributes(bg, templates[i].charBaseIndex, @@ -351,7 +351,7 @@ void InitBgFromTemplate(const struct BgTemplate *template) { u8 bg = template->bg; - if (bg < 4) + if (bg < NUM_BACKGROUNDS) { SetBgControlAttributes(bg, template->charBaseIndex, @@ -1239,7 +1239,7 @@ u32 GetBgType(u8 bg) bool32 IsInvalidBg32(u8 bg) { - if (bg > 3) + if (bg >= NUM_BACKGROUNDS) return TRUE; else return FALSE; diff --git a/gflib/window.c b/gflib/window.c index 7c87ea86d..6168e4083 100644 --- a/gflib/window.c +++ b/gflib/window.c @@ -4,12 +4,12 @@ #include "bg.h" #include "blit.h" -u32 filler_03002F58; -u32 filler_03002F5C; +u32 gUnusedWindowVar1; +u32 gUnusedWindowVar2; // This global is set to 0 and never changed. u8 gTransparentTileNumber; -u32 filler_03002F64; -void *gUnknown_03002F70[4]; +u32 gUnusedWindowVar3; +void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS]; extern u32 gUnneededFireRedVariable; #define WINDOWS_MAX 32 @@ -38,22 +38,22 @@ bool16 InitWindows(const struct WindowTemplate *templates) u8* allocatedTilemapBuffer; int allocatedBaseBlock; - for (i = 0; i < 0x4; ++i) + for (i = 0; i < NUM_BACKGROUNDS; ++i) { bgTilemapBuffer = GetBgTilemapBuffer(i); if (bgTilemapBuffer != NULL) - gUnknown_03002F70[i] = nullsub_8; + gWindowBgTilemapBuffers[i] = nullsub_8; else - gUnknown_03002F70[i] = bgTilemapBuffer; + gWindowBgTilemapBuffers[i] = bgTilemapBuffer; } - for (i = 0; i < 0x20; ++i) + for (i = 0; i < WINDOWS_MAX; ++i) { gWindows[i].window = sDummyWindowTemplate; gWindows[i].tileData = NULL; } - for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < 0x20; ++i, bgLayer = templates[i].bg) + for (i = 0, allocatedBaseBlock = 0, bgLayer = templates[i].bg; bgLayer != 0xFF && i < WINDOWS_MAX; ++i, bgLayer = templates[i].bg) { if (gUnneededFireRedVariable == 1) { @@ -62,7 +62,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) return FALSE; } - if (gUnknown_03002F70[bgLayer] == NULL) + if (gWindowBgTilemapBuffers[bgLayer] == NULL) { attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); @@ -79,19 +79,19 @@ bool16 InitWindows(const struct WindowTemplate *templates) for (j = 0; j < attrib; ++j) allocatedTilemapBuffer[j] = 0; - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer); } } - allocatedTilemapBuffer = AllocZeroed((u16)(0x20 * (templates[i].width * templates[i].height))); + allocatedTilemapBuffer = AllocZeroed((u16)(WINDOWS_MAX * (templates[i].width * templates[i].height))); if (allocatedTilemapBuffer == NULL) { - if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8)) + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != nullsub_8)) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; } return FALSE; @@ -140,7 +140,7 @@ u16 AddWindow(const struct WindowTemplate *template) return 0xFF; } - if (gUnknown_03002F70[bgLayer] == NULL) + if (gWindowBgTilemapBuffers[bgLayer] == NULL) { attrib = GetBgAttribute(bgLayer, BG_ATTR_METRIC); @@ -154,19 +154,19 @@ u16 AddWindow(const struct WindowTemplate *template) for (i = 0; i < attrib; ++i) allocatedTilemapBuffer[i] = 0; - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; SetBgTilemapBuffer(bgLayer, allocatedTilemapBuffer); } } - allocatedTilemapBuffer = AllocZeroed((u16)(0x20 * (template->width * template->height))); + allocatedTilemapBuffer = AllocZeroed((u16)(WINDOWS_MAX * (template->width * template->height))); if (allocatedTilemapBuffer == NULL) { - if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gUnknown_03002F70[bgLayer] != nullsub_8)) + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != nullsub_8)) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = allocatedTilemapBuffer; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; } return 0xFF; } @@ -233,10 +233,10 @@ void RemoveWindow(u8 windowId) if (GetNumActiveWindowsOnBg(bgLayer) == 0) { - if (gUnknown_03002F70[bgLayer] != nullsub_8) + if (gWindowBgTilemapBuffers[bgLayer] != nullsub_8) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = 0; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = 0; } } @@ -251,16 +251,16 @@ void FreeAllWindowBuffers(void) { int i; - for (i = 0; i < 4; ++i) + for (i = 0; i < NUM_BACKGROUNDS; ++i) { - if (gUnknown_03002F70[i] != NULL && gUnknown_03002F70[i] != nullsub_8) + if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != nullsub_8) { - Free(gUnknown_03002F70[i]); - gUnknown_03002F70[i] = NULL; + Free(gWindowBgTilemapBuffers[i]); + gWindowBgTilemapBuffers[i] = NULL; } } - for (i = 0; i < 0x20; ++i) + for (i = 0; i < WINDOWS_MAX; ++i) { if (gWindows[i].tileData != NULL) { @@ -610,7 +610,7 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) u8* memAddress; u8 bgLayer; - for (windowId = 0; windowId < 32; windowId++) + for (windowId = 0; windowId < WINDOWS_MAX; windowId++) { if (gWindows[windowId].window.bg == 0xFF) break; @@ -618,7 +618,7 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) if (windowId == WINDOWS_MAX) return 0xFF; bgLayer = template->bg; - if (gUnknown_03002F70[bgLayer] == 0) + if (gWindowBgTilemapBuffers[bgLayer] == 0) { u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attribute != 0xFFFF) @@ -629,17 +629,17 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) return 0xFF; for (i = 0; i < attribute; i++) // if we're going to zero out the memory anyway, why not call AllocZeroed? memAddress[i] = 0; - gUnknown_03002F70[bgLayer] = memAddress; + gWindowBgTilemapBuffers[bgLayer] = memAddress; SetBgTilemapBuffer(bgLayer, memAddress); } } memAddress = Alloc((u16)(0x40 * (template->width * template->height))); if (memAddress == NULL) { - if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gUnknown_03002F70[bgLayer] != nullsub_9) + if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != nullsub_9) { - Free(gUnknown_03002F70[bgLayer]); - gUnknown_03002F70[bgLayer] = NULL; + Free(gWindowBgTilemapBuffers[bgLayer]); + gWindowBgTilemapBuffers[bgLayer] = NULL; } return 0xFF; } diff --git a/gflib/window.h b/gflib/window.h index 10e447789..6e26155c0 100644 --- a/gflib/window.h +++ b/gflib/window.h @@ -70,9 +70,9 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u void CopyWindowToVram8Bit(u8 windowId, u8 mode); extern struct Window gWindows[]; -extern void* gUnknown_03002F70[]; -extern u32 filler_03002F58; -extern u32 filler_03002F5C; -extern u32 filler_03002F64; +extern void* gWindowBgTilemapBuffers[]; +extern u32 gUnusedWindowVar1; +extern u32 gUnusedWindowVar2; +extern u32 gUnusedWindowVar3; #endif // GUARD_WINDOW_H diff --git a/include/gba/defines.h b/include/gba/defines.h index 2df9a3feb..78c688593 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -50,6 +50,8 @@ #define BG_TILE_H_FLIP(n) (0x400 + (n)) #define BG_TILE_V_FLIP(n) (0x800 + (n)) +#define NUM_BACKGROUNDS 4 + // text-mode BG #define OBJ_VRAM0 (VRAM + 0x10000) #define OBJ_VRAM0_SIZE 0x8000 diff --git a/sym_common.txt b/sym_common.txt index 02fde8971..22d70d706 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -9,7 +9,7 @@ gUnneededFireRedVariable: gTransparentTileNumber: .space 1 .align 4 -gUnknown_03002F70: +gWindowBgTilemapBuffers: .space 16 @ ../gflib/text.o .align 4 From 64fc585cc3a5ac830d4de8e921d4833ad0cc8136 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 18 Feb 2021 10:00:27 -0500 Subject: [PATCH 5/6] Document pokenav ribbons summary screen --- .../{ribbons_icon.png => ribbons/icons.png} | Bin .../{ribbons_icon1.pal => ribbons/icons1.pal} | 0 .../{ribbons_icon2.pal => ribbons/icons2.pal} | 0 .../{ribbons_icon3.pal => ribbons/icons3.pal} | 0 .../{ribbons_icon4.pal => ribbons/icons4.pal} | 0 .../{ribbons_icon5.pal => ribbons/icons5.pal} | 0 .../icons_big.png} | Bin .../{ui_ribbons.bin => ribbons/list_bg.bin} | Bin .../{ui_ribbons.png => ribbons/list_bg.png} | Bin .../{8623790.pal => ribbons/list_ui.pal} | 0 .../{8624098.pal => ribbons/mon_info.pal} | 0 .../{ribbons.bin => ribbons/summary_bg.bin} | Bin .../{ribbons.png => ribbons/summary_bg.png} | Bin include/graphics.h | 6 +- src/data/text/gift_ribbon_descriptions.h | 2 +- src/data/text/ribbon_descriptions.h | 50 +- src/graphics.c | 8 +- src/pokenav_ribbons_1.c | 20 +- src/pokenav_ribbons_2.c | 813 ++++++++++-------- 19 files changed, 497 insertions(+), 402 deletions(-) rename graphics/pokenav/{ribbons_icon.png => ribbons/icons.png} (100%) rename graphics/pokenav/{ribbons_icon1.pal => ribbons/icons1.pal} (100%) rename graphics/pokenav/{ribbons_icon2.pal => ribbons/icons2.pal} (100%) rename graphics/pokenav/{ribbons_icon3.pal => ribbons/icons3.pal} (100%) rename graphics/pokenav/{ribbons_icon4.pal => ribbons/icons4.pal} (100%) rename graphics/pokenav/{ribbons_icon5.pal => ribbons/icons5.pal} (100%) rename graphics/pokenav/{ribbons_icon_big.png => ribbons/icons_big.png} (100%) rename graphics/pokenav/{ui_ribbons.bin => ribbons/list_bg.bin} (100%) rename graphics/pokenav/{ui_ribbons.png => ribbons/list_bg.png} (100%) rename graphics/pokenav/{8623790.pal => ribbons/list_ui.pal} (100%) rename graphics/pokenav/{8624098.pal => ribbons/mon_info.pal} (100%) rename graphics/pokenav/{ribbons.bin => ribbons/summary_bg.bin} (100%) rename graphics/pokenav/{ribbons.png => ribbons/summary_bg.png} (100%) diff --git a/graphics/pokenav/ribbons_icon.png b/graphics/pokenav/ribbons/icons.png similarity index 100% rename from graphics/pokenav/ribbons_icon.png rename to graphics/pokenav/ribbons/icons.png diff --git a/graphics/pokenav/ribbons_icon1.pal b/graphics/pokenav/ribbons/icons1.pal similarity index 100% rename from graphics/pokenav/ribbons_icon1.pal rename to graphics/pokenav/ribbons/icons1.pal diff --git a/graphics/pokenav/ribbons_icon2.pal b/graphics/pokenav/ribbons/icons2.pal similarity index 100% rename from graphics/pokenav/ribbons_icon2.pal rename to graphics/pokenav/ribbons/icons2.pal diff --git a/graphics/pokenav/ribbons_icon3.pal b/graphics/pokenav/ribbons/icons3.pal similarity index 100% rename from graphics/pokenav/ribbons_icon3.pal rename to graphics/pokenav/ribbons/icons3.pal diff --git a/graphics/pokenav/ribbons_icon4.pal b/graphics/pokenav/ribbons/icons4.pal similarity index 100% rename from graphics/pokenav/ribbons_icon4.pal rename to graphics/pokenav/ribbons/icons4.pal diff --git a/graphics/pokenav/ribbons_icon5.pal b/graphics/pokenav/ribbons/icons5.pal similarity index 100% rename from graphics/pokenav/ribbons_icon5.pal rename to graphics/pokenav/ribbons/icons5.pal diff --git a/graphics/pokenav/ribbons_icon_big.png b/graphics/pokenav/ribbons/icons_big.png similarity index 100% rename from graphics/pokenav/ribbons_icon_big.png rename to graphics/pokenav/ribbons/icons_big.png diff --git a/graphics/pokenav/ui_ribbons.bin b/graphics/pokenav/ribbons/list_bg.bin similarity index 100% rename from graphics/pokenav/ui_ribbons.bin rename to graphics/pokenav/ribbons/list_bg.bin diff --git a/graphics/pokenav/ui_ribbons.png b/graphics/pokenav/ribbons/list_bg.png similarity index 100% rename from graphics/pokenav/ui_ribbons.png rename to graphics/pokenav/ribbons/list_bg.png diff --git a/graphics/pokenav/8623790.pal b/graphics/pokenav/ribbons/list_ui.pal similarity index 100% rename from graphics/pokenav/8623790.pal rename to graphics/pokenav/ribbons/list_ui.pal diff --git a/graphics/pokenav/8624098.pal b/graphics/pokenav/ribbons/mon_info.pal similarity index 100% rename from graphics/pokenav/8624098.pal rename to graphics/pokenav/ribbons/mon_info.pal diff --git a/graphics/pokenav/ribbons.bin b/graphics/pokenav/ribbons/summary_bg.bin similarity index 100% rename from graphics/pokenav/ribbons.bin rename to graphics/pokenav/ribbons/summary_bg.bin diff --git a/graphics/pokenav/ribbons.png b/graphics/pokenav/ribbons/summary_bg.png similarity index 100% rename from graphics/pokenav/ribbons.png rename to graphics/pokenav/ribbons/summary_bg.png diff --git a/include/graphics.h b/include/graphics.h index d3d01bc57..bade0b0a7 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4033,9 +4033,9 @@ extern const u32 gPokenavLeftHeaderBeauty_Gfx[]; extern const u32 gPokenavLeftHeaderCute_Gfx[]; extern const u32 gPokenavLeftHeaderSmart_Gfx[]; extern const u32 gPokenavLeftHeaderTough_Gfx[]; -extern const u16 gUnknown_08DDE010[]; -extern const u32 gUnknown_08DDE030[]; -extern const u32 gUnknown_08DDE12C[]; +extern const u16 gPokenavRibbonsSummaryBg_Pal[]; +extern const u32 gPokenavRibbonsSummaryBg_Gfx[]; +extern const u32 gPokenavRibbonsSummaryBg_Tilemap[]; extern const u32 gPageInfoTilemap[]; extern const u32 gUnknown_08D98CC8[]; diff --git a/src/data/text/gift_ribbon_descriptions.h b/src/data/text/gift_ribbon_descriptions.h index ea108be18..a95f9729d 100644 --- a/src/data/text/gift_ribbon_descriptions.h +++ b/src/data/text/gift_ribbon_descriptions.h @@ -46,7 +46,7 @@ const u8 gGiftRibbonDescriptionPart2_LovedPokemon[] = _("for a loved POKéMON.") const u8 gGiftRibbonDescriptionPart1_LoveForPokemon[] = _("RIBBON that shows"); const u8 gGiftRibbonDescriptionPart2_LoveForPokemon[] = _("love for POKéMON."); -const u8 *const gGiftRibbonDescriptionPointers[][2] = +const u8 *const gGiftRibbonDescriptionPointers[MAX_GIFT_RIBBON][2] = { {gGiftRibbonDescriptionPart1_2003RegionalTourney, gGiftRibbonDescriptionPart2_Champion}, {gGiftRibbonDescriptionPart1_2003NationalTourney, gGiftRibbonDescriptionPart2_Champion}, diff --git a/src/data/text/ribbon_descriptions.h b/src/data/text/ribbon_descriptions.h index f455a7771..5db52dced 100644 --- a/src/data/text/ribbon_descriptions.h +++ b/src/data/text/ribbon_descriptions.h @@ -20,29 +20,29 @@ const u8 gRibbonDescriptionPart2_Effort[] = _("being a hard worker."); const u8 *const gRibbonDescriptionPointers[][2] = { - {gRibbonDescriptionPart1_Champion, gRibbonDescriptionPart2_Champion}, - {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_NormalRank}, - {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_SuperRank}, - {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_HyperRank}, - {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_MasterRank}, - {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_NormalRank}, - {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_SuperRank}, - {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_HyperRank}, - {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_MasterRank}, - {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_NormalRank}, - {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_SuperRank}, - {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_HyperRank}, - {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_MasterRank}, - {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_NormalRank}, - {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_SuperRank}, - {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_HyperRank}, - {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_MasterRank}, - {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_NormalRank}, - {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_SuperRank}, - {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_HyperRank}, - {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_MasterRank}, - {gRibbonDescriptionPart1_Winning, gRibbonDescriptionPart2_Winning}, - {gRibbonDescriptionPart1_Victory, gRibbonDescriptionPart2_Victory}, - {gRibbonDescriptionPart1_Artist, gRibbonDescriptionPart2_Artist}, - {gRibbonDescriptionPart1_Effort, gRibbonDescriptionPart2_Effort}, + [CHAMPION_RIBBON] = {gRibbonDescriptionPart1_Champion, gRibbonDescriptionPart2_Champion}, + [COOL_RIBBON_NORMAL] = {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_NormalRank}, + [COOL_RIBBON_SUPER] = {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_SuperRank}, + [COOL_RIBBON_HYPER] = {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_HyperRank}, + [COOL_RIBBON_MASTER] = {gRibbonDescriptionPart1_CoolContest, gRibbonDescriptionPart2_MasterRank}, + [BEAUTY_RIBBON_NORMAL] = {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_NormalRank}, + [BEAUTY_RIBBON_SUPER] = {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_SuperRank}, + [BEAUTY_RIBBON_HYPER] = {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_HyperRank}, + [BEAUTY_RIBBON_MASTER] = {gRibbonDescriptionPart1_BeautyContest, gRibbonDescriptionPart2_MasterRank}, + [CUTE_RIBBON_NORMAL] = {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_NormalRank}, + [CUTE_RIBBON_SUPER] = {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_SuperRank}, + [CUTE_RIBBON_HYPER] = {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_HyperRank}, + [CUTE_RIBBON_MASTER] = {gRibbonDescriptionPart1_CuteContest, gRibbonDescriptionPart2_MasterRank}, + [SMART_RIBBON_NORMAL] = {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_NormalRank}, + [SMART_RIBBON_SUPER] = {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_SuperRank}, + [SMART_RIBBON_HYPER] = {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_HyperRank}, + [SMART_RIBBON_MASTER] = {gRibbonDescriptionPart1_SmartContest, gRibbonDescriptionPart2_MasterRank}, + [TOUGH_RIBBON_NORMAL] = {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_NormalRank}, + [TOUGH_RIBBON_SUPER] = {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_SuperRank}, + [TOUGH_RIBBON_HYPER] = {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_HyperRank}, + [TOUGH_RIBBON_MASTER] = {gRibbonDescriptionPart1_ToughContest, gRibbonDescriptionPart2_MasterRank}, + [WINNING_RIBBON] = {gRibbonDescriptionPart1_Winning, gRibbonDescriptionPart2_Winning}, + [VICTORY_RIBBON] = {gRibbonDescriptionPart1_Victory, gRibbonDescriptionPart2_Victory}, + [ARTIST_RIBBON] = {gRibbonDescriptionPart1_Artist, gRibbonDescriptionPart2_Artist}, + [EFFORT_RIBBON] = {gRibbonDescriptionPart1_Effort, gRibbonDescriptionPart2_Effort}, }; diff --git a/src/graphics.c b/src/graphics.c index aa8d5c249..3f49cd2e7 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1506,11 +1506,9 @@ const u16 gWallpaperPalettes_Ribbon[][16] = const u32 gWallpaperTiles_Ribbon[] = INCBIN_U32("graphics/pokemon_storage/ribbon.4bpp.lz"); const u32 gWallpaperTilemap_Ribbon[] = INCBIN_U32("graphics/pokemon_storage/ribbon.bin.lz"); -// pokenav - -const u16 gUnknown_08DDE010[] = INCBIN_U16("graphics/pokenav/ribbons.gbapal"); -const u32 gUnknown_08DDE030[] = INCBIN_U32("graphics/pokenav/ribbons.4bpp.lz"); -const u32 gUnknown_08DDE12C[] = INCBIN_U32("graphics/pokenav/ribbons.bin.lz"); +const u16 gPokenavRibbonsSummaryBg_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/summary_bg.gbapal"); +const u32 gPokenavRibbonsSummaryBg_Gfx[] = INCBIN_U32("graphics/pokenav/ribbons/summary_bg.4bpp.lz"); +const u32 gPokenavRibbonsSummaryBg_Tilemap[] = INCBIN_U32("graphics/pokenav/ribbons/summary_bg.bin.lz"); const u16 gMonIconPalettes[][16] = { diff --git a/src/pokenav_ribbons_1.c b/src/pokenav_ribbons_1.c index 397e1e749..f80f95998 100644 --- a/src/pokenav_ribbons_1.c +++ b/src/pokenav_ribbons_1.c @@ -44,7 +44,7 @@ struct PokenavSub10 static u32 HandleRibbonsMonListInput_WaitListInit(struct PokenavSub9 *structPtr); static u32 HandleRibbonsMonListInput(struct PokenavSub9 *structPtr); static u32 RibbonsMonMenu_ReturnToMainMenu(struct PokenavSub9 *structPtr); -static u32 sub_81CFB10(struct PokenavSub9 *structPtr); +static u32 RibbonsMonMenu_ToSummaryScreen(struct PokenavSub9 *structPtr); static u32 BuildPartyMonRibbonList(s32 state); static u32 InitBoxMonRibbonList(s32 state); static u32 BuildBoxMonRibbonList(s32 state); @@ -71,10 +71,10 @@ static const LoopedTask sMonRibbonListLoopTaskFuncs[] = BuildBoxMonRibbonList }; -static const u16 sMonRibbonListFramePal[] = INCBIN_U16("graphics/pokenav/ui_ribbons.gbapal"); -static const u32 sMonRibbonListFrameTiles[] = INCBIN_U32("graphics/pokenav/ui_ribbons.4bpp.lz"); -static const u32 sMonRibbonListFrameTilemap[] = INCBIN_U32("graphics/pokenav/ui_ribbons.bin.lz"); -static const u16 gUnknown_08623790[] = INCBIN_U16("graphics/pokenav/8623790.gbapal"); +static const u16 sMonRibbonListFramePal[] = INCBIN_U16("graphics/pokenav/ribbons/list_bg.gbapal"); +static const u32 sMonRibbonListFrameTiles[] = INCBIN_U32("graphics/pokenav/ribbons/list_bg.4bpp.lz"); +static const u32 sMonRibbonListFrameTilemap[] = INCBIN_U32("graphics/pokenav/ribbons/list_bg.bin.lz"); +static const u16 sMonRibbonListUi_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/list_ui.gbapal"); static const struct BgTemplate sMonRibbonListBgTemplates[] = { @@ -192,7 +192,7 @@ static u32 HandleRibbonsMonListInput(struct PokenavSub9 *structPtr) { structPtr->monList->currIndex = GetSelectedPokenavListIndex(); structPtr->saveMonList = 1; - structPtr->callback = sub_81CFB10; + structPtr->callback = RibbonsMonMenu_ToSummaryScreen; return RIBBONS_MON_LIST_FUNC_OPEN_RIBBONS_SUMMARY; } return RIBBONS_MON_LIST_FUNC_NONE; @@ -203,7 +203,7 @@ static u32 RibbonsMonMenu_ReturnToMainMenu(struct PokenavSub9 *structPtr) return POKENAV_MAIN_MENU_CURSOR_ON_RIBBONS; } -static u32 sub_81CFB10(struct PokenavSub9 *structPtr) +static u32 RibbonsMonMenu_ToSummaryScreen(struct PokenavSub9 *structPtr) { return POKENAV_RIBBONS_SUMMARY_SCREEN; } @@ -342,8 +342,8 @@ static void sub_81CFCEC(struct PokenavSub9 *structPtr, struct PokenavMonList *it structPtr->monList->listCount++; } -//unused -static bool32 Unused_PlayerHasRibbonsMon(void) +// Unused +static bool32 PlayerHasRibbonsMon(void) { s32 i, j; @@ -446,7 +446,7 @@ static u32 LoopedTask_OpenRibbonsMonList(s32 state) case 2: if (FreeTempTileDataBuffersIfPossible()) return LT_PAUSE; - CopyPaletteIntoBufferUnfaded(gUnknown_08623790, 0x20, 0x20); + CopyPaletteIntoBufferUnfaded(sMonRibbonListUi_Pal, 0x20, 0x20); InitMonRibbonPokenavListMenuTemplate(); return LT_INC_AND_PAUSE; case 3: diff --git a/src/pokenav_ribbons_2.c b/src/pokenav_ribbons_2.c index 203aa19e5..cbcd29776 100644 --- a/src/pokenav_ribbons_2.c +++ b/src/pokenav_ribbons_2.c @@ -16,24 +16,41 @@ enum { RIBBONS_SUMMARY_FUNC_NONE, - RIBBONS_SUMMARY_FUNC_MOVED_CURSOR, + RIBBONS_SUMMARY_FUNC_SWITCH_MONS, RIBBONS_SUMMARY_FUNC_SELECT_RIBBON, RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE, RIBBONS_SUMMARY_FUNC_EXPANDED_CANCEL, RIBBONS_SUMMARY_FUNC_EXIT, }; +#define GFXTAG_RIBBON_ICONS_BIG 9 + +#define PALTAG_RIBBON_ICONS_1 15 +#define PALTAG_RIBBON_ICONS_2 16 +#define PALTAG_RIBBON_ICONS_3 17 +#define PALTAG_RIBBON_ICONS_4 18 +#define PALTAG_RIBBON_ICONS_5 19 + +#define RIBBONS_PER_ROW 9 +#define GIFT_RIBBON_ROW (1 + (FIRST_GIFT_RIBBON / RIBBONS_PER_ROW)) // Gift ribbons start on a new row after the normal ribbons. +#define GIFT_RIBBON_START_POS (RIBBONS_PER_ROW * GIFT_RIBBON_ROW) + +#define MON_SPRITE_X_ON 40 +#define MON_SPRITE_X_OFF -32 +#define MON_SPRITE_Y 104 + struct PokenavSub13 { - u8 filler0[0x8]; + u8 unused1[8]; struct PokenavSub18 *monList; - u16 field_C; - u16 field_E; - u16 field_10; - u16 field_12; - u32 field_14[25]; - u32 field_78[8]; - u32 (*callback)(struct PokenavSub13 *structPtr); + u16 selectedPos; + u16 normalRibbonLastRowStart; + u16 numNormalRibbons; + u16 numGiftRibbons; + u32 ribbonIds[FIRST_GIFT_RIBBON]; + u32 giftRibbonIds[NUM_GIFT_RIBBONS]; + u32 unused2; + u32 (*callback)(struct PokenavSub13 *); }; struct PokenavSub14 @@ -43,99 +60,99 @@ struct PokenavSub14 u16 nameWindowId; u16 ribbonCountWindowId; u16 listIdxWindowId; - u16 field_E; + u16 unusedWindowId; u16 monSpriteId; - struct Sprite *field_14; - u32 filler; + struct Sprite *bigRibbonSprite; + u32 unused; u8 tilemapBuffers[2][BG_SCREEN_SIZE]; }; -static u32 gUnknown_030012C0; -static u32 gUnknown_030012C4; +// Used for the initial drawing of the ribbons +static u32 sRibbonDraw_Total; +static u32 sRibbonDraw_Current; -void PrintCurrentMonRibbonCount(struct PokenavSub14 *structPtr); -void PrintRibbbonsSummaryMonInfo(struct PokenavSub14 *structPtr); -void PrintRibbonsMonListIndex(struct PokenavSub14 *structPtr); -void sub_81D1500(struct PokenavSub14 *structPtr); -void sub_81D0EFC(struct PokenavSub14 *structPtr); -void ResetSpritesAndDrawRibbonsMonFrontPic(struct PokenavSub14 *structPtr); -void AddRibbonListIndexWindow(struct PokenavSub14 *structPtr); -void DestroyRibbonsMonFrontPic(struct PokenavSub14 *structPtr); -void sub_81D11D8(struct PokenavSub14 *structPtr); -void sub_81D11FC(struct PokenavSub14 *structPtr); -void AddRibbonCountWindow(struct PokenavSub14 *structPtr); -void sub_81D1448(struct PokenavSub14 *structPtr); -void sub_81D13FC(struct PokenavSub14 *structPtr); -void AddRibbonSummaryMonNameWindow(struct PokenavSub14 *structPtr); -void sub_81D12D8(struct PokenavSub14 *structPtr); -bool32 sub_81D1524(struct PokenavSub14 *structPtr); -bool32 sub_81D1234(struct PokenavSub14 *structPtr); -void sub_81D0814(struct PokenavSub13 *structPtr); -u32 HandleExpandedRibbonInput(struct PokenavSub13 *structPtr); -u32 RibbonsSummaryHandleInput(struct PokenavSub13 *structPtr); -u32 ReturnToRibbonsListFromSummary(struct PokenavSub13 *structPtr); -bool32 sub_81D05DC(struct PokenavSub13 *structPtr); -bool32 sub_81D0688(struct PokenavSub13 *structPtr); -bool32 sub_81D0664(struct PokenavSub13 *structPtr); -bool32 sub_81D061C(struct PokenavSub13 *structPtr); -bool32 sub_81D0688(struct PokenavSub13 *structPtr); -bool32 GetCurrentLoopedTaskActive(void); -u32 GetRibbonsSummaryCurrentIndex(void); -u32 GetRibbonsSummaryMonListCount(void); -u16 DrawRibbonsMonFrontPic(s32 unused0, s32 unused1); -void sub_81D1258(struct Sprite *sprite, s32 arg1, s32 arg2, s32 arg3); -void sub_81D1284(struct Sprite *sprite); -void sub_81D1350(void); -void sub_81D13BC(u16 *dst, u32 id); -void sub_81D1370(u32 arg0, u32 id); -void sub_81D1538(struct Sprite *sprite); -u32 LoopedTask_OpenRibbonsSummaryMenu(s32 state); -u32 LoopedTask_UpdateRibbonsSummaryInfo(s32 state); -u32 LoopedTask_ExpandSelectedRibbon(s32 state); -u32 LoopedTask_MoveRibbonsCursorExpanded(s32 state); -u32 LoopedTask_ShrinkExpandedRibbon(s32 state); -u32 LoopedTask_ExitRibbonsSummaryMenu(s32 state); +static void PrintCurrentMonRibbonCount(struct PokenavSub14 *); +static void PrintRibbbonsSummaryMonInfo(struct PokenavSub14 *); +static void PrintRibbonsMonListIndex(struct PokenavSub14 *); +static void ZoomOutSelectedRibbon(struct PokenavSub14 *); +static void UpdateAndZoomInSelectedRibbon(struct PokenavSub14 *); +static void PrintRibbonNameAndDescription(struct PokenavSub14 *); +static void ResetSpritesAndDrawMonFrontPic(struct PokenavSub14 *); +static void AddRibbonListIndexWindow(struct PokenavSub14 *); +static void DestroyRibbonsMonFrontPic(struct PokenavSub14 *); +static void SlideMonSpriteOff(struct PokenavSub14 *); +static void SlideMonSpriteOn(struct PokenavSub14 *); +static void AddRibbonCountWindow(struct PokenavSub14 *); +static void CreateBigRibbonSprite(struct PokenavSub14 *); +static void AddRibbonSummaryMonNameWindow(struct PokenavSub14 *); +static void DrawAllRibbonsSmall(struct PokenavSub14 *); +static bool32 IsRibbonAnimating(struct PokenavSub14 *); +static bool32 IsMonSpriteAnimating(struct PokenavSub14 *); +static void GetMonRibbons(struct PokenavSub13 *); +static u32 HandleExpandedRibbonInput(struct PokenavSub13 *); +static u32 RibbonsSummaryHandleInput(struct PokenavSub13 *); +static u32 ReturnToRibbonsListFromSummary(struct PokenavSub13 *); +static bool32 TrySelectRibbonUp(struct PokenavSub13 *); +static bool32 TrySelectRibbonRight(struct PokenavSub13 *); +static bool32 TrySelectRibbonLeft(struct PokenavSub13 *); +static bool32 TrySelectRibbonDown(struct PokenavSub13 *); +static bool32 GetCurrentLoopedTaskActive(void); +static u32 GetRibbonsSummaryCurrentIndex(void); +static u32 GetRibbonsSummaryMonListCount(void); +static u16 DrawRibbonsMonFrontPic(s32, s32); +static void StartMonSpriteSlide(struct Sprite *, s32, s32, s32); +static void SpriteCB_MonSpriteSlide(struct Sprite *); +static void ClearRibbonsSummaryBg(void); +static void BufferSmallRibbonGfxData(u16 *, u32); +static void DrawRibbonSmall(u32, u32); +static void SpriteCB_WaitForRibbonAnimation(struct Sprite *); +static u32 LoopedTask_OpenRibbonsSummaryMenu(s32); +static u32 LoopedTask_SwitchRibbonsSummaryMon(s32); +static u32 LoopedTask_ExpandSelectedRibbon(s32); +static u32 LoopedTask_MoveRibbonsCursorExpanded(s32); +static u32 LoopedTask_ShrinkExpandedRibbon(s32); +static u32 LoopedTask_ExitRibbonsSummaryMenu(s32); struct { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; -} static const gUnknown_086237F8[] = + u8 numBits; // The number of bits needed to represent numRibbons + u8 numRibbons; // Never read. The contest ribbons have 4 (1 for each rank), the rest are just 1 ribbon + u8 ribbonId; + bool8 isGiftRibbon; +} static const sRibbonData[] = { - {1, 1, 0, 0}, - {3, 4, 1, 0}, - {3, 4, 5, 0}, - {3, 4, 9, 0}, - {3, 4, 13, 0}, - {3, 4, 17, 0}, - {1, 1, 21, 0}, - {1, 1, 22, 0}, - {1, 1, 23, 0}, - {1, 1, 24, 0}, - {1, 1, 25, 1}, - {1, 1, 26, 1}, - {1, 1, 27, 1}, - {1, 1, 28, 1}, - {1, 1, 29, 1}, - {1, 1, 30, 1}, - {1, 1, 31, 1} + {1, 1, CHAMPION_RIBBON, FALSE}, + {3, 4, COOL_RIBBON_NORMAL, FALSE}, + {3, 4, BEAUTY_RIBBON_NORMAL, FALSE}, + {3, 4, CUTE_RIBBON_NORMAL, FALSE}, + {3, 4, SMART_RIBBON_NORMAL, FALSE}, + {3, 4, TOUGH_RIBBON_NORMAL, FALSE}, + {1, 1, WINNING_RIBBON, FALSE}, + {1, 1, VICTORY_RIBBON, FALSE}, + {1, 1, ARTIST_RIBBON, FALSE}, + {1, 1, EFFORT_RIBBON, FALSE}, + {1, 1, MARINE_RIBBON, TRUE}, + {1, 1, LAND_RIBBON, TRUE}, + {1, 1, SKY_RIBBON, TRUE}, + {1, 1, COUNTRY_RIBBON, TRUE}, + {1, 1, NATIONAL_RIBBON, TRUE}, + {1, 1, EARTH_RIBBON, TRUE}, + {1, 1, WORLD_RIBBON, TRUE} }; #include "data/text/ribbon_descriptions.h" #include "data/text/gift_ribbon_descriptions.h" -static const u16 gUnknown_08623FF8[] = INCBIN_U16("graphics/pokenav/ribbons_icon1.gbapal"); -static const u16 gUnknown_08624018[] = INCBIN_U16("graphics/pokenav/ribbons_icon2.gbapal"); -static const u16 gUnknown_08624038[] = INCBIN_U16("graphics/pokenav/ribbons_icon3.gbapal"); -static const u16 gUnknown_08624058[] = INCBIN_U16("graphics/pokenav/ribbons_icon4.gbapal"); -static const u16 gUnknown_08624078[] = INCBIN_U16("graphics/pokenav/ribbons_icon5.gbapal"); -static const u16 gUnknown_08624098[] = INCBIN_U16("graphics/pokenav/8624098.gbapal"); -static const u32 sRibbonIconsSmall_Gfx[] = INCBIN_U32("graphics/pokenav/ribbons_icon.4bpp.lz"); -static const u32 sRibbonIconsBig_Gfx[] = INCBIN_U32("graphics/pokenav/ribbons_icon_big.4bpp.lz"); +static const u16 sRibbonIcons1_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/icons1.gbapal"); +static const u16 sRibbonIcons2_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/icons2.gbapal"); +static const u16 sRibbonIcons3_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/icons3.gbapal"); +static const u16 sRibbonIcons4_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/icons4.gbapal"); +static const u16 sRibbonIcons5_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/icons5.gbapal"); +static const u16 sMonInfo_Pal[] = INCBIN_U16("graphics/pokenav/ribbons/mon_info.gbapal"); // palette for Pokémon's name/gender/level text +static const u32 sRibbonIconsSmall_Gfx[] = INCBIN_U32("graphics/pokenav/ribbons/icons.4bpp.lz"); +static const u32 sRibbonIconsBig_Gfx[] = INCBIN_U32("graphics/pokenav/ribbons/icons_big.4bpp.lz"); -static const struct BgTemplate gUnknown_08624B98[] = +static const struct BgTemplate sBgTemplates[] = { { .bg = 1, @@ -160,14 +177,13 @@ static const struct BgTemplate gUnknown_08624B98[] = static const LoopedTask sRibbonsSummaryMenuLoopTaskFuncs[] = { [RIBBONS_SUMMARY_FUNC_NONE] = NULL, - [RIBBONS_SUMMARY_FUNC_MOVED_CURSOR] = LoopedTask_UpdateRibbonsSummaryInfo, + [RIBBONS_SUMMARY_FUNC_SWITCH_MONS] = LoopedTask_SwitchRibbonsSummaryMon, [RIBBONS_SUMMARY_FUNC_SELECT_RIBBON] = LoopedTask_ExpandSelectedRibbon, [RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE] = LoopedTask_MoveRibbonsCursorExpanded, [RIBBONS_SUMMARY_FUNC_EXPANDED_CANCEL] = LoopedTask_ShrinkExpandedRibbon, [RIBBONS_SUMMARY_FUNC_EXIT] = LoopedTask_ExitRibbonsSummaryMenu }; -// code bool32 PokenavCallback_Init_RibbonsSummaryMenu(void) { struct PokenavSub13 *structPtr = AllocSubstruct(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST, sizeof(struct PokenavSub13)); @@ -178,7 +194,7 @@ bool32 PokenavCallback_Init_RibbonsSummaryMenu(void) if (structPtr->monList == NULL) return FALSE; - sub_81D0814(structPtr); + GetMonRibbons(structPtr); structPtr->callback = RibbonsSummaryHandleInput; gKeyRepeatContinueDelay = 3; gKeyRepeatStartDelay = 10; @@ -196,153 +212,170 @@ void FreeRibbonsSummaryScreen1(void) FreePokenavSubstruct(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); } -u32 RibbonsSummaryHandleInput(struct PokenavSub13 *structPtr) +// Handles input when a specific ribbon is not currently selected +static u32 RibbonsSummaryHandleInput(struct PokenavSub13 *structPtr) { + // Handle Up/Down movement to select a new Pokémon to show ribbons for if (JOY_REPEAT(DPAD_UP) && structPtr->monList->currIndex != 0) { structPtr->monList->currIndex--; - structPtr->field_C = 0; - sub_81D0814(structPtr); - return RIBBONS_SUMMARY_FUNC_MOVED_CURSOR; + structPtr->selectedPos = 0; + GetMonRibbons(structPtr); + return RIBBONS_SUMMARY_FUNC_SWITCH_MONS; } if (JOY_REPEAT(DPAD_DOWN) && structPtr->monList->currIndex < structPtr->monList->listCount - 1) { structPtr->monList->currIndex++; - structPtr->field_C = 0; - sub_81D0814(structPtr); - return RIBBONS_SUMMARY_FUNC_MOVED_CURSOR; + structPtr->selectedPos = 0; + GetMonRibbons(structPtr); + return RIBBONS_SUMMARY_FUNC_SWITCH_MONS; } + if (JOY_NEW(A_BUTTON)) { + // Enter ribbon selection structPtr->callback = HandleExpandedRibbonInput; return RIBBONS_SUMMARY_FUNC_SELECT_RIBBON; } if (JOY_NEW(B_BUTTON)) { + // Exit ribbon summary menu structPtr->callback = ReturnToRibbonsListFromSummary; return RIBBONS_SUMMARY_FUNC_EXIT; } return RIBBONS_SUMMARY_FUNC_NONE; } -u32 HandleExpandedRibbonInput(struct PokenavSub13 *structPtr) +// Handles input when a ribbon is selected +static u32 HandleExpandedRibbonInput(struct PokenavSub13 *structPtr) { - if (JOY_REPEAT(DPAD_UP) && sub_81D05DC(structPtr)) + // Handle movement while a ribbon is selected + if (JOY_REPEAT(DPAD_UP) && TrySelectRibbonUp(structPtr)) return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_REPEAT(DPAD_DOWN) && sub_81D061C(structPtr)) + if (JOY_REPEAT(DPAD_DOWN) && TrySelectRibbonDown(structPtr)) return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_REPEAT(DPAD_LEFT) && sub_81D0664(structPtr)) + if (JOY_REPEAT(DPAD_LEFT) && TrySelectRibbonLeft(structPtr)) return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_REPEAT(DPAD_RIGHT) && sub_81D0688(structPtr)) + if (JOY_REPEAT(DPAD_RIGHT) && TrySelectRibbonRight(structPtr)) return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; + if (JOY_NEW(B_BUTTON)) { + // Exit ribbon selection structPtr->callback = RibbonsSummaryHandleInput; return RIBBONS_SUMMARY_FUNC_EXPANDED_CANCEL; } return RIBBONS_SUMMARY_FUNC_NONE; } -u32 ReturnToRibbonsListFromSummary(struct PokenavSub13 *structPtr) +static u32 ReturnToRibbonsListFromSummary(struct PokenavSub13 *structPtr) { return POKENAV_RIBBONS_RETURN_TO_MON_LIST; } -bool32 sub_81D05DC(struct PokenavSub13 *structPtr) +static bool32 TrySelectRibbonUp(struct PokenavSub13 *structPtr) { - if (structPtr->field_C < 25) + if (structPtr->selectedPos < FIRST_GIFT_RIBBON) { - if (structPtr->field_C <= 8) + // In normal ribbons, try to move up a row + if (structPtr->selectedPos < RIBBONS_PER_ROW) return FALSE; - structPtr->field_C -= 9; + structPtr->selectedPos -= RIBBONS_PER_ROW; return TRUE; } - if (structPtr->field_10 != 0) + if (structPtr->numNormalRibbons != 0) { - u32 var = structPtr->field_C - 27; - structPtr->field_C = var + structPtr->field_E; - if (structPtr->field_C >= structPtr->field_10) - structPtr->field_C = structPtr->field_10 - 1; + // In gift ribbons, try to move up into normal ribbons + // If there's > 1 row of gift ribbons (not normally possible) + // it's impossible to move up between them + u32 ribbonPos = structPtr->selectedPos - GIFT_RIBBON_START_POS; + structPtr->selectedPos = ribbonPos + structPtr->normalRibbonLastRowStart; + if (structPtr->selectedPos >= structPtr->numNormalRibbons) + structPtr->selectedPos = structPtr->numNormalRibbons - 1; return TRUE; } return FALSE; } -bool32 sub_81D061C(struct PokenavSub13 *structPtr) +static bool32 TrySelectRibbonDown(struct PokenavSub13 *structPtr) { - if (structPtr->field_C >= 25) + if (structPtr->selectedPos >= FIRST_GIFT_RIBBON) return FALSE; - if (structPtr->field_C < structPtr->field_E) + if (structPtr->selectedPos < structPtr->normalRibbonLastRowStart) { - structPtr->field_C += 9; - if (structPtr->field_C >= structPtr->field_10) - structPtr->field_C = structPtr->field_10 - 1; + // Not in last row of normal ribbons, advance to next row + structPtr->selectedPos += RIBBONS_PER_ROW; + if (structPtr->selectedPos >= structPtr->numNormalRibbons) + structPtr->selectedPos = structPtr->numNormalRibbons - 1; return TRUE; } - if (structPtr->field_12 != 0) + if (structPtr->numGiftRibbons != 0) { - int var = structPtr->field_C - structPtr->field_E; - if (var >= structPtr->field_12) - var = structPtr->field_12 - 1; + // In/beyond last of row of normal ribbons and gift ribbons present, move down to gift ribbon row + int ribbonPos = structPtr->selectedPos - structPtr->normalRibbonLastRowStart; + if (ribbonPos >= structPtr->numGiftRibbons) + ribbonPos = structPtr->numGiftRibbons - 1; - structPtr->field_C = var + 27; + structPtr->selectedPos = ribbonPos + GIFT_RIBBON_START_POS; return TRUE; } return FALSE; } -bool32 sub_81D0664(struct PokenavSub13 *structPtr) +static bool32 TrySelectRibbonLeft(struct PokenavSub13 *structPtr) { - u16 var = structPtr->field_C % 9; - if (var != 0) + u16 column = structPtr->selectedPos % RIBBONS_PER_ROW; + if (column != 0) { - structPtr->field_C--; + structPtr->selectedPos--; return TRUE; } return FALSE; } -bool32 sub_81D0688(struct PokenavSub13 *structPtr) +static bool32 TrySelectRibbonRight(struct PokenavSub13 *structPtr) { - int r1 = structPtr->field_C % 9; + int column = structPtr->selectedPos % RIBBONS_PER_ROW; - if (r1 >= 8) + if (column >= RIBBONS_PER_ROW - 1) return FALSE; - if (structPtr->field_C <= 26) + if (structPtr->selectedPos < GIFT_RIBBON_START_POS) { - if (structPtr->field_C < structPtr->field_10 - 1) + // Move right in normal ribbon row + if (structPtr->selectedPos < structPtr->numNormalRibbons - 1) { - structPtr->field_C++; + structPtr->selectedPos++; return TRUE; } } else { - if (r1 < structPtr->field_12 - 1) + // Move right in gift ribbon row + if (column < structPtr->numGiftRibbons - 1) { - structPtr->field_C++; + structPtr->selectedPos++; return TRUE; } } return FALSE; } -u32 GetRibbonsSummaryCurrentIndex(void) +static u32 GetRibbonsSummaryCurrentIndex(void) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); return structPtr->monList->currIndex; } -u32 GetRibbonsSummaryMonListCount(void) +static u32 GetRibbonsSummaryMonListCount(void) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); return structPtr->monList->listCount; } -static void GetCurrMonInfo1(u8 *nick, u8 *level, u8 *gender) +static void GetMonNicknameLevelGender(u8 *nick, u8 *level, u8 *gender) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); struct PokenavSub18 *mons = structPtr->monList; @@ -350,6 +383,7 @@ static void GetCurrMonInfo1(u8 *nick, u8 *level, u8 *gender) if (monInfo->boxId == TOTAL_BOXES_COUNT) { + // Get info for party mon struct Pokemon *mon = &gPlayerParty[monInfo->monId]; GetMonData(mon, MON_DATA_NICKNAME, nick); *level = GetLevelFromMonExp(mon); @@ -357,6 +391,7 @@ static void GetCurrMonInfo1(u8 *nick, u8 *level, u8 *gender) } else { + // Get info for PC box mon struct BoxPokemon *boxMon = GetBoxedMonPtr(monInfo->boxId, monInfo->monId); *gender = GetBoxMonGender(boxMon); *level = GetLevelFromBoxMonExp(boxMon); @@ -365,7 +400,7 @@ static void GetCurrMonInfo1(u8 *nick, u8 *level, u8 *gender) StringGetEnd10(nick); } -static void GetCurrMonInfo2(u16 *species, u32 *personality, u32 *otId) +static void GetMonSpeciesPersonalityOtId(u16 *species, u32 *personality, u32 *otId) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); struct PokenavSub18 *mons = structPtr->monList; @@ -373,6 +408,7 @@ static void GetCurrMonInfo2(u16 *species, u32 *personality, u32 *otId) if (monInfo->boxId == TOTAL_BOXES_COUNT) { + // Get info for party mon struct Pokemon *mon = &gPlayerParty[monInfo->monId]; *species = GetMonData(mon, MON_DATA_SPECIES); *personality = GetMonData(mon, MON_DATA_PERSONALITY); @@ -380,6 +416,7 @@ static void GetCurrMonInfo2(u16 *species, u32 *personality, u32 *otId) } else { + // Get info for PC box mon struct BoxPokemon *boxMon = GetBoxedMonPtr(monInfo->boxId, monInfo->monId); *species = GetBoxMonData(boxMon, MON_DATA_SPECIES); *personality = GetBoxMonData(boxMon, MON_DATA_PERSONALITY); @@ -399,76 +436,79 @@ static u32 GetCurrMonRibbonCount(void) return GetBoxMonDataAt(monInfo->boxId, monInfo->monId, MON_DATA_RIBBON_COUNT); } -void sub_81D0814(struct PokenavSub13 *structPtr) +static void GetMonRibbons(struct PokenavSub13 *structPtr) { - u32 ribbons; + u32 ribbonFlags; s32 i, j; struct PokenavSub18 *mons = structPtr->monList; struct PokenavMonList *monInfo = &mons->monData[mons->currIndex]; if (monInfo->boxId == TOTAL_BOXES_COUNT) - ribbons = GetMonData(&gPlayerParty[monInfo->monId], MON_DATA_RIBBONS); + ribbonFlags = GetMonData(&gPlayerParty[monInfo->monId], MON_DATA_RIBBONS); else - ribbons = GetBoxMonDataAt(monInfo->boxId, monInfo->monId, MON_DATA_RIBBONS); + ribbonFlags = GetBoxMonDataAt(monInfo->boxId, monInfo->monId, MON_DATA_RIBBONS); - structPtr->field_10 = 0; - structPtr->field_12 = 0; - for (i = 0; i < ARRAY_COUNT(gUnknown_086237F8); i++) + structPtr->numNormalRibbons = 0; + structPtr->numGiftRibbons = 0; + for (i = 0; i < ARRAY_COUNT(sRibbonData); i++) { - s32 r4 = ((1 << gUnknown_086237F8[i].unk0) - 1) & ribbons; - if (gUnknown_086237F8[i].unk3 == 0) + // For all non-contest ribbons, numRibbons will be 1 if they have it, 0 if they don't + // For contest ribbons, numRibbons will be 0-4 + s32 numRibbons = ((1 << sRibbonData[i].numBits) - 1) & ribbonFlags; + if (!sRibbonData[i].isGiftRibbon) { - for (j = 0; j < r4; j++) - structPtr->field_14[structPtr->field_10++] = gUnknown_086237F8[i].unk2 + j; + for (j = 0; j < numRibbons; j++) + structPtr->ribbonIds[structPtr->numNormalRibbons++] = sRibbonData[i].ribbonId + j; } else { - for (j = 0; j < r4; j++) - structPtr->field_78[structPtr->field_12++] = gUnknown_086237F8[i].unk2 + j; + for (j = 0; j < numRibbons; j++) + structPtr->giftRibbonIds[structPtr->numGiftRibbons++] = sRibbonData[i].ribbonId + j; } - ribbons >>= gUnknown_086237F8[i].unk0; + ribbonFlags >>= sRibbonData[i].numBits; } - if (structPtr->field_10 != 0) + if (structPtr->numNormalRibbons != 0) { - structPtr->field_E = ((structPtr->field_10 - 1) / 9) * 9; - structPtr->field_C = 0; + structPtr->normalRibbonLastRowStart = ((structPtr->numNormalRibbons - 1) / RIBBONS_PER_ROW) * RIBBONS_PER_ROW; + structPtr->selectedPos = 0; } else { - structPtr->field_E = 0; - structPtr->field_C = 27; + // There are no normal ribbons, move cursor to first gift ribbon + structPtr->normalRibbonLastRowStart = 0; + structPtr->selectedPos = GIFT_RIBBON_START_POS; } } -u32 *sub_81D0914(u32 *arg0) +static u32 *GetNormalRibbonIds(u32 *size) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); - *arg0 = structPtr->field_10; - return structPtr->field_14; + *size = structPtr->numNormalRibbons; + return structPtr->ribbonIds; } -u32 *sub_81D092C(u32 *arg0) +static u32 *GetGiftRibbonIds(u32 *size) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); - *arg0 = structPtr->field_12; - return structPtr->field_78; + *size = structPtr->numGiftRibbons; + return structPtr->giftRibbonIds; } -u16 sub_81D0944(void) +static u16 GetSelectedPosition(void) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); - return structPtr->field_C; + return structPtr->selectedPos; } -u32 sub_81D0954(void) +static u32 GetRibbonId(void) { struct PokenavSub13 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_LIST); - int var = structPtr->field_C; - if (var <= 24) - return structPtr->field_14[var]; + int ribbonPos = structPtr->selectedPos; + if (ribbonPos < FIRST_GIFT_RIBBON) + return structPtr->ribbonIds[ribbonPos]; else - return structPtr->field_78[var - 27]; + return structPtr->giftRibbonIds[ribbonPos - GIFT_RIBBON_START_POS]; } bool32 OpenRibbonsSummaryMenu(void) @@ -501,36 +541,38 @@ void FreeRibbonsSummaryScreen2(void) RemoveWindow(structPtr->ribbonCountWindowId); RemoveWindow(structPtr->nameWindowId); RemoveWindow(structPtr->listIdxWindowId); - RemoveWindow(structPtr->field_E); +#ifndef BUGFIX + RemoveWindow(structPtr->unusedWindowId); // Removing window, but window id is never set +#endif DestroyRibbonsMonFrontPic(structPtr); - FreeSpriteTilesByTag(9); - FreeSpritePaletteByTag(0xF); - FreeSpritePaletteByTag(0x10); - FreeSpritePaletteByTag(0x11); - FreeSpritePaletteByTag(0x12); - FreeSpritePaletteByTag(0x13); - FreeSpriteOamMatrix(structPtr->field_14); - DestroySprite(structPtr->field_14); + FreeSpriteTilesByTag(GFXTAG_RIBBON_ICONS_BIG); + FreeSpritePaletteByTag(PALTAG_RIBBON_ICONS_1); + FreeSpritePaletteByTag(PALTAG_RIBBON_ICONS_2); + FreeSpritePaletteByTag(PALTAG_RIBBON_ICONS_3); + FreeSpritePaletteByTag(PALTAG_RIBBON_ICONS_4); + FreeSpritePaletteByTag(PALTAG_RIBBON_ICONS_5); + FreeSpriteOamMatrix(structPtr->bigRibbonSprite); + DestroySprite(structPtr->bigRibbonSprite); FreePokenavSubstruct(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); } -bool32 GetCurrentLoopedTaskActive(void) +static bool32 GetCurrentLoopedTaskActive(void) { struct PokenavSub14 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); return IsLoopedTaskActive(structPtr->loopedTaskId); } -u32 LoopedTask_OpenRibbonsSummaryMenu(s32 state) +static u32 LoopedTask_OpenRibbonsSummaryMenu(s32 state) { struct PokenavSub14 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); switch (state) { case 0: - InitBgTemplates(gUnknown_08624B98, ARRAY_COUNT(gUnknown_08624B98)); - DecompressAndCopyTileDataToVram(2, gUnknown_08DDE030, 0, 0, 0); + InitBgTemplates(sBgTemplates, ARRAY_COUNT(sBgTemplates)); + DecompressAndCopyTileDataToVram(2, gPokenavRibbonsSummaryBg_Gfx, 0, 0, 0); SetBgTilemapBuffer(2, structPtr->tilemapBuffers[0]); - CopyToBgTilemapBuffer(2, gUnknown_08DDE12C, 0, 0); - CopyPaletteIntoBufferUnfaded(gUnknown_08DDE010, 0x10, 0x20); + CopyToBgTilemapBuffer(2, gPokenavRibbonsSummaryBg_Tilemap, 0, 0); + CopyPaletteIntoBufferUnfaded(gPokenavRibbonsSummaryBg_Pal, 0x10, 0x20); CopyBgTilemapBufferToVram(2); return LT_INC_AND_PAUSE; case 1: @@ -540,8 +582,8 @@ u32 LoopedTask_OpenRibbonsSummaryMenu(s32 state) DecompressAndCopyTileDataToVram(1, sRibbonIconsSmall_Gfx, 0, 1, 0); SetBgTilemapBuffer(1, structPtr->tilemapBuffers[1]); FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 32, 20); - CopyPaletteIntoBufferUnfaded(gUnknown_08623FF8, 0x20, 0xA0); - CopyPaletteIntoBufferUnfaded(gUnknown_08624098, 0xA0, 0x20); + CopyPaletteIntoBufferUnfaded(sRibbonIcons1_Pal, 0x20, 0xA0); + CopyPaletteIntoBufferUnfaded(sMonInfo_Pal, 0xA0, 0x20); CopyBgTilemapBufferToVram(1); return LT_INC_AND_PAUSE; } @@ -577,18 +619,18 @@ u32 LoopedTask_OpenRibbonsSummaryMenu(s32 state) case 6: if (!IsDma3ManagerBusyWithBgCopy()) { - ResetSpritesAndDrawRibbonsMonFrontPic(structPtr); + ResetSpritesAndDrawMonFrontPic(structPtr); return LT_INC_AND_CONTINUE; } return LT_PAUSE; case 7: - sub_81D12D8(structPtr); + DrawAllRibbonsSmall(structPtr); PrintHelpBarText(HELPBAR_RIBBONS_LIST); return LT_INC_AND_PAUSE; case 8: if (!IsDma3ManagerBusyWithBgCopy()) { - sub_81D13FC(structPtr); + CreateBigRibbonSprite(structPtr); ChangeBgX(1, 0, 0); ChangeBgY(1, 0, 0); ChangeBgX(2, 0, 0); @@ -603,12 +645,11 @@ u32 LoopedTask_OpenRibbonsSummaryMenu(s32 state) case 9: if (IsPaletteFadeActive()) return LT_PAUSE; - return LT_FINISH; } return LT_FINISH; } -u32 LoopedTask_ExitRibbonsSummaryMenu(s32 state) +static u32 LoopedTask_ExitRibbonsSummaryMenu(s32 state) { switch (state) { @@ -624,24 +665,24 @@ u32 LoopedTask_ExitRibbonsSummaryMenu(s32 state) return LT_FINISH; } -u32 LoopedTask_UpdateRibbonsSummaryInfo(s32 state) +static u32 LoopedTask_SwitchRibbonsSummaryMon(s32 state) { struct PokenavSub14 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); switch (state) { case 0: PlaySE(SE_SELECT); - sub_81D11D8(structPtr); + SlideMonSpriteOff(structPtr); return LT_INC_AND_PAUSE; case 1: - if (!sub_81D1234(structPtr)) + if (!IsMonSpriteAnimating(structPtr)) { PrintRibbbonsSummaryMonInfo(structPtr); return LT_INC_AND_CONTINUE; } return LT_PAUSE; case 2: - sub_81D12D8(structPtr); + DrawAllRibbonsSmall(structPtr); return LT_INC_AND_CONTINUE; case 3: PrintRibbonsMonListIndex(structPtr); @@ -652,31 +693,30 @@ u32 LoopedTask_UpdateRibbonsSummaryInfo(s32 state) case 5: if (!IsDma3ManagerBusyWithBgCopy()) { - sub_81D11FC(structPtr); + SlideMonSpriteOn(structPtr); return LT_INC_AND_PAUSE; } return LT_PAUSE; case 6: - if (sub_81D1234(structPtr)) + if (IsMonSpriteAnimating(structPtr)) return LT_PAUSE; - return LT_FINISH; } return LT_FINISH; } -u32 LoopedTask_ExpandSelectedRibbon(s32 state) +static u32 LoopedTask_ExpandSelectedRibbon(s32 state) { struct PokenavSub14 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); switch (state) { case 0: PlaySE(SE_SELECT); - sub_81D1448(structPtr); + UpdateAndZoomInSelectedRibbon(structPtr); return LT_INC_AND_PAUSE; case 1: - if (!sub_81D1524(structPtr)) + if (!IsRibbonAnimating(structPtr)) { - sub_81D0EFC(structPtr); + PrintRibbonNameAndDescription(structPtr); PrintHelpBarText(HELPBAR_RIBBONS_CHECK); return LT_INC_AND_PAUSE; } @@ -688,26 +728,26 @@ u32 LoopedTask_ExpandSelectedRibbon(s32 state) return LT_FINISH; } -u32 LoopedTask_MoveRibbonsCursorExpanded(s32 state) +static u32 LoopedTask_MoveRibbonsCursorExpanded(s32 state) { struct PokenavSub14 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); switch (state) { case 0: PlaySE(SE_SELECT); - sub_81D1500(structPtr); + ZoomOutSelectedRibbon(structPtr); return LT_INC_AND_PAUSE; case 1: - if (!sub_81D1524(structPtr)) + if (!IsRibbonAnimating(structPtr)) { - sub_81D1448(structPtr); + UpdateAndZoomInSelectedRibbon(structPtr); return LT_INC_AND_PAUSE; } return LT_PAUSE; case 2: - if (!sub_81D1524(structPtr)) + if (!IsRibbonAnimating(structPtr)) { - sub_81D0EFC(structPtr); + PrintRibbonNameAndDescription(structPtr); return LT_INC_AND_PAUSE; } return LT_PAUSE; @@ -718,17 +758,17 @@ u32 LoopedTask_MoveRibbonsCursorExpanded(s32 state) return LT_FINISH; } -u32 LoopedTask_ShrinkExpandedRibbon(s32 state) +static u32 LoopedTask_ShrinkExpandedRibbon(s32 state) { struct PokenavSub14 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_RIBBONS_SUMMARY_MENU); switch (state) { case 0: PlaySE(SE_SELECT); - sub_81D1500(structPtr); + ZoomOutSelectedRibbon(structPtr); return LT_INC_AND_PAUSE; case 1: - if (!sub_81D1524(structPtr)) + if (!IsRibbonAnimating(structPtr)) { PrintCurrentMonRibbonCount(structPtr); PrintHelpBarText(HELPBAR_RIBBONS_LIST); @@ -753,14 +793,14 @@ static const struct WindowTemplate sRibbonCountWindowTemplate = .baseBlock = 0x14, }; -void AddRibbonCountWindow(struct PokenavSub14 *structPtr) +static void AddRibbonCountWindow(struct PokenavSub14 *structPtr) { structPtr->ribbonCountWindowId = AddWindow(&sRibbonCountWindowTemplate); PutWindowTilemap(structPtr->ribbonCountWindowId); PrintCurrentMonRibbonCount(structPtr); } -void PrintCurrentMonRibbonCount(struct PokenavSub14 *structPtr) +static void PrintCurrentMonRibbonCount(struct PokenavSub14 *structPtr) { u8 color[] = {TEXT_COLOR_RED, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY}; @@ -773,24 +813,31 @@ void PrintCurrentMonRibbonCount(struct PokenavSub14 *structPtr) CopyWindowToVram(structPtr->ribbonCountWindowId, 2); } -void sub_81D0EFC(struct PokenavSub14 *structPtr) +static void PrintRibbonNameAndDescription(struct PokenavSub14 *structPtr) { s32 i; - u32 ribbonId = sub_81D0954(); + u32 ribbonId = GetRibbonId(); u8 color[] = {TEXT_COLOR_RED, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY}; FillWindowPixelBuffer(structPtr->ribbonCountWindowId, PIXEL_FILL(4)); - if (ribbonId < 25) + if (ribbonId < FIRST_GIFT_RIBBON) { + // Print normal ribbon name/description for (i = 0; i < 2; i++) AddTextPrinterParameterized3(structPtr->ribbonCountWindowId, 1, 0, (i * 16) + 1, color, -1, gRibbonDescriptionPointers[ribbonId][i]); } else { - ribbonId = gSaveBlock1Ptr->giftRibbons[ribbonId - 25]; + // ribbonId here is one of the 'gift' ribbon slots, used to read + // its actual value from giftRibbons to determine which specific + // gift ribbon it is + ribbonId = gSaveBlock1Ptr->giftRibbons[ribbonId - FIRST_GIFT_RIBBON]; + + // If 0, this gift ribbon slot is unoccupied if (ribbonId == 0) return; + // Print gift ribbon name/description ribbonId--; for (i = 0; i < 2; i++) AddTextPrinterParameterized3(structPtr->ribbonCountWindowId, 1, 0, (i * 16) + 1, color, -1, gGiftRibbonDescriptionPointers[ribbonId][i]); @@ -810,7 +857,7 @@ static const struct WindowTemplate sRibbonSummaryMonNameWindowTemplate = .baseBlock = 0x54, }; -void AddRibbonSummaryMonNameWindow(struct PokenavSub14 *structPtr) +static void AddRibbonSummaryMonNameWindow(struct PokenavSub14 *structPtr) { structPtr->nameWindowId = AddWindow(&sRibbonSummaryMonNameWindowTemplate); PutWindowTilemap(structPtr->nameWindowId); @@ -821,7 +868,7 @@ static const u8 sMaleIconString[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_RED}{WHITE static const u8 sFemaleIconString[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_GREEN}{WHITE}{BLUE}♀{COLOR_HIGHLIGHT_SHADOW}{DARK_GREY}{WHITE}{LIGHT_GREY}"); static const u8 sGenderlessIconString[] = _("{UNK_SPACER}"); -void PrintRibbbonsSummaryMonInfo(struct PokenavSub14 *structPtr) +static void PrintRibbbonsSummaryMonInfo(struct PokenavSub14 *structPtr) { const u8 *genderTxt; u8 *txtPtr; @@ -829,7 +876,7 @@ void PrintRibbbonsSummaryMonInfo(struct PokenavSub14 *structPtr) u16 windowId = structPtr->nameWindowId; FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); - GetCurrMonInfo1(gStringVar3, &level, &gender); + GetMonNicknameLevelGender(gStringVar3, &level, &gender); AddTextPrinterParameterized(windowId, 1, gStringVar3, 0, 1, TEXT_SPEED_FF, NULL); switch (gender) { @@ -867,7 +914,7 @@ static const struct WindowTemplate sRibbonMonListIndexWindowTemplate[] = {}, }; -void AddRibbonListIndexWindow(struct PokenavSub14 *structPtr) +static void AddRibbonListIndexWindow(struct PokenavSub14 *structPtr) { structPtr->listIdxWindowId = AddWindow(sRibbonMonListIndexWindowTemplate); FillWindowPixelBuffer(structPtr->listIdxWindowId, PIXEL_FILL(1)); @@ -875,7 +922,7 @@ void AddRibbonListIndexWindow(struct PokenavSub14 *structPtr) PrintRibbonsMonListIndex(structPtr); } -void PrintRibbonsMonListIndex(struct PokenavSub14 *structPtr) +static void PrintRibbonsMonListIndex(struct PokenavSub14 *structPtr) { s32 x; u8 *txtPtr; @@ -890,181 +937,219 @@ void PrintRibbonsMonListIndex(struct PokenavSub14 *structPtr) CopyWindowToVram(structPtr->listIdxWindowId, 2); } -void ResetSpritesAndDrawRibbonsMonFrontPic(struct PokenavSub14 *structPtr) +static void ResetSpritesAndDrawMonFrontPic(struct PokenavSub14 *structPtr) { u16 species; u32 personality, otId; - GetCurrMonInfo2(&species, &personality, &otId); + GetMonSpeciesPersonalityOtId(&species, &personality, &otId); ResetAllPicSprites(); - structPtr->monSpriteId = DrawRibbonsMonFrontPic(40, 104); + structPtr->monSpriteId = DrawRibbonsMonFrontPic(MON_SPRITE_X_ON, MON_SPRITE_Y); PokenavFillPalette(15, 0); } -void DestroyRibbonsMonFrontPic(struct PokenavSub14 *structPtr) +static void DestroyRibbonsMonFrontPic(struct PokenavSub14 *structPtr) { FreeAndDestroyMonPicSprite(structPtr->monSpriteId); } -u16 DrawRibbonsMonFrontPic(s32 unused0, s32 unused1) +// x and y arguments are ignored +// y is always given as MON_SPRITE_Y +// x is given as either MON_SPRITE_X_ON or MON_SPRITE_X_OFF (but ignored and MON_SPRITE_X_ON is used) +static u16 DrawRibbonsMonFrontPic(s32 x, s32 y) { u16 species, spriteId; u32 personality, otId; - GetCurrMonInfo2(&species, &personality, &otId); - spriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, 40, 104, 15, 0xFFFF); + GetMonSpeciesPersonalityOtId(&species, &personality, &otId); + spriteId = CreateMonPicSprite_HandleDeoxys(species, otId, personality, TRUE, MON_SPRITE_X_ON, MON_SPRITE_Y, 15, 0xFFFF); gSprites[spriteId].oam.priority = 0; return spriteId; } -void sub_81D11D8(struct PokenavSub14 *structPtr) +static void SlideMonSpriteOff(struct PokenavSub14 *structPtr) { - sub_81D1258(&gSprites[structPtr->monSpriteId], 40, -32, 6); + StartMonSpriteSlide(&gSprites[structPtr->monSpriteId], MON_SPRITE_X_ON, MON_SPRITE_X_OFF, 6); } -void sub_81D11FC(struct PokenavSub14 *structPtr) +static void SlideMonSpriteOn(struct PokenavSub14 *structPtr) { + // Switch to new mon sprite FreeAndDestroyMonPicSprite(structPtr->monSpriteId); - structPtr->monSpriteId = DrawRibbonsMonFrontPic(-32, 104); - sub_81D1258(&gSprites[structPtr->monSpriteId], -32, 40, 6); + structPtr->monSpriteId = DrawRibbonsMonFrontPic(MON_SPRITE_X_OFF, MON_SPRITE_Y); + + // Slide on + StartMonSpriteSlide(&gSprites[structPtr->monSpriteId], MON_SPRITE_X_OFF, MON_SPRITE_X_ON, 6); } -bool32 sub_81D1234(struct PokenavSub14 *structPtr) +// Is Pokémon summary sprite still sliding off/on +static bool32 IsMonSpriteAnimating(struct PokenavSub14 *structPtr) { return (gSprites[structPtr->monSpriteId].callback != SpriteCallbackDummy); } -void sub_81D1258(struct Sprite *sprite, s32 arg1, s32 arg2, s32 arg3) +#define sCurrX data[0] +#define sMoveIncr data[1] +#define sTime data[2] +#define sDestX data[3] + +static void StartMonSpriteSlide(struct Sprite *sprite, s32 startX, s32 destX, s32 time) { - u32 var = arg2 - arg1; + u32 delta = destX - startX; - sprite->pos1.x = arg1; - sprite->data[0] = arg1 << 4; - sprite->data[1] = (var << 4) / arg3; - sprite->data[2] = arg3; - sprite->data[3] = arg2; + sprite->pos1.x = startX; + sprite->sCurrX = startX << 4; + sprite->sMoveIncr = (delta << 4) / time; + sprite->sTime = time; + sprite->sDestX = destX; - sprite->callback = sub_81D1284; + sprite->callback = SpriteCB_MonSpriteSlide; } -void sub_81D1284(struct Sprite *sprite) +static void SpriteCB_MonSpriteSlide(struct Sprite *sprite) { - if (sprite->data[2] != 0) + if (sprite->sTime != 0) { - sprite->data[2]--; - sprite->data[0] += sprite->data[1]; - sprite->pos1.x = sprite->data[0] >> 4; - if (sprite->pos1.x <= -32) + sprite->sTime--; + sprite->sCurrX += sprite->sMoveIncr; + sprite->pos1.x = sprite->sCurrX >> 4; + if (sprite->pos1.x <= MON_SPRITE_X_OFF) sprite->invisible = TRUE; else sprite->invisible = FALSE; } else { - sprite->pos1.x = sprite->data[3]; + sprite->pos1.x = sprite->sDestX; sprite->callback = SpriteCallbackDummy; } } -void sub_81D12D8(struct PokenavSub14 *structPtr) +#undef sCurrX +#undef sMoveIncr +#undef sTime +#undef sDestX + +static void DrawAllRibbonsSmall(struct PokenavSub14 *structPtr) { - u32 *ptr; + u32 *ribbonIds; - sub_81D1350(); + ClearRibbonsSummaryBg(); - ptr = sub_81D0914(&gUnknown_030012C0); - for (gUnknown_030012C4 = 0; gUnknown_030012C4 < gUnknown_030012C0; gUnknown_030012C4++) - sub_81D1370(gUnknown_030012C4, *(ptr++)); + ribbonIds = GetNormalRibbonIds(&sRibbonDraw_Total); + for (sRibbonDraw_Current = 0; sRibbonDraw_Current < sRibbonDraw_Total; sRibbonDraw_Current++) + DrawRibbonSmall(sRibbonDraw_Current, *(ribbonIds++)); - ptr = sub_81D092C(&gUnknown_030012C0); - for (gUnknown_030012C4 = 0; gUnknown_030012C4 < gUnknown_030012C0; gUnknown_030012C4++) - sub_81D1370(gUnknown_030012C4 + 27, *(ptr++)); + ribbonIds = GetGiftRibbonIds(&sRibbonDraw_Total); + for (sRibbonDraw_Current = 0; sRibbonDraw_Current < sRibbonDraw_Total; sRibbonDraw_Current++) + DrawRibbonSmall(sRibbonDraw_Current + GIFT_RIBBON_START_POS, *(ribbonIds++)); CopyBgTilemapBufferToVram(1); } -void sub_81D1350(void) +// Redundant, the same FillBg is called in LoopedTask_OpenRibbonsSummaryMenu +static void ClearRibbonsSummaryBg(void) { FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 32, 20); } -void sub_81D1370(u32 arg0, u32 id) +static void DrawRibbonSmall(u32 i, u32 ribbonId) { u16 bgData[4]; - u32 destX = (arg0 % 9) * 2 + 11; - u32 destY = (arg0 / 9) * 2 + 4; + u32 destX = (i % RIBBONS_PER_ROW) * 2 + 11; + u32 destY = (i / RIBBONS_PER_ROW) * 2 + 4; - sub_81D13BC(bgData, id); + BufferSmallRibbonGfxData(bgData, ribbonId); CopyToBgTilemapBufferRect(1, bgData, destX, destY, 2, 2); } +// Below correspond to a ribbon icon in ribbons/icons.png and ribbons/icons_big.png; 0 at top, 11 at bottom +enum { + RIBBONGFX_CHAMPION, + RIBBONGFX_CONTEST_NORMAL, + RIBBONGFX_CONTEST_SUPER, + RIBBONGFX_CONTEST_HYPER, + RIBBONGFX_CONTEST_MASTER, + RIBBONGFX_WINNING, + RIBBONGFX_VICTORY, + RIBBONGFX_ARTIST, + RIBBONGFX_EFFORT, + RIBBONGFX_GIFT_1, + RIBBONGFX_GIFT_2, + RIBBONGFX_GIFT_3, +}; + +#define TO_PAL_OFFSET(palNum)((palNum) - PALTAG_RIBBON_ICONS_1) + struct { - u16 var0; - u16 var2; -} static const gUnknown_08624BF8[] = + u16 tileNumOffset; + u16 palNumOffset; +} static const sRibbonGfxData[] = { - {0, 0}, - {1, 0}, - {2, 0}, - {3, 0}, - {4, 0}, - {1, 1}, - {2, 1}, - {3, 1}, - {4, 1}, - {1, 2}, - {2, 2}, - {3, 2}, - {4, 2}, - {1, 3}, - {2, 3}, - {3, 3}, - {4, 3}, - {1, 4}, - {2, 4}, - {3, 4}, - {4, 4}, - {5, 0}, - {6, 0}, - {7, 1}, - {8, 2}, - {9, 1}, - {9, 3}, - {9, 4}, - {10, 3}, - {10, 4}, - {11, 0}, - {11, 1}, + [CHAMPION_RIBBON] = { RIBBONGFX_CHAMPION, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [COOL_RIBBON_NORMAL] = { RIBBONGFX_CONTEST_NORMAL, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [COOL_RIBBON_SUPER] = { RIBBONGFX_CONTEST_SUPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [COOL_RIBBON_HYPER] = { RIBBONGFX_CONTEST_HYPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [COOL_RIBBON_MASTER] = { RIBBONGFX_CONTEST_MASTER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [BEAUTY_RIBBON_NORMAL] = { RIBBONGFX_CONTEST_NORMAL, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, + [BEAUTY_RIBBON_SUPER] = { RIBBONGFX_CONTEST_SUPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, + [BEAUTY_RIBBON_HYPER] = { RIBBONGFX_CONTEST_HYPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, + [BEAUTY_RIBBON_MASTER] = { RIBBONGFX_CONTEST_MASTER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, + [CUTE_RIBBON_NORMAL] = { RIBBONGFX_CONTEST_NORMAL, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_3)}, + [CUTE_RIBBON_SUPER] = { RIBBONGFX_CONTEST_SUPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_3)}, + [CUTE_RIBBON_HYPER] = { RIBBONGFX_CONTEST_HYPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_3)}, + [CUTE_RIBBON_MASTER] = { RIBBONGFX_CONTEST_MASTER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_3)}, + [SMART_RIBBON_NORMAL] = { RIBBONGFX_CONTEST_NORMAL, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_4)}, + [SMART_RIBBON_SUPER] = { RIBBONGFX_CONTEST_SUPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_4)}, + [SMART_RIBBON_HYPER] = { RIBBONGFX_CONTEST_HYPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_4)}, + [SMART_RIBBON_MASTER] = { RIBBONGFX_CONTEST_MASTER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_4)}, + [TOUGH_RIBBON_NORMAL] = { RIBBONGFX_CONTEST_NORMAL, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_5)}, + [TOUGH_RIBBON_SUPER] = { RIBBONGFX_CONTEST_SUPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_5)}, + [TOUGH_RIBBON_HYPER] = { RIBBONGFX_CONTEST_HYPER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_5)}, + [TOUGH_RIBBON_MASTER] = { RIBBONGFX_CONTEST_MASTER, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_5)}, + [WINNING_RIBBON] = { RIBBONGFX_WINNING, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [VICTORY_RIBBON] = { RIBBONGFX_VICTORY, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [ARTIST_RIBBON] = { RIBBONGFX_ARTIST, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, + [EFFORT_RIBBON] = { RIBBONGFX_EFFORT, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_3)}, + [MARINE_RIBBON] = { RIBBONGFX_GIFT_1, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, + [LAND_RIBBON] = { RIBBONGFX_GIFT_1, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_4)}, + [SKY_RIBBON] = { RIBBONGFX_GIFT_1, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_5)}, + [COUNTRY_RIBBON] = { RIBBONGFX_GIFT_2, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_4)}, + [NATIONAL_RIBBON] = { RIBBONGFX_GIFT_2, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_5)}, + [EARTH_RIBBON] = { RIBBONGFX_GIFT_3, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_1)}, + [WORLD_RIBBON] = { RIBBONGFX_GIFT_3, TO_PAL_OFFSET(PALTAG_RIBBON_ICONS_2)}, }; -void sub_81D13BC(u16 *dst, u32 id) -{ - u16 r3 = gUnknown_08624BF8[id].var2 + 2; - u16 r1 = (gUnknown_08624BF8[id].var0 * 2) + 1; +#undef TO_PAL_OFFSET - dst[0] = r1 | (r3 << 12); - dst[1] = r1 | (r3 << 12) |0x400; - dst[2] = (r1 + 1) | (r3 << 12); - dst[3] = (r1 + 1) | (r3 << 12) | 0x400; +static void BufferSmallRibbonGfxData(u16 *dst, u32 ribbonId) +{ + u16 palNum = sRibbonGfxData[ribbonId].palNumOffset + 2; + u16 tileNum = (sRibbonGfxData[ribbonId].tileNumOffset * 2) + 1; + + dst[0] = tileNum | (palNum << 12); + dst[1] = tileNum | (palNum << 12) | 0x400; + dst[2] = (tileNum + 1) | (palNum << 12); + dst[3] = (tileNum + 1) | (palNum << 12) | 0x400; } -static const struct CompressedSpriteSheet gUnknown_08624C78 = +static const struct CompressedSpriteSheet sSpriteSheet_RibbonIconsBig = { - sRibbonIconsBig_Gfx, 0x1800, 9 + sRibbonIconsBig_Gfx, 0x1800, GFXTAG_RIBBON_ICONS_BIG }; -static const struct SpritePalette gUnknown_08624C80[] = +static const struct SpritePalette sSpritePalettes_RibbonIcons[] = { - {gUnknown_08623FF8, 15}, - {gUnknown_08624018, 16}, - {gUnknown_08624038, 17}, - {gUnknown_08624058, 18}, - {gUnknown_08624078, 19}, + {sRibbonIcons1_Pal, PALTAG_RIBBON_ICONS_1}, + {sRibbonIcons2_Pal, PALTAG_RIBBON_ICONS_2}, + {sRibbonIcons3_Pal, PALTAG_RIBBON_ICONS_3}, + {sRibbonIcons4_Pal, PALTAG_RIBBON_ICONS_4}, + {sRibbonIcons5_Pal, PALTAG_RIBBON_ICONS_5}, {}, }; -static const struct OamData sOamData_8624CB0 = +static const struct OamData sOamData_RibbonIconBig = { .y = 0, .affineMode = ST_OAM_AFFINE_NORMAL, @@ -1081,93 +1166,105 @@ static const struct OamData sOamData_8624CB0 = .affineParam = 0 }; -static const union AffineAnimCmd sSpriteAffineAnim_8624CB8[] = +static const union AffineAnimCmd sAffineAnim_RibbonIconBig_Normal[] = { AFFINEANIMCMD_FRAME(128, 128, 0, 0), AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_8624CC8[] = +static const union AffineAnimCmd sAffineAnim_RibbonIconBig_ZoomIn[] = { AFFINEANIMCMD_FRAME(128, 128, 0, 0), AFFINEANIMCMD_FRAME(32, 32, 0, 4), AFFINEANIMCMD_END }; -static const union AffineAnimCmd sSpriteAffineAnim_8624CE0[] = +static const union AffineAnimCmd sAffineAnim_RibbonIconBig_ZoomOut[] = { AFFINEANIMCMD_FRAME(256, 256, 0, 0), AFFINEANIMCMD_FRAME(-32, -32, 0, 4), AFFINEANIMCMD_END }; -static const union AffineAnimCmd *const sSpriteAffineAnimTable_8624CF8[] = -{ - sSpriteAffineAnim_8624CB8, - sSpriteAffineAnim_8624CC8, - sSpriteAffineAnim_8624CE0 +enum { + RIBBONANIM_NORMAL, + RIBBONANIM_ZOOM_IN, + RIBBONANIM_ZOOM_OUT, }; -static const struct SpriteTemplate gUnknown_08624D04 = +static const union AffineAnimCmd *const sAffineAnims_RibbonIconBig[] = { - .tileTag = 9, - .paletteTag = 15, - .oam = &sOamData_8624CB0, + [RIBBONANIM_NORMAL] = sAffineAnim_RibbonIconBig_Normal, + [RIBBONANIM_ZOOM_IN] = sAffineAnim_RibbonIconBig_ZoomIn, + [RIBBONANIM_ZOOM_OUT] = sAffineAnim_RibbonIconBig_ZoomOut +}; + +static const struct SpriteTemplate sSpriteTemplate_RibbonIconBig = +{ + .tileTag = GFXTAG_RIBBON_ICONS_BIG, + .paletteTag = PALTAG_RIBBON_ICONS_1, + .oam = &sOamData_RibbonIconBig, .anims = gDummySpriteAnimTable, .images = NULL, - .affineAnims = sSpriteAffineAnimTable_8624CF8, + .affineAnims = sAffineAnims_RibbonIconBig, .callback = SpriteCallbackDummy, }; -void sub_81D13FC(struct PokenavSub14 *structPtr) +// Create dummy sprite to be used for the zoomed in version of the selected ribbon +static void CreateBigRibbonSprite(struct PokenavSub14 *structPtr) { u8 spriteId; - LoadCompressedSpriteSheet(&gUnknown_08624C78); - Pokenav_AllocAndLoadPalettes(gUnknown_08624C80); + LoadCompressedSpriteSheet(&sSpriteSheet_RibbonIconsBig); + Pokenav_AllocAndLoadPalettes(sSpritePalettes_RibbonIcons); - spriteId = CreateSprite(&gUnknown_08624D04, 0, 0, 0); - structPtr->field_14 = &gSprites[spriteId]; - structPtr->field_14->invisible = TRUE; + spriteId = CreateSprite(&sSpriteTemplate_RibbonIconBig, 0, 0, 0); + structPtr->bigRibbonSprite = &gSprites[spriteId]; + structPtr->bigRibbonSprite->invisible = TRUE; } -void sub_81D1448(struct PokenavSub14 *structPtr) +#define sInvisibleWhenDone data[0] + +static void UpdateAndZoomInSelectedRibbon(struct PokenavSub14 *structPtr) { u32 ribbonId; - s32 r4 = sub_81D0944(); - s32 r5 = (r4 % 9) * 16 + 96; - s32 r0 = (r4 / 9) * 16 + 40; + s32 position = GetSelectedPosition(); + s32 x = (position % RIBBONS_PER_ROW) * 16 + 96; + s32 y = (position / RIBBONS_PER_ROW) * 16 + 40; - structPtr->field_14->pos1.x = r5; - structPtr->field_14->pos1.y = r0; + structPtr->bigRibbonSprite->pos1.x = x; + structPtr->bigRibbonSprite->pos1.y = y; - ribbonId = sub_81D0954(); - structPtr->field_14->oam.tileNum = (gUnknown_08624BF8[ribbonId].var0 * 16) + GetSpriteTileStartByTag(9); - structPtr->field_14->oam.paletteNum = IndexOfSpritePaletteTag(gUnknown_08624BF8[ribbonId].var2 + 15); + // Set new selected ribbon's gfx data + ribbonId = GetRibbonId(); + structPtr->bigRibbonSprite->oam.tileNum = (sRibbonGfxData[ribbonId].tileNumOffset * 16) + GetSpriteTileStartByTag(GFXTAG_RIBBON_ICONS_BIG); + structPtr->bigRibbonSprite->oam.paletteNum = IndexOfSpritePaletteTag(sRibbonGfxData[ribbonId].palNumOffset + PALTAG_RIBBON_ICONS_1); - StartSpriteAffineAnim(structPtr->field_14, 1); - structPtr->field_14->invisible = FALSE; - structPtr->field_14->data[0] = 0; - structPtr->field_14->callback = sub_81D1538; + // Start zoom in animation + StartSpriteAffineAnim(structPtr->bigRibbonSprite, RIBBONANIM_ZOOM_IN); + structPtr->bigRibbonSprite->invisible = FALSE; + structPtr->bigRibbonSprite->sInvisibleWhenDone = FALSE; + structPtr->bigRibbonSprite->callback = SpriteCB_WaitForRibbonAnimation; } -void sub_81D1500(struct PokenavSub14 *structPtr) +// Start animation to zoom out of selected ribbon +static void ZoomOutSelectedRibbon(struct PokenavSub14 *structPtr) { - structPtr->field_14->data[0] = 1; - StartSpriteAffineAnim(structPtr->field_14, 2); - structPtr->field_14->callback = sub_81D1538; + structPtr->bigRibbonSprite->sInvisibleWhenDone = TRUE; + StartSpriteAffineAnim(structPtr->bigRibbonSprite, RIBBONANIM_ZOOM_OUT); + structPtr->bigRibbonSprite->callback = SpriteCB_WaitForRibbonAnimation; } -bool32 sub_81D1524(struct PokenavSub14 *structPtr) +static bool32 IsRibbonAnimating(struct PokenavSub14 *structPtr) { - return (structPtr->field_14->callback != SpriteCallbackDummy); + return (structPtr->bigRibbonSprite->callback != SpriteCallbackDummy); } -void sub_81D1538(struct Sprite *sprite) +static void SpriteCB_WaitForRibbonAnimation(struct Sprite *sprite) { if (sprite->affineAnimEnded) { - sprite->invisible = sprite->data[0]; + sprite->invisible = sprite->sInvisibleWhenDone; sprite->callback = SpriteCallbackDummy; } } From da67b6ebd9bba43c047f6b237d11bdce28de441e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 18 Feb 2021 15:01:18 -0500 Subject: [PATCH 6/6] More window cleanup --- gflib/window.c | 54 +++++++++++++++++++++++++------------------------- gflib/window.h | 2 ++ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/gflib/window.c b/gflib/window.c index 6168e4083..b03b513da 100644 --- a/gflib/window.c +++ b/gflib/window.c @@ -23,7 +23,7 @@ static u8 GetNumActiveWindowsOnBg8Bit(u8 bgId); static const struct WindowTemplate sDummyWindowTemplate = DUMMY_WIN_TEMPLATE; -static void nullsub_8(void) +static void DummyWindowBgTilemap(void) { } @@ -42,7 +42,7 @@ bool16 InitWindows(const struct WindowTemplate *templates) { bgTilemapBuffer = GetBgTilemapBuffer(i); if (bgTilemapBuffer != NULL) - gWindowBgTilemapBuffers[i] = nullsub_8; + gWindowBgTilemapBuffers[i] = DummyWindowBgTilemap; else gWindowBgTilemapBuffers[i] = bgTilemapBuffer; } @@ -84,11 +84,11 @@ bool16 InitWindows(const struct WindowTemplate *templates) } } - allocatedTilemapBuffer = AllocZeroed((u16)(WINDOWS_MAX * (templates[i].width * templates[i].height))); + allocatedTilemapBuffer = AllocZeroed((u16)(32 * (templates[i].width * templates[i].height))); if (allocatedTilemapBuffer == NULL) { - if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != nullsub_8)) + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap)) { Free(gWindowBgTilemapBuffers[bgLayer]); gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; @@ -127,7 +127,7 @@ u16 AddWindow(const struct WindowTemplate *template) } if (win == WINDOWS_MAX) - return 0xFF; + return WINDOW_NONE; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -137,7 +137,7 @@ u16 AddWindow(const struct WindowTemplate *template) allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); if (allocatedBaseBlock == -1) - return 0xFF; + return WINDOW_NONE; } if (gWindowBgTilemapBuffers[bgLayer] == NULL) @@ -149,7 +149,7 @@ u16 AddWindow(const struct WindowTemplate *template) allocatedTilemapBuffer = AllocZeroed(attrib); if (allocatedTilemapBuffer == NULL) - return 0xFF; + return WINDOW_NONE; for (i = 0; i < attrib; ++i) allocatedTilemapBuffer[i] = 0; @@ -159,16 +159,16 @@ u16 AddWindow(const struct WindowTemplate *template) } } - allocatedTilemapBuffer = AllocZeroed((u16)(WINDOWS_MAX * (template->width * template->height))); + allocatedTilemapBuffer = AllocZeroed((u16)(32 * (template->width * template->height))); if (allocatedTilemapBuffer == NULL) { - if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != nullsub_8)) + if ((GetNumActiveWindowsOnBg(bgLayer) == 0) && (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap)) { Free(gWindowBgTilemapBuffers[bgLayer]); gWindowBgTilemapBuffers[bgLayer] = allocatedTilemapBuffer; } - return 0xFF; + return WINDOW_NONE; } gWindows[win].tileData = allocatedTilemapBuffer; @@ -196,7 +196,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) } if (win == WINDOWS_MAX) - return 0xFF; + return WINDOW_NONE; bgLayer = template->bg; allocatedBaseBlock = 0; @@ -206,7 +206,7 @@ int AddWindowWithoutTileMap(const struct WindowTemplate *template) allocatedBaseBlock = DummiedOutFireRedLeafGreenTileAllocFunc(bgLayer, 0, template->width * template->height, 0); if (allocatedBaseBlock == -1) - return 0xFF; + return WINDOW_NONE; } gWindows[win].window = *template; @@ -233,10 +233,10 @@ void RemoveWindow(u8 windowId) if (GetNumActiveWindowsOnBg(bgLayer) == 0) { - if (gWindowBgTilemapBuffers[bgLayer] != nullsub_8) + if (gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap) { Free(gWindowBgTilemapBuffers[bgLayer]); - gWindowBgTilemapBuffers[bgLayer] = 0; + gWindowBgTilemapBuffers[bgLayer] = NULL; } } @@ -253,7 +253,7 @@ void FreeAllWindowBuffers(void) for (i = 0; i < NUM_BACKGROUNDS; ++i) { - if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != nullsub_8) + if (gWindowBgTilemapBuffers[i] != NULL && gWindowBgTilemapBuffers[i] != DummyWindowBgTilemap) { Free(gWindowBgTilemapBuffers[i]); gWindowBgTilemapBuffers[i] = NULL; @@ -448,16 +448,16 @@ void FillWindowPixelRect(u8 windowId, u8 fillValue, u16 x, u16 y, u16 width, u16 void CopyToWindowPixelBuffer(u8 windowId, const void *src, u16 size, u16 tileOffset) { if (size != 0) - CpuCopy16(src, gWindows[windowId].tileData + (0x20 * tileOffset), size); + CpuCopy16(src, gWindows[windowId].tileData + (32 * tileOffset), size); else - LZ77UnCompWram(src, gWindows[windowId].tileData + (0x20 * tileOffset)); + LZ77UnCompWram(src, gWindows[windowId].tileData + (32 * tileOffset)); } // Sets all pixels within the window to the fillValue color. void FillWindowPixelBuffer(u8 windowId, u8 fillValue) { int fillSize = gWindows[windowId].window.width * gWindows[windowId].window.height; - CpuFastFill8(fillValue, gWindows[windowId].tileData, 0x20 * fillSize); + CpuFastFill8(fillValue, gWindows[windowId].tileData, 32 * fillSize); } #define MOVE_TILES_DOWN(a) \ @@ -599,7 +599,7 @@ static u8 GetNumActiveWindowsOnBg(u8 bgId) return windowsNum; } -static void nullsub_9(void) +static void DummyWindowBgTilemap8Bit(void) { } @@ -616,9 +616,9 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) break; } if (windowId == WINDOWS_MAX) - return 0xFF; + return WINDOW_NONE; bgLayer = template->bg; - if (gWindowBgTilemapBuffers[bgLayer] == 0) + if (gWindowBgTilemapBuffers[bgLayer] == NULL) { u16 attribute = GetBgAttribute(bgLayer, BG_ATTR_METRIC); if (attribute != 0xFFFF) @@ -626,22 +626,22 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) s32 i; memAddress = Alloc(attribute); if (memAddress == NULL) - return 0xFF; + return WINDOW_NONE; for (i = 0; i < attribute; i++) // if we're going to zero out the memory anyway, why not call AllocZeroed? memAddress[i] = 0; gWindowBgTilemapBuffers[bgLayer] = memAddress; SetBgTilemapBuffer(bgLayer, memAddress); } } - memAddress = Alloc((u16)(0x40 * (template->width * template->height))); + memAddress = Alloc((u16)(64 * (template->width * template->height))); if (memAddress == NULL) { - if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != nullsub_9) + if (GetNumActiveWindowsOnBg8Bit(bgLayer) == 0 && gWindowBgTilemapBuffers[bgLayer] != DummyWindowBgTilemap8Bit) { Free(gWindowBgTilemapBuffers[bgLayer]); gWindowBgTilemapBuffers[bgLayer] = NULL; } - return 0xFF; + return WINDOW_NONE; } else { @@ -656,7 +656,7 @@ void FillWindowPixelBuffer8Bit(u8 windowId, u8 fillValue) s32 i; s32 size; - size = (u16)(0x40 * (gWindows[windowId].window.width * gWindows[windowId].window.height)); + size = (u16)(64 * (gWindows[windowId].window.width * gWindows[windowId].window.height)); for (i = 0; i < size; i++) gWindows[windowId].tileData[i] = fillValue; } @@ -691,7 +691,7 @@ void BlitBitmapRectToWindow4BitTo8Bit(u8 windowId, const u8 *pixels, u16 srcX, u void CopyWindowToVram8Bit(u8 windowId, u8 mode) { sWindowPtr = &gWindows[windowId]; - sWindowSize = 0x40 * (sWindowPtr->window.width * sWindowPtr->window.height); + sWindowSize = 64 * (sWindowPtr->window.width * sWindowPtr->window.height); switch (mode) { diff --git a/gflib/window.h b/gflib/window.h index 6e26155c0..3eac75a28 100644 --- a/gflib/window.h +++ b/gflib/window.h @@ -37,6 +37,8 @@ struct WindowTemplate 0, \ } +#define WINDOW_NONE 0xFF + struct Window { struct WindowTemplate window;