diff options
author | 2023-04-09 14:07:32 +0200 | |
---|---|---|
committer | 2023-05-04 20:29:58 +0200 | |
commit | 28104cdbdfc39b0ced6411381ffb074772dce345 (patch) | |
tree | 42ac4aa65769e67e5879dc786234e852f321a830 /src/lib | |
parent | 472f441a1b395c6a9c3b44b3f8cc70ffad2b66f4 (diff) |
chd: Add dvd support. better abstraction in general, multi-image support in arcade-type drivers
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/util/chd.cpp | 42 | ||||
-rw-r--r-- | src/lib/util/chd.h | 18 | ||||
-rw-r--r-- | src/lib/util/dvdrom.cpp | 105 | ||||
-rw-r--r-- | src/lib/util/dvdrom.h | 41 |
4 files changed, 198 insertions, 8 deletions
diff --git a/src/lib/util/chd.cpp b/src/lib/util/chd.cpp index 9ce36afcdb0..4130e4a9241 100644 --- a/src/lib/util/chd.cpp +++ b/src/lib/util/chd.cpp @@ -133,7 +133,7 @@ struct chd_file::metadata_hash // a byte buffer //------------------------------------------------- -inline uint64_t chd_file::be_read(const uint8_t *base, int numbytes) +inline uint64_t chd_file::be_read(const uint8_t *base, int numbytes) const { uint64_t result = 0; while (numbytes--) @@ -163,7 +163,7 @@ inline void chd_file::be_write(uint8_t *base, uint64_t value, int numbytes) // stream in bigendian order //------------------------------------------------- -inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base) +inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base)const { util::sha1_t result; memcpy(&result.m_raw[0], base, sizeof(result.m_raw)); @@ -187,7 +187,7 @@ inline void chd_file::be_write_sha1(uint8_t *base, util::sha1_t value) // offset; on failure throw an error //------------------------------------------------- -inline void chd_file::file_read(uint64_t offset, void *dest, uint32_t length) +inline void chd_file::file_read(uint64_t offset, void *dest, uint32_t length) const { // no file = failure if (!m_file) @@ -2637,7 +2637,7 @@ void chd_file::hunk_copy_from_parent(uint32_t hunknum, uint64_t parentunit) * @return true if it succeeds, false if it fails. */ -bool chd_file::metadata_find(chd_metadata_tag metatag, int32_t metaindex, metadata_entry &metaentry, bool resume) +bool chd_file::metadata_find(chd_metadata_tag metatag, int32_t metaindex, metadata_entry &metaentry, bool resume) const { // start at the beginning unless we're resuming a previous search if (!resume) @@ -3302,3 +3302,37 @@ void chd_file_compressor::hashmap::add(uint64_t itemnum, util::crc16_t crc16, ut entry->m_next = m_map[crc16]; m_map[crc16] = entry; } + +bool chd_file::is_hd() const +{ + metadata_entry metaentry; + return metadata_find(HARD_DISK_METADATA_TAG, 0, metaentry); +} + +bool chd_file::is_cd() const +{ + metadata_entry metaentry; + return metadata_find(CDROM_OLD_METADATA_TAG, 0, metaentry) + || metadata_find(CDROM_TRACK_METADATA_TAG, 0, metaentry) + || metadata_find(CDROM_TRACK_METADATA2_TAG, 0, metaentry); +} + +bool chd_file::is_gd() const +{ + metadata_entry metaentry; + return metadata_find(GDROM_OLD_METADATA_TAG, 0, metaentry) + || metadata_find(GDROM_TRACK_METADATA_TAG, 0, metaentry); +} + +bool chd_file::is_dvd() const +{ + metadata_entry metaentry; + return metadata_find(DVD_METADATA_TAG, 0, metaentry); +} + +bool chd_file::is_av() const +{ + metadata_entry metaentry; + return metadata_find(AV_METADATA_TAG, 0, metaentry); +} + diff --git a/src/lib/util/chd.h b/src/lib/util/chd.h index 8d3e639438b..38f86c3f5e9 100644 --- a/src/lib/util/chd.h +++ b/src/lib/util/chd.h @@ -231,6 +231,9 @@ constexpr chd_metadata_tag GDROM_OLD_METADATA_TAG = CHD_MAKE_TAG('C','H','G','T' constexpr chd_metadata_tag GDROM_TRACK_METADATA_TAG = CHD_MAKE_TAG('C', 'H', 'G', 'D'); extern const char *GDROM_TRACK_METADATA_FORMAT; +// standard DVD metafata +constexpr chd_metadata_tag DVD_METADATA_TAG = CHD_MAKE_TAG('D', 'V', 'D', ' '); + // standard A/V metadata constexpr chd_metadata_tag AV_METADATA_TAG = CHD_MAKE_TAG('A','V','A','V'); extern const char *AV_METADATA_FORMAT; @@ -352,16 +355,23 @@ public: // codec interfaces std::error_condition codec_configure(chd_codec_type codec, int param, void *config); + // typing + bool is_hd() const; + bool is_cd() const; + bool is_gd() const; + bool is_dvd() const; + bool is_av() const; + private: struct metadata_entry; struct metadata_hash; // inline helpers - uint64_t be_read(const uint8_t *base, int numbytes); + uint64_t be_read(const uint8_t *base, int numbytes) const; void be_write(uint8_t *base, uint64_t value, int numbytes); - util::sha1_t be_read_sha1(const uint8_t *base); + util::sha1_t be_read_sha1(const uint8_t *base) const; void be_write_sha1(uint8_t *base, util::sha1_t value); - void file_read(uint64_t offset, void *dest, uint32_t length); + void file_read(uint64_t offset, void *dest, uint32_t length) const; void file_write(uint64_t offset, const void *source, uint32_t length); uint64_t file_append(const void *source, uint32_t length, uint32_t alignment = 0); uint8_t bits_for_value(uint64_t value); @@ -380,7 +390,7 @@ private: void hunk_write_compressed(uint32_t hunknum, int8_t compression, const uint8_t *compressed, uint32_t complength, util::crc16_t crc16); void hunk_copy_from_self(uint32_t hunknum, uint32_t otherhunk); void hunk_copy_from_parent(uint32_t hunknum, uint64_t parentunit); - bool metadata_find(chd_metadata_tag metatag, int32_t metaindex, metadata_entry &metaentry, bool resume = false); + bool metadata_find(chd_metadata_tag metatag, int32_t metaindex, metadata_entry &metaentry, bool resume = false) const; void metadata_set_previous_next(uint64_t prevoffset, uint64_t nextoffset); void metadata_update_hash(); static int CLIB_DECL metadata_hash_compare(const void *elem1, const void *elem2); diff --git a/src/lib/util/dvdrom.cpp b/src/lib/util/dvdrom.cpp new file mode 100644 index 00000000000..36dc29e7215 --- /dev/null +++ b/src/lib/util/dvdrom.cpp @@ -0,0 +1,105 @@ +// license:BSD-3-Clause +// copyright-holders:Aaron Giles,R. Belmont +/*************************************************************************** + + dvdrom.c + + Generic MAME DVD-ROM utilties - build IDE and SCSI DVD-ROMs on top of this + +***************************************************************************/ + +#include "dvdrom.h" + +#include "corestr.h" +#include "osdfile.h" +#include "strformat.h" + +#include <cassert> +#include <cstdlib> + + + +/** + * @fn constructor + * + * @brief Open a dvdrom for a file. + * + * @param inputfile The inputfile. + */ + +dvdrom_file::dvdrom_file(std::string_view inputfile) +{ + fhandle = nullptr; +} + +/*------------------------------------------------- + constructor - "open" a DVD-ROM file from an + already-opened CHD file +-------------------------------------------------*/ + +/** + * @fn dvdrom_file *dvdrom_open(chd_file *chd) + * + * @brief Queries if a given dvdrom open. + * + * @param [in,out] chd If non-null, the chd. + * + * @return null if it fails, else a dvdrom_file*. + */ + +dvdrom_file::dvdrom_file(chd_file *_chd) +{ + chd = _chd; + + /* validate the CHD information */ + if (chd->hunk_bytes() != 2048) + throw nullptr; + if (chd->unit_bytes() != 2048) + throw nullptr; + + /* check it's actually a DVD-ROM */ + if (!chd->is_dvd()) + throw nullptr; + + sector_count = chd->unit_count(); +} + + +/*------------------------------------------------- + destructor - "close" a DVD-ROM file +-------------------------------------------------*/ + +dvdrom_file::~dvdrom_file() +{ +} + + + +/*************************************************************************** + CORE READ ACCESS +***************************************************************************/ + + +/*------------------------------------------------- + dvdrom_read_data - read one 2048 bytes sector + from a DVD-ROM +-------------------------------------------------*/ + +/** + * @fn bool read_data(uint32_t lbasector, void *buffer) + * + * @brief Dvdrom read data. + * + * @param lbasector The lbasector. + * @param buffer The buffer. + * + * @return Success status. + */ + +std::error_condition dvdrom_file::read_data(uint32_t lbasector, void *buffer) +{ + if (lbasector >= sector_count) + return std::error_condition(chd_file::error::HUNK_OUT_OF_RANGE); + + return chd->read_hunk(lbasector, buffer); +} diff --git a/src/lib/util/dvdrom.h b/src/lib/util/dvdrom.h new file mode 100644 index 00000000000..47bd6a26172 --- /dev/null +++ b/src/lib/util/dvdrom.h @@ -0,0 +1,41 @@ +// license:BSD-3-Clause +// copyright-holders:Aaron Giles,R. Belmont +/*************************************************************************** + + dvdrom.h + + Generic MAME dvd-rom implementation + +***************************************************************************/ +#ifndef MAME_LIB_UTIL_DVDROM_H +#define MAME_LIB_UTIL_DVDROM_H + +#pragma once + +#include "chd.h" +#include "ioprocs.h" +#include "osdcore.h" + +class dvdrom_file { +public: + dvdrom_file(chd_file *chd); + dvdrom_file(std::string_view inputfile); + ~dvdrom_file(); + + uint32_t get_sector_count() const { return sector_count; } + + /* core read access */ + std::error_condition read_data(uint32_t lbasector, void *buffer); + +private: + /** @brief The chd, when there's one */ + chd_file * chd; /* CHD file */ + + /** @brief The raw file, when there isn't */ + util::random_read_write * fhandle; // file if not a CHD + + /** @brief Size of the dvd image in sectors */ + uint32_t sector_count; +}; + +#endif // MAME_LIB_UTIL_DVDROM_H |