From f4510fe8e723bc892049095724c60c419551f7cc Mon Sep 17 00:00:00 2001 From: Eebit Date: Wed, 21 Feb 2024 17:37:38 -0500 Subject: [PATCH 1/2] (colorfade) Decompile --- asm/code_80B24DC.s | 463 --------------------------------------------- ldscript.txt | 2 +- src/colorfade.c | 214 +++++++++++++++++++++ 3 files changed, 215 insertions(+), 464 deletions(-) delete mode 100644 asm/code_80B24DC.s create mode 100644 src/colorfade.c diff --git a/asm/code_80B24DC.s b/asm/code_80B24DC.s deleted file mode 100644 index d78be03ee..000000000 --- a/asm/code_80B24DC.s +++ /dev/null @@ -1,463 +0,0 @@ - .INCLUDE "macro.inc" - - .SYNTAX UNIFIED - - THUMB_FUNC_START sub_80B24DC -sub_80B24DC: @ 0x080B24DC - push {r4, r5, lr} - adds r5, r0, #0 - ldr r3, [r5, #0x5c] - ldr r0, [r5, #0x60] - adds r0, r3, r0 - cmp r3, r0 - bge _080B2508 - ldr r2, _080B2510 @ gUnknown_02014EF4 - ldr r1, _080B2514 @ gPaletteBuffer - lsls r0, r3, #1 - adds r4, r0, r1 - adds r2, r0, r2 -_080B24F4: - ldrh r0, [r4] - strh r0, [r2] - adds r4, #2 - adds r2, #2 - adds r3, #1 - ldr r0, [r5, #0x5c] - ldr r1, [r5, #0x60] - adds r0, r0, r1 - cmp r3, r0 - blt _080B24F4 -_080B2508: - pop {r4, r5} - pop {r0} - bx r0 - .align 2, 0 -_080B2510: .4byte gUnknown_02014EF4 -_080B2514: .4byte gPaletteBuffer - - THUMB_FUNC_END sub_80B24DC - - THUMB_FUNC_START nullsub_67 -nullsub_67: @ 0x080B2518 - bx lr - - THUMB_FUNC_END nullsub_67 - - THUMB_FUNC_START sub_80B251C -sub_80B251C: @ 0x080B251C - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, r9 - mov r5, r8 - push {r5, r6, r7} - mov r8, r0 - adds r0, #0x4e - ldrh r0, [r0] - movs r2, #0x80 - lsls r2, r2, #1 - adds r1, r2, #0 - subs r1, r1, r0 - lsls r1, r1, #0x10 - lsrs r1, r1, #0x10 - mov r9, r1 - mov r0, r8 - ldr r7, [r0, #0x5c] - ldr r0, [r0, #0x60] - adds r0, r7, r0 - cmp r7, r0 - bge _080B25D0 - movs r1, #0xf8 - lsls r1, r1, #7 - mov sl, r1 -_080B254C: - lsls r2, r7, #1 - mov ip, r2 - ldr r0, _080B2600 @ gUnknown_02014EF4 - add r0, ip - ldrh r6, [r0] - mov r1, sl - ands r1, r6 - mov r0, r8 - ldr r4, [r0, #0x58] - adds r0, r4, #0 - mov r2, sl - ands r0, r2 - subs r0, r1, r0 - mov r1, r9 - muls r1, r0, r1 - adds r0, r1, #0 - cmp r0, #0 - bge _080B2572 - adds r0, #0xff -_080B2572: - asrs r0, r0, #8 - adds r2, r0, r4 - mov r0, sl - ands r2, r0 - movs r5, #0xf8 - lsls r5, r5, #2 - adds r1, r5, #0 - ands r1, r6 - adds r0, r4, #0 - ands r0, r5 - subs r0, r1, r0 - mov r1, r9 - muls r1, r0, r1 - adds r0, r1, #0 - cmp r0, #0 - bge _080B2594 - adds r0, #0xff -_080B2594: - asrs r0, r0, #8 - adds r3, r0, r4 - ands r3, r5 - movs r5, #0x1f - adds r1, r5, #0 - ands r1, r6 - adds r0, r4, #0 - ands r0, r5 - subs r0, r1, r0 - mov r1, r9 - muls r1, r0, r1 - adds r0, r1, #0 - cmp r0, #0 - bge _080B25B2 - adds r0, #0xff -_080B25B2: - asrs r0, r0, #8 - adds r0, r0, r4 - ands r0, r5 - ldr r1, _080B2604 @ gPaletteBuffer - add r1, ip - orrs r2, r3 - orrs r2, r0 - strh r2, [r1] - adds r7, #1 - mov r2, r8 - ldr r0, [r2, #0x5c] - ldr r1, [r2, #0x60] - adds r0, r0, r1 - cmp r7, r0 - blt _080B254C -_080B25D0: - bl EnablePaletteSync - mov r1, r8 - adds r1, #0x4e - mov r0, r8 - adds r0, #0x64 - ldrh r0, [r0] - ldrh r2, [r1] - adds r0, r0, r2 - strh r0, [r1] - mov r0, r9 - cmp r0, #0 - bne _080B25F0 - mov r0, r8 - bl Proc_Break -_080B25F0: - pop {r3, r4, r5} - mov r8, r3 - mov r9, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_080B2600: .4byte gUnknown_02014EF4 -_080B2604: .4byte gPaletteBuffer - - THUMB_FUNC_END sub_80B251C - - THUMB_FUNC_START sub_80B2608 -sub_80B2608: @ 0x080B2608 - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, r9 - mov r5, r8 - push {r5, r6, r7} - mov r8, r0 - adds r0, #0x4e - ldrh r1, [r0] - movs r2, #0x80 - lsls r2, r2, #1 - adds r0, r2, #0 - subs r0, r0, r1 - lsls r0, r0, #0x10 - lsrs r0, r0, #0x10 - mov r9, r0 - cmp r0, #0 - beq _080B26C0 - mov r4, r8 - ldr r6, [r4, #0x5c] - ldr r0, [r4, #0x60] - adds r0, r6, r0 - cmp r6, r0 - bge _080B26C0 - movs r5, #0xf8 - lsls r5, r5, #7 - mov sl, r5 -_080B263C: - mov r0, r8 - ldr r5, [r0, #0x58] - adds r2, r5, #0 - mov r1, sl - ands r2, r1 - lsls r4, r6, #1 - mov ip, r4 - ldr r3, _080B2724 @ gUnknown_02014EF4 - add r3, ip - ldrh r1, [r3] - mov r0, sl - ands r0, r1 - subs r0, r2, r0 - mov r1, r9 - muls r1, r0, r1 - adds r0, r1, #0 - cmp r0, #0 - bge _080B2662 - adds r0, #0xff -_080B2662: - asrs r0, r0, #8 - ldrh r4, [r3] - adds r2, r0, r4 - mov r0, sl - ands r2, r0 - movs r7, #0xf8 - lsls r7, r7, #2 - adds r1, r5, #0 - ands r1, r7 - adds r0, r4, #0 - ands r0, r7 - subs r0, r1, r0 - mov r1, r9 - muls r1, r0, r1 - adds r0, r1, #0 - cmp r0, #0 - bge _080B2686 - adds r0, #0xff -_080B2686: - asrs r0, r0, #8 - adds r3, r0, r4 - ands r3, r7 - movs r1, #0x1f - ands r5, r1 - adds r0, r4, #0 - ands r0, r1 - subs r0, r5, r0 - mov r5, r9 - muls r5, r0, r5 - adds r0, r5, #0 - cmp r0, #0 - bge _080B26A2 - adds r0, #0xff -_080B26A2: - asrs r0, r0, #8 - adds r0, r0, r4 - ands r0, r1 - ldr r1, _080B2728 @ gPaletteBuffer - add r1, ip - orrs r2, r3 - orrs r2, r0 - strh r2, [r1] - adds r6, #1 - mov r1, r8 - ldr r0, [r1, #0x5c] - ldr r1, [r1, #0x60] - adds r0, r0, r1 - cmp r6, r0 - blt _080B263C -_080B26C0: - bl EnablePaletteSync - mov r1, r8 - adds r1, #0x4e - mov r0, r8 - adds r0, #0x64 - ldrh r0, [r0] - ldrh r2, [r1] - adds r0, r0, r2 - strh r0, [r1] - mov r4, r9 - cmp r4, #0 - bne _080B2714 - mov r5, r8 - ldr r6, [r5, #0x5c] - ldr r0, [r5, #0x60] - adds r0, r6, r0 - cmp r6, r0 - bge _080B270E - ldr r0, _080B2728 @ gPaletteBuffer - ldr r2, _080B2724 @ gUnknown_02014EF4 - lsls r1, r6, #1 - adds r3, r1, r0 - adds r2, r1, r2 -_080B26F0: - ldrh r0, [r2] - strh r0, [r3] - ldrh r0, [r2] - strh r0, [r3] - ldrh r0, [r2] - strh r0, [r3] - adds r3, #2 - adds r2, #2 - adds r6, #1 - mov r1, r8 - ldr r0, [r1, #0x5c] - ldr r1, [r1, #0x60] - adds r0, r0, r1 - cmp r6, r0 - blt _080B26F0 -_080B270E: - mov r0, r8 - bl Proc_Break -_080B2714: - pop {r3, r4, r5} - mov r8, r3 - mov r9, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r0} - bx r0 - .align 2, 0 -_080B2724: .4byte gUnknown_02014EF4 -_080B2728: .4byte gPaletteBuffer - - THUMB_FUNC_END sub_80B2608 - - THUMB_FUNC_START NewColFadeOut -NewColFadeOut: @ 0x080B272C - push {r4, r5, r6, lr} - adds r5, r0, #0 - adds r6, r1, #0 - adds r4, r2, #0 - adds r1, r3, #0 - ldr r0, _080B2758 @ ProcScr_ColFadeOut - bl Proc_StartBlocking - adds r1, r0, #0 - adds r0, #0x64 - movs r2, #0 - strh r5, [r0] - str r4, [r1, #0x58] - subs r0, #0x16 - strh r2, [r0] - cmp r6, #1 - beq _080B2768 - cmp r6, #1 - bgt _080B275C - cmp r6, #0 - beq _080B2762 - b _080B2778 - .align 2, 0 -_080B2758: .4byte ProcScr_ColFadeOut -_080B275C: - cmp r6, #2 - beq _080B2770 - b _080B2778 -_080B2762: - movs r0, #0x80 - str r0, [r1, #0x5c] - b _080B2776 -_080B2768: - str r2, [r1, #0x5c] - movs r0, #0x80 - lsls r0, r0, #2 - b _080B2776 -_080B2770: - str r2, [r1, #0x5c] - movs r0, #0x80 - lsls r0, r0, #3 -_080B2776: - str r0, [r1, #0x60] -_080B2778: - pop {r4, r5, r6} - pop {r0} - bx r0 - - THUMB_FUNC_END NewColFadeOut - - THUMB_FUNC_START NewColFadeIn -NewColFadeIn: @ 0x080B2780 - push {r4, r5, r6, lr} - adds r5, r0, #0 - adds r6, r1, #0 - adds r4, r2, #0 - adds r1, r3, #0 - ldr r0, _080B27B0 @ ProcScr_ColFadeIn - bl Proc_StartBlocking - mov ip, r0 - adds r0, #0x64 - movs r1, #0 - strh r5, [r0] - mov r0, ip - str r4, [r0, #0x58] - adds r0, #0x4e - strh r1, [r0] - cmp r6, #1 - beq _080B27C2 - cmp r6, #1 - bgt _080B27B4 - cmp r6, #0 - beq _080B27BA - b _080B27DA - .align 2, 0 -_080B27B0: .4byte ProcScr_ColFadeIn -_080B27B4: - cmp r6, #2 - beq _080B27CE - b _080B27DA -_080B27BA: - movs r0, #0x80 - mov r1, ip - str r0, [r1, #0x5c] - b _080B27D8 -_080B27C2: - mov r6, ip - str r1, [r6, #0x5c] - movs r0, #0x80 - lsls r0, r0, #2 - str r0, [r6, #0x60] - b _080B27DA -_080B27CE: - mov r0, ip - str r1, [r0, #0x5c] - movs r0, #0x80 - lsls r0, r0, #3 - mov r1, ip -_080B27D8: - str r0, [r1, #0x60] -_080B27DA: - mov r6, ip - ldr r4, [r6, #0x5c] - ldr r0, [r6, #0x60] - adds r0, r4, r0 - cmp r4, r0 - bge _080B280A - ldr r2, _080B2810 @ gUnknown_02014EF4 - ldr r1, _080B2814 @ gPaletteBuffer - movs r5, #0 - lsls r0, r4, #1 - adds r3, r0, r1 - adds r2, r0, r2 -_080B27F2: - ldrh r0, [r3] - strh r0, [r2] - strh r5, [r3] - adds r3, #2 - adds r2, #2 - adds r4, #1 - mov r1, ip - ldr r0, [r1, #0x5c] - ldr r1, [r1, #0x60] - adds r0, r0, r1 - cmp r4, r0 - blt _080B27F2 -_080B280A: - pop {r4, r5, r6} - pop {r0} - bx r0 - .align 2, 0 -_080B2810: .4byte gUnknown_02014EF4 -_080B2814: .4byte gPaletteBuffer - - THUMB_FUNC_END NewColFadeIn - -.align 2, 0 diff --git a/ldscript.txt b/ldscript.txt index cd06152b1..0703b37ac 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -306,7 +306,7 @@ SECTIONS src/extramenu_unk.o(.text); src/bonusclaim.o(.text); src/uiconfig.o(.text); - asm/code_80B24DC.o(.text); + src/colorfade.o(.text); src/opinfo.o(.text); src/classdisplayfont.o(.text); src/bmshop.o(.text); diff --git a/src/colorfade.c b/src/colorfade.c new file mode 100644 index 000000000..c1bf28282 --- /dev/null +++ b/src/colorfade.c @@ -0,0 +1,214 @@ +#include "global.h" + +#include "hardware.h" + +extern u16 gUnknown_02014EF4[]; + +struct ColFadeProc +{ + /* 00 */ PROC_HEADER; + /* 29 */ STRUCT_PAD(0x29, 0x4E); + + /* 4E */ u16 unk_4e; + + /* 50 */ STRUCT_PAD(0x50, 0x58); + + /* 58 */ int unk_58; + /* 5C */ int unk_5c; + /* 60 */ int unk_60; + /* 64 */ u16 unk_64; +}; + +//! FE8U = 0x080B24DC +void sub_80B24DC(struct ColFadeProc * proc) +{ + int i; + + for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + { + gUnknown_02014EF4[i] = gPaletteBuffer[i]; + } + + return; +} + +//! FE8U = 0x080B2518 +void nullsub_67(void) +{ + return; +} + +//! FE8U = 0x080B251C +void sub_80B251C(struct ColFadeProc * proc) +{ + int i; + + u16 val = 0x100 - proc->unk_4e; + + for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + { + int r, r1, r2; + int g, g1, g2; + int b, b1, b2; + + b1 = (gUnknown_02014EF4[i] & 0x7c00); + b2 = (proc->unk_58 & 0x7c00); + b2 = b1 - b2; + b = ((b2 * val / 0x100) + proc->unk_58) & 0x7c00; + + g1 = (gUnknown_02014EF4[i] & 0x3e0); + g2 = (proc->unk_58 & 0x3e0); + g2 = (g1 - g2); + g = ((g2 * val / 0x100) + proc->unk_58) & 0x3e0; + + r1 = (gUnknown_02014EF4[i] & 0x1f); + r2 = (proc->unk_58 & 0x1f); + r2 = r1 - r2; + r = ((r2 * val / 0x100) + proc->unk_58) & 0x1f; + + gPaletteBuffer[i] = b | g | r; + } + + EnablePaletteSync(); + + proc->unk_4e += proc->unk_64; + + if (val == 0) + { + Proc_Break(proc); + } + + return; +} + +//! FE8U = 0x080B2608 +void sub_80B2608(struct ColFadeProc * proc) +{ + int i; + + u16 val = 0x100 - proc->unk_4e; + + if (val != 0) + { + for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + { + int r, r1, r2; + int g, g1, g2; + int b, b1, b2; + + b1 = (proc->unk_58 & 0x7c00); + b2 = (gUnknown_02014EF4[i] & 0x7c00); + b2 = b1 - b2; + b = ((b2 * val / 0x100) + gUnknown_02014EF4[i]) & 0x7c00; + + g1 = (proc->unk_58 & 0x3e0); + g2 = (gUnknown_02014EF4[i] & 0x3e0); + g2 = (g1 - g2); + g = ((g2 * val / 0x100) + gUnknown_02014EF4[i]) & 0x3e0; + + r1 = (proc->unk_58 & 0x1f); + r2 = (gUnknown_02014EF4[i] & 0x1f); + r2 = r1 - r2; + r = ((r2 * val / 0x100) + gUnknown_02014EF4[i]) & 0x1f; + + gPaletteBuffer[i] = b | g | r; + } + } + + EnablePaletteSync(); + + proc->unk_4e += proc->unk_64; + + if (val == 0) + { + for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + { + gPaletteBuffer[i] = gUnknown_02014EF4[i]; + gPaletteBuffer[i] = gUnknown_02014EF4[i]; + gPaletteBuffer[i] = gUnknown_02014EF4[i]; + } + + Proc_Break(proc); + } + + return; +} + +extern struct ProcCmd ProcScr_ColFadeOut[]; + +//! FE8U = 0x080B272C +void NewColFadeOut(int speed, int kind, int color, ProcPtr parent) +{ + struct ColFadeProc * proc = Proc_StartBlocking(ProcScr_ColFadeOut, parent); + + proc->unk_64 = speed; + proc->unk_58 = color; + proc->unk_4e = 0; + + switch (kind) + { + case 0: + proc->unk_5c = 0x80; + proc->unk_60 = 0x80; + + break; + + case 1: + proc->unk_5c = 0; + proc->unk_60 = 0x200; + + break; + + case 2: + proc->unk_5c = 0; + proc->unk_60 = 0x400; + + break; + } + + return; +} + +extern struct ProcCmd ProcScr_ColFadeIn[]; + +//! FE8U = 0x080B2780 +void NewColFadeIn(int speed, int kind, int color, ProcPtr parent) +{ + int i; + + struct ColFadeProc * proc = Proc_StartBlocking(ProcScr_ColFadeIn, parent); + + proc->unk_64 = speed; + proc->unk_58 = color; + + proc->unk_4e = 0; + + switch (kind) + { + case 0: + proc->unk_5c = 0x80; + proc->unk_60 = 0x80; + + break; + + case 1: + proc->unk_5c = 0; + proc->unk_60 = 0x200; + + break; + + case 2: + proc->unk_5c = 0; + proc->unk_60 = 0x400; + + break; + } + + for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + { + gUnknown_02014EF4[i] = gPaletteBuffer[i]; + gPaletteBuffer[i] = 0; + } + + return; +} \ No newline at end of file From 17e982293b66d46b512d109d0f96ac1e400fdfd8 Mon Sep 17 00:00:00 2001 From: Eebit Date: Wed, 21 Feb 2024 17:55:34 -0500 Subject: [PATCH 2/2] (colorfade) Extract data and renames --- data/const_data_205E74.s | 9 --- data/data_A2EE90.s | 44 ------------ include/colorfade.h | 31 ++++++++ include/functions.h | 7 +- include/variables.h | 3 +- ldscript.txt | 4 +- src/colorfade.c | 150 ++++++++++++++++++++++----------------- src/eventscr.c | 1 + 8 files changed, 119 insertions(+), 130 deletions(-) delete mode 100644 data/const_data_205E74.s delete mode 100644 data/data_A2EE90.s create mode 100644 include/colorfade.h diff --git a/data/const_data_205E74.s b/data/const_data_205E74.s deleted file mode 100644 index bebb81563..000000000 --- a/data/const_data_205E74.s +++ /dev/null @@ -1,9 +0,0 @@ - .section .rodata - - @ 0x08205E74 - .asciz "ColFadeOut" - .align 2 - - @ 0x08205E80 - .asciz "ColFadeIn" - .align 2 diff --git a/data/data_A2EE90.s b/data/data_A2EE90.s deleted file mode 100644 index cc75e1398..000000000 --- a/data/data_A2EE90.s +++ /dev/null @@ -1,44 +0,0 @@ - .section .data - - .global ProcScr_ColFadeOut -ProcScr_ColFadeOut: @ 0x08A2EE90 - @ PROC_NAME - .short 0x1, 0x0 - .word 0x8205e74 - @ PROC_SLEEP - .short 0xe, 0x2 - .word 0x0 - @ PROC_CALL - .short 0x2, 0x0 - .word sub_80B24DC - @ PROC_YIELD - .short 0xe, 0x0 - .word 0x0 - @ PROC_REPEAT - .short 0x3, 0x0 - .word sub_80B251C - @ PROC_END - .short 0x0, 0x0 - .word 0x0 - - - .global ProcScr_ColFadeIn -ProcScr_ColFadeIn: @ 0x08A2EEC0 - @ PROC_NAME - .short 0x1, 0x0 - .word 0x8205e80 - @ PROC_SLEEP - .short 0xe, 0x2 - .word 0x0 - @ PROC_CALL - .short 0x2, 0x0 - .word nullsub_67 - @ PROC_YIELD - .short 0xe, 0x0 - .word 0x0 - @ PROC_REPEAT - .short 0x3, 0x0 - .word sub_80B2608 - @ PROC_END - .short 0x0, 0x0 - .word 0x0 diff --git a/include/colorfade.h b/include/colorfade.h new file mode 100644 index 000000000..61989e376 --- /dev/null +++ b/include/colorfade.h @@ -0,0 +1,31 @@ +#ifndef GUARD_COLORFADE_H +#define GUARD_COLORFADE_H + +struct ColFadeProc +{ + /* 00 */ PROC_HEADER; + /* 29 */ STRUCT_PAD(0x29, 0x4E); + + /* 4E */ u16 current; + + /* 50 */ STRUCT_PAD(0x50, 0x58); + + /* 58 */ int color; + /* 5C */ int start; + /* 60 */ int amount; + /* 64 */ u16 speed; +}; + +// ??? ColFadeOut_Init(???); +// ??? ColFadeIn_Init_Null(???); +// ??? ColFadeOut_Loop(???); +// ??? ColFadeIn_Loop(???); +void NewColFadeOut(int, int, int, ProcPtr); +void NewColFadeIn(int, int, int, ProcPtr); + +extern u16 gUnknown_02014EF4[]; + +// extern ??? ProcScr_ColFadeOut +// extern ??? ProcScr_ColFadeIn + +#endif // GUARD_COLORFADE_H diff --git a/include/functions.h b/include/functions.h index 38654def2..26e3242a8 100644 --- a/include/functions.h +++ b/include/functions.h @@ -526,12 +526,7 @@ int CountDigits(int number); // ??? sub_80B060C(???); // ??? sub_80B0620(???); // ??? sub_80B169C(???); -// ??? sub_80B24DC(???); -// ??? nullsub_67(???); -// ??? sub_80B251C(???); -// ??? sub_80B2608(???); -void NewColFadeOut(int, int, int, ProcPtr); -void NewColFadeIn(int, int, int, ProcPtr); + // ??? sub_80B5730(???); void StartArenaScreen(void); void StartArenaResultsScreen(void); diff --git a/include/variables.h b/include/variables.h index 87450ded1..c6986b227 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1187,8 +1187,7 @@ extern u8 gUnknown_08A2E4C4[]; // TSA extern u8 gUnknown_08A2E5EC[]; // Gfx extern u16 gUnknown_08A2E8F0[]; // Pal extern u8 Img_SysBlackBox[]; // Gfx -// extern ??? ProcScr_ColFadeOut -// extern ??? ProcScr_ColFadeIn + extern u8 gUnknown_08A301B0[]; // gfx? extern u16 gUnknown_08A30780[]; // pal extern u8 gUnknown_08A30800[]; // gfx diff --git a/ldscript.txt b/ldscript.txt index 0703b37ac..e8dba985c 100644 --- a/ldscript.txt +++ b/ldscript.txt @@ -569,7 +569,7 @@ SECTIONS . = ALIGN(4); src/savedrawcursor.o(.rodata); . = ALIGN(4); src/sysutil.o(.rodata); . = ALIGN(4); src/uiconfig.o(.rodata); - . = ALIGN(4); data/const_data_205E74.o(.rodata); + . = ALIGN(4); src/colorfade.o(.rodata); . = ALIGN(4); src/opinfo.o(.rodata); . = ALIGN(4); src/gamerankings.o(.rodata); . = ALIGN(4); src/worldmap_face.o(.rodata); @@ -891,7 +891,7 @@ SECTIONS . = ALIGN(4); src/bonusclaim.o(.data); . = ALIGN(4); data/data_A21658.o(.data); . = ALIGN(4); src/uiconfig.o(.data); - . = ALIGN(4); data/data_A2EE90.o(.data); + . = ALIGN(4); src/colorfade.o(.data); . = ALIGN(4); src/opinfo.o(.data); . = ALIGN(4); src/classdisplayfont.o(.data); . = ALIGN(4); data/data_A2EEF0.o(.data); diff --git a/src/colorfade.c b/src/colorfade.c index c1bf28282..23a671201 100644 --- a/src/colorfade.c +++ b/src/colorfade.c @@ -1,30 +1,16 @@ #include "global.h" #include "hardware.h" +#include "colorfade.h" extern u16 gUnknown_02014EF4[]; -struct ColFadeProc -{ - /* 00 */ PROC_HEADER; - /* 29 */ STRUCT_PAD(0x29, 0x4E); - - /* 4E */ u16 unk_4e; - - /* 50 */ STRUCT_PAD(0x50, 0x58); - - /* 58 */ int unk_58; - /* 5C */ int unk_5c; - /* 60 */ int unk_60; - /* 64 */ u16 unk_64; -}; - //! FE8U = 0x080B24DC -void sub_80B24DC(struct ColFadeProc * proc) +void ColFadeOut_Init(struct ColFadeProc * proc) { int i; - for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + for (i = proc->start; i < proc->start + proc->amount; i++) { gUnknown_02014EF4[i] = gPaletteBuffer[i]; } @@ -33,45 +19,45 @@ void sub_80B24DC(struct ColFadeProc * proc) } //! FE8U = 0x080B2518 -void nullsub_67(void) +void ColFadeIn_Init_Null(void) { return; } //! FE8U = 0x080B251C -void sub_80B251C(struct ColFadeProc * proc) +void ColFadeOut_Loop(struct ColFadeProc * proc) { int i; - u16 val = 0x100 - proc->unk_4e; + u16 val = 0x100 - proc->current; - for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + for (i = proc->start; i < proc->start + proc->amount; i++) { int r, r1, r2; int g, g1, g2; int b, b1, b2; - b1 = (gUnknown_02014EF4[i] & 0x7c00); - b2 = (proc->unk_58 & 0x7c00); + b1 = (gUnknown_02014EF4[i] & BLUE_MASK); + b2 = (proc->color & BLUE_MASK); b2 = b1 - b2; - b = ((b2 * val / 0x100) + proc->unk_58) & 0x7c00; + b = ((b2 * val / 0x100) + proc->color) & BLUE_MASK; - g1 = (gUnknown_02014EF4[i] & 0x3e0); - g2 = (proc->unk_58 & 0x3e0); + g1 = (gUnknown_02014EF4[i] & GREEN_MASK); + g2 = (proc->color & GREEN_MASK); g2 = (g1 - g2); - g = ((g2 * val / 0x100) + proc->unk_58) & 0x3e0; + g = ((g2 * val / 0x100) + proc->color) & GREEN_MASK; - r1 = (gUnknown_02014EF4[i] & 0x1f); - r2 = (proc->unk_58 & 0x1f); + r1 = (gUnknown_02014EF4[i] & RED_MASK); + r2 = (proc->color & RED_MASK); r2 = r1 - r2; - r = ((r2 * val / 0x100) + proc->unk_58) & 0x1f; + r = ((r2 * val / 0x100) + proc->color) & RED_MASK; gPaletteBuffer[i] = b | g | r; } EnablePaletteSync(); - proc->unk_4e += proc->unk_64; + proc->current += proc->speed; if (val == 0) { @@ -82,34 +68,34 @@ void sub_80B251C(struct ColFadeProc * proc) } //! FE8U = 0x080B2608 -void sub_80B2608(struct ColFadeProc * proc) +void ColFadeIn_Loop(struct ColFadeProc * proc) { int i; - u16 val = 0x100 - proc->unk_4e; + u16 val = 0x100 - proc->current; if (val != 0) { - for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + for (i = proc->start; i < proc->start + proc->amount; i++) { int r, r1, r2; int g, g1, g2; int b, b1, b2; - b1 = (proc->unk_58 & 0x7c00); - b2 = (gUnknown_02014EF4[i] & 0x7c00); + b1 = (proc->color & BLUE_MASK); + b2 = (gUnknown_02014EF4[i] & BLUE_MASK); b2 = b1 - b2; - b = ((b2 * val / 0x100) + gUnknown_02014EF4[i]) & 0x7c00; + b = ((b2 * val / 0x100) + gUnknown_02014EF4[i]) & BLUE_MASK; - g1 = (proc->unk_58 & 0x3e0); - g2 = (gUnknown_02014EF4[i] & 0x3e0); + g1 = (proc->color & GREEN_MASK); + g2 = (gUnknown_02014EF4[i] & GREEN_MASK); g2 = (g1 - g2); - g = ((g2 * val / 0x100) + gUnknown_02014EF4[i]) & 0x3e0; + g = ((g2 * val / 0x100) + gUnknown_02014EF4[i]) & GREEN_MASK; - r1 = (proc->unk_58 & 0x1f); - r2 = (gUnknown_02014EF4[i] & 0x1f); + r1 = (proc->color & RED_MASK); + r2 = (gUnknown_02014EF4[i] & RED_MASK); r2 = r1 - r2; - r = ((r2 * val / 0x100) + gUnknown_02014EF4[i]) & 0x1f; + r = ((r2 * val / 0x100) + gUnknown_02014EF4[i]) & RED_MASK; gPaletteBuffer[i] = b | g | r; } @@ -117,11 +103,11 @@ void sub_80B2608(struct ColFadeProc * proc) EnablePaletteSync(); - proc->unk_4e += proc->unk_64; + proc->current += proc->speed; if (val == 0) { - for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + for (i = proc->start; i < proc->start + proc->amount; i++) { gPaletteBuffer[i] = gUnknown_02014EF4[i]; gPaletteBuffer[i] = gUnknown_02014EF4[i]; @@ -134,34 +120,49 @@ void sub_80B2608(struct ColFadeProc * proc) return; } -extern struct ProcCmd ProcScr_ColFadeOut[]; +// clang-format off + +struct ProcCmd CONST_DATA ProcScr_ColFadeOut[] = +{ + PROC_NAME("ColFadeOut"), + PROC_SLEEP(2), + + PROC_CALL(ColFadeOut_Init), + PROC_YIELD, + + PROC_REPEAT(ColFadeOut_Loop), + + PROC_END, +}; + +// clang-format on //! FE8U = 0x080B272C void NewColFadeOut(int speed, int kind, int color, ProcPtr parent) { struct ColFadeProc * proc = Proc_StartBlocking(ProcScr_ColFadeOut, parent); - proc->unk_64 = speed; - proc->unk_58 = color; - proc->unk_4e = 0; + proc->speed = speed; + proc->color = color; + proc->current = 0; switch (kind) { case 0: - proc->unk_5c = 0x80; - proc->unk_60 = 0x80; + proc->start = 0x80; + proc->amount = 0x80; break; case 1: - proc->unk_5c = 0; - proc->unk_60 = 0x200; + proc->start = 0; + proc->amount = 0x200; break; case 2: - proc->unk_5c = 0; - proc->unk_60 = 0x400; + proc->start = 0; + proc->amount = 0x400; break; } @@ -169,7 +170,22 @@ void NewColFadeOut(int speed, int kind, int color, ProcPtr parent) return; } -extern struct ProcCmd ProcScr_ColFadeIn[]; +// clang-format off + +struct ProcCmd CONST_DATA ProcScr_ColFadeIn[] = +{ + PROC_NAME("ColFadeIn"), + PROC_SLEEP(2), + + PROC_CALL(ColFadeIn_Init_Null), + PROC_YIELD, + + PROC_REPEAT(ColFadeIn_Loop), + + PROC_END, +}; + +// clang-format on //! FE8U = 0x080B2780 void NewColFadeIn(int speed, int kind, int color, ProcPtr parent) @@ -178,37 +194,37 @@ void NewColFadeIn(int speed, int kind, int color, ProcPtr parent) struct ColFadeProc * proc = Proc_StartBlocking(ProcScr_ColFadeIn, parent); - proc->unk_64 = speed; - proc->unk_58 = color; + proc->speed = speed; + proc->color = color; - proc->unk_4e = 0; + proc->current = 0; switch (kind) { case 0: - proc->unk_5c = 0x80; - proc->unk_60 = 0x80; + proc->start = 0x80; + proc->amount = 0x80; break; case 1: - proc->unk_5c = 0; - proc->unk_60 = 0x200; + proc->start = 0; + proc->amount = 0x200; break; case 2: - proc->unk_5c = 0; - proc->unk_60 = 0x400; + proc->start = 0; + proc->amount = 0x400; break; } - for (i = proc->unk_5c; i < proc->unk_5c + proc->unk_60; i++) + for (i = proc->start; i < proc->start + proc->amount; i++) { gUnknown_02014EF4[i] = gPaletteBuffer[i]; gPaletteBuffer[i] = 0; } return; -} \ No newline at end of file +} diff --git a/src/eventscr.c b/src/eventscr.c index 5da38ed8f..d718bdc26 100644 --- a/src/eventscr.c +++ b/src/eventscr.c @@ -37,6 +37,7 @@ #include "eventcall.h" #include "bmdifficulty.h" #include "bmfx.h" +#include "colorfade.h" void BgChangeChr(int, int);