diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index be914da8..6fad7717 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -256,6 +256,7 @@ d/d_lang.cpp: d/d_main.cpp: .text start:0x80054F90 end:0x80055170 align:16 .sbss start:0x805751D0 end:0x805751E0 + .bss start:0x80597758 end:0x80597A70 d/d_pad.cpp: .text start:0x80055170 end:0x8005961C align:16 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 19e43777..c9998e05 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2239,9 +2239,9 @@ getCurrentLanguage__Fv = .text:0x80054F50; // type:function size:0x38 fn_80054F90 = .text:0x80054F90; // type:function size:0x18 fn_80054FB0 = .text:0x80054FB0; // type:function size:0x24 fn_80054FE0 = .text:0x80054FE0; // type:function size:0x20 -dMain__Create = .text:0x80055000; // type:function size:0x28 -dMain__Execute = .text:0x80055030; // type:function size:0x14 -dMain__main01 = .text:0x80055050; // type:function size:0x28 +Create__5dMainFv = .text:0x80055000; // type:function size:0x28 +Execute__5dMainFv = .text:0x80055030; // type:function size:0x14 +main01__5dMainFPv = .text:0x80055050; // type:function size:0x28 main = .text:0x80055080; // type:function size:0xE4 scope:global control_mpls_callback__4dPadFll = .text:0x80055170; // type:function size:0x38 isDeviceTypeMpls__4dPadFUl = .text:0x800551B0; // type:function size:0x24 @@ -42180,7 +42180,7 @@ layoutResHeap__5dHeap = .sbss:0x805751C0; // type:object size:0x4 data:4byte fontHeap__5dHeap = .sbss:0x805751C4; // type:object size:0x4 data:4byte HBMHeap__5dHeap = .sbss:0x805751C8; // type:object size:0x4 data:4byte lbl_805751D0 = .sbss:0x805751D0; // type:object size:0x8 data:4byte -dMain__g_InitialTime = .sbss:0x805751D8; // type:object size:0x8 data:4byte +g_InitialTime__5dMain = .sbss:0x805751D8; // type:object size:0x8 data:4byte m_connected__Q24dPad4ex_c = .sbss:0x805751E0; // type:object size:0x4 sInstance__13dPadManager_c = .sbss:0x805751E8; // type:object size:0x8 data:4byte LINK_ROT = .sbss:0x805751F0; // type:object size:0x2 data:2byte diff --git a/include/d/d_main.h b/include/d/d_main.h new file mode 100644 index 00000000..09537513 --- /dev/null +++ b/include/d/d_main.h @@ -0,0 +1,13 @@ +#ifndef D_MAIN_H +#define D_MAIN_H + +#include "rvl/OS.h" + +namespace dMain { + void Create(); + void Execute(); + void *main01(void *arg); + OSTime g_InitialTime; +}; + +#endif // D_MAIN_H diff --git a/include/d/d_sys.h b/include/d/d_sys.h index 7557307d..2bb13c1e 100644 --- a/include/d/d_sys.h +++ b/include/d/d_sys.h @@ -7,14 +7,22 @@ class dSys_c { public: + static void setBlack(bool); /* Frame rate values: 1 - 60fps, 2 - 30fps */ static void setFrameRate(u8); static u8 getFrameRate(); static void setClearColor(nw4r::ut::Color clr); + static void create(); + static void execute(); + static EGG::Heap *ms_RootHeapMem1; static EGG::Heap *ms_RootHeapMem2; }; +namespace dSystem { +void fixHeaps(); +}; + #endif diff --git a/include/rvl/OS/OSThread.h b/include/rvl/OS/OSThread.h index 871ce0a7..f315c558 100644 --- a/include/rvl/OS/OSThread.h +++ b/include/rvl/OS/OSThread.h @@ -12,6 +12,8 @@ extern "C" { #define OS_THREAD_STACK_MAGIC 0xDEADBABE +typedef s32 OSPriority; + typedef enum { OS_THREAD_STATE_EXITED = 0, OS_THREAD_STATE_READY = 1, @@ -97,6 +99,7 @@ s32 OSSuspendThread(OSThread *thread); void OSSleepThread(OSThreadQueue *queue); void OSWakeupThread(OSThreadQueue *queue); BOOL OSSetThreadPriority(OSThread *thread, s32 prio); +OSPriority OSGetThreadPriority(OSThread *thread); void OSClearStack(u8 val); void OSSleepTicks(s64 ticks); diff --git a/include/toBeSorted/d_lib.h b/include/toBeSorted/d_lib.h new file mode 100644 index 00000000..0a4787ca --- /dev/null +++ b/include/toBeSorted/d_lib.h @@ -0,0 +1,6 @@ +#ifndef D_LIB_H +#define D_LIB_H + +void fn_80006C20(); + +#endif // D_LIB_H diff --git a/include/toBeSorted/mpls.h b/include/toBeSorted/mpls.h new file mode 100644 index 00000000..561c5bff --- /dev/null +++ b/include/toBeSorted/mpls.h @@ -0,0 +1,7 @@ +#ifndef MPLS_H +#define MPLS_H + +void fn_80006CE0(int, char **); +void fn_80006D60(); + +#endif // MPLS_H diff --git a/src/d/d_main.cpp b/src/d/d_main.cpp new file mode 100644 index 00000000..9ad27e41 --- /dev/null +++ b/src/d/d_main.cpp @@ -0,0 +1,54 @@ +#include "d/d_main.h" + +#include "d/d_sys.h" +#include "rvl/OS.h" +#include "toBeSorted/d_lib.h" +#include "toBeSorted/mpls.h" + +OSThread MAIN_THREAD; + +#define STACK_SIZE 0xF000 + +void dMain::Create() { + dSys_c::create(); + dSys_c::setBlack(false); +} + +void dMain::Execute() { + while (true) { + dSys_c::execute(); + } +} + +void *dMain::main01(void *arg) { + Create(); + Execute(); + return nullptr; +} + +void main(int argc, char **argv) { + u8 pStackBase[STACK_SIZE] __attribute__((aligned(32))); + + fn_80006C20(); + dMain::g_InitialTime = OSGetTime(); + dSystem::fixHeaps(); + fn_80006CE0(argc, argv); + fn_80006D60(); + + OSThread *curThread = OSGetCurrentThread(); + OSPriority curPrio = OSGetThreadPriority(curThread); + + OSCreateThread( + &MAIN_THREAD, + dMain::main01, + nullptr, + &pStackBase[STACK_SIZE], + STACK_SIZE, + curPrio, + 0 + ); + + OSResumeThread(&MAIN_THREAD); + OSSetThreadPriority(curThread, 31); + OSSuspendThread(curThread); +}