* 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
+1 -1
View File
@@ -101,7 +101,7 @@ void* Graph_FaultAddrConv(void* address, void* param) {
s32 i;
for (i = 0; i < gGraphNumGameStates; i++, gameStateOvl++) {
diff = VRAM_PTR_SIZE(gameStateOvl);
diff = (uintptr_t)gameStateOvl->vramEnd - (uintptr_t)gameStateOvl->vramStart;
ramStart = gameStateOvl->loadedRamAddr;
ramConv = (uintptr_t)gameStateOvl->vramStart - (uintptr_t)ramStart;
+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;
}
+6 -5
View File
@@ -4,8 +4,8 @@
*/
#include "global.h"
#include "loadfragment.h"
#include "z64horse.h"
#include "z64load.h"
#include "z64quake.h"
#include "z64rumble.h"
#include "overlays/actors/ovl_En_Horse/z_en_horse.h"
@@ -3157,7 +3157,7 @@ ActorInit* Actor_LoadOverlay(ActorContext* actorCtx, s16 index) {
ActorOverlay* overlayEntry = &gActorOverlayTable[index];
ActorInit* actorInit;
overlaySize = VRAM_PTR_SIZE(overlayEntry);
overlaySize = (uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart;
if (overlayEntry->vramStart == NULL) {
actorInit = overlayEntry->initInfo;
@@ -3178,14 +3178,15 @@ ActorInit* Actor_LoadOverlay(ActorContext* actorCtx, s16 index) {
return NULL;
}
Load2_LoadOverlay(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart,
overlayEntry->vramEnd, overlayEntry->loadedRamAddr);
Overlay_Load(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd,
overlayEntry->loadedRamAddr);
overlayEntry->numLoaded = 0;
}
actorInit = (uintptr_t)(
(overlayEntry->initInfo != NULL)
? (void*)((uintptr_t)overlayEntry->initInfo - (intptr_t)OVERLAY_RELOCATION_OFFSET(overlayEntry))
? (void*)((uintptr_t)overlayEntry->initInfo -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
}
+2 -2
View File
@@ -52,7 +52,7 @@ void ActorOverlayTable_FaultClient(void* arg0, void* arg1) {
FaultDrawer_Printf("No. RamStart- RamEnd cn Name\n");
for (actorId = 0, overlayEntry = &gActorOverlayTable[0]; actorId < gMaxActorId; actorId++, overlayEntry++) {
overlaySize = VRAM_PTR_SIZE(overlayEntry);
overlaySize = (uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart;
if (overlayEntry->loadedRamAddr != NULL) {
FaultDrawer_Printf("%3d %08x-%08x %3d %s\n", actorId, overlayEntry->loadedRamAddr,
(u32)overlayEntry->loadedRamAddr + overlaySize, overlayEntry->numLoaded, "");
@@ -69,7 +69,7 @@ void* ActorOverlayTable_FaultAddrConv(void* address, void* param) {
ActorId actorId;
for (actorId = 0; actorId < gMaxActorId; actorId++, actorOvl++) {
diff = VRAM_PTR_SIZE(actorOvl);
diff = (uintptr_t)actorOvl->vramEnd - (uintptr_t)actorOvl->vramStart;
ramStart = actorOvl->loadedRamAddr;
ramConv = (uintptr_t)actorOvl->vramStart - (uintptr_t)ramStart;
+15 -12
View File
@@ -1,5 +1,5 @@
#include "global.h"
#include "z64load.h"
#include "loadfragment.h"
EffectSsInfo sEffectSsInfo = { NULL, 0, 0 };
@@ -164,7 +164,7 @@ void EffectSS_Copy(PlayState* play, EffectSs* effectsSs) {
void EffectSs_Spawn(PlayState* play, s32 type, s32 priority, void* initData) {
s32 index;
u32 overlaySize;
EffectSsOverlay* entry = &gParticleOverlayTable[type];
EffectSsOverlay* overlayEntry = &gParticleOverlayTable[type];
EffectSsInit* initInfo;
if (EffectSS_FindFreeSpace(priority, &index) != 0) {
@@ -173,24 +173,27 @@ void EffectSs_Spawn(PlayState* play, s32 type, s32 priority, void* initData) {
}
sEffectSsInfo.searchIndex = index + 1;
overlaySize = VRAM_PTR_SIZE(entry);
overlaySize = (uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart;
if (entry->vramStart == NULL) {
initInfo = entry->initInfo;
if (overlayEntry->vramStart == NULL) {
initInfo = overlayEntry->initInfo;
} else {
if (entry->loadedRamAddr == NULL) {
entry->loadedRamAddr = ZeldaArena_MallocR(overlaySize);
if (overlayEntry->loadedRamAddr == NULL) {
overlayEntry->loadedRamAddr = ZeldaArena_MallocR(overlaySize);
if (entry->loadedRamAddr == NULL) {
if (overlayEntry->loadedRamAddr == NULL) {
return;
}
Load2_LoadOverlay(entry->vromStart, entry->vromEnd, entry->vramStart, entry->vramEnd, entry->loadedRamAddr);
Overlay_Load(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd,
overlayEntry->loadedRamAddr);
}
initInfo = (uintptr_t)((entry->initInfo != NULL)
? (void*)((uintptr_t)entry->initInfo - (intptr_t)OVERLAY_RELOCATION_OFFSET(entry))
: NULL);
initInfo = (uintptr_t)(
(overlayEntry->initInfo != NULL)
? (void*)((uintptr_t)overlayEntry->initInfo -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
}
if (initInfo->init != NULL) {
+5 -5
View File
@@ -1,5 +1,5 @@
#include "global.h"
#include "z64load.h"
#include "loadfragment.h"
#define KALEIDO_OVERLAY(name) \
{ \
@@ -24,7 +24,7 @@ void* KaleidoManager_FaultAddrConv(void* address, void* param) {
size_t diff;
if (kaleidoMgrOvl != NULL) {
diff = VRAM_PTR_SIZE(kaleidoMgrOvl);
diff = (uintptr_t)kaleidoMgrOvl->vramEnd - (uintptr_t)kaleidoMgrOvl->vramStart;
ramStart = kaleidoMgrOvl->loadedRamAddr;
ramConv = (uintptr_t)kaleidoMgrOvl->vramStart - (uintptr_t)ramStart;
@@ -39,7 +39,7 @@ void* KaleidoManager_FaultAddrConv(void* address, void* param) {
void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl) {
ovl->loadedRamAddr = sKaleidoAreaPtr;
Load2_LoadOverlay(ovl->vromStart, ovl->vromEnd, ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr);
Overlay_Load(ovl->vromStart, ovl->vromEnd, ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr);
ovl->offset = (uintptr_t)ovl->loadedRamAddr - (uintptr_t)ovl->vramStart;
gKaleidoMgrCurOvl = ovl;
}
@@ -47,7 +47,7 @@ void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl) {
void KaleidoManager_ClearOvl(KaleidoMgrOverlay* ovl) {
if (ovl->loadedRamAddr != NULL) {
ovl->offset = 0;
bzero(ovl->loadedRamAddr, VRAM_PTR_SIZE(ovl));
bzero(ovl->loadedRamAddr, (uintptr_t)ovl->vramEnd - (uintptr_t)ovl->vramStart);
ovl->loadedRamAddr = NULL;
gKaleidoMgrCurOvl = NULL;
}
@@ -59,7 +59,7 @@ void KaleidoManager_Init(PlayState* play) {
u32 i;
for (i = 0; i < ARRAY_COUNT(gKaleidoMgrOverlayTable); i++) {
size = VRAM_PTR_SIZE(&gKaleidoMgrOverlayTable[i]);
size = (uintptr_t)gKaleidoMgrOverlayTable[i].vramEnd - (uintptr_t)gKaleidoMgrOverlayTable[i].vramStart;
if (size > largestSize) {
largestSize = size;
}
+1
View File
@@ -1,3 +1,4 @@
#include "prevent_bss_reordering.h"
#include "global.h"
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
#include "interface/parameter_static/parameter_static.h"
+4 -4
View File
@@ -13,7 +13,7 @@
*/
#include "global.h"
#include "z64load.h"
#include "loadfragment.h"
void* TransitionOverlay_VramToRam(TransitionOverlay* overlayEntry, void* vramAddr) {
void* loadedRamAddr = Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr);
@@ -40,13 +40,13 @@ s32 TransitionOverlay_Load(TransitionOverlay* overlayEntry) {
return 3;
}
if (Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr) == NULL) {
loadedRamAddr = ZeldaArena_Malloc(VRAM_PTR_SIZE(overlayEntry));
loadedRamAddr = ZeldaArena_Malloc((uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart);
if (loadedRamAddr == NULL) {
return -1;
}
Load2_LoadOverlay(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart,
overlayEntry->vramEnd, loadedRamAddr);
Overlay_Load(overlayEntry->vromStart, overlayEntry->vromEnd, overlayEntry->vramStart, overlayEntry->vramEnd,
loadedRamAddr);
overlayEntry->loadInfo.addr = Lib_VirtualToPhysical(loadedRamAddr);
overlayEntry->loadInfo.count = 1;
return 0;