System: Use existing CD media when loading state where possible

This commit is contained in:
Connor McLaughlin 2020-07-22 00:02:37 +10:00
parent 0398c6cb4a
commit 93528db388
5 changed files with 19 additions and 11 deletions

View File

@ -450,15 +450,15 @@ void CDROM::InsertMedia(std::unique_ptr<CDImage> media)
m_reader.SetMedia(std::move(media));
}
void CDROM::RemoveMedia(bool force /* = false */)
std::unique_ptr<CDImage> CDROM::RemoveMedia(bool force /* = false */)
{
if (!HasMedia() && !force)
return;
return nullptr;
const TickCount stop_ticks = GetTicksForStop(true);
Log_InfoPrintf("Removing CD...");
m_reader.RemoveMedia();
std::unique_ptr<CDImage> image = m_reader.RemoveMedia();
m_last_sector_header_valid = false;
@ -484,6 +484,8 @@ void CDROM::RemoveMedia(bool force /* = false */)
m_drive_state = DriveState::ShellOpening;
m_drive_event->SetIntervalAndSchedule(stop_ticks);
}
return image;
}
void CDROM::SetUseReadThread(bool enabled)

View File

@ -32,7 +32,7 @@ public:
std::string GetMediaFileName() const { return m_reader.GetMediaFileName(); }
void InsertMedia(std::unique_ptr<CDImage> media);
void RemoveMedia(bool force = false);
std::unique_ptr<CDImage> RemoveMedia(bool force = false);
// I/O
u8 ReadRegister(u32 offset);

View File

@ -43,10 +43,10 @@ void CDROMAsyncReader::SetMedia(std::unique_ptr<CDImage> media)
m_media = std::move(media);
}
void CDROMAsyncReader::RemoveMedia()
std::unique_ptr<CDImage> CDROMAsyncReader::RemoveMedia()
{
WaitForReadToComplete();
m_media.reset();
return std::move(m_media);
}
void CDROMAsyncReader::QueueReadSector(CDImage::LBA lba)

View File

@ -26,7 +26,7 @@ public:
void StopThread();
void SetMedia(std::unique_ptr<CDImage> media);
void RemoveMedia();
std::unique_ptr<CDImage> RemoveMedia();
void QueueReadSector(CDImage::LBA lba);
void QueueReadNextSector();

View File

@ -432,11 +432,17 @@ bool System::DoLoadState(ByteStream* state, bool init_components, bool force_sof
return false;
}
media = CDImage::Open(media_filename.c_str());
if (!media)
media = m_cdrom->RemoveMedia();
if (!media || media->GetFileName() != media_filename)
{
m_host_interface->ReportFormattedError("Failed to open CD image from save state: '%s'.", media_filename.c_str());
return false;
media.reset();
media = CDImage::Open(media_filename.c_str());
if (!media)
{
m_host_interface->ReportFormattedError("Failed to open CD image from save state: '%s'.",
media_filename.c_str());
return false;
}
}
}