Changed diimage.cpp to use C++ comments

This commit is contained in:
Nathan Woods 2016-07-05 21:47:30 -04:00
parent a620ba26cd
commit 4079da505e

View File

@ -148,10 +148,10 @@ void device_image_interface::device_compute_hash(hash_collection &hashes, const
hashes.compute(reinterpret_cast<const UINT8 *>(data), length, types); hashes.compute(reinterpret_cast<const UINT8 *>(data), length, types);
} }
/*------------------------------------------------- //-------------------------------------------------
set_image_filename - specifies the filename of // set_image_filename - specifies the filename of
an image // an image
-------------------------------------------------*/ //-------------------------------------------------
image_error_t device_image_interface::set_image_filename(const char *filename) image_error_t device_image_interface::set_image_filename(const char *filename)
{ {
@ -189,11 +189,11 @@ image_error_t device_image_interface::set_image_filename(const char *filename)
CREATION FORMATS CREATION FORMATS
****************************************************************************/ ****************************************************************************/
/*------------------------------------------------- //-------------------------------------------------
device_get_named_creatable_format - // device_get_named_creatable_format -
accesses a specific image format available for // accesses a specific image format available for
image creation by name // image creation by name
-------------------------------------------------*/ //-------------------------------------------------
const image_device_format *device_image_interface::device_get_named_creatable_format(const char *format_name) const image_device_format *device_image_interface::device_get_named_creatable_format(const char *format_name)
{ {
@ -203,14 +203,15 @@ const image_device_format *device_image_interface::device_get_named_creatable_fo
return nullptr; return nullptr;
} }
/**************************************************************************** /****************************************************************************
ERROR HANDLING ERROR HANDLING
****************************************************************************/ ****************************************************************************/
/*------------------------------------------------- //-------------------------------------------------
image_clear_error - clear out any specified // image_clear_error - clear out any specified
error // error
-------------------------------------------------*/ //-------------------------------------------------
void device_image_interface::clear_error() void device_image_interface::clear_error()
{ {
@ -223,10 +224,11 @@ void device_image_interface::clear_error()
/*------------------------------------------------- //-------------------------------------------------
error - returns the error text for an image // error - returns the error text for an image
error // error
-------------------------------------------------*/ //-------------------------------------------------
static const char *const messages[] = static const char *const messages[] =
{ {
"", "",
@ -246,9 +248,9 @@ const char *device_image_interface::error()
/*------------------------------------------------- //-------------------------------------------------
seterror - specifies an error on an image // seterror - specifies an error on an image
-------------------------------------------------*/ //-------------------------------------------------
void device_image_interface::seterror(image_error_t err, const char *message) void device_image_interface::seterror(image_error_t err, const char *message)
{ {
@ -262,10 +264,10 @@ void device_image_interface::seterror(image_error_t err, const char *message)
/*------------------------------------------------- //-------------------------------------------------
message - used to display a message while // message - used to display a message while
loading // loading
-------------------------------------------------*/ //-------------------------------------------------
void device_image_interface::message(const char *format, ...) void device_image_interface::message(const char *format, ...)
{ {
@ -288,11 +290,12 @@ void device_image_interface::message(const char *format, ...)
WORKING DIRECTORIES WORKING DIRECTORIES
***************************************************************************/ ***************************************************************************/
/*------------------------------------------------- //-------------------------------------------------
try_change_working_directory - tries to change // try_change_working_directory - tries to change
the working directory, but only if the directory // the working directory, but only if the directory
actually exists // actually exists
-------------------------------------------------*/ //-------------------------------------------------
bool device_image_interface::try_change_working_directory(const char *subdir) bool device_image_interface::try_change_working_directory(const char *subdir)
{ {
const osd::directory::entry *entry; const osd::directory::entry *entry;
@ -314,26 +317,28 @@ bool device_image_interface::try_change_working_directory(const char *subdir)
directory.reset(); directory.reset();
} }
/* did we successfully identify the directory? */ // did we successfully identify the directory?
if (success) if (success)
m_working_directory = util::zippath_combine(m_working_directory.c_str(), subdir); m_working_directory = util::zippath_combine(m_working_directory.c_str(), subdir);
return success; return success;
} }
/*-------------------------------------------------
setup_working_directory - sets up the working
directory according to a few defaults //-------------------------------------------------
-------------------------------------------------*/ // setup_working_directory - sets up the working
// directory according to a few defaults
//-------------------------------------------------
void device_image_interface::setup_working_directory() void device_image_interface::setup_working_directory()
{ {
/* first set up the working directory to be the starting directory */ // first set up the working directory to be the starting directory
osd_get_full_path(m_working_directory, "."); osd_get_full_path(m_working_directory, ".");
/* now try browsing down to "software" */ // now try browsing down to "software"
if (try_change_working_directory("software")) if (try_change_working_directory("software"))
{ {
/* now down to a directory for this computer */ // now down to a directory for this computer
int gamedrv = driver_list::find(device().machine().system()); int gamedrv = driver_list::find(device().machine().system());
while(gamedrv != -1 && !try_change_working_directory(driver_list::driver(gamedrv).name)) while(gamedrv != -1 && !try_change_working_directory(driver_list::driver(gamedrv).name))
{ {
@ -342,6 +347,7 @@ void device_image_interface::setup_working_directory()
} }
} }
//------------------------------------------------- //-------------------------------------------------
// working_directory - returns the working // working_directory - returns the working
// directory to use for this image; this is // directory to use for this image; this is
@ -350,7 +356,7 @@ void device_image_interface::setup_working_directory()
const char * device_image_interface::working_directory() const char * device_image_interface::working_directory()
{ {
/* check to see if we've never initialized the working directory */ // check to see if we've never initialized the working directory
if (m_working_directory.empty()) if (m_working_directory.empty())
setup_working_directory(); setup_working_directory();
@ -358,9 +364,9 @@ const char * device_image_interface::working_directory()
} }
/*------------------------------------------------- //-------------------------------------------------
get_software_region // get_software_region
-------------------------------------------------*/ //-------------------------------------------------
UINT8 *device_image_interface::get_software_region(const char *tag) UINT8 *device_image_interface::get_software_region(const char *tag)
{ {
@ -375,9 +381,9 @@ UINT8 *device_image_interface::get_software_region(const char *tag)
} }
/*------------------------------------------------- //-------------------------------------------------
image_get_software_region_length // image_get_software_region_length
-------------------------------------------------*/ //-------------------------------------------------
UINT32 device_image_interface::get_software_region_length(const char *tag) UINT32 device_image_interface::get_software_region_length(const char *tag)
{ {
@ -390,9 +396,9 @@ UINT32 device_image_interface::get_software_region_length(const char *tag)
} }
/*------------------------------------------------- //-------------------------------------------------
image_get_feature // image_get_feature
-------------------------------------------------*/ //-------------------------------------------------
const char *device_image_interface::get_feature(const char *feature_name) const char *device_image_interface::get_feature(const char *feature_name)
{ {
@ -418,12 +424,13 @@ bool device_image_interface::load_software_region(const char *tag, optional_shar
return size > 0; return size > 0;
} }
/****************************************************************************
Hash info loading
If the hash is not checked and the relevant info not loaded, force that info // ****************************************************************************
to be loaded // Hash info loading
****************************************************************************/ //
// If the hash is not checked and the relevant info not loaded, force that info
// to be loaded
// ****************************************************************************
void device_image_interface::run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), void device_image_interface::run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *),
hash_collection &hashes, const char *types) hash_collection &hashes, const char *types)
@ -437,7 +444,7 @@ void device_image_interface::run_hash(void (*partialhash)(hash_collection &, con
buf.resize(size); buf.resize(size);
memset(&buf[0], 0, size); memset(&buf[0], 0, size);
/* read the file */ // read the file
fseek(0, SEEK_SET); fseek(0, SEEK_SET);
fread(&buf[0], size); fread(&buf[0], size);
@ -446,7 +453,7 @@ void device_image_interface::run_hash(void (*partialhash)(hash_collection &, con
else else
hashes.compute(&buf[0], size, types); hashes.compute(&buf[0], size, types);
/* cleanup */ // cleanup
fseek(0, SEEK_SET); fseek(0, SEEK_SET);
} }
@ -456,20 +463,20 @@ void device_image_interface::image_checkhash()
{ {
device_image_partialhash_func partialhash; device_image_partialhash_func partialhash;
/* only calculate CRC if it hasn't been calculated, and the open_mode is read only */ // only calculate CRC if it hasn't been calculated, and the open_mode is read only
UINT32 crcval; UINT32 crcval;
if (!m_hash.crc(crcval) && m_readonly && !m_created) if (!m_hash.crc(crcval) && m_readonly && !m_created)
{ {
/* do not cause a linear read of 600 megs please */ // do not cause a linear read of 600 megs please
/* TODO: use SHA1 in the CHD header as the hash */ // TODO: use SHA1 in the CHD header as the hash
if (image_type() == IO_CDROM) if (image_type() == IO_CDROM)
return; return;
/* Skip calculating the hash when we have an image mounted through a software list */ // Skip calculating the hash when we have an image mounted through a software list
if ( m_software_info_ptr ) if ( m_software_info_ptr )
return; return;
/* retrieve the partial hash func */ // retrieve the partial hash func
partialhash = get_partial_hash(); partialhash = get_partial_hash();
run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL); run_hash(partialhash, m_hash, hash_collection::HASH_TYPES_ALL);
@ -487,20 +494,21 @@ UINT32 device_image_interface::crc()
return crc; return crc;
} }
/**************************************************************************** // ****************************************************************************
Battery functions // Battery functions
//
These functions provide transparent access to battery-backed RAM on an // These functions provide transparent access to battery-backed RAM on an
image; typically for cartridges. // image; typically for cartridges.
****************************************************************************/ // ****************************************************************************
/*------------------------------------------------- //-------------------------------------------------
battery_load - retrieves the battery // battery_load - retrieves the battery
backed RAM for an image. The file name is // backed RAM for an image. The file name is
created from the machine driver name and the // created from the machine driver name and the
image name. // image name.
-------------------------------------------------*/ //-------------------------------------------------
void device_image_interface::battery_load(void *buffer, int length, int fill) void device_image_interface::battery_load(void *buffer, int length, int fill)
{ {
assert_always(buffer && (length > 0), "Must specify sensical buffer/length"); assert_always(buffer && (length > 0), "Must specify sensical buffer/length");
@ -515,7 +523,7 @@ void device_image_interface::battery_load(void *buffer, int length, int fill)
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
bytes_read = file.read(buffer, length); bytes_read = file.read(buffer, length);
/* fill remaining bytes (if necessary) */ // fill remaining bytes (if necessary)
memset(((char *)buffer) + bytes_read, fill, length - bytes_read); memset(((char *)buffer) + bytes_read, fill, length - bytes_read);
} }
@ -527,35 +535,38 @@ void device_image_interface::battery_load(void *buffer, int length, void *def_bu
int bytes_read = 0; int bytes_read = 0;
std::string fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext.c_str()).append(".nv"); std::string fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext.c_str()).append(".nv");
/* try to open the battery file and read it in, if possible */ // try to open the battery file and read it in, if possible
emu_file file(device().machine().options().nvram_directory(), OPEN_FLAG_READ); emu_file file(device().machine().options().nvram_directory(), OPEN_FLAG_READ);
filerr = file.open(fname.c_str()); filerr = file.open(fname.c_str());
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
bytes_read = file.read(buffer, length); bytes_read = file.read(buffer, length);
/* if no file was present, copy the default battery */ // if no file was present, copy the default battery
if (bytes_read == 0 && def_buffer) if (bytes_read == 0 && def_buffer)
memcpy((char *)buffer, (char *)def_buffer, length); memcpy((char *)buffer, (char *)def_buffer, length);
} }
/*-------------------------------------------------
battery_save - stores the battery //-------------------------------------------------
backed RAM for an image. The file name is // battery_save - stores the battery
created from the machine driver name and the // backed RAM for an image. The file name is
image name. // created from the machine driver name and the
-------------------------------------------------*/ // image name.
//-------------------------------------------------
void device_image_interface::battery_save(const void *buffer, int length) void device_image_interface::battery_save(const void *buffer, int length)
{ {
assert_always(buffer && (length > 0), "Must specify sensical buffer/length"); assert_always(buffer && (length > 0), "Must specify sensical buffer/length");
std::string fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext.c_str()).append(".nv"); std::string fname = std::string(device().machine().system().name).append(PATH_SEPARATOR).append(m_basename_noext.c_str()).append(".nv");
/* try to open the battery file and write it out, if possible */ // 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); 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.c_str()); osd_file::error filerr = file.open(fname.c_str());
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
file.write(buffer, length); file.write(buffer, length);
} }
//------------------------------------------------- //-------------------------------------------------
// uses_file_extension - update configuration // uses_file_extension - update configuration
// based on completed device setup // based on completed device setup
@ -583,38 +594,40 @@ bool device_image_interface::uses_file_extension(const char *file_extension) con
return result; return result;
} }
/****************************************************************************
IMAGE LOADING
****************************************************************************/
/*------------------------------------------------- // ***************************************************************************
is_loaded - quick check to determine whether an // IMAGE LOADING
image is loaded // ***************************************************************************
-------------------------------------------------*/
//-------------------------------------------------
// is_loaded - quick check to determine whether an
// image is loaded
//-------------------------------------------------
bool device_image_interface::is_loaded() bool device_image_interface::is_loaded()
{ {
return (m_file != nullptr); return (m_file != nullptr);
} }
/*-------------------------------------------------
load_image_by_path - loads an image with a //-------------------------------------------------
specific path // load_image_by_path - loads an image with a
-------------------------------------------------*/ // specific path
//-------------------------------------------------
image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const char *path) image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, const char *path)
{ {
image_error_t err; image_error_t err;
std::string revised_path; std::string revised_path;
/* attempt to read the file */ // attempt to read the file
auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path); auto const filerr = util::zippath_fopen(path, open_flags, m_file, revised_path);
/* did the open succeed? */ // did the open succeed?
switch(filerr) switch(filerr)
{ {
case osd_file::error::NONE: case osd_file::error::NONE:
/* success! */ // success!
m_readonly = (open_flags & OPEN_FLAG_WRITE) ? 0 : 1; m_readonly = (open_flags & OPEN_FLAG_WRITE) ? 0 : 1;
m_created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0; m_created = (open_flags & OPEN_FLAG_CREATE) ? 1 : 0;
err = IMAGE_ERROR_SUCCESS; err = IMAGE_ERROR_SUCCESS;
@ -622,17 +635,17 @@ image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, cons
case osd_file::error::NOT_FOUND: case osd_file::error::NOT_FOUND:
case osd_file::error::ACCESS_DENIED: case osd_file::error::ACCESS_DENIED:
/* file not found (or otherwise cannot open); continue */ // file not found (or otherwise cannot open); continue
err = IMAGE_ERROR_FILENOTFOUND; err = IMAGE_ERROR_FILENOTFOUND;
break; break;
case osd_file::error::OUT_OF_MEMORY: case osd_file::error::OUT_OF_MEMORY:
/* out of memory */ // out of memory
err = IMAGE_ERROR_OUTOFMEMORY; err = IMAGE_ERROR_OUTOFMEMORY;
break; break;
case osd_file::error::ALREADY_OPEN: case osd_file::error::ALREADY_OPEN:
/* this shouldn't happen */ // this shouldn't happen
err = IMAGE_ERROR_ALREADYOPEN; err = IMAGE_ERROR_ALREADYOPEN;
break; break;
@ -640,12 +653,12 @@ image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, cons
case osd_file::error::TOO_MANY_FILES: case osd_file::error::TOO_MANY_FILES:
case osd_file::error::INVALID_DATA: case osd_file::error::INVALID_DATA:
default: default:
/* other errors */ // other errors
err = IMAGE_ERROR_INTERNAL; err = IMAGE_ERROR_INTERNAL;
break; break;
} }
/* if successful, set the file name */ // if successful, set the file name
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
set_image_filename(revised_path.c_str()); set_image_filename(revised_path.c_str());
@ -659,14 +672,14 @@ int device_image_interface::reopen_for_write(const char *path)
image_error_t err; image_error_t err;
std::string revised_path; std::string revised_path;
/* attempt to open the file for writing*/ // 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); auto const filerr = util::zippath_fopen(path, OPEN_FLAG_READ|OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, m_file, revised_path);
/* did the open succeed? */ // did the open succeed?
switch(filerr) switch(filerr)
{ {
case osd_file::error::NONE: case osd_file::error::NONE:
/* success! */ // success!
m_readonly = 0; m_readonly = 0;
m_created = 1; m_created = 1;
err = IMAGE_ERROR_SUCCESS; err = IMAGE_ERROR_SUCCESS;
@ -674,17 +687,17 @@ int device_image_interface::reopen_for_write(const char *path)
case osd_file::error::NOT_FOUND: case osd_file::error::NOT_FOUND:
case osd_file::error::ACCESS_DENIED: case osd_file::error::ACCESS_DENIED:
/* file not found (or otherwise cannot open); continue */ // file not found (or otherwise cannot open); continue
err = IMAGE_ERROR_FILENOTFOUND; err = IMAGE_ERROR_FILENOTFOUND;
break; break;
case osd_file::error::OUT_OF_MEMORY: case osd_file::error::OUT_OF_MEMORY:
/* out of memory */ // out of memory
err = IMAGE_ERROR_OUTOFMEMORY; err = IMAGE_ERROR_OUTOFMEMORY;
break; break;
case osd_file::error::ALREADY_OPEN: case osd_file::error::ALREADY_OPEN:
/* this shouldn't happen */ // this shouldn't happen
err = IMAGE_ERROR_ALREADYOPEN; err = IMAGE_ERROR_ALREADYOPEN;
break; break;
@ -692,28 +705,29 @@ int device_image_interface::reopen_for_write(const char *path)
case osd_file::error::TOO_MANY_FILES: case osd_file::error::TOO_MANY_FILES:
case osd_file::error::INVALID_DATA: case osd_file::error::INVALID_DATA:
default: default:
/* other errors */ // other errors
err = IMAGE_ERROR_INTERNAL; err = IMAGE_ERROR_INTERNAL;
break; break;
} }
/* if successful, set the file name */ // if successful, set the file name
if (filerr == osd_file::error::NONE) if (filerr == osd_file::error::NONE)
set_image_filename(revised_path.c_str()); set_image_filename(revised_path.c_str());
return err; return err;
} }
/*-------------------------------------------------
determine_open_plan - determines which open //-------------------------------------------------
flags to use, and in what order // determine_open_plan - determines which open
-------------------------------------------------*/ // flags to use, and in what order
//-------------------------------------------------
void device_image_interface::determine_open_plan(int is_create, UINT32 *open_plan) void device_image_interface::determine_open_plan(int is_create, UINT32 *open_plan)
{ {
int i = 0; int i = 0;
/* emit flags */ // emit flags
if (!is_create && is_readable() && is_writeable()) if (!is_create && is_readable() && is_writeable())
open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE; open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE;
if (!is_create && !is_readable() && is_writeable()) if (!is_create && !is_readable() && is_writeable())
@ -725,11 +739,12 @@ void device_image_interface::determine_open_plan(int is_create, UINT32 *open_pla
open_plan[i] = 0; open_plan[i] = 0;
} }
/*-------------------------------------------------
dump_wrong_and_correct_checksums - dump an //-------------------------------------------------
error message containing the wrong and the // dump_wrong_and_correct_checksums - dump an
correct checksums for a given software item // error message containing the wrong and the
-------------------------------------------------*/ // correct checksums for a given software item
//-------------------------------------------------
static void dump_wrong_and_correct_checksums(const hash_collection &hashes, const hash_collection &acthashes) static void dump_wrong_and_correct_checksums(const hash_collection &hashes, const hash_collection &acthashes)
{ {
@ -737,17 +752,18 @@ static void dump_wrong_and_correct_checksums(const hash_collection &hashes, cons
osd_printf_error(" FOUND: %s\n", acthashes.macro_string().c_str()); osd_printf_error(" FOUND: %s\n", acthashes.macro_string().c_str());
} }
/*-------------------------------------------------
verify_length_and_hash - verify the length //-------------------------------------------------
and hash signatures of a file // verify_length_and_hash - verify the length
-------------------------------------------------*/ // and hash signatures of a file
//-------------------------------------------------
static int verify_length_and_hash(emu_file *file, const char *name, UINT32 explength, const hash_collection &hashes) static int verify_length_and_hash(emu_file *file, const char *name, UINT32 explength, const hash_collection &hashes)
{ {
int retVal = 0; int retVal = 0;
if (file==nullptr) return 0; if (file==nullptr) return 0;
/* verify length */ // verify length
UINT32 actlength = file->size(); UINT32 actlength = file->size();
if (explength != actlength) if (explength != actlength)
{ {
@ -755,21 +771,21 @@ static int verify_length_and_hash(emu_file *file, const char *name, UINT32 exple
retVal++; retVal++;
} }
/* If there is no good dump known, write it */ // If there is no good dump known, write it
hash_collection &acthashes = file->hashes(hashes.hash_types().c_str()); hash_collection &acthashes = file->hashes(hashes.hash_types().c_str());
if (hashes.flag(hash_collection::FLAG_NO_DUMP)) if (hashes.flag(hash_collection::FLAG_NO_DUMP))
{ {
osd_printf_error("%s NO GOOD DUMP KNOWN\n", name); osd_printf_error("%s NO GOOD DUMP KNOWN\n", name);
} }
/* verify checksums */ // verify checksums
else if (hashes != acthashes) else if (hashes != acthashes)
{ {
/* otherwise, it's just bad */ // otherwise, it's just bad
osd_printf_error("%s WRONG CHECKSUMS:\n", name); osd_printf_error("%s WRONG CHECKSUMS:\n", name);
dump_wrong_and_correct_checksums(hashes, acthashes); dump_wrong_and_correct_checksums(hashes, acthashes);
retVal++; retVal++;
} }
/* If it matches, but it is actually a bad dump, write it */ // If it matches, but it is actually a bad dump, write it
else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) else if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
{ {
osd_printf_error("%s NEEDS REDUMP\n",name); osd_printf_error("%s NEEDS REDUMP\n",name);
@ -777,9 +793,10 @@ static int verify_length_and_hash(emu_file *file, const char *name, UINT32 exple
return retVal; return retVal;
} }
/*-------------------------------------------------
load_software - software image loading //-------------------------------------------------
-------------------------------------------------*/ // load_software - software image loading
//-------------------------------------------------
bool device_image_interface::load_software(software_list_device &swlist, const char *swname, const rom_entry *start) bool device_image_interface::load_software(software_list_device &swlist, const char *swname, const rom_entry *start)
{ {
@ -789,11 +806,11 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
int warningcount = 0; int warningcount = 0;
for (region = start; region != nullptr; region = rom_next_region(region)) for (region = start; region != nullptr; region = rom_next_region(region))
{ {
/* loop until we hit the end of this region */ // loop until we hit the end of this region
const rom_entry *romp = region + 1; const rom_entry *romp = region + 1;
while (!ROMENTRY_ISREGIONEND(romp)) while (!ROMENTRY_ISREGIONEND(romp))
{ {
/* handle files */ // handle files
if (ROMENTRY_ISFILE(romp)) if (ROMENTRY_ISFILE(romp))
{ {
osd_file::error filerr = osd_file::error::NOT_FOUND; osd_file::error filerr = osd_file::error::NOT_FOUND;
@ -882,9 +899,10 @@ bool device_image_interface::load_software(software_list_device &swlist, const c
return retVal; return retVal;
} }
/*-------------------------------------------------
load_internal - core image loading //-------------------------------------------------
-------------------------------------------------*/ // load_internal - core image loading
//-------------------------------------------------
bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args, bool just_load) bool device_image_interface::load_internal(const char *path, bool is_create, int create_format, option_resolution *create_args, bool just_load)
{ {
@ -897,16 +915,16 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
std::string pathstr(path); std::string pathstr(path);
bool filename_has_period = (pathstr.find_last_of('.') != -1) ? TRUE : FALSE; bool filename_has_period = (pathstr.find_last_of('.') != -1) ? TRUE : FALSE;
/* first unload the image */ // first unload the image
unload(); unload();
/* clear any possible error messages */ // clear any possible error messages
clear_error(); clear_error();
/* we are now loading */ // we are now loading
m_is_loading = TRUE; m_is_loading = TRUE;
/* record the filename */ // record the filename
m_err = set_image_filename(path); m_err = set_image_filename(path);
if (m_err) if (m_err)
@ -914,7 +932,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
if (core_opens_image_file()) if (core_opens_image_file())
{ {
/* Check if there's a software list defined for this device and use that if we're not creating an image */ // Check if there's a software list defined for this device and use that if we're not creating an image
if (!filename_has_period && !just_load) if (!filename_has_period && !just_load)
{ {
softload = load_software_part(path, m_software_part_ptr); softload = load_software_part(path, m_software_part_ptr);
@ -941,20 +959,20 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
if (is_create || filename_has_period) if (is_create || filename_has_period)
{ {
/* determine open plan */ // determine open plan
determine_open_plan(is_create, open_plan); determine_open_plan(is_create, open_plan);
/* attempt to open the file in various ways */ // attempt to open the file in various ways
for (i = 0; !m_file && open_plan[i]; i++) for (i = 0; !m_file && open_plan[i]; i++)
{ {
/* open the file */ // open the file
m_err = load_image_by_path(open_plan[i], path); m_err = load_image_by_path(open_plan[i], path);
if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND)) if (m_err && (m_err != IMAGE_ERROR_FILENOTFOUND))
goto done; goto done;
} }
} }
/* Copy some image information when we have been loaded through a software list */ // Copy some image information when we have been loaded through a software list
if ( m_software_info_ptr ) if ( m_software_info_ptr )
{ {
// sanitize // sanitize
@ -968,7 +986,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
//m_playable = m_software_info_ptr->supported(); //m_playable = m_software_info_ptr->supported();
} }
/* did we fail to find the file? */ // did we fail to find the file?
if (!is_loaded() && !softload) if (!is_loaded() && !softload)
{ {
m_err = IMAGE_ERROR_FILENOTFOUND; m_err = IMAGE_ERROR_FILENOTFOUND;
@ -976,7 +994,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
} }
} }
/* call device load or create */ // call device load or create
m_create_format = create_format; m_create_format = create_format;
m_create_args = create_args; m_create_args = create_args;
@ -985,7 +1003,7 @@ bool device_image_interface::load_internal(const char *path, bool is_create, int
if (m_err) if (m_err)
goto done; goto done;
} }
/* success! */ // success!
done: done:
if (just_load) { if (just_load) {
@ -1022,18 +1040,19 @@ done:
/*------------------------------------------------- //-------------------------------------------------
load - load an image into MESS // load - load an image into MAME
-------------------------------------------------*/ //-------------------------------------------------
bool device_image_interface::load(const char *path) bool device_image_interface::load(const char *path)
{ {
return load_internal(path, FALSE, 0, nullptr, FALSE); return load_internal(path, FALSE, 0, nullptr, FALSE);
} }
/*-------------------------------------------------
open_image_file - opening plain image file //-------------------------------------------------
-------------------------------------------------*/ // open_image_file - opening plain image file
//-------------------------------------------------
bool device_image_interface::open_image_file(emu_options &options) bool device_image_interface::open_image_file(emu_options &options)
{ {
@ -1049,10 +1068,11 @@ bool device_image_interface::open_image_file(emu_options &options)
return false; return false;
} }
/*-------------------------------------------------
image_finish_load - special call - only use //-------------------------------------------------
from core // image_finish_load - special call - only use
-------------------------------------------------*/ // from core
//-------------------------------------------------
bool device_image_interface::finish_load() bool device_image_interface::finish_load()
{ {
@ -1073,7 +1093,7 @@ bool device_image_interface::finish_load()
} }
else else
{ {
/* using device load */ // using device load
err = call_load(); err = call_load();
if (err) if (err)
{ {
@ -1089,9 +1109,10 @@ bool device_image_interface::finish_load()
return err; return err;
} }
/*-------------------------------------------------
create - create a image //-------------------------------------------------
-------------------------------------------------*/ // create - create a image
//-------------------------------------------------
bool device_image_interface::create(const char *path, const image_device_format *create_format, option_resolution *create_args) bool device_image_interface::create(const char *path, const image_device_format *create_format, option_resolution *create_args)
{ {
@ -1109,10 +1130,10 @@ bool device_image_interface::create(const char *path, const image_device_format
} }
/*------------------------------------------------- //-------------------------------------------------
clear - clear all internal data pertaining // clear - clear all internal data pertaining
to an image // to an image
-------------------------------------------------*/ //-------------------------------------------------
void device_image_interface::clear() void device_image_interface::clear()
{ {
@ -1136,9 +1157,10 @@ void device_image_interface::clear()
m_software_list_name.clear(); m_software_list_name.clear();
} }
/*-------------------------------------------------
unload - main call to unload an image //-------------------------------------------------
-------------------------------------------------*/ // unload - main call to unload an image
//-------------------------------------------------
void device_image_interface::unload() void device_image_interface::unload()
{ {
@ -1150,9 +1172,10 @@ void device_image_interface::unload()
clear_error(); clear_error();
} }
/*-------------------------------------------------
update_names - update brief and instance names //-------------------------------------------------
-------------------------------------------------*/ // update_names - update brief and instance names
//-------------------------------------------------
void device_image_interface::update_names(const device_type device_type, const char *inst, const char *brief) void device_image_interface::update_names(const device_type device_type, const char *inst, const char *brief)
{ {
@ -1357,7 +1380,7 @@ std::string device_image_interface::software_get_default_slot(const char *defaul
return result; return result;
} }
/* ----------------------------------------------------------------------- */ //----------------------------------------------------------------------------
static int image_fseek_thunk(void *file, INT64 offset, int whence) static int image_fseek_thunk(void *file, INT64 offset, int whence)
{ {
@ -1383,7 +1406,7 @@ static UINT64 image_fsize_thunk(void *file)
return image->length(); return image->length();
} }
/* ----------------------------------------------------------------------- */ //----------------------------------------------------------------------------
struct io_procs image_ioprocs = struct io_procs image_ioprocs =
{ {