diff options
| author | lepelog <25211966+lepelog@users.noreply.github.com> | 2025-08-02 00:39:03 +0200 |
|---|---|---|
| committer | lepelog <25211966+lepelog@users.noreply.github.com> | 2025-08-14 01:05:30 +0200 |
| commit | ea11808636d75072cd9a32c06d4aa207ef60c87c (patch) | |
| tree | 1c21620ab240cf06abe60a1e3616d567573fe183 /src | |
| parent | 899f86a57111df7545e5ab031e92d8564faa112a (diff) | |
d_thp with THPPlayer headers from SMS
Diffstat (limited to 'src')
| -rw-r--r-- | src/d/d_reset.cpp | 4 | ||||
| -rw-r--r-- | src/d/d_thp_player.cpp | 173 |
2 files changed, 175 insertions, 2 deletions
diff --git a/src/d/d_reset.cpp b/src/d/d_reset.cpp index 4f2910f2..096eddd4 100644 --- a/src/d/d_reset.cpp +++ b/src/d/d_reset.cpp @@ -27,6 +27,7 @@ #include "rvl/VI/vi.h" #include "toBeSorted/file_manager.h" #include "toBeSorted/save_manager.h" +#include "THPPlayer/THPPlayer.h" #include "rvl/OS.h" @@ -296,7 +297,6 @@ void Manage_c::ModeProc_Normal() { } } -extern "C" void fn_803267B0(s32, s32); void Manage_c::ModeInit_SoftReset() { DebugPrintMode("SoftReset"); if (mSoftReset) { @@ -315,7 +315,7 @@ void Manage_c::ModeInit_SoftReset() { } else { dSndPlayerMgr_c::GetInstance()->fn_8035E250(30); } - fn_803267B0(0, 60); + THPPlayerSetVolume(0, 60); mpFader->setFrame(30); mpFader->fadeOut(); field_0x66 = true; diff --git a/src/d/d_thp_player.cpp b/src/d/d_thp_player.cpp new file mode 100644 index 00000000..295fb160 --- /dev/null +++ b/src/d/d_thp_player.cpp @@ -0,0 +1,173 @@ + +#include "common.h" +#include "d/d_sys.h" +#include "f/f_base.h" +#include "f/f_profile.h" +#include "f/f_profile_name.h" +#include "m/m_color.h" +#include "m/m_video.h" +#include "rvl/OS/OSError.h" +#include "nw4r/ut/ut_LockedCache.h" +#include "m/m_heap.h" +#include "m/m3d/m3d.h" +#include "m/m_dvd.h" +#include "d/d_heap.h" +#include "THPPlayer/THPPlayer.h" +#include "d/d_thp_player.h" +#include "d/d_gfx.h" + +SPECIAL_BASE_PROFILE(THPPLAYER, dThpPlayer_c, fProfile::THPPLAYER, 0x3, 0x400); + +int dThpPlayer_c::create() { + reallyCreate(mVideo::m_video->pRenderMode->fbWidth, mVideo::m_video->pRenderMode->efbHeight); + return 1; +} + +int dThpPlayer_c::doDelete() { + if (destroy() == 0) { + return NOT_READY; +} else { + THPPlayerQuit(); + return SUCCEEDED; + } +} +int dThpPlayer_c::execute() { + reallyExecute(); + return SUCCEEDED; +} +int dThpPlayer_c::draw() { + dSys_c::setClearColor(mColor(0xFF)); + mScreen.addToDrawList(); + return SUCCEEDED; +} + +dThpPlayer_c::dThpPlayer_c(): mDvdCallback(), mFilename(), mLoadAllAtOnce(0), mFilenameSet(0), mSetupDone(0), isPlaying(0), mBuffer(nullptr), mScreen(), mSpecialType(3) {} + +dThpPlayer_c::~dThpPlayer_c() { + if (mBuffer != nullptr) { + dHeap::work2Heap.heap->free(mBuffer); + mBuffer = nullptr; + } +} + +void dThpPlayer_c::reallyCreate(u16 efbWidth, u16 efbHeight) { + THPPlayerInit(1); + isPlaying = 0; + mBuffer = nullptr; + mScreen.setEfbWidth(efbWidth); + mScreen.setEfbHeight(efbHeight); + m3d::resetMaterial(); +} + +extern "C" { + s32 THPVideoDecode(s32 p1, s32 p2, s32 p3, s32 p4, s32 p5); +} + +void drawTHPFrame(u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6) { + THPPlayerDrawCurrentFrame(p1, p2, p3, p4, p5, p6); + THPPlayerPostDrawDone(); +} + +static s32 callback(void* player) { + ((dThpPlayer_c*) player)->open(); + return 1; +} + +void dThpPlayer_c::open() { + if (!THPPlayerOpen(mFilename.mChars, mLoadAllAtOnce)) { + mFilenameSet = 0; + } +} + +void dThpPlayer_c::setupFile(char* filename, s32 loadAllAtOnce) { + if (destroy()) { + mFilenameSet = 1; + mFilename = filename; + mLoadAllAtOnce = loadAllAtOnce; + mDvdCallback = mDvd_callback_c::createOrDie((dvdReadCallback)callback, this); + } +} + +static const u8 SPECIAL_TYPES[] = {0x7A, 0x78, 0x78}; + +void dThpPlayer_c::reallyExecute() { + if (mDvdCallback == nullptr || mDvdCallback->mStatus == 0 || !mFilenameSet || mSetupDone) { + return; + } + if (mFilename == "THP/Demo01_01.thp") { + mSpecialType = 0; + } else if (mFilename == "THP/Demo01_02.thp") { + mSpecialType = 1; + } else if (mFilename == "THP/Demo78_01.thp") { + mSpecialType = 2; + } + if (mSpecialType != 3) { + THPPlayerSetVolume(SPECIAL_TYPES[mSpecialType], 0); + } + THPPlayerGetVideoInfo(&mVideoComponent); + THPPlayerGetAudioInfo(&mAudioComponent); + mScreen.setVideoDimensions( + mVideoComponent.xSize, + (mVideoComponent.ySize * (dGfx_c::getEFBHeightF() / dGfx_c::getCurrentScreenHeightF())) + ); + mBuffer = (u8*)dHeap::work2Heap.heap->alloc(THPPlayerCalcNeedMemory(), 0x20); + if (mBuffer == nullptr) { + #line 279 + OSError("Can\'t allocate memory."); + } else { + THPPlayerSetBuffer(mBuffer); + if (THPPlayerPrepare(0, 0, 0) == 0) { + #line 288 + OSError("Fail to prepare."); + } else { + mSetupDone = 1; + } + } +} + +s32 dThpPlayer_c::play() { + if (!mFilenameSet) { + return true; + } else if (!mSetupDone) { + return false; + } else { + THPPlayerPlay(); + isPlaying = 1; + return true; + } +} + +s32 dThpPlayer_c::destroy() { + if (mDvdCallback != nullptr) { + if (mDvdCallback->mStatus == 0) { + return NOT_READY; + } + THPPlayerStop(); + THPPlayerClose(); + if (mBuffer != nullptr) { + dHeap::work2Heap.heap->free(mBuffer); + mBuffer = nullptr; + } + mDvdCallback->do_delete(); + mDvdCallback = nullptr; + mFilenameSet = 0; + mSetupDone = 0; + isPlaying = 0; + } + return SUCCEEDED; +} + +s32 dThpPlayer_c::isDone() { + return THPPlayerGetState() == 3; +} + +void ThpVideoScreen::draw() { + drawTHPFrame(mEfbWidth, mEfbHeight, (mEfbWidth - mVideoWidth) / 2, (mEfbHeight - mVideoHeight) / 2, mVideoWidth, mVideoHeight); +} + +extern "C" s32 fn_80273B50(s32 p1, s32 p2, s32 p3, s32 p4, s32 p5) { + nw4r::ut::LC::Lock(); + s32 result = THPVideoDecode(p1, p2, p3, p4, p5); + nw4r::ut::LC::Unlock(); + return result; +} |
