From ded1d618f4cac77ccba16f5f4b694d7ea28ec54b Mon Sep 17 00:00:00 2001 From: mzxrules Date: Sat, 8 Jun 2024 23:00:13 -0400 Subject: [PATCH 1/4] Document "Normal" Skybox --- include/z64environment.h | 21 +++ include/z64skybox.h | 4 + src/code/z_kankyo.c | 125 ++++++++++-------- src/code/z_vr_box.c | 2 +- .../ovl_file_choose/z_file_choose.c | 4 +- 5 files changed, 101 insertions(+), 55 deletions(-) diff --git a/include/z64environment.h b/include/z64environment.h index 922c544258f..6c3517094bb 100644 --- a/include/z64environment.h +++ b/include/z64environment.h @@ -70,6 +70,27 @@ typedef enum { /* 5 */ WEATHER_MODE_HEAVY_RAIN // scene must define settings for light config 4 } WeatherMode; +typedef enum { +// Clear Sky + SKYBOX_INDEX_CLEAR_SUNRISE, + SKYBOX_INDEX_CLEAR_DAY, + SKYBOX_INDEX_CLEAR_SUNSET, + SKYBOX_INDEX_CLEAR_NIGHT, +// Cloudy Sky + SKYBOX_INDEX_CLOUDY_SUNRISE, + SKYBOX_INDEX_CLOUDY_DAY, + SKYBOX_INDEX_CLOUDY_SUNSET, + SKYBOX_INDEX_CLOUDY_NIGHT, +// Holy (not implemented correctly) + SKYBOX_INDEX_HOLY0, + SKYBOX_INDEX_HOLY_RESERVED_9, + SKYBOX_INDEX_HOLY_RESERVED_10, + SKYBOX_INDEX_HOLY_RESERVED_11, +// Error checking + SKYBOX_INDEX_INIT_MAGIC = 99, // Magic number used to detect a fault during initialization, value unused. + SKYBOX_INDEX_UNDEFINED = 0xFF +} SkyboxIndex; + typedef enum { /* 0 */ CHANGE_SKYBOX_INACTIVE, /* 1 */ CHANGE_SKYBOX_REQUESTED, diff --git a/include/z64skybox.h b/include/z64skybox.h index 73017cbb373..6264050952b 100644 --- a/include/z64skybox.h +++ b/include/z64skybox.h @@ -66,6 +66,10 @@ typedef struct { extern SkyboxFile gNormalSkyFiles[]; +// Tests if the skybox palette for the given skybox should be written to color index 0-127. +// If false, it should be written to color index 128-255 +#define IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(skyboxIndex) ((skyboxIndex & 1) ^ ((skyboxIndex & 4) >> 2)) + void Skybox_Init(struct GameState* state, SkyboxContext* skyboxCtx, s16 skyboxId); Mtx* Skybox_UpdateMatrix(SkyboxContext* skyboxCtx, f32 x, f32 y, f32 z); void Skybox_Draw(SkyboxContext* skyboxCtx, struct GraphicsContext* gfxCtx, s16 skyboxId, s16 blend, f32 x, f32 y, diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index ce79a7df93b..95663e99f40 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -98,86 +98,103 @@ TimeBasedLightEntry sTimeBasedLightConfigs[][7] = { TimeBasedSkyboxEntry gTimeBasedSkyboxConfigs[][9] = { { - { CLOCK_TIME(0, 0), CLOCK_TIME(4, 0) + 1, false, 3, 3 }, - { CLOCK_TIME(4, 0) + 1, CLOCK_TIME(5, 0) + 1, true, 3, 0 }, - { CLOCK_TIME(5, 0) + 1, CLOCK_TIME(6, 0), false, 0, 0 }, - { CLOCK_TIME(6, 0), CLOCK_TIME(8, 0) + 1, true, 0, 1 }, - { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(16, 0), false, 1, 1 }, - { CLOCK_TIME(16, 0), CLOCK_TIME(17, 0) + 1, true, 1, 2 }, - { CLOCK_TIME(17, 0) + 1, CLOCK_TIME(18, 0) + 1, false, 2, 2 }, - { CLOCK_TIME(18, 0) + 1, CLOCK_TIME(19, 0) + 1, true, 2, 3 }, - { CLOCK_TIME(19, 0) + 1, CLOCK_TIME(24, 0) - 1, false, 3, 3 }, + { CLOCK_TIME(0, 0), CLOCK_TIME(4, 0) + 1, false, SKYBOX_INDEX_CLEAR_NIGHT, SKYBOX_INDEX_CLEAR_NIGHT }, + { CLOCK_TIME(4, 0) + 1, CLOCK_TIME(5, 0) + 1, true, SKYBOX_INDEX_CLEAR_NIGHT, SKYBOX_INDEX_CLEAR_SUNRISE }, + { CLOCK_TIME(5, 0) + 1, CLOCK_TIME(6, 0), false, SKYBOX_INDEX_CLEAR_SUNRISE, SKYBOX_INDEX_CLEAR_SUNRISE }, + { CLOCK_TIME(6, 0), CLOCK_TIME(8, 0) + 1, true, SKYBOX_INDEX_CLEAR_SUNRISE, SKYBOX_INDEX_CLEAR_DAY }, + { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(16, 0), false, SKYBOX_INDEX_CLEAR_DAY, SKYBOX_INDEX_CLEAR_DAY }, + { CLOCK_TIME(16, 0), CLOCK_TIME(17, 0) + 1, true, SKYBOX_INDEX_CLEAR_DAY, SKYBOX_INDEX_CLEAR_SUNSET }, + { CLOCK_TIME(17, 0) + 1, CLOCK_TIME(18, 0) + 1, false, SKYBOX_INDEX_CLEAR_SUNSET, SKYBOX_INDEX_CLEAR_SUNSET }, + { CLOCK_TIME(18, 0) + 1, CLOCK_TIME(19, 0) + 1, true, SKYBOX_INDEX_CLEAR_SUNSET, SKYBOX_INDEX_CLEAR_NIGHT }, + { CLOCK_TIME(19, 0) + 1, CLOCK_TIME(24, 0) - 1, false, SKYBOX_INDEX_CLEAR_NIGHT, SKYBOX_INDEX_CLEAR_NIGHT }, }, { - { CLOCK_TIME(0, 0), CLOCK_TIME(4, 0) + 1, false, 7, 7 }, - { CLOCK_TIME(4, 0) + 1, CLOCK_TIME(5, 0) + 1, true, 7, 4 }, - { CLOCK_TIME(5, 0) + 1, CLOCK_TIME(6, 0), false, 4, 4 }, - { CLOCK_TIME(6, 0), CLOCK_TIME(8, 0) + 1, true, 4, 5 }, - { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(16, 0), false, 5, 5 }, - { CLOCK_TIME(16, 0), CLOCK_TIME(17, 0) + 1, true, 5, 6 }, - { CLOCK_TIME(17, 0) + 1, CLOCK_TIME(18, 0) + 1, false, 6, 6 }, - { CLOCK_TIME(18, 0) + 1, CLOCK_TIME(19, 0) + 1, true, 6, 7 }, - { CLOCK_TIME(19, 0) + 1, CLOCK_TIME(24, 0) - 1, false, 7, 7 }, + { CLOCK_TIME(0, 0), CLOCK_TIME(4, 0) + 1, false, SKYBOX_INDEX_CLOUDY_NIGHT, SKYBOX_INDEX_CLOUDY_NIGHT }, + { CLOCK_TIME(4, 0) + 1, CLOCK_TIME(5, 0) + 1, true, SKYBOX_INDEX_CLOUDY_NIGHT, SKYBOX_INDEX_CLOUDY_SUNRISE }, + { CLOCK_TIME(5, 0) + 1, CLOCK_TIME(6, 0), false, SKYBOX_INDEX_CLOUDY_SUNRISE, SKYBOX_INDEX_CLOUDY_SUNRISE }, + { CLOCK_TIME(6, 0), CLOCK_TIME(8, 0) + 1, true, SKYBOX_INDEX_CLOUDY_SUNRISE, SKYBOX_INDEX_CLOUDY_DAY }, + { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(16, 0), false, SKYBOX_INDEX_CLOUDY_DAY, SKYBOX_INDEX_CLOUDY_DAY }, + { CLOCK_TIME(16, 0), CLOCK_TIME(17, 0) + 1, true, SKYBOX_INDEX_CLOUDY_DAY, SKYBOX_INDEX_CLOUDY_SUNSET }, + { CLOCK_TIME(17, 0) + 1, CLOCK_TIME(18, 0) + 1, false, SKYBOX_INDEX_CLOUDY_SUNSET, SKYBOX_INDEX_CLOUDY_SUNSET }, + { CLOCK_TIME(18, 0) + 1, CLOCK_TIME(19, 0) + 1, true, SKYBOX_INDEX_CLOUDY_SUNSET, SKYBOX_INDEX_CLOUDY_NIGHT }, + { CLOCK_TIME(19, 0) + 1, CLOCK_TIME(24, 0) - 1, false, SKYBOX_INDEX_CLOUDY_NIGHT, SKYBOX_INDEX_CLOUDY_NIGHT }, }, { - { CLOCK_TIME(0, 0), CLOCK_TIME(2, 0) + 1, false, 3, 3 }, - { CLOCK_TIME(2, 0) + 1, CLOCK_TIME(4, 0) + 1, true, 3, 0 }, - { CLOCK_TIME(4, 0) + 1, CLOCK_TIME(8, 0) + 1, false, 0, 0 }, - { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(10, 0), true, 0, 1 }, - { CLOCK_TIME(10, 0), CLOCK_TIME(14, 0) + 1, false, 1, 1 }, - { CLOCK_TIME(14, 0) + 1, CLOCK_TIME(16, 0), true, 1, 2 }, - { CLOCK_TIME(16, 0), CLOCK_TIME(20, 0) + 1, false, 2, 2 }, - { CLOCK_TIME(20, 0) + 1, CLOCK_TIME(22, 0), true, 2, 3 }, - { CLOCK_TIME(22, 0), CLOCK_TIME(24, 0) - 1, false, 3, 3 }, + { CLOCK_TIME(0, 0), CLOCK_TIME(2, 0) + 1, false, SKYBOX_INDEX_CLEAR_NIGHT, SKYBOX_INDEX_CLEAR_NIGHT }, + { CLOCK_TIME(2, 0) + 1, CLOCK_TIME(4, 0) + 1, true, SKYBOX_INDEX_CLEAR_NIGHT, SKYBOX_INDEX_CLEAR_SUNRISE }, + { CLOCK_TIME(4, 0) + 1, CLOCK_TIME(8, 0) + 1, false, SKYBOX_INDEX_CLEAR_SUNRISE, SKYBOX_INDEX_CLEAR_SUNRISE }, + { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(10, 0), true, SKYBOX_INDEX_CLEAR_SUNRISE, SKYBOX_INDEX_CLEAR_DAY }, + { CLOCK_TIME(10, 0), CLOCK_TIME(14, 0) + 1, false, SKYBOX_INDEX_CLEAR_DAY, SKYBOX_INDEX_CLEAR_DAY }, + { CLOCK_TIME(14, 0) + 1, CLOCK_TIME(16, 0), true, SKYBOX_INDEX_CLEAR_DAY, SKYBOX_INDEX_CLEAR_SUNSET }, + { CLOCK_TIME(16, 0), CLOCK_TIME(20, 0) + 1, false, SKYBOX_INDEX_CLEAR_SUNSET, SKYBOX_INDEX_CLEAR_SUNSET }, + { CLOCK_TIME(20, 0) + 1, CLOCK_TIME(22, 0), true, SKYBOX_INDEX_CLEAR_SUNSET, SKYBOX_INDEX_CLEAR_NIGHT }, + { CLOCK_TIME(22, 0), CLOCK_TIME(24, 0) - 1, false, SKYBOX_INDEX_CLEAR_NIGHT, SKYBOX_INDEX_CLEAR_NIGHT }, }, { - { CLOCK_TIME(0, 0), CLOCK_TIME(5, 0) + 1, false, 11, 11 }, - { CLOCK_TIME(5, 0) + 1, CLOCK_TIME(6, 0), true, 11, 8 }, - { CLOCK_TIME(6, 0), CLOCK_TIME(7, 0), false, 8, 8 }, - { CLOCK_TIME(7, 0), CLOCK_TIME(8, 0) + 1, true, 8, 9 }, - { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(16, 0), false, 9, 9 }, - { CLOCK_TIME(16, 0), CLOCK_TIME(17, 0) + 1, true, 9, 10 }, - { CLOCK_TIME(17, 0) + 1, CLOCK_TIME(18, 0) + 1, false, 10, 10 }, - { CLOCK_TIME(18, 0) + 1, CLOCK_TIME(19, 0) + 1, true, 10, 11 }, - { CLOCK_TIME(19, 0) + 1, CLOCK_TIME(24, 0) - 1, false, 11, 11 }, + { CLOCK_TIME(0, 0), CLOCK_TIME(5, 0) + 1, false, SKYBOX_INDEX_HOLY_RESERVED_11, SKYBOX_INDEX_HOLY_RESERVED_11 }, + { CLOCK_TIME(5, 0) + 1, CLOCK_TIME(6, 0), true, SKYBOX_INDEX_HOLY_RESERVED_11, SKYBOX_INDEX_HOLY0 }, + { CLOCK_TIME(6, 0), CLOCK_TIME(7, 0), false, SKYBOX_INDEX_HOLY0, SKYBOX_INDEX_HOLY0 }, + { CLOCK_TIME(7, 0), CLOCK_TIME(8, 0) + 1, true, SKYBOX_INDEX_HOLY0, SKYBOX_INDEX_HOLY_RESERVED_9 }, + { CLOCK_TIME(8, 0) + 1, CLOCK_TIME(16, 0), false, SKYBOX_INDEX_HOLY_RESERVED_9, SKYBOX_INDEX_HOLY_RESERVED_9 }, + { CLOCK_TIME(16, 0), CLOCK_TIME(17, 0) + 1, true, SKYBOX_INDEX_HOLY_RESERVED_9, SKYBOX_INDEX_HOLY_RESERVED_10 }, + { CLOCK_TIME(17, 0) + 1, CLOCK_TIME(18, 0) + 1, false, SKYBOX_INDEX_HOLY_RESERVED_10, + SKYBOX_INDEX_HOLY_RESERVED_10 }, + { CLOCK_TIME(18, 0) + 1, CLOCK_TIME(19, 0) + 1, true, SKYBOX_INDEX_HOLY_RESERVED_10, + SKYBOX_INDEX_HOLY_RESERVED_11 }, + { CLOCK_TIME(19, 0) + 1, CLOCK_TIME(24, 0) - 1, false, SKYBOX_INDEX_HOLY_RESERVED_11, + SKYBOX_INDEX_HOLY_RESERVED_11 }, }, }; +//! @brief File data for the "normal" skybox used in the overworld. +//! Up to two different skyboxes can loaded at once for the purpose of blending. Skyboxes can only +//! transition either to the next step in the day night cycle (e.g clear day to clear sunset), +//! or the opposing weather condition in the same step of the day/night cycle (e.g. cloudy night to clear night). +// +//! The skybox image data is color indexed, capped to a maximum 128 colors to allow the palette data for two different +//! skyboxes to fit in one 256 color tlut. This means the image data for the skyboxes is required to alternate between +//! starting at color index 0 and color index 128. +// +//! IS_NORMAL_SKY_PALETTE_ALLOC_FRONT depends on the order of this table to determine where to write palette data. SkyboxFile gNormalSkyFiles[] = { + // Clear Sky { - ROM_FILE(vr_fine0_static), + ROM_FILE(vr_fine0_static), // color index start 128 ROM_FILE(vr_fine0_pal_static), }, { - ROM_FILE(vr_fine1_static), + ROM_FILE(vr_fine1_static), // color index start 0 ROM_FILE(vr_fine1_pal_static), }, { - ROM_FILE(vr_fine2_static), + ROM_FILE(vr_fine2_static), // color index start 128 ROM_FILE(vr_fine2_pal_static), }, { - ROM_FILE(vr_fine3_static), + ROM_FILE(vr_fine3_static), // color index start 0 ROM_FILE(vr_fine3_pal_static), }, + // Cloudy Sky { - ROM_FILE(vr_cloud0_static), + ROM_FILE(vr_cloud0_static), // color index start 0 ROM_FILE(vr_cloud0_pal_static), }, { - ROM_FILE(vr_cloud1_static), + ROM_FILE(vr_cloud1_static), // color index start 128 ROM_FILE(vr_cloud1_pal_static), }, { - ROM_FILE(vr_cloud2_static), + ROM_FILE(vr_cloud2_static), // color index start 0 ROM_FILE(vr_cloud2_pal_static), }, { - ROM_FILE(vr_cloud3_static), + ROM_FILE(vr_cloud3_static), // color index start 128 ROM_FILE(vr_cloud3_pal_static), }, + // Holy Sky + // Will appear incorrect due to IS_NORMAL_SKY_PALETTE_ALLOC_FRONT putting the palette at color index 128 { - ROM_FILE(vr_holy0_static), + ROM_FILE(vr_holy0_static), // color index start 0 ROM_FILE(vr_holy0_pal_static), }, }; @@ -279,8 +296,8 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused) Lights_DirectionalSetInfo(&envCtx->dirLight2, 80, 80, 80, 80, 80, 80); LightContext_InsertLight(play, &play->lightCtx, &envCtx->dirLight2); - envCtx->skybox1Index = 99; - envCtx->skybox2Index = 99; + envCtx->skybox1Index = SKYBOX_INDEX_INIT_MAGIC; + envCtx->skybox2Index = SKYBOX_INDEX_INIT_MAGIC; envCtx->changeSkyboxState = CHANGE_SKYBOX_INACTIVE; envCtx->changeSkyboxTimer = 0; @@ -648,8 +665,8 @@ void Environment_UpdateStorm(EnvironmentContext* envCtx, u8 unused) { void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxContext* skyboxCtx) { u32 size; u8 i; - u8 newSkybox1Index = 0xFF; - u8 newSkybox2Index = 0xFF; + u8 newSkybox1Index = SKYBOX_INDEX_UNDEFINED; + u8 newSkybox2Index = SKYBOX_INDEX_UNDEFINED; u8 skyboxBlend = 0; if (skyboxId == SKYBOX_CUTSCENE_MAP) { @@ -719,7 +736,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon } #if OOT_DEBUG - if (newSkybox1Index == 0xFF) { + if (newSkybox1Index == SKYBOX_INDEX_UNDEFINED) { // "Environment VR data acquisition failed! Report to Sasaki!" PRINTF(VT_COL(RED, WHITE) "\n環境VRデータ取得失敗! ささきまでご報告を!" VT_RST); } @@ -750,7 +767,8 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon if (envCtx->skyboxDmaState == SKYBOX_DMA_TEXTURE1_DONE) { envCtx->skyboxDmaState = SKYBOX_DMA_TLUT1_START; - if ((newSkybox1Index & 1) ^ ((newSkybox1Index & 4) >> 2)) { + if (IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(newSkybox1Index)) { + // Reserve palette at the front size = gNormalSkyFiles[newSkybox1Index].palette.vromEnd - gNormalSkyFiles[newSkybox1Index].palette.vromStart; @@ -759,6 +777,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon gNormalSkyFiles[newSkybox1Index].palette.vromStart, size, 0, &envCtx->loadQueue, NULL, "../z_kankyo.c", 1307); } else { + // Reserve palette at the back size = gNormalSkyFiles[newSkybox1Index].palette.vromEnd - gNormalSkyFiles[newSkybox1Index].palette.vromStart; osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1); @@ -771,7 +790,8 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon if (envCtx->skyboxDmaState == SKYBOX_DMA_TEXTURE2_DONE) { envCtx->skyboxDmaState = SKYBOX_DMA_TLUT2_START; - if ((newSkybox2Index & 1) ^ ((newSkybox2Index & 4) >> 2)) { + if (IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(newSkybox2Index)) { + // Reserve palette at the front size = gNormalSkyFiles[newSkybox2Index].palette.vromEnd - gNormalSkyFiles[newSkybox2Index].palette.vromStart; @@ -780,6 +800,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon gNormalSkyFiles[newSkybox2Index].palette.vromStart, size, 0, &envCtx->loadQueue, NULL, "../z_kankyo.c", 1342); } else { + // Reserve palette at the back size = gNormalSkyFiles[newSkybox2Index].palette.vromEnd - gNormalSkyFiles[newSkybox2Index].palette.vromStart; osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1); diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c index caebcec0b8e..a56d02e53c0 100644 --- a/src/code/z_vr_box.c +++ b/src/code/z_vr_box.c @@ -502,7 +502,7 @@ void Skybox_Setup(PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId) { DMA_REQUEST_SYNC(skyboxCtx->staticSegments[1], gNormalSkyFiles[skybox2Index].file.vromStart, size, "../z_vr_box.c", 1064); - if ((skybox1Index & 1) ^ ((skybox1Index & 4) >> 2)) { + if (IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(skybox1Index)) { size = gNormalSkyFiles[skybox1Index].palette.vromEnd - gNormalSkyFiles[skybox1Index].palette.vromStart; skyboxCtx->palettes = GAME_STATE_ALLOC(&play->state, size * 2, "../z_vr_box.c", 1072); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 13a4e46032a..9efcf789f11 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1846,8 +1846,8 @@ void FileSelect_InitContext(GameState* thisx) { envCtx->changeLightEnabled = false; envCtx->changeLightTimer = 0; envCtx->skyboxDmaState = SKYBOX_DMA_INACTIVE; - envCtx->skybox1Index = 99; - envCtx->skybox2Index = 99; + envCtx->skybox1Index = SKYBOX_INDEX_INIT_MAGIC; + envCtx->skybox2Index = SKYBOX_INDEX_INIT_MAGIC; envCtx->lightConfig = 0; envCtx->changeLightNextConfig = 0; envCtx->lightSetting = 0; From 78f6eee516b81ad82bd9cb2897394bca36629f4f Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 17 Jun 2024 22:52:06 -0400 Subject: [PATCH 2/4] fix .bss shift in gfxbuffers.c --- src/buffers/gfxbuffers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/buffers/gfxbuffers.c b/src/buffers/gfxbuffers.c index fa466bc8290..64f935119a2 100644 --- a/src/buffers/gfxbuffers.c +++ b/src/buffers/gfxbuffers.c @@ -1,4 +1,5 @@ -#include "z64.h" +#include "alignment.h" +#include "gfx.h" ALIGNED(16) u64 gGfxSPTaskOutputBuffer[0x3000]; From 81011406f387decaeb51c75b44545a6fd74a4ed0 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Mon, 23 Sep 2024 20:18:51 -0400 Subject: [PATCH 3/4] PR suggestions, minor comment tweaks --- include/z64environment.h | 2 +- include/z64skybox.h | 6 +-- src/code/z_kankyo.c | 43 ++++++++++--------- src/code/z_vr_box.c | 2 +- .../ovl_file_choose/z_file_choose.c | 4 +- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/include/z64environment.h b/include/z64environment.h index 2b6143a5691..3e711b07c31 100644 --- a/include/z64environment.h +++ b/include/z64environment.h @@ -87,7 +87,7 @@ typedef enum { SKYBOX_INDEX_HOLY_RESERVED_10, SKYBOX_INDEX_HOLY_RESERVED_11, // Error checking - SKYBOX_INDEX_INIT_MAGIC = 99, // Magic number used to detect a fault during initialization, value unused. + SKYBOX_INDEX_INIT = 99, // Magic number used to detect a fault during initialization, value unused. SKYBOX_INDEX_UNDEFINED = 0xFF } SkyboxIndex; diff --git a/include/z64skybox.h b/include/z64skybox.h index 21cc92556d5..4f174f16723 100644 --- a/include/z64skybox.h +++ b/include/z64skybox.h @@ -66,9 +66,9 @@ typedef struct SkyboxFile { extern SkyboxFile gNormalSkyFiles[]; -// Tests if the skybox palette for the given skybox should be written to color index 0-127. -// If false, it should be written to color index 128-255 -#define IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(skyboxIndex) ((skyboxIndex & 1) ^ ((skyboxIndex & 4) >> 2)) +// Tests if the skybox palette for the given skybox is assigned to color index 0-127. +// If false, it is assigned to color index 128-255 instead. +#define IS_NORMAL_SKYBOX_IMAGE_COLOR_INDEX_0(skyboxIndex) ((skyboxIndex & 1) ^ ((skyboxIndex & 4) >> 2)) void Skybox_Init(struct GameState* state, SkyboxContext* skyboxCtx, s16 skyboxId); Mtx* Skybox_UpdateMatrix(SkyboxContext* skyboxCtx, f32 x, f32 y, f32 z); diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 027dc48f24e..8a7107fa25d 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -146,16 +146,19 @@ TimeBasedSkyboxEntry gTimeBasedSkyboxConfigs[][9] = { }, }; -//! @brief File data for the "normal" skybox used in the overworld. -//! Up to two different skyboxes can loaded at once for the purpose of blending. Skyboxes can only -//! transition either to the next step in the day night cycle (e.g clear day to clear sunset), -//! or the opposing weather condition in the same step of the day/night cycle (e.g. cloudy night to clear night). -// -//! The skybox image data is color indexed, capped to a maximum 128 colors to allow the palette data for two different -//! skyboxes to fit in one 256 color tlut. This means the image data for the skyboxes is required to alternate between -//! starting at color index 0 and color index 128. -// -//! IS_NORMAL_SKY_PALETTE_ALLOC_FRONT depends on the order of this table to determine where to write palette data. +/** + * File data for the "normal" skybox used in the overworld. + * + * Up to two different skyboxes can loaded at once for the purpose of blending. Skyboxes can only + * transition either to the next step in the day night cycle (e.g clear day to clear sunset), + * or the opposing weather condition in the same step of the day/night cycle (e.g. cloudy night to clear night). + * + * The skybox image data is color indexed, capped to a maximum 128 colors to allow the palette data for two different + * skyboxes to fit in one 256 color tlut. This means the image data for the skyboxes is required to alternate between + * starting at color index 0 and color index 128. + * + * IS_NORMAL_SKYBOX_IMAGE_COLOR_INDEX_0 depends on the order of this table to determine where to write palette data. + */ SkyboxFile gNormalSkyFiles[] = { // Clear Sky { @@ -191,8 +194,8 @@ SkyboxFile gNormalSkyFiles[] = { ROM_FILE(vr_cloud3_static), // color index start 128 ROM_FILE(vr_cloud3_pal_static), }, - // Holy Sky - // Will appear incorrect due to IS_NORMAL_SKY_PALETTE_ALLOC_FRONT putting the palette at color index 128 + // Holy Sky (Unused) + // Will appear incorrectly due to IS_NORMAL_SKYBOX_IMAGE_COLOR_INDEX_0 putting the palette at color index 128 { ROM_FILE(vr_holy0_static), // color index start 0 ROM_FILE(vr_holy0_pal_static), @@ -294,8 +297,8 @@ void Environment_Init(PlayState* play2, EnvironmentContext* envCtx, s32 unused) Lights_DirectionalSetInfo(&envCtx->dirLight2, 80, 80, 80, 80, 80, 80); LightContext_InsertLight(play, &play->lightCtx, &envCtx->dirLight2); - envCtx->skybox1Index = SKYBOX_INDEX_INIT_MAGIC; - envCtx->skybox2Index = SKYBOX_INDEX_INIT_MAGIC; + envCtx->skybox1Index = SKYBOX_INDEX_INIT; + envCtx->skybox2Index = SKYBOX_INDEX_INIT; envCtx->changeSkyboxState = CHANGE_SKYBOX_INACTIVE; envCtx->changeSkyboxTimer = 0; @@ -765,8 +768,8 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon if (envCtx->skyboxDmaState == SKYBOX_DMA_TEXTURE1_DONE) { envCtx->skyboxDmaState = SKYBOX_DMA_TLUT1_START; - if (IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(newSkybox1Index)) { - // Reserve palette at the front + if (IS_NORMAL_SKYBOX_IMAGE_COLOR_INDEX_0(newSkybox1Index)) { + // Reserve palette color index 0-127 size = gNormalSkyFiles[newSkybox1Index].palette.vromEnd - gNormalSkyFiles[newSkybox1Index].palette.vromStart; @@ -775,7 +778,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon gNormalSkyFiles[newSkybox1Index].palette.vromStart, size, 0, &envCtx->loadQueue, NULL, "../z_kankyo.c", 1307); } else { - // Reserve palette at the back + // Reserve palette color index 128-255 size = gNormalSkyFiles[newSkybox1Index].palette.vromEnd - gNormalSkyFiles[newSkybox1Index].palette.vromStart; osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1); @@ -788,8 +791,8 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon if (envCtx->skyboxDmaState == SKYBOX_DMA_TEXTURE2_DONE) { envCtx->skyboxDmaState = SKYBOX_DMA_TLUT2_START; - if (IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(newSkybox2Index)) { - // Reserve palette at the front + if (IS_NORMAL_SKYBOX_IMAGE_COLOR_INDEX_0(newSkybox2Index)) { + // Reserve palette color index 0-127 size = gNormalSkyFiles[newSkybox2Index].palette.vromEnd - gNormalSkyFiles[newSkybox2Index].palette.vromStart; @@ -798,7 +801,7 @@ void Environment_UpdateSkybox(u8 skyboxId, EnvironmentContext* envCtx, SkyboxCon gNormalSkyFiles[newSkybox2Index].palette.vromStart, size, 0, &envCtx->loadQueue, NULL, "../z_kankyo.c", 1342); } else { - // Reserve palette at the back + // Reserve palette color index 128-255 size = gNormalSkyFiles[newSkybox2Index].palette.vromEnd - gNormalSkyFiles[newSkybox2Index].palette.vromStart; osCreateMesgQueue(&envCtx->loadQueue, &envCtx->loadMsg, 1); diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c index 04e592a9289..c03f09ec697 100644 --- a/src/code/z_vr_box.c +++ b/src/code/z_vr_box.c @@ -504,7 +504,7 @@ void Skybox_Setup(PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId) { DMA_REQUEST_SYNC(skyboxCtx->staticSegments[1], gNormalSkyFiles[skybox2Index].file.vromStart, size, "../z_vr_box.c", 1064); - if (IS_NORMAL_SKY_PALETTE_ALLOC_FRONT(skybox1Index)) { + if (IS_NORMAL_SKYBOX_IMAGE_COLOR_INDEX_0(skybox1Index)) { size = gNormalSkyFiles[skybox1Index].palette.vromEnd - gNormalSkyFiles[skybox1Index].palette.vromStart; skyboxCtx->palettes = GAME_STATE_ALLOC(&play->state, size * 2, "../z_vr_box.c", 1072); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 3f562db125b..83de8f420d7 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1908,8 +1908,8 @@ void FileSelect_InitContext(GameState* thisx) { envCtx->changeLightEnabled = false; envCtx->changeLightTimer = 0; envCtx->skyboxDmaState = SKYBOX_DMA_INACTIVE; - envCtx->skybox1Index = SKYBOX_INDEX_INIT_MAGIC; - envCtx->skybox2Index = SKYBOX_INDEX_INIT_MAGIC; + envCtx->skybox1Index = SKYBOX_INDEX_INIT; + envCtx->skybox2Index = SKYBOX_INDEX_INIT; envCtx->lightConfig = 0; envCtx->changeLightNextConfig = 0; envCtx->lightSetting = 0; From b2000a7a9a3d55b3317bda626908b0626d6069e6 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Tue, 24 Sep 2024 00:46:49 -0400 Subject: [PATCH 4/4] add increment_block_number to fix kankyo bss issue --- src/code/main.c | 2 +- src/code/z_kankyo.c | 5 +++-- src/overlays/actors/ovl_Fishing/z_fishing.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/code/main.c b/src/code/main.c index e17005a9804..d1b7cc82053 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -22,7 +22,7 @@ extern struct IrqMgr gIrqMgr; #include "n64dd.h" #endif -#pragma increment_block_number "gc-eu:192 gc-eu-mq:192 gc-jp:192 gc-jp-ce:160 gc-jp-mq:192 gc-us:192 gc-us-mq:192" \ +#pragma increment_block_number "gc-eu:192 gc-eu-mq:160 gc-jp:192 gc-jp-ce:160 gc-jp-mq:192 gc-us:192 gc-us-mq:192" \ "ntsc-1.2:160" extern u8 _buffersSegmentEnd[]; diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 8a7107fa25d..f83cd013a47 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -1,3 +1,4 @@ +#pragma increment_block_number "gc-eu:0 gc-eu-mq:128 gc-jp:0 gc-jp-ce:0 gc-jp-mq:0 gc-us:0 gc-us-mq:0 ntsc-1.2:0" #include "global.h" #include "ultra64.h" #include "terminal.h" @@ -7,7 +8,7 @@ #include "assets/objects/gameplay_keep/gameplay_keep.h" #include "assets/objects/gameplay_field_keep/gameplay_field_keep.h" -#pragma increment_block_number "gc-eu:0 gc-eu-mq:0 gc-jp:0 gc-jp-ce:0 gc-jp-mq:0 gc-us:0 gc-us-mq:0 ntsc-1.2:0" +#pragma increment_block_number "gc-eu:0 gc-eu-mq:128 gc-jp:0 gc-jp-ce:0 gc-jp-mq:0 gc-us:0 gc-us-mq:0 ntsc-1.2:0" typedef enum LightningBoltState { /* 0x00 */ LIGHTNING_BOLT_START, @@ -232,7 +233,7 @@ s16 sLightningFlashAlpha; s16 sSunDepthTestX; s16 sSunDepthTestY; -#pragma increment_block_number "gc-eu:240 gc-eu-mq:240 gc-jp:216 gc-jp-ce:214 gc-jp-mq:216 gc-us:216 gc-us-mq:216" \ +#pragma increment_block_number "gc-eu:240 gc-eu-mq:128 gc-jp:216 gc-jp-ce:214 gc-jp-mq:216 gc-us:216 gc-us-mq:216" \ "ntsc-1.2:224" LightNode* sNGameOverLightNode; diff --git a/src/overlays/actors/ovl_Fishing/z_fishing.c b/src/overlays/actors/ovl_Fishing/z_fishing.c index cd783233a5b..a1328e138b9 100644 --- a/src/overlays/actors/ovl_Fishing/z_fishing.c +++ b/src/overlays/actors/ovl_Fishing/z_fishing.c @@ -16,7 +16,7 @@ #include "cic6105.h" #endif -#pragma increment_block_number "gc-eu:125 gc-eu-mq:125 gc-jp:127 gc-jp-ce:124 gc-jp-mq:127 gc-us:127 gc-us-mq:127" +#pragma increment_block_number "gc-eu:125 gc-eu-mq:122 gc-jp:127 gc-jp-ce:124 gc-jp-mq:127 gc-us:127 gc-us-mq:127" #define FLAGS ACTOR_FLAG_4