Merge pull request #308 from bgsamm/d_state

Matches for d_state.cpp, m_state.cpp, m_thread.cpp, eggSystem.cpp, and eggUnk.cpp
This commit is contained in:
Elijah Thomas
2026-04-18 09:16:02 -04:00
committed by GitHub
20 changed files with 435 additions and 71 deletions
+2 -2
View File
@@ -4893,13 +4893,13 @@ egg/core/eggThread.cpp:
.sbss start:0x80576770 end:0x80576778
.bss start:0x80673B10 end:0x80673B20
egg/core/eggUnk.cpp:
egg/core/eggThreadMgr.cpp:
.text start:0x80496DE0 end:0x8049716C align:16
.sbss start:0x80576778 end:0x80576780
egg/core/eggSystem.cpp:
.text start:0x80497170 end:0x8049752C align:16
.data start:0x8056EA58 end:0x8056EAC8
.data start:0x8056EA58 end:0x8056EA8C
.sbss start:0x80576780 end:0x80576788
egg/core/eggDisplay.cpp:
+19 -15
View File
@@ -2236,9 +2236,9 @@ __sinit_\d_heap_cpp = .text:0x80054F00; // type:function size:0x30 scope:local
getCurrentLanguage1__Fv = .text:0x80054F30; // type:function size:0x4
getCurrentLanguage2__Fv = .text:0x80054F40; // type:function size:0x4
getCurrentLanguage__Fv = .text:0x80054F50; // type:function size:0x38
fn_80054F90__FUl = .text:0x80054F90; // type:function size:0x18
fn_80054FB0__FUl = .text:0x80054FB0; // type:function size:0x24
fn_80054FE0__FUl = .text:0x80054FE0; // type:function size:0x20
isStopFlagSet__5dMainFUl = .text:0x80054F90; // type:function size:0x18
setStopFlag__5dMainFUl = .text:0x80054FB0; // type:function size:0x24
clearStopFlag__5dMainFUl = .text:0x80054FE0; // type:function size:0x20
Create__5dMainFv = .text:0x80055000; // type:function size:0x28
Execute__5dMainFv = .text:0x80055030; // type:function size:0x14
main01__5dMainFPv = .text:0x80055050; // type:function size:0x28
@@ -17687,10 +17687,10 @@ __sinit_\m_shadow_cpp = .text:0x802EDF20; // type:function size:0xC scope:local
__ct__Q23m3d6smdl_cFv = .text:0x802EDF30; // type:function size:0x4C
__dt__Q23m3d6smdl_cFv = .text:0x802EDF80; // type:function size:0x58
create__Q23m3d6smdl_cFQ34nw4r3g3d6ResMdlP12mAllocator_cUliPUl = .text:0x802EDFE0; // type:function size:0xB4
fn_802EE0A0 = .text:0x802EE0A0; // type:function size:0x4
fn_802EE0B0 = .text:0x802EE0B0; // type:function size:0x4
fn_802EE0C0 = .text:0x802EE0C0; // type:function size:0x4
fn_802EE0D0 = .text:0x802EE0D0; // type:function size:0x8
unkStub1__Q23m3d6mStateFv = .text:0x802EE0A0; // type:function size:0x4
unkStub2__Q23m3d6mStateFv = .text:0x802EE0B0; // type:function size:0x4
unkStub3__Q23m3d6mStateFv = .text:0x802EE0C0; // type:function size:0x4
unkAlwaysTrue__Q23m3d6mStateFv = .text:0x802EE0D0; // type:function size:0x8
__ct__12mAllocator_cFv = .text:0x802EE0E0; // type:function size:0x44
__dt__12mAllocator_cFv = .text:0x802EE130; // type:function size:0x58
attach__12mAllocator_cFPQ23EGG4Heapi = .text:0x802EE190; // type:function size:0x50
@@ -17861,7 +17861,7 @@ Set__7mQuat_cFRC7mVec3_cRC7mVec3_c = .text:0x802F2330; // type:function size:0x1
fn_802F2450__7mQuat_cFRC7mVec3_cRC7mVec3_cf = .text:0x802F2450; // type:function size:0x18C
fn_802F25E0 = .text:0x802F25E0; // type:function size:0x19C
fn_802F2780__7mQuat_cFRC7mQuat_c = .text:0x802F2780; // type:function size:0x198
fn_802F2920 = .text:0x802F2920; // type:function size:0x48
registerThread__7mThreadFP8OSThreadPv = .text:0x802F2920; // type:function size:0x48
createProjectionXZ__7mVec3_cFRC7mAng3_cf = .text:0x802F2970; // type:function size:0x110
mVec__fromXY = .text:0x802F2A80; // type:function size:0xF0
normalize__7mVec3_cFv = .text:0x802F2B70; // type:function size:0x78
@@ -26254,10 +26254,10 @@ switchThreadCallback__Q23EGG6ThreadFP8OSThreadP8OSThread = .text:0x80496C70; //
setCommonMesgQueue__Q23EGG6ThreadFiPQ23EGG4Heap = .text:0x80496D60; // type:function size:0x5C
start__Q23EGG6ThreadFPv = .text:0x80496DC0; // type:function size:0x10
run__Q23EGG6ThreadFv = .text:0x80496DD0; // type:function size:0x8 scope:weak
FUN_80496de0 = .text:0x80496DE0; // type:function size:0x44
FUN_80496e30 = .text:0x80496E30; // type:function size:0xD8
FUN_80496f10 = .text:0x80496F10; // type:function size:0x1CC
FUN_804970e0 = .text:0x804970E0; // type:function size:0x8C
getThreadIndex__Q23EGG13ThreadMgrFP8OSThread = .text:0x80496DE0; // type:function size:0x44
doRegisterThread__Q23EGG13ThreadMgrFP8OSThread = .text:0x80496E30; // type:function size:0xD8
sortByPriority__Q23EGG13ThreadMgrFv = .text:0x80496F10; // type:function size:0x1CC
registerThread__Q23EGG13ThreadMgrFP8OSThreadQ23EGG13UnknownStruct = .text:0x804970E0; // type:function size:0x8C
initMemory__Q23EGG17ConfigurationDataFv = .text:0x80497170; // type:function size:0x174
run__Q23EGG17ConfigurationDataFv = .text:0x804972F0; // type:function size:0x23C
PreRetraceCallback = .text:0x80497530; // type:function size:0x40
@@ -39536,7 +39536,11 @@ __vt__Q23EGG7FrmHeap = .data:0x8056E9D0; // type:object size:0x30
__vt__Q23EGG10AssertHeap = .data:0x8056EA00; // type:object size:0x30
__vt__Q23EGG8Disposer = .data:0x8056EA30; // type:object size:0xC
__vt__Q23EGG6Thread = .data:0x8056EA40; // type:object size:0x18
lbl_8056EA58 = .data:0x8056EA58; // type:object size:0x70
@8336 = .data:0x8056EA58; // type:object size:0xC data:string
@8337 = .data:0x8056EA64; // type:object size:0xC data:string
@8338 = .data:0x8056EA70; // type:object size:0xD data:string
@8339 = .data:0x8056EA80; // type:object size:0xA data:string
lbl_8056EA8C = .data:0x8056EA8C; // type:object size:0x3C
__vt__Q23EGG7Display = .data:0x8056EAC8; // type:object size:0x20
__vt__Q23EGG10ColorFader = .data:0x8056EAE8; // type:object size:0x24
clear_z_TX__29@unnamed@eggAsyncDisplay_cpp@ = .data:0x8056EB20; // type:object size:0x40 scope:local align:32
@@ -42183,7 +42187,7 @@ layoutEx2Heap__5dHeap = .sbss:0x805751BC; // type:object size:0x4 data:4byte
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:0x4 data:4byte
sStopFlags = .sbss:0x805751D0; // type:object size:0x4 data:4byte
g_InitialTime = .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
@@ -43330,7 +43334,7 @@ sFreeCallbackArg__Q23EGG4Heap = .sbss:0x80576760; // type:object size:0x4 data:4
sCreateCallback__Q23EGG4Heap = .sbss:0x80576764; // type:object size:0x4 data:4byte
sDestroyCallback__Q23EGG4Heap = .sbss:0x80576768; // type:object size:0x4 data:4byte
sOldSwitchThreadCallback__Q23EGG6Thread = .sbss:0x80576770; // type:object size:0x4 data:4byte
lbl_80576778 = .sbss:0x80576778; // type:object size:0x8 data:4byte
sInstance__Q23EGG13ThreadMgr = .sbss:0x80576778; // type:object size:0x4 data:4byte
mConfigData__Q23EGG10BaseSystem = .sbss:0x80576780; // type:object size:0x4 data:4byte
sTickPeriod__Q23EGG7Display = .sbss:0x80576788; // type:object size:0x4 data:4byte
spSelector = .sbss:0x80576790; // type:object size:0x4 scope:local data:4byte
+5 -5
View File
@@ -463,7 +463,7 @@ config.libs = [
Object(Matching, "d/d_player_guide_colors.cpp"),
Object(Matching, "d/d_rawarchive.cpp"),
Object(Matching, "d/d_scene.cpp"),
Object(NonMatching, "d/d_state.cpp"),
Object(Matching, "d/d_state.cpp"),
Object(Matching, "d/d_stage_parse.cpp"),
Object(Matching, "d/d_sys.cpp"),
Object(NonMatching, "d/d_sys_init.cpp"),
@@ -878,7 +878,7 @@ config.libs = [
Object(NonMatching, "m/m3d/m_shadow.cpp"),
Object(Matching, "m/m3d/m_scnleaf.cpp"),
Object(Matching, "m/m3d/m_smdl.cpp"),
Object(NonMatching, "m/m3d/m_state.cpp"),
Object(Matching, "m/m3d/m_state.cpp"),
Object(Matching, "m/m2d.cpp"),
Object(Matching, "m/m_allocator.cpp"),
Object(Matching, "m/m_angle.cpp"),
@@ -893,7 +893,7 @@ config.libs = [
Object(Matching, "m/m_pad.cpp"),
# probably two files due to sdata2 float duplication and gap
Object(NonMatching, "m/m_quat.cpp"),
Object(NonMatching, "m/m_thread.cpp"),
Object(Matching, "m/m_thread.cpp"),
Object(NonMatching, "m/m_vec.cpp"),
Object(NonMatching, "m/m_video.cpp"),
],
@@ -1232,8 +1232,8 @@ config.libs = [
Object(Matching, "egg/core/eggAssertHeap.cpp"),
Object(Matching, "egg/core/eggDisposer.cpp"),
Object(Matching, "egg/core/eggThread.cpp"),
Object(NonMatching, "egg/core/eggUnk.cpp"),
Object(NonMatching, "egg/core/eggSystem.cpp"),
Object(Matching, "egg/core/eggThreadMgr.cpp"),
Object(Matching, "egg/core/eggSystem.cpp"),
Object(Matching, "egg/core/eggDisplay.cpp"),
Object(Matching, "egg/core/eggColorFader.cpp"),
Object(Matching, "egg/core/eggAsyncDisplay.cpp"),
+4
View File
@@ -5,6 +5,10 @@
namespace dMain {
bool isStopFlagSet(u32 val);
void setStopFlag(u32 val);
void clearStopFlag(u32 val);
void Create();
void Execute();
void *main01(void *arg);
+1 -1
View File
@@ -8,6 +8,6 @@ void fn_80062E50();
void fn_80062EB0();
bool fn_80062EC0();
}
} // namespace dState
#endif // D_STATE_H
+24
View File
@@ -0,0 +1,24 @@
#ifndef EGG_PERF_H
#define EGG_PERF_H
#include "egg/core/eggThread.h"
namespace EGG {
class PerformanceView {
public:
// vtable at 0x0
/* 0x08 */ virtual void measureBeginFrame() = 0;
/* 0x0C */ virtual void measureEndFrame() = 0;
/* 0x10 */ virtual void measureBeginRender() = 0;
/* 0x14 */ virtual void measureEndRender() = 0;
/* 0x18 */ virtual void callbackDrawSync(u16 token) = 0;
/* 0x1C */ virtual void unused() = 0;
/* 0x20 */ virtual void draw() = 0;
/* 0x24 */ virtual void setVisible(bool visible) = 0;
/* 0x28 */ virtual bool isVisible() = 0;
};
}; // namespace EGG
#endif // EGG_PERF_H
+2 -3
View File
@@ -1,14 +1,13 @@
#ifndef EGG_PROCESS_METER_H
#define EGG_PROCESS_METER_H
#include "egg/core/eggPerf.h"
#include "egg/core/eggThread.h"
namespace EGG {
class PerformanceView {};
class ProcessMeter : public Thread, public PerformanceView {};
};
}; // namespace EGG
#endif // EGG_PROCESS_METER_H
+20
View File
@@ -0,0 +1,20 @@
#ifndef EGG_SCENE_MANAGER_H
#define EGG_SCENE_MANAGER_H
namespace EGG {
class SceneManager {
public:
// vtable at 0x0
/* 0x08 */ virtual void calc();
/* 0x0C */ virtual void draw();
/* 0x10 */ virtual void calcCurrentScene();
/* 0x14 */ virtual void calcCurrentFader();
/* 0x18 */ virtual void drawCurrentScene();
/* 0x1C */ virtual void drawCurrentFader();
/* 0x20 */ virtual void createDefaultFader();
};
} // namespace EGG
#endif // EGG_SCENE_MANAGER_H
+8 -6
View File
@@ -4,6 +4,8 @@
#include "common.h"
#include "egg/core/eggVideo.h"
struct OSBootInfo;
namespace EGG {
class Display;
@@ -35,18 +37,18 @@ public:
/* vt 0x38 */ virtual void initialize() = 0;
public:
/* 0x04 */ u32 mRoot1HeapStart;
/* 0x08 */ u32 mRoot1HeapEnd;
/* 0x0C */ u32 mRoot2HeapStart;
/* 0x10 */ u32 mRoot2HeapEnd;
/* 0x04 */ void *mRoot1HeapStart;
/* 0x08 */ void *mRoot1HeapEnd;
/* 0x0C */ void *mRoot2HeapStart;
/* 0x10 */ void *mRoot2HeapEnd;
/* 0x14 */ u32 mMemSize;
/* 0x18 */ Heap *mRootHeapMem1;
/* 0x1C */ Heap *mRootHeapMem2;
/* 0x20 */ Heap *mRootHeapDebug;
/* 0x24 */ Heap *mSystemHeap;
/* 0x28 */ Thread *mSystemThread;
/* 0x2C */ u32 field_0x2C;
/* 0x30 */ u32 mSystemHeapStart;
/* 0x2C */ OSBootInfo *mBootInfo;
/* 0x30 */ void *mSystemHeapStart;
/* 0x34 */ u32 mSystemHeapSize;
};
class BaseSystem {
+65
View File
@@ -0,0 +1,65 @@
#ifndef EGG_THREAD_MGR_H
#define EGG_THREAD_MGR_H
#include "common.h"
#include "rvl/OS.h" // IWYU pragma: export
// This is seen in Animal Crossing: City Folk also. Idk where it belongs
// Seen between EGG::Thread and EGG::ConfigurationData (eggThread and eggSystem)
// dSysNandThread (or NandRequestThread ) inherits from eggThread,
// with part of that thread referencing tsome of these funcs
namespace EGG {
// Color? Tag?
struct UnknownStruct {
u8 _00;
u8 _01;
u8 _02;
u8 _03;
};
struct ThreadInfo {
OSThread *mThread;
UnknownStruct _04;
bool _08;
char _09[32]; // Buffer for name?
u32 _2C;
};
// This is a complete guess
class ThreadMgr {
public:
void registerThread(OSThread *thread, UnknownStruct);
static ThreadMgr *getInstance() {
return sInstance;
}
private:
s32 getThreadIndex(OSThread *thread);
s32 doRegisterThread(OSThread *thread);
void sortByPriority();
private:
u8 _placeholder_00[0x8];
/* 0x08 */ s32 mMaxThreads;
u8 _placeholder_0C[0x3C - 0xC];
/* 0x3C */ ThreadInfo *mThreadList;
u8 _placeholder_40[0x44 - 0x40];
/* 0x44 */ s32 mThreadCount;
u8 _placeholder_48[0xEC - 0x48];
/* 0xEC */ UnknownStruct _EC; // Default color/tag?
u8 _placeholder_F0[0xF4 - 0xF0];
/* 0xF4 */ u32 _F4;
/* 0xF8 */ bool mSortEnabled;
// size unsure, but this is the limit seen
static ThreadMgr *sInstance;
};
} // namespace EGG
#endif // EGG_THREAD_MGR_H
-25
View File
@@ -1,25 +0,0 @@
#ifndef EGG_UNK_H
#define EGG_UNK_H
#include "common.h"
#include "rvl/OS.h" // IWYU pragma: export
// This is seen in Animal Crossing: City Folk also. Idk where it belongs
// Seen between EGG::Thread and EGG::ConfigurationData (eggThread and eggSystem)
// dSysNandThread (or NandRequestThread ) inherits from eggThread,
// with part of that thread referencing tsome of these funcs
namespace EGG {
class Unknown {
public:
u8 _[0xfC - 0x00]; // size unsure, but this is the limit seen
void fn_80496de0(OSThread *);
void fn_80496e30(OSThread *);
void fn_80496f10();
void fn_804970e0(OSThread *, u8 *);
};
} // namespace EGG
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef M3D_M_STATE_H
#define M3D_M_STATE_H
namespace m3d {
namespace mState {
void unkStub1();
void unkStub2();
void unkStub3();
bool unkAlwaysTrue();
} // namespace mState
} // namespace m3d
#endif // M3D_M_STATE_H
+8
View File
@@ -3,4 +3,12 @@
// This file is a complete guess
struct OSThread;
namespace mThread {
void registerThread(OSThread *thread, void *threadArg);
} // namespace mThread
#endif
+11 -11
View File
@@ -7,15 +7,14 @@
#include "rvl/OS.h"
u32 lbl_805751D0;
OSTime g_InitialTime;
u32 sStopFlags;
bool fn_80054F90(u32 val) {
return lbl_805751D0 & val;
bool dMain::isStopFlagSet(u32 val) {
return sStopFlags & val;
}
void fn_80054FB0(u32 val) {
u32 flags = lbl_805751D0;
void dMain::setStopFlag(u32 val) {
u32 flags = sStopFlags;
if (!flags) {
fManager_c::setStopProcFlags(
@@ -24,13 +23,13 @@ void fn_80054FB0(u32 val) {
);
}
lbl_805751D0 = flags | val;
sStopFlags = flags | val;
}
void fn_80054FE0(u32 val) {
lbl_805751D0 &= ~val;
void dMain::clearStopFlag(u32 val) {
sStopFlags &= ~val;
if (!lbl_805751D0) {
if (!sStopFlags) {
fManager_c::maskStopProcFlags(fManager_c::PROC_FLAG_DRAW);
}
}
@@ -54,7 +53,8 @@ void *dMain::main01(void *arg) {
#define STACK_SIZE 0xF000
static OSThread MAIN_THREAD;
OSTime g_InitialTime;
OSThread MAIN_THREAD;
void main(int argc, char **argv) {
u8 pStackBase[STACK_SIZE] __attribute__((aligned(32)));
+30
View File
@@ -0,0 +1,30 @@
#include "d/d_state.h"
#include "d/d_main.h"
#include "m/m3d/m_state.h"
void dState::fn_80062E40() {
m3d::mState::unkStub1();
}
void dState::fn_80062E50() {
m3d::mState::unkStub2();
if (m3d::mState::unkAlwaysTrue()) {
if (dMain::isStopFlagSet(1)) {
dMain::clearStopFlag(1);
}
} else {
if (!dMain::isStopFlagSet(1)) {
dMain::setStopFlag(1);
}
}
}
void dState::fn_80062EB0() {
m3d::mState::unkStub3();
}
bool dState::fn_80062EC0() {
return m3d::mState::unkAlwaysTrue();
}
+119
View File
@@ -0,0 +1,119 @@
#include "egg/core/eggSystem.h"
#include "egg/audio/eggAudioMgr.h"
#include "egg/core/eggController.h"
#include "egg/core/eggDisplay.h"
#include "egg/core/eggExpHeap.h"
#include "egg/core/eggHeap.h"
#include "egg/core/eggPerf.h"
#include "egg/core/eggSceneManager.h"
#include "rvl/OS.h"
#define MB_TO_BYTES(mb) ((mb) * 1024 * 1024)
#define RETAIL_MEM2_SIZE MB_TO_BYTES(64)
namespace EGG {
ConfigurationData *BaseSystem::mConfigData;
void ConfigurationData::initMemory() {
void *pMEM1ArenaLo = OSGetMEM1ArenaLo();
void *pMEM1ArenaHi = OSGetMEM1ArenaHi();
void *pMEM2ArenaLo = OSGetMEM2ArenaLo();
void *pMEM2ArenaHi = OSGetMEM2ArenaHi();
pMEM1ArenaLo = ROUND_UP_PTR(pMEM1ArenaLo, 32);
pMEM1ArenaHi = ROUND_DOWN_PTR(pMEM1ArenaHi, 32);
pMEM2ArenaLo = ROUND_UP_PTR(pMEM2ArenaLo, 32);
pMEM2ArenaHi = ROUND_DOWN_PTR(pMEM2ArenaHi, 32);
mBootInfo = &OS_BOOT_INFO;
mSystemHeapStart = pMEM1ArenaLo;
mRoot1HeapStart = pMEM1ArenaLo;
mRoot1HeapEnd = pMEM1ArenaHi;
mRoot2HeapStart = pMEM2ArenaLo;
mRoot2HeapEnd = pMEM2ArenaHi;
mMemSize = mBootInfo->physMemSize;
OSSetMEM1ArenaLo(pMEM1ArenaHi);
OSSetMEM1ArenaHi(pMEM1ArenaHi);
OSSetMEM2ArenaLo(pMEM2ArenaHi);
OSSetMEM2ArenaHi(pMEM2ArenaHi);
Heap::initialize();
void *root1HeapPtr = mRoot1HeapStart;
u32 root1HeapSize = (u32)mRoot1HeapEnd - (u32)mRoot1HeapStart;
void *root2HeapPtr = mRoot2HeapStart;
u32 root2HeapSize = (u32)mRoot2HeapEnd - (u32)mRoot2HeapStart;
u32 debugHeapSize;
if (root2HeapSize >= RETAIL_MEM2_SIZE) {
debugHeapSize = RETAIL_MEM2_SIZE;
root2HeapSize = OSRoundDown32B(root2HeapSize - RETAIL_MEM2_SIZE);
} else {
debugHeapSize = 0;
}
void *debugHeapPtr = (u8 *)root2HeapPtr + root2HeapSize;
mRootHeapMem1 = ExpHeap::create(root1HeapPtr, root1HeapSize, 0);
mRootHeapMem1->setName("EGGRootMEM1");
mRootHeapMem2 = ExpHeap::create(root2HeapPtr, root2HeapSize, 0);
mRootHeapMem2->setName("EGGRootMEM2");
if (debugHeapSize > 0) {
mRootHeapDebug = ExpHeap::create(debugHeapPtr, debugHeapSize, 0);
mRootHeapDebug->setName("EGGRootDebug");
} else {
mRootHeapDebug = nullptr;
}
mSystemHeap = ExpHeap::create(mSystemHeapSize, mRootHeapMem1, 0);
mSystemHeap->setName("EGGSystem");
mSystemHeap->becomeCurrentHeap();
}
void ConfigurationData::run() {
CoreControllerMgr *pControllerMgr = CoreControllerMgr::instance();
while (true) {
getDisplay()->beginFrame();
onBeginFrame();
getPerfView()->measureBeginFrame();
pControllerMgr->beginFrame();
getDisplay()->beginRender();
getPerfView()->measureBeginRender();
getSceneMgr()->draw();
getPerfView()->draw();
getPerfView()->measureEndRender();
getDisplay()->endRender();
getSceneMgr()->calc();
pControllerMgr->endFrame();
if (getAudioMgr()) {
getAudioMgr()->calc();
}
getDisplay()->endFrame();
onEndFrame();
getPerfView()->measureEndFrame();
}
}
} // namespace EGG
+73
View File
@@ -0,0 +1,73 @@
#include "egg/core/eggThreadMgr.h"
#include "rvl/OS.h"
namespace EGG {
ThreadMgr *ThreadMgr::sInstance; // Never initialized
s32 ThreadMgr::getThreadIndex(OSThread *thread) {
for (s32 i = 0; i < mThreadCount; i++) {
if (mThreadList[i].mThread == thread) {
return i;
}
}
return -1;
}
s32 ThreadMgr::doRegisterThread(OSThread *thread) {
if (mThreadCount != mMaxThreads) {
s32 i = mThreadCount;
mThreadList[i].mThread = thread;
mThreadList[i]._04 = _EC;
mThreadList[i]._08 = true;
mThreadList[i]._09[0] = '\0';
mThreadList[i]._2C = _F4;
mThreadCount++;
if (mSortEnabled) {
sortByPriority();
}
return getThreadIndex(thread);
}
return -1;
}
void ThreadMgr::sortByPriority() {
// Selection sort on thread priority
for (s32 i = 0; i < mThreadCount - 1; i++) {
OSPriority minPrio = 31;
s32 minPrioIndex = -1;
for (s32 j = i; j < mThreadCount; j++) {
OSPriority prio = OSGetThreadPriority(mThreadList[j].mThread);
if (prio <= minPrio) {
minPrio = prio;
minPrioIndex = j;
}
}
if (i != minPrioIndex) {
ThreadInfo temp = mThreadList[i];
mThreadList[i] = mThreadList[minPrioIndex];
mThreadList[minPrioIndex] = temp;
}
}
}
void ThreadMgr::registerThread(OSThread *thread, UnknownStruct arg) {
s32 i = getThreadIndex(thread);
if (i == -1) {
i = doRegisterThread(thread);
}
if (i != -1) {
mThreadList[i]._04 = arg;
}
}
} // namespace EGG
+15
View File
@@ -0,0 +1,15 @@
#include "m/m3d/m_state.h"
namespace m3d {
void mState::unkStub1() {}
void mState::unkStub2() {}
void mState::unkStub3() {}
bool mState::unkAlwaysTrue() {
return true;
}
}
+10
View File
@@ -0,0 +1,10 @@
#include "m/m_thread.h"
#include "egg/core/eggThreadMgr.h"
#include "rvl/OS/OSThread.h"
void mThread::registerThread(OSThread *thread, void *threadArg) {
if (threadArg && EGG::ThreadMgr::getInstance()) {
EGG::ThreadMgr::getInstance()->registerThread(thread, *(EGG::UnknownStruct *)threadArg);
}
}
+2 -3
View File
@@ -4,6 +4,7 @@
#include "egg/core/eggAssertHeap.h" // IWYU pragma: export
#include "egg/core/eggThread.h"
#include "m/m_heap.h"
#include "m/m_thread.h"
#include "rvl/NAND/NANDCheck.h"
#include "rvl/NAND/NANDCore.h"
#include "rvl/NAND/nand.h"
@@ -13,8 +14,6 @@
#include <cstring>
extern "C" void fn_802F2920(OSThread *, size_t);
NandRequestThread::NandRequestThread(
int priority, EGG::Heap *commandHeap, void *bufFromGameHeap, size_t bufSize, void *mThreadArg, EGG::Heap *heap
)
@@ -27,7 +26,7 @@ NandRequestThread::NandRequestThread(
mBufSize = bufSize;
setThreadCurrentHeap(mHeap::g_assertHeap);
fn_802F2920(mOSThread, bufSize);
mThread::registerThread(mOSThread, mThreadArg);
OSInitMessageQueue(&mMessageQueue, &mMessageBuffer, 1);
OSInitMutex(&mMutex);
OSResumeThread(mOSThread);