From ec9a3af9e98853fd493631153ee78e32d73b9046 Mon Sep 17 00:00:00 2001 From: Max <34987259+mparisi20@users.noreply.github.com> Date: Sat, 2 May 2026 22:01:13 -0400 Subject: [PATCH] Match mv_THPRead.cpp --- config/RSBE01_02/splits.txt | 6 +- config/RSBE01_02/symbols.txt | 24 +++---- configure.py | 1 + include/lib/BrawlHeaders | 2 +- src/sora/mv/mv_THPAudioDecode.cpp | 6 +- src/sora/mv/mv_THPRead.cpp | 114 ++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 src/sora/mv/mv_THPRead.cpp diff --git a/config/RSBE01_02/splits.txt b/config/RSBE01_02/splits.txt index c6471c8..be2790d 100644 --- a/config/RSBE01_02/splits.txt +++ b/config/RSBE01_02/splits.txt @@ -181,7 +181,11 @@ sora/snd/snd_init_thread.cpp: sora/mv/mv_THPAudioDecode.cpp: .text start:0x8007B0B4 end:0x8007B4A4 - .sbss start:0x805A01E0 end:0x805A01E8 + .sbss start:0x805A01E0 end:0x805A01E4 + +sora/mv/mv_THPRead.cpp: + .text start:0x8007E0EC end:0x8007E3A4 + .sbss start:0x805A0200 end:0x805A0204 sora/cm/cm_controller_default.cpp: .text start:0x8009F560 end:0x8009F564 diff --git a/config/RSBE01_02/symbols.txt b/config/RSBE01_02/symbols.txt index 3ca2afc..dffa610 100644 --- a/config/RSBE01_02/symbols.txt +++ b/config/RSBE01_02/symbols.txt @@ -3938,16 +3938,16 @@ fn_8007D9F8 = .text:0x8007D9F8; // type:function size:0x290 fn_8007DC88 = .text:0x8007DC88; // type:function size:0x118 fn_8007DDA0 = .text:0x8007DDA0; // type:function size:0x330 fn_8007E0D0 = .text:0x8007E0D0; // type:function size:0x1C -fn_8007E0EC = .text:0x8007E0EC; // type:function size:0x8 -fn_8007E0F4 = .text:0x8007E0F4; // type:function size:0x1C -fn_8007E110 = .text:0x8007E110; // type:function size:0xC -fn_8007E11C = .text:0x8007E11C; // type:function size:0xA0 -fn_8007E1BC = .text:0x8007E1BC; // type:function size:0x1C -fn_8007E1D8 = .text:0x8007E1D8; // type:function size:0x40 -fn_8007E218 = .text:0x8007E218; // type:function size:0xFC +GetSizeTHPReadWork__Fv = .text:0x8007E0EC; // type:function size:0x8 +SetTHPReadWork__FP11THPReadWork = .text:0x8007E0F4; // type:function size:0x1C +FreeTHPReadWork__Fv = .text:0x8007E110; // type:function size:0xC +CreateReadThread__Fl = .text:0x8007E11C; // type:function size:0xA0 +ReadThreadStart__Fv = .text:0x8007E1BC; // type:function size:0x1C +ReadThreadCancel__Fv = .text:0x8007E1D8; // type:function size:0x40 +Reader__FPv = .text:0x8007E218; // type:function size:0xFC PopReadedBuffer__Fv = .text:0x8007E314; // type:function size:0x34 -fn_8007E348 = .text:0x8007E348; // type:function size:0x14 -fn_8007E35C = .text:0x8007E35C; // type:function size:0x34 +PushFreeReadBuffer__FPv = .text:0x8007E348; // type:function size:0x14 +PopReadedBuffer2__Fv = .text:0x8007E35C; // type:function size:0x34 PushReadedBuffer2__FPv = .text:0x8007E390; // type:function size:0x14 fn_8007E3A4 = .text:0x8007E3A4; // type:function size:0x8 fn_8007E3AC = .text:0x8007E3AC; // type:function size:0x1C @@ -9317,7 +9317,7 @@ fn_801F6524 = .text:0x801F6524; // type:function size:0x24 fn_801F6548 = .text:0x801F6548; // type:function size:0x1C0 fn_801F6708 = .text:0x801F6708; // type:function size:0xD0 fn_801F67D8 = .text:0x801F67D8; // type:function size:0x18 -fn_801F67F0 = .text:0x801F67F0; // type:function size:0x128 +DVDReadPrio = .text:0x801F67F0; // type:function size:0x128 fn_801F6918 = .text:0x801F6918; // type:function size:0x8 fn_801F6920 = .text:0x801F6920; // type:function size:0xB0 fn_801F69D0 = .text:0x801F69D0; // type:function size:0x8 @@ -30726,13 +30726,13 @@ lbl_805A01CC = .sbss:0x805A01CC; // type:object size:0x1 data:byte g_sndSystem = .sbss:0x805A01D0; // type:object size:0x4 data:4byte lbl_805A01D4 = .sbss:0x805A01D4; // type:object size:0x4 data:4byte lbl_805A01D8 = .sbss:0x805A01D8; // type:object size:0x8 data:4byte -g_audioDecWork = .sbss:0x805A01E0; // type:object size:0x8 data:4byte +g_audioDecWork = .sbss:0x805A01E0; // type:object size:0x4 data:4byte lbl_805A01E8 = .sbss:0x805A01E8; // type:object size:0x4 data:4byte lbl_805A01EC = .sbss:0x805A01EC; // type:object size:0x4 data:4byte lbl_805A01F0 = .sbss:0x805A01F0; // type:object size:0x4 data:4byte lbl_805A01F4 = .sbss:0x805A01F4; // type:object size:0x4 data:4byte lbl_805A01F8 = .sbss:0x805A01F8; // type:object size:0x8 data:4byte -lbl_805A0200 = .sbss:0x805A0200; // type:object size:0x8 data:4byte +g_readWork = .sbss:0x805A0200; // type:object size:0x4 scope:local data:4byte lbl_805A0208 = .sbss:0x805A0208; // type:object size:0x8 data:4byte lbl_805A0210 = .sbss:0x805A0210; // type:object size:0x4 data:4byte lbl_805A0214 = .sbss:0x805A0214; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index a9a8462..be9a88f 100755 --- a/configure.py +++ b/configure.py @@ -328,6 +328,7 @@ def MatchingFor(*versions): Object(Matching, "sora/ec/ec_trace_mgr.cpp"), Object(Matching, "sora/snd/snd_init_thread.cpp"), Object(Matching, "sora/mv/mv_THPAudioDecode.cpp"), + Object(Matching, "sora/mv/mv_THPRead.cpp"), Object(Matching, "sora/cm/cm_controller_default.cpp", extra_cflags=["-RTTI off"]), Object(NonMatching, "sora/cm/cm_controller_menu_fixed.cpp"), Object(Matching, "sora/cm/cm_controller_melee_fixed.cpp"), diff --git a/include/lib/BrawlHeaders b/include/lib/BrawlHeaders index 60bdfee..c6027f7 160000 --- a/include/lib/BrawlHeaders +++ b/include/lib/BrawlHeaders @@ -1 +1 @@ -Subproject commit 60bdfee45716410c9bb856574dc1f1c27fe1051a +Subproject commit c6027f7ee674d4a8165003edf507b598f11fd338 diff --git a/src/sora/mv/mv_THPAudioDecode.cpp b/src/sora/mv/mv_THPAudioDecode.cpp index 839b11e..d0433ab 100644 --- a/src/sora/mv/mv_THPAudioDecode.cpp +++ b/src/sora/mv/mv_THPAudioDecode.cpp @@ -30,13 +30,13 @@ bool CreateAudioDecodeThread(s32 prio, void* funcArg) { if (funcArg) { if (!OSCreateThread(&g_audioDecWork->m_thread, AudioDecoderForOnMemory, funcArg, g_audioDecWork->m_stack + THPAudioDecWork::StackSize, - THPAudioDecWork::StackSize, prio, 1)) { + THPAudioDecWork::StackSize, prio, OS_THREAD_DETACHED)) { return false; } } else { if (!OSCreateThread(&g_audioDecWork->m_thread, AudioDecoder, nullptr, g_audioDecWork->m_stack + THPAudioDecWork::StackSize, THPAudioDecWork::StackSize, - prio, 1)) { + prio, OS_THREAD_DETACHED)) { return false; } } @@ -76,7 +76,7 @@ void* AudioDecoder(void* p1) { if (r29 == 2) { PrepareReady(true); } - PushReadedBuffer2(static_cast(r30)); + PushReadedBuffer2(r30); r29++; } } diff --git a/src/sora/mv/mv_THPRead.cpp b/src/sora/mv/mv_THPRead.cpp new file mode 100644 index 0000000..4a75fe5 --- /dev/null +++ b/src/sora/mv/mv_THPRead.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include + +static THPReadWork* g_readWork; + +u32 GetSizeTHPReadWork() { + return sizeof(THPReadWork); +} + +void SetTHPReadWork(THPReadWork* work) { + if (!g_readWork) { + g_readWork = work; + work->m_threadActive = false; + } +} + +void FreeTHPReadWork() { + g_readWork = nullptr; +} + +static void* Reader(void* arg); + +bool CreateReadThread(s32 prio) { + if (!OSCreateThread(&g_readWork->m_thread, Reader, + nullptr, g_readWork->m_stack + THPReadWork::StackSize, + THPReadWork::StackSize, prio, OS_THREAD_DETACHED)) { + return false; + } + OSInitMessageQueue(&g_readWork->m_freeReadQueue, + g_readWork->m_freeReadBuf, THPReadWork::BufferCap); + OSInitMessageQueue(&g_readWork->m_pastReadQueue, + g_readWork->m_pastReadBuf, THPReadWork::BufferCap); + OSInitMessageQueue(&g_readWork->m_pastRead2Queue, + g_readWork->m_pastRead2Buf, THPReadWork::BufferCap); + g_readWork->m_threadActive = true; + return true; +} + +void ReadThreadStart() { + if (g_readWork->m_threadActive) { + OSResumeThread(&g_readWork->m_thread); + } +} + +void ReadThreadCancel() { + if (g_readWork->m_threadActive) { + OSCancelThread(&g_readWork->m_thread); + g_readWork->m_threadActive = false; + } +} + +static void* Reader(void* arg) { + s32 offs = g_thpObject.unkB8; + s32 size = g_thpObject.unkBC; + s32 i = 0; + while (true) { + THPReadMessage* readMsg = reinterpret_cast(PopFreeReadBuffer()); + s32 bytesRead = DVDReadPrio(&g_thpObject.m_fInfo, readMsg->m_block, size, offs, 2); + if (bytesRead != size) { + if (bytesRead == DVD_RESULT_FATAL) + g_thpObject.unkA8 = -1; + if (i == 0) + PrepareReady(false); + OSSuspendThread(&g_readWork->m_thread); + } + readMsg->m_blockNum = i; + PushReadedBuffer(readMsg); + offs += size; + size = readMsg->m_block->m_nextBlockSize; + + u32 pos = (i + g_thpObject.unkC0) % g_thpObject.unk50; + if (pos == (g_thpObject.unk50 - 1)) { + if (g_thpObject.unkA6 & 0x1) + offs = g_thpObject.unk64; + else + OSSuspendThread(&g_readWork->m_thread); + } + i++; + } +} + +OSMessage PopReadedBuffer() { + OSMessage msg; + OSReceiveMessage(&g_readWork->m_pastReadQueue, &msg, OS_MSG_BLOCKING); + return msg; +} + +void PushReadedBuffer(OSMessage msg) { + OSSendMessage(&g_readWork->m_pastReadQueue, msg, OS_MSG_BLOCKING); +} + +OSMessage PopFreeReadBuffer() { + OSMessage msg; + OSReceiveMessage(&g_readWork->m_freeReadQueue, &msg, OS_MSG_BLOCKING); + return msg; +} + +void PushFreeReadBuffer(OSMessage msg) { + OSSendMessage(&g_readWork->m_freeReadQueue, msg, OS_MSG_BLOCKING); +} + +OSMessage PopReadedBuffer2() { + OSMessage msg; + OSReceiveMessage(&g_readWork->m_pastRead2Queue, &msg, OS_MSG_BLOCKING); + return msg; +} + +void PushReadedBuffer2(OSMessage msg) { + OSSendMessage(&g_readWork->m_pastRead2Queue, msg, OS_MSG_BLOCKING); +}