CDROM: Store the image path/current lba as part of the save state

This commit is contained in:
Connor McLaughlin 2019-09-24 23:55:22 +10:00
parent 1276241622
commit 575a3b36f5
2 changed files with 21 additions and 1 deletions

View file

@ -60,12 +60,28 @@ bool CDROM::DoState(StateWrapper& sw)
sw.Do(&m_response_fifo); sw.Do(&m_response_fifo);
sw.Do(&m_data_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 (sw.IsReading())
{ {
if (m_command_state == CommandState::WaitForExecute) if (m_command_state == CommandState::WaitForExecute)
m_system->SetDowncount(m_command_remaining_ticks); m_system->SetDowncount(m_command_remaining_ticks);
if (m_reading) if (m_reading)
m_system->SetDowncount(m_sector_read_remaining_ticks); 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<CDImage>();
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(); return !sw.HasError();
@ -84,6 +100,7 @@ bool CDROM::InsertMedia(const char* filename)
RemoveMedia(); RemoveMedia();
m_media = std::move(media); m_media = std::move(media);
m_media_filename = filename;
// m_secondary_status.shell_open = false; // m_secondary_status.shell_open = false;
return true; return true;
} }
@ -96,6 +113,7 @@ void CDROM::RemoveMedia()
// TODO: Error while reading? // TODO: Error while reading?
Log_InfoPrintf("Removing CD..."); Log_InfoPrintf("Removing CD...");
m_media.reset(); m_media.reset();
m_media_filename.clear();
// m_secondary_status.shell_open = true; // m_secondary_status.shell_open = true;
} }
@ -260,7 +278,7 @@ void CDROM::WriteRegister(u32 offset, u8 value)
} }
Log_DebugPrintf("Loading data FIFO"); 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<u32>(m_sector_buffer.size()));
m_sector_buffer.clear(); m_sector_buffer.clear();
} }
else else

View file

@ -2,6 +2,7 @@
#include "common/bitfield.h" #include "common/bitfield.h"
#include "common/fifo_queue.h" #include "common/fifo_queue.h"
#include "types.h" #include "types.h"
#include <string>
#include <vector> #include <vector>
class CDImage; class CDImage;
@ -164,6 +165,7 @@ private:
DMA* m_dma = nullptr; DMA* m_dma = nullptr;
InterruptController* m_interrupt_controller = nullptr; InterruptController* m_interrupt_controller = nullptr;
std::unique_ptr<CDImage> m_media; std::unique_ptr<CDImage> m_media;
std::string m_media_filename;
CommandState m_command_state = CommandState::Idle; CommandState m_command_state = CommandState::Idle;
Command m_command = Command::Sync; Command m_command = Command::Sync;