diff options
| author | cadmic <cadmic24@gmail.com> | 2024-04-14 14:51:32 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-14 23:51:32 +0200 |
| commit | f643499462f8cf908ddf1ee77b5625ebaff2cf25 (patch) | |
| tree | 852eb24ec8f3c8c507d779c4878be92cf5ff36c7 /src/code | |
| parent | a94661054ed8e7ac895c3f4df07b8ac339fc3ce0 (diff) | |
Match retail BSS ordering (#1927)
* Match retail BSS ordering
* Revert moving some global variables to headers
* Adjust block numbers after header changes
* Fix debug build
* Overlay bss ordering
* Fix BSS ordering after header changes
* gc-eu-mq OK
* Implement preprocessor for #pragma increment_block_number
* Transfer usage comment from reencode.sh
* Use temporary directory instead of temporary file
* Move ColChkMassType back
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/fault.c | 19 | ||||
| -rw-r--r-- | src/code/fault_drawer.c | 7 | ||||
| -rw-r--r-- | src/code/sys_math3d.c | 4 | ||||
| -rw-r--r-- | src/code/z_actor.c | 7 | ||||
| -rw-r--r-- | src/code/z_camera.c | 6 | ||||
| -rw-r--r-- | src/code/z_collision_check.c | 26 | ||||
| -rw-r--r-- | src/code/z_common_data.c | 5 | ||||
| -rw-r--r-- | src/code/z_kaleido_scope_call.c | 5 | ||||
| -rw-r--r-- | src/code/z_kankyo.c | 14 | ||||
| -rw-r--r-- | src/code/z_play.c | 24 |
10 files changed, 81 insertions, 36 deletions
diff --git a/src/code/fault.c b/src/code/fault.c index 8b05fb820..662c1a9f1 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -44,6 +44,15 @@ #include "terminal.h" #include "alloca.h" +// For retail BSS ordering, the block number of sFaultInstance must be 0 or +// just above (the exact upper bound depends on the block numbers assigned to +// extern variables declared in headers). +#if OOT_DEBUG +#pragma increment_block_number 20 +#else +#pragma increment_block_number 25 +#endif + void FaultDrawer_Init(void); void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled); void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color); @@ -76,21 +85,11 @@ const char* sFpExceptionNames[] = { "Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", "Inexact operation", }; -#ifndef NON_MATCHING -// TODO: match .bss (has reordering issues) -extern FaultMgr* sFaultInstance; -extern u8 sFaultAwaitingInput; -extern STACK(sFaultStack, 0x600); -extern StackEntry sFaultThreadInfo; -extern FaultMgr gFaultMgr; -#else -// Non-matching version for struct shiftability FaultMgr* sFaultInstance; u8 sFaultAwaitingInput; STACK(sFaultStack, 0x600); StackEntry sFaultThreadInfo; FaultMgr gFaultMgr; -#endif typedef struct { /* 0x00 */ s32 (*callback)(void*, void*); diff --git a/src/code/fault_drawer.c b/src/code/fault_drawer.c index 8f5fbcbe4..5c82b7a0b 100644 --- a/src/code/fault_drawer.c +++ b/src/code/fault_drawer.c @@ -99,15 +99,8 @@ FaultDrawer sFaultDrawerDefault = { NULL, }; -#ifndef NON_MATCHING -// TODO: match .bss (has reordering issues) -extern FaultDrawer sFaultDrawer; -extern char D_8016B6C0[0x20]; -#else -// Non-matching version for struct shiftability FaultDrawer sFaultDrawer; char D_8016B6C0[0x20]; -#endif void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) { sFaultDrawer.osSyncPrintfEnabled = enabled; diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 3e50249b1..a3b8ca2d6 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1,6 +1,10 @@ #include "global.h" #include "terminal.h" +// For retail BSS ordering, the block number of cbf in Math3D_CylVsCylOverlapCenterDist +// must be 0. +#pragma increment_block_number 190 + s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, diff --git a/src/code/z_actor.c b/src/code/z_actor.c index dfa9d88dd..5e8b86aaa 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -8,6 +8,9 @@ #include "assets/objects/gameplay_dangeon_keep/gameplay_dangeon_keep.h" #include "assets/objects/object_bdoor/object_bdoor.h" +// For retail BSS ordering, the block number of sCurCeilingPoly +// must be between 2 and 243 inclusive. + static CollisionPoly* sCurCeilingPoly; static s32 sCurCeilingBgId; @@ -1894,7 +1897,9 @@ s32 func_8002F9EC(PlayState* play, Actor* actor, CollisionPoly* poly, s32 bgId, return false; } -// Local data used for Farore's Wind light (stored in BSS, possibly a struct?) +#pragma increment_block_number 22 + +// Local data used for Farore's Wind light (stored in BSS) LightInfo D_8015BC00; LightNode* D_8015BC10; s32 D_8015BC14; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index a54d64070..4caafe18c 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -4,6 +4,10 @@ #include "terminal.h" #include "overlays/actors/ovl_En_Horse/z_en_horse.h" +// For retail BSS ordering, the block number of D_8015BD7C +// must be between 88 and 123 inclusive. +#pragma increment_block_number 30 + s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags); s32 Camera_RequestModeImpl(Camera* camera, s16 requestedMode, u8 forceModeChange); s32 Camera_UpdateWater(Camera* camera); @@ -3628,6 +3632,8 @@ s32 Camera_KeepOn3(Camera* camera) { return 1; } +#pragma increment_block_number 100 + s32 Camera_KeepOn4(Camera* camera) { static Vec3f D_8015BD50; static Vec3f D_8015BD60; diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 14822cf1c..118a445d7 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -7,6 +7,10 @@ typedef void (*ColChkApplyFunc)(PlayState*, CollisionCheckContext*, Collider*); typedef void (*ColChkVsFunc)(PlayState*, CollisionCheckContext*, Collider*, Collider*); typedef s32 (*ColChkLineFunc)(PlayState*, CollisionCheckContext*, Collider*, Vec3f*, Vec3f*); +// For retail BSS ordering, the block number of sparkInit in CollisionCheck_BlueBlood +// must be between 183 and 255 inclusive. +#pragma increment_block_number 50 + #if OOT_DEBUG /** * Draws a red triangle with vertices vA, vB, and vC. @@ -2238,8 +2242,10 @@ void CollisionCheck_ATCylVsACQuad(PlayState* play, CollisionCheckContext* colChk } } +#if OOT_DEBUG static s8 sBssDummy0; static s8 sBssDummy1; +#endif void CollisionCheck_ATQuadVsACCyl(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol, Collider* acCol) { static TriNorm tri1; @@ -2300,10 +2306,12 @@ void CollisionCheck_ATQuadVsACCyl(PlayState* play, CollisionCheckContext* colChk } } +#if OOT_DEBUG static s8 sBssDummy3; static s8 sBssDummy4; static s8 sBssDummy5; static s8 sBssDummy6; +#endif void CollisionCheck_ATTrisVsACTris(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol, Collider* acCol) { @@ -2350,10 +2358,12 @@ void CollisionCheck_ATTrisVsACTris(PlayState* play, CollisionCheckContext* colCh } } +#if OOT_DEBUG static s8 sBssDummy7; static s8 sBssDummy8; static s8 sBssDummy9; static s8 sBssDummy10; +#endif void CollisionCheck_ATTrisVsACQuad(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol, Collider* acCol) { @@ -2586,9 +2596,10 @@ static ColChkApplyFunc sColChkApplyFuncs[] = { */ void CollisionCheck_SetHitEffects(PlayState* play, CollisionCheckContext* colChkCtx) { Collider** acColP; + Collider* acCol; for (acColP = colChkCtx->colAC; acColP < colChkCtx->colAC + colChkCtx->colACCount; acColP++) { - Collider* acCol = *acColP; + acCol = *acColP; if (acCol != NULL && acCol->acFlags & AC_ON) { if (acCol->actor != NULL && acCol->actor->update == NULL) { @@ -2635,9 +2646,10 @@ static ColChkVsFunc sACVsFuncs[COLSHAPE_MAX][COLSHAPE_MAX] = { */ void CollisionCheck_AC(PlayState* play, CollisionCheckContext* colChkCtx, Collider* atCol) { Collider** acColP; + Collider* acCol; for (acColP = colChkCtx->colAC; acColP < colChkCtx->colAC + colChkCtx->colACCount; acColP++) { - Collider* acCol = *acColP; + acCol = *acColP; if (acCol != NULL && acCol->acFlags & AC_ON) { if (acCol->actor != NULL && acCol->actor->update == NULL) { @@ -2661,12 +2673,13 @@ void CollisionCheck_AC(PlayState* play, CollisionCheckContext* colChkCtx, Collid */ void CollisionCheck_AT(PlayState* play, CollisionCheckContext* colChkCtx) { Collider** atColP; + Collider* atCol; if (colChkCtx->colATCount == 0 || colChkCtx->colACCount == 0) { return; } for (atColP = colChkCtx->colAT; atColP < colChkCtx->colAT + colChkCtx->colATCount; atColP++) { - Collider* atCol = *atColP; + atCol = *atColP; if (atCol != NULL && atCol->atFlags & AT_ON) { if (atCol->actor != NULL && atCol->actor->update == NULL) { @@ -2684,6 +2697,8 @@ typedef enum { /* 2 */ MASSTYPE_NORMAL } ColChkMassType; +#pragma increment_block_number 253 + /** * Get mass type. Immovable colliders cannot be pushed, while heavy colliders can only be pushed by heavy and immovable * colliders. @@ -3134,9 +3149,10 @@ static ColChkApplyFunc sApplyDamageFuncs[COLSHAPE_MAX] = { */ void CollisionCheck_Damage(PlayState* play, CollisionCheckContext* colChkCtx) { s32 i; + Collider* col; for (i = 0; i < colChkCtx->colACCount; i++) { - Collider* col = colChkCtx->colAC[i]; + col = colChkCtx->colAC[i]; if (col == NULL) { continue; @@ -3312,12 +3328,14 @@ void Collider_SetTrisDim(PlayState* play, ColliderTris* tris, s32 elemIndex, Col Collider_SetTrisElementDim(play, &trisElem->dim, src); } +#if OOT_DEBUG // Due to an unknown reason, bss ordering changed between the 2 static Vec3f variables in the function below. // In order to reproduce this behavior, we need a specific number of bss variables in the file before that point. // For this, we introduce a certain amount of dummy variables throughout the file, which we fit inside padding added // by the compiler between structs like TriNorm and/or Vec3f, so they don't take space in bss. static s8 sBssDummy11; static s8 sBssDummy12; +#endif /** * Updates the world spheres for all of the collider's JntSph elements attached to the specified limb diff --git a/src/code/z_common_data.c b/src/code/z_common_data.c index 2d7c36fc8..47aecd9e6 100644 --- a/src/code/z_common_data.c +++ b/src/code/z_common_data.c @@ -1,5 +1,10 @@ #include "global.h" +// For retail BSS ordering, the block number of D_8015FA88 must be 0 or +// just above (the exact upper bound depends on the block numbers assigned to +// extern variables declared in headers). +#pragma increment_block_number 60 + ALIGNED(16) SaveContext gSaveContext; u32 D_8015FA88; u32 D_8015FA8C; diff --git a/src/code/z_kaleido_scope_call.c b/src/code/z_kaleido_scope_call.c index be1d9aa59..7b53b8521 100644 --- a/src/code/z_kaleido_scope_call.c +++ b/src/code/z_kaleido_scope_call.c @@ -1,6 +1,11 @@ #include "global.h" #include "terminal.h" +// For retail BSS ordering, the block number of sKaleidoScopeUpdateFunc must be 0 or +// just above (the exact upper bound depends on the block numbers assigned to +// extern variables declared in headers). +#pragma increment_block_number 60 + void (*sKaleidoScopeUpdateFunc)(PlayState* play); void (*sKaleidoScopeDrawFunc)(PlayState* play); f32 gBossMarkScale; diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index db8080735..ce79a7df9 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -4,6 +4,11 @@ #include "assets/objects/gameplay_keep/gameplay_keep.h" #include "assets/objects/gameplay_field_keep/gameplay_field_keep.h" +// For retail BSS ordering, the block number of sLensFlareUnused must be lower +// than the extern variables declared in the header (e.g. gLightningStrike) +// while the block number of sNGameOverLightNode must be higher. +#pragma increment_block_number 80 + typedef enum { /* 0x00 */ LIGHTNING_BOLT_START, /* 0x01 */ LIGHTNING_BOLT_WAIT, @@ -183,7 +188,7 @@ f32 sSandstormLerpScale = 0.0f; u8 gCustomLensFlareOn; Vec3f gCustomLensFlarePos; -s16 gLensFlareUnused; +s16 sLensFlareUnused; s16 gLensFlareScale; f32 gLensFlareColorIntensity; s16 gLensFlareGlareStrength; @@ -207,6 +212,11 @@ s16 sLightningFlashAlpha; s16 sSunDepthTestX; s16 sSunDepthTestY; +// These variables could be moved farther down in the file to reduce the amount +// of block number padding here, but currently this causes BSS ordering issues +// for debug. +#pragma increment_block_number 230 + LightNode* sNGameOverLightNode; LightInfo sNGameOverLightInfo; LightNode* sSGameOverLightNode; @@ -2208,7 +2218,7 @@ void Environment_DrawCustomLensFlare(PlayState* play) { pos.y = gCustomLensFlarePos.y; pos.z = gCustomLensFlarePos.z; - Environment_DrawLensFlare(play, &play->envCtx, &play->view, play->state.gfxCtx, pos, gLensFlareUnused, + Environment_DrawLensFlare(play, &play->envCtx, &play->view, play->state.gfxCtx, pos, sLensFlareUnused, gLensFlareScale, gLensFlareColorIntensity, gLensFlareGlareStrength, false); } } diff --git a/src/code/z_play.c b/src/code/z_play.c index c418c4089..f86986839 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -9,9 +9,9 @@ UNK_TYPE D_8012D1F4 = 0; // unused Input* D_8012D1F8 = NULL; -TransitionTile sTransitionTile; +TransitionTile gTransitionTile; s32 gTransitionTileState; -VisMono sPlayVisMono; +VisMono gPlayVisMono; Color_RGBA8_u32 gVisMonoColor; #if OOT_DEBUG @@ -199,7 +199,7 @@ void Play_Destroy(GameState* thisx) { CollisionCheck_DestroyContext(this, &this->colChkCtx); if (gTransitionTileState == TRANS_TILE_READY) { - TransitionTile_Destroy(&sTransitionTile); + TransitionTile_Destroy(&gTransitionTile); gTransitionTileState = TRANS_TILE_OFF; } @@ -211,7 +211,7 @@ void Play_Destroy(GameState* thisx) { Letterbox_Destroy(); TransitionFade_Destroy(&this->transitionFadeFlash); - VisMono_Destroy(&sPlayVisMono); + VisMono_Destroy(&gPlayVisMono); if (gSaveContext.save.linkAge != this->linkAgeOnLoad) { Inventory_SwapAgeEquipment(); @@ -409,7 +409,7 @@ void Play_Init(GameState* thisx) { TransitionFade_SetType(&this->transitionFadeFlash, TRANS_INSTANCE_TYPE_FADE_FLASH); TransitionFade_SetColor(&this->transitionFadeFlash, RGBA8(160, 160, 160, 255)); TransitionFade_Start(&this->transitionFadeFlash); - VisMono_Init(&sPlayVisMono); + VisMono_Init(&gPlayVisMono); gVisMonoColor.a = 0; CutsceneFlags_UnsetAll(this); @@ -521,18 +521,18 @@ void Play_Update(PlayState* this) { if (gTransitionTileState != TRANS_TILE_OFF) { switch (gTransitionTileState) { case TRANS_TILE_PROCESS: - if (TransitionTile_Init(&sTransitionTile, 10, 7) == NULL) { + if (TransitionTile_Init(&gTransitionTile, 10, 7) == NULL) { PRINTF("fbdemo_init呼出し失敗!\n"); // "fbdemo_init call failed!" gTransitionTileState = TRANS_TILE_OFF; } else { - sTransitionTile.zBuffer = (u16*)gZBuffer; + gTransitionTile.zBuffer = (u16*)gZBuffer; gTransitionTileState = TRANS_TILE_READY; R_UPDATE_RATE = 1; } break; case TRANS_TILE_READY: - TransitionTile_Update(&sTransitionTile); + TransitionTile_Update(&gTransitionTile); break; default: @@ -687,7 +687,7 @@ void Play_Update(PlayState* this) { this->transitionMode = TRANS_MODE_OFF; if (gTransitionTileState == TRANS_TILE_READY) { - TransitionTile_Destroy(&sTransitionTile); + TransitionTile_Destroy(&gTransitionTile); gTransitionTileState = TRANS_TILE_OFF; R_UPDATE_RATE = 3; } @@ -1135,8 +1135,8 @@ void Play_Draw(PlayState* this) { TransitionFade_Draw(&this->transitionFadeFlash, &gfxP); if (gVisMonoColor.a > 0) { - sPlayVisMono.vis.primColor.rgba = gVisMonoColor.rgba; - VisMono_Draw(&sPlayVisMono, &gfxP); + gPlayVisMono.vis.primColor.rgba = gVisMonoColor.rgba; + VisMono_Draw(&gPlayVisMono, &gfxP); } gSPEndDisplayList(gfxP++); @@ -1147,7 +1147,7 @@ void Play_Draw(PlayState* this) { if (gTransitionTileState == TRANS_TILE_READY) { Gfx* sp88 = POLY_OPA_DISP; - TransitionTile_Draw(&sTransitionTile, &sp88); + TransitionTile_Draw(&gTransitionTile, &sp88); POLY_OPA_DISP = sp88; goto Play_Draw_DrawOverlayElements; } |
