From 7038a841bdca30e0bfe9a6b424fc04370fe19b87 Mon Sep 17 00:00:00 2001 From: skidau Date: Sat, 21 Apr 2012 15:50:07 +1000 Subject: [PATCH 1/5] Fixed the erroneous looping in audio streaming games like Eternal Darkness and Zoids: Battle Legends. Thanks for the tip, tueidj. Fixes issue 5378. --- Source/Core/Core/Src/HW/DVDInterface.cpp | 72 ++++++++++++++---------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/Source/Core/Core/Src/HW/DVDInterface.cpp b/Source/Core/Core/Src/HW/DVDInterface.cpp index 205cd00448..784a9a61e4 100644 --- a/Source/Core/Core/Src/HW/DVDInterface.cpp +++ b/Source/Core/Core/Src/HW/DVDInterface.cpp @@ -203,7 +203,9 @@ static UDICFG m_DICFG; static u32 AudioStart; static u32 AudioPos; +static u32 CurrentStart; static u32 AudioLength; +static u32 CurrentLength; u32 g_ErrorCode = 0; bool g_bDiscInside = false; @@ -351,33 +353,46 @@ bool DVDRead(u32 _iDVDOffset, u32 _iRamAddress, u32 _iLength) bool DVDReadADPCM(u8* _pDestBuffer, u32 _iNumSamples) { + _iNumSamples &= ~31; + if (AudioPos == 0) { - //MessageBox(0,"DVD: Trying to stream from 0", "bah", 0); memset(_pDestBuffer, 0, _iNumSamples); // probably __AI_SRC_INIT :P - return false; } - _iNumSamples &= ~31; + else { - std::lock_guard lk(dvdread_section); - VolumeHandler::ReadToPtr(_pDestBuffer, AudioPos, _iNumSamples); + std::lock_guard lk(dvdread_section); + VolumeHandler::ReadToPtr(_pDestBuffer, AudioPos, _iNumSamples); } - // - // FIX THIS - // // loop check - // - AudioPos += _iNumSamples; - if (AudioPos >= AudioStart + AudioLength) + if (g_bStream) { - g_bStream = false; // Starfox Adventures - AudioPos = AudioStart; - NGCADPCM::InitFilter(); - } + AudioPos += _iNumSamples; - //WARN_LOG(DVDINTERFACE,"ReadADPCM"); - return true; + if (AudioPos >= CurrentStart + CurrentLength) + { + if (AudioStart == 0 || AudioLength == 0) + { + AudioPos = 0; + CurrentStart = 0; + CurrentLength = 0; + g_bStream = false; // Starfox Adventures + } + else + { + AudioPos = AudioStart; + CurrentStart = AudioStart; + CurrentLength = AudioLength; + NGCADPCM::InitFilter(); + } + } + + //WARN_LOG(DVDINTERFACE,"ReadADPCM"); + return true; + } + else + return false; } void Read32(u32& _uReturnValue, const u32 _iAddress) @@ -813,21 +828,20 @@ void ExecuteCommand(UDICR& _DICR) // m_DICMDBUF[2].Hex = Length of the stream case 0xE1: { - // ugly hack to catch the disable command - if (m_DICMDBUF[1].Hex != 0) + if (!g_bStream) { - AudioPos = m_DICMDBUF[1].Hex << 2; - AudioStart = AudioPos; - AudioLength = m_DICMDBUF[2].Hex; - NGCADPCM::InitFilter(); - + AudioPos = m_DICMDBUF[1].Hex << 2; + CurrentStart = AudioPos; + CurrentLength = m_DICMDBUF[2].Hex; + NGCADPCM::InitFilter(); g_bStream = true; - - WARN_LOG(DVDINTERFACE, "(Audio) Stream subcmd = %02x offset = %08x length=%08x", - m_DICMDBUF[0].CMDBYTE1, AudioPos, AudioLength); } - else - WARN_LOG(DVDINTERFACE, "(Audio) Off?"); + + AudioStart = m_DICMDBUF[1].Hex << 2; + AudioLength = m_DICMDBUF[2].Hex; + + WARN_LOG(DVDINTERFACE, "(Audio) Stream subcmd = %02x offset = %08x length=%08x", + m_DICMDBUF[0].CMDBYTE1, AudioPos, AudioLength); } break; From f0a5214a3fc00ab7d278012a833775356fdc75c4 Mon Sep 17 00:00:00 2001 From: skidau Date: Mon, 23 Apr 2012 04:47:31 +1000 Subject: [PATCH 2/5] Added the response for audio streaming disc offset requests. Generate an AI interrupt at the end of the audio streaming loop. Fixes Pac-man Fever and the background music in Eternal Darkness. --- Source/Core/Core/Src/HW/AudioInterface.cpp | 9 ++- Source/Core/Core/Src/HW/AudioInterface.h | 2 + Source/Core/Core/Src/HW/DVDInterface.cpp | 94 ++++++++++++++++------ 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/Source/Core/Core/Src/HW/AudioInterface.cpp b/Source/Core/Core/Src/HW/AudioInterface.cpp index 40b0c620b3..f4141818ae 100644 --- a/Source/Core/Core/Src/HW/AudioInterface.cpp +++ b/Source/Core/Core/Src/HW/AudioInterface.cpp @@ -234,8 +234,8 @@ void Write32(const u32 _Value, const u32 _Address) m_Control.PSTAT = tmpAICtrl.PSTAT; g_LastCPUTime = CoreTiming::GetTicks(); - // Tell Drive Interface to stop streaming - if (!tmpAICtrl.PSTAT) DVDInterface::g_bStream = false; + // Tell Drive Interface to start/stop streaming + DVDInterface::g_bStream = tmpAICtrl.PSTAT; } // AI Interrupt @@ -293,6 +293,11 @@ static void GenerateAudioInterrupt() UpdateInterrupts(); } +void GenerateAISInterrupt() +{ + GenerateAudioInterrupt(); +} + void Callback_GetSampleRate(unsigned int &_AISampleRate, unsigned int &_DACSampleRate) { _AISampleRate = g_AISSampleRate; diff --git a/Source/Core/Core/Src/HW/AudioInterface.h b/Source/Core/Core/Src/HW/AudioInterface.h index 8f01e9f7e7..1504198621 100644 --- a/Source/Core/Core/Src/HW/AudioInterface.h +++ b/Source/Core/Core/Src/HW/AudioInterface.h @@ -43,6 +43,8 @@ void Write32(const u32 _iValue, const u32 _iAddress); // Get the audio rates (48000 or 32000 only) unsigned int GetAIDSampleRate(); +void GenerateAISInterrupt(); + } // namespace #endif diff --git a/Source/Core/Core/Src/HW/DVDInterface.cpp b/Source/Core/Core/Src/HW/DVDInterface.cpp index 784a9a61e4..b5c738adb5 100644 --- a/Source/Core/Core/Src/HW/DVDInterface.cpp +++ b/Source/Core/Core/Src/HW/DVDInterface.cpp @@ -28,6 +28,7 @@ #include "Thread.h" #include "Memmap.h" #include "../VolumeHandler.h" +#include "AudioInterface.h" // Disc transfer rate measured in bytes per second static const u32 DISC_TRANSFER_RATE_GC = 3125 * 1024; @@ -201,10 +202,10 @@ static UDICR m_DICR; static UDIIMMBUF m_DIIMMBUF; static UDICFG m_DICFG; -static u32 AudioStart; +static u32 LoopStart; static u32 AudioPos; static u32 CurrentStart; -static u32 AudioLength; +static u32 LoopLength; static u32 CurrentLength; u32 g_ErrorCode = 0; @@ -240,12 +241,15 @@ void DoState(PointerWrap &p) p.Do(m_DIIMMBUF); p.Do(m_DICFG); - p.Do(AudioStart); + p.Do(LoopStart); p.Do(AudioPos); - p.Do(AudioLength); + p.Do(LoopLength); p.Do(g_ErrorCode); p.Do(g_bDiscInside); + + p.Do(CurrentStart); + p.Do(CurrentLength); } void TransferComplete(u64 userdata, int cyclesLate) @@ -268,9 +272,11 @@ void Init() m_DICFG.Hex = 0; m_DICFG.CONFIG = 1; // Disable bootrom descrambler - AudioStart = 0; - AudioPos = 0; - AudioLength = 0; + AudioPos = 0; + LoopStart = 0; + LoopLength = 0; + CurrentStart = 0; + CurrentLength = 0; ejectDisc = CoreTiming::RegisterEvent("EjectDisc", EjectDiscCallback); insertDisc = CoreTiming::RegisterEvent("InsertDisc", InsertDiscCallback); @@ -372,20 +378,20 @@ bool DVDReadADPCM(u8* _pDestBuffer, u32 _iNumSamples) if (AudioPos >= CurrentStart + CurrentLength) { - if (AudioStart == 0 || AudioLength == 0) + if (LoopStart == 0) { AudioPos = 0; CurrentStart = 0; CurrentLength = 0; - g_bStream = false; // Starfox Adventures } else { - AudioPos = AudioStart; - CurrentStart = AudioStart; - CurrentLength = AudioLength; - NGCADPCM::InitFilter(); + AudioPos = LoopStart; + CurrentStart = LoopStart; + CurrentLength = LoopLength; } + NGCADPCM::InitFilter(); + AudioInterface::GenerateAISInterrupt(); } //WARN_LOG(DVDINTERFACE,"ReadADPCM"); @@ -828,27 +834,69 @@ void ExecuteCommand(UDICR& _DICR) // m_DICMDBUF[2].Hex = Length of the stream case 0xE1: { - if (!g_bStream) + u32 pos = m_DICMDBUF[1].Hex << 2; + u32 length = m_DICMDBUF[2].Hex; + + // Start playing + if (!g_bStream && m_DICMDBUF[0].CMDBYTE1 == 0 && pos != 0 && length != 0) { - AudioPos = m_DICMDBUF[1].Hex << 2; - CurrentStart = AudioPos; - CurrentLength = m_DICMDBUF[2].Hex; + AudioPos = pos; + CurrentStart = pos; + CurrentLength = length; NGCADPCM::InitFilter(); g_bStream = true; } - AudioStart = m_DICMDBUF[1].Hex << 2; - AudioLength = m_DICMDBUF[2].Hex; + LoopStart = pos; + LoopLength = length; + g_bStream = (m_DICMDBUF[0].CMDBYTE1 == 0); // This command can start/stop the stream - WARN_LOG(DVDINTERFACE, "(Audio) Stream subcmd = %02x offset = %08x length=%08x", - m_DICMDBUF[0].CMDBYTE1, AudioPos, AudioLength); + // Stop stream + if (m_DICMDBUF[0].CMDBYTE1 == 1) + { + AudioPos = 0; + LoopStart = 0; + LoopLength = 0; + CurrentStart = 0; + CurrentLength = 0; + } + + WARN_LOG(DVDINTERFACE, "(Audio) Stream subcmd = %08x offset = %08x length=%08x", + m_DICMDBUF[0].Hex, m_DICMDBUF[1].Hex << 2, m_DICMDBUF[2].Hex); } break; // Request Audio Status (Immediate) case 0xE2: - m_DIIMMBUF.Hex = g_bStream ? 1 : 0; - //WARN_LOG(DVDINTERFACE, "(Audio): Request Audio status %s", g_bStream? "on":"off"); + { + switch (m_DICMDBUF[0].CMDBYTE1) + { + case 0x00: // Returns streaming status + m_DIIMMBUF.Hex = (AudioPos == 0) ? 0 : 1; + break; + case 0x01: // Returns the current offset + if (g_bStream) + m_DIIMMBUF.Hex = (AudioPos - CurrentStart) >> 2; + else + m_DIIMMBUF.Hex = 0; + break; + case 0x02: // Returns the start offset + if (g_bStream) + m_DIIMMBUF.Hex = CurrentStart >> 2; + else + m_DIIMMBUF.Hex = 0; + break; + case 0x03: // Returns the total length + if (g_bStream) + m_DIIMMBUF.Hex = CurrentLength; + else + m_DIIMMBUF.Hex = 0; + break; + default: + WARN_LOG(DVDINTERFACE, "(Audio): Subcommand: %02x Request Audio status %s", m_DICMDBUF[0].CMDBYTE1, g_bStream? "on":"off"); + break; + } + } break; case DVDLowStopMotor: From 5ceef0c51347d0678c2fcf6b32201f3f834b9a5f Mon Sep 17 00:00:00 2001 From: skidau Date: Mon, 23 Apr 2012 05:02:43 +1000 Subject: [PATCH 3/5] Removed the DTK Music option. It is now always enabled. --- Source/Core/AudioCommon/Src/AudioCommonConfig.cpp | 3 --- Source/Core/AudioCommon/Src/AudioCommonConfig.h | 1 - Source/Core/AudioCommon/Src/Mixer.cpp | 10 +++------- Source/Core/AudioCommon/Src/Mixer.h | 2 -- Source/Core/DolphinWX/Src/ConfigMain.cpp | 7 ------- Source/Core/DolphinWX/Src/ConfigMain.h | 2 -- 6 files changed, 3 insertions(+), 22 deletions(-) diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp b/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp index 533c6b4313..08902e1c3f 100644 --- a/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.cpp @@ -31,7 +31,6 @@ void AudioCommonConfig::Load() IniFile file; file.Load(File::GetUserPath(F_DSPCONFIG_IDX)); - file.Get("Config", "EnableDTKMusic", &m_EnableDTKMusic, true); file.Get("Config", "EnableJIT", &m_EnableJIT, true); file.Get("Config", "DumpAudio", &m_DumpAudio, false); #if defined __linux__ && HAVE_ALSA @@ -53,7 +52,6 @@ void AudioCommonConfig::SaveSettings() IniFile file; file.Load(File::GetUserPath(F_DSPCONFIG_IDX)); - file.Set("Config", "EnableDTKMusic", m_EnableDTKMusic); file.Set("Config", "EnableJIT", m_EnableJIT); file.Set("Config", "DumpAudio", m_DumpAudio); file.Set("Config", "Backend", sBackend); @@ -67,7 +65,6 @@ void AudioCommonConfig::SaveSettings() void AudioCommonConfig::Update() { if (soundStream) { soundStream->GetMixer()->SetThrottle(SConfig::GetInstance().m_Framelimit == 2); - soundStream->GetMixer()->SetDTKMusic(m_EnableDTKMusic); soundStream->SetVolume(m_Volume); } } diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.h b/Source/Core/AudioCommon/Src/AudioCommonConfig.h index 076ef2d4e1..76c50c6408 100644 --- a/Source/Core/AudioCommon/Src/AudioCommonConfig.h +++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.h @@ -33,7 +33,6 @@ struct AudioCommonConfig { - bool m_EnableDTKMusic; bool m_EnableJIT; bool m_DumpAudio; int m_Volume; diff --git a/Source/Core/AudioCommon/Src/Mixer.cpp b/Source/Core/AudioCommon/Src/Mixer.cpp index 6ee0ddbf7a..8340df8b59 100644 --- a/Source/Core/AudioCommon/Src/Mixer.cpp +++ b/Source/Core/AudioCommon/Src/Mixer.cpp @@ -136,8 +136,7 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) if (m_AIplaying) { Premix(samples, numLeft); - if (m_EnableDTKMusic) - AudioInterface::Callback_GetStreaming(samples, numLeft, m_sampleRate); + AudioInterface::Callback_GetStreaming(samples, numLeft, m_sampleRate); g_wave_writer.AddStereoSamples(samples, numLeft); } @@ -147,11 +146,8 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) Premix(samples, numSamples); // Add the DTK Music - if (m_EnableDTKMusic) - { - // Re-sampling is done inside - AudioInterface::Callback_GetStreaming(samples, numSamples, m_sampleRate); - } + // Re-sampling is done inside + AudioInterface::Callback_GetStreaming(samples, numSamples, m_sampleRate); } diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index 95d89d7334..f850b58add 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -61,7 +61,6 @@ public: unsigned int GetSampleRate() {return m_sampleRate;} void SetThrottle(bool use) { m_throttle = use;} - void SetDTKMusic(bool use) { m_EnableDTKMusic = use;} // TODO: do we need this bool IsHLEReady() { return m_HLEready;} @@ -103,7 +102,6 @@ protected: bool m_HLEready; bool m_logAudio; - bool m_EnableDTKMusic; bool m_throttle; short m_buffer[MAX_SAMPLES * 2]; diff --git a/Source/Core/DolphinWX/Src/ConfigMain.cpp b/Source/Core/DolphinWX/Src/ConfigMain.cpp index 5ad6859778..40217c7482 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Src/ConfigMain.cpp @@ -116,7 +116,6 @@ EVT_CHECKBOX(ID_NTSCJ, CConfigMain::CoreSettingsChanged) EVT_RADIOBOX(ID_DSPENGINE, CConfigMain::AudioSettingsChanged) -EVT_CHECKBOX(ID_ENABLE_DTK_MUSIC, CConfigMain::AudioSettingsChanged) EVT_CHECKBOX(ID_DSPTHREAD, CConfigMain::AudioSettingsChanged) EVT_CHECKBOX(ID_ENABLE_THROTTLE, CConfigMain::AudioSettingsChanged) EVT_CHECKBOX(ID_DUMP_AUDIO, CConfigMain::AudioSettingsChanged) @@ -359,7 +358,6 @@ void CConfigMain::InitializeGUIValues() VolumeSlider->Enable(SupportsVolumeChanges(ac_Config.sBackend)); VolumeSlider->SetValue(ac_Config.m_Volume); VolumeText->SetLabel(wxString::Format(wxT("%d %%"), ac_Config.m_Volume)); - EnableDTKMusic->SetValue(ac_Config.m_EnableDTKMusic ? true : false); DSPThread->SetValue(startup_params.bDSPThread); DumpAudio->SetValue(ac_Config.m_DumpAudio ? true : false); FrequencySelection->SetSelection( @@ -502,7 +500,6 @@ void CConfigMain::InitializeGUITooltips() InterfaceLang->SetToolTip(_("Change the language of the user interface.\nRequires restart.")); // Audio tooltips - EnableDTKMusic->SetToolTip(_("This is used to play music tracks, like BGM.")); DSPThread->SetToolTip(_("Run DSP LLE on a dedicated thread (not recommended).")); FrequencySelection->SetToolTip(_("Changing this will have no effect while the emulator is running!")); BackendSelection->SetToolTip(_("Changing this will have no effect while the emulator is running!")); @@ -602,8 +599,6 @@ void CConfigMain::CreateGUIControls() // Audio page DSPEngine = new wxRadioBox(AudioPage, ID_DSPENGINE, _("DSP Emulator Engine"), wxDefaultPosition, wxDefaultSize, arrayStringFor_DSPEngine, 0, wxRA_SPECIFY_ROWS); - EnableDTKMusic = new wxCheckBox(AudioPage, ID_ENABLE_DTK_MUSIC, _("Enable DTK Music"), - wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); DSPThread = new wxCheckBox(AudioPage, ID_DSPTHREAD, _("DSP LLE on Thread")); DumpAudio = new wxCheckBox(AudioPage, ID_DUMP_AUDIO, _("Dump Audio"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); @@ -620,7 +615,6 @@ void CConfigMain::CreateGUIControls() // Create sizer and add items to dialog wxStaticBoxSizer *sbAudioSettings = new wxStaticBoxSizer(wxVERTICAL, AudioPage, _("Sound Settings")); sbAudioSettings->Add(DSPEngine, 0, wxALL | wxEXPAND, 5); - sbAudioSettings->Add(EnableDTKMusic, 0, wxALL, 5); sbAudioSettings->Add(DSPThread, 0, wxALL, 5); sbAudioSettings->Add(DumpAudio, 0, wxALL, 5); @@ -918,7 +912,6 @@ void CConfigMain::AudioSettingsChanged(wxCommandEvent& event) break; default: - ac_Config.m_EnableDTKMusic = EnableDTKMusic->GetValue(); ac_Config.m_DumpAudio = DumpAudio->GetValue(); long int frequency; diff --git a/Source/Core/DolphinWX/Src/ConfigMain.h b/Source/Core/DolphinWX/Src/ConfigMain.h index 7cb6c81dc7..eae9f8996d 100644 --- a/Source/Core/DolphinWX/Src/ConfigMain.h +++ b/Source/Core/DolphinWX/Src/ConfigMain.h @@ -77,7 +77,6 @@ private: // Audio Settings ID_DSPENGINE, ID_ENABLE_HLE_AUDIO, - ID_ENABLE_DTK_MUSIC, ID_ENABLE_THROTTLE, ID_DUMP_AUDIO, ID_FREQUENCY, @@ -156,7 +155,6 @@ private: wxRadioBox* DSPEngine; wxSlider* VolumeSlider; wxStaticText* VolumeText; - wxCheckBox* EnableDTKMusic; wxCheckBox* DumpAudio; wxArrayString wxArrayBackends; wxChoice* BackendSelection; From 26521aa66af52594f97633f991a467bd37100362 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 23 Apr 2012 00:38:58 -0700 Subject: [PATCH 4/5] force VolumeDirectory to align files to 32KB (only streaming audio files really need to be aligned...) --- Source/Core/Common/Src/MathUtil.h | 1 + Source/Core/Core/Src/Boot/Boot.cpp | 5 +++-- Source/Core/DiscIO/Src/VolumeDirectory.cpp | 26 +++++++++------------- Source/Core/DiscIO/Src/VolumeDirectory.h | 10 +++++++++ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Source/Core/Common/Src/MathUtil.h b/Source/Core/Common/Src/MathUtil.h index ecace1fb4a..a6290ff602 100644 --- a/Source/Core/Common/Src/MathUtil.h +++ b/Source/Core/Common/Src/MathUtil.h @@ -161,6 +161,7 @@ void LoadDefaultSSEState(); float MathFloatVectorSum(const std::vector&); #define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define ROUND_DOWN(x, a) ((x) & ~((a) - 1)) // Tiny matrix/vector library. diff --git a/Source/Core/Core/Src/Boot/Boot.cpp b/Source/Core/Core/Src/Boot/Boot.cpp index 8d000611c8..be82d217dc 100644 --- a/Source/Core/Core/Src/Boot/Boot.cpp +++ b/Source/Core/Core/Src/Boot/Boot.cpp @@ -19,6 +19,7 @@ #include "Common.h" // Common #include "StringUtil.h" #include "FileUtil.h" +#include "MathUtil.h" #include "../HLE/HLE.h" // Core #include "../PowerPC/PowerPC.h" @@ -68,13 +69,13 @@ void CBoot::Load_FST(bool _bIsWii) u32 fstSize = VolumeHandler::Read32(0x0428) << shift; u32 maxFstSize = VolumeHandler::Read32(0x042c) << shift; - u32 arenaHigh = 0x817FFFF4 - maxFstSize; + u32 arenaHigh = ROUND_DOWN(0x817FFFFF - maxFstSize, 0x20); Memory::Write_U32(arenaHigh, 0x00000034); // load FST VolumeHandler::ReadToPtr(Memory::GetPointer(arenaHigh), fstOffset, fstSize); Memory::Write_U32(arenaHigh, 0x00000038); - Memory::Write_U32(maxFstSize, 0x0000003c); + Memory::Write_U32(maxFstSize, 0x0000003c); } void CBoot::UpdateDebugger_MapLoaded(const char *_gameID) diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.cpp b/Source/Core/DiscIO/Src/VolumeDirectory.cpp index 52e9f4389a..dc76e2e641 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/Src/VolumeDirectory.cpp @@ -16,6 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include "Common.h" +#include "MathUtil.h" #include "CommonPaths.h" #include "VolumeDirectory.h" #include "FileBlob.h" @@ -23,17 +24,6 @@ namespace DiscIO { -static const u8 ENTRY_SIZE = 0x0c; -static const u8 FILE_ENTRY = 0; -static const u8 DIRECTORY_ENTRY = 1; -static const u64 DISKHEADER_ADDRESS = 0; -static const u64 DISKHEADERINFO_ADDRESS = 0x440; -static const u64 APPLOADER_ADDRESS = 0x2440; -static const u32 MAX_NAME_LENGTH = 0x3df; -// relocatable -static u64 FST_ADDRESS = 0x440; -static u64 DOL_ADDRESS = 0; - CVolumeDirectory::CVolumeDirectory(const std::string& _rDirectory, bool _bIsWii, const std::string& _rApploader, const std::string& _rDOL) : m_totalNameSize(0) @@ -44,6 +34,8 @@ CVolumeDirectory::CVolumeDirectory(const std::string& _rDirectory, bool _bIsWii, , m_apploader(NULL) , m_DOLSize(0) , m_DOL(NULL) + , FST_ADDRESS(0) + , DOL_ADDRESS(0) { m_rootDirectory = ExtractDirectoryName(_rDirectory); @@ -321,7 +313,7 @@ bool CVolumeDirectory::SetApploader(const std::string& _rApploader) copy(data.begin(), data.end(), m_apploader); // 32byte aligned (plus 0x20 padding) - DOL_ADDRESS = (APPLOADER_ADDRESS + m_apploaderSize + 0x20 + 31) & ~31ULL; + DOL_ADDRESS = ROUND_UP(APPLOADER_ADDRESS + m_apploaderSize + 0x20, 0x20ull); return true; } else @@ -347,7 +339,7 @@ void CVolumeDirectory::SetDOL(const std::string& _rDOL) Write32((u32)(DOL_ADDRESS >> m_addressShift), 0x0420, m_diskHeader); // 32byte aligned (plus 0x20 padding) - FST_ADDRESS = (DOL_ADDRESS + m_DOLSize + 0x20 + 31) & ~31ULL; + FST_ADDRESS = ROUND_UP(DOL_ADDRESS + m_DOLSize + 0x20, 0x20ull); } } @@ -367,8 +359,12 @@ void CVolumeDirectory::BuildFST() m_fstSize = m_fstNameOffset + m_totalNameSize; m_FSTData = new u8[(u32)m_fstSize]; + // if FST hasn't been assigned (ie no apploader/dol setup), set to default + if (FST_ADDRESS == 0) + FST_ADDRESS = APPLOADER_ADDRESS + 0x2000; + // 4 byte aligned start of data on disk - m_dataStartAddress = (FST_ADDRESS + m_fstSize + 3) & ~3; + m_dataStartAddress = ROUND_UP(FST_ADDRESS + m_fstSize, 0x8000ull); u64 curDataAddress = m_dataStartAddress; u32 fstOffset = 0; // offset within FST data @@ -490,7 +486,7 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u m_virtualDisk.insert(make_pair(dataOffset, entry.physicalName)); // 4 byte aligned - dataOffset = (dataOffset + entry.size + 3) & ~3ULL; + dataOffset = ROUND_UP(dataOffset + entry.size, 0x8000ull); } } diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.h b/Source/Core/DiscIO/Src/VolumeDirectory.h index 727974a417..0547be3b8a 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.h +++ b/Source/Core/DiscIO/Src/VolumeDirectory.h @@ -141,6 +141,16 @@ private: u64 m_DOLSize; u8* m_DOL; + + static const u8 ENTRY_SIZE = 0x0c; + static const u8 FILE_ENTRY = 0; + static const u8 DIRECTORY_ENTRY = 1; + static const u64 DISKHEADER_ADDRESS = 0; + static const u64 DISKHEADERINFO_ADDRESS = 0x440; + static const u64 APPLOADER_ADDRESS = 0x2440; + static const u32 MAX_NAME_LENGTH = 0x3df; + u64 FST_ADDRESS; + u64 DOL_ADDRESS; }; } // namespace From f0e1b4c1dddf6ffe5f3eb79c364bc5ed07f0b55e Mon Sep 17 00:00:00 2001 From: skidau Date: Mon, 23 Apr 2012 22:15:23 +1000 Subject: [PATCH 5/5] Reset the stream playing flag on init. --- Source/Core/Core/Src/HW/DVDInterface.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/Core/Src/HW/DVDInterface.cpp b/Source/Core/Core/Src/HW/DVDInterface.cpp index b5c738adb5..cb400f43a9 100644 --- a/Source/Core/Core/Src/HW/DVDInterface.cpp +++ b/Source/Core/Core/Src/HW/DVDInterface.cpp @@ -247,6 +247,7 @@ void DoState(PointerWrap &p) p.Do(g_ErrorCode); p.Do(g_bDiscInside); + p.Do(g_bStream); p.Do(CurrentStart); p.Do(CurrentLength); @@ -278,6 +279,8 @@ void Init() CurrentStart = 0; CurrentLength = 0; + g_bStream = false; + ejectDisc = CoreTiming::RegisterEvent("EjectDisc", EjectDiscCallback); insertDisc = CoreTiming::RegisterEvent("InsertDisc", InsertDiscCallback);