* Sync with OoT

* Macro cleanup

* Some cleanup/rename load system name to Fragment

* Format

* bss

* Some clarifying comments regarding fragments

* PR suggestions

* size_t and numRelocations
This commit is contained in:
Derek Hensley
2023-06-23 21:26:36 -07:00
committed by GitHub
parent aa9e368561
commit 5619dc5b5e
19 changed files with 307 additions and 197 deletions
+35 -16
View File
@@ -1,6 +1,6 @@
#include "global.h"
#include "system_malloc.h"
#include "z64load.h"
#include "loadfragment.h"
void Overlay_LoadGameState(GameStateOverlay* overlayEntry) {
void* vramStart;
@@ -13,29 +13,38 @@ void Overlay_LoadGameState(GameStateOverlay* overlayEntry) {
overlayEntry->unk_28 = 0;
return;
}
overlayEntry->loadedRamAddr = Load2_AllocateAndLoad(overlayEntry->vromStart, overlayEntry->vromEnd,
(uintptr_t)vramStart, (uintptr_t)overlayEntry->vramEnd);
overlayEntry->loadedRamAddr = Overlay_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))
? (void*)((uintptr_t)overlayEntry->unk_14 -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->init =
(uintptr_t)((overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
: NULL);
overlayEntry->init = (uintptr_t)(
(overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->destroy = (uintptr_t)(
(overlayEntry->destroy != NULL)
? (void*)((uintptr_t)overlayEntry->destroy - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->destroy -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_20 = (uintptr_t)(
(overlayEntry->unk_20 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_20 - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->unk_20 -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_24 = (uintptr_t)(
(overlayEntry->unk_24 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_24 - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->unk_24 -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_28 = 0;
@@ -50,24 +59,34 @@ void Overlay_FreeGameState(GameStateOverlay* overlayEntry) {
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))
? (void*)((uintptr_t)overlayEntry->unk_14 +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->init = (uintptr_t)(
(overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->init +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->destroy = (uintptr_t)(
(overlayEntry->destroy != NULL)
? (void*)((uintptr_t)overlayEntry->destroy + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->destroy +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_20 = (uintptr_t)(
(overlayEntry->unk_20 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_20 + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->unk_20 +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_24 = (uintptr_t)(
(overlayEntry->unk_24 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_24 + (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->unk_24 +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
SystemArena_Free(overlayEntry->loadedRamAddr);
overlayEntry->loadedRamAddr = NULL;
}