diff --git a/asm/non_matching/subtask2/Subtask_FadeIn.inc b/asm/non_matching/subtask2/Subtask_FadeIn.inc deleted file mode 100644 index 041a2026..00000000 --- a/asm/non_matching/subtask2/Subtask_FadeIn.inc +++ /dev/null @@ -1,87 +0,0 @@ - .syntax unified - push {r4, lr} - ldr r0, _080A72E8 @ =gFadeControl - ldrb r0, [r0] - cmp r0, #0 - bne _080A72E4 - ldr r0, _080A72EC @ =gScreen - ldr r1, _080A72F0 @ =gUnk_03001020 - movs r2, #0x7c - bl MemCopy - ldr r0, _080A72F4 @ =gPaletteBuffer - ldr r1, _080A72F8 @ =gUnk_02024090 - movs r2, #0x80 - lsls r2, r2, #3 - bl MemCopy - ldr r0, _080A72FC @ =gGFXSlots - ldr r4, _080A7300 @ =gUnk_02032F14 - movs r2, #0x85 - lsls r2, r2, #2 - adds r1, r4, #0 - bl MemCopy - ldr r0, _080A7304 @ =gPaletteList - movs r2, #0x85 - lsls r2, r2, #2 - adds r1, r4, r2 - movs r2, #0x40 - bl MemCopy - ldr r0, _080A7308 @ =gRoomControls - adds r1, r4, #0 - subs r1, #0x38 - movs r2, #0x38 - bl MemCopy - ldr r0, _080A730C @ =gUnk_03000420 - movs r2, #0x95 - lsls r2, r2, #2 - adds r1, r4, r2 - movs r2, #0x80 - lsls r2, r2, #1 - bl MemCopy - ldr r0, _080A7310 @ =gActiveScriptInfo - movs r2, #0xd5 - lsls r2, r2, #2 - adds r1, r4, r2 - movs r2, #0xc - bl MemCopy - bl sub_0805E958 - adds r1, r4, #0 - subs r1, #0x54 - ldr r0, _080A7314 @ =gRoomTransition - adds r0, #0x2f - ldrb r0, [r0] - strb r0, [r1, #0xd] - ldr r0, _080A7318 @ =gPlayerState - adds r0, #0x8b - ldrb r0, [r0] - strb r0, [r1, #0xc] - ldr r0, _080A731C @ =gCurrentRoomProperties - ldr r0, [r0] - str r0, [r1, #0x10] - ldr r0, _080A7320 @ =gMapBottom - ldr r0, [r0] - str r0, [r1, #0x14] - ldr r0, _080A7324 @ =gMapTop - ldr r0, [r0] - str r0, [r1, #0x18] - movs r0, #1 - strb r0, [r1] -_080A72E4: - pop {r4, pc} - .align 2, 0 -_080A72E8: .4byte gFadeControl -_080A72EC: .4byte gScreen -_080A72F0: .4byte gUnk_03001020 -_080A72F4: .4byte gPaletteBuffer -_080A72F8: .4byte gUnk_02024090 -_080A72FC: .4byte gGFXSlots -_080A7300: .4byte gUnk_02032F14 -_080A7304: .4byte gPaletteList -_080A7308: .4byte gRoomControls -_080A730C: .4byte gUnk_03000420 -_080A7310: .4byte gActiveScriptInfo -_080A7314: .4byte gRoomTransition -_080A7318: .4byte gPlayerState -_080A731C: .4byte gCurrentRoomProperties -_080A7320: .4byte gMapBottom -_080A7324: .4byte gMapTop - .syntax divided diff --git a/include/entity.h b/include/entity.h index 618bb701..30bc9a75 100644 --- a/include/entity.h +++ b/include/entity.h @@ -485,6 +485,8 @@ void SetInitializationPriority(void); */ void ResetSystemPriority(void); +void sub_0805E958(void); + /** * LinkedList's which point to allocate Entities. * These work together with Entity.prev and Entity.next fields diff --git a/include/main.h b/include/main.h index 0a2c97bf..134ca8e0 100644 --- a/include/main.h +++ b/include/main.h @@ -2,7 +2,9 @@ #define MAIN_H #include "global.h" -#include "room.h" // just to get the type of screenTransitionData +#include "structures.h" +#include "room.h" +#include "script.h" /** File signature */ #define SIGNATURE 'MCZ3' @@ -69,19 +71,28 @@ typedef struct { * HUD structure. */ typedef struct { - /*0x00*/ u8 nextToLoad; - /*0x01*/ u8 _1; - /*0x02*/ u8 lastState; - /*0x03*/ u8 field_0x3; - /*0x04*/ u8 state; - /*0x05*/ u8 field_0x5; - /*0x06*/ u8 field_0x6; - /*0x07*/ u8 pauseFadeIn; - /*0x08*/ u16 isLoading; - /*0x0A*/ u16 fadeInTime; - /*0x0C*/ u8 fillerC[0x10]; - /*0x1c*/ RoomControls unk_1c; - /*0x2e+4*/ u8 unk_2e[0x360]; + /*0x000*/ u8 nextToLoad; + /*0x001*/ u8 _1; + /*0x002*/ u8 lastState; + /*0x003*/ u8 field_0x3; + /*0x004*/ u8 state; + /*0x005*/ u8 field_0x5; + /*0x006*/ u8 field_0x6; + /*0x007*/ u8 pauseFadeIn; + /*0x008*/ u16 fadeType; + /*0x00A*/ u16 fadeInTime; + /*0x00C*/ u8 controlMode; + /*0x00D*/ u8 unk_d; + /*0x00E*/ u8 unk_e; + /*0x00F*/ u8 unk_f; + /*0x010*/ void** currentRoomProperties; + /*0x014*/ u16* mapBottomBgControlPtr; + /*0x018*/ u16* mapTopBgControlPtr; + /*0x01C*/ RoomControls roomControls; + /*0x054*/ GfxSlotList gfxSlotList; + /*0x268*/ Palette palettes[0x10]; + /*0x2A8*/ u8 unk_2a8[0x100]; + /*0x3A8*/ ActiveScriptInfo activeScriptInfo; } UI; static_assert(sizeof(UI) == 0x3b4); diff --git a/include/room.h b/include/room.h index f4663028..747379b6 100644 --- a/include/room.h +++ b/include/room.h @@ -216,6 +216,8 @@ typedef enum { TILE_ENTITY_D, } TileEntityType; +extern void** gCurrentRoomProperties; + void SetTileType(u32, u32, u32); void InitScreenShake(u32 time, u32 magnitude); diff --git a/linker.ld b/linker.ld index cfb9da2a..0d37d73a 100644 --- a/linker.ld +++ b/linker.ld @@ -105,8 +105,6 @@ SECTIONS { . = 0x00030EB4; gUnk_02030EB4 = .; . = 0x00031EC0; gUnk_02031EC0 = .; . = 0x00032EC0; gUI = .; - . = 0x00032EDC; gUnk_02032EDC = .; - . = 0x00032F14; gUnk_02032F14 = .; . = 0x00033280; gActiveScriptInfo = .; . = 0x00033290; gUnk_02033290 = .; . = 0x00033A90; gArea = .; diff --git a/src/enterPortalSubtask.c b/src/enterPortalSubtask.c index c9f49205..5e616656 100644 --- a/src/enterPortalSubtask.c +++ b/src/enterPortalSubtask.c @@ -89,7 +89,7 @@ void sub_0804AB70(void) { gScreen.bg1.yOffset = 0; controls->scroll_y = 0; portalId = gArea.portal_type; - if ((portalId == 2) && (gUI.unk_1c.area != 2)) { + if ((portalId == 2) && (gUI.roomControls.area != 2)) { portalId = 3; } ptr = &gUnk_080D4138[portalId * 2]; @@ -142,7 +142,7 @@ bool32 sub_0804ACA8(void) { void sub_0804ACC8(void) { if (gFadeControl.active == 0) { SetGlobalFlag(gArea.portal_type + ENTRANCE_0); - sub_0804AD6C((RoomControls*)&gUI.unk_1c); + sub_0804AD6C(&gUI.roomControls); sub_080A71F4(0); } } diff --git a/src/game.c b/src/game.c index 2d76138e..325b71c9 100644 --- a/src/game.c +++ b/src/game.c @@ -1828,11 +1828,11 @@ void sub_0805368C(void) { } void sub_080536A8(void) { - sub_080A71C4(5, 5, 4, 0x10); + sub_080A71C4(5, 5, FADE_INSTANT, 0x10); } void sub_080536B8(void) { - sub_080A71C4(5, 3, 4, 4); + sub_080A71C4(5, 3, FADE_INSTANT, 4); SetFade(FADE_IN_OUT | FADE_INSTANT, 0x100); } @@ -1972,7 +1972,7 @@ void sub_08053B10(void) { } void sub_08053B3C(void) { - sub_080A71C4(5, 4, 5, 0x100); + sub_080A71C4(5, 4, FADE_IN_OUT | FADE_INSTANT, 0x100); SetFade(FADE_IN_OUT | FADE_INSTANT, 0x100); } @@ -2002,7 +2002,7 @@ void sub_08053BBC(void) { } void sub_08053BE8(void) { - sub_080A71C4(5, 2, 5, 0x100); + sub_080A71C4(5, 2, FADE_IN_OUT | FADE_INSTANT, 0x100); SetFade(FADE_IN_OUT | FADE_INSTANT, 0x100); } diff --git a/src/roomInit.c b/src/roomInit.c index 927e090c..680b3a2d 100644 --- a/src/roomInit.c +++ b/src/roomInit.c @@ -4974,7 +4974,7 @@ extern u32 script_PlayerIntro; void sub_StateChange_HouseInteriors2_LinksHouseBedroom(void) { if (!CheckGlobalFlag(START) && !CheckLocalFlag(0x46)) { - sub_080A71C4(5, 1, 4, 4); + sub_080A71C4(5, 1, FADE_INSTANT, 4); gUpdateVisibleTiles = 0; SetFade(FADE_IN_OUT | FADE_INSTANT, 256); sub_080751E8(0, 6, &script_PlayerIntro); diff --git a/src/subtask2.c b/src/subtask2.c index 1a9d51c5..9717352c 100644 --- a/src/subtask2.c +++ b/src/subtask2.c @@ -30,6 +30,9 @@ extern u8 gUnk_08128C00[]; extern Frame* gSpriteAnimations_322[]; extern u32 gUnk_085C4620[]; extern u16* gMoreSpritePtrs[]; +extern Screen gUnk_03001020; +extern u8 gUnk_02024090[]; +extern u8 gUnk_03000420[]; void sub_080A5CFC(u32, void*, u32); void sub_080A6FB4(u32, u32); @@ -1262,7 +1265,7 @@ void MenuFadeIn(u32 param_1, u32 param_2) { gUI.nextToLoad = 1; } gUI.field_0x6 = 0; - gUI.isLoading = -1; + gUI.fadeType = -1; gUI.fadeInTime = 0x20; gMain.substate = GAMEMAIN_SUBTASK; SetFade(FADE_IN_OUT | FADE_INSTANT, 0x20); @@ -1272,16 +1275,16 @@ void MenuFadeIn(u32 param_1, u32 param_2) { void sub_080A71A4(u32 param_1, u32 param_2, u32 param_3) { if (gUI.nextToLoad == 0) { - gUI.fillerC[2] = param_3; + gUI.unk_e = param_3; } else { - gUI.fillerC[3] = param_3; + gUI.unk_f = param_3; } MenuFadeIn(param_1, param_2); } -void sub_080A71C4(u32 param_1, u32 param_2, u32 param_3, u32 param_4) { +void sub_080A71C4(u32 param_1, u32 param_2, u32 fadeType, u32 param_4) { MenuFadeIn(param_1, param_2); - gUI.isLoading = param_3; + gUI.fadeType = fadeType; gUI.fadeInTime = param_4; } @@ -1312,7 +1315,24 @@ void GameMain_Subtask(void) { gUnk_0812901C[gUI.nextToLoad](); } -ASM_FUNC("asm/non_matching/subtask2/Subtask_FadeIn.inc", void Subtask_FadeIn()) +void Subtask_FadeIn(void) { + if (!gFadeControl.active) { + MemCopy(&gScreen, &gUnk_03001020, sizeof(Screen)); + MemCopy(gPaletteBuffer, gUnk_02024090, 0x400); + MemCopy(&gGFXSlots, &gUI.gfxSlotList, sizeof(GfxSlotList)); + MemCopy(gPaletteList, gUI.palettes, sizeof(gUI.palettes)); + MemCopy(&gRoomControls, &gUI.roomControls, sizeof(RoomControls)); + MemCopy(gUnk_03000420, gUI.unk_2a8, sizeof(gUI.unk_2a8)); + MemCopy(&gActiveScriptInfo, &gUI.activeScriptInfo, sizeof(ActiveScriptInfo)); + sub_0805E958(); + gUI.unk_d = gRoomTransition.field_0x2c[2]; + gUI.controlMode = gPlayerState.controlMode; + gUI.currentRoomProperties = gCurrentRoomProperties; + gUI.mapBottomBgControlPtr = gMapBottom.bgControlPtr; + gUI.mapTopBgControlPtr = gMapTop.bgControlPtr; + gUI.nextToLoad = 1; + } +} void Subtask_Init(void) { if (gFadeControl.active == 0) { @@ -1332,7 +1352,34 @@ void Subtask_Init(void) { } } -ASM_FUNC("asm/non_matching/subtask2/Subtask_FadeOut.inc", void Subtask_FadeOut()) +void Subtask_FadeOut(void) { + if (!gFadeControl.active) { + DeleteAllEntities(); + sub_0805E974(); + gCurrentRoomProperties = gUI.currentRoomProperties; + gPlayerState.controlMode = gUI.controlMode; + gMapBottom.bgControlPtr = gUI.mapBottomBgControlPtr; + gMapTop.bgControlPtr = gUI.mapTopBgControlPtr; + MemCopy(&gUI.activeScriptInfo, &gActiveScriptInfo, sizeof(ActiveScriptInfo)); + MemCopy(gUI.unk_2a8, gUnk_03000420, sizeof(gUI.unk_2a8)); + MemCopy(gUI.palettes, gPaletteList, sizeof(gUI.palettes)); + MemCopy(&gUI.gfxSlotList, &gGFXSlots, sizeof(gGFXSlots)); + MemCopy(&gUI.roomControls, &gRoomControls, sizeof(RoomControls)); + MemCopy(&gUnk_03001020, &gScreen, sizeof(Screen)); + gArea.localFlagOffset = GetFlagBankOffset(gRoomControls.area); + gArea.pCurrentRoomInfo = GetCurrentRoomInfo(); + RestoreGameTask(gUI.field_0x6); + sub_0801D000(gUI.unk_d != 0); + sub_080A74F4(); + if (gUI.fadeType != 0xffff) { + SetFade(gUI.fadeType, gUI.fadeInTime); + } else { + SetFadeInverted(gUI.fadeInTime); + } + gUI.nextToLoad = 4; + gRoomTransition.field_0x2c[3] = 0; + } +} void Subtask_Die(void) { sub_080A74F4();