From 8cdae6fc1d65906f11708048a754dc2b72b38c2d Mon Sep 17 00:00:00 2001 From: luigi2us Date: Fri, 17 Jul 2009 23:26:21 +0000 Subject: [PATCH] Zelda uCode (SMS): fix a bug where we would receive more sync mails that expected. Actually the sync mail sequences contain 3 mails, not 2. That's what happens when you don't look at the uCode enough... git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3824 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp | 57 +++++++++++-------- .../Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.h | 3 + 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp index e98b47c42f..3ce574bd37 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.cpp @@ -34,6 +34,8 @@ CUCode_Zelda::CUCode_Zelda(CMailHandler& _rMailHandler, u32 _CRC) IUCode(_rMailHandler), m_CRC(_CRC), + m_NumSyncMail(0), + m_bSyncInProgress(false), m_MaxVoice(0), @@ -188,39 +190,41 @@ void CUCode_Zelda::HandleMail_LightVersion(u32 _uMail) void CUCode_Zelda::HandleMail_SMSVersion(u32 _uMail) { - if (m_bSyncCmdPending) + if (m_bSyncInProgress) { - if (m_bSyncInProgress) + if (m_bSyncCmdPending) { - m_bSyncInProgress = false; + m_SyncFlags[(m_NumSyncMail << 1) ] = _uMail >> 16; + m_SyncFlags[(m_NumSyncMail << 1) + 1] = _uMail & 0xFFFF; - m_SyncFlags[2] = _uMail >> 16; - m_SyncFlags[3] = _uMail & 0xFFFF; - - m_CurBuffer++; - - m_rMailHandler.PushMail(DSP_SYNC); - g_dspInitialize.pGenerateDSPInterrupt(); - m_rMailHandler.PushMail(0xF355FF00 | m_CurBuffer); - - if (m_CurBuffer == m_NumBuffers) + m_NumSyncMail++; + if (m_NumSyncMail == 2) { - m_rMailHandler.PushMail(DSP_FRAME_END); - //g_dspInitialize.pGenerateDSPInterrupt(); + m_NumSyncMail = 0; + m_bSyncInProgress = false; - soundStream->GetMixer()->SetHLEReady(true); - DEBUG_LOG(DSPHLE, "Update the SoundThread to be in sync"); - soundStream->Update(); //do it in this thread to avoid sync problems + m_CurBuffer++; - m_bSyncCmdPending = false; + m_rMailHandler.PushMail(DSP_SYNC); + g_dspInitialize.pGenerateDSPInterrupt(); + m_rMailHandler.PushMail(0xF355FF00 | m_CurBuffer); + + if (m_CurBuffer == m_NumBuffers) + { + m_rMailHandler.PushMail(DSP_FRAME_END); + //g_dspInitialize.pGenerateDSPInterrupt(); + + soundStream->GetMixer()->SetHLEReady(true); + DEBUG_LOG(DSPHLE, "Update the SoundThread to be in sync"); + soundStream->Update(); //do it in this thread to avoid sync problems + + m_bSyncCmdPending = false; + } } } else { - m_bSyncInProgress = true; - - m_SyncFlags[0] = _uMail >> 16; - m_SyncFlags[1] = _uMail & 0xFFFF; + m_bSyncInProgress = false; } return; @@ -245,6 +249,11 @@ void CUCode_Zelda::HandleMail_SMSVersion(u32 _uMail) // Here holds: m_bSyncInProgress == false && m_bListInProgress == false + if (_uMail == 0) + { + m_bSyncInProgress = true; + m_NumSyncMail = 0; + } if ((_uMail >> 16) == 0) { m_bListInProgress = true; @@ -553,6 +562,8 @@ void CUCode_Zelda::DoState(PointerWrap &p) p.Do(m_MaxVoice); p.Do(m_SyncFlags); + p.Do(m_NumSyncMail); + p.Do(m_NumVoices); p.Do(m_bSyncCmdPending); diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.h b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.h index 0a745cc4d0..2fa6289ae1 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.h +++ b/Source/Plugins/Plugin_DSP_HLE/Src/UCodes/UCode_Zelda.h @@ -242,6 +242,9 @@ private: u32 m_MaxVoice; u32 m_SyncFlags[16]; + // Used by SMS version + u32 m_NumSyncMail; + u32 m_NumVoices; bool m_bSyncCmdPending;