Skip to content

Commit

Permalink
Merge pull request #579 from Eebit/colorfade
Browse files Browse the repository at this point in the history
Decompile color fade effects
  • Loading branch information
RevoSucks authored Feb 26, 2024
2 parents d6abec5 + 17e9822 commit c80a433
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 527 deletions.
463 changes: 0 additions & 463 deletions asm/code_80B24DC.s

This file was deleted.

9 changes: 0 additions & 9 deletions data/const_data_205E74.s

This file was deleted.

44 changes: 0 additions & 44 deletions data/data_A2EE90.s

This file was deleted.

31 changes: 31 additions & 0 deletions include/colorfade.h
Original file line number Diff line number Diff line change
@@ -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
7 changes: 1 addition & 6 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ldscript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
230 changes: 230 additions & 0 deletions src/colorfade.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#include "global.h"

#include "hardware.h"
#include "colorfade.h"

extern u16 gUnknown_02014EF4[];

//! FE8U = 0x080B24DC
void ColFadeOut_Init(struct ColFadeProc * proc)
{
int i;

for (i = proc->start; i < proc->start + proc->amount; i++)
{
gUnknown_02014EF4[i] = gPaletteBuffer[i];
}

return;
}

//! FE8U = 0x080B2518
void ColFadeIn_Init_Null(void)
{
return;
}

//! FE8U = 0x080B251C
void ColFadeOut_Loop(struct ColFadeProc * proc)
{
int i;

u16 val = 0x100 - proc->current;

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] & BLUE_MASK);
b2 = (proc->color & BLUE_MASK);
b2 = b1 - b2;
b = ((b2 * val / 0x100) + proc->color) & BLUE_MASK;

g1 = (gUnknown_02014EF4[i] & GREEN_MASK);
g2 = (proc->color & GREEN_MASK);
g2 = (g1 - g2);
g = ((g2 * val / 0x100) + proc->color) & GREEN_MASK;

r1 = (gUnknown_02014EF4[i] & RED_MASK);
r2 = (proc->color & RED_MASK);
r2 = r1 - r2;
r = ((r2 * val / 0x100) + proc->color) & RED_MASK;

gPaletteBuffer[i] = b | g | r;
}

EnablePaletteSync();

proc->current += proc->speed;

if (val == 0)
{
Proc_Break(proc);
}

return;
}

//! FE8U = 0x080B2608
void ColFadeIn_Loop(struct ColFadeProc * proc)
{
int i;

u16 val = 0x100 - proc->current;

if (val != 0)
{
for (i = proc->start; i < proc->start + proc->amount; i++)
{
int r, r1, r2;
int g, g1, g2;
int b, b1, b2;

b1 = (proc->color & BLUE_MASK);
b2 = (gUnknown_02014EF4[i] & BLUE_MASK);
b2 = b1 - b2;
b = ((b2 * val / 0x100) + gUnknown_02014EF4[i]) & BLUE_MASK;

g1 = (proc->color & GREEN_MASK);
g2 = (gUnknown_02014EF4[i] & GREEN_MASK);
g2 = (g1 - g2);
g = ((g2 * val / 0x100) + gUnknown_02014EF4[i]) & GREEN_MASK;

r1 = (proc->color & RED_MASK);
r2 = (gUnknown_02014EF4[i] & RED_MASK);
r2 = r1 - r2;
r = ((r2 * val / 0x100) + gUnknown_02014EF4[i]) & RED_MASK;

gPaletteBuffer[i] = b | g | r;
}
}

EnablePaletteSync();

proc->current += proc->speed;

if (val == 0)
{
for (i = proc->start; i < proc->start + proc->amount; i++)
{
gPaletteBuffer[i] = gUnknown_02014EF4[i];
gPaletteBuffer[i] = gUnknown_02014EF4[i];
gPaletteBuffer[i] = gUnknown_02014EF4[i];
}

Proc_Break(proc);
}

return;
}

// 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->speed = speed;
proc->color = color;
proc->current = 0;

switch (kind)
{
case 0:
proc->start = 0x80;
proc->amount = 0x80;

break;

case 1:
proc->start = 0;
proc->amount = 0x200;

break;

case 2:
proc->start = 0;
proc->amount = 0x400;

break;
}

return;
}

// 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)
{
int i;

struct ColFadeProc * proc = Proc_StartBlocking(ProcScr_ColFadeIn, parent);

proc->speed = speed;
proc->color = color;

proc->current = 0;

switch (kind)
{
case 0:
proc->start = 0x80;
proc->amount = 0x80;

break;

case 1:
proc->start = 0;
proc->amount = 0x200;

break;

case 2:
proc->start = 0;
proc->amount = 0x400;

break;
}

for (i = proc->start; i < proc->start + proc->amount; i++)
{
gUnknown_02014EF4[i] = gPaletteBuffer[i];
gPaletteBuffer[i] = 0;
}

return;
}
1 change: 1 addition & 0 deletions src/eventscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "eventcall.h"
#include "bmdifficulty.h"
#include "bmfx.h"
#include "colorfade.h"

void BgChangeChr(int, int);

Expand Down

0 comments on commit c80a433

Please sign in to comment.