Skip to content

Commit

Permalink
PSP DRA func_800EA720 (#2048)
Browse files Browse the repository at this point in the history
Required some rearrangement for this one. Since those color masks aren't
used anywhere else, I moved them out of dra.h and instead they're just
attached to the function.
  • Loading branch information
bismurphy authored Jan 9, 2025
1 parent 5eee03b commit 0019ad3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
1 change: 1 addition & 0 deletions config/symbols.pspeu.dra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ func_80105428 = 0x090DEAC8;
func_800EA538 = 0x090DFC98;
func_800EA5AC = 0x090DFD38;
func_800EA5E4 = 0x090DFD70;
func_800EA720 = 0x090DFED8;
func_800EDB08 = 0x090E0CF0;
func_800EDB58 = 0x090E0D68;
AllocPrimitives = 0x090E0E30;
Expand Down
42 changes: 27 additions & 15 deletions src/dra/4A538.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,43 @@ s32 func_800EA5E4(u32 arg0) {
return -1;
}

u16 func_800EA720(u32 colorDst, u32 colorSrc) {
u16 colorRes = colorSrc;
#define RED_MASK 0x1F
#define GREEN_MASK 0x3E0
#define BLUE_MASK 0x7C00
// These could be ~RED_MASK, but that doesn't match.
#define UNRED_MASK 0xFFFF - RED_MASK
#define UNGREEN_MASK 0xFFFF - GREEN_MASK
#define UNBLUE_MASK 0xFFFF - BLUE_MASK

if (GET_RED(colorRes) < GET_RED(colorDst)) {
colorRes = (colorRes & ~RED_MASK) | (GET_RED(colorRes) + 1);
#define GET_RED(x) ((x) & RED_MASK)
#define GET_GREEN(x) ((x) & GREEN_MASK)
#define GET_BLUE(x) ((x) & BLUE_MASK)

// Takes a color "col" in RGB555 and increments/decrements each component
// to bring it closer to the target by 1.
u16 func_800EA720(u16 target, u16 col) {
if (GET_RED(target) > GET_RED(col)) {
col = (col & UNRED_MASK) | (GET_RED(col) + 1);
}
if (GET_RED(colorDst) < GET_RED(colorRes)) {
colorRes = (colorRes & ~RED_MASK) | (GET_RED(colorRes) - 1);
if (GET_RED(target) < GET_RED(col)) {
col = (col & UNRED_MASK) | (GET_RED(col) - 1);
}

if (GET_GREEN(colorRes) < GET_GREEN(colorDst)) {
colorRes = (colorRes & ~GREEN_MASK) | (GET_GREEN(colorRes) + 0x20);
if (GET_GREEN(target) > GET_GREEN(col)) {
col = (col & UNGREEN_MASK) | (GET_GREEN(col) + (1 << 5));
}
if (GET_GREEN(colorDst) < GET_GREEN(colorRes)) {
colorRes = (colorRes & ~GREEN_MASK) | (GET_GREEN(colorRes) - 0x20);
if (GET_GREEN(target) < GET_GREEN(col)) {
col = (col & UNGREEN_MASK) | (GET_GREEN(col) - (1 << 5));
}

if (GET_BLUE(colorRes) < GET_BLUE(colorDst)) {
colorRes = (colorRes & ~BLUE_MASK) | (GET_BLUE(colorRes) + 0x400);
if (GET_BLUE(target) > GET_BLUE(col)) {
col = (col & UNBLUE_MASK) | (GET_BLUE(col) + (1 << 10));
}
if (GET_BLUE(colorDst) < GET_BLUE(colorRes)) {
colorRes = (colorRes & ~BLUE_MASK) | (GET_BLUE(colorRes) - 0x400);
if (GET_BLUE(target) < GET_BLUE(col)) {
col = (col & UNBLUE_MASK) | (GET_BLUE(col) - (1 << 10));
}

return colorRes;
return col;
}

void func_800EA7CC(void) {
Expand Down
8 changes: 0 additions & 8 deletions src/dra/dra.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
#define SEQ_TABLE_S_MAX 0x10
#define SEQ_TABLE_T_MAX 1

#define RED_MASK 0x1F
#define GREEN_MASK 0x3E0
#define BLUE_MASK 0x7C00

#define GET_RED(x) ((x) & RED_MASK)
#define GET_GREEN(x) ((x) & GREEN_MASK)
#define GET_BLUE(x) ((x) & BLUE_MASK)

#define VSYNC_UNK_LEN 1024

#define NUM_CH 4
Expand Down
39 changes: 38 additions & 1 deletion src/dra_psp/33F0.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,44 @@ s32 func_800EA5E4(u32 arg0) {
return -1;
}

INCLUDE_ASM("dra_psp/psp/dra_psp/33F0", func_psp_090DFED8);
#define RED_MASK 0x1F
#define GREEN_MASK 0x3E0
#define BLUE_MASK 0x7C00
// These could be ~RED_MASK, but that doesn't match.
#define UNRED_MASK 0xFFFF - RED_MASK
#define UNGREEN_MASK 0xFFFF - GREEN_MASK
#define UNBLUE_MASK 0xFFFF - BLUE_MASK

#define GET_RED(x) ((x) & RED_MASK)
#define GET_GREEN(x) ((x) & GREEN_MASK)
#define GET_BLUE(x) ((x) & BLUE_MASK)

// Takes a color "col" in RGB555 and increments/decrements each component
// to bring it closer to the target by 1.
u16 func_800EA720(u16 target, u16 col) {
if (GET_RED(target) > GET_RED(col)) {
col = (col & UNRED_MASK) | (GET_RED(col) + 1);
}
if (GET_RED(target) < GET_RED(col)) {
col = (col & UNRED_MASK) | (GET_RED(col) - 1);
}

if (GET_GREEN(target) > GET_GREEN(col)) {
col = (col & UNGREEN_MASK) | (GET_GREEN(col) + (1 << 5));
}
if (GET_GREEN(target) < GET_GREEN(col)) {
col = (col & UNGREEN_MASK) | (GET_GREEN(col) - (1 << 5));
}

if (GET_BLUE(target) > GET_BLUE(col)) {
col = (col & UNBLUE_MASK) | (GET_BLUE(col) + (1 << 10));
}
if (GET_BLUE(target) < GET_BLUE(col)) {
col = (col & UNBLUE_MASK) | (GET_BLUE(col) - (1 << 10));
}

return col;
}

INCLUDE_ASM("dra_psp/psp/dra_psp/33F0", func_psp_090DFFD0);

Expand Down

0 comments on commit 0019ad3

Please sign in to comment.