add NON_MATCHING

This commit is contained in:
Alex Bates 2020-08-19 02:45:26 +01:00
parent c52ad332cc
commit fbbbf83d22
No known key found for this signature in database
GPG Key ID: 5E11C2DB78877706
7 changed files with 66 additions and 37 deletions

View File

@ -54,9 +54,12 @@ INCLUDE_ASM(code_6000, collision_heap_create);
INCLUDE_ASM(code_6000, collision_heap_malloc); INCLUDE_ASM(code_6000, collision_heap_malloc);
INCLUDE_ASM(code_6000, collision_heap_free); #ifdef NON_MATCHING
/*s32 collision_heap_free(s32 size) { s32 collision_heap_free(s32 size) {
s32 isBattle = (*gGameStatusPtr)->isBattle; s32 isBattle = (*gGameStatusPtr)->isBattle;
return _heap_free((isBattle == 0) ? (&D_80268000) : (&D_803DA800), size); return _heap_free((isBattle == 0) ? (&D_80268000) : (&D_803DA800), size);
}*/ }
#else
INCLUDE_ASM(code_6000, collision_heap_free);
#endif

View File

@ -716,10 +716,10 @@ void reset_status_menu(void) {
func_801452B4(uiStatus->iconIndexC, uiStatus->iconIndexC); func_801452B4(uiStatus->iconIndexC, uiStatus->iconIndexC);
} }
#ifdef NON_MATCHING
// uses a jumptable, which we need .rodata support for. // 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. // Somewhat close. Needs work.
/*s32 is_ability_active(s32 arg0) { s32 is_ability_active(s32 arg0) {
s32 iVar2; s32 iVar2;
u32 uVar3; u32 uVar3;
s32 iVar5; s32 iVar5;
@ -965,7 +965,10 @@ s32 INCLUDE_ASM(code_80850_len_3060, is_ability_active, s32 arg0);
} }
return iVar7; return iVar7;
} }
}*/ }
#else
s32 INCLUDE_ASM(code_80850_len_3060, is_ability_active, s32 arg0);
#endif
s32 is_partner_ability_active(void) { s32 is_partner_ability_active(void) {
return 0; return 0;

View File

@ -41,8 +41,8 @@ Trigger* get_trigger_by_id(s32 triggerID) {
return (*gCurrentTriggerListPtr)[triggerID]; return (*gCurrentTriggerListPtr)[triggerID];
} }
INCLUDE_ASM(code_dbd70_len_700, func_80145CE8); #ifdef NON_MATCHING
/*s32 func_80145CE8(s32 arg0) { s32 func_80145CE8(s32 arg0) {
s32 i; s32 i;
s32 ret; s32 ret;
@ -60,4 +60,7 @@ INCLUDE_ASM(code_dbd70_len_700, func_80145CE8);
} }
return ret; return ret;
}*/ }
#else
INCLUDE_ASM(code_dbd70_len_700, func_80145CE8);
#endif

View File

