From 3128bace4ccd486e12668d0e2c75d7ef63f69801 Mon Sep 17 00:00:00 2001 From: citrusbolt Date: Sat, 24 Feb 2024 20:12:15 -0700 Subject: [PATCH] Sync Spinda dot drawing formatting from `pokeemerald` --- payload/src/pokemon.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/payload/src/pokemon.c b/payload/src/pokemon.c index 9b5a3eb..7dc0b14 100644 --- a/payload/src/pokemon.c +++ b/payload/src/pokemon.c @@ -728,11 +728,21 @@ u32 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection) return retVal; } +#define SPINDA_SPOT_HEIGHT 16 +#define SPINDA_SPOT_WIDTH 16 + +// Spots can be drawn on Spinda's color indexes 1, 2, or 3 +#define FIRST_SPOT_COLOR 1 +#define LAST_SPOT_COLOR 3 + +// To draw a spot pixel, add 4 to the color index +#define SPOT_COLOR_ADJUSTMENT 4 + void DrawSpindasSpots(u16 species, u32 personality, u8 *dest) { if (species == SPECIES_SPINDA) { - s32 i, j, k; + s32 i, row, column; u32 var; if (gRomDetection_IsRubySapphire != FALSE) @@ -745,29 +755,32 @@ void DrawSpindasSpots(u16 species, u32 personality, u8 *dest) u8 x = gSpindaSpotGraphics[i].x + ((personality & 0x0F) - 8); u8 y = gSpindaSpotGraphics[i].y + (((personality & 0xF0) >> 4) - 8) - var; - for (j = 0; j < 16; j++) + for (row = 0; row < SPINDA_SPOT_HEIGHT; row++) { - s32 row = gSpindaSpotGraphics[i].image[j]; + s32 spotPixelRow = gSpindaSpotGraphics[i].image[row]; - for (k = x; k < x + 16; k++) + for (column = x; column < x + SPINDA_SPOT_WIDTH; column++) { - u8 *val = dest + ((k / 8) * 32) + ((k % 8) / 2) + ((y >> 3) << 8) + ((y & 7) << 2); + u8 *destPixels = dest + ((column / 8) * TILE_SIZE_4BPP) + + ((column % 8) / 2) + + ((y / 8) * TILE_SIZE_4BPP * 8) + + ((y % 8) * 4); - if (row & 1) + if (spotPixelRow & 1) { - if (k & 1) + if (column & 1) { - if ((u8)((*val & 0xF0) - 0x10) <= 0x20) - *val += 0x40; + if ((u8)((*destPixels & 0xF0) - (FIRST_SPOT_COLOR << 4)) <= ((LAST_SPOT_COLOR - FIRST_SPOT_COLOR) << 4)) + *destPixels += (SPOT_COLOR_ADJUSTMENT << 4); } else { - if ((u8)((*val & 0xF) - 0x01) <= 0x02) - *val += 0x04; + if ((u8)((*destPixels & 0xF) - FIRST_SPOT_COLOR) <= (LAST_SPOT_COLOR - FIRST_SPOT_COLOR)) + *destPixels += SPOT_COLOR_ADJUSTMENT; } } - row >>= 1; + spotPixelRow >>= 1; } y++; @@ -1209,7 +1222,7 @@ u16 FixUnownSpecies(u16 species, u32 personality) else { if (species > SPECIES_EGG) - result = 260; + result = SPECIES_OLD_UNOWN_J; // ??? else result = species; }