1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-02 15:55:59 +00:00
oot/src/code/z_kaleido_manager.c

107 lines
3.6 KiB
C
Raw Normal View History

#include "global.h"
#include "terminal.h"
2020-03-17 04:31:30 +00:00
#define KALEIDO_OVERLAY(name, nameString) \
{ \
NULL, (uintptr_t)_ovl_##name##SegmentRomStart, (uintptr_t)_ovl_##name##SegmentRomEnd, \
_ovl_##name##SegmentStart, _ovl_##name##SegmentEnd, 0, nameString, \
2020-03-17 04:31:30 +00:00
}
KaleidoMgrOverlay gKaleidoMgrOverlayTable[] = {
KALEIDO_OVERLAY(kaleido_scope, "kaleido_scope"),
KALEIDO_OVERLAY(player_actor, "player_actor"),
2020-03-17 04:31:30 +00:00
};
void* sKaleidoAreaPtr = NULL;
KaleidoMgrOverlay* gKaleidoMgrCurOvl = NULL;
u8 gBossMarkState = 0;
2020-03-17 04:31:30 +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);
2020-03-17 04:31:30 +00:00
ovl->loadedRamAddr = sKaleidoAreaPtr;
Overlay_Load(ovl->vromStart, ovl->vromEnd, ovl->vramStart, ovl->vramEnd, ovl->loadedRamAddr);
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,
(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);
ovl->offset = (u32)ovl->loadedRamAddr - (u32)ovl->vramStart;
2020-03-17 04:31:30 +00:00
gKaleidoMgrCurOvl = ovl;
}
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;
}
}
void KaleidoManager_Init(PlayState* play) {
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
}
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_FGCOL(GREEN));
osSyncPrintf("KaleidoArea の最大サイズは %d バイトを確保します\n", largestSize);
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_RST);
sKaleidoAreaPtr = GameState_Alloc(&play->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);
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_FGCOL(GREEN));
osSyncPrintf("KaleidoArea %08x - %08x\n", sKaleidoAreaPtr, (u32)sKaleidoAreaPtr + largestSize);
2020-03-17 04:31:30 +00:00
osSyncPrintf(VT_RST);
gKaleidoMgrCurOvl = NULL;
2020-03-17 04:31:30 +00:00
}
2022-03-21 19:49:11 +00:00
void KaleidoManager_Destroy(void) {
if (gKaleidoMgrCurOvl != NULL) {
2020-03-17 04:31:30 +00:00
KaleidoManager_ClearOvl(gKaleidoMgrCurOvl);
gKaleidoMgrCurOvl = NULL;
}
2020-03-17 04:31:30 +00:00
sKaleidoAreaPtr = NULL;
}
Fix/cleanup/rephrase miscellaneous stuff (#983) * Add parens around params usage in VEC_SET macro * Remove unnecessary space character in a xml * Use defines instead of magic values in head/tail magic comments * Use `OS_USEC_TO_CYCLES` to make a time look better in `Graph_TaskSet00` * `0x25800` -> `sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])` * `0x803DA800` -> `0x80400000 - frame buffer size` * Use `OS_VI_` defines instead of hex * Add empty line after some variable declarations * Remove unused `extern CutsceneData` in `z_bg_dy_yoseizo.c` * `Matrix_MtxFToYXZRotS` does not use `MTXMODE_` * Use `MTXMODE_` more * Remove `ASCII_TO_U32`, use `'IS64'` * Add explicit `!= NULL` in some ternaries * Use `INV_CONTENT`, `AMMO` macros more * Use `PLAYER_AP_` enum more to compare to `Player#heldItemActionParam` * Get rid of lowercase hex (outside libultra) * `gWindMill*` -> `gWindmill*` * Format and small fix enums in `z_boss_mo.h` * Use `CHECK_BTN_ANY` more * Fix xz/xy mistake in comment in tektite * Rephrase comments mentioning "the devs" in a more neutral way * Clean-up some objectively useless parens * Fix some negative values written as u16 instead of s16 in ichains * `SKJ_ACTON_` -> `SKJ_ACTION_` * Run formatter * Fix unk_ offset of `TransformUpdateIndex#unk_10` -> `unk_0E` * Remove comments using in-game text * Remove `U` suffix from integer literals * Revert "Remove `ASCII_TO_U32`, use `'IS64'`" This reverts commit c801337dde9fe5e8b7a7ecf85ad3629bf5b87aaf. * Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)` * Add empty line after decl x2 * Revert "Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`" This reverts commit d80bdb32da449edc74e02b8ab3f5a2c532e74bdb. * Make `CUR_UPG_VALUE(UPG_STRENGTH)` compare to integers (eventually needs its own enum) * Only use `PLAYER_SHIELD_` enum with `Player#currentShield` * Only use `PLAYER_TUNIC_` enum with `Player#currentTunic`
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) {
KaleidoMgrOverlay* iter = gKaleidoMgrCurOvl;
KaleidoMgrOverlay* ovl = iter;
u32 i;
2020-03-17 04:31:30 +00:00
if (ovl == NULL) {
2020-03-17 04:31:30 +00:00
iter = &gKaleidoMgrOverlayTable[0];
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;
}
Fix/cleanup/rephrase miscellaneous stuff (#983) * Add parens around params usage in VEC_SET macro * Remove unnecessary space character in a xml * Use defines instead of magic values in head/tail magic comments * Use `OS_USEC_TO_CYCLES` to make a time look better in `Graph_TaskSet00` * `0x25800` -> `sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])` * `0x803DA800` -> `0x80400000 - frame buffer size` * Use `OS_VI_` defines instead of hex * Add empty line after some variable declarations * Remove unused `extern CutsceneData` in `z_bg_dy_yoseizo.c` * `Matrix_MtxFToYXZRotS` does not use `MTXMODE_` * Use `MTXMODE_` more * Remove `ASCII_TO_U32`, use `'IS64'` * Add explicit `!= NULL` in some ternaries * Use `INV_CONTENT`, `AMMO` macros more * Use `PLAYER_AP_` enum more to compare to `Player#heldItemActionParam` * Get rid of lowercase hex (outside libultra) * `gWindMill*` -> `gWindmill*` * Format and small fix enums in `z_boss_mo.h` * Use `CHECK_BTN_ANY` more * Fix xz/xy mistake in comment in tektite * Rephrase comments mentioning "the devs" in a more neutral way * Clean-up some objectively useless parens * Fix some negative values written as u16 instead of s16 in ichains * `SKJ_ACTON_` -> `SKJ_ACTION_` * Run formatter * Fix unk_ offset of `TransformUpdateIndex#unk_10` -> `unk_0E` * Remove comments using in-game text * Remove `U` suffix from integer literals * Revert "Remove `ASCII_TO_U32`, use `'IS64'`" This reverts commit c801337dde9fe5e8b7a7ecf85ad3629bf5b87aaf. * Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)` * Add empty line after decl x2 * Revert "Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`" This reverts commit d80bdb32da449edc74e02b8ab3f5a2c532e74bdb. * Make `CUR_UPG_VALUE(UPG_STRENGTH)` compare to integers (eventually needs its own enum) * Only use `PLAYER_SHIELD_` enum with `Player#currentShield` * Only use `PLAYER_TUNIC_` enum with `Player#currentTunic`
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
osSyncPrintf("異常\n"); // "Abnormal"
2020-03-17 04:31:30 +00:00
return NULL;
}
KaleidoManager_GetRamAddr_end:
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
return (void*)((u32)vram + ovl->offset);
2020-03-17 04:31:30 +00:00
}