2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
#define KALEIDO_OVERLAY(name) \
|
|
|
|
{ \
|
|
|
|
NULL, (u32)_ovl_##name##SegmentRomStart, (u32)_ovl_##name##SegmentRomEnd, _ovl_##name##SegmentStart, \
|
|
|
|
_ovl_##name##SegmentEnd, 0, #name, \
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 23:15:16 +00:00
|
|
|
KaleidoMgrOverlay gKaleidoMgrOverlayTable[] = {
|
2020-03-17 04:31:30 +00:00
|
|
|
KALEIDO_OVERLAY(kaleido_scope),
|
|
|
|
KALEIDO_OVERLAY(player_actor),
|
|
|
|
};
|
|
|
|
|
|
|
|
void* sKaleidoAreaPtr = NULL;
|
2021-05-02 23:15:16 +00:00
|
|
|
KaleidoMgrOverlay* gKaleidoMgrCurOvl = NULL;
|
|
|
|
u8 gBossMarkState = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-05-02 23:15:16 +00:00
|
|
|
void KaleidoManager_LoadOvl(KaleidoMgrOverlay* ovl) {
|
2020-03-17 04:31:30 +00:00
|
|
|
LogUtils_CheckNullPointer("KaleidoArea_allocp", sKaleidoAreaPtr, "../z_kaleido_manager.c", 99);
|
2021-05-02 23:15:16 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
ovl->loadedRamAddr = sKaleidoAreaPtr;
|
|
|
|
Overlay_Load(ovl->vromStart, ovl->vromEnd, ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr);
|
2021-05-02 23:15:16 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(GREEN));
|
2020-03-22 21:19:43 +00:00
|
|
|
osSyncPrintf("OVL(k):Seg:%08x-%08x Ram:%08x-%08x Off:%08x %s\n", ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr,
|
2021-05-02 23:15:16 +00:00
|
|
|
(u32)ovl->loadedRamAddr + (u32)ovl->vramEnd - (u32)ovl->vramStart,
|
2020-03-22 21:19:43 +00:00
|
|
|
(u32)ovl->vramStart - (u32)ovl->loadedRamAddr, ovl->name);
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2021-05-02 23:15:16 +00:00
|
|
|
|
|
|
|
ovl->offset = (u32)ovl->loadedRamAddr - (u32)ovl->vramStart;
|
2020-03-17 04:31:30 +00:00
|
|
|
gKaleidoMgrCurOvl = ovl;
|
|
|
|
}
|
|
|
|
|
2021-05-02 23:15:16 +00:00
|
|
|
void KaleidoManager_ClearOvl(KaleidoMgrOverlay* ovl) {
|
|
|
|
if (ovl->loadedRamAddr != NULL) {
|
|
|
|
ovl->offset = 0;
|
|
|
|
bzero(ovl->loadedRamAddr, (u32)ovl->vramEnd - (u32)ovl->vramStart);
|
2020-03-17 04:31:30 +00:00
|
|
|
ovl->loadedRamAddr = NULL;
|
|
|
|
gKaleidoMgrCurOvl = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void KaleidoManager_Init(GlobalContext* globalCtx) {
|
2021-05-02 23:15:16 +00:00
|
|
|
s32 largestSize = 0;
|
|
|
|
s32 size;
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_COUNT(gKaleidoMgrOverlayTable); i++) {
|
|
|
|
size = (u32)gKaleidoMgrOverlayTable[i].vramEnd - (u32)gKaleidoMgrOverlayTable[i].vramStart;
|
|
|
|
if (size > largestSize) {
|
|
|
|
largestSize = size;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2021-05-02 23:15:16 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(GREEN));
|
2021-05-02 23:15:16 +00:00
|
|
|
osSyncPrintf("KaleidoArea の最大サイズは %d バイトを確保します\n", largestSize);
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2021-05-02 23:15:16 +00:00
|
|
|
|
|
|
|
sKaleidoAreaPtr = GameState_Alloc(&globalCtx->state, largestSize, "../z_kaleido_manager.c", 150);
|
2020-03-17 04:31:30 +00:00
|
|
|
LogUtils_CheckNullPointer("KaleidoArea_allocp", sKaleidoAreaPtr, "../z_kaleido_manager.c", 151);
|
2021-05-02 23:15:16 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(GREEN));
|
2021-05-02 23:15:16 +00:00
|
|
|
osSyncPrintf("KaleidoArea %08x - %08x\n", sKaleidoAreaPtr, (u32)sKaleidoAreaPtr + largestSize);
|
2020-03-17 04:31:30 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2021-05-02 23:15:16 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
gKaleidoMgrCurOvl = 0;
|
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
void KaleidoManager_Destroy() {
|
2021-05-02 23:15:16 +00:00
|
|
|
if (gKaleidoMgrCurOvl != NULL) {
|
2020-03-17 04:31:30 +00:00
|
|
|
KaleidoManager_ClearOvl(gKaleidoMgrCurOvl);
|
|
|
|
gKaleidoMgrCurOvl = NULL;
|
|
|
|
}
|
2021-05-02 23:15:16 +00:00
|
|
|
|
2020-03-17 04:31:30 +00:00
|
|
|
sKaleidoAreaPtr = NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-03 03:17:09 +00:00
|
|
|
// NOTE: this function looks messed up and probably doesn't work how it was intended to
|
2020-03-22 21:19:43 +00:00
|
|
|
void* KaleidoManager_GetRamAddr(void* vram) {
|
2021-05-02 23:15:16 +00:00
|
|
|
KaleidoMgrOverlay* iter = gKaleidoMgrCurOvl;
|
|
|
|
KaleidoMgrOverlay* ovl = iter;
|
|
|
|
u32 i;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
if (ovl == NULL) {
|
2020-03-17 04:31:30 +00:00
|
|
|
iter = &gKaleidoMgrOverlayTable[0];
|
2021-05-02 23:15:16 +00:00
|
|
|
for (i = 0; i < ARRAY_COUNT(gKaleidoMgrOverlayTable); i++) {
|
|
|
|
if (((u32)vram >= (u32)iter->vramStart) && ((u32)iter->vramEnd >= (u32)vram)) {
|
2020-03-17 04:31:30 +00:00
|
|
|
KaleidoManager_LoadOvl(iter);
|
|
|
|
ovl = iter;
|
|
|
|
goto KaleidoManager_GetRamAddr_end;
|
|
|
|
}
|
2021-10-03 03:17:09 +00:00
|
|
|
//! @bug Probably missing iter++ here
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("異常\n"); // "Abnormal"
|
2020-03-17 04:31:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
KaleidoManager_GetRamAddr_end:
|
2021-05-02 23:15:16 +00:00
|
|
|
if ((ovl == NULL) || ((u32)vram < (u32)ovl->vramStart) || ((u32)vram >= (u32)ovl->vramEnd)) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return NULL;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-05-02 23:15:16 +00:00
|
|
|
return (void*)((u32)vram + ovl->offset);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|