From 55e44b0951395c4d351738f825c6dd67281e6cb3 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 29 Dec 2018 12:10:06 +0100 Subject: [PATCH] a bit more of contest painting effect --- asm/contest_painting_effects.s | 457 ----------------------------- include/constants/rgb.h | 3 +- include/contest_painting_effects.h | 8 +- ld_script.txt | 1 + src/contest_painting_effects.c | 169 +++++++++++ 5 files changed, 176 insertions(+), 462 deletions(-) diff --git a/asm/contest_painting_effects.s b/asm/contest_painting_effects.s index f9f2b96fc..801e840b9 100644 --- a/asm/contest_painting_effects.s +++ b/asm/contest_painting_effects.s @@ -6,465 +6,8 @@ .text - thumb_func_start sub_8125CF4 -sub_8125CF4: @ 8125CF4 - push {r4-r7,lr} - sub sp, 0x14 - adds r7, r1, 0 - ldrh r4, [r0] - ldrh r5, [r7] - lsls r6, r4, 16 - lsls r0, r5, 16 - mov r12, r0 - cmp r4, r5 - beq _08125D66 - mov r2, sp - movs r3, 0x1F - movs r1, 0x1F - adds r0, r1, 0 - ands r0, r4 - strh r0, [r2] - lsrs r0, r6, 21 - ands r0, r3 - strh r0, [r2, 0x2] - lsrs r0, r6, 26 - ands r0, r3 - strh r0, [r2, 0x4] - mov r0, sp - ands r1, r5 - strh r1, [r0, 0x6] - mov r1, sp - mov r2, r12 - lsrs r0, r2, 21 - ands r0, r3 - strh r0, [r1, 0x8] - lsrs r0, r2, 26 - ands r0, r3 - strh r0, [r1, 0xA] - mov r0, sp - ldrh r0, [r0] - cmp r0, 0x19 - bls _08125D4E - mov r0, sp - ldrh r0, [r0, 0x2] - cmp r0, 0x19 - bls _08125D4E - mov r0, sp - ldrh r0, [r0, 0x4] - cmp r0, 0x19 - bhi _08125D66 -_08125D4E: - mov r0, sp - ldrh r0, [r0, 0x6] - cmp r0, 0x19 - bls _08125D6A - mov r0, sp - ldrh r0, [r0, 0x8] - cmp r0, 0x19 - bls _08125D6A - mov r0, sp - ldrh r0, [r0, 0xA] - cmp r0, 0x19 - bls _08125D6A -_08125D66: - ldrh r0, [r7] - b _08125E10 -_08125D6A: - movs r4, 0 - add r6, sp, 0xC - mov r7, sp - adds r7, 0x6 - adds r5, r6, 0 -_08125D74: - lsls r2, r4, 1 - mov r1, sp - adds r0, r1, r2 - adds r1, r7, r2 - ldrh r3, [r0] - ldrh r0, [r1] - cmp r3, r0 - bls _08125D8A - adds r1, r5, r2 - subs r0, r3, r0 - b _08125D8E -_08125D8A: - adds r1, r5, r2 - subs r0, r3 -_08125D8E: - strh r0, [r1] - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x2 - bls _08125D74 - adds r1, r6, 0 - ldrh r0, [r1, 0x2] - ldrh r3, [r1] - cmp r3, r0 - bcc _08125DB4 - ldrh r2, [r1, 0x4] - cmp r3, r2 - bcc _08125DAE - adds r2, r3, 0 - b _08125DC8 -_08125DAE: - cmp r0, r2 - bcs _08125DBA - b _08125DC2 -_08125DB4: - ldrh r2, [r1, 0x4] - cmp r0, r2 - bcc _08125DBE -_08125DBA: - ldrh r2, [r1, 0x2] - b _08125DC8 -_08125DBE: - cmp r2, r3 - bcc _08125DC6 -_08125DC2: - ldrh r2, [r1, 0x4] - b _08125DC8 -_08125DC6: - ldrh r2, [r6] -_08125DC8: - mov r0, sp - ldrh r1, [r0, 0x6] - lsrs r0, r2, 1 - movs r6, 0x1F - subs r6, r0 - adds r0, r1, 0 - muls r0, r6 - movs r1, 0x1F - bl __divsi3 - adds r5, r0, 0 - lsls r5, 16 - lsrs r5, 16 - mov r0, sp - ldrh r0, [r0, 0x8] - muls r0, r6 - movs r1, 0x1F - bl __divsi3 - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, sp - ldrh r0, [r0, 0xA] - muls r0, r6 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r0, 6 - lsls r4, 5 - orrs r0, r4 - orrs r5, r0 - lsls r5, 16 - lsrs r5, 16 - adds r0, r5, 0 -_08125E10: - add sp, 0x14 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8125CF4 - thumb_func_start sub_8125E18 -sub_8125E18: @ 8125E18 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r3, r0, 0 - mov r10, r1 - str r2, [sp] - ldrh r1, [r3] - mov r0, r10 - ldrh r0, [r0] - cmp r1, r0 - bne _08125E40 - ldrh r0, [r2] - cmp r0, r1 - bne _08125E40 - mov r1, r10 - ldrh r0, [r1] - b _08125F28 -_08125E40: - mov r2, r10 - ldrh r0, [r2] - movs r1, 0x1F - mov r9, r1 - movs r4, 0x1F - adds r5, r4, 0 - ands r5, r0 - lsls r0, 16 - lsrs r2, r0, 21 - mov r1, r9 - ands r1, r2 - mov r8, r1 - lsrs r0, 26 - mov r2, r9 - ands r2, r0 - str r2, [sp, 0x4] - ldrh r2, [r3] - adds r0, r4, 0 - ands r0, r2 - lsls r2, 16 - lsrs r1, r2, 21 - mov r3, r9 - ands r1, r3 - adds r0, r1 - lsrs r2, 26 - ands r2, r3 - adds r0, r2 - movs r1, 0x3 - bl __divsi3 - lsls r0, 16 - lsrs r7, r0, 16 - mov r1, r8 - adds r0, r5, r1 - ldr r2, [sp, 0x4] - adds r0, r2 - movs r1, 0x3 - bl __divsi3 - lsls r0, 16 - lsrs r6, r0, 16 - ldr r3, [sp] - ldrh r1, [r3] - ands r4, r1 - lsls r1, 16 - lsrs r0, r1, 21 - mov r2, r9 - ands r0, r2 - adds r4, r0 - lsrs r1, 26 - ands r1, r2 - adds r4, r1 - adds r0, r4, 0 - movs r1, 0x3 - bl __divsi3 - lsls r0, 16 - lsrs r1, r0, 16 - cmp r7, r6 - bne _08125EC2 - cmp r1, r6 - bne _08125EC2 - mov r3, r10 - ldrh r0, [r3] - b _08125F28 -_08125EC2: - cmp r7, r6 - bls _08125ECA - subs r0, r7, r6 - b _08125ECC -_08125ECA: - subs r0, r6, r7 -_08125ECC: - lsls r0, 16 - lsrs r2, r0, 16 - cmp r1, r6 - bls _08125ED8 - subs r0, r1, r6 - b _08125EDA -_08125ED8: - subs r0, r6, r1 -_08125EDA: - lsls r0, 16 - lsrs r0, 16 - cmp r2, r0 - bcc _08125EE4 - adds r0, r2, 0 -_08125EE4: - lsrs r0, 1 - movs r4, 0x1F - subs r4, r0 - lsls r4, 16 - lsrs r4, 16 - adds r0, r5, 0 - muls r0, r4 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r5, r0, 16 - mov r0, r8 - muls r0, r4 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - ldr r1, [sp, 0x4] - adds r0, r1, 0 - muls r0, r4 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r0, 6 - mov r2, r8 - lsls r1, r2, 5 - orrs r0, r1 - orrs r5, r0 - lsls r0, r5, 16 - lsrs r0, 16 -_08125F28: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8125E18 - thumb_func_start sub_8125F38 -sub_8125F38: @ 8125F38 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - adds r3, r0, 0 - mov r10, r1 - str r2, [sp] - ldrh r1, [r3] - mov r0, r10 - ldrh r0, [r0] - cmp r1, r0 - bne _08125F60 - ldrh r0, [r2] - cmp r0, r1 - bne _08125F60 - mov r1, r10 - ldrh r0, [r1] - b _08126046 -_08125F60: - mov r2, r10 - ldrh r0, [r2] - movs r1, 0x1F - mov r9, r1 - movs r4, 0x1F - adds r5, r4, 0 - ands r5, r0 - lsls r0, 16 - lsrs r2, r0, 21 - mov r1, r9 - ands r1, r2 - mov r8, r1 - lsrs r0, 26 - mov r2, r9 - ands r2, r0 - str r2, [sp, 0x4] - ldrh r2, [r3] - adds r0, r4, 0 - ands r0, r2 - lsls r2, 16 - lsrs r1, r2, 21 - mov r3, r9 - ands r1, r3 - adds r0, r1 - lsrs r2, 26 - ands r2, r3 - adds r0, r2 - movs r1, 0x3 - bl __divsi3 - lsls r0, 16 - lsrs r7, r0, 16 - mov r1, r8 - adds r0, r5, r1 - ldr r2, [sp, 0x4] - adds r0, r2 - movs r1, 0x3 - bl __divsi3 - lsls r0, 16 - lsrs r6, r0, 16 - ldr r3, [sp] - ldrh r1, [r3] - ands r4, r1 - lsls r1, 16 - lsrs r0, r1, 21 - mov r2, r9 - ands r0, r2 - adds r4, r0 - lsrs r1, 26 - ands r1, r2 - adds r4, r1 - adds r0, r4, 0 - movs r1, 0x3 - bl __divsi3 - lsls r0, 16 - lsrs r1, r0, 16 - cmp r7, r6 - bne _08125FE2 - cmp r1, r6 - bne _08125FE2 - mov r3, r10 - ldrh r0, [r3] - b _08126046 -_08125FE2: - cmp r7, r6 - bls _08125FEA - subs r0, r7, r6 - b _08125FEC -_08125FEA: - subs r0, r6, r7 -_08125FEC: - lsls r0, 16 - lsrs r2, r0, 16 - cmp r1, r6 - bls _08125FF8 - subs r0, r1, r6 - b _08125FFA -_08125FF8: - subs r0, r6, r1 -_08125FFA: - lsls r0, 16 - lsrs r0, 16 - cmp r2, r0 - bcc _08126004 - adds r0, r2, 0 -_08126004: - movs r4, 0x1F - subs r4, r0 - lsls r4, 16 - lsrs r4, 16 - adds r0, r5, 0 - muls r0, r4 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r5, r0, 16 - mov r0, r8 - muls r0, r4 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - ldr r1, [sp, 0x4] - adds r0, r1, 0 - muls r0, r4 - movs r1, 0x1F - bl __divsi3 - lsls r0, 16 - lsrs r0, 6 - mov r2, r8 - lsls r1, r2, 5 - orrs r0, r1 - orrs r5, r0 - lsls r0, r5, 16 - lsrs r0, 16 -_08126046: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8125F38 thumb_func_start sub_8126058 sub_8126058: @ 8126058 diff --git a/include/constants/rgb.h b/include/constants/rgb.h index fd9c5c5a7..80d951f4b 100644 --- a/include/constants/rgb.h +++ b/include/constants/rgb.h @@ -2,6 +2,7 @@ #define GUARD_RGB_H #define RGB(r, g, b) ((r) | ((g) << 5) | ((b) << 10)) +#define RGB2(r, g, b) (((b) << 10) | ((g) << 5) | (r)) #define _RGB(r, g, b) ((((b) & 0x1F) << 10) + (((g) & 0x1F) << 5) + ((r) & 0x1F)) #define RGB_BLACK RGB(0, 0, 0) @@ -12,6 +13,6 @@ #define RGB_YELLOW RGB(31, 31, 0) #define RGB_MAGENTA RGB(31, 0, 31) #define RGB_CYAN RGB(0, 31, 31) -#define RGB_WHITEALPHA RGB_WHITE | 0x8000 +#define RGB_WHITEALPHA (RGB_WHITE | 0x8000) #endif // GUARD_RGB_H diff --git a/include/contest_painting_effects.h b/include/contest_painting_effects.h index 3b6964666..86c87842c 100755 --- a/include/contest_painting_effects.h +++ b/include/contest_painting_effects.h @@ -1,7 +1,7 @@ #ifndef GUARD_CONTEST_PAINTING_EFFECTS_H #define GUARD_CONTEST_PAINTING_EFFECTS_H -struct Unk030061A0 +struct Unk03005E20 { u8 var_0; u8 pad1[3]; @@ -21,8 +21,8 @@ struct Unk030061A0 u8 var_1F; }; -void sub_8124F2C(struct Unk030061A0 *); -void sub_81261A4(struct Unk030061A0 *); -void sub_8126058(struct Unk030061A0 *); +void sub_8124F2C(struct Unk03005E20 *); +void sub_81261A4(struct Unk03005E20 *); +void sub_8126058(struct Unk03005E20 *); #endif diff --git a/ld_script.txt b/ld_script.txt index 0de40a396..1ed5d75aa 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -185,6 +185,7 @@ SECTIONS { src/dewford_trend.o(.text); src/heal_location.o(.text); src/region_map.o(.text); + src/contest_painting_effects.o(.text); asm/contest_painting_effects.o(.text); src/decoration.o(.text); src/slot_machine.o(.text); diff --git a/src/contest_painting_effects.c b/src/contest_painting_effects.c index 46bc375db..994fee57c 100644 --- a/src/contest_painting_effects.c +++ b/src/contest_painting_effects.c @@ -600,3 +600,172 @@ u16 InvertColor(u16 *color) return RGB2(red, green, blue); } + +u16 sub_8125CF4(u16 *a0, u16 *a1) +{ + u16 sp0[2][3]; + u16 spC[3]; + u8 r4; + u16 r2; + u16 r, g, b; + + if (*a0 == *a1) + return *a1; + + sp0[0][0] = (*a0 >> 0) & 0x1F; + sp0[0][1] = (*a0 >> 5) & 0x1F; + sp0[0][2] = (*a0 >> 10) & 0x1F; + sp0[1][0] = (*a1 >> 0) & 0x1F; + sp0[1][1] = (*a1 >> 5) & 0x1F; + sp0[1][2] = (*a1 >> 10) & 0x1F; + + if (sp0[0][0] > 25 && sp0[0][1] > 25 && sp0[0][2] > 25) + return *a1; + if (sp0[1][0] > 25 && sp0[1][1] > 25 && sp0[1][2] > 25) + return *a1; + + for (r4 = 0; r4 < 3; r4++) + { + if (sp0[0][r4] > sp0[1][r4]) + spC[r4] = sp0[0][r4] - sp0[1][r4]; + else + spC[r4] = sp0[1][r4] - sp0[0][r4]; + } + + if (spC[0] >= spC[1]) + { + if (spC[0] >= spC[2]) + r2 = spC[0]; + else if (spC[1] >= spC[2]) + r2 = spC[1]; + else + r2 = spC[2]; + } + else + { + if (spC[1] >= spC[2]) + r2 = spC[1]; + else if (spC[2] >= spC[0]) + r2 = spC[2]; + else + r2 = spC[0]; + } + + r = (sp0[1][0] * (31 - r2 / 2)) / 31; + g = (sp0[1][1] * (31 - r2 / 2)) / 31; + b = (sp0[1][2] * (31 - r2 / 2)) / 31; + return RGB2(r, g, b); +} + +u16 sub_8125E18(u16 * a0, u16 * a1, u16 * a2) +{ + u16 red, green, blue; + u16 avg0, avg1, avg2; + u16 diff1, diff2; + u32 minimum; + u16 factor; + + if (*a0 == *a1 && *a2 == *a1) + return *a1; + + red = (*a1 >> 0) & 0x1F; + green = (*a1 >> 5) & 0x1F; + blue = (*a1 >> 10) & 0x1F; + + avg0 = (((*a0 >> 0) & 0x1F) + ((*a0 >> 5) & 0x1F) + ((*a0 >> 10) & 0x1F)) / 3; + avg1 = (((*a1 >> 0) & 0x1F) + ((*a1 >> 5) & 0x1F) + ((*a1 >> 10) & 0x1F)) / 3; + avg2 = (((*a2 >> 0) & 0x1F) + ((*a2 >> 5) & 0x1F) + ((*a2 >> 10) & 0x1F)) / 3; + + if (avg0 == avg1 && avg2 == avg1) + return *a1; + + if (avg0 > avg1) + diff1 = avg0 - avg1; + else + diff1 = avg1 - avg0; + + if (avg2 > avg1) + diff2 = avg2 - avg1; + else + diff2 = avg1 - avg2; + + if (diff1 >= diff2) + minimum = diff1; + else + minimum = diff2; + + factor = 31 - minimum / 2; + red = red * factor / 31; + green = green * factor / 31; + blue = blue * factor / 31; + return RGB2(red, green, blue); +} + +u16 sub_8125F38(u16 *a0, u16 *a1, u16 *a2) +{ + u16 red, green, blue; + u16 avg0, avg1, avg2; + u16 diff1, diff2; + u32 minimum; + u16 factor; + + if (*a0 == *a1 && *a2 == *a1) + return *a1; + + red = (*a1 >> 0) & 0x1F; + green = (*a1 >> 5) & 0x1F; + blue = (*a1 >> 10) & 0x1F; + + avg0 = (((*a0 >> 0) & 0x1F) + ((*a0 >> 5) & 0x1F) + ((*a0 >> 10) & 0x1F)) / 3; + avg1 = (((*a1 >> 0) & 0x1F) + ((*a1 >> 5) & 0x1F) + ((*a1 >> 10) & 0x1F)) / 3; + avg2 = (((*a2 >> 0) & 0x1F) + ((*a2 >> 5) & 0x1F) + ((*a2 >> 10) & 0x1F)) / 3; + + if (avg0 == avg1 && avg2 == avg1) + return *a1; + + if (avg0 > avg1) + diff1 = avg0 - avg1; + else + diff1 = avg1 - avg0; + + if (avg2 > avg1) + diff2 = avg2 - avg1; + else + diff2 = avg1 - avg2; + + if (diff1 >= diff2) + minimum = diff1; + else + minimum = diff2; + + factor = 31 - minimum; + red = red * factor / 31; + green = green * factor / 31; + blue = blue * factor / 31; + return RGB2(red, green, blue); +} + +/* +void sub_8126058(struct Unk03005E20 *arg0) +{ + u16 i, j, k; + u8 r5 = arg0->var_1D >> 3; + u8 var_24 = arg0->var_1E >> 3; + u16 (*var_2C)[][32] = arg0->var_4; + u32 var_28 = arg0->var_10; + + if (arg0->var_16 == 2) + { + for (i = 0; i < var_24; i++) + { + for (j = 0; j < r5; j++) + { + for (k = 0; k < 8; k++) + { + (*var_2C)[][]; + } + } + } + } +} +*/