summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/imagedev/diablo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/imagedev/diablo.cpp')
-rw-r--r--src/devices/imagedev/diablo.cpp91
1 files changed, 31 insertions, 60 deletions
diff --git a/src/devices/imagedev/diablo.cpp b/src/devices/imagedev/diablo.cpp
index cdc7665f61d..46f60fe70d2 100644
--- a/src/devices/imagedev/diablo.cpp
+++ b/src/devices/imagedev/diablo.cpp
@@ -8,6 +8,7 @@
#include "diablo.h"
#include "emuopts.h"
+#include "fileio.h"
#include "harddisk.h"
#include "romload.h"
@@ -34,13 +35,12 @@ DEFINE_DEVICE_TYPE(DIABLO, diablo_image_device, "diablo_image", "Diablo")
//-------------------------------------------------
diablo_image_device::diablo_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
- : device_t(mconfig, DIABLO, tag, owner, clock),
- device_image_interface(mconfig, *this),
- m_chd(nullptr),
- m_hard_disk_handle(nullptr),
- m_device_image_load(*this),
- m_device_image_unload(*this),
- m_interface(nullptr)
+ : harddisk_image_base_device(mconfig, DIABLO, tag, owner, clock)
+ , m_chd(nullptr)
+ , m_hard_disk_handle()
+ , m_device_image_load(*this)
+ , m_device_image_unload(*this)
+ , m_interface(nullptr)
{
}
@@ -81,25 +81,20 @@ void diablo_image_device::device_start()
// try to locate the CHD from a DISK_REGION
chd_file *handle = machine().rom_load().get_disk_handle(tag());
- if (handle != nullptr)
- {
- m_hard_disk_handle = hard_disk_open(handle);
- }
+ if (handle)
+ m_hard_disk_handle.reset(new hard_disk_file(handle));
else
- {
- m_hard_disk_handle = nullptr;
- }
+ m_hard_disk_handle.reset();
}
void diablo_image_device::device_stop()
{
- if (m_hard_disk_handle)
- hard_disk_close(m_hard_disk_handle);
+ m_hard_disk_handle.reset();
}
-image_init_result diablo_image_device::call_load()
+std::pair<std::error_condition, std::string> diablo_image_device::call_load()
{
- image_init_result our_result;
+ std::error_condition our_result;
our_result = internal_load_dsk();
/* Check if there is an image_load callback defined */
@@ -108,11 +103,11 @@ image_init_result diablo_image_device::call_load()
/* Let the override do some additional work/checks */
our_result = m_device_image_load(*this);
}
- return our_result;
+ return std::make_pair(our_result, std::string());
}
-image_init_result diablo_image_device::call_create(int create_format, util::option_resolution *create_args)
+std::pair<std::error_condition, std::string> diablo_image_device::call_create(int create_format, util::option_resolution *create_args)
{
if (!create_args)
throw emu_fatalerror("diablo_image_device::call_create: Expected create_args to not be nullptr");
@@ -132,31 +127,25 @@ image_init_result diablo_image_device::call_create(int create_format, util::opti
if (!err)
m_origchd.create(std::move(proxy), uint64_t(totalsectors) * uint64_t(sectorsize), hunksize, sectorsize, compression);
if (err)
- return image_init_result::FAIL;
+ return std::make_pair(err, std::string());
/* if we created the image and hence, have metadata to set, set the metadata */
err = m_origchd.write_metadata(HARD_DISK_METADATA_TAG, 0, string_format(HARD_DISK_METADATA_FORMAT, cylinders, heads, sectors, sectorsize));
m_origchd.close();
if (err)
- return image_init_result::FAIL;
+ return std::make_pair(err, std::string());
- return internal_load_dsk();
+ return std::make_pair(internal_load_dsk(), std::string());
}
void diablo_image_device::call_unload()
{
- /* Check if there is an image_unload callback defined */
- if ( !m_device_image_unload.isnull() )
- {
+ // Check if there is an image_unload callback defined
+ if (!m_device_image_unload.isnull())
m_device_image_unload(*this);
- }
- if (m_hard_disk_handle != nullptr)
- {
- hard_disk_close(m_hard_disk_handle);
- m_hard_disk_handle = nullptr;
- }
+ m_hard_disk_handle.reset();
m_origchd.close();
m_diffchd.close();
@@ -206,16 +195,15 @@ static std::error_condition open_disk_diff(emu_options &options, const char *nam
return std::errc::no_such_file_or_directory;
}
-image_init_result diablo_image_device::internal_load_dsk()
+std::error_condition diablo_image_device::internal_load_dsk()
{
std::error_condition err;
m_chd = nullptr;
- if (m_hard_disk_handle)
- hard_disk_close(m_hard_disk_handle);
+ m_hard_disk_handle.reset();
- /* open the CHD file */
+ // open the CHD file
if (loaded_through_softlist())
{
m_chd = device().machine().rom_load().get_disk_handle(device().subtag("harddriv").c_str());
@@ -246,35 +234,18 @@ image_init_result diablo_image_device::internal_load_dsk()
}
}
- if (m_chd != nullptr)
+ if (m_chd)
{
- /* open the hard disk file */
- m_hard_disk_handle = hard_disk_open(m_chd);
- if (m_hard_disk_handle != nullptr)
- return image_init_result::PASS;
+ // open the hard disk file
+ m_hard_disk_handle.reset(new hard_disk_file(m_chd));
+ if (m_hard_disk_handle)
+ return std::error_condition();
}
- /* if we had an error, close out the CHD */
+ // if we had an error, close out the CHD
m_origchd.close();
m_diffchd.close();
m_chd = nullptr;
- seterror(err, nullptr);
-
- return image_init_result::FAIL;
-}
-
-/*************************************
- *
- * Get the CHD file (from the src/chd.c core)
- * after an image has been opened with the hd core
- *
- *************************************/
-chd_file *diablo_image_device::get_chd_file()
-{
- chd_file *result = nullptr;
- hard_disk_file *hd_file = get_hard_disk_file();
- if (hd_file)
- result = hard_disk_get_chd(hd_file);
- return result;
+ return err ? err : image_error::UNSPECIFIED;
}