summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/romload.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2011-02-12 03:47:37 +0000
committer Aaron Giles <aaron@aarongiles.com>2011-02-12 03:47:37 +0000
commit1b54456be5fd090b039b3e9f691ac0464ffdff12 (patch)
tree3839c21fada7804940b1c828dcceb6a57ff9c74f /src/emu/romload.c
parent061548d2bec629c46712844ffe459292f3c745f4 (diff)
mame_file is now emu_file and is a class. It is required
to pass a core_options object to the constructor, along with a search path. This required pushing either a running_machine or a core_options through some code that wasn't previously ready to handle it. emu_files can be reused over multiple open/close sessions, and a lot of core code cleaned up nicely as things were converted to them. Also created a file_enumerator class for iterating over files in a searchpath. This replaces the old mame_openpath functions. Changed machine->options() to return a reference. Removed public nvram_open() and fixed jchan/kaneko16 to stop directly saving NVRAM. Removed most of the mame_options() calls; this will soon go away entirely, so don't add any more. Added core_options to device_validity_check() so they can be used to validate things.
Diffstat (limited to 'src/emu/romload.c')
-rw-r--r--src/emu/romload.c147
1 files changed, 71 insertions, 76 deletions
diff --git a/src/emu/romload.c b/src/emu/romload.c
index 56943bbb94d..95fa97d6c6d 100644
--- a/src/emu/romload.c
+++ b/src/emu/romload.c
@@ -40,9 +40,9 @@ struct _open_chd
open_chd * next; /* pointer to next in the list */
const char * region; /* disk region we came from */
chd_file * origchd; /* handle to the original CHD */
- mame_file * origfile; /* file handle to the original CHD file */
+ emu_file * origfile; /* file handle to the original CHD file */
chd_file * diffchd; /* handle to the diff CHD */
- mame_file * difffile; /* file handle to the diff CHD file */
+ emu_file * difffile; /* file handle to the diff CHD file */
};
@@ -61,7 +61,7 @@ struct _romload_private
UINT32 romsloadedsize; /* total size of ROMs loaded so far */
UINT32 romstotalsize; /* total size of ROMs to read */
- mame_file * file; /* current file */
+ emu_file * file; /* current file */
open_chd * chd_list; /* disks */
open_chd ** chd_list_tailptr;
@@ -81,34 +81,39 @@ static void rom_exit(running_machine &machine);
HELPERS (also used by devimage.c)
***************************************************************************/
-file_error common_process_file_options(core_options *options, const char *location, const char *ext, const rom_entry *romp, mame_file **image_file)
+file_error common_process_file(core_options &options, const char *location, const char *ext, const rom_entry *romp, emu_file **image_file)
{
+ *image_file = global_alloc(emu_file(options, SEARCHPATH_IMAGE, OPEN_FLAG_READ));
+ file_error filerr;
+
if (location != NULL && strcmp(location, "") != 0)
- {
- astring fname(location, PATH_SEPARATOR, ROM_GETNAME(romp));
- fname.cat(ext);
- return mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
- }
+ filerr = (*image_file)->open(location, PATH_SEPARATOR, ROM_GETNAME(romp), ext);
else
+ filerr = (*image_file)->open(ROM_GETNAME(romp), ext);
+
+ if (filerr != FILERR_NONE)
{
- astring fname(ROM_GETNAME(romp));
- fname.cat(ext);
- return mame_fopen_options(options, SEARCHPATH_IMAGE, fname, OPEN_FLAG_READ, image_file);
+ global_free(*image_file);
+ *image_file = NULL;
}
-
- return FILERR_NOT_FOUND;
+ return filerr;
}
-file_error common_process_file(const char *location, bool has_crc, UINT32 crc, const rom_entry *romp, mame_file **image_file)
+file_error common_process_file(core_options &options, const char *location, bool has_crc, UINT32 crc, const rom_entry *romp, emu_file **image_file)
{
+ *image_file = global_alloc(emu_file(options, SEARCHPATH_IMAGE, OPEN_FLAG_READ));
file_error filerr;
- astring fname(location, PATH_SEPARATOR, ROM_GETNAME(romp));
if (has_crc)
- filerr = mame_fopen_crc(SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ, image_file);
+ filerr = (*image_file)->open(location, PATH_SEPARATOR, ROM_GETNAME(romp), crc);
else
- filerr = mame_fopen(SEARCHPATH_ROM, fname, OPEN_FLAG_READ, image_file);
+ filerr = (*image_file)->open(location, PATH_SEPARATOR, ROM_GETNAME(romp));
+ if (filerr != FILERR_NONE)
+ {
+ global_free(*image_file);
+ *image_file = NULL;
+ }
return filerr;
}
@@ -153,17 +158,17 @@ static void add_disk_handle(running_machine *machine, open_chd *chd)
file associated with the given region
-------------------------------------------------*/
-void set_disk_handle(running_machine *machine, const char *region, mame_file *file, chd_file *chdfile)
+void set_disk_handle(running_machine &machine, const char *region, emu_file &file, chd_file &chdfile)
{
open_chd chd = { 0 };
/* note the region we are in */
chd.region = region;
- chd.origchd = chdfile;
- chd.origfile = file;
+ chd.origchd = &chdfile;
+ chd.origfile = &file;
/* we're okay, add to the list of disks */
- add_disk_handle(machine, &chd);
+ add_disk_handle(&machine, &chd);
}
@@ -325,7 +330,7 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...)
static void determine_bios_rom(rom_load_data *romdata)
{
- const char *specbios = options_get_string(romdata->machine->options(), OPTION_BIOS);
+ const char *specbios = options_get_string(&romdata->machine->options(), OPTION_BIOS);
const char *defaultname = NULL;
const rom_entry *rom;
int default_no = 1;
@@ -508,8 +513,8 @@ static void verify_length_and_hash(rom_load_data *romdata, const char *name, UIN
return;
/* get the length and CRC from the file */
- actlength = mame_fsize(romdata->file);
- acthash = mame_fhash(romdata->file, hash_data_used_functions(hash));
+ actlength = romdata->file->size();
+ acthash = romdata->file->hash_string(hash_data_used_functions(hash));
/* verify length */
if (explength != actlength)
@@ -658,7 +663,7 @@ static int open_rom_file(rom_load_data *romdata, const char *regiontag, const ro
romdata->file = NULL;
for (drv = romdata->machine->gamedrv; romdata->file == NULL && drv != NULL; drv = driver_get_clone(drv))
if (drv->name != NULL && *drv->name != 0)
- filerr = common_process_file(drv->name, has_crc, crc, romp, &romdata->file);
+ filerr = common_process_file(romdata->machine->options(), drv->name, has_crc, crc, romp, &romdata->file);
/* if the region is load by name, load the ROM from there */
if (romdata->file == NULL && regiontag != NULL)
@@ -708,21 +713,21 @@ static int open_rom_file(rom_load_data *romdata, const char *regiontag, const ro
// - if we are not using lists, we have regiontag only;
// - if we are using lists, we have: list/clonename, list/parentname, clonename, parentname
if (!is_list)
- filerr = common_process_file(tag1.cstr(), has_crc, crc, romp, &romdata->file);
+ filerr = common_process_file(romdata->machine->options(), tag1.cstr(), has_crc, crc, romp, &romdata->file);
else
{
// try to load from list/setname
if ((romdata->file == NULL) && (tag2.cstr() != NULL))
- filerr = common_process_file(tag2.cstr(), has_crc, crc, romp, &romdata->file);
+ filerr = common_process_file(romdata->machine->options(), tag2.cstr(), has_crc, crc, romp, &romdata->file);
// try to load from list/parentname
if ((romdata->file == NULL) && has_parent && (tag3.cstr() != NULL))
- filerr = common_process_file(tag3.cstr(), has_crc, crc, romp, &romdata->file);
+ filerr = common_process_file(romdata->machine->options(), tag3.cstr(), has_crc, crc, romp, &romdata->file);
// try to load from setname
if ((romdata->file == NULL) && (tag4.cstr() != NULL))
- filerr = common_process_file(tag4.cstr(), has_crc, crc, romp, &romdata->file);
+ filerr = common_process_file(romdata->machine->options(), tag4.cstr(), has_crc, crc, romp, &romdata->file);
// try to load from parentname
if ((romdata->file == NULL) && has_parent && (tag5.cstr() != NULL))
- filerr = common_process_file(tag5.cstr(), has_crc, crc, romp, &romdata->file);
+ filerr = common_process_file(romdata->machine->options(), tag5.cstr(), has_crc, crc, romp, &romdata->file);
}
}
@@ -744,7 +749,7 @@ static int rom_fread(rom_load_data *romdata, UINT8 *buffer, int length)
{
/* files just pass through */
if (romdata->file != NULL)
- return mame_fread(romdata->file, buffer, length);
+ return romdata->file->read(buffer, length);
/* otherwise, fill with randomness */
else
@@ -1007,7 +1012,7 @@ static void process_rom_entries(rom_load_data *romdata, const char *regiontag, c
/* reseek to the start and clear the baserom so we don't reverify */
if (romdata->file != NULL)
- mame_fseek(romdata->file, 0, SEEK_SET);
+ romdata->file->seek(0, SEEK_SET);
baserom = NULL;
explength = 0;
}
@@ -1017,7 +1022,7 @@ static void process_rom_entries(rom_load_data *romdata, const char *regiontag, c
if (romdata->file != NULL)
{
LOG(("Closing ROM file\n"));
- mame_fclose(romdata->file);
+ global_free(romdata->file);
romdata->file = NULL;
}
}
@@ -1030,23 +1035,12 @@ static void process_rom_entries(rom_load_data *romdata, const char *regiontag, c
/*-------------------------------------------------
- open_disk_image - open a disk image, searching
- up the parent and loading by checksum
--------------------------------------------------*/
-
-chd_error open_disk_image(const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd, const char *locationtag)
-{
- return open_disk_image_options(mame_options(), gamedrv, romp, image_file, image_chd, locationtag);
-}
-
-
-/*-------------------------------------------------
- open_disk_image_options - open a disk image,
+ open_disk_image - open a disk image,
searching up the parent and loading by
checksum
-------------------------------------------------*/
-chd_error open_disk_image_options(core_options *options, const game_driver *gamedrv, const rom_entry *romp, mame_file **image_file, chd_file **image_chd, const char *locationtag)
+chd_error open_disk_image(core_options &options, const game_driver *gamedrv, const rom_entry *romp, emu_file **image_file, chd_file **image_chd, const char *locationtag)
{
const game_driver *drv, *searchdrv;
const rom_entry *region, *rom;
@@ -1060,10 +1054,10 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game
/* attempt to open the properly named file, scanning up through parent directories */
filerr = FILERR_NOT_FOUND;
for (searchdrv = gamedrv; searchdrv != NULL && filerr != FILERR_NONE; searchdrv = driver_get_clone(searchdrv))
- filerr = common_process_file_options(options, searchdrv->name, ".chd", romp, image_file);
+ filerr = common_process_file(options, searchdrv->name, ".chd", romp, image_file);
if (filerr != FILERR_NONE)
- filerr = common_process_file_options(options, NULL, ".chd", romp, image_file);
+ filerr = common_process_file(options, NULL, ".chd", romp, image_file);
/* look for the disk in the locationtag too */
if (filerr != FILERR_NONE && locationtag != NULL)
@@ -1113,26 +1107,26 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game
// - if we are not using lists, we have locationtag only;
// - if we are using lists, we have: list/clonename, list/parentname, clonename, parentname
if (!is_list)
- filerr = common_process_file_options(options, locationtag, ".chd", romp, image_file);
+ filerr = common_process_file(options, locationtag, ".chd", romp, image_file);
else
{
// try to load from list/setname
if ((filerr != FILERR_NONE) && (tag2.cstr() != NULL))
- filerr = common_process_file_options(options, tag2.cstr(), ".chd", romp, image_file);
+ filerr = common_process_file(options, tag2.cstr(), ".chd", romp, image_file);
// try to load from list/parentname (if any)
if ((filerr != FILERR_NONE) && has_parent && (tag3.cstr() != NULL))
- filerr = common_process_file_options(options, tag3.cstr(), ".chd", romp, image_file);
+ filerr = common_process_file(options, tag3.cstr(), ".chd", romp, image_file);
// try to load from setname
if ((filerr != FILERR_NONE) && (tag4.cstr() != NULL))
- filerr = common_process_file_options(options, tag4.cstr(), ".chd", romp, image_file);
+ filerr = common_process_file(options, tag4.cstr(), ".chd", romp, image_file);
// try to load from parentname (if any)
if ((filerr != FILERR_NONE) && has_parent && (tag5.cstr() != NULL))
- filerr = common_process_file_options(options, tag5.cstr(), ".chd", romp, image_file);
+ filerr = common_process_file(options, tag5.cstr(), ".chd", romp, image_file);
// only for CHD we also try to load from list/
if ((filerr != FILERR_NONE) && (tag1.cstr() != NULL))
{
tag1.del(tag1.len() - 1, 1); // remove the PATH_SEPARATOR
- filerr = common_process_file_options(options, tag1.cstr(), ".chd", romp, image_file);
+ filerr = common_process_file(options, tag1.cstr(), ".chd", romp, image_file);
}
}
}
@@ -1141,12 +1135,12 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game
if (filerr == FILERR_NONE)
{
/* try to open the CHD */
- err = chd_open_file(mame_core_file(*image_file), CHD_OPEN_READ, NULL, image_chd);
+ err = chd_open_file(**image_file, CHD_OPEN_READ, NULL, image_chd);
if (err == CHDERR_NONE)
return err;
/* close the file on failure */
- mame_fclose(*image_file);
+ global_free(*image_file);
*image_file = NULL;
}
else
@@ -1169,21 +1163,21 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game
/* attempt to open the properly named file, scanning up through parent directories */
filerr = FILERR_NOT_FOUND;
for (searchdrv = drv; searchdrv != NULL && filerr != FILERR_NONE; searchdrv = driver_get_clone(searchdrv))
- filerr = common_process_file_options(options, searchdrv->name, ".chd", rom, image_file);
+ filerr = common_process_file(options, searchdrv->name, ".chd", rom, image_file);
if (filerr != FILERR_NONE)
- filerr = common_process_file_options(options, NULL, ".chd", rom, image_file);
+ filerr = common_process_file(options, NULL, ".chd", rom, image_file);
/* did the file open succeed? */
if (filerr == FILERR_NONE)
{
/* try to open the CHD */
- err = chd_open_file(mame_core_file(*image_file), CHD_OPEN_READ, NULL, image_chd);
+ err = chd_open_file(**image_file, CHD_OPEN_READ, NULL, image_chd);
if (err == CHDERR_NONE)
return err;
/* close the file on failure */
- mame_fclose(*image_file);
+ global_free(*image_file);
*image_file = NULL;
}
}
@@ -1197,10 +1191,9 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game
open_disk_diff - open a DISK diff file
-------------------------------------------------*/
-static chd_error open_disk_diff(const game_driver *drv, const rom_entry *romp, chd_file *source, mame_file **diff_file, chd_file **diff_chd)
+static chd_error open_disk_diff(core_options &options, const rom_entry *romp, chd_file *source, emu_file **diff_file, chd_file **diff_chd)
{
astring fname(ROM_GETNAME(romp), ".dif");
- file_error filerr;
chd_error err;
*diff_file = NULL;
@@ -1208,12 +1201,14 @@ static chd_error open_disk_diff(const game_driver *drv, const rom_entry *romp, c
/* try to open the diff */
LOG(("Opening differencing image file: %s\n", fname.cstr()));
- filerr = mame_fopen(SEARCHPATH_IMAGE_DIFF, fname, OPEN_FLAG_READ | OPEN_FLAG_WRITE, diff_file);
+ *diff_file = global_alloc(emu_file(options, SEARCHPATH_IMAGE_DIFF, OPEN_FLAG_READ | OPEN_FLAG_WRITE));
+ file_error filerr = (*diff_file)->open(fname);
if (filerr != FILERR_NONE)
{
/* didn't work; try creating it instead */
LOG(("Creating differencing image: %s\n", fname.cstr()));
- filerr = mame_fopen(SEARCHPATH_IMAGE_DIFF, fname, OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, diff_file);
+ (*diff_file)->set_openflags(OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ filerr = (*diff_file)->open(fname);
if (filerr != FILERR_NONE)
{
err = CHDERR_FILE_NOT_FOUND;
@@ -1221,20 +1216,20 @@ static chd_error open_disk_diff(const game_driver *drv, const rom_entry *romp, c
}
/* create the CHD */
- err = chd_create_file(mame_core_file(*diff_file), 0, 0, CHDCOMPRESSION_NONE, source);
+ err = chd_create_file(**diff_file, 0, 0, CHDCOMPRESSION_NONE, source);
if (err != CHDERR_NONE)
goto done;
}
LOG(("Opening differencing image file: %s\n", fname.cstr()));
- err = chd_open_file(mame_core_file(*diff_file), CHD_OPEN_READWRITE, source, diff_chd);
+ err = chd_open_file(**diff_file, CHD_OPEN_READWRITE, source, diff_chd);
if (err != CHDERR_NONE)
goto done;
done:
if ((err != CHDERR_NONE) && (*diff_file != NULL))
{
- mame_fclose(*diff_file);
+ global_free(*diff_file);
*diff_file = NULL;
}
return err;
@@ -1267,7 +1262,7 @@ static void process_disk_entries(rom_load_data *romdata, const char *regiontag,
/* first open the source drive */
LOG(("Opening disk image: %s\n", filename.cstr()));
- err = open_disk_image(romdata->machine->gamedrv, romp, &chd.origfile, &chd.origchd, locationtag);
+ err = open_disk_image(romdata->machine->options(), romdata->machine->gamedrv, romp, &chd.origfile, &chd.origchd, locationtag);
if (err != CHDERR_NONE)
{
if (err == CHDERR_FILE_NOT_FOUND)
@@ -1307,7 +1302,7 @@ static void process_disk_entries(rom_load_data *romdata, const char *regiontag,
if (!DISK_ISREADONLY(romp))
{
/* try to open or create the diff */
- err = open_disk_diff(romdata->machine->gamedrv, romp, chd.origchd, &chd.difffile, &chd.diffchd);
+ err = open_disk_diff(romdata->machine->options(), romp, chd.origchd, &chd.difffile, &chd.diffchd);
if (err != CHDERR_NONE)
{
romdata->errorstring.catprintf("%s DIFF CHD ERROR: %s\n", filename.cstr(), chd_error_string(err));
@@ -1384,7 +1379,7 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom
// " swlist % clonename % parentname "
// open_rom_file contains the code to split the elements and to create paths to load from
- software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL);
+ software_list *software_list_ptr = software_list_open(device->machine->options(), swlist, FALSE, NULL);
if (software_list_ptr)
{
locationtag.cat(breakstr);
@@ -1398,7 +1393,7 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom
locationtag.cat(breakstr);
// printf("%s\n", locationtag.cstr());
}
- const char *parentname = software_get_clone(swlist, swinfo->shortname);
+ const char *parentname = software_get_clone(device->machine->options(), swlist, swinfo->shortname);
if (parentname != NULL)
swinfo = software_list_find(software_list_ptr, parentname, NULL);
else
@@ -1414,12 +1409,12 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom
romdata->errorstring.reset();
- if (software_get_support(swlist, swname) == SOFTWARE_SUPPORTED_PARTIAL)
+ if (software_get_support(device->machine->options(), swlist, swname) == SOFTWARE_SUPPORTED_PARTIAL)
{
romdata->errorstring.catprintf("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist);
romdata->warnings++;
}
- if (software_get_support(swlist, swname) == SOFTWARE_SUPPORTED_NO)
+ if (software_get_support(device->machine->options(), swlist, swname) == SOFTWARE_SUPPORTED_NO)
{
romdata->errorstring.catprintf("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist);
romdata->warnings++;
@@ -1593,11 +1588,11 @@ static void rom_exit(running_machine &machine)
if (curchd->diffchd != NULL)
chd_close(curchd->diffchd);
if (curchd->difffile != NULL)
- mame_fclose(curchd->difffile);
+ global_free(curchd->difffile);
if (curchd->origchd != NULL)
chd_close(curchd->origchd);
if (curchd->origfile != NULL)
- mame_fclose(curchd->origfile);
+ global_free(curchd->origfile);
}
}