diff --git a/CMakeLists.txt b/CMakeLists.txt index ce8774aa..da3e31a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,7 @@ add_library(lego1 SHARED LEGO1/mxpresenterlist.cpp LEGO1/mxramstreamcontroller.cpp LEGO1/mxramstreamprovider.cpp + LEGO1/mxregion.cpp LEGO1/mxscheduler.cpp LEGO1/mxsemaphore.cpp LEGO1/mxsmkpresenter.cpp diff --git a/LEGO1/mxmusicmanager.cpp b/LEGO1/mxmusicmanager.cpp index c1488f43..1318d50b 100644 --- a/LEGO1/mxmusicmanager.cpp +++ b/LEGO1/mxmusicmanager.cpp @@ -120,44 +120,32 @@ void MxMusicManager::SetVolume(MxS32 p_volume) } // OFFSET: LEGO1 0x100c0840 -MxResult MxMusicManager::StartMIDIThread(MxU32 p_frequencyMS, MxBool p_noRegister) +MxResult MxMusicManager::StartMIDIThread(MxU32 p_frequencyMS, MxBool p_createThread) { MxResult status = FAILURE; MxBool locked = FALSE; - MxResult result = MxAudioManager::InitPresenters(); - if (result == SUCCESS) - { - if (p_noRegister) - { + if (MxAudioManager::InitPresenters() == SUCCESS) { + if (p_createThread) { m_criticalSection.Enter(); locked = TRUE; m_thread = new MxTickleThread(this, p_frequencyMS); - if (m_thread) - { - if (m_thread->Start(0, 0) == SUCCESS) - { - status = SUCCESS; - } - } + if (!m_thread || m_thread->Start(0, 0) != SUCCESS) + goto done; } else - { TickleManager()->RegisterClient(this, p_frequencyMS); - status = SUCCESS; - } + + status = SUCCESS; } +done: if (status != SUCCESS) - { Destroy(); - } if (locked) - { m_criticalSection.Leave(); - } return status; } \ No newline at end of file diff --git a/LEGO1/mxmusicmanager.h b/LEGO1/mxmusicmanager.h index b46c8878..4e037bee 100644 --- a/LEGO1/mxmusicmanager.h +++ b/LEGO1/mxmusicmanager.h @@ -14,7 +14,7 @@ class MxMusicManager : public MxAudioManager virtual void Destroy() override; // vtable+18 virtual void SetVolume(MxS32 p_volume) override; // vtable+2c - virtual MxResult StartMIDIThread(MxU32 p_frequencyMS, MxU8 p_noRegister); // vtable+30 + virtual MxResult StartMIDIThread(MxU32 p_frequencyMS, MxBool p_createThread); // vtable+30 inline MxBool GetMIDIInitialized() { return m_MIDIInitialized; } diff --git a/LEGO1/mxomni.cpp b/LEGO1/mxomni.cpp index 43b9578a..028b0af4 100644 --- a/LEGO1/mxomni.cpp +++ b/LEGO1/mxomni.cpp @@ -254,8 +254,7 @@ MxResult MxOmni::Create(MxOmniCreateParam &p) MxVideoManager *videoManager = new MxVideoManager(); this->m_videoManager = videoManager; - if (videoManager != NULL && videoManager->vtable0x2c(p.GetVideoParam(), 100, 0) != SUCCESS) - { + if (videoManager && videoManager->Create(p.GetVideoParam(), 100, 0) != SUCCESS) { delete m_videoManager; m_videoManager = NULL; } diff --git a/LEGO1/mxregion.cpp b/LEGO1/mxregion.cpp new file mode 100644 index 00000000..8b275e24 --- /dev/null +++ b/LEGO1/mxregion.cpp @@ -0,0 +1,39 @@ +#include "mxregion.h" + +DECOMP_SIZE_ASSERT(MxRegion, 0x1c); + +// OFFSET: LEGO1 0x100c31c0 STUB +MxRegion::MxRegion() +{ + // TODO +} + +// OFFSET: LEGO1 0x100c3690 STUB +MxRegion::~MxRegion() +{ + // TODO +} + +// OFFSET: LEGO1 0x100c3700 STUB +void MxRegion::Reset() +{ + // TODO +} + +// OFFSET: LEGO1 0x100c3750 STUB +void MxRegion::vtable18() +{ + // TODO +} + +// OFFSET: LEGO1 0x100c3e20 STUB +void MxRegion::vtable1c() +{ + // TODO +} + +// OFFSET: LEGO1 0x100c3660 STUB +void MxRegion::vtable20() +{ + // TODO +} \ No newline at end of file diff --git a/LEGO1/mxregion.h b/LEGO1/mxregion.h index 717be924..92493c32 100644 --- a/LEGO1/mxregion.h +++ b/LEGO1/mxregion.h @@ -2,6 +2,7 @@ #define MXREGION_H #include "mxcore.h" +#include "decomp.h" // VTABLE 0x100dcae8 // SIZE 0x1c @@ -21,6 +22,7 @@ class MxRegion : public MxCore // MxList *m_rects; // 4 coordinates (could be MxRect32) // MxS32 left, top, right, bottom; + undefined pad[0x14]; }; #endif // MXREGION_H diff --git a/LEGO1/mxvideomanager.cpp b/LEGO1/mxvideomanager.cpp index 44a04169..5c45f00d 100644 --- a/LEGO1/mxvideomanager.cpp +++ b/LEGO1/mxvideomanager.cpp @@ -155,14 +155,146 @@ MxLong MxVideoManager::RealizePalette(MxPalette *p_palette) return 0; } -// OFFSET: LEGO1 0x100be600 STUB -void MxVideoManager::vtable0x28() +// OFFSET: LEGO1 0x100be600 +MxResult MxVideoManager::vtable0x28( + MxVideoParam &p_videoParam, + LPDIRECTDRAW p_pDirectDraw, + LPDIRECTDRAWSURFACE p_pDDSurface, + LPDIRECTDRAWSURFACE p_ddSurface1, + LPDIRECTDRAWSURFACE p_ddSurface2, + LPDIRECTDRAWCLIPPER p_ddClipper, + MxU32 p_frequencyMS, + MxBool p_createThread) { + MxBool locked = FALSE; + MxResult status = FAILURE; + m_unk60 = FALSE; + + if (MxMediaManager::InitPresenters() != SUCCESS) + goto done; + + m_criticalSection.Enter(); + locked = TRUE; + + m_videoParam = p_videoParam; + m_region = new MxRegion(); + + if (!m_region) + goto done; + + m_pDirectDraw = p_pDirectDraw; + m_pDDSurface = p_pDDSurface; + + MxPalette *palette; + if (p_videoParam.GetPalette() == NULL) { + palette = new MxPalette(); + m_videoParam.SetPalette(palette); + + if (!palette) + goto done; + } + else { + palette = p_videoParam.GetPalette()->Clone(); + m_videoParam.SetPalette(palette); + + if (!palette) + goto done; + } + + m_displaySurface = new MxDisplaySurface(); + if (m_displaySurface && m_displaySurface->Init(m_videoParam, p_ddSurface1, p_ddSurface2, p_ddClipper) == SUCCESS) { + m_displaySurface->SetPalette(m_videoParam.GetPalette()); + + if (p_createThread) { + m_thread = new MxTickleThread(this, p_frequencyMS); + + if (!m_thread || m_thread->Start(0, 0) != SUCCESS) + goto done; + } + else + TickleManager()->RegisterClient(this, p_frequencyMS); + + status = SUCCESS; + } + +done: + if (status != SUCCESS) + Destroy(); + + if (locked) + m_criticalSection.Leave(); + + return status; } -// OFFSET: LEGO1 0x100bebe0 STUB -MxResult MxVideoManager::vtable0x2c(MxVideoParam& p_videoParam, undefined4 p_unknown1, MxU8 p_unknown2) +// OFFSET: LEGO1 0x100be820 +MxResult MxVideoManager::Create( + MxVideoParam &p_videoParam, + MxU32 p_frequencyMS, + MxBool p_createThread) { - return FAILURE; + MxBool locked = FALSE; + MxResult status = FAILURE; + + m_unk60 = TRUE; + + if (MxMediaManager::InitPresenters() != SUCCESS) + goto done; + + m_criticalSection.Enter(); + locked = TRUE; + + m_videoParam = p_videoParam; + m_region = new MxRegion(); + + if (!m_region) + goto done; + + if (DirectDrawCreate(NULL, &m_pDirectDraw, NULL) != DD_OK) + goto done; + + if (m_pDirectDraw->SetCooperativeLevel(MxOmni::GetInstance()->GetWindowHandle(), DDSCL_NORMAL) != DD_OK) + goto done; + + MxPalette *palette; + if (p_videoParam.GetPalette() == NULL) { + palette = new MxPalette(); + m_videoParam.SetPalette(palette); + + if (!palette) + goto done; + } + else { + palette = p_videoParam.GetPalette()->Clone(); + m_videoParam.SetPalette(palette); + + if (!palette) + goto done; + } + + m_displaySurface = new MxDisplaySurface(); + if (m_displaySurface && m_displaySurface->Create(m_videoParam) == SUCCESS) { + m_displaySurface->SetPalette(m_videoParam.GetPalette()); + + if (p_createThread) { + m_thread = new MxTickleThread(this, p_frequencyMS); + + if (!m_thread || m_thread->Start(0, 0) != SUCCESS) + goto done; + } + else + TickleManager()->RegisterClient(this, p_frequencyMS); + + status = SUCCESS; + } + +done: + if (status != SUCCESS) + Destroy(); + + if (locked) + m_criticalSection.Leave(); + + return status; } diff --git a/LEGO1/mxvideomanager.h b/LEGO1/mxvideomanager.h index ea97ab84..6e0e6b76 100644 --- a/LEGO1/mxvideomanager.h +++ b/LEGO1/mxvideomanager.h @@ -15,8 +15,17 @@ class MxVideoManager : public MxMediaManager virtual MxResult Tickle() override; // vtable+0x8 virtual void Destroy() override; // vtable+0x18 - virtual void vtable0x28(); // vtable+0x28 (TODO ARGUMENTS) - virtual MxResult vtable0x2c(MxVideoParam& p_videoParam, undefined4 p_unknown1, MxU8 p_unknown2); // vtable+0x2c + virtual MxResult vtable0x28( + MxVideoParam& p_videoParam, + LPDIRECTDRAW p_pDirectDraw, + LPDIRECTDRAWSURFACE p_pDDSurface, + LPDIRECTDRAWSURFACE p_ddSurface1, + LPDIRECTDRAWSURFACE p_ddSurface2, + LPDIRECTDRAWCLIPPER p_ddClipper, + MxU32 p_frequencyMS, + MxBool p_createThread + ); // vtable+0x28 + virtual MxResult Create(MxVideoParam& p_videoParam, MxU32 p_frequencyMS, MxBool p_createThread); // vtable+0x2c __declspec(dllexport) void InvalidateRect(MxRect32 &); __declspec(dllexport) virtual MxLong RealizePalette(MxPalette *); // vtable+0x30