@ -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, func_802C39F8);
INCLUDE_ASM(code_e79b0_len_1920, restart_script); #ifdef NON_MATCHING
/*
ScriptInstance* restart_script(ScriptInstance* script) { ScriptInstance* restart_script(ScriptInstance* script) {
script->loopDepth = -1; script->loopDepth = -1;
script->switchDepth = -1; script->switchDepth = -1;
@ -39,7 +38,9 @@ ScriptInstance* restart_script(ScriptInstance* script) {
return script; return script;
} }
*/ #else
INCLUDE_ASM(code_e79b0_len_1920, restart_script);
#endif
INCLUDE_ASM(code_e79b0_len_1920, update_scripts); INCLUDE_ASM(code_e79b0_len_1920, update_scripts);
@ -104,22 +105,23 @@ void set_script_timescale(ScriptInstance* script, f32 timeScale) {
script->timeScale = timeScale * gGlobalTimeSpace; 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 // TODO: figure out why compiler/assembler isn't putting SWC1 in delay slot
void set_global_timespace(f32 timeScale) { void set_global_timespace(f32 timeScale) {
//gGlobalTimeSpace = timeScale; //gGlobalTimeSpace = timeScale;
} }
*/ #else
INCLUDE_ASM(code_e79b0_len_1920, set_global_timespace);
#endif
#ifdef NON_MATCHING
INCLUDE_ASM(code_e79b0_len_1920, get_global_timespace);
/*
// TODO: figure out why compiler/assembler isn't putting LWC1 in delay slot // TODO: figure out why compiler/assembler isn't putting LWC1 in delay slot
f32 get_global_timespace(void) { f32 get_global_timespace(void) {
//return gGlobalTimeSpace; //return gGlobalTimeSpace;
} }
*/ #else
INCLUDE_ASM(code_e79b0_len_1920, get_global_timespace);
#endif
void set_script_group(ScriptInstance* script, s8 groupFlags) { void set_script_group(ScriptInstance* script, s8 groupFlags) {
script->groupFlags = 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 // TODO: Really close but some weirdness is going on
void clear_script_flags(ScriptInstance* script, s32 flags) { void clear_script_flags(ScriptInstance* script, s32 flags) {
int i; 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

View File

@ -66,10 +66,9 @@ ApiStatus SetMessageString(ScriptInstance* script, s32 isInitialCall) {
return ApiStatus_DONE2; 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 // TODO: Figure out why there's an extra NOP after this function
// It's probably because of a file split issue // It's probably because of a file split issue
/*
ApiStatus SetMessageValue(ScriptInstance* script, s32 initialCall) { ApiStatus SetMessageValue(ScriptInstance* script, s32 initialCall) {
Bytecode* ptrReadPos = script->ptrReadPos; Bytecode* ptrReadPos = script->ptrReadPos;
Bytecode value = get_variable(script, *ptrReadPos++); Bytecode value = get_variable(script, *ptrReadPos++);
@ -78,7 +77,9 @@ ApiStatus SetMessageValue(ScriptInstance* script, s32 initialCall) {
set_message_value(value, index); set_message_value(value, index);
return ApiStatus_DONE2; return ApiStatus_DONE2;
} }
*/ #else
INCLUDE_API_ASM(code_f4c60_len_4300, SetMessageValue);
#endif
INCLUDE_API_ASM(code_f4c60_len_4300, HidePlayerShadow); INCLUDE_API_ASM(code_f4c60_len_4300, HidePlayerShadow);

View File

@ -335,8 +335,7 @@ ApiStatus AddStarPieces(ScriptInstance* script, s32 isInitialCall) {
return ApiStatus_DONE2; return ApiStatus_DONE2;
} }
INCLUDE_API_ASM(code_fa4c0_len_3bf0, GetItemPower); #ifdef NON_MATCHING
/*
// Close to working // Close to working
ApiStatus GetItemPower(ScriptInstance* script, s32 isInitialCall) { ApiStatus GetItemPower(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos; Bytecode* ptrReadPos = script->ptrReadPos;
@ -349,7 +348,9 @@ ApiStatus GetItemPower(ScriptInstance* script, s32 isInitialCall) {
set_variable(script, ptrNextPos++, item->potencyB); set_variable(script, ptrNextPos++, item->potencyB);
return ApiStatus_DONE2; return ApiStatus_DONE2;
} }
*/ #else
INCLUDE_API_ASM(code_fa4c0_len_3bf0, GetItemPower);
#endif
INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowGotItem); 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, ShowEmote);
INCLUDE_API_ASM(code_fa4c0_len_3bf0, RemoveEffect); #ifdef NON_MATCHING
/*
// Works // Works
ApiStatus RemoveEffect(ScriptInstance* script, s32 isInitialCall) { ApiStatus RemoveEffect(ScriptInstance* script, s32 isInitialCall) {
Bytecode* ptrReadPos = script->ptrReadPos; Bytecode* ptrReadPos = script->ptrReadPos;
@ -398,8 +398,10 @@ ApiStatus func_802D7B74(ScriptInstance* script, s32 isInitialCall) {
return ApiStatus_DONE2; 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); INCLUDE_API_ASM(code_fa4c0_len_3bf0, ShowSleepBubble);

View File

@ -28,16 +28,28 @@ c_func_pattern = re.compile(
re.MULTILINE re.MULTILINE
) )
def funcs_in_c(text): 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 = [] matched = []
asm = []
for filename in C_FILES: for filename in C_FILES:
with open(filename, "r") as file: 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] 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 __name__ == "__main__":
if "--help" in argv: if "--help" in argv:
@ -46,7 +58,7 @@ if __name__ == "__main__":
exit() exit()
total = len(matched) + len(non_matched) 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: 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)}") 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: for func in matched_but_undeleted_asm:
file = glob(path.join(DIR, f"../asm/nonmatchings/*/{func}.s"))[0] file = glob(path.join(DIR, f"../asm/nonmatchings/*/{func}.s"))[0]
remove(file) 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)})")