diff options
author | 2021-10-05 03:34:45 +1100 | |
---|---|---|
committer | 2021-10-05 03:34:45 +1100 | |
commit | aeb9eae87469e67bc6a91caf3840c34c11d959fc (patch) | |
tree | 45bffedf374dbce47caca633ad7bda547592e6c9 /src/devices/imagedev | |
parent | 33723892a3f06e678d817b36aef84364c32848ec (diff) |
util: Further API cleanups: (#8661)
* Turned `core_file` into an implementation of `random_read_write`.
* Turned PNG errors into a standard error category.
* Added a helper for generating what look like derived classes on-the-fly.
Diffstat (limited to 'src/devices/imagedev')
-rw-r--r-- | src/devices/imagedev/cassette.cpp | 5 | ||||
-rw-r--r-- | src/devices/imagedev/chd_cd.cpp | 5 | ||||
-rw-r--r-- | src/devices/imagedev/diablo.cpp | 14 | ||||
-rw-r--r-- | src/devices/imagedev/flopdrv.cpp | 3 | ||||
-rw-r--r-- | src/devices/imagedev/floppy.cpp | 7 | ||||
-rw-r--r-- | src/devices/imagedev/harddriv.cpp | 17 | ||||
-rw-r--r-- | src/devices/imagedev/midiin.cpp | 2 |
7 files changed, 38 insertions, 15 deletions
diff --git a/src/devices/imagedev/cassette.cpp b/src/devices/imagedev/cassette.cpp index 52103cb1e7d..338f1ed7413 100644 --- a/src/devices/imagedev/cassette.cpp +++ b/src/devices/imagedev/cassette.cpp @@ -14,6 +14,7 @@ #include "formats/imageutl.h" #include "util/ioprocs.h" +#include "util/ioprocsfilter.h" #define LOG_WARN (1U<<1) // Warnings #define LOG_DETAIL (1U<<2) // Details @@ -260,7 +261,7 @@ image_init_result cassette_image_device::internal_load(bool is_create) check_for_file(); if (is_create || (length()==0)) // empty existing images are fine to write over. { - auto io = util::core_file_read_write(image_core_file(), 0x00); + auto io = util::random_read_write_fill(image_core_file(), 0x00); if (io) { // creating an image @@ -285,7 +286,7 @@ image_init_result cassette_image_device::internal_load(bool is_create) // we probably don't want to retry... retry = false; - auto io = util::core_file_read_write(image_core_file(), 0x00); + auto io = util::random_read_write_fill(image_core_file(), 0x00); if (io) { // try opening the cassette diff --git a/src/devices/imagedev/chd_cd.cpp b/src/devices/imagedev/chd_cd.cpp index 4eacb3d3b58..753a7b88212 100644 --- a/src/devices/imagedev/chd_cd.cpp +++ b/src/devices/imagedev/chd_cd.cpp @@ -91,7 +91,10 @@ image_init_result cdrom_image_device::call_load() if (!loaded_through_softlist()) { if (is_filetype("chd") && is_loaded()) { - err = m_self_chd.open(util::core_file_read_write(image_core_file())); // CDs are never writeable + util::core_file::ptr proxy; + err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + err = m_self_chd.open(std::move(proxy)); // CDs are never writeable if (err) goto error; chd = &m_self_chd; diff --git a/src/devices/imagedev/diablo.cpp b/src/devices/imagedev/diablo.cpp index 0a4107ac90a..cdc7665f61d 100644 --- a/src/devices/imagedev/diablo.cpp +++ b/src/devices/imagedev/diablo.cpp @@ -127,7 +127,10 @@ image_init_result diablo_image_device::call_create(int create_format, util::opti /* create the CHD file */ chd_codec_type compression[4] = { CHD_CODEC_NONE }; - std::error_condition err = m_origchd.create(util::core_file_read_write(image_core_file()), uint64_t(totalsectors) * uint64_t(sectorsize), hunksize, sectorsize, compression); + util::core_file::ptr proxy; + std::error_condition err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + m_origchd.create(std::move(proxy), uint64_t(totalsectors) * uint64_t(sectorsize), hunksize, sectorsize, compression); if (err) return image_init_result::FAIL; @@ -219,14 +222,19 @@ image_init_result diablo_image_device::internal_load_dsk() } else { - err = m_origchd.open(util::core_file_read_write(image_core_file()), true); + util::core_file::ptr proxy; + err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + err = m_origchd.open(std::move(proxy), true); if (!err) { m_chd = &m_origchd; } else if (err == chd_file::error::FILE_NOT_WRITEABLE) { - err = m_origchd.open(util::core_file_read_write(image_core_file()), false); + err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + err = m_origchd.open(std::move(proxy), false); if (!err) { err = open_disk_diff(device().machine().options(), basename_noext(), m_origchd, m_diffchd); diff --git a/src/devices/imagedev/flopdrv.cpp b/src/devices/imagedev/flopdrv.cpp index 316b66ef713..1188519d648 100644 --- a/src/devices/imagedev/flopdrv.cpp +++ b/src/devices/imagedev/flopdrv.cpp @@ -19,6 +19,7 @@ #include "formats/imageutl.h" #include "util/ioprocs.h" +#include "util/ioprocsfilter.h" #define VERBOSE 0 @@ -426,7 +427,7 @@ image_init_result legacy_floppy_image_device::internal_floppy_device_load(bool i floperr_t err; check_for_file(); - auto io = util::core_file_read_write(image_core_file(), 0xff); + auto io = util::random_read_write_fill(image_core_file(), 0xff); if (!io) { err = FLOPPY_ERROR_OUTOFMEMORY; diff --git a/src/devices/imagedev/floppy.cpp b/src/devices/imagedev/floppy.cpp index 5d3956e2cab..00d4b77ecd3 100644 --- a/src/devices/imagedev/floppy.cpp +++ b/src/devices/imagedev/floppy.cpp @@ -30,6 +30,7 @@ #include "formats/imageutl.h" #include "util/ioprocs.h" +#include "util/ioprocsfilter.h" #include "util/zippath.h" /* @@ -403,7 +404,7 @@ void floppy_image_device::commit_image() return; check_for_file(); - auto io = util::core_file_read_write(image_core_file(), 0xff); + auto io = util::random_read_write_fill(image_core_file(), 0xff); if(!io) { popmessage("Error, out of memory"); return; @@ -543,7 +544,7 @@ floppy_image_format_t *floppy_image_device::identify(std::string filename) return nullptr; } - auto io = util::core_file_read(std::move(fd), 0xff); + auto io = util::random_read_fill(std::move(fd), 0xff); if(!io) { seterror(std::errc::not_enough_memory, nullptr); return nullptr; @@ -591,7 +592,7 @@ void floppy_image_device::init_floppy_load(bool write_supported) image_init_result floppy_image_device::call_load() { check_for_file(); - auto io = util::core_file_read(image_core_file(), 0xff); + auto io = util::random_read_fill(image_core_file(), 0xff); if(!io) { seterror(std::errc::not_enough_memory, nullptr); return image_init_result::FAIL; diff --git a/src/devices/imagedev/harddriv.cpp b/src/devices/imagedev/harddriv.cpp index 384bc8c3e92..ff623d58150 100644 --- a/src/devices/imagedev/harddriv.cpp +++ b/src/devices/imagedev/harddriv.cpp @@ -148,7 +148,10 @@ image_init_result harddisk_image_device::call_create(int create_format, util::op /* create the CHD file */ chd_codec_type compression[4] = { CHD_CODEC_NONE }; - std::error_condition err = m_origchd.create(util::core_file_read_write(image_core_file()), (uint64_t)totalsectors * (uint64_t)sectorsize, hunksize, sectorsize, compression); + util::core_file::ptr proxy; + std::error_condition err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + err = m_origchd.create(std::move(proxy), uint64_t(totalsectors) * uint64_t(sectorsize), hunksize, sectorsize, compression); if (err) return image_init_result::FAIL; @@ -250,7 +253,10 @@ image_init_result harddisk_image_device::internal_load_hd() if (!memcmp("MComprHD", header, 8)) { - err = m_origchd.open(util::core_file_read_write(image_core_file()), true); + util::core_file::ptr proxy; + err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + err = m_origchd.open(std::move(proxy), true); if (!err) { @@ -258,7 +264,10 @@ image_init_result harddisk_image_device::internal_load_hd() } else if (err == chd_file::error::FILE_NOT_WRITEABLE) { - err = m_origchd.open(util::core_file_read_write(image_core_file()), false); + err = util::core_file::open_proxy(image_core_file(), proxy); + if (!err) + err = m_origchd.open(std::move(proxy), false); + if (!err) { err = open_disk_diff(device().machine().options(), basename_noext(), m_origchd, m_diffchd); @@ -295,7 +304,7 @@ image_init_result harddisk_image_device::internal_load_hd() { skip = header[0x8] | (header[0x9] << 8) | (header[0xa] << 16) | (header[0xb] << 24); uint32_t data_size = header[0xc] | (header[0xd] << 8) | (header[0xe] << 16) | (header[0xf] << 24); - if (data_size == image_core_file().size() - skip) + if (data_size == length() - skip) { osd_printf_verbose("harddriv: detected Anex86 HDI, data at %08x\n", skip); } diff --git a/src/devices/imagedev/midiin.cpp b/src/devices/imagedev/midiin.cpp index e2386afb532..63afc1c83f5 100644 --- a/src/devices/imagedev/midiin.cpp +++ b/src/devices/imagedev/midiin.cpp @@ -134,7 +134,7 @@ image_init_result midiin_device::call_load() // if the parsing succeeds, schedule the start to happen at least // 10 seconds after starting to allow the keyboards to initialize // TODO: this should perhaps be a driver-configurable parameter? - if (m_sequence.parse(reinterpret_cast<u8 *>(ptr()), length())) + if (m_sequence.parse(reinterpret_cast<u8 const *>(ptr()), length())) { m_sequence_start = std::max(machine().time(), attotime(10, 0)); m_timer->adjust(attotime::zero); |