From f19d490243bceb91aed3dac0c1fc400d11ca6865 Mon Sep 17 00:00:00 2001 From: JaceCear <11230293+JaceCear@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:01:19 +0100 Subject: [PATCH] Some Sp Stage documentation and a crash fix (#187) --- src/game/special_stage/main.c | 10 +++++----- src/game/special_stage/player.c | 11 ++++++----- src/game/special_stage/utils.c | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/game/special_stage/main.c b/src/game/special_stage/main.c index 75b403a8a..9475b05dd 100644 --- a/src/game/special_stage/main.c +++ b/src/game/special_stage/main.c @@ -130,10 +130,10 @@ void CreateSpecialStage(s16 selectedCharacter, s16 level) static void SetupIntroScreenRegisters(void) { - gDispCnt = 0x1641; - gBgCntRegs[1] = 0x703; - gBgCntRegs[2] = 0xD086; - gBldRegs.bldCnt = 0xAF; + gDispCnt = (DISPCNT_OBJ_ON | DISPCNT_BG1_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_1D_MAP | DISPCNT_MODE_1); + gBgCntRegs[1] = (BGCNT_TXT256x256 | BGCNT_16COLOR | BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7)); + gBgCntRegs[2] = (BGCNT_TXT512x512 | BGCNT_256COLOR | BGCNT_PRIORITY(2) | BGCNT_CHARBASE(1) | BGCNT_SCREENBASE(16)); + gBldRegs.bldCnt = BLDCNT_EFFECT_LIGHTEN | (BLDCNT_TGT1_ALL & ~BLDCNT_TGT1_OBJ); gBldRegs.bldY = 0x10; gBgScrollRegs[1][0] = 0; @@ -716,7 +716,7 @@ static void Task_ShowIntroScreen(void) { struct SpecialStage *stage = TASK_DATA(gCurTask); SetupIntroScreenRegisters(); - sub_806CA88(&stage->introText, RENDER_TARGET_SCREEN, 0x28, 0x37C, 0, 0x78, 0x50, 0, 0, 0); + sub_806CA88(&stage->introText, RENDER_TARGET_SCREEN, 0x28, 0x37C, 0, (DISPLAY_WIDTH / 2), (DISPLAY_HEIGHT / 2), 0, 0, 0); stage->state = 1; m4aSongNumStart(MUS_SPECIAL_STAGE_INTRO); diff --git a/src/game/special_stage/player.c b/src/game/special_stage/player.c index 4b359227a..ac25822a9 100644 --- a/src/game/special_stage/player.c +++ b/src/game/special_stage/player.c @@ -106,7 +106,8 @@ struct Task *CreateSpecialStagePlayer(struct SpecialStage *stage) s->graphics.dest = player->unkA0; s->graphics.size = 0; s->graphics.anim = SA2_ANIM_SP_STAGE_ARROW; - s->frameFlags = 0x107E; + s->frameFlags = SPRITE_FLAG(PRIORITY, 1) | SPRITE_FLAG(ROT_SCALE_DOUBLE_SIZE, 1) | SPRITE_FLAG(ROT_SCALE_ENABLE, 1) + | SPRITE_FLAG(ROT_SCALE, 30); s->x = (DISPLAY_WIDTH / 2); s->y = (DISPLAY_HEIGHT / 2); s->oamFlags = SPRITE_OAM_ORDER(0); @@ -296,19 +297,19 @@ void sub_806D4E4(void) void sub_806D548(Sprite *s, void *vram, s16 a, u8 b, const struct UNK_80DF670 *c4) { - u32 unk10 = 0x1000; + u32 frameFlags = SPRITE_FLAG(PRIORITY, 1); if (c4->unk7 & 1) { - unk10 |= 0x400; + frameFlags |= SPRITE_FLAG(X_FLIP, 1); } if (c4->unk7 & 2) { - unk10 |= 0x800; + frameFlags |= SPRITE_FLAG(Y_FLIP, 1); } s->graphics.dest = vram; s->graphics.size = 0; s->graphics.anim = c4->anim; - s->frameFlags = unk10; + s->frameFlags = frameFlags; s->x = (DISPLAY_WIDTH / 2); s->y = a; s->oamFlags = SPRITE_OAM_ORDER(b); diff --git a/src/game/special_stage/utils.c b/src/game/special_stage/utils.c index c81e28950..5cf8995b9 100644 --- a/src/game/special_stage/utils.c +++ b/src/game/special_stage/utils.c @@ -60,11 +60,20 @@ void sub_806CA88(Sprite *obj, s8 target, u32 size, u16 anim, u32 unk10, s16 xPos // TODO: SpecialStageCollectables_UNK874 is probably it's own type bool16 sub_806CB84(struct UNK_806CB84 *a, struct SpecialStageCollectables_UNK874_2 *unk874, struct SpecialStage *stage) { - struct SpecialStageWorld *world = TASK_DATA(stage->worldTask); + struct SpecialStageWorld *world; s32 r9; s32 r4; s16 val2, val; +#ifdef BUG_FIX + // worldTask can sometimes be NULL when directly calling Special Stage code + if (stage->worldTask == NULL) { + return FALSE; + } +#endif + + world = TASK_DATA(stage->worldTask); + { u16 deg = -stage->cameraBearing & 0x3FF; s32 r2 = SIN(deg) * 4; @@ -181,14 +190,14 @@ void InitSpecialStageScreenVram(void) gUnknown_03005B58 = NULL; } -void sub_806CEC4(Background *background, u32 a, u32 b, u8 assetId, u16 d, u16 e, u16 palOffset, u8 bg_id, u16 scrollX, u16 scrollY) +void sub_806CEC4(Background *background, u32 a, u32 b, u8 tilemapId, u16 d, u16 e, u16 palOffset, u8 bg_id, u16 scrollX, u16 scrollY) { background->graphics.dest = (void *)BG_CHAR_ADDR(a); background->graphics.anim = 0; background->layoutVram = (void *)BG_SCREEN_ADDR(b); background->unk18 = 0; background->unk1A = 0; - background->tilemapId = assetId; + background->tilemapId = tilemapId; background->unk1E = 0; background->unk20 = 0; background->unk22 = 0;