From 760e1351fb04fee9575205fd71ccdf36a7484409 Mon Sep 17 00:00:00 2001 From: Jdog Date: Fri, 14 Aug 2020 15:05:05 -0700 Subject: [PATCH] Working more on script-related functions --- include/variables.h | 2 + src/code_e79b0_len_1920.c | 242 +++++++++++++++++++++++++++++++++++--- undefined_syms.txt | 1 + 3 files changed, 229 insertions(+), 16 deletions(-) diff --git a/include/variables.h b/include/variables.h index 1dbe05b68a..354398f8a0 100644 --- a/include/variables.h +++ b/include/variables.h @@ -15,6 +15,8 @@ extern script_context* gWorldScriptList[128]; extern script_context* gBattleScriptList[128]; extern script_context** gCurrentScriptListPtr[128]; +extern f32 gGlobalTimeSpace; + extern s8 D_800A0900; extern s16* D_80151328; extern s16 D_8010CD10; diff --git a/src/code_e79b0_len_1920.c b/src/code_e79b0_len_1920.c index 9093b6bd64..9382a4e4fd 100644 --- a/src/code_e79b0_len_1920.c +++ b/src/code_e79b0_len_1920.c @@ -18,7 +18,29 @@ 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); +//INCLUDE_ASM(code_e79b0_len_1920, restart_script); +/* +// TODO: Find out why things break when script->timeScale = 1 goes after the previous lines +script_context* restart_script(script_context* script) { + script->loopDepth = -1; + script->switchDepth = -1; + script->currentOpcode = 0; + script->frameCounter = 0; + script->frameCounter = 0; + script->unk_158 = 0; + + //script->timeScale = 1; + script->ptrNextLine = script->ptrFirstLine; + script->ptrCurrentLine = script->ptrFirstLine; + script->timeScale = 1.0f; + + + script->timeScale = gGlobalTimeSpace; + find_script_labels(); + func_802C3390(script); + return script; +} +*/ INCLUDE_ASM(code_e79b0_len_1920, update_scripts); @@ -64,41 +86,194 @@ s32 does_script_exist(s32 id) { return 0; } -INCLUDE_ASM(code_e79b0_len_1920, does_script_exist_by_ref); +s32 does_script_exist_by_ref(script_context* script) { + s32 i; -INCLUDE_ASM(code_e79b0_len_1920, set_script_priority); + for(i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + if(script == (*gCurrentScriptListPtr)[i]) { + return 1; + } + } + return 0; +} -INCLUDE_ASM(code_e79b0_len_1920, set_script_timescale); +void set_script_priority(script_context* script, s8 priority) { + script->priority = priority; +} + +void set_script_timescale(script_context* script, f32 timeScale) { + script->timeScale = timeScale * gGlobalTimeSpace; +} INCLUDE_ASM(code_e79b0_len_1920, set_global_timespace); +/* +// TODO: figure out why compiler/assembler isn't putting SWC1 in delay slot +void set_global_timespace(f32 timeScale) { + //gGlobalTimeSpace = timeScale; + __asm__("LUI $at,0x802e;" + "SWC1 $f12,-0x6358($at);" + ); +} +*/ + INCLUDE_ASM(code_e79b0_len_1920, get_global_timespace); +/* +// TODO: figure out why compiler/assembler isn't putting LWC1 in delay slot +f32 get_global_timespace(void) { + //return gGlobalTimeSpace; + __asm__("LUI $at,0x802e;" + "LWC1 $f0,-0x6358($at);" + ); +} +*/ -INCLUDE_ASM(code_e79b0_len_1920, set_script_group); +void set_script_group(script_context* script, s8 groupFlags) { + script->groupFlags = groupFlags; +} INCLUDE_ASM(code_e79b0_len_1920, bind_trigger); INCLUDE_ASM(code_e79b0_len_1920, bind_trigger_1); -INCLUDE_ASM(code_e79b0_len_1920, suspend_group_script); +void suspend_group_script(script_context* script, s32 groupFlags) { + int i; + script_context* scriptContextPtr; + script_context* childScript = script->childScript; -INCLUDE_ASM(code_e79b0_len_1920, resume_group_script); + if (childScript != NULL) { + suspend_group_script(childScript, groupFlags); + } -INCLUDE_ASM(code_e79b0_len_1920, suspend_all_script); + for(i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) { + suspend_group_script(scriptContextPtr, groupFlags); + } + } -INCLUDE_ASM(code_e79b0_len_1920, resume_all_script); + if ((script->groupFlags & groupFlags) != 0) { + script->state |= 0x2; + } +} -INCLUDE_ASM(code_e79b0_len_1920, suspend_group_script_index); +void resume_group_script(script_context* script, s32 groupFlags) { + int i; + script_context* scriptContextPtr; + script_context* childScript = script->childScript; -INCLUDE_ASM(code_e79b0_len_1920, resume_group_script_index); + if (childScript != NULL) { + resume_group_script(childScript, groupFlags); + } -INCLUDE_ASM(code_e79b0_len_1920, suspend_all_group); + for(i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) { + suspend_group_script(scriptContextPtr, groupFlags); + } + } -INCLUDE_ASM(code_e79b0_len_1920, resume_all_group); + if ((script->groupFlags & groupFlags) != 0) { + script->state &= 0xFD; + } +} -INCLUDE_ASM(code_e79b0_len_1920, suspend_group_others); +s32 suspend_all_script(s32 id) { + s32 i; + script_context* scriptContextPtr; -INCLUDE_ASM(code_e79b0_len_1920, resume_group_others); + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->uniqueID == id) { + suspend_group_script(scriptContextPtr, 0xEF); + } + } +} + +s32 resume_all_script(s32 id) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->uniqueID == id) { + resume_group_script(scriptContextPtr, 0xEF); + } + } +} + +void suspend_group_script_index(s32 id, s32 groupFlags) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->uniqueID == id) { + suspend_group_script(scriptContextPtr, groupFlags); + } + } +} + +void resume_group_script_index(s32 id, s32 groupFlags) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->uniqueID == id) { + resume_group_script(scriptContextPtr, groupFlags); + } + } +} + +s32 suspend_all_group(s32 groupFlags) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL) { + suspend_group_script(scriptContextPtr, groupFlags); + } + } +} + +s32 resume_all_group(s32 groupFlags) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL) { + resume_group_script(scriptContextPtr, groupFlags); + } + } +} + + +void suspend_group_others(s32 script, s32 groupFlags) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr != script) { + suspend_group_script(scriptContextPtr, groupFlags); + } + } +} + +void resume_group_others(s32 script, s32 groupFlags) { + s32 i; + script_context* scriptContextPtr; + + for (i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr != script) { + resume_group_script(scriptContextPtr, groupFlags); + } + } +} script_context* get_script_by_index(s32 index) { return (*gCurrentScriptListPtr)[index]; @@ -119,7 +294,42 @@ script_context* get_script_by_id(s32 id) { return 0; } +void set_script_flags(script_context* script, s32 flags) { + int i; + script_context* scriptContextPtr; + script_context* childScript = script->childScript; -INCLUDE_ASM(code_e79b0_len_1920, set_script_flags); + script->state |= flags; + if (childScript != NULL) { + set_script_flags(childScript, flags); + } + + for(i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) { + set_script_flags(script->parentScript, flags); + } + } +} INCLUDE_ASM(code_e79b0_len_1920, clear_script_flags); +/* +// TODO: Really close but some weirdness is going on +void clear_script_flags(script_context* script, s32 flags) { + int i; + script_context* scriptContextPtr; + script_context* childScript = script->childScript; + + script->state &= ~flags; + if (childScript != NULL) { + clear_script_flags(childScript, flags); + } + + for(i=0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++) { + scriptContextPtr = (*gCurrentScriptListPtr)[i]; + if (scriptContextPtr != NULL && scriptContextPtr->parentScript == script) { + clear_script_flags(script->parentScript, flags); + } + } +} +*/ diff --git a/undefined_syms.txt b/undefined_syms.txt index 32f85a9d6e..5f0a1e30c9 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -6,6 +6,7 @@ gItemTable = 0x800878E0; gWorldScriptList = 0x802DA490; gBattleScriptList = 0x802DA690; gCurrentScriptListPtr = 0x802DA890; +gGlobalTimeSpace = 0x802D9CA8; D_80147574 = 0x80147574; gMapTransitionAlpha = 0x800A0940;