From 575a3b36f5e9b0e2049cf287ac034453759316b8 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 24 Sep 2019 23:55:22 +1000 Subject: [PATCH] CDROM: Store the image path/current lba as part of the save state --- src/pse/cdrom.cpp | 20 +++++++++++++++++++- src/pse/cdrom.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pse/cdrom.cpp b/src/pse/cdrom.cpp index f21cac47c..af54a7966 100644 --- a/src/pse/cdrom.cpp +++ b/src/pse/cdrom.cpp @@ -60,12 +60,28 @@ bool CDROM::DoState(StateWrapper& sw) sw.Do(&m_response_fifo); sw.Do(&m_data_fifo); + u64 media_lba = m_media ? m_media->GetCurrentLBA() : 0; + sw.Do(&m_media_filename); + sw.Do(&media_lba); + if (sw.IsReading()) { if (m_command_state == CommandState::WaitForExecute) m_system->SetDowncount(m_command_remaining_ticks); if (m_reading) m_system->SetDowncount(m_sector_read_remaining_ticks); + + // load up media if we had something in there before + m_media.reset(); + if (!m_media_filename.empty()) + { + m_media = std::make_unique(); + if (!m_media->Open(m_media_filename.c_str()) || !m_media->Seek(media_lba)) + { + Log_ErrorPrintf("Failed to re-insert CD media from save state: '%s'. Ejecting.", m_media_filename.c_str()); + RemoveMedia(); + } + } } return !sw.HasError(); @@ -84,6 +100,7 @@ bool CDROM::InsertMedia(const char* filename) RemoveMedia(); m_media = std::move(media); + m_media_filename = filename; // m_secondary_status.shell_open = false; return true; } @@ -96,6 +113,7 @@ void CDROM::RemoveMedia() // TODO: Error while reading? Log_InfoPrintf("Removing CD..."); m_media.reset(); + m_media_filename.clear(); // m_secondary_status.shell_open = true; } @@ -260,7 +278,7 @@ void CDROM::WriteRegister(u32 offset, u8 value) } Log_DebugPrintf("Loading data FIFO"); - m_data_fifo.PushRange(m_sector_buffer.data(), m_sector_buffer.size()); + m_data_fifo.PushRange(m_sector_buffer.data(), static_cast(m_sector_buffer.size())); m_sector_buffer.clear(); } else diff --git a/src/pse/cdrom.h b/src/pse/cdrom.h index 177baaa78..a3881f5e2 100644 --- a/src/pse/cdrom.h +++ b/src/pse/cdrom.h @@ -2,6 +2,7 @@ #include "common/bitfield.h" #include "common/fifo_queue.h" #include "types.h" +#include #include class CDImage; @@ -164,6 +165,7 @@ private: DMA* m_dma = nullptr; InterruptController* m_interrupt_controller = nullptr; std::unique_ptr m_media; + std::string m_media_filename; CommandState m_command_state = CommandState::Idle; Command m_command = Command::Sync;