From fbbbf83d2215bee44adef73c6104c628ae1bfd3b Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Wed, 19 Aug 2020 02:45:26 +0100 Subject: [PATCH] add NON_MATCHING --- src/code_6000.c | 9 ++++++--- src/code_80850_len_3060.c | 9 ++++++--- src/code_dbd70_len_700.c | 9 ++++++--- src/code_e79b0_len_1920.c | 29 ++++++++++++++++------------- src/code_f4c60_len_4300.c | 7 ++++--- src/code_fa4c0_len_3bf0.c | 16 +++++++++------- tools/coverage.py | 24 +++++++++++++++++++----- 7 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/code_6000.c b/src/code_6000.c index 2c9e2d3851..85ec0ca1ae 100644 --- a/src/code_6000.c +++ b/src/code_6000.c @@ -54,9 +54,12 @@ INCLUDE_ASM(code_6000, collision_heap_create); INCLUDE_ASM(code_6000, collision_heap_malloc); -INCLUDE_ASM(code_6000, collision_heap_free); -/*s32 collision_heap_free(s32 size) { +#ifdef NON_MATCHING +s32 collision_heap_free(s32 size) { s32 isBattle = (*gGameStatusPtr)->isBattle; return _heap_free((isBattle == 0) ? (&D_80268000) : (&D_803DA800), size); -}*/ +} +#else +INCLUDE_ASM(code_6000, collision_heap_free); +#endif diff --git a/src/code_80850_len_3060.c b/src/code_80850_len_3060.c index 3c2461b09d..47a9dbc6d9 100644 --- a/src/code_80850_len_3060.c +++ b/src/code_80850_len_3060.c @@ -716,10 +716,10 @@ void reset_status_menu(void) { func_801452B4(uiStatus->iconIndexC, uiStatus->iconIndexC); } +#ifdef NON_MATCHING // uses a jumptable, which we need .rodata support for. -s32 INCLUDE_ASM(code_80850_len_3060, is_ability_active, s32 arg0); // Somewhat close. Needs work. -/*s32 is_ability_active(s32 arg0) { +s32 is_ability_active(s32 arg0) { s32 iVar2; u32 uVar3; s32 iVar5; @@ -965,7 +965,10 @@ s32 INCLUDE_ASM(code_80850_len_3060, is_ability_active, s32 arg0); } return iVar7; } -}*/ +} +#else +s32 INCLUDE_ASM(code_80850_len_3060, is_ability_active, s32 arg0); +#endif s32 is_partner_ability_active(void) { return 0; diff --git a/src/code_dbd70_len_700.c b/src/code_dbd70_len_700.c index 2cccfd0d02..6e88c215f3 100644 --- a/src/code_dbd70_len_700.c +++ b/src/code_dbd70_len_700.c @@ -41,8 +41,8 @@ Trigger* get_trigger_by_id(s32 triggerID) { return (*gCurrentTriggerListPtr)[triggerID]; } -INCLUDE_ASM(code_dbd70_len_700, func_80145CE8); -/*s32 func_80145CE8(s32 arg0) { +#ifdef NON_MATCHING +s32 func_80145CE8(s32 arg0) { s32 i; s32 ret; @@ -60,4 +60,7 @@ INCLUDE_ASM(code_dbd70_len_700, func_80145CE8); } return ret; -}*/ +} +#else +INCLUDE_ASM(code_dbd70_len_700, func_80145CE8); +#endif diff --git a/src/code_e79b0_len_1920.c b/src/code_e79b0_len_1920.c index 85b517f52d..1f76a67f93 100644 --- a/src/code_e79b0_len_1920.c +++ b/src/code_e79b0_len_1920.c @@ -18,8 +18,7 @@ INCLUDE_ASM(code_e79b0_len_1920, start_child_script); INCLUDE_ASM(code_e79b0_len_1920, func_802C39F8); -INCLUDE_ASM(code_e79b0_len_1920, restart_script); -/* +#ifdef NON_MATCHING ScriptInstance* restart_script(ScriptInstance* script) { script->loopDepth = -1; script->switchDepth = -1; @@ -39,7 +38,9 @@ ScriptInstance* restart_script(ScriptInstance* script) { return script; } -*/ +#else +INCLUDE_ASM(code_e79b0_len_1920, restart_script); +#endif INCLUDE_ASM(code_e79b0_len_1920, update_scripts); @@ -104,22 +105,23 @@ void set_script_timescale(ScriptInstance* script, f32 timeScale) { script->timeScale = timeScale * gGlobalTimeSpace; } -INCLUDE_ASM(code_e79b0_len_1920, set_global_timespace); -/* +#ifdef NON_MATCHING // TODO: figure out why compiler/assembler isn't putting SWC1 in delay slot void set_global_timespace(f32 timeScale) { //gGlobalTimeSpace = timeScale; } -*/ +#else +INCLUDE_ASM(code_e79b0_len_1920, set_global_timespace); +#endif - -INCLUDE_ASM(code_e79b0_len_1920, get_global_timespace); -/* +#ifdef NON_MATCHING // TODO: figure out why compiler/assembler isn't putting LWC1 in delay slot f32 get_global_timespace(void) { //return gGlobalTimeSpace; } -*/ +#else +INCLUDE_ASM(code_e79b0_len_1920, get_global_timespace); +#endif void set_script_group(ScriptInstance* script, s8 groupFlags) { script->groupFlags = groupFlags; @@ -305,8 +307,7 @@ void set_script_flags(ScriptInstance* script, s32 flags) { } } -INCLUDE_ASM(code_e79b0_len_1920, clear_script_flags); -/* +#ifdef NON_MATCHING // TODO: Really close but some weirdness is going on void clear_script_flags(ScriptInstance* script, s32 flags) { int i; @@ -325,4 +326,6 @@ void clear_script_flags(ScriptInstance* script, s32 flags) { } } } -*/ +#else +INCLUDE_ASM(code_e79b0_len_1920, clear_script_flags); +#endif diff --git a/src/code_f4c60_len_4300.c b/src/code_f4c60_len_4300.c index 2c6e22fdde..b9a3441dbf 100644 --- a/src/code_f4c60_len_4300.c +++ b/src/code_f4c60_len_4300.c @@ -66,10 +66,9 @@ ApiStatus SetMessageString(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -INCLUDE_API_ASM(code_f4c60_len_4300, SetMessageValue); +#ifdef NON_MATCHING // TODO: Figure out why there's an extra NOP after this function // It's probably because of a file split issue -/* ApiStatus SetMessageValue(ScriptInstance* script, s32 initialCall) { Bytecode* ptrReadPos = script->ptrReadPos; Bytecode value = get_variable(script, *ptrReadPos++); @@ -78,7 +77,9 @@ ApiStatus SetMessageValue(ScriptInstance* script, s32 initialCall) { set_message_value(value, index); return ApiStatus_DONE2; } -*/ +#else +INCLUDE_API_ASM(code_f4c60_len_4300, SetMessageValue); +#endif INCLUDE_API_ASM(code_f4c60_len_4300, HidePlayerShadow); diff --git a/src/code_fa4c0_len_3bf0.c b/src/code_fa4c0_len_3bf0.c index fe1eb96348..5416ac46c5 100644 --- a/src/code_fa4c0_len_3bf0.c +++ b/src/code_fa4c0_len_3bf0.c @@ -335,8 +335,7 @@ ApiStatus AddStarPieces(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -INCLUDE_API_ASM(code_fa4c0_len_3bf0, GetItemPower); -/* +#ifdef NON_MATCHING // Close to working ApiStatus GetItemPower(ScriptInstance* script, s32 isInitialCall) { Bytecode* ptrReadPos = script->ptrReadPos; @@ -349,7 +348,9 @@ ApiStatus GetItemPower(ScriptInstance* script, s32 isInitialCall) { set_variable(script, ptrNextPos++, item->potencyB); return ApiStatus_DONE2; } -*/ +#else +INCLUDE_API_ASM(code_fa4c0_len_3bf0, GetItemPower); +#endif INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowGotItem); @@ -359,8 +360,7 @@ INCLUDE_ASM(code_fa4c0_len_3bf0, func_802D74C0); INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowEmote); -INCLUDE_API_ASM(code_fa4c0_len_3bf0, RemoveEffect); -/* +#ifdef NON_MATCHING // Works ApiStatus RemoveEffect(ScriptInstance* script, s32 isInitialCall) { Bytecode* ptrReadPos = script->ptrReadPos; @@ -398,8 +398,10 @@ ApiStatus func_802D7B74(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -// More functions still in RemoveEffect.s but the ones above are matching properly -*/ +// TODO: More functions still in RemoveEffect.s but the ones above are matching properly +#else +INCLUDE_API_ASM(code_fa4c0_len_3bf0, RemoveEffect); +#endif INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowSleepBubble); diff --git a/tools/coverage.py b/tools/coverage.py index 75dd019c14..f60730ed6a 100755 --- a/tools/coverage.py +++ b/tools/coverage.py @@ -28,16 +28,28 @@ c_func_pattern = re.compile( re.MULTILINE ) def funcs_in_c(text): - text = strip_c_comments(text) - return [match.group(1) for match in c_func_pattern.finditer(text)] + return (match.group(1) for match in c_func_pattern.finditer(text)) + +asm_func_pattern = re.compile( + r"INCLUDE_(?:API_)?ASM\([^,]+, ([^,)]+)", + re.MULTILINE +) +def include_asms_in_c(text): + return (match.group(1) for match in asm_func_pattern.finditer(text)) matched = [] +asm = [] for filename in C_FILES: with open(filename, "r") as file: - matched += funcs_in_c(file.read()) + text = strip_c_comments(file.read()) + matched.extend((m for m in funcs_in_c(text) if not m in matched)) + asm.extend((m for m in include_asms_in_c(text) if not m in asm)) non_matched = [path.splitext(path.basename(filename))[0] for filename in ASM_FILES] -matched_but_undeleted_asm = [f for f in matched if f in non_matched] + +partial_matched = [f for f in matched if f in asm] +matched = [f for f in matched if not f in partial_matched] +matched_but_undeleted_asm = [f for f in matched if f in non_matched and not f in partial_matched] if __name__ == "__main__": if "--help" in argv: @@ -46,7 +58,7 @@ if __name__ == "__main__": exit() total = len(matched) + len(non_matched) - print(f"{len(matched)}/{total} ({(len(matched) / total) * 100:.2f}%)") + print(f"{len(matched)}+{len(partial_matched)} / {total} functions ({(len(matched) / total) * 100:.2f}% matched)") if len(matched_but_undeleted_asm) > 0: print(f"The following functions have been matched but still exist in asm/nonmatchings/: {' '.join(matched_but_undeleted_asm)}") @@ -59,3 +71,5 @@ if __name__ == "__main__": for func in matched_but_undeleted_asm: file = glob(path.join(DIR, f"../asm/nonmatchings/*/{func}.s"))[0] remove(file) + elif len(asm) != len(non_matched): + print(f"warning: number of INCLUDE_ASM macros ({len(asm)}) != number of asm files ({len(non_matched)})")