summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2021-08-22 09:06:15 +1000
committer GitHub <noreply@github.com>2021-08-22 09:06:15 +1000
commite8bbea1fc6e94e14768509d322f6c624403ffb36 (patch)
tree74dd1606a900d83de8aecff17a6737af4113308d /src/emu
parente319bde5fc3696d7f48f62b15b6366c4377fe5d1 (diff)
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter. unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename. Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums. Allow mounting TI-99 RPK from inside archives.
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/addrmap.h2
-rw-r--r--src/emu/config.cpp20
-rw-r--r--src/emu/crsshair.cpp6
-rw-r--r--src/emu/debug/debugcmd.cpp6
-rw-r--r--src/emu/debug/debugcpu.cpp8
-rw-r--r--src/emu/devcb.h104
-rw-r--r--src/emu/devdelegate.h16
-rw-r--r--src/emu/devfind.h2
-rw-r--r--src/emu/device.h12
-rw-r--r--src/emu/diimage.cpp207
-rw-r--r--src/emu/diimage.h33
-rw-r--r--src/emu/dimemory.h10
-rw-r--r--src/emu/dipty.cpp9
-rw-r--r--src/emu/dipty.h8
-rw-r--r--src/emu/fileio.cpp69
-rw-r--r--src/emu/fileio.h26
-rw-r--r--src/emu/hashfile.cpp4
-rw-r--r--src/emu/http.cpp6
-rw-r--r--src/emu/image.cpp4
-rw-r--r--src/emu/ioport.cpp77
-rw-r--r--src/emu/ioport.h9
-rw-r--r--src/emu/machine.cpp16
-rw-r--r--src/emu/render.cpp5
-rw-r--r--src/emu/rendfont.cpp16
-rw-r--r--src/emu/rendlay.cpp41
-rw-r--r--src/emu/romload.cpp70
-rw-r--r--src/emu/romload.h13
-rw-r--r--src/emu/save.cpp55
-rw-r--r--src/emu/save.h8
-rw-r--r--src/emu/screen.cpp6
-rw-r--r--src/emu/softlist_dev.cpp6
-rw-r--r--src/emu/uiinput.h2
-rw-r--r--src/emu/video.cpp26
-rw-r--r--src/emu/video.h4
34 files changed, 431 insertions, 475 deletions
diff --git a/src/emu/addrmap.h b/src/emu/addrmap.h
index c5a6c17d128..76cdc6aef54 100644
--- a/src/emu/addrmap.h
+++ b/src/emu/addrmap.h
@@ -72,7 +72,7 @@ class address_map_entry
friend class address_map;
template <typename T, typename Ret, typename... Params>
- struct is_addrmap_method { static constexpr bool value = std::is_constructible<address_map_constructor, Ret (T::*)(Params...), const char *, T*>::value; };
+ using is_addrmap_method = std::bool_constant<std::is_constructible_v<address_map_constructor, Ret (T::*)(Params...), const char *, T *> >;
template <typename T, typename Ret, typename... Params>
static std::enable_if_t<is_addrmap_method<T, Ret, Params...>::value, address_map_constructor> make_delegate(Ret (T::*func)(Params...), const char *name, T *obj)
diff --git a/src/emu/config.cpp b/src/emu/config.cpp
index 46bec43c1dd..792da6f255d 100644
--- a/src/emu/config.cpp
+++ b/src/emu/config.cpp
@@ -64,16 +64,16 @@ bool configuration_manager::load_settings()
type.load(config_type::INIT, config_level::DEFAULT, nullptr);
// now load the controller file
- const char *controller = machine().options().ctrlr();
+ char const *const controller = machine().options().ctrlr();
if (controller && *controller)
{
// open the config file
emu_file file(machine().options().ctrlr_path(), OPEN_FLAG_READ);
osd_printf_verbose("Attempting to parse: %s.cfg\n", controller);
- osd_file::error filerr = file.open(std::string(controller) + ".cfg");
+ std::error_condition const filerr = file.open(std::string(controller) + ".cfg");
- if (filerr != osd_file::error::NONE)
- throw emu_fatalerror("Could not open controller file %s.cfg", controller);
+ if (filerr)
+ throw emu_fatalerror("Could not open controller file %s.cfg (%s:%d %s)", controller, filerr.category().name(), filerr.value(), filerr.message());
// load the XML
if (!load_xml(file, config_type::CONTROLLER))
@@ -82,15 +82,15 @@ bool configuration_manager::load_settings()
// next load the defaults file
emu_file file(machine().options().cfg_directory(), OPEN_FLAG_READ);
- osd_file::error filerr = file.open("default.cfg");
+ std::error_condition filerr = file.open("default.cfg");
osd_printf_verbose("Attempting to parse: default.cfg\n");
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
load_xml(file, config_type::DEFAULT);
// finally, load the game-specific file
filerr = file.open(machine().basename() + ".cfg");
osd_printf_verbose("Attempting to parse: %s.cfg\n",machine().basename());
- const bool loaded = (osd_file::error::NONE == filerr) && load_xml(file, config_type::SYSTEM);
+ const bool loaded = !filerr && load_xml(file, config_type::SYSTEM);
// loop over all registrants and call their final function
for (const auto &type : m_typelist)
@@ -110,13 +110,13 @@ void configuration_manager::save_settings()
// save the defaults file
emu_file file(machine().options().cfg_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open("default.cfg");
- if (filerr == osd_file::error::NONE)
+ std::error_condition filerr = file.open("default.cfg");
+ if (!filerr)
save_xml(file, config_type::DEFAULT);
// finally, save the system-specific file
filerr = file.open(machine().basename() + ".cfg");
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
save_xml(file, config_type::SYSTEM);
// loop over all registrants and call their final function
diff --git a/src/emu/crsshair.cpp b/src/emu/crsshair.cpp
index 43eac50587b..3c6a6b807f0 100644
--- a/src/emu/crsshair.cpp
+++ b/src/emu/crsshair.cpp
@@ -189,7 +189,7 @@ void render_crosshair::create_bitmap()
if (!m_name.empty())
{
// look for user specified file
- if (crossfile.open(m_name + ".png") == osd_file::error::NONE)
+ if (!crossfile.open(m_name + ".png"))
{
render_load_png(*m_bitmap, crossfile);
crossfile.close();
@@ -199,14 +199,14 @@ void render_crosshair::create_bitmap()
{
// look for default cross?.png in crsshair/game dir
std::string const filename = string_format("cross%d.png", m_player + 1);
- if (crossfile.open(m_machine.system().name + (PATH_SEPARATOR + filename)) == osd_file::error::NONE)
+ if (!crossfile.open(m_machine.system().name + (PATH_SEPARATOR + filename)))
{
render_load_png(*m_bitmap, crossfile);
crossfile.close();
}
// look for default cross?.png in crsshair dir
- if (!m_bitmap->valid() && (crossfile.open(filename) == osd_file::error::NONE))
+ if (!m_bitmap->valid() && !crossfile.open(filename))
{
render_load_png(*m_bitmap, crossfile);
crossfile.close();
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp
index bd537935851..58cc85f7a86 100644
--- a/src/emu/debug/debugcmd.cpp
+++ b/src/emu/debug/debugcmd.cpp
@@ -3671,11 +3671,11 @@ void debugger_commands::execute_snap(int ref, const std::vector<std::string> &pa
if (fname.find(".png") == -1)
fname.append(".png");
emu_file file(m_machine.options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open(std::move(fname));
+ std::error_condition filerr = file.open(std::move(fname));
- if (filerr != osd_file::error::NONE)
+ if (filerr)
{
- m_console.printf("Error creating file '%s'\n", filename);
+ m_console.printf("Error creating file '%s' (%s:%d %s)\n", filename, filerr.category().name(), filerr.value(), filerr.message());
return;
}
diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp
index 1399a6b8ec2..233e369433e 100644
--- a/src/emu/debug/debugcpu.cpp
+++ b/src/emu/debug/debugcpu.cpp
@@ -168,8 +168,8 @@ bool debugger_cpu::comment_save()
if (found_comments)
{
emu_file file(m_machine.options().comment_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open(m_machine.basename() + ".cmt");
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = file.open(m_machine.basename() + ".cmt");
+ if (!filerr)
{
root->write(file);
comments_saved = true;
@@ -194,10 +194,10 @@ bool debugger_cpu::comment_load(bool is_inline)
{
// open the file
emu_file file(m_machine.options().comment_directory(), OPEN_FLAG_READ);
- osd_file::error filerr = file.open(m_machine.basename() + ".cmt");
+ std::error_condition const filerr = file.open(m_machine.basename() + ".cmt");
// if an error, just return false
- if (filerr != osd_file::error::NONE)
+ if (filerr)
return false;
// wrap in a try/catch to handle errors
diff --git a/src/emu/devcb.h b/src/emu/devcb.h
index ec543aa48d6..d27d3beb74d 100644
--- a/src/emu/devcb.h
+++ b/src/emu/devcb.h
@@ -82,16 +82,16 @@ protected:
template <typename T, typename U> using mask_t = std::make_unsigned_t<intermediate_t<T, U> >;
// Detecting candidates for transform functions
- template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form1 { static constexpr bool value = false; };
- template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form2 { static constexpr bool value = false; };
- template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form3 { static constexpr bool value = false; };
- template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form4 { static constexpr bool value = false; };
- template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form5 { static constexpr bool value = false; };
- template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form6 { static constexpr bool value = false; };
- template <typename Input, typename Result, typename Func> struct is_transform_form3<Input, Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t &, Input, std::make_unsigned_t<Input> &>, Result>::value> > { static constexpr bool value = true; };
- template <typename Input, typename Result, typename Func> struct is_transform_form4<Input, Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t &, Input>, Result>::value> > { static constexpr bool value = true; };
- template <typename Input, typename Result, typename Func> struct is_transform_form6<Input, Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, Input>, Result>::value> > { static constexpr bool value = true; };
- template <typename Input, typename Result, typename Func> struct is_transform { static constexpr bool value = is_transform_form1<Input, Result, Func>::value || is_transform_form2<Input, Result, Func>::value || is_transform_form3<Input, Result, Func>::value || is_transform_form4<Input, Result, Func>::value || is_transform_form5<Input, Result, Func>::value || is_transform_form6<Input, Result, Func>::value; };
+ template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form1 : public std::false_type { };
+ template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form2 : public std::false_type { };
+ template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form3 : public std::false_type { };
+ template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form4 : public std::false_type { };
+ template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form5 : public std::false_type { };
+ template <typename Input, typename Result, typename Func, typename Enable = void> struct is_transform_form6 : public std::false_type { };
+ template <typename Input, typename Result, typename Func> struct is_transform_form3<Input, Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t &, Input, std::make_unsigned_t<Input> &>, Result>::value> > : public std::true_type { };
+ template <typename Input, typename Result, typename Func> struct is_transform_form4<Input, Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t &, Input>, Result>::value> > : public std::true_type { };
+ template <typename Input, typename Result, typename Func> struct is_transform_form6<Input, Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, Input>, Result>::value> > : public std::true_type { };
+ template <typename Input, typename Result, typename Func> struct is_transform : public std::bool_constant<is_transform_form1<Input, Result, Func>::value || is_transform_form2<Input, Result, Func>::value || is_transform_form3<Input, Result, Func>::value || is_transform_form4<Input, Result, Func>::value || is_transform_form5<Input, Result, Func>::value || is_transform_form6<Input, Result, Func>::value> { };
// Determining the result type of a transform function
template <typename Input, typename Result, typename Func, typename Enable = void> struct transform_result;
@@ -211,13 +211,13 @@ class devcb_read_base : public devcb_base
{
protected:
// Detecting candidates for read functions
- template <typename Result, typename Func, typename Enable = void> struct is_read_form1 { static constexpr bool value = false; };
- template <typename Result, typename Func, typename Enable = void> struct is_read_form2 { static constexpr bool value = false; };
- template <typename Result, typename Func, typename Enable = void> struct is_read_form3 { static constexpr bool value = false; };
- template <typename Result, typename Func> struct is_read_form1<Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t, Result>, Result>::value> > { static constexpr bool value = true; };
- template <typename Result, typename Func> struct is_read_form2<Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t>, Result>::value> > { static constexpr bool value = true; };
- template <typename Result, typename Func> struct is_read_form3<Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func>, Result>::value> > { static constexpr bool value = true; };
- template <typename Result, typename Func> struct is_read { static constexpr bool value = is_read_form1<Result, Func>::value || is_read_form2<Result, Func>::value || is_read_form3<Result, Func>::value; };
+ template <typename Result, typename Func, typename Enable = void> struct is_read_form1 : public std::false_type { };
+ template <typename Result, typename Func, typename Enable = void> struct is_read_form2 : public std::false_type { };
+ template <typename Result, typename Func, typename Enable = void> struct is_read_form3 : public std::false_type { };
+ template <typename Result, typename Func> struct is_read_form1<Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t, Result>, Result>::value> > : public std::true_type { };
+ template <typename Result, typename Func> struct is_read_form2<Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func, offs_t>, Result>::value> > : public std::true_type { };
+ template <typename Result, typename Func> struct is_read_form3<Result, Func, std::enable_if_t<std::is_convertible<std::invoke_result_t<Func>, Result>::value> > : public std::true_type { };
+ template <typename Result, typename Func> struct is_read : public std::bool_constant<is_read_form1<Result, Func>::value || is_read_form2<Result, Func>::value || is_read_form3<Result, Func>::value> { };
// Determining the result type of a read function
template <typename Result, typename Func, typename Enable = void> struct read_result;
@@ -227,20 +227,20 @@ protected:
template <typename Result, typename Func> using read_result_t = typename read_result<Result, Func>::type;
// Detecting candidates for read delegates
- template <typename T, typename Enable = void> struct is_read_method { static constexpr bool value = false; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read8s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read16s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read32s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read64s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read8sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read16sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read32sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read64sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read8smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read16smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read32smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read64smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read_line_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
+ template <typename T, typename Enable = void> struct is_read_method : public std::false_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read8s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read16s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read32s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read64s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read8sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read16sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read32sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read64sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read8smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read16smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read32smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read64smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_read_method<T, void_t<emu::detail::rw_device_class_t<read_line_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
// Invoking read callbacks
template <typename Result, typename T> static std::enable_if_t<is_read_form1<Result, T>::value, mask_t<read_result_t<Result, T>, Result> > invoke_read(T const &cb, offs_t offset, std::make_unsigned_t<Result> mem_mask) { return std::make_unsigned_t<read_result_t<Result, T> >(cb(offset, mem_mask)); }
@@ -275,29 +275,29 @@ class devcb_write_base : public devcb_base
{
protected:
// Detecting candidates for write functions
- template <typename Input, typename Func, typename Enable = void> struct is_write_form1 { static constexpr bool value = false; };
- template <typename Input, typename Func, typename Enable = void> struct is_write_form2 { static constexpr bool value = false; };
- template <typename Input, typename Func, typename Enable = void> struct is_write_form3 { static constexpr bool value = false; };
- template <typename Input, typename Func> struct is_write_form1<Input, Func, void_t<std::invoke_result_t<Func, offs_t, Input, std::make_unsigned_t<Input>> > > { static constexpr bool value = true; };
- template <typename Input, typename Func> struct is_write_form2<Input, Func, void_t<std::invoke_result_t<Func, offs_t, Input> > > { static constexpr bool value = true; };
- template <typename Input, typename Func> struct is_write_form3<Input, Func, void_t<std::invoke_result_t<Func, Input> > > { static constexpr bool value = true; };
- template <typename Input, typename Func> struct is_write { static constexpr bool value = is_write_form1<Input, Func>::value || is_write_form2<Input, Func>::value || is_write_form3<Input, Func>::value; };
+ template <typename Input, typename Func, typename Enable = void> struct is_write_form1 : public std::false_type { };
+ template <typename Input, typename Func, typename Enable = void> struct is_write_form2 : public std::false_type { };
+ template <typename Input, typename Func, typename Enable = void> struct is_write_form3 : public std::false_type { };
+ template <typename Input, typename Func> struct is_write_form1<Input, Func, void_t<std::invoke_result_t<Func, offs_t, Input, std::make_unsigned_t<Input>> > > : public std::true_type { };
+ template <typename Input, typename Func> struct is_write_form2<Input, Func, void_t<std::invoke_result_t<Func, offs_t, Input> > > : public std::true_type { };
+ template <typename Input, typename Func> struct is_write_form3<Input, Func, void_t<std::invoke_result_t<Func, Input> > > : public std::true_type { };
+ template <typename Input, typename Func> struct is_write : public std::bool_constant<is_write_form1<Input, Func>::value || is_write_form2<Input, Func>::value || is_write_form3<Input, Func>::value> { };
// Detecting candidates for write delegates
- template <typename T, typename Enable = void> struct is_write_method { static constexpr bool value = false; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write8s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write16s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write32s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write64s_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write8sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write16sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write32sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write64sm_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write8smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write16smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write32smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write64smo_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
- template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write_line_delegate, std::remove_reference_t<T> > > > { static constexpr bool value = true; };
+ template <typename T, typename Enable = void> struct is_write_method : public std::false_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write8s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write16s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write32s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write64s_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write8sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write16sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write32sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write64sm_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write8smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write16smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write32smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write64smo_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
+ template <typename T> struct is_write_method<T, void_t<emu::detail::rw_device_class_t<write_line_delegate, std::remove_reference_t<T> > > > : public std::true_type { };
// Invoking write callbacks
template <typename Input, typename T> static std::enable_if_t<is_write_form1<Input, T>::value> invoke_write(T const &cb, offs_t &offset, Input data, std::make_unsigned_t<Input> mem_mask) { return cb(offset, data, mem_mask); }
diff --git a/src/emu/devdelegate.h b/src/emu/devdelegate.h
index 1ba303d3ef3..906e1da9274 100644
--- a/src/emu/devdelegate.h
+++ b/src/emu/devdelegate.h
@@ -111,12 +111,12 @@ class device_delegate<ReturnType (Params...)> : protected named_delegate<ReturnT
private:
using basetype = named_delegate<ReturnType (Params...)>;
- template <class T, class U> struct is_related_device_implementation
- { static constexpr bool value = std::is_base_of<T, U>::value && std::is_base_of<device_t, U>::value; };
- template <class T, class U> struct is_related_device_interface
- { static constexpr bool value = std::is_base_of<T, U>::value && std::is_base_of<device_interface, U>::value && !std::is_base_of<device_t, U>::value; };
- template <class T, class U> struct is_related_device
- { static constexpr bool value = is_related_device_implementation<T, U>::value || is_related_device_interface<T, U>::value; };
+ template <class T, class U>
+ using is_related_device_implementation = std::bool_constant<std::is_base_of_v<T, U> && std::is_base_of_v<device_t, U> >;
+ template <class T, class U>
+ using is_related_device_interface = std::bool_constant<std::is_base_of_v<T, U> && std::is_base_of_v<device_interface, U> && !std::is_base_of_v<device_t, U> >;
+ template <class T, class U>
+ using is_related_device = std::bool_constant<is_related_device_implementation<T, U>::value || is_related_device_interface<T, U>::value>;
template <class T> static std::enable_if_t<is_related_device_implementation<T, T>::value, device_t &> get_device(T &object) { return object; }
template <class T> static std::enable_if_t<is_related_device_interface<T, T>::value, device_t &> get_device(T &object) { return object.device(); }
@@ -124,8 +124,8 @@ private:
public:
template <unsigned Count> using array = device_delegate_array<ReturnType (Params...), Count>;
- template <typename T> struct supports_callback
- { static constexpr bool value = std::is_constructible<device_delegate, device_t &, char const *, T, char const *>::value; };
+ template <typename T>
+ using supports_callback = std::bool_constant<std::is_constructible_v<device_delegate, device_t &, char const *, T, char const *> >;
// construct/assign
explicit device_delegate(device_t &owner) : basetype(), detail::device_delegate_helper(owner) { }
diff --git a/src/emu/devfind.h b/src/emu/devfind.h
index c5f7a04929a..8253fb123f6 100644
--- a/src/emu/devfind.h
+++ b/src/emu/devfind.h
@@ -308,7 +308,7 @@ public:
}
/// \brief Dummy tag always treated as not found
- constexpr static char DUMMY_TAG[17] = "finder_dummy_tag";
+ static constexpr char DUMMY_TAG[17] = "finder_dummy_tag";
protected:
/// \brief Designated constructor
diff --git a/src/emu/device.h b/src/emu/device.h
index 21ac3bcba6e..d5fe81dd305 100644
--- a/src/emu/device.h
+++ b/src/emu/device.h
@@ -69,15 +69,11 @@ namespace emu::detail {
class device_type_impl_base;
-template <typename T> struct is_device_implementation
-{
- static constexpr bool value = std::is_base_of<device_t, T>::value;
-};
+template <typename T>
+using is_device_implementation = std::bool_constant<std::is_base_of_v<device_t, T> >;
-template <typename T> struct is_device_interface
-{
- static constexpr bool value = std::is_base_of<device_interface, T>::value && !is_device_implementation<T>::value;
-};
+template <typename T>
+using is_device_interface = std::bool_constant<std::is_base_of_v<device_interface, T> && !is_device_implementation<T>::value>;
struct device_feature
diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp
index 55a9193f3f1..e38b4939a2b 100644
--- a/src/emu/diimage.cpp
+++ b/src/emu/diimage.cpp
@@ -10,14 +10,15 @@
#include "emu.h"
-#include "corestr.h"
#include "emuopts.h"
#include "romload.h"
-#include "ui/uimain.h"
-#include "zippath.h"
#include "softlist.h"
#include "softlist_dev.h"
-#include "formats/ioprocs.h"
+
+#include "ui/uimain.h"
+
+#include "corestr.h"
+#include "zippath.h"
#include <algorithm>
#include <cctype>
@@ -270,11 +271,8 @@ void device_image_interface::add_format(std::string &&name, std::string &&descri
void device_image_interface::clear_error()
{
- m_err = IMAGE_ERROR_SUCCESS;
- if (!m_err_message.empty())
- {
- m_err_message.clear();
- }
+ m_err.clear();
+ m_err_message.clear();
}
@@ -284,21 +282,38 @@ void device_image_interface::clear_error()
// error
//-------------------------------------------------
-static std::string_view messages[] =
+std::error_category const &image_category() noexcept
{
- "",
- "Internal error",
- "Unsupported operation",
- "Out of memory",
- "File not found",
- "Invalid image",
- "File already open",
- "Unspecified error"
-};
+ class image_category_impl : public std::error_category
+ {
+ public:
+ virtual char const *name() const noexcept override { return "image"; }
+
+ virtual std::string message(int condition) const override
+ {
+ using namespace std::literals;
+ static std::string_view const s_messages[] = {
+ "No error"sv,
+ "Internal error"sv,
+ "Unsupported operation"sv,
+ "Invalid image"sv,
+ "File already open"sv,
+ "Unspecified error"sv };
+ if ((0 <= condition) && (std::size(s_messages) > condition))
+ return std::string(s_messages[condition]);
+ else
+ return "Unknown error"s;
+ }
+ };
+ static image_category_impl const s_image_category_instance;
+ return s_image_category_instance;
+}
std::string_view device_image_interface::error()
{
- return (!m_err_message.empty()) ? m_err_message : messages[m_err];
+ if (m_err && m_err_message.empty())
+ m_err_message = m_err.message();
+ return m_err_message;
}
@@ -307,14 +322,12 @@ std::string_view device_image_interface::error()
// seterror - specifies an error on an image
//-------------------------------------------------
-void device_image_interface::seterror(image_error_t err, const char *message)
+void device_image_interface::seterror(std::error_condition err, const char *message)
{
clear_error();
m_err = err;
- if (message != nullptr)
- {
+ if (message)
m_err_message = message;
- }
}
@@ -544,14 +557,13 @@ void device_image_interface::battery_load(void *buffer, int length, int fill)
if (!buffer || (length <= 0))
throw emu_fatalerror("device_image_interface::battery_load: Must specify sensical buffer/length");
- osd_file::error filerr;
- int bytes_read = 0;
- std::string fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext).append(".nv");
+ std::string const fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext).append(".nv");
/* try to open the battery file and read it in, if possible */
emu_file file(device().machine().options().nvram_directory(), OPEN_FLAG_READ);
- filerr = file.open(fname);
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = file.open(fname);
+ int bytes_read = 0;
+ if (!filerr)
bytes_read = file.read(buffer, length);
// fill remaining bytes (if necessary)
@@ -563,14 +575,13 @@ void device_image_interface::battery_load(void *buffer, int length, const void *
if (!buffer || (length <= 0))
throw emu_fatalerror("device_image_interface::battery_load: Must specify sensical buffer/length");
- osd_file::error filerr;
- int bytes_read = 0;
- std::string fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext).append(".nv");
+ std::string const fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext).append(".nv");
// try to open the battery file and read it in, if possible
emu_file file(device().machine().options().nvram_directory(), OPEN_FLAG_READ);
- filerr = file.open(fname);
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = file.open(fname);
+ int bytes_read = 0;
+ if (!filerr)
bytes_read = file.read(buffer, length);
// if no file was present, copy the default contents
@@ -598,8 +609,8 @@ void device_image_interface::battery_save(const void *buffer, int length)
// try to open the battery file and write it out, if possible
emu_file file(device().machine().options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open(fname);
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = file.open(fname);
+ if (!filerr)
file.write(buffer, length);
}
@@ -637,58 +648,30 @@ bool device_image_interface::uses_file_extension(const char *file_extension) con
// ***************************************************************************
//-------------------------------------------------
-// image_error_from_file_error - converts an image
-// error to a file error
-//-------------------------------------------------
-
-image_error_t device_image_interface::image_error_from_file_error(osd_file::error filerr)
-{
- switch (filerr)
- {
- case osd_file::error::NONE:
- return IMAGE_ERROR_SUCCESS;
-
- case osd_file::error::NOT_FOUND:
- case osd_file::error::ACCESS_DENIED:
- // file not found (or otherwise cannot open)
- return IMAGE_ERROR_FILENOTFOUND;
-
- case osd_file::error::OUT_OF_MEMORY:
- // out of memory
- return IMAGE_ERROR_OUTOFMEMORY;
-
- case osd_file::error::ALREADY_OPEN:
- // this shouldn't happen
- return IMAGE_ERROR_ALREADYOPEN;
-
- case osd_file::error::FAILURE:
- case osd_file::error::TOO_MANY_FILES:
- case osd_file::error::INVALID_DATA:
- default:
- // other errors
- return IMAGE_ERROR_INTERNAL;
- }
-}
-
-
-//-------------------------------------------------
// load_image_by_path - loads an image with a
// specific path
//-------------------------------------------------
-image_error_t device_image_interface::load_image_by_path(u32 open_flags, std::string_view path)
+std::error_condition device_image_interface::load_image_by_path(u32 open_flags, std::string_view path)
{
std::string revised_path;
// attempt to read the file
- auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path);
- if (filerr != osd_file::error::NONE)
- return image_error_from_file_error(filerr);
+ auto filerr = util::zippath_fopen(path, open_flags, m_file, revised_path);
+ if (filerr)
+ {
+ osd_printf_verbose("%s: error opening image file %s with flags=%08X (%s:%d %s)\n", device().tag(), path, open_flags, filerr.category().name(), filerr.value(), filerr.message());
+ return filerr;
+ }
+ else
+ {
+ osd_printf_verbose("%s: opened image file %s with flags=%08X\n", device().tag(), path, open_flags);
+ }
m_readonly = (open_flags & OPEN_FLAG_WRITE) ? 0 : 1;
m_created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0;
set_image_filename(revised_path);
- return IMAGE_ERROR_SUCCESS;
+ return std::error_condition();
}
@@ -696,7 +679,7 @@ image_error_t device_image_interface::load_image_by_path(u32 open_flags, std::st
// reopen_for_write
//-------------------------------------------------
-int device_image_interface::reopen_for_write(std::string_view path)
+std::error_condition device_image_interface::reopen_for_write(std::string_view path)
{
m_file.reset();
@@ -704,15 +687,15 @@ int device_image_interface::reopen_for_write(std::string_view path)
// attempt to open the file for writing
auto const filerr = util::zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path);
- if (filerr != osd_file::error::NONE)
- return image_error_from_file_error(filerr);
+ if (filerr)
+ return filerr;
// success!
m_readonly = 0;
m_created = 1;
set_image_filename(revised_path);
- return IMAGE_ERROR_SUCCESS;
+ return std::error_condition();
}
@@ -823,19 +806,19 @@ bool device_image_interface::load_software(software_list_device &swlist, std::st
// try to load the file
m_mame_file.reset(new emu_file(device().machine().options().media_path(), searchpath, OPEN_FLAG_READ));
m_mame_file->set_restrict_to_mediapath(1);
- osd_file::error filerr;
+ std::error_condition filerr;
if (has_crc)
filerr = m_mame_file->open(romp->name(), crc);
else
filerr = m_mame_file->open(romp->name());
- if (filerr != osd_file::error::NONE)
+ if (filerr)
m_mame_file.reset();
warningcount += verify_length_and_hash(m_mame_file.get(), romp->name(), romp->get_length(), util::hash_collection(romp->hashdata()));
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
filerr = util::core_file::open_proxy(*m_mame_file, m_file);
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
retval = true;
break; // load first item for start
@@ -878,14 +861,14 @@ image_init_result device_image_interface::load_internal(std::string_view path, b
{
// open the file
m_err = load_image_by_path(*iter, path);
- if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND))
+ if (m_err && (m_err != std::errc::no_such_file_or_directory) && (m_err != std::errc::permission_denied))
goto done;
}
// did we fail to find the file?
if (!m_file)
{
- m_err = IMAGE_ERROR_FILENOTFOUND;
+ m_err = std::errc::no_such_file_or_directory;
goto done;
}
}
@@ -894,15 +877,17 @@ image_init_result device_image_interface::load_internal(std::string_view path, b
m_create_format = create_format;
m_create_args = create_args;
- if (init_phase()==false) {
- m_err = (finish_load() == image_init_result::PASS) ? IMAGE_ERROR_SUCCESS : IMAGE_ERROR_INTERNAL;
+ if (!init_phase())
+ {
+ m_err = (finish_load() == image_init_result::PASS) ? std::error_condition() : image_error::INTERNAL;
if (m_err)
goto done;
}
// success!
done:
- if (m_err!=0) {
+ if (m_err)
+ {
if (!init_phase())
{
if (device().machine().phase() == machine_phase::RUNNING)
@@ -1004,7 +989,7 @@ image_init_result device_image_interface::finish_load()
{
if (!image_checkhash())
{
- m_err = IMAGE_ERROR_INVALIDIMAGE;
+ m_err = image_error::INVALIDIMAGE;
err = image_init_result::FAIL;
}
@@ -1016,7 +1001,7 @@ image_init_result device_image_interface::finish_load()
if (err != image_init_result::PASS)
{
if (!m_err)
- m_err = IMAGE_ERROR_UNSPECIFIED;
+ m_err = image_error::UNSPECIFIED;
}
}
else
@@ -1026,7 +1011,7 @@ image_init_result device_image_interface::finish_load()
if (err != image_init_result::PASS)
{
if (!m_err)
- m_err = IMAGE_ERROR_UNSPECIFIED;
+ m_err = image_error::UNSPECIFIED;
}
}
}
@@ -1354,41 +1339,3 @@ bool device_image_interface::init_phase() const
return !device().has_running_machine()
|| device().machine().phase() == machine_phase::INIT;
}
-
-
-//----------------------------------------------------------------------------
-
-static int image_fseek_thunk(void *file, s64 offset, int whence)
-{
- device_image_interface *image = (device_image_interface *) file;
- return image->fseek(offset, whence);
-}
-
-static size_t image_fread_thunk(void *file, void *buffer, size_t length)
-{
- device_image_interface *image = (device_image_interface *) file;
- return image->fread(buffer, length);
-}
-
-static size_t image_fwrite_thunk(void *file, const void *buffer, size_t length)
-{
- device_image_interface *image = (device_image_interface *) file;
- return image->fwrite(buffer, length);
-}
-
-static u64 image_fsize_thunk(void *file)
-{
- device_image_interface *image = (device_image_interface *) file;
- return image->length();
-}
-
-//----------------------------------------------------------------------------
-
-struct io_procs image_ioprocs =
-{
- nullptr,
- image_fseek_thunk,
- image_fread_thunk,
- image_fwrite_thunk,
- image_fsize_thunk
-};
diff --git a/src/emu/diimage.h b/src/emu/diimage.h
index 507fd34e1d3..05f714f2647 100644
--- a/src/emu/diimage.h
+++ b/src/emu/diimage.h
@@ -19,6 +19,7 @@
#include <memory>
#include <string>
+#include <system_error>
#include <vector>
@@ -26,8 +27,6 @@
// TYPE DEFINITIONS
//**************************************************************************
-extern struct io_procs image_ioprocs;
-
enum iodevice_t
{
/* List of all supported devices. Refer to the device by these names only */
@@ -55,18 +54,19 @@ enum iodevice_t
IO_COUNT /* 21 - Total Number of IO_devices for searching */
};
-enum image_error_t
+enum class image_error : int
{
- IMAGE_ERROR_SUCCESS,
- IMAGE_ERROR_INTERNAL,
- IMAGE_ERROR_UNSUPPORTED,
- IMAGE_ERROR_OUTOFMEMORY,
- IMAGE_ERROR_FILENOTFOUND,
- IMAGE_ERROR_INVALIDIMAGE,
- IMAGE_ERROR_ALREADYOPEN,
- IMAGE_ERROR_UNSPECIFIED
+ INTERNAL = 1,
+ UNSUPPORTED,
+ INVALIDIMAGE,
+ ALREADYOPEN,
+ UNSPECIFIED
};
+const std::error_category &image_category() noexcept;
+inline std::error_condition make_error_condition(image_error e) noexcept { return std::error_condition(int(e), image_category()); }
+namespace std { template <> struct is_error_condition_enum<image_error> : public std::true_type { }; }
+
struct image_device_type_info
{
iodevice_t m_type;
@@ -150,7 +150,7 @@ public:
const util::option_guide &device_get_creation_option_guide() const { return create_option_guide(); }
std::string_view error();
- void seterror(image_error_t err, const char *message);
+ void seterror(std::error_condition err, const char *message);
void message(const char *format, ...) ATTR_PRINTF(2,3);
bool exists() const noexcept { return !m_image_name.empty(); }
@@ -172,7 +172,7 @@ public:
int fgetc() { char ch; if (fread(&ch, 1) != 1) ch = '\0'; return ch; }
char *fgets(char *buffer, u32 length) { check_for_file(); return m_file->gets(buffer, length); }
int image_feof() { check_for_file(); return m_file->eof(); }
- void *ptr() {check_for_file(); return const_cast<void *>(m_file->buffer()); }
+ void *ptr() { check_for_file(); return const_cast<void *>(m_file->buffer()); }
// configuration access
const software_info *software_entry() const noexcept;
@@ -217,7 +217,7 @@ public:
image_init_result create(std::string_view path, const image_device_format *create_format, util::option_resolution *create_args);
image_init_result create(std::string_view path);
bool load_software(software_list_device &swlist, std::string_view swname, const rom_entry *entry);
- int reopen_for_write(std::string_view path);
+ std::error_condition reopen_for_write(std::string_view path);
void set_user_loadable(bool user_loadable) { m_user_loadable = user_loadable; }
@@ -233,7 +233,7 @@ protected:
virtual const bool use_software_list_file_extension_for_filetype() const { return false; }
image_init_result load_internal(std::string_view path, bool is_create, int create_format, util::option_resolution *create_args);
- image_error_t load_image_by_path(u32 open_flags, std::string_view path);
+ std::error_condition load_image_by_path(u32 open_flags, std::string_view path);
void clear();
bool is_loaded() const { return m_file != nullptr; }
@@ -260,7 +260,7 @@ protected:
static const image_device_type_info m_device_info_array[];
// error related info
- image_error_t m_err;
+ std::error_condition m_err;
std::string m_err_message;
private:
@@ -277,7 +277,6 @@ private:
const software_part *m_software_part_ptr;
std::string m_software_list_name;
- static image_error_t image_error_from_file_error(osd_file::error filerr);
std::vector<u32> determine_open_plan(bool is_create);
void update_names();
bool load_software_part(std::string_view identifier);
diff --git a/src/emu/dimemory.h b/src/emu/dimemory.h
index f15a04166f4..119ec9bc6f9 100644
--- a/src/emu/dimemory.h
+++ b/src/emu/dimemory.h
@@ -50,11 +50,11 @@ constexpr int TRANSLATE_FETCH_DEBUG = (TRANSLATE_FETCH | TRANSLATE_DEBUG_MAS
class device_memory_interface : public device_interface
{
friend class device_scheduler;
- template <typename T, typename U> struct is_related_class { static constexpr bool value = std::is_convertible<std::add_pointer_t<T>, std::add_pointer_t<U> >::value; };
- template <typename T, typename U> struct is_related_device { static constexpr bool value = emu::detail::is_device_implementation<T>::value && is_related_class<T, U>::value; };
- template <typename T, typename U> struct is_related_interface { static constexpr bool value = emu::detail::is_device_interface<T>::value && is_related_class<T, U>::value; };
- template <typename T, typename U> struct is_unrelated_device { static constexpr bool value = emu::detail::is_device_implementation<T>::value && !is_related_class<T, U>::value; };
- template <typename T, typename U> struct is_unrelated_interface { static constexpr bool value = emu::detail::is_device_interface<T>::value && !is_related_class<T, U>::value; };
+ template <typename T, typename U> using is_related_class = std::bool_constant<std::is_convertible_v<std::add_pointer_t<T>, std::add_pointer_t<U> > >;
+ template <typename T, typename U> using is_related_device = std::bool_constant<emu::detail::is_device_implementation<T>::value && is_related_class<T, U>::value >;
+ template <typename T, typename U> using is_related_interface = std::bool_constant<emu::detail::is_device_interface<T>::value && is_related_class<T, U>::value >;
+ template <typename T, typename U> using is_unrelated_device = std::bool_constant<emu::detail::is_device_implementation<T>::value && !is_related_class<T, U>::value >;
+ template <typename T, typename U> using is_unrelated_interface = std::bool_constant<emu::detail::is_device_interface<T>::value && !is_related_class<T, U>::value >;
public:
// construction/destruction
diff --git a/src/emu/dipty.cpp b/src/emu/dipty.cpp
index 925113edd08..6a323d84e7f 100644
--- a/src/emu/dipty.cpp
+++ b/src/emu/dipty.cpp
@@ -27,7 +27,7 @@ bool device_pty_interface::open()
{
if (!m_opened)
{
- if (osd_file::openpty(m_pty_master, m_slave_name) == osd_file::error::NONE)
+ if (!osd_file::openpty(m_pty_master, m_slave_name))
{
m_opened = true;
}
@@ -54,7 +54,7 @@ bool device_pty_interface::is_open() const
ssize_t device_pty_interface::read(u8 *rx_chars , size_t count) const
{
u32 actual_bytes;
- if (m_opened && m_pty_master->read(rx_chars, 0, count, actual_bytes) == osd_file::error::NONE)
+ if (m_opened && !m_pty_master->read(rx_chars, 0, count, actual_bytes))
return actual_bytes;
else
return -1;
@@ -72,8 +72,3 @@ bool device_pty_interface::is_slave_connected() const
// TODO: really check for slave status
return m_opened;
}
-
-const char *device_pty_interface::slave_name() const
-{
- return m_slave_name.c_str();
-}
diff --git a/src/emu/dipty.h b/src/emu/dipty.h
index 790d4ec39b0..9fc1ddbc7e1 100644
--- a/src/emu/dipty.h
+++ b/src/emu/dipty.h
@@ -7,10 +7,14 @@
Device PTY interface
***************************************************************************/
-
#ifndef MAME_EMU_DIPTY_H
#define MAME_EMU_DIPTY_H
+#pragma once
+
+#include <string>
+
+
class device_pty_interface : public device_interface
{
public:
@@ -28,7 +32,7 @@ public:
bool is_slave_connected() const;
- const char *slave_name() const;
+ const std::string &slave_name() const { return m_slave_name; }
protected:
osd_file::ptr m_pty_master;
diff --git a/src/emu/fileio.cpp b/src/emu/fileio.cpp
index 293c23045b4..0fa41d3cd11 100644
--- a/src/emu/fileio.cpp
+++ b/src/emu/fileio.cpp
@@ -11,7 +11,8 @@
#include "emu.h"
#include "fileio.h"
-#include "unzip.h"
+#include "util/path.h"
+#include "util/unzip.h"
//#define VERBOSE 1
#define LOG_OUTPUT_FUNC osd_printf_verbose
@@ -121,12 +122,7 @@ bool path_iterator::next(std::string &buffer, const char *name)
// append the name if we have one
if (name)
- {
- // compute the full pathname
- if (!buffer.empty() && !util::is_directory_separator(buffer.back()))
- buffer.append(PATH_SEPARATOR);
- buffer.append(name);
- }
+ util::path_append(buffer, name);
// bump the index and return true
m_is_first = false;
@@ -298,7 +294,7 @@ util::hash_collection &emu_file::hashes(std::string_view types)
// open - open a file by searching paths
//-------------------------------------------------
-osd_file::error emu_file::open(std::string &&name)
+std::error_condition emu_file::open(std::string &&name)
{
// remember the filename and CRC info
m_filename = std::move(name);
@@ -310,7 +306,7 @@ osd_file::error emu_file::open(std::string &&name)
return open_next();
}
-osd_file::error emu_file::open(std::string &&name, u32 crc)
+std::error_condition emu_file::open(std::string &&name, u32 crc)
{
// remember the filename and CRC info
m_filename = std::move(name);
@@ -328,7 +324,7 @@ osd_file::error emu_file::open(std::string &&name, u32 crc)
// the filename by iterating over paths
//-------------------------------------------------
-osd_file::error emu_file::open_next()
+std::error_condition emu_file::open_next()
{
// if we're open from a previous attempt, close up now
if (m_file)
@@ -336,8 +332,8 @@ osd_file::error emu_file::open_next()
// loop over paths
LOG("emu_file: open next '%s'\n", m_filename);
- osd_file::error filerr = osd_file::error::NOT_FOUND;
- while (osd_file::error::NONE != filerr)
+ std::error_condition filerr = std::errc::no_such_file_or_directory;
+ while (filerr)
{
if (m_first)
{
@@ -385,7 +381,7 @@ osd_file::error emu_file::open_next()
filerr = util::core_file::open(m_fullpath, m_openflags, m_file);
// if we're opening for read-only we have other options
- if ((osd_file::error::NONE != filerr) && ((m_openflags & (OPEN_FLAG_READ | OPEN_FLAG_WRITE)) == OPEN_FLAG_READ))
+ if (filerr && ((m_openflags & (OPEN_FLAG_READ | OPEN_FLAG_WRITE)) == OPEN_FLAG_READ))
{
LOG("emu_file: attempting to open '%s' from archives\n", m_fullpath);
filerr = attempt_zipped();
@@ -400,7 +396,7 @@ osd_file::error emu_file::open_next()
// just an array of data in RAM
//-------------------------------------------------
-osd_file::error emu_file::open_ram(const void *data, u32 length)
+std::error_condition emu_file::open_ram(const void *data, u32 length)
{
// set a fake filename and CRC
m_filename = "RAM";
@@ -435,29 +431,14 @@ void emu_file::close()
//-------------------------------------------------
-// compress - enable/disable streaming file
-// compression via zlib; level is 0 to disable
-// compression, or up to 9 for max compression
-//-------------------------------------------------
-
-osd_file::error emu_file::compress(int level)
-{
- return m_file->compress(level);
-}
-
-
-//-------------------------------------------------
// compressed_file_ready - ensure our zip is ready
// loading if needed
//-------------------------------------------------
-bool emu_file::compressed_file_ready()
+std::error_condition emu_file::compressed_file_ready()
{
// load the ZIP file now if we haven't yet
- if (m_zipfile && (load_zipped_file() != osd_file::error::NONE))
- return true;
-
- return false;
+ return m_zipfile ? load_zipped_file() : std::error_condition();
}
//-------------------------------------------------
@@ -715,9 +696,9 @@ bool emu_file::part_of_mediapath(const std::string &path)
// attempt_zipped - attempt to open a ZIPped file
//-------------------------------------------------
-osd_file::error emu_file::attempt_zipped()
+std::error_condition emu_file::attempt_zipped()
{
- typedef util::archive_file::error (*open_func)(const std::string &filename, util::archive_file::ptr &result);
+ typedef std::error_condition (*open_func)(std::string_view filename, util::archive_file::ptr &result);
char const *const suffixes[] = { ".zip", ".7z" };
open_func const open_funcs[std::size(suffixes)] = { &util::archive_file::open_zip, &util::archive_file::open_7z };
@@ -750,13 +731,13 @@ osd_file::error emu_file::attempt_zipped()
// attempt to open the archive file
util::archive_file::ptr zip;
- util::archive_file::error ziperr = open_funcs[i](m_fullpath, zip);
+ std::error_condition ziperr = open_funcs[i](m_fullpath, zip);
// chop the archive suffix back off the filename before continuing
m_fullpath = m_fullpath.substr(0, dirsep);
// if we failed to open this file, continue scanning
- if (ziperr != util::archive_file::error::NONE)
+ if (ziperr)
continue;
int header = -1;
@@ -788,14 +769,14 @@ osd_file::error emu_file::attempt_zipped()
m_hashes.reset();
m_hashes.add_crc(m_zipfile->current_crc());
m_fullpath = savepath;
- return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? osd_file::error::NONE : load_zipped_file();
+ return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? std::error_condition() : load_zipped_file();
}
// close up the archive file and try the next level
zip.reset();
}
}
- return osd_file::error::NOT_FOUND;
+ return std::errc::no_such_file_or_directory;
}
@@ -803,7 +784,7 @@ osd_file::error emu_file::attempt_zipped()
// load_zipped_file - load a ZIPped file
//-------------------------------------------------
-osd_file::error emu_file::load_zipped_file()
+std::error_condition emu_file::load_zipped_file()
{
assert(m_file == nullptr);
assert(m_zipdata.empty());
@@ -814,21 +795,21 @@ osd_file::error emu_file::load_zipped_file()
// read the data into our buffer and return
auto const ziperr = m_zipfile->decompress(&m_zipdata[0], m_zipdata.size());
- if (ziperr != util::archive_file::error::NONE)
+ if (ziperr)
{
m_zipdata.clear();
- return osd_file::error::FAILURE;
+ return ziperr;
}
// convert to RAM file
- osd_file::error filerr = util::core_file::open_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, m_file);
- if (filerr != osd_file::error::NONE)
+ std::error_condition const filerr = util::core_file::open_ram(&m_zipdata[0], m_zipdata.size(), m_openflags, m_file);
+ if (filerr)
{
m_zipdata.clear();
- return osd_file::error::FAILURE;
+ return filerr;
}
// close out the ZIP file
m_zipfile.reset();
- return osd_file::error::NONE;
+ return std::error_condition();
}
diff --git a/src/emu/fileio.h b/src/emu/fileio.h
index d05905efa83..f05706dffed 100644
--- a/src/emu/fileio.h
+++ b/src/emu/fileio.h
@@ -18,6 +18,7 @@
#include <iterator>
#include <string>
+#include <system_error>
#include <type_traits>
#include <utility>
#include <vector>
@@ -156,19 +157,16 @@ public:
void set_restrict_to_mediapath(int rtmp) { m_restrict_to_mediapath = rtmp; }
// open/close
- osd_file::error open(std::string &&name);
- osd_file::error open(std::string &&name, u32 crc);
- osd_file::error open(std::string_view name) { return open(std::string(name)); }
- osd_file::error open(std::string_view name, u32 crc) { return open(std::string(name), crc); }
- osd_file::error open(const char *name) { return open(std::string(name)); }
- osd_file::error open(const char *name, u32 crc) { return open(std::string(name), crc); }
- osd_file::error open_next();
- osd_file::error open_ram(const void *data, u32 length);
+ std::error_condition open(std::string &&name);
+ std::error_condition open(std::string &&name, u32 crc);
+ std::error_condition open(std::string_view name) { return open(std::string(name)); }
+ std::error_condition open(std::string_view name, u32 crc) { return open(std::string(name), crc); }
+ std::error_condition open(const char *name) { return open(std::string(name)); }
+ std::error_condition open(const char *name, u32 crc) { return open(std::string(name), crc); }
+ std::error_condition open_next();
+ std::error_condition open_ram(const void *data, u32 length);
void close();
- // control
- osd_file::error compress(int compress);
-
// position
int seek(s64 offset, int whence);
u64 tell();
@@ -213,11 +211,11 @@ private:
}
bool part_of_mediapath(const std::string &path);
- bool compressed_file_ready();
+ std::error_condition compressed_file_ready();
// internal helpers
- osd_file::error attempt_zipped();
- osd_file::error load_zipped_file();
+ std::error_condition attempt_zipped();
+ std::error_condition load_zipped_file();
// internal state
std::string m_filename; // original filename provided
diff --git a/src/emu/hashfile.cpp b/src/emu/hashfile.cpp
index 50a32a60b29..a6107e5e630 100644
--- a/src/emu/hashfile.cpp
+++ b/src/emu/hashfile.cpp
@@ -27,10 +27,8 @@ static bool read_hash_config(const char *hash_path, const util::hash_collection
{
/* open a file */
emu_file file(hash_path, OPEN_FLAG_READ);
- if (file.open(std::string(sysname) + ".hsi") != osd_file::error::NONE)
- {
+ if (file.open(std::string(sysname) + ".hsi"))
return false;
- }
pugi::xml_document doc;
diff --git a/src/emu/http.cpp b/src/emu/http.cpp
index b384049a37f..42d8120d32e 100644
--- a/src/emu/http.cpp
+++ b/src/emu/http.cpp
@@ -422,8 +422,8 @@ bool http_manager::read_file(std::ostream &os, const std::string &path) {
std::ostringstream full_path;
full_path << m_root << path;
util::core_file::ptr f;
- osd_file::error e = util::core_file::open(full_path.str(), OPEN_FLAG_READ, f);
- if (e == osd_file::error::NONE)
+ std::error_condition const e = util::core_file::open(full_path.str(), OPEN_FLAG_READ, f);
+ if (!e)
{
int c;
while ((c = f->getc()) >= 0)
@@ -431,7 +431,7 @@ bool http_manager::read_file(std::ostream &os, const std::string &path) {
os.put(c);
}
}
- return e == osd_file::error::NONE;
+ return !e;
}
void http_manager::serve_document(http_request_ptr request, http_response_ptr response, const std::string &filename) {
diff --git a/src/emu/image.cpp b/src/emu/image.cpp
index c80d9bafde7..02cc25ce80b 100644
--- a/src/emu/image.cpp
+++ b/src/emu/image.cpp
@@ -173,8 +173,8 @@ int image_manager::write_config(emu_options &options, const char *filename, cons
}
emu_file file(options.ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE);
- osd_file::error filerr = file.open(filename);
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = file.open(filename);
+ if (!filerr)
{
std::string inistring = options.output_ini();
file.puts(inistring);
diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp
index 2e9d115e46e..cae37f28c17 100644
--- a/src/emu/ioport.cpp
+++ b/src/emu/ioport.cpp
@@ -99,9 +99,11 @@
#include "inputdev.h"
#include "natkeyboard.h"
-#include "corestr.h"
+#include "util/corestr.h"
+#include "util/ioprocsfilter.h"
+#include "util/unicode.h"
+
#include "osdepend.h"
-#include "unicode.h"
#include <cctype>
#include <ctime>
@@ -2652,23 +2654,26 @@ template<typename Type>
Type ioport_manager::playback_read(Type &result)
{
// protect against nullptr handles if previous reads fail
- if (!m_playback_file.is_open())
- result = 0;
+ if (!m_playback_stream)
+ return result = Type(0);
// read the value; if we fail, end playback
- else if (m_playback_file.read(&result, sizeof(result)) != sizeof(result))
+ size_t read;
+ m_playback_stream->read(&result, sizeof(result), read);
+ if (sizeof(result) != read)
{
playback_end("End of file");
- result = 0;
+ return result = Type(0);
}
- // return the appropriate value
- else if (sizeof(result) == 8)
+ // normalize byte order
+ if (sizeof(result) == 8)
result = little_endianize_int64(result);
else if (sizeof(result) == 4)
result = little_endianize_int32(result);
else if (sizeof(result) == 2)
result = little_endianize_int16(result);
+
return result;
}
@@ -2693,15 +2698,15 @@ time_t ioport_manager::playback_init()
return 0;
// open the playback file
- osd_file::error filerr = m_playback_file.open(filename);
+ std::error_condition const filerr = m_playback_file.open(filename);
// return an explicit error if file isn't found in given path
- if(filerr == osd_file::error::NOT_FOUND)
+ if (filerr == std::errc::no_such_file_or_directory)
fatalerror("Input file %s not found\n",filename);
// TODO: bail out any other error laconically for now
- if(filerr != osd_file::error::NONE)
- fatalerror("Failed to open file %s for playback (code error=%d)\n",filename,int(filerr));
+ if (filerr)
+ fatalerror("Failed to open file %s for playback (%s:%d %s)\n", filename, filerr.category().name(), filerr.value(), filerr.message());
// read the header and verify that it is a modern version; if not, print an error
inp_header header;
@@ -2725,7 +2730,7 @@ time_t ioport_manager::playback_init()
osd_printf_info("Input file is for machine '%s', not for current machine '%s'\n", sysname, machine().system().name);
// enable compression
- m_playback_file.compress(FCOMPRESS_MEDIUM);
+ m_playback_stream = util::zlib_read(util::core_file_read(m_playback_file), 16386);
return basetime;
}
@@ -2737,9 +2742,10 @@ time_t ioport_manager::playback_init()
void ioport_manager::playback_end(const char *message)
{
// only applies if we have a live file
- if (m_playback_file.is_open())
+ if (m_playback_stream)
{
// close the file
+ m_playback_stream.reset();
m_playback_file.close();
// pop a message
@@ -2753,7 +2759,8 @@ void ioport_manager::playback_end(const char *message)
osd_printf_info("Average recorded speed: %d%%\n", u32((m_playback_accumulated_speed * 200 + 1) >> 21));
// close the program at the end of inp file playback
- if (machine().options().exit_after_playback()) {
+ if (machine().options().exit_after_playback())
+ {
osd_printf_info("Exiting MAME now...\n");
machine().schedule_exit();
}
@@ -2769,7 +2776,7 @@ void ioport_manager::playback_end(const char *message)
void ioport_manager::playback_frame(const attotime &curtime)
{
// if playing back, fetch the information and verify
- if (m_playback_file.is_open())
+ if (m_playback_stream)
{
// first the absolute time
seconds_t seconds_temp;
@@ -2795,7 +2802,7 @@ void ioport_manager::playback_frame(const attotime &curtime)
void ioport_manager::playback_port(ioport_port &port)
{
// if playing back, fetch information about this port
- if (m_playback_file.is_open())
+ if (m_playback_stream)
{
// read the default value and the digital state
playback_read(port.live().defvalue);
@@ -2824,11 +2831,20 @@ template<typename Type>
void ioport_manager::record_write(Type value)
{
// protect against nullptr handles if previous reads fail
- if (!m_record_file.is_open())
+ if (!m_record_stream)
return;
- // read the value; if we fail, end playback
- if (m_record_file.write(&value, sizeof(value)) != sizeof(value))
+ // normalize byte order
+ if (sizeof(value) == 8)
+ value = little_endianize_int64(value);
+ else if (sizeof(value) == 4)
+ value = little_endianize_int32(value);
+ else if (sizeof(value) == 2)
+ value = little_endianize_int16(value);
+
+ // write the value; if we fail, end recording
+ size_t written;
+ if (m_record_stream->write(&value, sizeof(value), written) || (sizeof(value) != written))
record_end("Out of space");
}
@@ -2875,9 +2891,9 @@ void ioport_manager::record_init()
return;
// open the record file
- osd_file::error filerr = m_record_file.open(filename);
- if (filerr != osd_file::error::NONE)
- throw emu_fatalerror("ioport_manager::record_init: Failed to open file for recording");
+ std::error_condition const filerr = m_record_file.open(filename);
+ if (filerr)
+ throw emu_fatalerror("ioport_manager::record_init: Failed to open file for recording (%s:%d %s)", filerr.category().name(), filerr.value(), filerr.message());
// get the base time
system_time systime;
@@ -2895,7 +2911,7 @@ void ioport_manager::record_init()
header.write(m_record_file);
// enable compression
- m_record_file.compress(FCOMPRESS_MEDIUM);
+ m_record_stream = util::zlib_write(util::core_file_read_write(m_record_file), 6, 16384);
}
@@ -2922,9 +2938,9 @@ void ioport_manager::timecode_init()
filename.append(record_filename).append(".timecode");
osd_printf_info("Record input timecode file: %s\n", record_filename);
- osd_file::error filerr = m_timecode_file.open(filename);
- if (filerr != osd_file::error::NONE)
- throw emu_fatalerror("ioport_manager::timecode_init: Failed to open file for input timecode recording");
+ std::error_condition const filerr = m_timecode_file.open(filename);
+ if (filerr)
+ throw emu_fatalerror("ioport_manager::timecode_init: Failed to open file for input timecode recording (%s:%d %s)", filerr.category().name(), filerr.value(), filerr.message());
m_timecode_file.puts("# ==========================================\n");
m_timecode_file.puts("# TIMECODE FILE FOR VIDEO PREVIEW GENERATION\n");
@@ -2948,9 +2964,10 @@ void ioport_manager::timecode_init()
void ioport_manager::record_end(const char *message)
{
// only applies if we have a live file
- if (m_record_file.is_open())
+ if (m_record_stream)
{
// close the file
+ m_record_stream.reset(); // TODO: check for errors flushing the last compressed block before doing this
m_record_file.close();
// pop a message
@@ -2981,7 +2998,7 @@ void ioport_manager::timecode_end(const char *message)
void ioport_manager::record_frame(const attotime &curtime)
{
// if recording, record information about the current frame
- if (m_record_file.is_open())
+ if (m_record_stream)
{
// first the absolute time
record_write(curtime.seconds());
@@ -3091,7 +3108,7 @@ void ioport_manager::record_frame(const attotime &curtime)
void ioport_manager::record_port(ioport_port &port)
{
// if recording, store information about this port
- if (m_record_file.is_open())
+ if (m_record_stream)
{
// store the default value and digital state
record_write(port.live().defvalue);
diff --git a/src/emu/ioport.h b/src/emu/ioport.h
index 11dcf006be9..fdf859b9afd 100644
--- a/src/emu/ioport.h
+++ b/src/emu/ioport.h
@@ -17,11 +17,14 @@
#ifndef MAME_EMU_IOPORT_H
#define MAME_EMU_IOPORT_H
+#include "ioprocs.h"
+
#include <array>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <list>
+#include <memory>
#include <vector>
@@ -1447,8 +1450,10 @@ private:
attoseconds_t m_last_delta_nsec; // nanoseconds that passed since the previous callback
// playback/record information
- emu_file m_record_file; // recording file (nullptr if not recording)
- emu_file m_playback_file; // playback file (nullptr if not recording)
+ emu_file m_record_file; // recording file (closed if not recording)
+ emu_file m_playback_file; // playback file (closed if not recording)
+ util::write_stream::ptr m_record_stream; // recording stream (nullptr if not recording)
+ util::read_stream::ptr m_playback_stream; // playback stream (nullptr if not recording)
u64 m_playback_accumulated_speed; // accumulated speed during playback
u32 m_playback_accumulated_frames; // accumulated frames during playback
emu_file m_timecode_file; // timecode/frames playback file (nullptr if not recording)
diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp
index 5568bb48e85..3721ba9bec8 100644
--- a/src/emu/machine.cpp
+++ b/src/emu/machine.cpp
@@ -313,8 +313,8 @@ int running_machine::run(bool quiet)
if (options().log() && !quiet)
{
m_logfile = std::make_unique<emu_file>(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = m_logfile->open("error.log");
- if (filerr != osd_file::error::NONE)
+ std::error_condition const filerr = m_logfile->open("error.log");
+ if (filerr)
throw emu_fatalerror("running_machine::run: unable to open error.log file");
using namespace std::placeholders;
@@ -324,8 +324,8 @@ int running_machine::run(bool quiet)
if (options().debug() && options().debuglog())
{
m_debuglogfile = std::make_unique<emu_file>(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = m_debuglogfile->open("debug.log");
- if (filerr != osd_file::error::NONE)
+ std::error_condition const filerr = m_debuglogfile->open("debug.log");
+ if (filerr)
throw emu_fatalerror("running_machine::run: unable to open debug.log file");
}
@@ -931,7 +931,7 @@ void running_machine::handle_saveload()
// open the file
emu_file file(m_saveload_searchpath ? m_saveload_searchpath : "", openflags);
auto const filerr = file.open(m_saveload_pending_file);
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
{
const char *const opnamed = (m_saveload_schedule == saveload_schedule::LOAD) ? "loaded" : "saved";
@@ -973,7 +973,7 @@ void running_machine::handle_saveload()
if (saverr != STATERR_NONE && m_saveload_schedule == saveload_schedule::SAVE)
file.remove_on_close();
}
- else if (openflags == OPEN_FLAG_READ && filerr == osd_file::error::NOT_FOUND)
+ else if ((openflags == OPEN_FLAG_READ) && (std::errc::no_such_file_or_directory == filerr))
{
// attempt to load a non-existent savestate, report empty slot
popmessage("Error: No savestate file to load.", opname);
@@ -1174,7 +1174,7 @@ void running_machine::nvram_load()
for (device_nvram_interface &nvram : nvram_interface_enumerator(root_device()))
{
emu_file file(options().nvram_directory(), OPEN_FLAG_READ);
- if (file.open(nvram_filename(nvram.device())) == osd_file::error::NONE)
+ if (!file.open(nvram_filename(nvram.device())))
{
nvram.nvram_load(file);
file.close();
@@ -1196,7 +1196,7 @@ void running_machine::nvram_save()
if (nvram.nvram_can_save())
{
emu_file file(options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- if (file.open(nvram_filename(nvram.device())) == osd_file::error::NONE)
+ if (!file.open(nvram_filename(nvram.device())))
{
nvram.nvram_save(file);
file.close();
diff --git a/src/emu/render.cpp b/src/emu/render.cpp
index 1c176929aad..2c4541cb6b9 100644
--- a/src/emu/render.cpp
+++ b/src/emu/render.cpp
@@ -50,7 +50,8 @@
#include "ui/uimain.h"
-#include "xmlfile.h"
+#include "util/path.h"
+#include "util/xmlfile.h"
#include <zlib.h>
@@ -2186,7 +2187,7 @@ bool render_target::load_layout_file(const char *dirname, const char *filename)
emu_file layoutfile(m_manager.machine().options().art_path(), OPEN_FLAG_READ);
layoutfile.set_restrict_to_mediapath(1);
bool result(false);
- for (osd_file::error filerr = layoutfile.open(fname); osd_file::error::NONE == filerr; filerr = layoutfile.open_next())
+ for (std::error_condition filerr = layoutfile.open(fname); !filerr; filerr = layoutfile.open_next())
{
// read the file and parse as XML
util::xml::file::ptr const rootnode(util::xml::file::read(layoutfile, &parseopt));
diff --git a/src/emu/rendfont.cpp b/src/emu/rendfont.cpp
index c20a7979bbc..ae295e39e2d 100644
--- a/src/emu/rendfont.cpp
+++ b/src/emu/rendfont.cpp
@@ -594,8 +594,8 @@ render_font::render_font(render_manager &manager, const char *filename)
// load the compiled in data instead
emu_file ramfile(OPEN_FLAG_READ);
- osd_file::error const filerr(ramfile.open_ram(font_uismall, sizeof(font_uismall)));
- if (osd_file::error::NONE == filerr)
+ std::error_condition const filerr(ramfile.open_ram(font_uismall, sizeof(font_uismall)));
+ if (!filerr)
load_cached(ramfile, 0, 0);
render_font_command_glyph();
}
@@ -908,14 +908,14 @@ float render_font::utf8string_width(float height, float aspect, std::string_view
bool render_font::load_cached_bdf(const char *filename)
{
- osd_file::error filerr;
+ std::error_condition filerr;
u32 chunk;
u64 bytes;
// first try to open the BDF itself
emu_file file(m_manager.machine().options().font_path(), OPEN_FLAG_READ);
filerr = file.open(filename);
- if (filerr != osd_file::error::NONE)
+ if (filerr)
return false;
// determine the file size and allocate memory
@@ -952,7 +952,7 @@ bool render_font::load_cached_bdf(const char *filename)
{
emu_file cachefile(m_manager.machine().options().font_path(), OPEN_FLAG_READ);
filerr = cachefile.open(cachedname);
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
{
// if we have a cached version, load it
bool const result = load_cached(cachefile, m_rawsize, hash);
@@ -1456,8 +1456,8 @@ bool render_font::save_cached(const char *filename, u64 length, u32 hash)
// attempt to open the file
emu_file file(m_manager.machine().options().font_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE);
- osd_file::error const filerr = file.open(filename);
- if (osd_file::error::NONE != filerr)
+ std::error_condition const filerr = file.open(filename);
+ if (filerr)
return false;
// count glyphs
@@ -1596,7 +1596,7 @@ void render_font::render_font_command_glyph()
{
// FIXME: this is copy/pasta from the BDC loading, and it shouldn't be injected into every font
emu_file file(OPEN_FLAG_READ);
- if (file.open_ram(font_uicmd14, sizeof(font_uicmd14)) == osd_file::error::NONE)
+ if (!file.open_ram(font_uicmd14, sizeof(font_uicmd14)))
{
// get the file size, read the header, and check that it looks good
u64 const filesize(file.size());
diff --git a/src/emu/rendlay.cpp b/src/emu/rendlay.cpp
index 13b2d6e16c1..c3f7a70a2e8 100644
--- a/src/emu/rendlay.cpp
+++ b/src/emu/rendlay.cpp
@@ -17,10 +17,11 @@
#include "rendutil.h"
#include "video/rgbutil.h"
-#include "nanosvg.h"
-#include "unicode.h"
-#include "vecstream.h"
-#include "xmlfile.h"
+#include "util/nanosvg.h"
+#include "util/path.h"
+#include "util/unicode.h"
+#include "util/vecstream.h"
+#include "util/xmlfile.h"
#include <cctype>
#include <algorithm>
@@ -1713,12 +1714,10 @@ private:
std::string filename;
if (!m_searchpath.empty())
filename = m_dirname;
- if (!filename.empty() && !util::is_directory_separator(filename[filename.size() - 1]))
- filename.append(PATH_SEPARATOR);
- filename.append(m_imagefile);
+ util::path_append(filename, m_imagefile);
LOGMASKED(LOG_IMAGE_LOAD, "Image component attempt to load image file '%s'\n", filename);
- osd_file::error const imgerr = file.open(filename);
- if (osd_file::error::NONE == imgerr)
+ std::error_condition const imgerr = file.open(filename);
+ if (!imgerr)
{
if (!load_bitmap(file))
{
@@ -1729,7 +1728,8 @@ private:
}
else
{
- LOGMASKED(LOG_IMAGE_LOAD, "Image component unable to open image file '%s'\n", filename);
+ LOGMASKED(LOG_IMAGE_LOAD, "Image component unable to open image file '%s' (%s:%d %s)\n",
+ filename, imgerr.category().name(), imgerr.value(), imgerr.message());
}
}
else if (!m_data.empty())
@@ -1745,12 +1745,10 @@ private:
std::string filename;
if (!m_searchpath.empty())
filename = m_dirname;
- if (!filename.empty() && !util::is_directory_separator(filename[filename.size() - 1]))
- filename.append(PATH_SEPARATOR);
- filename.append(m_alphafile);
+ util::path_append(filename, m_alphafile);
LOGMASKED(LOG_IMAGE_LOAD, "Image component attempt to load alpha channel from file '%s'\n", filename);
- osd_file::error const alferr = file.open(filename);
- if (osd_file::error::NONE == alferr)
+ std::error_condition const alferr = file.open(filename);
+ if (!alferr)
{
// TODO: no way to detect corner case where we had alpha from the image but the alpha PNG makes it entirely opaque
if (render_load_png(m_bitmap, file, true))
@@ -1759,7 +1757,8 @@ private:
}
else
{
- LOGMASKED(LOG_IMAGE_LOAD, "Image component unable to open alpha channel file '%s'\n", filename);
+ LOGMASKED(LOG_IMAGE_LOAD, "Image component unable to open alpha channel file '%s' (%s:%d %s)\n",
+ filename, alferr.category().name(), alferr.value(), alferr.message());
}
}
else if (m_svg)
@@ -1841,8 +1840,8 @@ private:
// make a file wrapper for the data and see if it looks like a bitmap
util::core_file::ptr file;
- osd_file::error const filerr(util::core_file::open_ram(m_data.c_str(), m_data.size(), OPEN_FLAG_READ, file));
- bool const bitmapdata((osd_file::error::NONE == filerr) && file && load_bitmap(*file));
+ std::error_condition const filerr(util::core_file::open_ram(m_data.c_str(), m_data.size(), OPEN_FLAG_READ, file));
+ bool const bitmapdata(!filerr && file && load_bitmap(*file));
file.reset();
// if it didn't look like a bitmap, see if it looks like it might be XML and hence SVG
@@ -3398,12 +3397,10 @@ private:
std::string filename;
if (!m_searchpath.empty())
filename = m_dirname;
- if (!filename.empty() && !util::is_directory_separator(filename[filename.size() - 1]))
- filename.append(PATH_SEPARATOR);
- filename.append(m_imagefile[number]);
+ util::path_append(filename, m_imagefile[number]);
// load the basic bitmap
- if (file.open(filename) == osd_file::error::NONE)
+ if (!file.open(filename))
render_load_png(m_bitmap[number], file);
// if we can't load the bitmap just use text rendering
diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp
index 36d7896e467..c4c3101bc89 100644
--- a/src/emu/romload.cpp
+++ b/src/emu/romload.cpp
@@ -101,15 +101,15 @@ std::vector<std::string> make_software_searchpath(software_list_device &swlist,
}
-chd_error do_open_disk(const emu_options &options, std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, chd_file &chd, std::function<const rom_entry * ()> next_parent)
+std::error_condition do_open_disk(const emu_options &options, std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, chd_file &chd, std::function<const rom_entry * ()> next_parent)
{
// hashes are fixed, but we might need to try multiple filenames
std::set<std::string> tried;
const util::hash_collection hashes(romp->hashdata());
std::string filename, fullpath;
const rom_entry *parent(nullptr);
- chd_error result(CHDERR_FILE_NOT_FOUND);
- while (romp && (CHDERR_NONE != result))
+ std::error_condition result(std::errc::no_such_file_or_directory);
+ while (romp && result)
{
filename = romp->name() + ".chd";
if (tried.insert(filename).second)
@@ -120,8 +120,8 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re
{
imgfile.reset(new emu_file(options.media_path(), paths, OPEN_FLAG_READ));
imgfile->set_restrict_to_mediapath(1);
- const osd_file::error filerr(imgfile->open(filename, OPEN_FLAG_READ));
- if (osd_file::error::NONE == filerr)
+ const std::error_condition filerr(imgfile->open(filename, OPEN_FLAG_READ));
+ if (!filerr)
break;
else
imgfile.reset();
@@ -132,12 +132,12 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re
{
fullpath = imgfile->fullpath();
imgfile.reset();
- result = chd.open(fullpath.c_str());
+ result = chd.open(fullpath);
}
}
// walk the parents looking for a CHD with the same hashes but a different name
- if (CHDERR_NONE != result)
+ if (result)
{
while (romp)
{
@@ -345,11 +345,11 @@ chd_file *rom_load_manager::get_disk_handle(std::string_view region)
file associated with the given region
-------------------------------------------------*/
-int rom_load_manager::set_disk_handle(std::string_view region, const char *fullpath)
+std::error_condition rom_load_manager::set_disk_handle(std::string_view region, const char *fullpath)
{
auto chd = std::make_unique<open_chd>(region);
auto err = chd->orig_chd().open(fullpath);
- if (err == CHDERR_NONE)
+ if (!err)
m_chd_list.push_back(std::move(chd));
return err;
}
@@ -439,7 +439,7 @@ void rom_load_manager::fill_random(u8 *base, u32 length)
for missing files
-------------------------------------------------*/
-void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, chd_error chderr)
+void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, std::error_condition chderr)
{
std::string tried;
if (!tried_file_names.empty())
@@ -453,12 +453,12 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec
tried += ')';
}
- const bool is_chd(chderr != CHDERR_NONE);
+ const bool is_chd(chderr);
const std::string name(is_chd ? romp->name() + ".chd" : romp->name());
- const bool is_chd_error(is_chd && chderr != CHDERR_FILE_NOT_FOUND);
+ const bool is_chd_error(is_chd && chderr != std::errc::no_such_file_or_directory);
if (is_chd_error)
- m_errorstring.append(string_format("%s CHD ERROR: %s\n", name, chd_file::error_string(chderr)));
+ m_errorstring.append(string_format("%s CHD ERROR: %s\n", name, chderr.message()));
if (ROM_ISOPTIONAL(romp))
{
@@ -638,7 +638,7 @@ void rom_load_manager::region_post_process(memory_region *region, bool invert)
std::unique_ptr<emu_file> rom_load_manager::open_rom_file(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, std::vector<std::string> &tried_file_names, bool from_list)
{
- osd_file::error filerr = osd_file::error::NOT_FOUND;
+ std::error_condition filerr = std::errc::no_such_file_or_directory;
u32 const romsize = rom_file_size(romp);
tried_file_names.clear();
@@ -664,14 +664,14 @@ std::unique_ptr<emu_file> rom_load_manager::open_rom_file(std::initializer_list<
m_romsloadedsize += romsize;
// return the result
- if (osd_file::error::NONE != filerr)
+ if (filerr)
return nullptr;
else
return result;
}
-std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, std::string_view name, osd_file::error &filerr)
+std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, std::string_view name, std::error_condition &filerr)
{
// record the set names we search
tried.insert(tried.end(), paths.begin(), paths.end());
@@ -685,7 +685,7 @@ std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std:
filerr = result->open(name);
// don't return anything if unsuccessful
- if (osd_file::error::NONE != filerr)
+ if (filerr)
return nullptr;
else
return result;
@@ -939,7 +939,7 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_
{
file = open_rom_file(searchpath, romp, tried_file_names, from_list);
if (!file)
- handle_missing_file(romp, tried_file_names, CHDERR_NONE);
+ handle_missing_file(romp, tried_file_names, std::error_condition());
}
// loop until we run out of reloads
@@ -1000,44 +1000,44 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_
open_disk_diff - open a DISK diff file
-------------------------------------------------*/
-chd_error rom_load_manager::open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd)
+std::error_condition rom_load_manager::open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd)
{
// TODO: use system name and/or software list name in the path - the current setup doesn't scale
std::string fname = romp->name() + ".dif";
- /* try to open the diff */
+ // try to open the diff
LOG("Opening differencing image file: %s\n", fname.c_str());
emu_file diff_file(options.diff_directory(), OPEN_FLAG_READ | OPEN_FLAG_WRITE);
- osd_file::error filerr = diff_file.open(fname);
- if (filerr == osd_file::error::NONE)
+ std::error_condition filerr = diff_file.open(fname);
+ if (!filerr)
{
std::string fullpath(diff_file.fullpath());
diff_file.close();
LOG("Opening differencing image file: %s\n", fullpath.c_str());
- return diff_chd.open(fullpath.c_str(), true, &source);
+ return diff_chd.open(fullpath, true, &source);
}
- /* didn't work; try creating it instead */
+ // didn't work; try creating it instead
LOG("Creating differencing image: %s\n", fname.c_str());
diff_file.set_openflags(OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
filerr = diff_file.open(fname);
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
{
std::string fullpath(diff_file.fullpath());
diff_file.close();
- /* create the CHD */
+ // create the CHD
LOG("Creating differencing image file: %s\n", fullpath.c_str());
chd_codec_type compression[4] = { CHD_CODEC_NONE };
- chd_error err = diff_chd.create(fullpath.c_str(), source.logical_bytes(), source.hunk_bytes(), compression, source);
- if (err != CHDERR_NONE)
+ std::error_condition err = diff_chd.create(fullpath, source.logical_bytes(), source.hunk_bytes(), compression, source);
+ if (err)
return err;
return diff_chd.clone_all_metadata(source);
}
- return CHDERR_FILE_NOT_FOUND;
+ return std::errc::no_such_file_or_directory;
}
@@ -1059,7 +1059,7 @@ void rom_load_manager::process_disk_entries(std::initializer_list<std::reference
if (ROMENTRY_ISFILE(romp))
{
auto chd = std::make_unique<open_chd>(regiontag);
- chd_error err;
+ std::error_condition err;
/* make the filename of the source */
const std::string filename = romp->name() + ".chd";
@@ -1068,7 +1068,7 @@ void rom_load_manager::process_disk_entries(std::initializer_list<std::reference
// FIXME: we've lost the ability to search parents here
LOG("Opening disk image: %s\n", filename.c_str());
err = do_open_disk(machine().options(), searchpath, romp, chd->orig_chd(), next_parent);
- if (err != CHDERR_NONE)
+ if (err)
{
handle_missing_file(romp, std::vector<std::string>(), err);
chd = nullptr;
@@ -1098,9 +1098,9 @@ void rom_load_manager::process_disk_entries(std::initializer_list<std::reference
{
/* try to open or create the diff */
err = open_disk_diff(machine().options(), romp, chd->orig_chd(), chd->diff_chd());
- if (err != CHDERR_NONE)
+ if (err)
{
- m_errorstring.append(string_format("%s DIFF CHD ERROR: %s\n", filename, chd_file::error_string(err)));
+ m_errorstring.append(string_format("%s DIFF CHD ERROR: %s\n", filename, err.message()));
m_errors++;
chd = nullptr;
continue;
@@ -1132,7 +1132,7 @@ std::vector<std::string> rom_load_manager::get_software_searchpath(software_list
device
-------------------------------------------------*/
-chd_error rom_load_manager::open_disk_image(const emu_options &options, const device_t &device, const rom_entry *romp, chd_file &image_chd)
+std::error_condition rom_load_manager::open_disk_image(const emu_options &options, const device_t &device, const rom_entry *romp, chd_file &image_chd)
{
const std::vector<std::string> searchpath(device.searchpath());
@@ -1151,7 +1151,7 @@ chd_error rom_load_manager::open_disk_image(const emu_options &options, const de
software item
-------------------------------------------------*/
-chd_error rom_load_manager::open_disk_image(const emu_options &options, software_list_device &swlist, const software_info &swinfo, const rom_entry *romp, chd_file &image_chd)
+std::error_condition rom_load_manager::open_disk_image(const emu_options &options, software_list_device &swlist, const software_info &swinfo, const rom_entry *romp, chd_file &image_chd)
{
std::vector<software_info const *> parents;
std::vector<std::string> searchpath = make_software_searchpath(swlist, swinfo, parents);
diff --git a/src/emu/romload.h b/src/emu/romload.h
index 29caaf8e124..76fdb111cc6 100644
--- a/src/emu/romload.h
+++ b/src/emu/romload.h
@@ -18,6 +18,7 @@
#include <functional>
#include <initializer_list>
#include <string>
+#include <system_error>
#include <type_traits>
#include <vector>
@@ -419,7 +420,7 @@ public:
chd_file *get_disk_handle(std::string_view region);
/* set a pointer to the CHD file associated with the given region */
- int set_disk_handle(std::string_view region, const char *fullpath);
+ std::error_condition set_disk_handle(std::string_view region, const char *fullpath);
void load_software_part_region(device_t &device, software_list_device &swlist, std::string_view swname, const rom_entry *start_region);
@@ -427,27 +428,27 @@ public:
static std::vector<std::string> get_software_searchpath(software_list_device &swlist, const software_info &swinfo);
/* open a disk image, searching up the parent and loading by checksum */
- static chd_error open_disk_image(const emu_options &options, const device_t &device, const rom_entry *romp, chd_file &image_chd);
- static chd_error open_disk_image(const emu_options &options, software_list_device &swlist, const software_info &swinfo, const rom_entry *romp, chd_file &image_chd);
+ static std::error_condition open_disk_image(const emu_options &options, const device_t &device, const rom_entry *romp, chd_file &image_chd);
+ static std::error_condition open_disk_image(const emu_options &options, software_list_device &swlist, const software_info &swinfo, const rom_entry *romp, chd_file &image_chd);
private:
void determine_bios_rom(device_t &device, const char *specbios);
void count_roms();
void fill_random(u8 *base, u32 length);
- void handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, chd_error chderr);
+ void handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, std::error_condition chderr);
void dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes);
void verify_length_and_hash(emu_file *file, std::string_view name, u32 explength, const util::hash_collection &hashes);
void display_loading_rom_message(const char *name, bool from_list);
void display_rom_load_results(bool from_list);
void region_post_process(memory_region *region, bool invert);
std::unique_ptr<emu_file> open_rom_file(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, std::vector<std::string> &tried_file_names, bool from_list);
- std::unique_ptr<emu_file> open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, std::string_view name, osd_file::error &filerr);
+ std::unique_ptr<emu_file> open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, std::string_view name, std::error_condition &filerr);
int rom_fread(emu_file *file, u8 *buffer, int length, const rom_entry *parent_region);
int read_rom_data(emu_file *file, const rom_entry *parent_region, const rom_entry *romp);
void fill_rom_data(const rom_entry *romp);
void copy_rom_data(const rom_entry *romp);
void process_rom_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, u8 bios, const rom_entry *parent_region, const rom_entry *romp, bool from_list);
- chd_error open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd);
+ std::error_condition open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd);
void process_disk_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, std::string_view regiontag, const rom_entry *romp, std::function<const rom_entry * ()> next_parent);
void normalize_flags_for_device(std::string_view rgntag, u8 &width, endianness_t &endian);
void process_region_list();
diff --git a/src/emu/save.cpp b/src/emu/save.cpp
index 96fb3429a1c..120fa883655 100644
--- a/src/emu/save.cpp
+++ b/src/emu/save.cpp
@@ -24,7 +24,10 @@
#include "emu.h"
#include "emuopts.h"
-#include "coreutil.h"
+
+#include "util/coreutil.h"
+#include "util/ioprocs.h"
+#include "util/ioprocsfilter.h"
//**************************************************************************
@@ -212,7 +215,6 @@ save_error save_manager::check_file(running_machine &machine, emu_file &file, co
sig = machine.save().signature();
// seek to the beginning and read the header
- file.compress(FCOMPRESS_NONE);
file.seek(0, SEEK_SET);
u8 header[HEADER_SIZE];
if (file.read(header, sizeof(header)) != sizeof(header))
@@ -257,20 +259,28 @@ void save_manager::dispatch_presave()
save_error save_manager::write_file(emu_file &file)
{
- return do_write(
+ util::write_stream::ptr writer;
+ save_error err = do_write(
[] (size_t total_size) { return true; },
- [&file] (const void *data, size_t size) { return file.write(data, size) == size; },
- [&file] ()
+ [&writer] (const void *data, size_t size)
{
- file.compress(FCOMPRESS_NONE);
- file.seek(0, SEEK_SET);
- return true;
+ size_t written;
+ std::error_condition filerr = writer->write(data, size, written);
+ return !filerr && (size == written);
},
- [&file] ()
+ [&file, &writer] ()
{
- file.compress(FCOMPRESS_MEDIUM);
- return true;
+ if (file.seek(0, SEEK_SET))
+ return false;
+ writer = util::core_file_read_write(file);
+ return bool(writer);
+ },
+ [&file, &writer] ()
+ {
+ writer = util::zlib_write(util::core_file_read_write(file), 6, 16384);
+ return bool(writer);
});
+ return (STATERR_NONE != err) ? err : writer->finalize() ? STATERR_WRITE_ERROR : STATERR_NONE;
}
@@ -280,19 +290,26 @@ save_error save_manager::write_file(emu_file &file)
save_error save_manager::read_file(emu_file &file)
{
+ util::read_stream::ptr reader;
return do_read(
[] (size_t total_size) { return true; },
- [&file] (void *data, size_t size) { return file.read(data, size) == size; },
- [&file] ()
+ [&reader] (void *data, size_t size)
{
- file.compress(FCOMPRESS_NONE);
- file.seek(0, SEEK_SET);
- return true;
+ std::size_t read;
+ std::error_condition filerr = reader->read(data, size, read);
+ return !filerr && (read == size);
},
- [&file] ()
+ [&file, &reader] ()
{
- file.compress(FCOMPRESS_MEDIUM);
- return true;
+ if (file.seek(0, SEEK_SET))
+ return false;
+ reader = util::core_file_read(file);
+ return bool(reader);
+ },
+ [&file, &reader] ()
+ {
+ reader = util::zlib_read(util::core_file_read(file), 16384);
+ return bool(reader);
});
}
diff --git a/src/emu/save.h b/src/emu/save.h
index 32ba0526486..cfd674e738e 100644
--- a/src/emu/save.h
+++ b/src/emu/save.h
@@ -55,12 +55,12 @@ typedef named_delegate<void ()> save_prepost_delegate;
// saved; in general, this is intended only to be used for specific enum types
// defined by your device
#define ALLOW_SAVE_TYPE(TYPE) \
- template <> struct save_manager::is_atom<TYPE> { static constexpr bool value = true; };
+ template <> struct save_manager::is_atom<TYPE> : public std::true_type { };
// use this as above, but also to declare that std::vector<TYPE> is safe as well
#define ALLOW_SAVE_TYPE_AND_VECTOR(TYPE) \
ALLOW_SAVE_TYPE(TYPE) \
- template <> struct save_manager::is_vector_safe<TYPE> { static constexpr bool value = true; };
+ template <> struct save_manager::is_vector_safe<TYPE> : public std::true_type { };
// use this for saving members of structures in arrays
#define STRUCT_MEMBER(s, m) s, &save_manager::pointer_unwrap<decltype(s)>::underlying_type::m, #s "." #m
@@ -99,8 +99,8 @@ class save_manager
};
// set of templates to identify valid save types
- template <typename ItemType> struct is_atom { static constexpr bool value = false; };
- template <typename ItemType> struct is_vector_safe { static constexpr bool value = false; };
+ template <typename ItemType> struct is_atom : public std::false_type { };
+ template <typename ItemType> struct is_vector_safe : public std::false_type { };
class state_entry
{
diff --git a/src/emu/screen.cpp b/src/emu/screen.cpp
index 1a1c5dee8ad..0993473de49 100644
--- a/src/emu/screen.cpp
+++ b/src/emu/screen.cpp
@@ -1911,8 +1911,8 @@ void screen_device::finalize_burnin()
// compute the name and create the file
emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open(util::string_format("%s" PATH_SEPARATOR "burnin-%s.png", machine().basename(), tag() + 1));
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = file.open(util::string_format("%s" PATH_SEPARATOR "burnin-%s.png", machine().basename(), tag() + 1));
+ if (!filerr)
{
util::png_info pnginfo;
@@ -1942,7 +1942,7 @@ void screen_device::load_effect_overlay(const char *filename)
// load the file
m_screen_overlay_bitmap.reset();
emu_file file(machine().options().art_path(), OPEN_FLAG_READ);
- if (file.open(fullname) == osd_file::error::NONE)
+ if (!file.open(fullname))
{
render_load_png(m_screen_overlay_bitmap, file);
file.close();
diff --git a/src/emu/softlist_dev.cpp b/src/emu/softlist_dev.cpp
index c48f7820c23..7d25dd17013 100644
--- a/src/emu/softlist_dev.cpp
+++ b/src/emu/softlist_dev.cpp
@@ -288,9 +288,9 @@ void software_list_device::parse()
// attempt to open the file
emu_file file(mconfig().options().hash_path(), OPEN_FLAG_READ);
- const osd_file::error filerr = file.open(m_list_name + ".xml");
+ const std::error_condition filerr = file.open(m_list_name + ".xml");
m_filename = file.filename();
- if (filerr == osd_file::error::NONE)
+ if (!filerr)
{
// parse if no error
std::ostringstream errs;
@@ -298,7 +298,7 @@ void software_list_device::parse()
file.close();
m_errors = errs.str();
}
- else if (filerr == osd_file::error::NOT_FOUND)
+ else if (std::errc::no_such_file_or_directory == filerr)
{
osd_printf_verbose("%s: Software list %s not found\n", tag(), m_filename);
}
diff --git a/src/emu/uiinput.h b/src/emu/uiinput.h
index 29b18d06d30..3fc89d7a4ff 100644
--- a/src/emu/uiinput.h
+++ b/src/emu/uiinput.h
@@ -103,7 +103,7 @@ public:
private:
// constants
- constexpr static unsigned EVENT_QUEUE_SIZE = 128;
+ static constexpr unsigned EVENT_QUEUE_SIZE = 128;
// internal state
running_machine & m_machine; // reference to our machine
diff --git a/src/emu/video.cpp b/src/emu/video.cpp
index b6dada1c0b5..56f877ec8fa 100644
--- a/src/emu/video.cpp
+++ b/src/emu/video.cpp
@@ -359,8 +359,8 @@ void video_manager::save_active_screen_snapshots()
if (machine().render().is_live(screen))
{
emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = open_next(file, "png");
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = open_next(file, "png");
+ if (!filerr)
save_snapshot(&screen, file);
}
}
@@ -368,8 +368,8 @@ void video_manager::save_active_screen_snapshots()
{
// otherwise, just write a single snapshot
emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = open_next(file, "png");
- if (filerr == osd_file::error::NONE)
+ std::error_condition const filerr = open_next(file, "png");
+ if (!filerr)
save_snapshot(nullptr, file);
}
}
@@ -431,12 +431,12 @@ void video_manager::begin_recording_screen(const std::string &filename, uint32_t
OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
// and open the actual file
- osd_file::error filerr = filename.empty()
+ std::error_condition filerr = filename.empty()
? open_next(*movie_file, extension)
: movie_file->open(filename);
- if (filerr != osd_file::error::NONE)
+ if (filerr)
{
- osd_printf_error("Error creating movie, osd_file::error=%d\n", int(filerr));
+ osd_printf_error("Error creating movie, %s:%d %s\n", filerr.category().name(), filerr.value(), filerr.message());
return;
}
@@ -1007,8 +1007,8 @@ void video_manager::recompute_speed(const attotime &emutime)
{
// create a final screenshot
emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- osd_file::error filerr = file.open(machine().basename() + PATH_SEPARATOR "final.png");
- if (filerr == osd_file::error::NONE)
+ std::error_condition filerr = file.open(machine().basename() + PATH_SEPARATOR "final.png");
+ if (!filerr)
save_snapshot(nullptr, file);
//printf("Scheduled exit at %f\n", emutime.as_double());
@@ -1096,7 +1096,7 @@ void video_manager::pixels(u32 *buffer)
// scheme
//-------------------------------------------------
-osd_file::error video_manager::open_next(emu_file &file, const char *extension, uint32_t added_index)
+std::error_condition video_manager::open_next(emu_file &file, const char *extension, uint32_t added_index)
{
u32 origflags = file.openflags();
@@ -1205,11 +1205,9 @@ osd_file::error video_manager::open_next(emu_file &file, const char *extension,
strreplace(fname, "%i", string_format("%04d", seq));
// try to open the file; stop when we fail
- osd_file::error filerr = file.open(fname);
- if (filerr == osd_file::error::NOT_FOUND)
- {
+ std::error_condition const filerr = file.open(fname);
+ if (std::errc::no_such_file_or_directory == filerr)
break;
- }
}
}
diff --git a/src/emu/video.h b/src/emu/video.h
index bd58db9ca1d..3544bf19823 100644
--- a/src/emu/video.h
+++ b/src/emu/video.h
@@ -19,6 +19,8 @@
#include "recording.h"
+#include <system_error>
+
//**************************************************************************
// CONSTANTS
@@ -61,7 +63,7 @@ public:
// misc
void toggle_record_movie(movie_recording::format format);
- osd_file::error open_next(emu_file &file, const char *extension, uint32_t index = 0);
+ std::error_condition open_next(emu_file &file, const char *extension, uint32_t index = 0);
void compute_snapshot_size(s32 &width, s32 &height);
void pixels(u32 *buffer);