From 29be6ffd0036e1fff5b6b7e22a28dd254228d020 Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sat, 16 May 2026 14:08:05 +0200 Subject: [PATCH 1/7] Game_16 OK --- include/Render/FadeControl.hpp | 1 - src/16_Startup/Game/Game_16.cpp | 42 +++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/Render/FadeControl.hpp b/include/Render/FadeControl.hpp index 8e9697ef5..e9b8fe173 100644 --- a/include/Render/FadeControl.hpp +++ b/include/Render/FadeControl.hpp @@ -22,7 +22,6 @@ struct FadeControl { void Register(); void Unregister(); - FadeControl(); void func_0202aba8(s32 fadeLength, unk32 param2, unk32 newState); bool func_0202abdc(s32 fadeLength, unk32 param2); bool func_0202abf4(s32 fadeLength, unk32 param2); diff --git a/src/16_Startup/Game/Game_16.cpp b/src/16_Startup/Game/Game_16.cpp index 85e094b35..f136fec4d 100644 --- a/src/16_Startup/Game/Game_16.cpp +++ b/src/16_Startup/Game/Game_16.cpp @@ -1,4 +1,42 @@ #include "Game/Game.hpp" -Game::Game() {} -void Game::func_ov016_0211fd68() {} +#include "GameStart/GameStart.hpp" +#include "Render/FadeController.hpp" +#include "System/OverlayManager.hpp" + +extern "C" void func_ov016_0211fab8(void *, void (*)(), void *, unk32); +extern "C" void func_0200d938(void *); +extern "C" void _ZN4Game13func_0202cf44Ev(Game *); +extern "C" void _ZN11FadeControlC2Ev(FadeControl *); + +ARM Game::Game() { + mModeId = 1; + mPrevModeId = 1; + mMode = NULL; + func_ov016_0211fab8(mUnk_00c, (void (*)()) _ZN4Game13func_0202cf44Ev, this, 0); + _ZN11FadeControlC2Ev(&mFadeControl); + mUnk_0f0 = 0; + mUnk_0f2 = 1; + mUnk_0f4 = 0; + mUnk_0f8 = 0; + mUnk_0fc = 0; + mUnk_0fe = 0; + mUnk_100 = false; + mUnk_101 = 0; + mUnk_102 = false; + mUnk_103 = 0; +} + +ARM void Game::func_ov016_0211fd68() { + mFadeControl.Register(); + mFadeControl.mUnk_20 = false; + gFadeController.func_0202d77c(&mFadeControl); + if (*(s32 *) 0x027ffc20 == 2) { + gOverlayManager.LoadGameMode(1); + GameStart::func_ov008_02112e88(); + gOverlayManager.UnloadGameMode(); + mPrevModeId = 4; + mModeId = 3; + } + func_0200d938(mUnk_00c); +} From a7c25e1e8ff265c5eefb95fb24b16de3fd9259ef Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sat, 16 May 2026 16:22:53 +0200 Subject: [PATCH 2/7] Remove unnecessary FadeControl constructor definition --- src/Main/Render/FadeControl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Main/Render/FadeControl.cpp b/src/Main/Render/FadeControl.cpp index 5413595b5..ac52dc944 100644 --- a/src/Main/Render/FadeControl.cpp +++ b/src/Main/Render/FadeControl.cpp @@ -2,7 +2,6 @@ void FadeControl::Register() {} void FadeControl::Unregister() {} -FadeControl::FadeControl() {} void FadeControl::func_0202aba8(s32 fadeLength, unk32 param2, unk32 newState) {} bool FadeControl::func_0202abdc(s32 fadeLength, unk32 param2) {} bool FadeControl::func_0202abf4(s32 fadeLength, unk32 param2) {} From d5f871bbdd394765b99693ec9ae084e5689e52b6 Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sat, 16 May 2026 18:13:08 +0200 Subject: [PATCH 3/7] Define HW_RESET_PARAMETER_BUF macro to replace hardcoded address --- libs/nds/include/nds/system.h | 17 +++++++++++++++++ src/16_Startup/Game/Game_16.cpp | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 libs/nds/include/nds/system.h diff --git a/libs/nds/include/nds/system.h b/libs/nds/include/nds/system.h new file mode 100644 index 000000000..73d680c83 --- /dev/null +++ b/libs/nds/include/nds/system.h @@ -0,0 +1,17 @@ +#ifndef _NDS_SYSTEM_H +#define _NDS_SYSTEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +// Reset Parameter Buffer (BIOS reset information) +// Not documented on gbatek, located at 0x027ffc20 +// Contains reset state information - value 2 indicates specific reset condition +#define HW_RESET_PARAMETER_BUF (*(s32 *) 0x027ffc20) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/16_Startup/Game/Game_16.cpp b/src/16_Startup/Game/Game_16.cpp index f136fec4d..514e836a3 100644 --- a/src/16_Startup/Game/Game_16.cpp +++ b/src/16_Startup/Game/Game_16.cpp @@ -1,5 +1,7 @@ #include "Game/Game.hpp" +#include + #include "GameStart/GameStart.hpp" #include "Render/FadeController.hpp" #include "System/OverlayManager.hpp" @@ -31,7 +33,7 @@ ARM void Game::func_ov016_0211fd68() { mFadeControl.Register(); mFadeControl.mUnk_20 = false; gFadeController.func_0202d77c(&mFadeControl); - if (*(s32 *) 0x027ffc20 == 2) { + if (HW_RESET_PARAMETER_BUF == 2) { gOverlayManager.LoadGameMode(1); GameStart::func_ov008_02112e88(); gOverlayManager.UnloadGameMode(); From e9dfab123cd585af264168a0a88dd62300385bfc Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sat, 16 May 2026 20:24:56 +0200 Subject: [PATCH 4/7] Refactor Game constructor to use proper C++ initialization Address Yanis' review comments: - Make Game::func_0202cf44 static with Game* parameter to allow passing as callback pointer - Replace raw mUnk_00c array with Game_0c class containing constructor - Add Game_0c constructor with inline initialization calling func_ov016_0211fab8 - Add FadeControl_Derived1 class for mFadeControl member - Use C++ initializer list in Game constructor for mModeId, mPrevModeId, mMode, mUnk_00c, and mFadeControl --- include/Game/Game.hpp | 29 ++++++++++++++++++++++++++--- src/16_Startup/Game/Game_16.cpp | 17 +++++++---------- src/Main/Game/Game.cpp | 26 +++++++++++++------------- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/include/Game/Game.hpp b/include/Game/Game.hpp index 607d13a3a..3845e5099 100644 --- a/include/Game/Game.hpp +++ b/include/Game/Game.hpp @@ -7,6 +7,9 @@ #include "Render/FadeControl.hpp" #include "System/OverlayManager.hpp" +class Game; +typedef void (*UnkCallback)(Game *); + typedef GameMode *(*GameModeCreateFunc)(GameModeId modeId); struct GameModeData { @@ -24,13 +27,33 @@ struct GameModeData { }; extern const GameModeData gGameModes[]; +extern "C" void func_ov016_0211fab8(void *, void (*)(), void *, unk32); + +class Game_0c { +public: + /* 00 */ unk8 pad[0xC0]; + + Game_0c(UnkCallback callback, void *param2, u32 param3) { + func_ov016_0211fab8(pad, (void (*)()) callback, param2, param3); + } +}; + +extern "C" void _ZN11FadeControlC2Ev(FadeControl *); + +class FadeControl_Derived1 : public FadeControl { +public: + FadeControl_Derived1() { + _ZN11FadeControlC2Ev(this); + } +}; + class Game { public: /* 000 */ GameModeId mModeId; /* 004 */ GameModeId mPrevModeId; /* 008 */ GameMode *mMode; - /* 00c */ unk8 mUnk_00c[0xc0]; - /* 0cc */ FadeControl mFadeControl; + /* 00c */ Game_0c mUnk_00c; + /* 0cc */ FadeControl_Derived1 mFadeControl; /* 0f0 */ u16 mUnk_0f0; /* 0f2 */ vu16 mUnk_0f2; /* 0f4 */ s32 mUnk_0f4; @@ -55,7 +78,7 @@ class Game { void Run(); bool func_0202cec8(s32 param1, bool param2); void func_0202cf34(); - void func_0202cf44(); + static void func_0202cf44(Game *game); void func_ov016_0211fd68(); }; diff --git a/src/16_Startup/Game/Game_16.cpp b/src/16_Startup/Game/Game_16.cpp index 514e836a3..82065bc8b 100644 --- a/src/16_Startup/Game/Game_16.cpp +++ b/src/16_Startup/Game/Game_16.cpp @@ -6,17 +6,14 @@ #include "Render/FadeController.hpp" #include "System/OverlayManager.hpp" -extern "C" void func_ov016_0211fab8(void *, void (*)(), void *, unk32); extern "C" void func_0200d938(void *); -extern "C" void _ZN4Game13func_0202cf44Ev(Game *); -extern "C" void _ZN11FadeControlC2Ev(FadeControl *); -ARM Game::Game() { - mModeId = 1; - mPrevModeId = 1; - mMode = NULL; - func_ov016_0211fab8(mUnk_00c, (void (*)()) _ZN4Game13func_0202cf44Ev, this, 0); - _ZN11FadeControlC2Ev(&mFadeControl); +ARM Game::Game() : + mModeId(1), + mPrevModeId(1), + mMode(NULL), + mUnk_00c(Game::func_0202cf44, this, 0), + mFadeControl() { mUnk_0f0 = 0; mUnk_0f2 = 1; mUnk_0f4 = 0; @@ -40,5 +37,5 @@ ARM void Game::func_ov016_0211fd68() { mPrevModeId = 4; mModeId = 3; } - func_0200d938(mUnk_00c); + func_0200d938(mUnk_00c.pad); } diff --git a/src/Main/Game/Game.cpp b/src/Main/Game/Game.cpp index b02fa9f93..fa3019c28 100644 --- a/src/Main/Game/Game.cpp +++ b/src/Main/Game/Game.cpp @@ -467,38 +467,38 @@ THUMB void Game::func_0202cf34() { } extern "C" void func_02017cd0(); -ARM void Game::func_0202cf44() { +ARM void Game::func_0202cf44(Game *game) { while (true) { - if (mUnk_100) { - mUnk_0f4 += 1; + if (game->mUnk_100) { + game->mUnk_0f4 += 1; while (REG_GFX_RAM_COUNT_2 != 0) { } func_02005778(); func_02017cd0(); - if (mUnk_0fc != mUnk_0fe) { - this->func_0202c678(); + if (game->mUnk_0fc != game->mUnk_0fe) { + game->func_0202c678(); } if (data_027e080c.func_0202eef8()) { data_027e08f8.mUnk_1 = true; } else { - data_027e0c54.func_02036240(&mUnk_0f0); - data_027e0c38.func_02033d84(&mUnk_0f0); - mMode->vfunc_0c(&mUnk_0f0); - gMessageManager.func_02036c50(&mUnk_0f0); + data_027e0c54.func_02036240(&game->mUnk_0f0); + data_027e0c38.func_02033d84(&game->mUnk_0f0); + game->mMode->vfunc_0c(&game->mUnk_0f0); + gMessageManager.func_02036c50(&game->mUnk_0f0); if ((s32) (data_027e080c.mUnk_04 == 3 || data_027e080c.mUnk_08 == 3) == 0) { - gFadeController.SetScreenBrightness(mUnk_103); + gFadeController.SetScreenBrightness(game->mUnk_103); } - data_027e0cbc.func_0203d67c(&mUnk_0f0); + data_027e0cbc.func_0203d67c(&game->mUnk_0f0); if (gOverlayManager.mLoadedOverlays[0] != OverlayId_None) { data_027e0db0.func_ov000_0207b43c(); } - if (mModeId == 2) { + if (game->mModeId == 2) { data_027e077c.func_ov009_0211653c(); } data_02068894.func_0203235c(); data_02075dac.func_0203f974(); } - mUnk_100 = false; + game->mUnk_100 = false; } data_027e08e4.func_0202f2ac(); } From 98b49356f88bb7c8a049ef254c2218eee216d7cc Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sat, 16 May 2026 21:44:29 +0200 Subject: [PATCH 5/7] Fix Game constructor and FadeControl initialization - Use PAD macro in Game_0c instead of unk8 pad[] - Pass 'this' instead of 'pad' to func_ov016_0211fab8 - Add FadeControl constructor that calls _ZN11FadeControlC2Ev - FadeControl_Derived1 now uses empty constructor (base class ctor called automatically) - Update mUnk_00c.pad to mUnk_00c.pad_0x00 (PAD macro creates named member) - Add types.h include to nds/system.h --- include/Game/Game.hpp | 10 +++------- include/Render/FadeControl.hpp | 2 ++ libs/nds/include/nds/system.h | 2 ++ src/16_Startup/Game/Game_16.cpp | 2 +- src/Main/Render/FadeControl.cpp | 6 ++++++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/Game/Game.hpp b/include/Game/Game.hpp index 3845e5099..606255264 100644 --- a/include/Game/Game.hpp +++ b/include/Game/Game.hpp @@ -31,20 +31,16 @@ extern "C" void func_ov016_0211fab8(void *, void (*)(), void *, unk32); class Game_0c { public: - /* 00 */ unk8 pad[0xC0]; + /* 00 */ PAD(0x00, 0xC0); Game_0c(UnkCallback callback, void *param2, u32 param3) { - func_ov016_0211fab8(pad, (void (*)()) callback, param2, param3); + func_ov016_0211fab8(this, (void (*)()) callback, param2, param3); } }; -extern "C" void _ZN11FadeControlC2Ev(FadeControl *); - class FadeControl_Derived1 : public FadeControl { public: - FadeControl_Derived1() { - _ZN11FadeControlC2Ev(this); - } + FadeControl_Derived1() {} }; class Game { diff --git a/include/Render/FadeControl.hpp b/include/Render/FadeControl.hpp index e9b8fe173..66cc7f843 100644 --- a/include/Render/FadeControl.hpp +++ b/include/Render/FadeControl.hpp @@ -20,6 +20,8 @@ struct FadeControl { /* 23 */ unk8 mUnk_23; /* 24 */ + FadeControl(); + void Register(); void Unregister(); void func_0202aba8(s32 fadeLength, unk32 param2, unk32 newState); diff --git a/libs/nds/include/nds/system.h b/libs/nds/include/nds/system.h index 73d680c83..9649a657f 100644 --- a/libs/nds/include/nds/system.h +++ b/libs/nds/include/nds/system.h @@ -1,6 +1,8 @@ #ifndef _NDS_SYSTEM_H #define _NDS_SYSTEM_H +#include "types.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/src/16_Startup/Game/Game_16.cpp b/src/16_Startup/Game/Game_16.cpp index 82065bc8b..4a2437063 100644 --- a/src/16_Startup/Game/Game_16.cpp +++ b/src/16_Startup/Game/Game_16.cpp @@ -37,5 +37,5 @@ ARM void Game::func_ov016_0211fd68() { mPrevModeId = 4; mModeId = 3; } - func_0200d938(mUnk_00c.pad); + func_0200d938(mUnk_00c.pad_0x00); } diff --git a/src/Main/Render/FadeControl.cpp b/src/Main/Render/FadeControl.cpp index ac52dc944..4dee62208 100644 --- a/src/Main/Render/FadeControl.cpp +++ b/src/Main/Render/FadeControl.cpp @@ -1,5 +1,11 @@ #include "Render/FadeControl.hpp" +extern "C" void _ZN11FadeControlC2Ev(FadeControl *); + +FadeControl::FadeControl() { + _ZN11FadeControlC2Ev(this); +} + void FadeControl::Register() {} void FadeControl::Unregister() {} void FadeControl::func_0202aba8(s32 fadeLength, unk32 param2, unk32 newState) {} From 4e1f4a3a9cfa913da89291f25dbbb81478500c47 Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sat, 16 May 2026 22:18:30 +0200 Subject: [PATCH 6/7] Remove explicit call to mangled constructor symbol - Removed _ZN11FadeControlC2Ev call from FadeControl constructor - FadeControl now has an empty constructor (called automatically by derived classes) - FadeControl_Derived1 uses empty constructor which calls base class ctor --- include/Render/FadeControl.hpp | 3 +-- src/Main/Render/FadeControl.cpp | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/include/Render/FadeControl.hpp b/include/Render/FadeControl.hpp index 66cc7f843..8e9697ef5 100644 --- a/include/Render/FadeControl.hpp +++ b/include/Render/FadeControl.hpp @@ -20,10 +20,9 @@ struct FadeControl { /* 23 */ unk8 mUnk_23; /* 24 */ - FadeControl(); - void Register(); void Unregister(); + FadeControl(); void func_0202aba8(s32 fadeLength, unk32 param2, unk32 newState); bool func_0202abdc(s32 fadeLength, unk32 param2); bool func_0202abf4(s32 fadeLength, unk32 param2); diff --git a/src/Main/Render/FadeControl.cpp b/src/Main/Render/FadeControl.cpp index 4dee62208..5413595b5 100644 --- a/src/Main/Render/FadeControl.cpp +++ b/src/Main/Render/FadeControl.cpp @@ -1,13 +1,8 @@ #include "Render/FadeControl.hpp" -extern "C" void _ZN11FadeControlC2Ev(FadeControl *); - -FadeControl::FadeControl() { - _ZN11FadeControlC2Ev(this); -} - void FadeControl::Register() {} void FadeControl::Unregister() {} +FadeControl::FadeControl() {} void FadeControl::func_0202aba8(s32 fadeLength, unk32 param2, unk32 newState) {} bool FadeControl::func_0202abdc(s32 fadeLength, unk32 param2) {} bool FadeControl::func_0202abf4(s32 fadeLength, unk32 param2) {} From 5b73154d7dc5e48d196ee35ae5c95caa259c7c7f Mon Sep 17 00:00:00 2001 From: Aurel <285191559+0Aurel@users.noreply.github.com> Date: Sun, 17 May 2026 21:11:13 +0200 Subject: [PATCH 7/7] Update symbols.txt for func_0202cf44 signature change Changed mangled name from _ZN4Game13func_0202cf44Ev to _ZN4Game13func_0202cf44EPS_ to reflect the function becoming static with a Game* parameter. --- config/eur/arm9/symbols.txt | 2 +- config/usa/arm9/symbols.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/eur/arm9/symbols.txt b/config/eur/arm9/symbols.txt index f765415a7..f9dc3d5f2 100644 --- a/config/eur/arm9/symbols.txt +++ b/config/eur/arm9/symbols.txt @@ -1384,7 +1384,7 @@ _ZN4Game13func_0202c97cEv kind:function(thumb,size=0x24) addr:0x0202c97c _ZN4Game3RunEv kind:function(arm,size=0x528) addr:0x0202c9a0 _ZN4Game13func_0202cec8Eib kind:function(thumb,size=0x6c) addr:0x0202cec8 _ZN4Game13func_0202cf34Ev kind:function(thumb,size=0x10) addr:0x0202cf34 -_ZN4Game13func_0202cf44Ev kind:function(arm,size=0x170) addr:0x0202cf44 +_ZN4Game13func_0202cf44EPS_ kind:function(arm,size=0x170) addr:0x0202cf44 _ZN4GameD1Ev kind:function(arm,size=0x18) addr:0x0202d0b4 func_0202d0cc kind:function(thumb,size=0x3a) addr:0x0202d0cc func_0202d108 kind:function(thumb,size=0x38) addr:0x0202d108 diff --git a/config/usa/arm9/symbols.txt b/config/usa/arm9/symbols.txt index f46857bd7..992e9c13e 100644 --- a/config/usa/arm9/symbols.txt +++ b/config/usa/arm9/symbols.txt @@ -1384,7 +1384,7 @@ _ZN4Game13func_0202c97cEv kind:function(thumb,size=0x24) addr:0x0202c964 _ZN4Game3RunEv kind:function(arm,size=0x528) addr:0x0202c988 _ZN4Game13func_0202cec8Eib kind:function(thumb,size=0x6c) addr:0x0202ceb0 _ZN4Game13func_0202cf34Ev kind:function(thumb,size=0x10) addr:0x0202cf1c -_ZN4Game13func_0202cf44Ev kind:function(arm,size=0x170) addr:0x0202cf2c +_ZN4Game13func_0202cf44EPS_ kind:function(arm,size=0x170) addr:0x0202cf2c _ZN4GameD1Ev kind:function(arm,size=0x18) addr:0x0202d09c func_0202d0cc kind:function(thumb,size=0x3a) addr:0x0202d0b4 func_0202d108 kind:function(thumb,size=0x38) addr:0x0202d0f0