From d40870e5f899f0dfc3b706f64aeceb3ea159b5f7 Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Tue, 25 Aug 2020 14:23:12 -0400 Subject: [PATCH 1/4] Match InitContestMonPixels --- src/contest_painting.c | 119 +++-------------------------------------- 1 file changed, 6 insertions(+), 113 deletions(-) diff --git a/src/contest_painting.c b/src/contest_painting.c index 5dd4a70a5..0ea5e8000 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -384,11 +384,9 @@ static void InitContestMonPixels(u16 species, u8 whichSprite) } } -#ifdef NONMATCHING -// functionally equivalent. static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels)[64][64]) { - u16 tileY, tileX, pixelY, pixelX; + u16 tileY, tileX, pixelY, pixelX, temp; u8 colorIndex; for (tileY = 0; tileY < 8; tileY++) @@ -399,125 +397,20 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) { for (pixelX = 0; pixelX < 8; pixelX++) { - int offset = 32 * (8 * tileY + tileX) + (pixelY * 4 + pixelX / 2); - colorIndex = spriteGfx[offset]; + colorIndex = spriteGfx[(((tileY * 8) + tileX) * 32) + (pixelY << 2) + (pixelX >> 1)]; if (pixelX & 1) colorIndex >>= 4; else - colorIndex &= 0xF; - - if (colorIndex == 0) // transparent pixel - (*destPixels)[8 * tileY + pixelY][tileX * 8 + pixelX] = 0x8000; + colorIndex &= 0xF; // %=16 works here too. Both match + if (colorIndex == 0) // transparent pixel + (*destPixels)[((tileY * 8) + pixelY)][((tileX * 8) + pixelX)] = 0x8000; else - (*destPixels)[8 * tileY + pixelY][tileX * 8 + pixelX] = palette[colorIndex]; + (*destPixels)[((tileY * 8) + pixelY)][((tileX * 8) + pixelX)] = palette[colorIndex]; } } } } } -#else -NAKED -static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels)[64][64]) -{ - asm_unified("\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - sub sp, 0xC\n\ - mov r10, r0\n\ - mov r9, r1\n\ - str r2, [sp]\n\ - movs r0, 0\n\ -_08130394:\n\ - movs r3, 0\n\ - adds r1, r0, 0x1\n\ - str r1, [sp, 0x4]\n\ - lsls r0, 3\n\ - str r0, [sp, 0x8]\n\ -_0813039E:\n\ - movs r1, 0\n\ - adds r2, r3, 0x1\n\ - mov r8, r2\n\ - ldr r7, [sp, 0x8]\n\ - adds r0, r7, r3\n\ - lsls r0, 5\n\ - mov r12, r0\n\ - lsls r4, r3, 3\n\ -_081303AE:\n\ - movs r3, 0\n\ - lsls r0, r1, 2\n\ - adds r6, r1, 0x1\n\ - mov r2, r12\n\ - adds r5, r2, r0\n\ - ldr r7, [sp, 0x8]\n\ - adds r0, r7, r1\n\ - lsls r0, 7\n\ - ldr r1, [sp]\n\ - adds r2, r0, r1\n\ -_081303C2:\n\ - lsrs r0, r3, 1\n\ - adds r0, r5, r0\n\ - add r0, r10\n\ - ldrb r1, [r0]\n\ - movs r0, 0x1\n\ - ands r0, r3\n\ - cmp r0, 0\n\ - beq _081303D6\n\ - lsrs r1, 4\n\ - b _081303DA\n\ -_081303D6:\n\ - movs r0, 0xF\n\ - ands r1, r0\n\ -_081303DA:\n\ - cmp r1, 0\n\ - bne _081303EC\n\ - adds r0, r4, r3\n\ - lsls r0, 1\n\ - adds r0, r2\n\ - movs r7, 0x80\n\ - lsls r7, 8\n\ - adds r1, r7, 0\n\ - b _081303F8\n\ -_081303EC:\n\ - adds r0, r4, r3\n\ - lsls r0, 1\n\ - adds r0, r2\n\ - lsls r1, 1\n\ - add r1, r9\n\ - ldrh r1, [r1]\n\ -_081303F8:\n\ - strh r1, [r0]\n\ - adds r0, r3, 0x1\n\ - lsls r0, 16\n\ - lsrs r3, r0, 16\n\ - cmp r3, 0x7\n\ - bls _081303C2\n\ - lsls r0, r6, 16\n\ - lsrs r1, r0, 16\n\ - cmp r1, 0x7\n\ - bls _081303AE\n\ - mov r1, r8\n\ - lsls r0, r1, 16\n\ - lsrs r3, r0, 16\n\ - cmp r3, 0x7\n\ - bls _0813039E\n\ - ldr r2, [sp, 0x4]\n\ - lsls r0, r2, 16\n\ - lsrs r0, 16\n\ - cmp r0, 0x7\n\ - bls _08130394\n\ - add sp, 0xC\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0"); -} -#endif #define VRAM_PICTURE_DATA(x, y) (((u16 *)(BG_SCREEN_ADDR(12)))[(y) * 32 + (x)]) From bf1e261177a4a7177173c631c2da68d3d218f7cd Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Tue, 25 Aug 2020 16:03:04 -0400 Subject: [PATCH 2/4] Fix mistakes --- src/contest_painting.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/contest_painting.c b/src/contest_painting.c index 0ea5e8000..789d30006 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -386,7 +386,7 @@ static void InitContestMonPixels(u16 species, u8 whichSprite) static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels)[64][64]) { - u16 tileY, tileX, pixelY, pixelX, temp; + u16 tileY, tileX, pixelY, pixelX; u8 colorIndex; for (tileY = 0; tileY < 8; tileY++) @@ -402,6 +402,7 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) colorIndex >>= 4; else colorIndex &= 0xF; // %=16 works here too. Both match + if (colorIndex == 0) // transparent pixel (*destPixels)[((tileY * 8) + pixelY)][((tileX * 8) + pixelX)] = 0x8000; else From ba853d6b39be12b8ce6954401d124c6f580a984d Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Tue, 25 Aug 2020 16:08:37 -0400 Subject: [PATCH 3/4] Removed unneeded parenthesis --- src/contest_painting.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/contest_painting.c b/src/contest_painting.c index 789d30006..5ec774d82 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -397,16 +397,16 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) { for (pixelX = 0; pixelX < 8; pixelX++) { - colorIndex = spriteGfx[(((tileY * 8) + tileX) * 32) + (pixelY << 2) + (pixelX >> 1)]; + colorIndex = spriteGfx[((tileY * 8) + tileX) * 32 + (pixelY << 2) + (pixelX >> 1)]; if (pixelX & 1) colorIndex >>= 4; else colorIndex &= 0xF; // %=16 works here too. Both match if (colorIndex == 0) // transparent pixel - (*destPixels)[((tileY * 8) + pixelY)][((tileX * 8) + pixelX)] = 0x8000; + (*destPixels)[(tileY * 8 + pixelY)][(tileX * 8 + pixelX)] = 0x8000; else - (*destPixels)[((tileY * 8) + pixelY)][((tileX * 8) + pixelX)] = palette[colorIndex]; + (*destPixels)[(tileY * 8 + pixelY)][(tileX * 8 + pixelX)] = palette[colorIndex]; } } } From a2efccd6d59050b46ab52e323a51e2327f52500f Mon Sep 17 00:00:00 2001 From: PokeCodec Date: Tue, 25 Aug 2020 16:11:23 -0400 Subject: [PATCH 4/4] remove outside parenthesis --- src/contest_painting.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/contest_painting.c b/src/contest_painting.c index 5ec774d82..a0c39dfc7 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -404,9 +404,9 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) colorIndex &= 0xF; // %=16 works here too. Both match if (colorIndex == 0) // transparent pixel - (*destPixels)[(tileY * 8 + pixelY)][(tileX * 8 + pixelX)] = 0x8000; + (*destPixels)[tileY * 8 + pixelY][tileX * 8 + pixelX] = 0x8000; else - (*destPixels)[(tileY * 8 + pixelY)][(tileX * 8 + pixelX)] = palette[colorIndex]; + (*destPixels)[tileY * 8 + pixelY][tileX * 8 + pixelX] = palette[colorIndex]; } } }