From 4c43661cf34544a6ffc6817912021de5679e8f42 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Tue, 12 Oct 2021 14:25:20 +0100 Subject: [PATCH] Decompile the GameStateOverlay table (#337) * Decomp GameStateOverlayTable * spec * Review * gSchedContext * Format * Fix bss --- include/functions.h | 4 +- include/variables.h | 14 +- include/z64.h | 160 +++--------------- spec | 2 +- src/boot_O2_g3/fault_drawer.c | 2 +- src/boot_O2_g3/idle.c | 1 - src/code/z_game_dlftbls.c | 26 +++ .../ovl_file_choose/z_file_choose.h | 2 + 8 files changed, 58 insertions(+), 153 deletions(-) create mode 100644 src/code/z_game_dlftbls.c diff --git a/include/functions.h b/include/functions.h index 685a246959..8c8b76a3e6 100644 --- a/include/functions.h +++ b/include/functions.h @@ -107,7 +107,7 @@ void FaultDrawer_VPrintf(const char* str, char* args); void FaultDrawer_Printf(const char* fmt, ...); void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...); void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h); -void FaultDrawer_SetInputCallback(func_ptr func); +void FaultDrawer_SetInputCallback(void* func); void FaultDrawer_Init(void); void func_80084940(void); void func_80084968(void); @@ -3010,7 +3010,7 @@ void func_80165438(UNK_PTR param_1); // void func_80165EC0(void); // void func_80166060(void); Gfx* func_801660B8(GlobalContext* globalCtx, Gfx* gfx); -void Play_Fini(GlobalContext* globalCtx); +void Play_Fini(GameState* gameState); // void func_801663C4(void); // void func_80166644(void); // void func_801668B4(void); diff --git a/include/variables.h b/include/variables.h index eddb73875d..7d6969543e 100644 --- a/include/variables.h +++ b/include/variables.h @@ -937,13 +937,13 @@ extern s16 actorCutsceneReturnCamera; extern s16 D_801BD8C6; extern ColliderCylinderInit fireObjCollisionInit; extern FireObjLightParams D_801BD8FC[2]; -extern GameStateOverlay gGameStateOverlayTable; -extern GameStateOverlay D_801BD940; -extern GameStateOverlay titleGameStateInfo; -extern GameStateOverlay mainGameStateInfo; -extern GameStateOverlay openingGameStateInfo; -extern GameStateOverlay fileChooseGameStateInfo; -extern GameStateOverlay daytelopGameStateInfo; +extern GameStateOverlay gGameStateOverlayTable[]; +// extern GameStateOverlay D_801BD940; +// extern GameStateOverlay titleGameStateInfo; +// extern GameStateOverlay mainGameStateInfo; +// extern GameStateOverlay openingGameStateInfo; +// extern GameStateOverlay fileChooseGameStateInfo; +// extern GameStateOverlay daytelopGameStateInfo; // extern UNK_TYPE4 graphNumGameStates; // extern UNK_TYPE2 D_801BDA70; // extern UNK_TYPE2 D_801BDA74; diff --git a/include/z64.h b/include/z64.h index 0061eb547b..6e179ebe22 100644 --- a/include/z64.h +++ b/include/z64.h @@ -411,10 +411,6 @@ typedef void*(*fault_address_converter_func)(void* addr, void* arg); typedef void(*fault_client_func)(void* arg1, void* arg2); -typedef unsigned long(*func)(void); - -typedef void(*func_ptr)(void); - typedef void(*osCreateThread_func)(void*); typedef void* (*PrintCallback)(void*, const char*, u32); @@ -540,7 +536,7 @@ typedef struct { /* 0x20 */ u16 printColors[10]; /* 0x34 */ u8 escCode; /* 0x35 */ u8 osSyncPrintfEnabled; - /* 0x38 */ func_ptr inputCallback; + /* 0x38 */ void* inputCallback; } FaultDrawer; // size = 0x3C typedef struct GfxPrint { @@ -564,19 +560,23 @@ typedef enum { GFXPRINT_OPEN = 0x80 } GfxPrintFlag; +typedef struct GameState GameState; + +typedef void (*GameStateFunc)(GameState* gameState); + typedef struct { - /* 0x00 */ void* loadedRamAddr; - /* 0x04 */ u32 vromStart; - /* 0x08 */ u32 vromEnd; - /* 0x0C */ void* vramStart; - /* 0x10 */ void* vramEnd; - /* 0x14 */ UNK_TYPE4 unk14; - /* 0x18 */ func_ptr init; - /* 0x1C */ func_ptr destroy; - /* 0x20 */ UNK_TYPE4 unk20; - /* 0x24 */ UNK_TYPE4 unk24; - /* 0x28 */ UNK_TYPE4 unk28; - /* 0x2C */ u32 instanceSize; + /* 0x00 */ void* loadedRamAddr; + /* 0x04 */ uintptr_t vromStart; // if applicable + /* 0x08 */ uintptr_t vromEnd; // if applicable + /* 0x0C */ void* vramStart; // if applicable + /* 0x10 */ void* vramEnd; // if applicable + /* 0x14 */ UNK_PTR unk_14; + /* 0x18 */ GameStateFunc init; // initializes and executes the given context + /* 0x1C */ GameStateFunc destroy; // deconstructs the context, and sets the next context to load + /* 0x20 */ UNK_PTR unk_20; + /* 0x24 */ UNK_PTR unk_24; + /* 0x28 */ UNK_TYPE unk_28; + /* 0x2C */ size_t instanceSize; } GameStateOverlay; // size = 0x30 typedef struct { @@ -985,14 +985,6 @@ typedef struct { /* 0x120D8 */ UNK_TYPE1 pad120D8[0x8]; } MessageContext; // size = 0x120E0 -typedef struct ActorBgMbarChair ActorBgMbarChair; - -typedef struct ActorEnBji01 ActorEnBji01; - -typedef struct ActorEnTest ActorEnTest; - -typedef struct ActorListEntry ActorListEntry; - typedef struct ArenaNode_t { /* 0x0 */ s16 magic; // Should always be 0x7373 /* 0x2 */ s16 isFree; @@ -1010,14 +1002,6 @@ typedef struct { /* 0x22 */ u8 flag; } Arena; // size = 0x24 -typedef struct ActorEnBom ActorEnBom; - -typedef struct ActorEnFirefly ActorEnFirefly; - -typedef struct ActorObjBell ActorObjBell; - -typedef struct ActorBgIknvObj ActorBgIknvObj; - typedef struct FaultAddrConvClient FaultAddrConvClient; struct FaultAddrConvClient { @@ -1059,8 +1043,6 @@ typedef struct FireObjLight FireObjLight; typedef struct GameAlloc GameAlloc; -typedef struct GameState GameState; - typedef struct PreNMIContext PreNMIContext; typedef struct GameAllocNode GameAllocNode; @@ -1077,8 +1059,6 @@ struct GameAlloc { /* 0x10 */ GameAllocNode* head; }; // size = 0x14 -typedef void (*GameStateFunc)(struct GameState* gameState); - struct GameState { /* 0x00 */ GraphicsContext* gfxCtx; /* 0x04 */ GameStateFunc main; @@ -1374,11 +1354,11 @@ struct FireObjLight { /* 0x12 */ u8 unk12; }; // size = 0x13 -struct ActorListEntry { +typedef struct ActorListEntry { /* 0x0 */ s32 length; // number of actors loaded of this type /* 0x4 */ Actor* first; // pointer to first actor of this type /* 0x8 */ UNK_TYPE1 pad8[0x4]; -}; // size = 0xC +} ActorListEntry; // size = 0xC #define OS_SC_RETRACE_MSG 1 #define OS_SC_DONE_MSG 2 @@ -1642,108 +1622,6 @@ typedef struct { /* 0x8 */ s32 unk8; } struct_80133038_arg2; // size = 0xC -typedef struct { - /* 0x000 */ Actor base; - /* 0x144 */ ColliderQuad unk144; - /* 0x1C4 */ ColliderQuad unk1C4; - /* 0x244 */ Vec3f unk244; - /* 0x250 */ f32 unk250; - /* 0x254 */ f32 unk254; - /* 0x258 */ ActorFunc update; - /* 0x25C */ s16 unk25C; - /* 0x25E */ u16 unk25E; - /* 0x260 */ u8 unk260; - /* 0x261 */ UNK_TYPE1 pad261[0x3]; -} ActorArrowFire; // size = 0x264 - -struct ActorBgMbarChair { - /* 0x000 */ Actor base; - /* 0x144 */ UNK_TYPE1 pad144[0x18]; -}; // size = 0x15C - -struct ActorEnBji01 { - /* 0x000 */ Actor base; - /* 0x144 */ UNK_TYPE1 pad144[0x170]; -}; // size = 0x2B4 - -struct ActorEnBom { - /* 0x000 */ Actor base; - /* 0x144 */ ColliderCylinder unk144; - /* 0x190 */ ColliderJntSph unk190; - /* 0x1B0 */ ColliderJntSphElement unk1B0[1]; - /* 0x1F0 */ s16 unk1F0; - /* 0x1F2 */ UNK_TYPE1 pad1F2[0x6]; - /* 0x1F8 */ u8 unk1F8; - /* 0x1F9 */ u8 unk1F9; - /* 0x1FA */ UNK_TYPE1 pad1FA[0x2]; - /* 0x1FC */ u8 unk1FC; - /* 0x1FD */ UNK_TYPE1 pad1FD[0x3]; - /* 0x200 */ func_ptr unk200; -}; // size = 0x204 - -struct ActorEnFirefly { - /* 0x000 */ Actor base; - /* 0x144 */ UNK_TYPE1 pad144[0x1C]; - /* 0x160 */ f32 unk160; - /* 0x164 */ UNK_TYPE1 pad164[0x24]; - /* 0x188 */ func_ptr updateFunc; - /* 0x18C */ UNK_TYPE1 type; - /* 0x18D */ u8 unk18D; - /* 0x18E */ u8 unk18E; - /* 0x18F */ u8 unk18F; - /* 0x190 */ s16 unk190; - /* 0x192 */ UNK_TYPE1 pad192[0x152]; - /* 0x2E4 */ f32 unk2E4; - /* 0x2E8 */ f32 unk2E8; - /* 0x2EC */ f32 unk2EC; - /* 0x2F0 */ f32 unk2F0; - /* 0x2F4 */ UNK_TYPE1 pad2F4[0x28]; - /* 0x31C */ ColliderSphere collision; -}; // size = 0x374 - -struct ActorEnTest { - /* 0x000 */ Actor base; - /* 0x144 */ UNK_TYPE1 pad144[0x10]; - /* 0x154 */ f32 unk154; - /* 0x158 */ UNK_TYPE1 pad158[0xB0]; - /* 0x208 */ u8 unk208; - /* 0x209 */ UNK_TYPE1 pad209[0x1]; - /* 0x20A */ u8 unk20A; - /* 0x20B */ UNK_TYPE1 pad20B[0x1]; - /* 0x20C */ ActorEnTest20C unk20C[20]; -}; // size = 0x6BC - -typedef struct { - /* 0x000 */ Actor base; - /* 0x144 */ s8 unk144; - /* 0x145 */ u8 unk145; - /* 0x146 */ u16 unk146; - /* 0x148 */ u16 unk148; - /* 0x14A */ u16 unk14A; - /* 0x14C */ u8 unk14C; - /* 0x14D */ UNK_TYPE1 pad14D[0x3]; - /* 0x150 */ ActorFunc unk150; -} ActorEnTest4; // size = 0x154 - -struct ActorObjBell { - /* 0x000 */ Actor base; - /* 0x144 */ UNK_TYPE1 pad144[0x18]; - /* 0x15C */ ColliderSphere unk15C; - /* 0x1B4 */ ColliderSphere unk1B4; - /* 0x20C */ UNK_TYPE1 pad20C[0x2]; - /* 0x20E */ s16 unk20E; - /* 0x210 */ UNK_TYPE1 pad210[0x4]; - /* 0x214 */ s16 unk214; - /* 0x216 */ UNK_TYPE1 pad216[0x12]; -}; // size = 0x228 - -struct ActorBgIknvObj { - /* 0x000 */ DynaPolyActor bg; - /* 0x15C */ ColliderCylinder collision; - /* 0x1A8 */ u32 displayListAddr; - /* 0x1AC */ ActorFunc updateFunc; -}; // size = 0x1B0 - typedef struct { /* 0x00 */ u32 type; /* 0x04 */ u32 setScissor; diff --git a/spec b/spec index a91f653cf6..8ca54bfc5f 100644 --- a/spec +++ b/spec @@ -497,7 +497,7 @@ beginseg include "build/data/code/code_801BD830.data.o" include "build/src/code/z_fireobj.o" include "build/data/code/z_fireobj.data.o" - include "build/data/code/code_801BD910.data.o" + include "build/src/code/z_game_dlftbls.o" include "build/src/code/z_horse.o" include "build/data/code/z_horse.data.o" include "build/src/code/z_jpeg.o" diff --git a/src/boot_O2_g3/fault_drawer.c b/src/boot_O2_g3/fault_drawer.c index 74a3b7e5ec..4e6518d145 100644 --- a/src/boot_O2_g3/fault_drawer.c +++ b/src/boot_O2_g3/fault_drawer.c @@ -173,7 +173,7 @@ void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) { sFaultDrawContext->h = h; } -void FaultDrawer_SetInputCallback(void (*callback)()) { +void FaultDrawer_SetInputCallback(void* callback) { sFaultDrawContext->inputCallback = callback; } diff --git a/src/boot_O2_g3/idle.c b/src/boot_O2_g3/idle.c index f2cded98c2..4be8a1094f 100644 --- a/src/boot_O2_g3/idle.c +++ b/src/boot_O2_g3/idle.c @@ -1,4 +1,3 @@ -#include "prevent_bss_reordering.h" #include "global.h" u8 D_80096B20 = 1; diff --git a/src/code/z_game_dlftbls.c b/src/code/z_game_dlftbls.c new file mode 100644 index 0000000000..4e2590a6ae --- /dev/null +++ b/src/code/z_game_dlftbls.c @@ -0,0 +1,26 @@ +#include "global.h" +#include "overlays/gamestates/ovl_daytelop/z_daytelop.h" +#include "overlays/gamestates/ovl_file_choose/z_file_choose.h" +#include "overlays/gamestates/ovl_opening/z_opening.h" +#include "overlays/gamestates/ovl_select/z_select.h" +#include "overlays/gamestates/ovl_title/z_title.h" + +#define GAMESTATE_OVERLAY(name, init, destroy, size) \ + { \ + NULL, SEGMENT_ROM_START(ovl_##name), SEGMENT_ROM_END(ovl_##name), SEGMENT_START(ovl_##name), \ + SEGMENT_END(ovl_##name), 0, init, destroy, 0, 0, 0, size \ + } +#define GAMESTATE_OVERLAY_INTERNAL(init, destroy, size) \ + { NULL, 0, 0, NULL, NULL, 0, init, destroy, 0, 0, 0, size } + +GameStateOverlay gGameStateOverlayTable[] = { + GAMESTATE_OVERLAY_INTERNAL(TitleSetup_Init, TitleSetup_Destroy, sizeof(GameState)), + GAMESTATE_OVERLAY(select, Select_Init, Select_Destroy, sizeof(SelectContext)), + GAMESTATE_OVERLAY(title, Title_Init, Title_Destroy, sizeof(TitleContext)), + GAMESTATE_OVERLAY_INTERNAL(Play_Init, Play_Fini, sizeof(GlobalContext)), + GAMESTATE_OVERLAY(opening, Opening_Init, Opening_Destroy, sizeof(OpeningContext)), + GAMESTATE_OVERLAY(file_choose, FileChoose_Init, FileChoose_Destroy, sizeof(FileChooseContext)), + GAMESTATE_OVERLAY(daytelop, Daytelop_Init, Daytelop_Destroy, sizeof(DaytelopContext)), +}; + +s32 graphNumGameStates = ARRAY_COUNT(gGameStateOverlayTable); diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.h b/src/overlays/gamestates/ovl_file_choose/z_file_choose.h index bae203c680..d2e71587dd 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.h +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.h @@ -8,6 +8,7 @@ void FileChoose_Destroy(GameState* thisx); typedef struct { /* 0x00000 */ GameState state; + /* 0x000A4 */ Vtx* unk_A4; /* 0x000A8 */ u8* staticSegment; /* 0x000AC */ u8* parameterSegment; /* 0x000B0 */ u8* titleSegment; @@ -16,6 +17,7 @@ typedef struct { /* 0x00248 */ SkyboxContext skyboxCtx; /* 0x00470 */ MessageContext msgCtx; /* 0x12550 */ Font font; + /* 0x242DC */ UNK_TYPE1 unk_242DC[4]; /* 0x242E0 */ EnvironmentContext envCtx; /* 0x243E0 */ Vtx* unk_243E0; /* 0x243E4 */ Vtx* unk_243E4;