Remove the use of UnkStructClut (#960)

Rewrites SEL's `banks.c` to use an array of `u_long` and make use of
declarations to populate it.

This PR comes after giving up at believing the original developers would
had the decency of using structs instead of crude array of data. They
are really developers from another era.
This commit is contained in:
Luciano Ciccariello 2024-01-10 19:47:15 +00:00 committed by GitHub
parent 90f210367b
commit 9ae1ffec21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 114 additions and 87 deletions

View File

@ -30,6 +30,7 @@
#endif
#define LOH(x) (*(s16*)&(x))
#define HIH(x) (((s16*)&(x))[1])
#define LOHU(x) (*(u16*)&(x))
#define LOW(x) (*(s32*)&(x))
#define LOWU(x) (*(u32*)&(x))

View File

@ -968,7 +968,7 @@ typedef struct {
/* 8003C780 */ void (*InitRoomEntities)(s32 layoutId);
/* 8003C784 */ RoomHeader* rooms;
/* 8003C788 */ s16** spriteBanks;
/* 8003C78C */ UnkStructClut** cluts;
/* 8003C78C */ u_long** cluts;
/* 8003C790 */ void* unk1C; // related to entity layout
/* 8003C794 */ RoomDef* tileLayers;
/* 8003C798 */ GfxBank** gfxBanks;
@ -1545,7 +1545,7 @@ extern s32 g_IsUsingCd;
extern Entity* g_CurrentEntity;
extern Unkstruct_8006C3C4 D_8006C3C4[32];
extern s32 g_Servant; // Currently selected familiar in the menu
extern u16 g_Clut[];
extern u16 g_Clut[0x3000];
extern u32 D_8006EBCC;
extern u16 D_8006EBE0;
extern u16 D_8006F3CC[];

View File

@ -32,15 +32,28 @@ typedef struct {
/* 0x00 */ s32 unk0;
} Unkstruct_80137990;
#define MAKE_PAL_OP(kind, freq) ((kind) | ((freq) << 0x10))
#define GET_PAL_OP_KIND(x) (LOH(x))
#define GET_PAL_OP_FREQ(x) (HIH(x))
#define PAL_GLOW_ANIM 4
#define PAL_GLOW_INFO(dst, n) (u_long*)(dst), (u_long*)(n)
#define PAL_GLOW_DATA(data) (u_long*)(data)
#define PAL_BULK_COPY 5
#define PAL_BULK(dst, n, data) (u_long*)(dst), (u_long*)(n), (u_long*)(data)
#define PAL_TERMINATE() ((u_long*)-1)
typedef struct {
struct UnkStructClut* struct1;
struct UnkStructClut* struct2;
u16 unk8;
u16 unkA;
u16 unkC;
u16 unkE;
u8 unkArray[0x30];
} Unkstruct_8006C3C4; // size = 0x40
/* 0x00 */ u_long* desc;
/* 0x04 */ u_long* data;
/* 0x08 */ u16 unk8; // anim mode?
/* 0x0A */ u16 index;
/* 0x0C */ u16 unkC;
/* 0x0E */ u16 unkE;
/* 0x10 */ u8 unkArray[0x30]; // color buffer
} Unkstruct_8006C3C4; // size = 0x40
typedef struct {
s16 unk0;
@ -172,14 +185,6 @@ typedef struct {
/* 0x8 */ s32 unk8;
} Unkstruct_80180FE0;
typedef struct {
s32 unk0;
s32 unk4;
s32 unk8;
s32 unkC;
s32 unk10;
} UnkStructClut;
typedef struct Unkstruct_801C7954 {
/* 0x00 */ u16 x1;
/* 0x02 */ u16 x0;

View File

@ -11,7 +11,7 @@ void func_800EA538(s32 arg0) {
v1 = (temp >> (arg0 - 1));
if (arg0 != 0) {
for (i = 0; i < 32; i++) {
for (i = 0; i < LEN(D_8006C3C4); i++) {
if (v1 & D_8006C3C4[i].unk8) {
D_8006C3C4[i].unk8 = 0;
}
@ -22,7 +22,7 @@ void func_800EA538(s32 arg0) {
D_8003C0F8 = 0;
var_v0 = &D_8006C3C4;
for (i = 0; i < 32; i++) {
for (i = 0; i < LEN(D_8006C3C4); i++) {
var_v0->unk8 = 0;
var_v0++;
}
@ -39,10 +39,10 @@ s32 func_800EA5E4(u32 arg0) {
u16 temp_v0;
s32 i;
s32 j;
u32 ones_start;
u32 ones_end;
UnkStructClut* clut;
Unkstruct_8006C3C4* unkStruct;
u32 start;
u32 count;
u_long* clut;
Unkstruct_8006C3C4* clutAnim;
temp_v0 = arg0 & 0xFF00;
arg0 = arg0 & 0xFF;
@ -53,38 +53,39 @@ s32 func_800EA5E4(u32 arg0) {
clut = D_800A3BB8[arg0];
}
if (clut->unk0 == 0) {
if (clut[0] == 0) {
return 1;
}
if (clut->unk0 == -1) {
if (clut[0] == -1) {
return 1;
}
unkStruct = &D_8006C3C4;
for (j = 0; j < LEN(D_8006C3C4); unkStruct++) {
clutAnim = &D_8006C3C4;
for (j = 0; j < LEN(D_8006C3C4); clutAnim++) {
j++;
if (unkStruct->unk8 != 0) {
if (clutAnim->unk8 != 0) {
continue;
}
unkStruct->struct1 = clut;
unkStruct->struct2 = &clut->unkC;
unkStruct->unk8 = (temp_v0 | clut->unk0);
unkStruct->unkA = 0;
unkStruct->unkC = 0;
clutAnim->desc = clut;
clutAnim->data = clut + 3;
clutAnim->unk8 = (temp_v0 | GET_PAL_OP_KIND(clut[0]));
clutAnim->index = 0;
clutAnim->unkC = 0;
// Set unkStruct's array to all zeros, except within this range
ones_start = clut->unk4;
ones_end = (clut->unk4 + clut->unk8) - 1;
ones_start >>= 8;
ones_end >>= 8;
for (i = 0; i < LEN(unkStruct->unkArray); i++) {
unkStruct->unkArray[i] = 0;
start = clut[1];
count = clut[1] + clut[2] - 1;
start >>= 8;
count >>= 8;
for (i = 0; i < LEN(clutAnim->unkArray); i++) {
clutAnim->unkArray[i] = 0;
}
for (i = ones_start; ones_end >= i; i++) {
unkStruct->unkArray[i] = 1;
for (i = start; count >= i; i++) {
clutAnim->unkArray[i] = 1;
}
if ((u8)unkStruct->unk8 == 2 || (u8)unkStruct->unk8 == 16) {
unkStruct->unkE = 0x1F;
if ((u8)clutAnim->unk8 == 2 || (u8)clutAnim->unk8 == 16) {
clutAnim->unkE = 0x1F;
}
return 0;
}

View File

@ -378,7 +378,7 @@ extern MATRIX D_800A37B8;
extern Unkstruct_801092E8 D_800A37D8;
extern JosephsCloak g_JosephsCloak;
extern GfxBank** g_GfxSharedBank[];
extern UnkStructClut* D_800A3BB8[];
extern u_long* D_800A3BB8[];
extern Lba g_StagesLba[80];
extern SubweaponDef g_SubwpnDefs[13];
extern Equipment g_EquipDefs[217];

View File

@ -35,7 +35,7 @@ GfxBank** g_GfxStageBank[0x40] = {
&g_FakeGfxBank, &g_FakeGfxBank, &g_FakeGfxBank, &g_FakeGfxBank,
&g_FakeGfxBank, &g_FakeGfxBank, &g_FakeGfxBank, &g_FakeGfxBank,
};
extern UnkStructClut* D_800A3BB8[];
extern u_long* D_800A3BB8[];
void WeaponLoadPaletteStub(s32 arg0) { NOT_IMPLEMENTED; }

View File

@ -305,8 +305,8 @@ s32 g_DecReadNibbleFlag = 0;
s32 g_DecWriteNibbleFlag = 0;
u8 g_GfxEquipIcon[32][16 * 16 / 2] = {0};
s16 g_PalEquipIcon[32] = {0};
UnkStructClut g_FakeUnkStruct = {0};
UnkStructClut* D_800A3BB8[] = {
u_long g_FakeUnkStruct = {MAKE_PAL_OP(0, 0)};
u_long* D_800A3BB8[] = {
&g_FakeUnkStruct, &g_FakeUnkStruct, &g_FakeUnkStruct, &g_FakeUnkStruct,
&g_FakeUnkStruct, &g_FakeUnkStruct, &g_FakeUnkStruct, &g_FakeUnkStruct,
&g_FakeUnkStruct, &g_FakeUnkStruct, &g_FakeUnkStruct, &g_FakeUnkStruct,

View File

@ -51,62 +51,82 @@ s16** g_SpriteBanks[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
extern u32 D_8018CD54[];
extern u32 D_8018CDB4[];
extern u32 D_8018D5D4[];
extern u32 D_8018CFB4[];
extern u32 D_8018CFB4[];
extern u32 D_8018D1B4[];
extern u32 D_8018D3B4[];
extern u32 D_8018D5B4[];
extern u32 D_80180764[];
extern u32 D_80180784[];
extern u32 D_801807A4[];
extern u32 D_801807C4[];
extern u32 D_801807E4[];
extern u32 D_80180804[];
extern u32 D_801808E4[];
extern u16 D_8018CD54[16 * 3];
extern u16 D_8018CDB4[256];
extern u16 D_8018D5D4[256 * 3];
extern u16 D_8018CFB4[128];
extern u16 D_8018D1B4[128];
extern u16 D_8018D3B4[128];
extern u16 D_8018D5B4[16];
extern u16 D_80180764[16];
extern u16 D_80180784[16];
extern u16 D_801807A4[16];
extern u16 D_801807C4[16];
extern u16 D_801807E4[16];
extern u16 D_80180804[16];
extern u16 D_801808E4[256];
void* D_801805FC[] = {
0x00000000, 0x00000000, 0x00000000, 0x00006339,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
u16 D_801805FC[] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6339, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
};
void* D_8018061C[] = {
0x00000005, 0x00002000, 0x00000030, D_8018CD54,
0x00002100, 0x00000100, D_8018CDB4, 0xFFFFFFFF,
u_long* D_8018061C[] = {
MAKE_PAL_OP(PAL_BULK_COPY, 0),
PAL_BULK(0x2000, LEN(D_8018CD54), D_8018CD54),
PAL_BULK(0x2100, LEN(D_8018CDB4), D_8018CDB4),
PAL_TERMINATE(),
};
void* D_8018063C[] = {
0x00000005, 0x00001960, 0x00000010, D_801805FC, 0x00002100,
0x00000300, D_8018D5D4, 0x00002400, 0x00000080, D_8018CFB4,
0x00002480, 0x00000080, D_8018D1B4, 0x00002500, 0x00000080,
D_8018D3B4, 0x00002580, 0x00000010, D_8018D5B4, 0xFFFFFFFF,
u_long* D_8018063C[] = {
MAKE_PAL_OP(PAL_BULK_COPY, 0),
PAL_BULK(0x1960, LEN(D_801805FC), D_801805FC),
PAL_BULK(0x2100, LEN(D_8018D5D4), D_8018D5D4),
PAL_BULK(0x2400, LEN(D_8018CFB4), D_8018CFB4),
PAL_BULK(0x2480, LEN(D_8018D1B4), D_8018D1B4),
PAL_BULK(0x2500, LEN(D_8018D3B4), D_8018D3B4),
PAL_BULK(0x2580, LEN(D_8018D5B4), D_8018D5B4),
PAL_TERMINATE(),
};
void* D_8018068C[] = {
0x00000005, 0x00001960, 0x00000010, D_801805FC, 0xFFFFFFFF,
u_long* D_8018068C[] = {
MAKE_PAL_OP(PAL_BULK_COPY, 0),
PAL_BULK(0x1960, LEN(D_801805FC), D_801805FC),
PAL_TERMINATE(),
};
void* D_801806A0[] = {
0x00000005, 0x00002030, 0x00000010, D_80180764,
0x00002040, 0x00000010, D_80180804, 0xFFFFFFFF,
u_long* D_801806A0[] = {
MAKE_PAL_OP(PAL_BULK_COPY, 0),
PAL_BULK(0x2030, LEN(D_80180764), D_80180764),
PAL_BULK(0x2040, LEN(D_80180804), D_80180804),
PAL_TERMINATE(),
};
void* D_801806C0[] = {
0x00020004, 0x00002030, 0x00000010, D_80180784, D_80180764, 0xFFFFFFFF,
u_long* D_801806C0[] = {
MAKE_PAL_OP(PAL_GLOW_ANIM, 2),
PAL_GLOW_INFO(0x2030, 16),
PAL_GLOW_DATA(D_80180784),
PAL_GLOW_DATA(D_80180764),
PAL_TERMINATE(),
};
void* D_801806D8[] = {
0x00010004, 0x00002040, 0x00000010, D_801807A4,
D_801807C4, D_801807E4, D_80180804, 0xFFFFFFFF,
u_long* D_801806D8[] = {
MAKE_PAL_OP(PAL_GLOW_ANIM, 1),
PAL_GLOW_INFO(0x2040, 16),
PAL_GLOW_DATA(D_801807A4),
PAL_GLOW_DATA(D_801807C4),
PAL_GLOW_DATA(D_801807E4),
PAL_GLOW_DATA(D_80180804),
PAL_TERMINATE(),
};
void* D_801806F8[] = {
0x00000005, 0x00002200, 0x00000100, D_801808E4, 0xFFFFFFFF,
u_long* D_801806F8[] = {
MAKE_PAL_OP(PAL_BULK_COPY, 0),
PAL_BULK(0x2200, LEN(D_801808E4), D_801808E4),
PAL_TERMINATE(),
};
void** g_Cluts[] = {
u_long* g_Cluts[] = {
D_8018061C, D_801806A0, D_801806C0, D_801806D8,
D_801806F8, D_8018063C, D_8018068C,
};