diff options
| author | louist103 <35883445+louist103@users.noreply.github.com> | 2022-08-04 00:47:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-04 05:47:01 +0100 |
| commit | fb445b7d4b7d75372f48d3980239f2f9205c4d45 (patch) | |
| tree | b04c9e5f09531ca2649c8b6fe5f091a9474128aa /src/code | |
| parent | 8f7f3d24c750cec3e99cf5f6309406dbd98eaf6b (diff) | |
Z_DLF OK (#965)
* matched both
* use overlay reloc macro
* fix fake looking match
* PR fixes and change other overlay loading functions
* rename
* formatter
* fix build
* re format
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/z_DLF.c | 72 | ||||
| -rw-r--r-- | src/code/z_actor.c | 8 | ||||
| -rw-r--r-- | src/code/z_effect_soft_sprite.c | 5 |
3 files changed, 77 insertions, 8 deletions
diff --git a/src/code/z_DLF.c b/src/code/z_DLF.c index 862463b76..020edcf27 100644 --- a/src/code/z_DLF.c +++ b/src/code/z_DLF.c @@ -2,6 +2,74 @@ #include "system_malloc.h" #include "z64load.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/z_DLF/Overlay_LoadGameState.s") +void Overlay_LoadGameState(GameStateOverlay* overlayEntry) { + void* vramStart; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_DLF/Overlay_FreeGameState.s") + if (overlayEntry->loadedRamAddr != NULL) { + return; + } + vramStart = overlayEntry->vramStart; + if (vramStart == NULL) { + overlayEntry->unk_28 = 0; + return; + } + overlayEntry->loadedRamAddr = Load2_AllocateAndLoad(overlayEntry->vromStart, overlayEntry->vromEnd, + (uintptr_t)vramStart, (uintptr_t)overlayEntry->vramEnd); + if (overlayEntry->loadedRamAddr != NULL) { + + overlayEntry->unk_14 = (uintptr_t)( + (overlayEntry->unk_14 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_14 - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->init = + (uintptr_t)((overlayEntry->init != NULL) + ? (void*)((uintptr_t)overlayEntry->init - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->destroy = (uintptr_t)( + (overlayEntry->destroy != NULL) + ? (void*)((uintptr_t)overlayEntry->destroy - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->unk_20 = (uintptr_t)( + (overlayEntry->unk_20 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_20 - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->unk_24 = (uintptr_t)( + (overlayEntry->unk_24 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_24 - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + + overlayEntry->unk_28 = 0; + } +} + +void Overlay_FreeGameState(GameStateOverlay* overlayEntry) { + s32 var_v0; + + if (overlayEntry->loadedRamAddr != NULL) { + var_v0 = overlayEntry->unk_28 != 0 ? -1 : 0; + if (var_v0 == 0) { + overlayEntry->unk_14 = (uintptr_t)( + (overlayEntry->unk_14 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_14 + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->init = (uintptr_t)( + (overlayEntry->init != NULL) + ? (void*)((uintptr_t)overlayEntry->init + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->destroy = (uintptr_t)( + (overlayEntry->destroy != NULL) + ? (void*)((uintptr_t)overlayEntry->destroy + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->unk_20 = (uintptr_t)( + (overlayEntry->unk_20 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_20 + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + overlayEntry->unk_24 = (uintptr_t)( + (overlayEntry->unk_24 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_24 + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); + SystemArena_Free(overlayEntry->loadedRamAddr); + overlayEntry->loadedRamAddr = NULL; + } + } +} diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 53341c783..cee64182b 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -3153,10 +3153,10 @@ ActorInit* Actor_LoadOverlay(ActorContext* actorCtx, s16 index) { overlayEntry->numLoaded = 0; } - actorInit = - (uintptr_t)((overlayEntry->initInfo != NULL) - ? (void*)(-OVERLAY_RELOCATION_OFFSET(overlayEntry) + (uintptr_t)overlayEntry->initInfo) - : NULL); + actorInit = (uintptr_t)( + (overlayEntry->initInfo != NULL) + ? (void*)((uintptr_t)overlayEntry->initInfo - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry)) + : NULL); } return actorInit; diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c index 422bb401e..87f1958bd 100644 --- a/src/code/z_effect_soft_sprite.c +++ b/src/code/z_effect_soft_sprite.c @@ -188,8 +188,9 @@ void EffectSs_Spawn(PlayState* play, s32 type, s32 priority, void* initData) { Load2_LoadOverlay(entry->vromStart, entry->vromEnd, entry->vramStart, entry->vramEnd, entry->loadedRamAddr); } - initInfo = (uintptr_t)( - (entry->initInfo != NULL) ? (void*)(-OVERLAY_RELOCATION_OFFSET(entry) + (uintptr_t)entry->initInfo) : NULL); + initInfo = (uintptr_t)((entry->initInfo != NULL) + ? (void*)((uintptr_t)entry->initInfo - (intptr_t)OVERLAY_RELOCATION_OFFSET(entry)) + : NULL); } if (initInfo->init != NULL) { |
