Skip to content

Commit

Permalink
match func_80099AEC and fix some warnings (#699)
Browse files Browse the repository at this point in the history
* match func_80099AEC and fix some warnings
  • Loading branch information
sonicdcer authored Jan 24, 2025
1 parent 731b24e commit 8094505
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 130 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ CC_CHECK ?= gcc
CC_CHECK_CFLAGS := -fsyntax-only -fsigned-char $(CC_CFLAGS) $(TARGET_CFLAGS) -std=gnu90 -Wall -Wempty-body -Wextra -Wno-format-security -Wno-main -DNON_MATCHING -DAVOID_UB $(DEF_INC_CFLAGS)

# C compiler options
HIDE_WARNINGS := -woff 838,649
HIDE_WARNINGS := -woff 838,649,807
CFLAGS = -G 0 $(OPT_FLAGS) $(TARGET_CFLAGS) $(MIPSISET) $(DEF_INC_CFLAGS)
ifeq ($(COMPILER),gcc)
CFLAGS += -mno-shared -march=vr4300 -mfix4300 -mabi=32 -mhard-float -mdivide-breaks -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-PIC -mno-abicalls -fno-strict-aliasing -fno-inline-functions -ffreestanding -fwrapv -Wall -Wextra
Expand Down
4 changes: 2 additions & 2 deletions include/spline.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This stuff is all about the b-splines used objects like Lakitu and the Boos on B
For splines used during the award ceremony and credits, see src/ending/ceremony_and_credits.h
*/

typedef struct {
typedef struct SplineControlPoint {
/* 0x0 */ Vec3s pos;
// Don't really know what to call this member.
// It somehow controls the speed of travel along a segment of the spline but I don't really get how it works
Expand All @@ -28,7 +28,7 @@ typedef struct {
// WARNING!!!
// You really, really shouldn't use this type for actual spline data. This is intended as a generic SplineData
// type. I would use a union, but that would cause significant ugliness elsewhere in the codebase
typedef struct {
typedef struct SplineData {
// This name is a little misleading
// The control point arrays have more control points in them than this number indicates. Not sure why though.
s16 numControlPoints;
Expand Down
88 changes: 44 additions & 44 deletions src/audio/external.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/audio/external.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ extern u16 D_800EA1C4;
// a sound source, its usage makes it look like a 0'd Vec3f for general usage
extern Vec3f D_800EA1C8; // = {0.0f, 0.0f, 0.0f}
extern f32 D_800EA1D4;
extern u8 D_800EA1DC; // = 0;
extern s8 D_800EA1DC; // = 0;
extern u8 D_800EA1E4;
extern u8 D_800EA1E8;
extern u8 D_800EA1EC;
Expand Down
2 changes: 1 addition & 1 deletion src/code_8006E9C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void func_8006EF60(void) {
s16 huh;
u8* wut;

wut = gMenuCompressedBuffer + 0xFFFF0000;
wut = (u8*) &gMenuCompressedBuffer[0x3FFFC000];
// clang-format off
// God forgive me for my sins...
huh = 0x14; if (0) {} for (i = 0; i < huh; i++) { D_8018D248[i] = dma_copy_base_misc_textures(gCourseOutlineTextures[i], wut, D_800E5520[i], D_800E5520[i]); wut += D_800E5520[i]; }
Expand Down
6 changes: 1 addition & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@
#include "crash_screen.h"
#include "buffers/gfx_output_buffer.h"

// Declarations (not in this file)
void func_80091B78(void);

void audio_init();

void audio_init(void);
void create_debug_thread(void);
void start_debug_thread(void);

struct SPTask* create_next_audio_frame_task(void);

struct VblankHandler* gVblankHandler1 = NULL;
Expand Down
146 changes: 74 additions & 72 deletions src/menu_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
void guMtxCatL(Mtx* m, Mtx* n, Mtx* res);

u16* gMenuTextureBuffer;
u8* gMenuCompressedBuffer;
u32* gMenuCompressedBuffer;
u8* sTKMK00_LowResBuffer;
u8* sGPPointsCopy;
void* gSomeDLBuffer;
Expand Down Expand Up @@ -1251,7 +1251,7 @@ void func_80091B78(void) {
gNextFreeMemoryAddress = gFreeMemoryResetAnchor;
// Hypothetically, this should be a ptr... But only hypothetically.
gMenuTextureBuffer = get_next_available_memory_addr(0x000900B0);
gMenuCompressedBuffer = (u8*) get_next_available_memory_addr(0x0000CE00);
gMenuCompressedBuffer = get_next_available_memory_addr(0x0000CE00);
sTKMK00_LowResBuffer = (u8*) get_next_available_memory_addr(SCREEN_WIDTH * SCREEN_HEIGHT);
gSomeDLBuffer = (struct_8018EE10_entry*) get_next_available_memory_addr(0x00001000);
func_800AF9B0();
Expand Down Expand Up @@ -1348,7 +1348,7 @@ void func_80091FA4(void) {
s32 i;

//! @todo These sizes need to be sizeof() for shiftability if possible
gMenuCompressedBuffer = (u8*) get_next_available_memory_addr(0x00002800);
gMenuCompressedBuffer = get_next_available_memory_addr(0x00002800);
gMenuTextureBuffer = (u16*) get_next_available_memory_addr(0x000124F8);
sTKMK00_LowResBuffer = (u8*) get_next_available_memory_addr(0x00001000);
sGPPointsCopy = get_next_available_memory_addr(4);
Expand Down Expand Up @@ -3441,7 +3441,7 @@ void load_menu_img(MenuTexture* addr) {
size = ((size / 8) * 8) + 8;
}
dma_copy_mio0_segment(texAddr->textureData, size, gMenuCompressedBuffer);
mio0decode(gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex]);
mio0decode((u8*) gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex]);
} else {
dma_copy_mio0_segment(texAddr->textureData, (texAddr->height * texAddr->width) * 2,
&gMenuTextureBuffer[sMenuTextureBufferIndex]);
Expand Down Expand Up @@ -3505,7 +3505,7 @@ void func_8009952C(MenuTexture* addr) {

if (imgLoaded == false) {
dma_copy_mio0_segment(texAddr->textureData, 0x00008000U, gMenuCompressedBuffer);
mio0decode(gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex]);
mio0decode((u8*) gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex]);
texMap[sMenuTextureEntries].textureData = texAddr->textureData;
texMap[sMenuTextureEntries].offset = sMenuTextureBufferIndex;
sMenuTextureBufferIndex += texAddr->height * texAddr->width;
Expand Down Expand Up @@ -3561,7 +3561,7 @@ void load_menu_img_comp_type(MenuTexture* addr, s32 compType) {
switch (compType) {
case LOAD_MENU_IMG_MIO0_ONCE:
case LOAD_MENU_IMG_MIO0_FORCE:
mio0decode(gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex]);
mio0decode((u8*) gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex]);
break;
case LOAD_MENU_IMG_TKMK00_ONCE:
case LOAD_MENU_IMG_TKMK00_FORCE:
Expand All @@ -3572,7 +3572,7 @@ void load_menu_img_comp_type(MenuTexture* addr, s32 compType) {
}
if (1) {}
tkmk00decode(gMenuCompressedBuffer, sTKMK00_LowResBuffer,
(u8*) &gMenuTextureBuffer[sMenuTextureBufferIndex], clearBit);
&gMenuTextureBuffer[sMenuTextureBufferIndex], clearBit);
break;
}

Expand Down Expand Up @@ -3602,7 +3602,7 @@ void func_80099958(MenuTexture* addr, s32 arg1, s32 arg2) {
size = ((size / 8) * 8) + 8;
}
dma_copy_mio0_segment(texAddr->textureData, size, gMenuCompressedBuffer);
mio0decode(gMenuCompressedBuffer, D_802BFB80.arraySize4[arg2][arg1 / 2][(arg1 % 2) + 2].pixel_index_array);
mio0decode((u8*) gMenuCompressedBuffer, (u8*) D_802BFB80.arraySize4[arg2][arg1 / 2][(arg1 % 2) + 2].pixel_index_array);
texAddr++;
}
}
Expand All @@ -3625,101 +3625,103 @@ void func_80099A94(MenuTexture* arg0, s32 arg1) {
var_v1->texNum = arg1;
}

#ifdef NON_MATCHING
// https://decomp.me/scratch/rxEoi
// Something's up with the handling of `_textures_0aSegmentRomStart`, I don't know how to fix it
void func_80099AEC(void) {
s32 some_var;
s8 texEnd;
s32 size;
UNUSED s32 stackPadding0;
UNUSED s32 stackPadding1;
s32 texSize;
struct_8018E060_entry* var_s1;
TextureMap* entry;
MenuTexture* texPtr;
OSIoMesg mb;
OSMesg msg;
UNUSED u8* test;
OSMesg sp64;
s32 cacheSize;
s32 bufSize;
MenuTexture* texAddr;
struct_8018E060_entry* var_s1;

if (gGamestate == RACING) {
bufSize = 0x00000500;
bufSize = 0x500;
} else {
bufSize = 0x00001000;
bufSize = 0x1000;
}

texEnd = 0;
var_s1 = D_8018E060;
texAddr = var_s1->texture;
entry = &sMenuTextureMap[0];
var_s1 = &D_8018E060[0];
texPtr = var_s1->texture;

if (texAddr == NULL)
if (texPtr == NULL) {
return;
}

texSize = texAddr->size;
if (texSize != 0) {
size = texSize;
if (texPtr->size) {
cacheSize = texPtr->size;
} else {
size = 0x1400;
cacheSize = 0x1400;
}
if (size % 8) {
size = ((size / 8) * 8) + 8;
if (cacheSize % 8) {
cacheSize = ((cacheSize / 8) * 8) + 8;
}
osInvalDCache(gMenuCompressedBuffer, size);
osPiStartDma(&mb, 0, 0, (uintptr_t) &_textures_0aSegmentRomStart[SEGMENT_OFFSET(texAddr->textureData)],
gMenuCompressedBuffer, size, &gDmaMesgQueue);
osRecvMesg(&gDmaMesgQueue, &msg, 1);

osInvalDCache(gMenuCompressedBuffer, cacheSize);
osPiStartDma(&mb, 0, 0, (uintptr_t) _textures_0aSegmentRomStart + SEGMENT_OFFSET(texPtr->textureData),
gMenuCompressedBuffer, cacheSize, &gDmaMesgQueue);
osRecvMesg(&gDmaMesgQueue, &sp64, 1);

while (1) {
if ((var_s1 + 1)->texture == NULL) {
texEnd += 1;
} else {
texAddr = (var_s1 + 1)->texture;
texSize = (var_s1 + 1)->texture->size;
if (texSize != 0) {
size = texSize;
texPtr = (var_s1 + 1)->texture;
if (texPtr->size) {
cacheSize = texPtr->size;
} else {
size = 0x1400;
cacheSize = 0x1400;
}
if (size % 8) {
size = ((size / 8) * 8) + 8;
if (cacheSize % 8) {
cacheSize = ((cacheSize / 8) * 8) + 8;
}
osInvalDCache(gMenuCompressedBuffer + bufSize * 4, size);
osPiStartDma(&mb, 0, 0, (uintptr_t) &_textures_0aSegmentRomStart[SEGMENT_OFFSET(texAddr->textureData)],
gMenuCompressedBuffer + bufSize * 4, size, &gDmaMesgQueue);
osInvalDCache(&gMenuCompressedBuffer[bufSize], cacheSize);
osPiStartDma(&mb, 0, 0, (uintptr_t) _textures_0aSegmentRomStart + SEGMENT_OFFSET(texPtr->textureData),
&gMenuCompressedBuffer[bufSize], cacheSize, &gDmaMesgQueue);
}
mio0decode(gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[sMenuTextureMap[var_s1->texNum].offset]);

some_var = (entry + var_s1->texNum)->offset;

mio0decode((u8*) gMenuCompressedBuffer, (u8*) &gMenuTextureBuffer[some_var]);

var_s1->texture = NULL;
var_s1++;
if (texEnd != 0)
if (texEnd) {
break;
osRecvMesg(&gDmaMesgQueue, &msg, 1);
}

osRecvMesg(&gDmaMesgQueue, &sp64, 1);

if ((var_s1 + 1)->texture == NULL) {
texEnd += 1;
} else {
texAddr = (var_s1 + 1)->texture;
texSize = (var_s1 + 1)->texture->size;
if (texSize != 0) {
size = texSize;
texPtr = (var_s1 + 1)->texture;
if (texPtr->size) {
cacheSize = texPtr->size;
} else {
size = 0x1400;
cacheSize = 0x1400;
}
if (size % 8) {
size = ((size / 8) * 8) + 8;
if (cacheSize % 8) {
cacheSize = ((cacheSize / 8) * 8) + 8;
}
osInvalDCache(gMenuCompressedBuffer, size);
osPiStartDma(&mb, 0, 0, (uintptr_t) &_textures_0aSegmentRomStart[SEGMENT_OFFSET(texAddr->textureData)],
gMenuCompressedBuffer, size, &gDmaMesgQueue);
osInvalDCache(gMenuCompressedBuffer, cacheSize);
osPiStartDma(&mb, 0, 0, (uintptr_t) _textures_0aSegmentRomStart + SEGMENT_OFFSET(texPtr->textureData),
gMenuCompressedBuffer, cacheSize, &gDmaMesgQueue);
}
mio0decode(gMenuCompressedBuffer + bufSize * 4,
(u8*) &gMenuTextureBuffer[sMenuTextureMap[var_s1->texNum].offset]);

some_var = (entry + var_s1->texNum)->offset;
mio0decode((u8*) &gMenuCompressedBuffer[bufSize], (u8*) &gMenuTextureBuffer[some_var]);
var_s1->texture = NULL;
var_s1++;
if (texEnd != 0)
if (texEnd) {
break;
osRecvMesg(&gDmaMesgQueue, &msg, 1);
}
osRecvMesg(&gDmaMesgQueue, &sp64, 1);
}
}
#else
GLOBAL_ASM("asm/non_matchings/menu_items/func_80099AEC.s")
#endif

void func_80099E54(void) {
D_8018E0E8[0].mk64Texture = NULL;
Expand Down Expand Up @@ -3794,8 +3796,8 @@ void func_80099EC4(void) {
osPiStartDma(&sp68, 0, 0, (uintptr_t) &_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)],
gMenuCompressedBuffer + 0x1400, var_s0, &gDmaMesgQueue);
}
mio0decode(gMenuCompressedBuffer,
D_802BFB80.arraySize4[var_s1->unk6][var_s1->unk4 / 2][(var_s1->unk4 % 2) + 2].pixel_index_array);
mio0decode((u8*) gMenuCompressedBuffer,
(u8*) D_802BFB80.arraySize4[var_s1->unk6][var_s1->unk4 / 2][(var_s1->unk4 % 2) + 2].pixel_index_array);
var_s1->mk64Texture = NULL;
var_s1++;
if (var_s4 != 0)
Expand All @@ -3818,8 +3820,8 @@ void func_80099EC4(void) {
osPiStartDma(&sp68, 0, 0, (uintptr_t) &_textures_0aSegmentRomStart[SEGMENT_OFFSET(temp_s2->textureData)],
gMenuCompressedBuffer, var_s0, &gDmaMesgQueue);
}
mio0decode(gMenuCompressedBuffer + 0x1400,
D_802BFB80.arraySize4[var_s1->unk6][var_s1->unk4 / 2][(var_s1->unk4 % 2) + 2].pixel_index_array);
mio0decode((u8*) gMenuCompressedBuffer + 0x1400,
(u8*) D_802BFB80.arraySize4[var_s1->unk6][var_s1->unk4 / 2][(var_s1->unk4 % 2) + 2].pixel_index_array);
var_s1->mk64Texture = NULL;
var_s1++;
if (var_s4 != 0)
Expand All @@ -3844,7 +3846,7 @@ void func_8009A238(MenuTexture* arg0, s32 arg1) {
var_a3 = ((var_a3 / 8) * 8) + 8;
}
dma_tkmk00_textures(sp24, var_a3, gMenuCompressedBuffer);
tkmk00decode(gMenuCompressedBuffer, sTKMK00_LowResBuffer, (u8*) &gMenuTextureBuffer[temp_v1], 1);
tkmk00decode(gMenuCompressedBuffer, sTKMK00_LowResBuffer, &gMenuTextureBuffer[temp_v1], 1);
sMenuTextureMap[arg1].textureData = sp24;
}

Expand Down Expand Up @@ -4640,7 +4642,7 @@ void func_8009CBE4(s32 arg0, s32 arg1, s32 arg2) {
color->green, color->blue, 0xFF - (D_8018E7D0[arg0] * 0xFF / D_8018E7B8[arg0]));

if ((arg1 == 0) && (D_8018E7D0[arg0] += 1, (D_8018E7D0[arg0] >= D_8018E7B8[arg0]))) {
if (gGamestate == 4) {
if (gGamestate == RACING) {
D_8018E7AC[arg0] = 6;
return;
}
Expand Down Expand Up @@ -4690,7 +4692,7 @@ void func_8009CE64(s32 arg0) {
gGotoMenu = 1;
gMenuSelection = 0x0000000B;
}
} else if (gGamestate == 4) {
} else if (gGamestate == RACING) {
if (D_8018E7AC[arg0] == 2) {
if (arg0 != 4) {
D_8018E7AC[arg0] = 5;
Expand Down Expand Up @@ -7582,7 +7584,7 @@ void render_lap_times(s32 recordType, s32 column, s32 row) {
char sp38[3];
MenuItem* temp_v0;
s32 sp30;
if (gGamestate == 4) {
if (gGamestate == RACING) {
sp30 = 0;
} else {
sp30 = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/menu_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void func_800AF740(MenuItem*);

// This really, really shouldn't be in this header file, but I don't know where else to put it
void rmonPrintf(const char*, ...);
void tkmk00decode(u8*, u8*, u8*, s32);
void tkmk00decode(u32*, u8*, u16*, s32);

/* File specific defines */

Expand All @@ -657,7 +657,7 @@ extern s32 D_800DDB24;
extern s16 gGetPlayerByCharacterId[];

extern u16* gMenuTextureBuffer;
extern u8* gMenuCompressedBuffer;
extern u32* gMenuCompressedBuffer;
extern u8* sTKMK00_LowResBuffer;
extern u8* sGPPointsCopy;
extern void* gSomeDLBuffer;
Expand Down
1 change: 1 addition & 0 deletions src/render_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,7 @@ void render_texture_tile_rgba32_block(s16 x, s16 y, u8* texture, u32 width, u32
gSPDisplayList(gDisplayListHead++, D_0D007EB8);
}
#else
void render_texture_tile_rgba32_block(s16 x, s16 y, u8* texture, u32 width, u32 height);
GLOBAL_ASM("asm/non_matchings/render_objects/render_texture_tile_rgba32_block.s")
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ s32 func_800B6178(s32 arg0) {
default:
return -1;
}
if (gGamestate == 4) {
if (gGamestate == RACING) {
func_800051C4();
}
temp_s3 = &D_8018EE10[arg0];
Expand All @@ -787,7 +787,7 @@ s32 func_800B6178(s32 arg0) {
0x00003C00, (u8*) D_800DC714);
if (var_v0 == 0) {
temp_s3->ghostDataSaved = 1;
if (gGamestate == 4) {
if (gGamestate == RACING) {
temp_s3->courseIndex = (gCupSelection * 4) + gCourseIndexInCup;
}
temp_s3->unk_00 = D_80162DFC;
Expand Down

0 comments on commit 8094505

Please sign in to comment.