From 232c846392e39423b57ee9b86159707d897c2d87 Mon Sep 17 00:00:00 2001 From: Olivier Galibert Date: Fri, 5 May 2023 15:51:13 +0200 Subject: cdrom: Bunch of fixes --- src/devices/imagedev/cdromimg.cpp | 33 ++++++++++++++++++++++++++++----- src/lib/util/cdrom.h | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/devices/imagedev/cdromimg.cpp b/src/devices/imagedev/cdromimg.cpp index b0196bdf492..78bb1bb1866 100644 --- a/src/devices/imagedev/cdromimg.cpp +++ b/src/devices/imagedev/cdromimg.cpp @@ -129,12 +129,33 @@ std::pair cdrom_image_device::call_load() // open the CHD file if (chd) + { + if (chd->is_cd()) + m_cdrom_handle.reset(new cdrom_file(chd)); + else if(m_dvd_compat && chd->is_dvd()) + m_dvdrom_handle.reset(new dvdrom_file(chd)); + else + { + err = image_error::UNSUPPORTED; + goto error; + } m_cdrom_handle.reset(new cdrom_file(chd)); + } else - m_cdrom_handle.reset(new cdrom_file(filename())); - - if (!m_cdrom_handle) - goto error; + { + try { + auto *cdrom = new cdrom_file(filename()); + m_cdrom_handle.reset(cdrom); + } catch(void *) { + try { + auto *dvdrom = new dvdrom_file(filename()); + m_dvdrom_handle.reset(dvdrom); + } catch(void *) { + err = image_error::UNSUPPORTED; + goto error; + } + } + } return std::make_pair(std::error_condition(), std::string()); @@ -178,6 +199,8 @@ bool cdrom_image_device::read_data(uint32_t lbasector, void *buffer, uint32_t da { if (m_cdrom_handle) return m_cdrom_handle->read_data(lbasector, buffer, datatype, phys); + if (m_dvdrom_handle) + return !m_dvdrom_handle->read_data(lbasector, buffer); return 0; } @@ -217,7 +240,7 @@ bool cdrom_image_device::is_cd() const bool cdrom_image_device::is_gd() const { - return false; + return m_cdrom_handle && m_cdrom_handle->is_gdrom(); } bool cdrom_image_device::is_dvd() const diff --git a/src/lib/util/cdrom.h b/src/lib/util/cdrom.h index ed293429f21..f8bdb29b93b 100644 --- a/src/lib/util/cdrom.h +++ b/src/lib/util/cdrom.h @@ -151,6 +151,7 @@ public: static const char *get_subtype_string(uint32_t subtype); static std::error_condition parse_metadata(chd_file *chd, toc &toc); static std::error_condition write_metadata(chd_file *chd, const toc &toc); + bool is_gdrom() const { return cdtoc.flags & (CD_FLAG_GDROM|CD_FLAG_GDROMLE); } // ECC utilities static bool ecc_verify(const uint8_t *sector); -- cgit v1.2.3