Finish palette.c decomp

This commit is contained in:
PikalaxALT 2024-01-15 06:12:29 -05:00
parent 41b19f585c
commit 737e77a2fa
No known key found for this signature in database
GPG Key ID: C7E3D40F3BAC7AEB
6 changed files with 47 additions and 254 deletions

View File

@ -1,69 +0,0 @@
#include <nitro/fs/overlay.h>
#pragma once
.public PaletteData_Init
.public PaletteData_Free
.public PaletteData_SetBuffers
.public PaletteData_AllocBuffers
.public PaletteData_FreeBuffers
.public PaletteData_LoadPalette
.public PaletteData_LoadFromNarc
.public PaletteData_LoadNarc
.public PaletteData_LoadFromOpenNarc
.public PaletteData_LoadOpenNarc
.public sub_020032A4
.public PaletteData_CopyPalette
.public PaletteData_GetUnfadedBuf
.public PaletteData_GetFadedBuf
.public sub_02003370
.public sub_02003474
.public sub_0200374C
.public PaletteData_PushTransparentBuffers
.public sub_02003B44
.public PaletteData_SetAutoTransparent
.public sub_02003B74
.public sub_02003BA8
.public sub_02003D5C
.public sub_02003DBC
.public sub_02003DE8
.public sub_02003E5C
.public sub_02003EA4
.public TintPalette_GrayScale
.public TintPalette_CustomTone
.public sub_02003FC8
.public sub_020040AC
.public GfGfxLoader_GetPlttData
.public GfGfxLoader_GetPlttDataFromOpenNarc
.public CreateSysTask
.public DestroySysTask
.public AllocFromHeap
.public FreeToHeap
.public FreeToHeapExplicit
.public GF_AssertFail
.public sub_02026E84
.public sub_02026E94
.public sub_02026EA4
.public sub_02026EAC
.public GX_LoadBGPltt
.public GXS_LoadBGPltt
.public GX_LoadOBJPltt
.public GXS_LoadOBJPltt
.public GX_BeginLoadBGExtPltt
.public GX_LoadBGExtPltt
.public GX_EndLoadBGExtPltt
.public GX_BeginLoadOBJExtPltt
.public GX_LoadOBJExtPltt
.public GX_EndLoadOBJExtPltt
.public GXS_BeginLoadBGExtPltt
.public GXS_LoadBGExtPltt
.public GXS_EndLoadBGExtPltt
.public GXS_BeginLoadOBJExtPltt
.public GXS_LoadOBJExtPltt
.public GXS_EndLoadOBJExtPltt
.public DC_FlushRange
.public MIi_CpuClear16
.public MIi_CpuCopy16
.public MIi_CpuCopyFast
.public MI_CpuFill8
.public abs
.public memset
.public _s32_div_f

View File

