mirror of
https://github.com/zeldaret/mm.git
synced 2026-07-09 13:45:23 -04:00
z_kaleido_manager and z_kaleido_scope_call OK (#489)
* migrated data and bss for z_kaleido_manager, renamed ovl_Player_Actor to ovl_player_actor to make it work with the data * z_kaleido_manager OK * add to functions.h variables.h and variables.txt * init * rename parameters in func_80163700 * rename func_80163700 to KaleidoManager_FaultAddrConvFunc * change u32 casts to uintptr_t casts in z_kaleido_manager. (u8 *) casts must stay, they are the only casts that match * ran format, uintptr_t * made suggested changes
This commit is contained in:
@@ -1,15 +1,104 @@
|
||||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/D_801DF9C0.s")
|
||||
#define KALEIDO_OVERLAY(name) \
|
||||
{ \
|
||||
NULL, SEGMENT_ROM_START(ovl_##name), SEGMENT_ROM_END(ovl_##name), SEGMENT_START(ovl_##name), \
|
||||
SEGMENT_END(ovl_##name), 0, #name, \
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/func_80163700.s")
|
||||
KaleidoMgrOverlay gKaleidoMgrOverlayTable[] = {
|
||||
KALEIDO_OVERLAY(kaleido_scope),
|
||||
KALEIDO_OVERLAY(player_actor),
|
||||
};
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/func_80163758.s")
|
||||
void* sKaleidoAreaPtr = NULL;
|
||||
KaleidoMgrOverlay* gKaleidoMgrCurOvl = NULL;
|
||||
FaultAddrConvClient sKaleidoAreaFaultClient;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/func_801637B4.s")
|
||||
void* KaleidoManager_FaultAddrConvFunc(void* address, void* param) {
|
||||
u8* ptr = address;
|
||||
KaleidoMgrOverlay* ovl = &gKaleidoMgrCurOvl[0];
|
||||
u8* ramStart;
|
||||
u8* ramEnd;
|
||||
size_t size;
|
||||
uintptr_t offset;
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/func_80163804.s")
|
||||
if (ovl != NULL) {
|
||||
size = (u8*)ovl->vramEnd - (u8*)ovl->vramStart;
|
||||
ramStart = ovl->loadedRamAddr;
|
||||
ramEnd = ramStart + size;
|
||||
offset = (u8*)ovl->vramStart - ramStart;
|
||||
if (ramStart != NULL) {
|
||||
if (ptr >= ramStart && ptr < ramEnd) {
|
||||
return ptr + offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/func_8016388C.s")
|
||||
void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl) {
|
||||
ovl->loadedRamAddr = sKaleidoAreaPtr;
|
||||
Load2_LoadOverlay(ovl->vromStart, ovl->vromEnd, ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr);
|
||||
ovl->offset = (uintptr_t)ovl->loadedRamAddr - (uintptr_t)ovl->vramStart;
|
||||
gKaleidoMgrCurOvl = ovl;
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_manager/func_801638D8.s")
|
||||
void KaleidoManager_ClearOvl(KaleidoMgrOverlay* ovl) {
|
||||
if (ovl->loadedRamAddr != NULL) {
|
||||
ovl->offset = 0;
|
||||
bzero(ovl->loadedRamAddr, (uintptr_t)ovl->vramEnd - (uintptr_t)ovl->vramStart);
|
||||
ovl->loadedRamAddr = NULL;
|
||||
gKaleidoMgrCurOvl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void KaleidoManager_Init(GlobalContext* globalCtx) {
|
||||
s32 largestSize = 0;
|
||||
s32 size;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(gKaleidoMgrOverlayTable); i++) {
|
||||
size = (uintptr_t)gKaleidoMgrOverlayTable[i].vramEnd - (uintptr_t)gKaleidoMgrOverlayTable[i].vramStart;
|
||||
if (size > largestSize) {
|
||||
largestSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
sKaleidoAreaPtr = THA_AllocEndAlign16(&globalCtx->state.heap, largestSize);
|
||||
gKaleidoMgrCurOvl = NULL;
|
||||
Fault_AddAddrConvClient(&sKaleidoAreaFaultClient, KaleidoManager_FaultAddrConvFunc, NULL);
|
||||
}
|
||||
|
||||
void KaleidoManager_Destroy() {
|
||||
Fault_RemoveAddrConvClient(&sKaleidoAreaFaultClient);
|
||||
|
||||
if (gKaleidoMgrCurOvl != NULL) {
|
||||
KaleidoManager_ClearOvl(gKaleidoMgrCurOvl);
|
||||
gKaleidoMgrCurOvl = NULL;
|
||||
}
|
||||
|
||||
sKaleidoAreaPtr = NULL;
|
||||
}
|
||||
|
||||
void* KaleidoManager_GetRamAddr(void* vram) {
|
||||
if (gKaleidoMgrCurOvl == NULL) {
|
||||
s32 pad[2];
|
||||
KaleidoMgrOverlay* ovl = &gKaleidoMgrOverlayTable[0];
|
||||
|
||||
do {
|
||||
if (((uintptr_t)vram >= (uintptr_t)ovl->vramStart) && ((uintptr_t)ovl->vramEnd >= (uintptr_t)vram)) {
|
||||
KaleidoManager_LoadOvl(ovl);
|
||||
return (void*)((uintptr_t)vram + ovl->offset);
|
||||
}
|
||||
ovl++;
|
||||
} while (ovl != (KaleidoMgrOverlay*)&sKaleidoAreaPtr);
|
||||
|
||||
return NULL;
|
||||
} else if (((uintptr_t)vram < (uintptr_t)gKaleidoMgrCurOvl->vramStart) ||
|
||||
((uintptr_t)vram >= (uintptr_t)gKaleidoMgrCurOvl->vramEnd)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void*)((uintptr_t)vram + gKaleidoMgrCurOvl->offset);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,84 @@
|
||||
#include "global.h"
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_scope_call/func_801639A0.s")
|
||||
void (*sKaleidoScopeUpdateFunc)(GlobalContext* globalCtx);
|
||||
void (*sKaleidoScopeDrawFunc)(GlobalContext* globalCtx);
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_scope_call/func_801639EC.s")
|
||||
extern void KaleidoScope_Update(GlobalContext* globalCtx);
|
||||
extern void KaleidoScope_Draw(GlobalContext* globalCtx);
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_scope_call/func_80163A38.s")
|
||||
void KaleidoScopeCall_LoadPlayer() {
|
||||
KaleidoMgrOverlay* playerActorOvl = &gKaleidoMgrOverlayTable[KALEIDO_OVL_PLAYER_ACTOR];
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_scope_call/func_80163A58.s")
|
||||
if (gKaleidoMgrCurOvl != playerActorOvl) {
|
||||
if (gKaleidoMgrCurOvl != NULL) {
|
||||
KaleidoManager_ClearOvl(gKaleidoMgrCurOvl);
|
||||
}
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_scope_call/func_80163C0C.s")
|
||||
KaleidoManager_LoadOvl(playerActorOvl);
|
||||
}
|
||||
}
|
||||
|
||||
void KaleidoScopeCall_Init(GlobalContext* globalCtx) {
|
||||
sKaleidoScopeUpdateFunc = KaleidoManager_GetRamAddr(KaleidoScope_Update);
|
||||
sKaleidoScopeDrawFunc = KaleidoManager_GetRamAddr(KaleidoScope_Draw);
|
||||
KaleidoSetup_Init(globalCtx);
|
||||
}
|
||||
|
||||
void KaleidoScopeCall_Destroy(GlobalContext* globalCtx) {
|
||||
KaleidoSetup_Destroy(globalCtx);
|
||||
}
|
||||
|
||||
void KaleidoScopeCall_Update(GlobalContext* globalCtx) {
|
||||
PauseContext* pauseCtx = &globalCtx->pauseCtx;
|
||||
KaleidoMgrOverlay* kaleidoScopeOvl = &gKaleidoMgrOverlayTable[KALEIDO_OVL_KALEIDO_SCOPE];
|
||||
|
||||
if ((globalCtx->pauseCtx.state != 0) || (globalCtx->pauseCtx.debugState != 0)) {
|
||||
if (pauseCtx->state == 1 || pauseCtx->state == 19) {
|
||||
if (ShrinkWindow_GetLetterboxMagnitude() == 0) {
|
||||
R_PAUSE_MENU_MODE = 1;
|
||||
pauseCtx->unk_200 = 0;
|
||||
pauseCtx->unk_208 = 0;
|
||||
pauseCtx->state = (pauseCtx->state & 0xFFFF) + 1;
|
||||
}
|
||||
} else if (pauseCtx->state == 8) {
|
||||
R_PAUSE_MENU_MODE = 1;
|
||||
pauseCtx->unk_200 = 0;
|
||||
pauseCtx->unk_208 = 0;
|
||||
pauseCtx->state = (pauseCtx->state & 0xFFFF) + 1;
|
||||
} else if ((pauseCtx->state == 2) || (pauseCtx->state == 9) || (pauseCtx->state == 20)) {
|
||||
if (R_PAUSE_MENU_MODE == 3) {
|
||||
pauseCtx->state++;
|
||||
}
|
||||
} else if (pauseCtx->state != 0) {
|
||||
if (gKaleidoMgrCurOvl != kaleidoScopeOvl) {
|
||||
if (gKaleidoMgrCurOvl != NULL) {
|
||||
KaleidoManager_ClearOvl(gKaleidoMgrCurOvl);
|
||||
}
|
||||
|
||||
KaleidoManager_LoadOvl(kaleidoScopeOvl);
|
||||
}
|
||||
|
||||
if (gKaleidoMgrCurOvl == kaleidoScopeOvl) {
|
||||
sKaleidoScopeUpdateFunc(globalCtx);
|
||||
|
||||
if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0)) {
|
||||
KaleidoManager_ClearOvl(kaleidoScopeOvl);
|
||||
KaleidoScopeCall_LoadPlayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KaleidoScopeCall_Draw(GlobalContext* globalCtx) {
|
||||
KaleidoMgrOverlay* kaleidoScopeOvl = &gKaleidoMgrOverlayTable[KALEIDO_OVL_KALEIDO_SCOPE];
|
||||
|
||||
if (R_PAUSE_MENU_MODE == 3) {
|
||||
if (((globalCtx->pauseCtx.state >= 4) && (globalCtx->pauseCtx.state <= 7)) ||
|
||||
((globalCtx->pauseCtx.state >= 11) && (globalCtx->pauseCtx.state <= 26))) {
|
||||
if (gKaleidoMgrCurOvl == kaleidoScopeOvl) {
|
||||
sKaleidoScopeDrawFunc(globalCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_setup/func_800F4C0C.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_setup/func_800F4E20.s")
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_setup/KaleidoSetup_Init.s")
|
||||
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_setup/func_800F4F28.s")
|
||||
#pragma GLOBAL_ASM("asm/non_matchings/code/z_kaleido_setup/KaleidoSetup_Destroy.s")
|
||||
|
||||
Reference in New Issue
Block a user