Move texture data from asm to C (#142)

* Move texture data from asm to C

Required dropping a couple typedefs since they no longer had a purpose

Regenerated a couple mips_to_c outputs based on the updated types

Signed-off-by: Taggerung <tyler.taggerung@gmail.com>
This commit is contained in:
Tyler McGavran 2022-01-18 02:44:11 -05:00 committed by GitHub
parent 1bbc7674ff
commit dac4698b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 5436 additions and 3392 deletions

File diff suppressed because it is too large Load Diff

View File

@ -442,41 +442,25 @@ typedef struct {
// The rest of the bytes are used as an offset
typedef u32 segment_address_t;
// Every Mk64_Texture must be followed by either another Mk64_Texture or an Mk64_Texture sized block of zero's
typedef struct {
/* 0x00 */ s16 type;
/* 0x02 */ s16 unused1;
/* 0x04 */ segment_address_t textureData; // After converting to a virtual address, this should point actual texture data (i.e. something in texture_data_2.s)
/* 0x04 */ u64 *textureData; // This should be interpreted as a segmented address
/* 0x08 */ s16 width;
/* 0x0A */ s16 height;
/* 0x0C */ s16 dX;
/* 0x0D */ s16 dY;
/* 0x10 */ s16 size; // This size is NOT equal to width*height. Its likely the size of the compressed texture
/* 0x12 */ s16 unused2;
} Mk64_Texture; // size = 0x14
} MkTexture; // size = 0x14
/**
* A series of Mk64_Textures can be chained back-to-back in memroy to create an easily accessible group
* This group must still be ended by an Mk64_Texture sized block of zero's
* See D_020015CC in data_segment2.s for an example
*/
typedef Mk64_Texture *Mk64_Texture_Group;
// Every Mk64_Animation_Part must be followed by either another Mk64_Animation_Part or an Mk64_Animation_Part sized block of zero's
typedef struct {
/* 0x00 */ segment_address_t mk64Texture; // After converting to a virtual address, this should point to an Mk64_Texture
/* 0x00 */ MkTexture *mk64Texture; // This should be interpreted as a segmented address
/* 0x04 */ s32 frame_length;
} Mk64_Animation_Part; // size = 0x8
/**
* A series of Mk64_Animation_Parts can be chained back-to-back to create an easily accesssible "animation"
* This "animation" must still be ended an Mk64_Animation_Part sized block of zero's
* See D_02006718 in data_segment2.s for an example
*/
typedef Mk64_Animation_Part *Mk64_Animation;
} MkAnimation; // size = 0x8
typedef struct {
/* 0x00 */ Mk64_Animation textureSequence;
/* 0x00 */ MkAnimation *textureSequence;
/* 0x04 */ s32 sequenceIndex; // Index in textureSequence that the animation is currently on
/* 0x08 */ s32 frameCountDown; // Frames left for the given animation part
/* 0x0C */ u32 visible; // visbile if 0x80000000, otherwise invisbile AND paused
@ -492,7 +476,7 @@ typedef struct {
} RGBA16; // size = 0x08
typedef struct {
/* 0x00 */ segment_address_t textureData;
/* 0x00 */ u64 *textureData; // This should be interpreted as a segmented address
/**
* Its hard to tell what exactly what this is meant to be,
* but it appears to be used as some sort of offset/index from the address stored in D_8018D9B0.

View File

@ -381,7 +381,7 @@ SECTIONS
/* texture tables and DLs, set as segment 0x02 */
BEGIN_SEG(data_segment2, 0x02000000)
{
BUILD_DIR/data/data_segment2.o(.data);
BUILD_DIR/src/textures.inc.o(.data);
BUILD_DIR/src/data_segment2.inc.o(.data);
}
END_SEG(data_segment2)

View File

@ -10,4 +10,4 @@ fi
#echo "Replace $1 with $2?"
#read
grep -rl "$1" asm/**/*.s data/*.s src/*.c src/os/*.{c,h} undefined_syms.txt | xargs sed -i "s/\b$1\b/$2/g"
grep -rl "$1" asm/**/*.s data/*.s src/*.c src/*.h src/os/*.{c,h} undefined_syms.txt | xargs sed -i "s/\b$1\b/$2/g"

View File

@ -3942,36 +3942,38 @@ void func_80099110(void) {
gNumD_8018E118Entries = 0;
}
void *segmented_to_virtual(segment_address_t arg0) {
return gSegmentTable[arg0 >> 0x18] + (arg0 & 0xFFFFFF) + 0x80000000;
void *segmented_to_virtual(void *arg0) {
return gSegmentTable[(uintptr_t)arg0 >> 0x18] + ((uintptr_t)arg0 & 0xFFFFFF) + 0x80000000;
}
void *segmented_to_virtual_dupe(segment_address_t arg0) {
return gSegmentTable[arg0 >> 0x18] + (arg0 & 0xFFFFFF) + 0x80000000;
void *segmented_to_virtual_dupe(void *arg0) {
return gSegmentTable[(uintptr_t)arg0 >> 0x18] + ((uintptr_t)arg0 & 0xFFFFFF) + 0x80000000;
}
#ifdef MIPS_TO_C
//generated by mips_to_c commit 5bd751fca3befef73d6a2e20d84a88cc918a77fe
? dma_copy_base_729a30(u32, s32, s32); /* extern */
//generated by mips_to_c commit 0ca3d5f5fa5e3d957908269ac1535e7d4f12bce9
? dma_copy_base_729a30(u64 *, s32, s32); /* extern */
? mio0decode(s32, s32); /* extern */
extern s32 D_8018D9B0;
extern s32 D_8018D9B4;
void func_80099184(u32 arg0) {
Mk64_Texture *temp_v0;
void func_80099184(MkTexture *arg0) {
MkTexture *temp_v0;
s32 temp_t3;
s32 temp_t6;
s32 temp_v0_2;
s32 temp_v1;
u16 temp_v0_3;
u32 temp_a0;
u64 *temp_a0;
s32 phi_v0;
Mk64_Texture *phi_s1;
MkTexture *phi_s1;
s32 phi_a1;
s32 phi_a1_2;
s32 phi_a1_3;
temp_v0 = segmented_to_virtual(arg0);
phi_s1 = temp_v0;
if (temp_v0->segmentAddress != 0) {
if (temp_v0->textureData != 0) {
do {
temp_v1 = gNumD_8018E118Entries;
phi_v0 = 0;
@ -3980,14 +3982,14 @@ void func_80099184(u32 arg0) {
loop_4:
temp_v0_2 = phi_v0 + 1;
phi_v0 = temp_v0_2;
if (D_8018E118[phi_v0].textureData == phi_s1->segmentAddress) {
if (D_8018E118[phi_v0].textureData == phi_s1->textureData) {
phi_a1 = 1;
} else if (temp_v0_2 < temp_v1) {
goto loop_4;
}
}
if (phi_a1 == 0) {
temp_a0 = phi_s1->segmentAddress;
temp_a0 = phi_s1->textureData;
if (phi_s1->type == 3) {
temp_v0_3 = phi_s1->size;
phi_a1_2 = 0x1000;
@ -4003,7 +4005,7 @@ loop_4:
} else {
dma_copy_base_729a30(temp_a0, phi_s1->height * phi_s1->width * 2, (gD_8018E118TotalSize * 2) + D_8018D9B0);
}
D_8018E118[gNumD_8018E118Entries].textureData = phi_s1->segmentAddress;
D_8018E118[gNumD_8018E118Entries].textureData = phi_s1->textureData;
D_8018E118[gNumD_8018E118Entries].offset = gD_8018E118TotalSize;
gNumD_8018E118Entries += 1;
temp_t3 = gD_8018E118TotalSize + (phi_s1->height * phi_s1->width);
@ -4031,32 +4033,32 @@ GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009969C.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit 5bd751fca3befef73d6a2e20d84a88cc918a77fe
? dma_copy_base_729a30(u32, s32, s32); /* extern */
? dma_copy_base_7fa3c0(u32, s32, s32); /* extern */
//generated by mips_to_c commit 0ca3d5f5fa5e3d957908269ac1535e7d4f12bce9
? dma_copy_base_729a30(u64 *, s32, s32); /* extern */
? dma_copy_base_7fa3c0(u64 *, s32, s32); /* extern */
? mio0decode(s32, s32); /* extern */
? tkmk00decode(s32, s32, s32, ?); /* extern */
extern s32 D_8018D9B0;
extern s32 D_8018D9B4;
extern s32 D_8018D9B8;
void func_800996BC(u32 arg0, s32 arg1) {
Mk64_Texture *temp_v0;
void func_800996BC(MkTexture *arg0, s32 arg1) {
MkTexture *temp_v0;
s32 temp_t0;
s32 temp_t1;
s32 temp_v0_2;
s32 temp_v1;
u16 temp_v0_3;
s32 phi_v0;
Mk64_Texture *phi_s0;
MkTexture *phi_s0;
s32 phi_a1;
s32 phi_a1_2;
s32 phi_a1_3;
? phi_v0_2;
temp_v0 = segmented_to_virtual();
temp_v0 = segmented_to_virtual(arg0);
phi_s0 = temp_v0;
if (temp_v0->segmentAddress != 0) {
if (temp_v0->textureData != 0) {
do {
temp_v1 = gNumD_8018E118Entries;
phi_v0 = 0;
@ -4065,7 +4067,7 @@ void func_800996BC(u32 arg0, s32 arg1) {
loop_4:
temp_v0_2 = phi_v0 + 1;
phi_v0 = temp_v0_2;
if (D_8018E118[phi_v0].textureData == phi_s0->segmentAddress) {
if (D_8018E118[phi_v0].textureData == phi_s0->textureData) {
phi_a1 = 1;
} else if (temp_v0_2 < temp_v1) {
goto loop_4;
@ -4084,11 +4086,11 @@ loop_4:
switch (arg1) { /* irregular */
case -1:
case 1:
dma_copy_base_729a30(phi_s0->segmentAddress, phi_a1_3, D_8018D9B4);
dma_copy_base_729a30(phi_s0->textureData, phi_a1_3, D_8018D9B4);
break;
case 0:
case 2:
dma_copy_base_7fa3c0(phi_s0->segmentAddress, phi_a1_3, D_8018D9B4);
dma_copy_base_7fa3c0(phi_s0->textureData, phi_a1_3, D_8018D9B4);
break;
}
switch (arg1) { /* switch 1; irregular */
@ -4105,7 +4107,7 @@ loop_4:
tkmk00decode(D_8018D9B4, D_8018D9B8, (gD_8018E118TotalSize * 2) + D_8018D9B0, phi_v0_2);
break;
}
D_8018E118[gNumD_8018E118Entries].textureData = phi_s0->segmentAddress;
D_8018E118[gNumD_8018E118Entries].textureData = phi_s0->textureData;
D_8018E118[gNumD_8018E118Entries].offset = gD_8018E118TotalSize;
gNumD_8018E118Entries += 1;
temp_t0 = gD_8018E118TotalSize + (phi_s0->height * phi_s0->width);
@ -4495,22 +4497,22 @@ GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A344.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit 5bd751fca3befef73d6a2e20d84a88cc918a77fe
? func_8009969C(u32, s32, Mk64_Animation_Part *); /* extern */
//generated by mips_to_c commit 0ca3d5f5fa5e3d957908269ac1535e7d4f12bce9
? func_8009969C(MkTexture *, s32, MkAnimation *); /* extern */
s32 func_8009A374(Mk64_Animation_Part *arg0) {
s32 func_8009A374(MkAnimation *arg0) {
s32 sp24;
struct_8018DEE0_entry *sp1C;
Mk64_Animation_Part *temp_a2;
Mk64_Animation_Part *temp_v0;
MkAnimation *temp_a2;
MkAnimation *temp_v0;
MkTexture *temp_a0;
s32 temp_a1;
struct_8018DEE0_entry *temp_v1;
struct_8018DEE0_entry *temp_v1_2;
u32 temp_a0;
s32 phi_a1;
struct_8018DEE0_entry *phi_v1;
s32 phi_a1_2;
Mk64_Animation_Part *phi_a2;
MkAnimation *phi_a2;
temp_v0 = segmented_to_virtual_dupe(arg0);
temp_a2 = temp_v0;
@ -4536,16 +4538,16 @@ loop_3:
}
block_5:
temp_v1_2 = &D_8018DEE0[phi_a1_2];
temp_v1_2->texutreSequence = temp_v0;
temp_v1_2->textureSequence = temp_v0;
temp_v1_2->sequenceIndex = -1;
temp_v1_2->frameCountDown = 0;
temp_v1_2->visible = 0x80000000;
temp_v1_2->D_8018E118_index = gNumD_8018E118Entries;
if (temp_v0->texture != 0) {
if (temp_v0->mk64Texture != 0) {
arg0 = temp_a2;
sp24 = phi_a1_2;
sp1C = temp_v1_2;
func_8009969C(temp_a2->texture, phi_a1_2, temp_a2);
func_8009969C(temp_a2->mk64Texture, phi_a1_2, temp_a2);
phi_a2 = arg0;
}
temp_a0 = phi_a2->unk8;
@ -4556,7 +4558,7 @@ block_5:
} else {
sp24 = phi_a1_2;
sp1C = &D_8018DEE0[phi_a1_2];
func_8009969C(phi_a2->texture, phi_a1_2, phi_a2);
func_8009969C(phi_a2->mk64Texture, phi_a1_2, phi_a2);
}
D_8018DEE0[phi_a1_2].unk14 = 0;
return sp24;
@ -4566,18 +4568,18 @@ GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A374.s")
#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit 5bd751fca3befef73d6a2e20d84a88cc918a77fe
? func_80099958(u32, s32, ?, s32); /* extern */
//generated by mips_to_c commit 0ca3d5f5fa5e3d957908269ac1535e7d4f12bce9
? func_80099958(MkTexture *, s32, ?, s32); /* extern */
s32 func_8009A478(Mk64_Animation_Part *arg0, s32 arg1) {
s32 func_8009A478(MkAnimation *arg0, s32 arg1) {
s32 sp2C;
struct_8018DEE0_entry *sp24;
Mk64_Animation_Part *temp_s0;
Mk64_Animation_Part *temp_v0;
MkAnimation *temp_s0;
MkAnimation *temp_v0;
MkTexture *temp_a0;
s32 temp_a3;
struct_8018DEE0_entry *temp_v1;
struct_8018DEE0_entry *temp_v1_2;
u32 temp_a0;
s32 phi_a3;
struct_8018DEE0_entry *phi_v1;
s32 phi_a3_2;
@ -4605,15 +4607,15 @@ loop_3:
}
block_5:
temp_v1_2 = &D_8018DEE0[phi_a3_2];
temp_v1_2->texutreSequence = temp_v0;
temp_v1_2->textureSequence = temp_v0;
temp_v1_2->sequenceIndex = -1;
temp_v1_2->frameCountDown = 0;
temp_v1_2->visible = 0x80000000;
temp_v1_2->D_8018E118_index = gNumD_8018E118Entries;
if (temp_v0->texture != 0) {
if (temp_v0->mk64Texture != 0) {
sp2C = phi_a3_2;
sp24 = temp_v1_2;
func_80099958(temp_s0->texture, arg1, 0, phi_a3_2);
func_80099958(temp_s0->mk64Texture, arg1, 0, phi_a3_2);
}
temp_a0 = temp_s0->unk8;
if (temp_a0 != 0) {
@ -4623,7 +4625,7 @@ block_5:
} else {
sp2C = phi_a3_2;
sp24 = &D_8018DEE0[phi_a3_2];
func_80099958(temp_s0->texture, arg1, 1, phi_a3_2);
func_80099958(temp_s0->mk64Texture, arg1, 1, phi_a3_2);
}
D_8018DEE0[phi_a3_2].unk14 = 0;
return sp2C;
@ -4633,13 +4635,13 @@ GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A478.s")
#endif
#ifdef NON_MATCHING
void func_80099A94(Mk64_Texture *, s32); /* extern */
void func_80099A94(MkTexture *, s32); /* extern */
// Non-matching due to the argument registers to an addu command being swapped.
void func_8009A594(s32 arg0, s32 arg1, segment_address_t arg2) {
Mk64_Animation temp_v0;
MkAnimation *temp_v0;
struct_8018DEE0_entry *temp_s0;
Mk64_Texture *temp_v0_2;
MkTexture *temp_v0_2;
s32 thing = arg1;
temp_v0 = segmented_to_virtual_dupe(arg2);
@ -4663,10 +4665,10 @@ GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A594.s")
#ifdef NON_MATCHING
// Non-matching due to the argument registers to an addu command being swapped.
// Also some stack mangement around the segmented_to_virtual call is wrong
extern void func_80099E60(Mk64_Texture *, s32, s32);
extern void func_80099E60(MkTexture *, s32, s32);
void func_8009A640(s32 arg0, s32 arg1, s32 arg2, segment_address_t arg3) {
Mk64_Animation temp_v0;
Mk64_Texture *temp_a0;
MkAnimation *temp_v0;
MkTexture *temp_a0;
s32 thing = arg1;
temp_v0 = segmented_to_virtual_dupe(arg3);
@ -4722,14 +4724,14 @@ void func_8009A7EC(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) {
#ifdef MIPS_TO_C
//generated by mips_to_c commit 0ca3d5f5fa5e3d957908269ac1535e7d4f12bce9
void func_8009A878(struct_8018DEE0_entry *arg0) {
Mk64_Animation_Part *temp_v0;
Mk64_Animation_Part *temp_v1;
Mk64_Texture *temp_v0_2;
MkTexture *func_8009A878(struct_8018DEE0_entry *arg0) {
MkAnimation *temp_v0;
MkAnimation *temp_v1;
MkTexture *temp_v0_2;
s32 temp_t1;
s32 temp_t3;
s32 temp_t8;
Mk64_Animation_Part *phi_v0;
MkAnimation *phi_v0;
temp_v1 = arg0->textureSequence;
if (arg0->sequenceIndex < 0) {
@ -4758,6 +4760,7 @@ void func_8009A878(struct_8018DEE0_entry *arg0) {
arg0->unk14 = 1;
}
}
return arg0->textureSequence[arg0->sequenceIndex].mk64Texture;
}
#else
GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A878.s")
@ -4765,15 +4768,15 @@ GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A878.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 0ca3d5f5fa5e3d957908269ac1535e7d4f12bce9
void func_8009A944(struct_8018DEE0_entry *arg0, s32 arg1) {
Mk64_Animation_Part *temp_v0;
Mk64_Animation_Part *temp_v1;
Mk64_Texture *temp_a0;
MkTexture *func_8009A944(struct_8018DEE0_entry *arg0, s32 arg1) {
MkAnimation *temp_v0;
MkAnimation *temp_v1;
MkTexture *temp_a0;
s32 temp_a2;
s32 temp_t1;
s32 temp_t3;
s32 temp_t8;
Mk64_Animation_Part *phi_v0;
MkAnimation *phi_v0;
temp_v1 = arg0->textureSequence;
if (arg0->sequenceIndex < 0) {
@ -4799,6 +4802,7 @@ void func_8009A944(struct_8018DEE0_entry *arg0, s32 arg1) {
arg0->unk14 = temp_a2;
func_80099E60(temp_a0, arg1, temp_a2);
}
return *(arg0->textureSequence + (arg0->sequenceIndex * 8));
}
#else
GLOBAL_ASM("asm/non_matchings/code_80091750/func_8009A944.s")

View File

@ -2,6 +2,7 @@
#define CODE_80091750_H
#include "common_structs.h"
#include "textures.h"
#include "main.h"
/* Function Prototypes */
@ -53,15 +54,15 @@ Gfx *draw_box(Gfx*, s32, s32, s32, s32, s32, s32, s32, s32);
Gfx *func_80098FC8(Gfx*, s32, s32, s32, s32);
void func_80099110();
void func_80099184(s32);
void *segmented_to_virtual(segment_address_t);
void *segmented_to_virtual_dupe(segment_address_t);
Gfx *func_8009C204(Gfx*, Mk64_Texture*, s32, s32, s32);
void *segmented_to_virtual(void*);
void *segmented_to_virtual_dupe(void*);
Gfx *func_8009C204(Gfx*, MkTexture*, s32, s32, s32);
void func_8009CA2C();
void func_8009CA6C(s32);
void func_80099A94(Mk64_Texture *, s32);
void func_80099A94(MkTexture *, s32);
void func_80099AEC();
void func_80099E54();
void func_80099E60(Mk64_Texture *, s32, s32);
void func_80099E60(MkTexture *, s32, s32);
void func_80099EC4();
void func_80099A70();
void func_8009A594(s32, s32, segment_address_t);
@ -70,7 +71,7 @@ void func_8009A76C(s32, s32, s32, s32);
void func_8009A7EC(s32, s32, s32, s32, s32);
void func_8009A878(struct_8018DEE0_entry*);
void func_8009A944(struct_8018DEE0_entry*, s32);
Gfx *func_8009BA74(Gfx *, Mk64_Texture*, s32, s32);
Gfx *func_8009BA74(Gfx *, MkTexture*, s32, s32);
Gfx *func_8009BEF0(Gfx*, s32, f32, f32, s32, f32,f32);
Gfx *func_8009C434(Gfx*, struct_8018DEE0_entry*, s32, s32, s32);
Gfx *func_8009C708(Gfx*, struct_8018DEE0_entry *, s32, s32, s32, s32);
@ -130,11 +131,6 @@ void func_80057CE4();
/* This is where I'd put my static data, if I had any */
extern Mk64_Texture D_0200157C;
extern Mk64_Texture D_02001874;
extern Mk64_Texture D_02001FA4;
extern Mk64_Texture D_02004A0C;
extern Gfx D_02007650[];
extern Gfx D_020076B0[];
extern Gfx D_020077A8[];
@ -170,11 +166,11 @@ extern char *D_800E7860[2];
extern char *D_800E7A88[4];
extern char *D_800E7A98;
extern char *D_800E7A9C[2];
extern Mk64_Texture *D_800E7D74[0x14];
extern Mk64_Texture *D_800E7DC4[0x17];
extern Mk64_Animation_Part *D_800E7E34[0x14];
extern MkTexture *D_800E7D74[0x14];
extern MkTexture *D_800E7DC4[0x17];
extern MkAnimation *D_800E7E34[0x14];
extern s32 gGlyphTextureLUT[]; // D_800E7E84
extern Mk64_Texture_Group *D_800E82B4[5];
extern MkTexture *D_800E82B4[5];
extern f32 D_800E8530;
extern f32 D_800E8534;
extern s8 D_800E86D0[20];

1353
src/textures.h Normal file

File diff suppressed because it is too large Load Diff

3997
src/textures.inc.c Normal file

File diff suppressed because it is too large Load Diff