@ -1,183 +0,0 @@
.include "asm/macros.inc"
.include "palette.inc"
.include "global.inc"
.text
thumb_func_start sub_02004020
sub_02004020: ; 0x02004020
push {r3, r4, r5, r6, r7, lr}
sub sp, #0x10
str r0, [sp]
ldr r0, [sp, #0x28]
str r1, [sp, #4]
str r0, [sp, #0x28]
ldr r0, [sp, #0x2c]
add r7, r2, #0
str r0, [sp, #0x2c]
ldr r0, [sp, #0x30]
add r6, r3, #0
str r0, [sp, #0x30]
mov r0, #0
str r0, [sp, #0xc]
_0200403C:
ldr r0, [sp]
mov r1, #0x1f
ldrh r0, [r0]
asr r2, r0, #5
add r4, r0, #0
add r5, r2, #0
and r4, r1
and r5, r1
asr r1, r0, #0xa
mov r0, #0x1f
and r0, r1
str r0, [sp, #8]
ldr r0, [sp, #0x28]
add r1, r7, #0
sub r0, r0, r4
mul r0, r6
bl _s32_div_f
add r4, r4, r0
ldr r0, [sp, #0x2c]
add r1, r7, #0
sub r0, r0, r5
mul r0, r6
bl _s32_div_f
add r5, r5, r0
ldr r1, [sp, #0x30]
ldr r0, [sp, #8]
sub r0, r1, r0
mul r0, r6
add r1, r7, #0
bl _s32_div_f
ldr r1, [sp, #8]
add r0, r1, r0
lsl r1, r0, #0xa
lsl r0, r5, #5
orr r0, r1
add r1, r4, #0
orr r1, r0
ldr r0, [sp, #4]
strh r1, [r0]
ldr r0, [sp]
add r0, r0, #2
str r0, [sp]
ldr r0, [sp, #4]
add r0, r0, #2
str r0, [sp, #4]
ldr r0, [sp, #0xc]
add r0, r0, #1
str r0, [sp, #0xc]
cmp r0, #0x10
blt _0200403C
add sp, #0x10
pop {r3, r4, r5, r6, r7, pc}
.balign 4, 0
thumb_func_end sub_02004020
thumb_func_start sub_020040AC
sub_020040AC: ; 0x020040AC
push {r4, r5, r6, r7, lr}
sub sp, #0x24
add r7, r2, #0
mov r2, #0x46
add r5, r0, #0
ldr r0, [sp, #0x38]
lsl r2, r2, #2
str r1, [sp, #0xc]
str r0, [sp, #0x38]
ldrh r1, [r5, r2]
mov r0, #3
str r3, [sp, #0x10]
bic r1, r0
mov r0, #1
orr r0, r1
strh r0, [r5, r2]
add r0, r2, #2
ldr r1, [sp, #0xc]
ldrh r0, [r5, r0]
ldr r3, _02004170 ; =0xFFFFC000
lsl r1, r1, #0x10
lsr r4, r1, #0x10
lsr r1, r3, #0x12
and r0, r3
and r1, r4
orr r1, r0
add r0, r2, #2
strh r1, [r5, r0]
add r0, sp, #0x28
ldrh r2, [r0, #0x14]
mov r1, #0x1f
add r0, r2, #0
and r0, r1
str r0, [sp, #0x1c]
asr r0, r2, #5
and r0, r1
str r0, [sp, #0x18]
asr r0, r2, #0xa
and r0, r1
str r0, [sp, #0x14]
mov r0, #0
str r0, [sp, #0x20]
_02004100:
ldr r0, [r5, #4]
cmp r0, #0
beq _0200415E
ldr r1, [sp, #0xc]
ldr r0, [sp, #0x20]
asr r1, r0
mov r0, #1
tst r1, r0
beq _0200415E
mov r6, #0
strh r7, [r5, #0xc]
lsl r0, r0, #9
str r0, [r5, #8]
add r4, r6, #0
_0200411C:
add r1, r7, #0
asr r1, r6
mov r0, #1
tst r0, r1
beq _02004146
ldr r0, [sp, #0x1c]
lsl r1, r4, #1
str r0, [sp]
ldr r0, [sp, #0x18]
ldr r3, [sp, #0x38]
str r0, [sp, #4]
ldr r0, [sp, #0x14]
str r0, [sp, #8]
ldr r0, [r5]
ldr r2, [r5, #4]
add r0, r0, r1
add r1, r2, r1
ldr r2, [sp, #0x10]
bl sub_02004020
b _02004156
_02004146:
ldr r0, [r5]
lsl r1, r4, #1
ldr r2, [r5, #4]
add r0, r0, r1
add r1, r2, r1
mov r2, #0x20
bl MIi_CpuCopyFast
_02004156:
add r6, r6, #1
add r4, #0x10
cmp r6, #0x10
blt _0200411C
_0200415E:
ldr r0, [sp, #0x20]
add r5, #0x14
add r0, r0, #1
str r0, [sp, #0x20]
cmp r0, #0xe
blt _02004100
add sp, #0x24
pop {r4, r5, r6, r7, pc}
nop
_02004170: .word 0xFFFFC000
thumb_func_end sub_020040AC

View File

@ -92,5 +92,6 @@ void sub_02003EA4(PaletteData *data, PaletteBufferId bufferID, u16 selectedBuffe
void TintPalette_GrayScale(u16 *palette, int count);
void TintPalette_CustomTone(u16 *palette, int count, int rTone, int gTone, int bTone);
void sub_02003FC8(PaletteData *data, NarcId narcId, s32 memberNo, HeapID heapId, PaletteBufferId bufferID, u32 size, u16 pos, int rTone, int gTone, int bTone);
void sub_020040AC(PaletteData *plttData, int transparentBit, int opaqueBit, int denom, int numer, u16 target);
#endif //POKEHEARTGOLD_PALETTE_H

View File

@ -3,4 +3,4 @@
int abs(int);
#endif _MSL_STDLIB_H
#endif //_MSL_STDLIB_H

View File

@ -17,7 +17,6 @@ Static main
Object asm/render_text.o
Object src/font.o
Object src/palette.o
Object asm/palette_s.o
Object src/sound.o
Object src/sound_radio_sys.o
Object asm/unk_02004A44.o

View File

@ -16,6 +16,7 @@ void sub_020037A0(PaletteData *data, u16 bufferID, u16 size);
void sub_020037FC(PaletteData *data, u16 bufferID, u16 size);
void sub_02003858(u16 *opaque, u16 *transparent, SelectedPaletteData *selectedBit, u16 size);
void sub_020038E4(PaletteData *data, u8 bufferID, SelectedPaletteData *selectedBit);
void sub_02004020(const u16 *src, u16 *dest, int denom, int numer, int rTarget, int gTarget, int bTarget);
PaletteData *PaletteData_Init(HeapID heapId) {
PaletteData *ret = AllocFromHeap(heapId, sizeof(PaletteData));
@ -615,3 +616,47 @@ void sub_02003FC8(PaletteData *data, NarcId narcId, s32 memberNo, HeapID heapId,
PaletteData_LoadPalette(data, pPlttData->pRawData, bufferID, pos, size);
FreeToHeap(rawBuf);
}
void sub_02004020(const u16 *src, u16 *dest, int denom, int numer, int rTarget, int gTarget, int bTarget) {
int i, r, g, b;
for (i = 0; i < 16; ++i) {
r = *src & 0x1F;
g = (*src >> 5) & 0x1F;
b = (*src >> 10) & 0x1F;
r += (rTarget - r) * numer / denom;
g += (gTarget - g) * numer / denom;
b += (bTarget - b) * numer / denom;
*dest = (b << 10) | (g << 5) | r;
++src;
++dest;
}
}
void sub_020040AC(PaletteData *plttData, int transparentBit, int opaqueBit, int denom, int numer, u16 target) {
int i, j, r, g, b;
plttData->selectedFlag = 1;
plttData->transparentBit = transparentBit;
r = target & 0x1F;
g = (target >> 5) & 0x1F;
b = (target >> 10) & 0x1F;
for (i = 0; i < PLTTBUF_MAX; ++i) {
if (plttData->buffers[i].transparent != NULL && (transparentBit >> i) & 1) {
plttData->buffers[i].selected.opaqueBit = opaqueBit;
plttData->buffers[i].size = 0x200;
for (j = 0; j < 16; ++j) {
if ((opaqueBit >> j) & 1) {
sub_02004020(&plttData->buffers[i].opaque[j * 16], &plttData->buffers[i].transparent[j * 16], denom, numer, r, g, b);
} else {
MI_CpuCopyFast(&plttData->buffers[i].opaque[j * 16], &plttData->buffers[i].transparent[j * 16], 0x20);
}
}
}
}
}