diff --git a/.clang-tidy b/.clang-tidy index d1f01520b0..8a77d190b1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,2 +1,2 @@ -Checks: '-*,clang-analyzer-core.*,clang-analyzer-deadcode.*,readability-*,-readability-magic-numbers,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-clang-diagnostic-error' +Checks: '-*,clang-analyzer-core.*,clang-analyzer-deadcode.*,readability-*,-readability-magic-numbers,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-isolate-declaration,-clang-diagnostic-error' HeaderFilterRegex: '(src|include)\/.*\.h' diff --git a/Makefile b/Makefile index 95b28a0690..f3ff32cd8e 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ ifdef PM_HEADER_REBUILD H_FILES := $(foreach dir,$(INCLUDE_DIRS),$(wildcard $(dir)/*.h)) endif DATA_FILES := $(foreach dir,$(DATA_DIRS),$(wildcard $(dir)/*.bin)) -COMPRESSED_FILES := $(foreach dir,$(COMPRESSED_DIRS),$(wildcard $(dir)/*.yay0)) -MAP_FILES := $(foreach dir,$(MAP_DIRS),$(wildcard $(dir)/*.FS)) +COMPRESSED_FILES := $(foreach dir,$(COMPRESSED_DIRS),$(wildcard $(dir)/*.yay0)) +MAP_FILES := $(foreach dir,$(MAP_DIRS),$(wildcard $(dir)/*.FS)) BGM_FILES := $(foreach dir,$(BGM_DIRS),$(wildcard $(dir)/*.bgm)) # Object files @@ -54,10 +54,10 @@ OBJCOPY = $(CROSS)objcopy TARGET = papermario -CPPFLAGS = -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 +CPPFLAGS = -fno-builtin -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 ASFLAGS = -EB -march=vr4300 -mtune=vr4300 -Iinclude OLDASFLAGS= -EB -Iinclude -CFLAGS = -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 +CFLAGS = -fno-builtin -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 LDFLAGS = -T undefined_syms.txt -T $(LD_SCRIPT) -Map $(BUILD_DIR)/papermario.map --no-check-sections ######################## Targets ############################# diff --git a/include/common_structs.h b/include/common_structs.h index d12f2d7414..7900ed00fe 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -222,6 +222,11 @@ typedef struct StaticNpcSettings { /* 0x2A */ s16 unkFlags; } StaticNpcSettings; // size = 0x2C +typedef union ScriptBufferValue { + f32 f; + s32 s; +} ScriptBufferValue; + typedef struct ScriptInstance { /* 0x000 */ u8 state; /* 0x001 */ u8 currentArgc; @@ -247,9 +252,9 @@ typedef struct ScriptInstance { /* 0x0F0 */ s32 loopCounterTable[8]; /* 0x110 */ u8 switchBlockState[8]; /* 0x118 */ s32 switchBlockValue[8]; - /* 0x138 */ s32* buffer; - /* 0x13C */ UNK_PTR array; - /* 0x140 */ UNK_PTR flagArray; + /* 0x138 */ ScriptBufferValue* buffer; + /* 0x13C */ s32* array; + /* 0x140 */ s32* flagArray; /* 0x144 */ s32 uniqueID; /* 0x148 */ struct Enemy* ownerActorID; /* controller*, battle ID, trigger* */ /* 0x14C */ u32 ownerID; /* can be an npcID, a triggerID, a trigger ptr */ @@ -1268,8 +1273,8 @@ typedef struct TileDescriptor { } TileDescriptor; // size = 0x30 typedef struct BackgroundHeader { - /* 0x00 */ u32 raster; - /* 0x04 */ u32 palette; + /* 0x00 */ UNK_PTR raster; + /* 0x04 */ UNK_PTR palette; /* 0x08 */ u16 startX; /* 0x0A */ u16 startY; /* 0x0C */ u16 width; diff --git a/include/variables.h b/include/variables.h index d3602c9944..893888fe81 100644 --- a/include/variables.h +++ b/include/variables.h @@ -56,10 +56,10 @@ extern PrintContext* gCurrentPrintContext; extern PrintContext* D_802DB268; // Triggers -/* 0x80151334 */ extern s16 gTriggerCount; -/* 0x80159190 */ extern Trigger gTriggerList1[64]; -/* 0x80159290 */ extern Trigger gTriggerList2[64]; -/* 0x80159390 */ extern Trigger** gCurrentTriggerListPtr[64]; +extern s16 gTriggerCount; +extern Trigger* gTriggerList1[64]; +extern Trigger* gTriggerList2[64]; +extern Trigger** gCurrentTriggerListPtr[64]; extern u16 gMapTransitionAlpha; extern u16 D_800A0942; @@ -76,8 +76,5 @@ extern UNK_TYPE D_80147474; extern UNK_TYPE D_80147574; extern UNK_TYPE D_80109270; extern UNK_TYPE D_80108558; -extern u16 D_800A0940; -extern u16 D_800A0942; -extern s16 D_800A0944; #endif diff --git a/src/code_341d0_len_20d0.c b/src/code_341d0_len_20d0.c index 3f7e624218..87e02a201a 100644 --- a/src/code_341d0_len_20d0.c +++ b/src/code_341d0_len_20d0.c @@ -40,6 +40,6 @@ INCLUDE_ASM("code_341d0_len_20d0", get_current_map_header); INCLUDE_ASM("code_341d0_len_20d0", get_map_IDs_by_name); -INCLUDE_ASM("code_341d0_len_20d0", load_asset_by_name); +void* INCLUDE_ASM("code_341d0_len_20d0", load_asset_by_name, char* name, s32* decompressedSize); INCLUDE_ASM("code_341d0_len_20d0", get_asset_offset); diff --git a/src/code_80850_len_3060.c b/src/code_80850_len_3060.c index caa5d64198..75d76ba0e6 100644 --- a/src/code_80850_len_3060.c +++ b/src/code_80850_len_3060.c @@ -373,7 +373,6 @@ void show_coin_counter(void) { uiStatus->ignoreChanges = 1; D_8010CD10 = 1; } - return; } void hide_coin_counter(void) { diff --git a/src/code_dbd70_len_700.c b/src/code_dbd70_len_700.c index b03cb1c4f2..5ca62082c6 100644 --- a/src/code_dbd70_len_700.c +++ b/src/code_dbd70_len_700.c @@ -7,7 +7,6 @@ void default_trigger_function_handler(s32* arg0) { INCLUDE_ASM("code_dbd70_len_700", clear_trigger_data); -//INCLUDE_ASM("code_dbd70_len_700", init_trigger_list); void init_trigger_list(void) { if ((*gGameStatusPtr)->isBattle == 0) { *gCurrentTriggerListPtr = gTriggerList1; @@ -40,7 +39,6 @@ void delete_trigger(Trigger* toDelete) { INCLUDE_ASM("code_dbd70_len_700", is_trigger_bound); -//INCLUDE_ASM("code_dbd70_len_700", get_trigger_by_id); Trigger* get_trigger_by_id(s32 triggerID) { return (*gCurrentTriggerListPtr)[triggerID]; } diff --git a/src/code_e79b0_len_1920.c b/src/code_e79b0_len_1920.c index 8df4e5ca69..c412d6f728 100644 --- a/src/code_e79b0_len_1920.c +++ b/src/code_e79b0_len_1920.c @@ -243,8 +243,7 @@ s32 resume_all_group(s32 groupFlags) { } } - -void suspend_group_others(s32 script, s32 groupFlags) { +void suspend_group_others(ScriptInstance* script, s32 groupFlags) { s32 i; ScriptInstance* scriptContextPtr; @@ -256,7 +255,7 @@ void suspend_group_others(s32 script, s32 groupFlags) { } } -void resume_group_others(s32 script, s32 groupFlags) { +void resume_group_others(ScriptInstance* script, s32 groupFlags) { s32 i; ScriptInstance* scriptContextPtr; diff --git a/src/code_e92d0_len_5da0.c b/src/code_e92d0_len_5da0.c index 543723ce04..cc57a3e6ed 100644 --- a/src/code_e92d0_len_5da0.c +++ b/src/code_e92d0_len_5da0.c @@ -68,7 +68,6 @@ ApiStatus si_handle_if_AND(ScriptInstance* script) { return ApiStatus_DONE2; } -//INCLUDE_ASM("code_e92d0_len_5da0", si_handle_if_not_AND); ApiStatus si_handle_if_not_AND(ScriptInstance* script) { s32 var1; s32* ptrReadPos = script->ptrReadPos; @@ -197,20 +196,19 @@ INCLUDE_ASM("code_e92d0_len_5da0", si_handle_multiplyF); INCLUDE_ASM("code_e92d0_len_5da0", si_handle_divideF); ApiStatus si_handle_set_int_buffer_ptr(ScriptInstance* script) { - script->buffer = get_variable(script, *script->ptrReadPos); + script->buffer = (ScriptBufferValue*)get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } ApiStatus si_handle_set_float_buffer_ptr(ScriptInstance* script) { - script->buffer = get_variable(script, *script->ptrReadPos); + script->buffer = (ScriptBufferValue*)get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } ApiStatus si_handle_get_1_word(ScriptInstance* script) { - s32 ptrReadPos = *script->ptrReadPos; - s32 buffer = *script->buffer++; + s32 out = *script->ptrReadPos; - set_variable(script, ptrReadPos, buffer); + set_variable(script, out, (*script->buffer++).s); return ApiStatus_DONE2; } @@ -222,9 +220,10 @@ INCLUDE_ASM("code_e92d0_len_5da0", si_handle_get_4_word); ApiStatus si_handle_get_Nth_word(ScriptInstance* script) { Bytecode* ptrReadPos = script->ptrReadPos; - s32 curPtrReadPos = ptrReadPos[0]; + s32 out = ptrReadPos[0]; + s32 n = get_variable(script, ptrReadPos[1]); - set_variable(script, curPtrReadPos, script->buffer[get_variable(script, ptrReadPos[1])]); + set_variable(script, out, script->buffer[n].s); return ApiStatus_DONE2; } @@ -239,12 +238,12 @@ INCLUDE_ASM("code_e92d0_len_5da0", si_handle_get_4_float); INCLUDE_ASM("code_e92d0_len_5da0", si_handle_get_Nth_float); ApiStatus si_handle_set_array(ScriptInstance* script) { - script->array = get_variable(script, *script->ptrReadPos); + script->array = (s32*)get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } ApiStatus si_handle_set_flag_array(ScriptInstance* script) { - script->flagArray = get_variable(script, *script->ptrReadPos); + script->flagArray = (s32*)get_variable(script, *script->ptrReadPos); return ApiStatus_DONE2; } @@ -293,7 +292,7 @@ ApiStatus si_handle_exec_wait(ScriptInstance* script) { } ApiStatus si_handle_jump(ScriptInstance* script) { - script->ptrFirstLine = get_variable(script, *script->ptrReadPos); + script->ptrFirstLine = (Bytecode*)get_variable(script, *script->ptrReadPos); restart_script(script); return ApiStatus_DONE2; } @@ -387,7 +386,7 @@ ApiStatus func_802C6E14(ScriptInstance* script) { ApiStatus INCLUDE_ASM("code_e92d0_len_5da0", si_handle_print_debug_var); ApiStatus func_802C739C(ScriptInstance* script) { - script->ptrSavedPosition = *script->ptrReadPos; + script->ptrSavedPosition = (Bytecode*)*script->ptrReadPos; return ApiStatus_DONE2; } diff --git a/src/code_f2470_len_27f0.c b/src/code_f2470_len_27f0.c index 0f6e402e7b..24858f9194 100644 --- a/src/code_f2470_len_27f0.c +++ b/src/code_f2470_len_27f0.c @@ -28,7 +28,7 @@ ApiStatus GetNpcPointer(ScriptInstance* script, s32 isInitialCall) { NpcId npcID = get_variable(script, *ptrReadPos++); Bytecode varNPC = *ptrReadPos++; - set_variable(script, varNPC, get_npc_safe(npcID)); + set_variable(script, varNPC, (s32)get_npc_safe(npcID)); return ApiStatus_DONE2; } diff --git a/src/code_fa4c0_len_3bf0.c b/src/code_fa4c0_len_3bf0.c index 2995494b67..ca4c190c57 100644 --- a/src/code_fa4c0_len_3bf0.c +++ b/src/code_fa4c0_len_3bf0.c @@ -181,9 +181,9 @@ ApiStatus FindKeyItem(ScriptInstance* script, s32 isInitialCall) { ApiStatus AddItem(ScriptInstance* script, s32 isInitialCall) { Bytecode* ptrReadPos = script->ptrReadPos; s32 itemID = get_variable(script, *ptrReadPos++); - s32* ptrNextPos = (s32*) *ptrReadPos++; + Bytecode outItemIdx = *ptrReadPos++; - set_variable(script, ptrNextPos, add_item(itemID)); + set_variable(script, outItemIdx, add_item(itemID)); return ApiStatus_DONE2; } @@ -291,10 +291,10 @@ ApiStatus RemoveItemEntity(ScriptInstance* script, s32 isInitialCall) { ApiStatus AddBadge(ScriptInstance* script, s32 isInitialCall) { Bytecode* ptrReadPos = script->ptrReadPos; - s32 itemID = get_variable(script, *ptrReadPos++); - s32* ptrNextPos = (s32*) *ptrReadPos++; + s32 badgeID = get_variable(script, *ptrReadPos++); + Bytecode outBadgeIdx = *ptrReadPos++; - set_variable(script, ptrNextPos, add_badge(itemID)); + set_variable(script, outBadgeIdx, add_badge(badgeID)); return ApiStatus_DONE2; } diff --git a/src/os/code_3d2f0_len_10.c b/src/os/code_3d2f0_len_10.c index 74e91100d8..b2ae29f1e4 100644 --- a/src/os/code_3d2f0_len_10.c +++ b/src/os/code_3d2f0_len_10.c @@ -1,3 +1,3 @@ #include "common.h" -INCLUDE_API_ASM("os/code_3d2f0_len_10", sqrtf); +f32 INCLUDE_ASM("os/code_3d2f0_len_10", sqrtf, f32 value); diff --git a/src/os/code_4a1f0_len_170.c b/src/os/code_4a1f0_len_170.c index 2420933dc0..e7509593d6 100644 --- a/src/os/code_4a1f0_len_170.c +++ b/src/os/code_4a1f0_len_170.c @@ -1,3 +1,3 @@ #include "common.h" -INCLUDE_ASM("os/code_4a1f0_len_170", decode_yay0); +void INCLUDE_ASM("os/code_4a1f0_len_170", decode_yay0, void* src, void* dest);