summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/audit.c57
-rw-r--r--src/emu/cheat.c118
-rw-r--r--src/emu/cheat.h10
-rw-r--r--src/emu/clifront.c14
-rw-r--r--src/emu/config.c49
-rw-r--r--src/emu/crsshair.c7
-rw-r--r--src/emu/debug/debugcmd.c10
-rw-r--r--src/emu/debug/debugcpu.c20
-rw-r--r--src/emu/devimage.c20
-rw-r--r--src/emu/devintrf.c10
-rw-r--r--src/emu/devintrf.h6
-rw-r--r--src/emu/devlegcy.c8
-rw-r--r--src/emu/devlegcy.h14
-rw-r--r--src/emu/diexec.c2
-rw-r--r--src/emu/diexec.h2
-rw-r--r--src/emu/diimage.c6
-rw-r--r--src/emu/diimage.h2
-rw-r--r--src/emu/dimemory.c2
-rw-r--r--src/emu/dimemory.h2
-rw-r--r--src/emu/dinvram.h8
-rw-r--r--src/emu/disound.c2
-rw-r--r--src/emu/disound.h2
-rw-r--r--src/emu/emuopts.c4
-rw-r--r--src/emu/fileio.c1130
-rw-r--r--src/emu/fileio.h287
-rw-r--r--src/emu/hashfile.c44
-rw-r--r--src/emu/hashfile.h6
-rw-r--r--src/emu/image.c65
-rw-r--r--src/emu/image.h4
-rw-r--r--src/emu/imagedev/multcart.c4
-rw-r--r--src/emu/inptport.c67
-rw-r--r--src/emu/input.c20
-rw-r--r--src/emu/machine.c20
-rw-r--r--src/emu/machine.h4
-rw-r--r--src/emu/machine/at28c16.c10
-rw-r--r--src/emu/machine/at28c16.h6
-rw-r--r--src/emu/machine/ds2404.c8
-rw-r--r--src/emu/machine/ds2404.h4
-rw-r--r--src/emu/machine/eeprom.c10
-rw-r--r--src/emu/machine/eeprom.h6
-rw-r--r--src/emu/machine/er2055.c8
-rw-r--r--src/emu/machine/er2055.h4
-rw-r--r--src/emu/machine/generic.c68
-rw-r--r--src/emu/machine/generic.h3
-rw-r--r--src/emu/machine/i2cmem.c10
-rw-r--r--src/emu/machine/i2cmem.h6
-rw-r--r--src/emu/machine/intelfsh.c8
-rw-r--r--src/emu/machine/intelfsh.h4
-rw-r--r--src/emu/machine/mb3773.c2
-rw-r--r--src/emu/machine/mb3773.h2
-rw-r--r--src/emu/machine/mc146818.c8
-rw-r--r--src/emu/machine/mc146818.h4
-rw-r--r--src/emu/machine/nvram.c8
-rw-r--r--src/emu/machine/nvram.h4
-rw-r--r--src/emu/machine/ram.c7
-rw-r--r--src/emu/machine/rtc65271.c40
-rw-r--r--src/emu/machine/timekpr.c8
-rw-r--r--src/emu/machine/timekpr.h4
-rw-r--r--src/emu/machine/x2212.c8
-rw-r--r--src/emu/machine/x2212.h4
-rw-r--r--src/emu/machine/x76f041.c28
-rw-r--r--src/emu/machine/x76f041.h4
-rw-r--r--src/emu/machine/x76f100.c20
-rw-r--r--src/emu/machine/x76f100.h4
-rw-r--r--src/emu/mame.c15
-rw-r--r--src/emu/mconfig.h8
-rw-r--r--src/emu/render.c37
-rw-r--r--src/emu/rendfont.c72
-rw-r--r--src/emu/rendfont.h2
-rw-r--r--src/emu/rendlay.c8
-rw-r--r--src/emu/rendlay.h1
-rw-r--r--src/emu/rendutil.c10
-rw-r--r--src/emu/rendutil.h2
-rw-r--r--src/emu/romload.c147
-rw-r--r--src/emu/romload.h11
-rw-r--r--src/emu/screen.c20
-rw-r--r--src/emu/screen.h2
-rw-r--r--src/emu/softlist.c44
-rw-r--r--src/emu/softlist.h6
-rw-r--r--src/emu/sound.c8
-rw-r--r--src/emu/sound/samples.c56
-rw-r--r--src/emu/state.c32
-rw-r--r--src/emu/state.h6
-rw-r--r--src/emu/timer.c2
-rw-r--r--src/emu/timer.h2
-rw-r--r--src/emu/ui.c16
-rw-r--r--src/emu/uimenu.c184
-rw-r--r--src/emu/validity.c8
-rw-r--r--src/emu/validity.h2
-rw-r--r--src/emu/video.c139
-rw-r--r--src/emu/video.h6
-rw-r--r--src/emu/video/vector.c6
92 files changed, 1441 insertions, 1747 deletions
diff --git a/src/emu/audit.c b/src/emu/audit.c
index 28a5e4ab868..781ca3009a0 100644
--- a/src/emu/audit.c
+++ b/src/emu/audit.c
@@ -192,28 +192,19 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor
sharedname = &intf->samplenames[sampnum][1];
else
{
- file_error filerr;
- mame_file *file;
-
/* attempt to access the file from the game driver name */
- astring fname(gamedrv->name, PATH_SEPARATOR, intf->samplenames[sampnum]);
- filerr = mame_fopen_options(options, SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file);
+ emu_file file(*options, SEARCHPATH_SAMPLE, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD);
+ file_error filerr = file.open(gamedrv->name, PATH_SEPARATOR, intf->samplenames[sampnum]);
/* attempt to access the file from the shared driver name */
if (filerr != FILERR_NONE && sharedname != NULL)
- {
- fname.cpy(sharedname).cat(PATH_SEPARATOR).cat(intf->samplenames[sampnum]);
- filerr = mame_fopen_options(options, SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file);
- }
+ filerr = file.open(sharedname, PATH_SEPARATOR, intf->samplenames[sampnum]);
/* fill in the record */
record->type = AUDIT_FILE_SAMPLE;
record->name = intf->samplenames[sampnum];
if (filerr == FILERR_NONE)
- {
set_status(record++, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD);
- mame_fclose(file);
- }
else
set_status(record++, AUDIT_STATUS_NOT_FOUND, SUBSTATUS_NOT_FOUND);
}
@@ -350,22 +341,18 @@ static void audit_one_rom(core_options *options, const rom_entry *rom, const cha
/* find the file and checksum it, getting the file length along the way */
for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv))
{
- file_error filerr;
- mame_file *file;
+ emu_file file(*options, SEARCHPATH_ROM, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD);
/* open the file if we can */
- astring fname(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom));
- if (has_crc)
- filerr = mame_fopen_crc_options(options, SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file);
+ file_error filerr;
+ if (has_crc)
+ filerr = file.open(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom), crc);
else
- filerr = mame_fopen_options(options, SEARCHPATH_ROM, fname, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file);
-
- /* if we got it, extract the hash and length */
+ filerr = file.open(drv->name, PATH_SEPARATOR, ROM_GETNAME(rom));
if (filerr == FILERR_NONE)
{
- hash_data_copy(record->hash, mame_fhash(file, validation));
- record->length = (UINT32)mame_fsize(file);
- mame_fclose(file);
+ hash_data_copy(record->hash, file.hash_string(validation));
+ record->length = (UINT32)file.size();
break;
}
}
@@ -373,22 +360,18 @@ static void audit_one_rom(core_options *options, const rom_entry *rom, const cha
/* if not found, check the region as a backup */
if (record->length == 0 && regiontag != NULL)
{
- file_error filerr;
- mame_file *file;
+ emu_file file(*options, SEARCHPATH_ROM, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD);
/* open the file if we can */
- astring fname(regiontag, PATH_SEPARATOR, ROM_GETNAME(rom));
+ file_error filerr;
if (has_crc)
- filerr = mame_fopen_crc_options(options, SEARCHPATH_ROM, fname, crc, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file);
- else
- filerr = mame_fopen_options(options, SEARCHPATH_ROM, fname, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file);
-
- /* if we got it, extract the hash and length */
+ filerr = file.open(regiontag, PATH_SEPARATOR, ROM_GETNAME(rom), crc);
+ else
+ filerr = file.open(regiontag, PATH_SEPARATOR, ROM_GETNAME(rom));
if (filerr == FILERR_NONE)
{
- hash_data_copy(record->hash, mame_fhash(file, validation));
- record->length = (UINT32)mame_fsize(file);
- mame_fclose(file);
+ hash_data_copy(record->hash, file.hash_string(validation));
+ record->length = (UINT32)file.size();
}
}
@@ -446,7 +429,7 @@ static void audit_one_rom(core_options *options, const rom_entry *rom, const cha
static void audit_one_disk(core_options *options, const rom_entry *rom, const game_driver *gamedrv, UINT32 validation, audit_record *record)
{
- mame_file *source_file;
+ emu_file *source_file;
chd_file *source;
chd_error err;
@@ -456,7 +439,7 @@ static void audit_one_disk(core_options *options, const rom_entry *rom, const ga
record->exphash = ROM_GETHASHDATA(rom);
/* open the disk */
- err = open_disk_image_options(options, gamedrv, rom, &source_file, &source, NULL);
+ err = open_disk_image(*options, gamedrv, rom, &source_file, &source, NULL);
/* if we failed, report the error */
if (err != CHDERR_NONE)
@@ -507,7 +490,7 @@ static void audit_one_disk(core_options *options, const rom_entry *rom, const ga
set_status(record, AUDIT_STATUS_GOOD, SUBSTATUS_GOOD);
chd_close(source);
- mame_fclose(source_file);
+ global_free(source_file);
}
}
diff --git a/src/emu/cheat.c b/src/emu/cheat.c
index 19733754ba8..91082f1a291 100644
--- a/src/emu/cheat.c
+++ b/src/emu/cheat.c
@@ -230,30 +230,30 @@ const char *cheat_parameter::text()
// save - save a single cheat parameter
//-------------------------------------------------
-void cheat_parameter::save(mame_file &cheatfile) const
+void cheat_parameter::save(emu_file &cheatfile) const
{
// output the parameter tag
- mame_fprintf(&cheatfile, "\t\t<parameter");
+ cheatfile.printf("\t\t<parameter");
// if no items, just output min/max/step
astring string;
if (!has_itemlist())
{
if (m_minval != 0)
- mame_fprintf(&cheatfile, " min=\"%s\"", m_minval.format(string));
+ cheatfile.printf(" min=\"%s\"", m_minval.format(string));
if (m_maxval != 0)
- mame_fprintf(&cheatfile, " max=\"%s\"", m_maxval.format(string));
+ cheatfile.printf(" max=\"%s\"", m_maxval.format(string));
if (m_stepval != 1)
- mame_fprintf(&cheatfile, " step=\"%s\"", m_stepval.format(string));
- mame_fprintf(&cheatfile, "/>\n");
+ cheatfile.printf(" step=\"%s\"", m_stepval.format(string));
+ cheatfile.printf("/>\n");
}
// iterate over items
else
{
for (const item *curitem = m_itemlist.first(); curitem != NULL; curitem = curitem->next())
- mame_fprintf(&cheatfile, "\t\t\t<item value=\"%s\">%s</item>\n", curitem->value().format(string), curitem->text());
- mame_fprintf(&cheatfile, "\t\t</parameter>\n");
+ cheatfile.printf("\t\t\t<item value=\"%s\">%s</item>\n", curitem->value().format(string), curitem->text());
+ cheatfile.printf("\t\t</parameter>\n");
}
}
@@ -402,26 +402,26 @@ void cheat_script::execute(cheat_manager &manager, UINT64 &argindex)
// save - save a single cheat script
//-------------------------------------------------
-void cheat_script::save(mame_file &cheatfile) const
+void cheat_script::save(emu_file &cheatfile) const
{
// output the script tag
- mame_fprintf(&cheatfile, "\t\t<script");
+ cheatfile.printf("\t\t<script");
switch (m_state)
{
- case SCRIPT_STATE_OFF: mame_fprintf(&cheatfile, " state=\"off\""); break;
- case SCRIPT_STATE_ON: mame_fprintf(&cheatfile, " state=\"on\""); break;
+ case SCRIPT_STATE_OFF: cheatfile.printf(" state=\"off\""); break;
+ case SCRIPT_STATE_ON: cheatfile.printf(" state=\"on\""); break;
default:
- case SCRIPT_STATE_RUN: mame_fprintf(&cheatfile, " state=\"run\""); break;
- case SCRIPT_STATE_CHANGE: mame_fprintf(&cheatfile, " state=\"change\""); break;
+ case SCRIPT_STATE_RUN: cheatfile.printf(" state=\"run\""); break;
+ case SCRIPT_STATE_CHANGE: cheatfile.printf(" state=\"change\""); break;
}
- mame_fprintf(&cheatfile, ">\n");
+ cheatfile.printf(">\n");
// output entries
for (const script_entry *entry = m_entrylist.first(); entry != NULL; entry = entry->next())
entry->save(cheatfile);
// close the tag
- mame_fprintf(&cheatfile, "\t\t</script>\n");
+ cheatfile.printf("\t\t</script>\n");
}
@@ -557,41 +557,41 @@ void cheat_script::script_entry::execute(cheat_manager &manager, UINT64 &arginde
// save - save a single action or output
//-------------------------------------------------
-void cheat_script::script_entry::save(mame_file &cheatfile) const
+void cheat_script::script_entry::save(emu_file &cheatfile) const
{
astring tempstring;
// output an action
if (!m_format)
{
- mame_fprintf(&cheatfile, "\t\t\t<action");
+ cheatfile.printf("\t\t\t<action");
if (!m_condition.is_empty())
- mame_fprintf(&cheatfile, " condition=\"%s\"", cheat_manager::quote_expression(tempstring, m_condition));
- mame_fprintf(&cheatfile, ">%s</action>\n", cheat_manager::quote_expression(tempstring, m_expression));
+ cheatfile.printf(" condition=\"%s\"", cheat_manager::quote_expression(tempstring, m_condition));
+ cheatfile.printf(">%s</action>\n", cheat_manager::quote_expression(tempstring, m_expression));
}
// output an output
else
{
- mame_fprintf(&cheatfile, "\t\t\t<output format=\"%s\"", m_format.cstr());
+ cheatfile.printf("\t\t\t<output format=\"%s\"", m_format.cstr());
if (!m_condition.is_empty())
- mame_fprintf(&cheatfile, " condition=\"%s\"", cheat_manager::quote_expression(tempstring, m_condition));
+ cheatfile.printf(" condition=\"%s\"", cheat_manager::quote_expression(tempstring, m_condition));
if (m_line != 0)
- mame_fprintf(&cheatfile, " line=\"%d\"", m_line);
+ cheatfile.printf(" line=\"%d\"", m_line);
if (m_justify == JUSTIFY_CENTER)
- mame_fprintf(&cheatfile, " align=\"center\"");
+ cheatfile.printf(" align=\"center\"");
else if (m_justify == JUSTIFY_RIGHT)
- mame_fprintf(&cheatfile, " align=\"right\"");
+ cheatfile.printf(" align=\"right\"");
if (m_arglist.count() == 0)
- mame_fprintf(&cheatfile, " />\n");
+ cheatfile.printf(" />\n");
// output arguments
else
{
- mame_fprintf(&cheatfile, ">\n");
+ cheatfile.printf(">\n");
for (const output_argument *curarg = m_arglist.first(); curarg != NULL; curarg = curarg->next())
curarg->save(cheatfile);
- mame_fprintf(&cheatfile, "\t\t\t</output>\n");
+ cheatfile.printf("\t\t\t</output>\n");
}
}
}
@@ -691,14 +691,14 @@ int cheat_script::script_entry::output_argument::values(UINT64 &argindex, UINT64
// save - save a single output argument
//-------------------------------------------------
-void cheat_script::script_entry::output_argument::save(mame_file &cheatfile) const
+void cheat_script::script_entry::output_argument::save(emu_file &cheatfile) const
{
astring tempstring;
- mame_fprintf(&cheatfile, "\t\t\t\t<argument");
+ cheatfile.printf("\t\t\t\t<argument");
if (m_count != 1)
- mame_fprintf(&cheatfile, " count=\"%d\"", (int)m_count);
- mame_fprintf(&cheatfile, ">%s</argument>\n", cheat_manager::quote_expression(tempstring, m_expression));
+ cheatfile.printf(" count=\"%d\"", (int)m_count);
+ cheatfile.printf(">%s</argument>\n", cheat_manager::quote_expression(tempstring, m_expression));
}
@@ -815,24 +815,24 @@ cheat_entry::~cheat_entry()
// save - save a single cheat entry
//-------------------------------------------------
-void cheat_entry::save(mame_file &cheatfile) const
+void cheat_entry::save(emu_file &cheatfile) const
{
// determine if we have scripts
bool has_scripts = (m_off_script != NULL || m_on_script != NULL || m_run_script != NULL || m_change_script != NULL);
// output the cheat tag
- mame_fprintf(&cheatfile, "\t<cheat desc=\"%s\"", m_description.cstr());
+ cheatfile.printf("\t<cheat desc=\"%s\"", m_description.cstr());
if (m_numtemp != DEFAULT_TEMP_VARIABLES)
- mame_fprintf(&cheatfile, " tempvariables=\"%d\"", m_numtemp);
+ cheatfile.printf(" tempvariables=\"%d\"", m_numtemp);
if (!m_comment && m_parameter == NULL && !has_scripts)
- mame_fprintf(&cheatfile, " />\n");
+ cheatfile.printf(" />\n");
else
{
- mame_fprintf(&cheatfile, ">\n");
+ cheatfile.printf(">\n");
// save the comment
if (m_comment)
- mame_fprintf(&cheatfile, "\t\t<comment><![CDATA[\n%s\n\t\t]]></comment>\n", m_comment.cstr());
+ cheatfile.printf("\t\t<comment><![CDATA[\n%s\n\t\t]]></comment>\n", m_comment.cstr());
// output the parameter, if present
if (m_parameter != NULL)
@@ -849,7 +849,7 @@ void cheat_entry::save(mame_file &cheatfile) const
m_run_script->save(cheatfile);
// close the cheat tag
- mame_fprintf(&cheatfile, "\t</cheat>\n");
+ cheatfile.printf("\t</cheat>\n");
}
}
@@ -1093,7 +1093,7 @@ cheat_manager::cheat_manager(running_machine &machine)
m_symtable(&machine)
{
// if the cheat engine is disabled, we're done
- if (!options_get_bool(machine.options(), OPTION_CHEAT))
+ if (!options_get_bool(&machine.options(), OPTION_CHEAT))
return;
// request a callback
@@ -1125,7 +1125,7 @@ cheat_manager::cheat_manager(running_machine &machine)
void cheat_manager::set_enable(bool enable)
{
// if the cheat engine is disabled, we're done
- if (!options_get_bool(m_machine.options(), OPTION_CHEAT))
+ if (!options_get_bool(&m_machine.options(), OPTION_CHEAT))
return;
// if we're enabled currently and we don't want to be, turn things off
@@ -1160,7 +1160,7 @@ void cheat_manager::set_enable(bool enable)
void cheat_manager::reload()
{
// if the cheat engine is disabled, we're done
- if (!options_get_bool(m_machine.options(), OPTION_CHEAT))
+ if (!options_get_bool(&m_machine.options(), OPTION_CHEAT))
return;
// free everything
@@ -1215,9 +1215,8 @@ void cheat_manager::reload()
bool cheat_manager::save_all(const char *filename)
{
// open the file with the proper name
- astring fname(filename, ".xml");
- mame_file *cheatfile;
- file_error filerr = mame_fopen(SEARCHPATH_CHEAT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &cheatfile);
+ emu_file cheatfile(m_machine.options(), SEARCHPATH_CHEAT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = cheatfile.open(filename, ".xml");
// if that failed, return nothing
if (filerr != FILERR_NONE)
@@ -1227,17 +1226,16 @@ bool cheat_manager::save_all(const char *filename)
try
{
// output the outer layers
- mame_fprintf(cheatfile, "<?xml version=\"1.0\"?>\n");
- mame_fprintf(cheatfile, "<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");
- mame_fprintf(cheatfile, "<mamecheat version=\"%d\">\n", CHEAT_VERSION);
+ cheatfile.printf("<?xml version=\"1.0\"?>\n");
+ cheatfile.printf("<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");
+ cheatfile.printf("<mamecheat version=\"%d\">\n", CHEAT_VERSION);
// iterate over cheats in the list and save them
for (cheat_entry *cheat = m_cheatlist.first(); cheat != NULL; cheat = cheat->next())
- cheat->save(*cheatfile);
+ cheat->save(cheatfile);
// close out the file
- mame_fprintf(cheatfile, "</mamecheat>\n");
- mame_fclose(cheatfile);
+ cheatfile.printf("</mamecheat>\n");
return true;
}
@@ -1245,8 +1243,7 @@ bool cheat_manager::save_all(const char *filename)
catch (emu_fatalerror &err)
{
mame_printf_error("%s\n", err.string());
- mame_fclose(cheatfile);
- osd_rmfile(filename);
+ cheatfile.remove_on_close();
}
return false;
}
@@ -1414,23 +1411,22 @@ void cheat_manager::frame_update()
void cheat_manager::load_cheats(const char *filename)
{
xml_data_node *rootnode = NULL;
- mame_file *cheatfile = NULL;
+ emu_file cheatfile(m_machine.options(), SEARCHPATH_CHEAT, OPEN_FLAG_READ);
try
{
// open the file with the proper name
- astring fname(filename, ".xml");
- file_error filerr = mame_fopen(SEARCHPATH_CHEAT, fname, OPEN_FLAG_READ, &cheatfile);
+ file_error filerr = cheatfile.open(filename, ".xml");
// loop over all instrances of the files found in our search paths
while (filerr == FILERR_NONE)
{
- mame_printf_verbose("Loading cheats file from %s\n", mame_file_full_name(cheatfile).cstr());
+ mame_printf_verbose("Loading cheats file from %s\n", cheatfile.fullpath());
// read the XML file into internal data structures
xml_parse_options options = { 0 };
xml_parse_error error;
options.error = &error;
- rootnode = xml_file_read(mame_core_file(cheatfile), &options);
+ rootnode = xml_file_read(cheatfile, &options);
// if unable to parse the file, just bail
if (rootnode == NULL)
@@ -1458,7 +1454,7 @@ void cheat_manager::load_cheats(const char *filename)
for (scannode = m_cheatlist.first(); scannode != NULL; scannode = scannode->next())
if (strcmp(scannode->description(), curcheat->description()) == 0)
{
- mame_printf_verbose("Ignoring duplicate cheat '%s' from file %s\n", curcheat->description(), mame_file_full_name(cheatfile).cstr());
+ mame_printf_verbose("Ignoring duplicate cheat '%s' from file %s\n", curcheat->description(), cheatfile.fullpath());
break;
}
@@ -1473,7 +1469,7 @@ void cheat_manager::load_cheats(const char *filename)
xml_file_free(rootnode);
// open the next file in sequence
- filerr = mame_fclose_and_open_next(&cheatfile, fname, OPEN_FLAG_READ);
+ filerr = cheatfile.open_next();
}
}
@@ -1484,7 +1480,5 @@ void cheat_manager::load_cheats(const char *filename)
m_cheatlist.reset();
if (rootnode != NULL)
xml_file_free(rootnode);
- if (cheatfile != NULL)
- mame_fclose(cheatfile);
}
}
diff --git a/src/emu/cheat.h b/src/emu/cheat.h
index 84bab06ed92..f8be8233a59 100644
--- a/src/emu/cheat.h
+++ b/src/emu/cheat.h
@@ -115,7 +115,7 @@ public:
bool set_next_state();
// actions
- void save(mame_file &cheatfile) const;
+ void save(emu_file &cheatfile) const;
private:
// a single item in a parameter item list
@@ -168,7 +168,7 @@ public:
// actions
void execute(cheat_manager &manager, UINT64 &argindex);
- void save(mame_file &cheatfile) const;
+ void save(emu_file &cheatfile) const;
private:
// an entry within the script
@@ -185,7 +185,7 @@ private:
// actions
void execute(cheat_manager &manager, UINT64 &argindex);
- void save(mame_file &cheatfile) const;
+ void save(emu_file &cheatfile) const;
private:
// an argument for output
@@ -203,7 +203,7 @@ private:
int values(UINT64 &argindex, UINT64 *result);
// actions
- void save(mame_file &cheatfile) const;
+ void save(emu_file &cheatfile) const;
private:
// internal state
@@ -278,7 +278,7 @@ public:
bool select_default_state();
bool select_previous_state();
bool select_next_state();
- void save(mame_file &cheatfile) const;
+ void save(emu_file &cheatfile) const;
// UI helpers
void menu_text(astring &description, astring &state, UINT32 &flags);
diff --git a/src/emu/clifront.c b/src/emu/clifront.c
index af4fcd26e2a..30628a6dffc 100644
--- a/src/emu/clifront.c
+++ b/src/emu/clifront.c
@@ -253,7 +253,7 @@ static int execute_simple_commands(core_options *options, const char *exename)
if (options_get_bool(options, CLIOPTION_VALIDATE))
{
set_mame_options(options);
- return mame_validitychecks(NULL);
+ return mame_validitychecks(*options, NULL);
}
return -1;
@@ -293,14 +293,13 @@ static int execute_commands(core_options *options, const char *exename, const ga
/* createconfig? */
if (options_get_bool(options, CLIOPTION_CREATECONFIG))
{
- file_error filerr;
- mame_file *file;
+ emu_file file(*options, NULL, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
/* parse any relevant INI files before proceeding */
mame_parse_ini_files(options, driver);
/* make the output filename */
- filerr = mame_fopen_options(options, NULL, CONFIGNAME ".ini", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ file_error filerr = file.open(CONFIGNAME ".ini");
/* error if unable to create the file */
if (filerr != FILERR_NONE)
@@ -310,8 +309,7 @@ static int execute_commands(core_options *options, const char *exename, const ga
}
/* output the configuration and exit cleanly */
- options_output_ini_file(options, mame_core_file(file));
- mame_fclose(file);
+ options_output_ini_file(options, file);
return MAMERR_NONE;
}
@@ -905,7 +903,7 @@ static int info_listsoftware(core_options *options, const char *gamename)
{
if ( swlist->list_name[i] && *swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM))
{
- software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL );
+ software_list *list = software_list_open( *options, swlist->list_name[i], FALSE, NULL );
if ( list )
{
@@ -1103,7 +1101,7 @@ static void softlist_match_roms(core_options *options, const char *hash, int len
{
if ( swlist->list_name[i] )
{
- software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL );
+ software_list *list = software_list_open( *options, swlist->list_name[i], FALSE, NULL );
for ( software_info *swinfo = software_list_find( list, "*", NULL ); swinfo != NULL; swinfo = software_list_find( list, "*", swinfo ) )
{
diff --git a/src/emu/config.c b/src/emu/config.c
index ac1fed0c93a..f20d8a2a10a 100644
--- a/src/emu/config.c
+++ b/src/emu/config.c
@@ -46,8 +46,8 @@ static config_type *typelist;
FUNCTION PROTOTYPES
***************************************************************************/
-static int config_load_xml(running_machine *machine, mame_file *file, int type);
-static int config_save_xml(running_machine *machine, mame_file *file, int type);
+static int config_load_xml(running_machine *machine, emu_file &file, int type);
+static int config_save_xml(running_machine *machine, emu_file &file, int type);
@@ -102,10 +102,8 @@ void config_register(running_machine *machine, const char *nodename, config_call
int config_load_settings(running_machine *machine)
{
- const char *controller = options_get_string(machine->options(), OPTION_CTRLR);
- file_error filerr;
+ const char *controller = options_get_string(&machine->options(), OPTION_CTRLR);
config_type *type;
- mame_file *file;
int loaded = 0;
/* loop over all registrants and call their init function */
@@ -116,8 +114,8 @@ int config_load_settings(running_machine *machine)
if (controller[0] != 0)
{
/* open the config file */
- astring fname(controller, ".cfg");
- filerr = mame_fopen(SEARCHPATH_CTRLR, fname, OPEN_FLAG_READ, &file);
+ emu_file file(machine->options(), SEARCHPATH_CTRLR, OPEN_FLAG_READ);
+ file_error filerr = file.open(controller, ".cfg");
if (filerr != FILERR_NONE)
throw emu_fatalerror("Could not load controller file %s.cfg", controller);
@@ -125,26 +123,18 @@ int config_load_settings(running_machine *machine)
/* load the XML */
if (!config_load_xml(machine, file, CONFIG_TYPE_CONTROLLER))
throw emu_fatalerror("Could not load controller file %s.cfg", controller);
- mame_fclose(file);
}
/* next load the defaults file */
- filerr = mame_fopen(SEARCHPATH_CONFIG, "default.cfg", OPEN_FLAG_READ, &file);
+ emu_file file(machine->options(), SEARCHPATH_CONFIG, OPEN_FLAG_READ);
+ file_error filerr = file.open("default.cfg");
if (filerr == FILERR_NONE)
- {
config_load_xml(machine, file, CONFIG_TYPE_DEFAULT);
- mame_fclose(file);
- }
/* finally, load the game-specific file */
- astring fname(machine->basename(), ".cfg");
- filerr = mame_fopen(SEARCHPATH_CONFIG, fname, OPEN_FLAG_READ, &file);
-
+ filerr = file.open(machine->basename(), ".cfg");
if (filerr == FILERR_NONE)
- {
loaded = config_load_xml(machine, file, CONFIG_TYPE_GAME);
- mame_fclose(file);
- }
/* loop over all registrants and call their final function */
for (type = typelist; type; type = type->next)
@@ -158,31 +148,22 @@ int config_load_settings(running_machine *machine)
void config_save_settings(running_machine *machine)
{
- file_error filerr;
config_type *type;
- mame_file *file;
/* loop over all registrants and call their init function */
for (type = typelist; type; type = type->next)
(*type->save)(machine, CONFIG_TYPE_INIT, NULL);
/* save the defaults file */
- filerr = mame_fopen(SEARCHPATH_CONFIG, "default.cfg", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ emu_file file(machine->options(), SEARCHPATH_CONFIG, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open("default.cfg");
if (filerr == FILERR_NONE)
- {
config_save_xml(machine, file, CONFIG_TYPE_DEFAULT);
- mame_fclose(file);
- }
/* finally, save the game-specific file */
- astring fname(machine->basename(), ".cfg");
- filerr = mame_fopen(SEARCHPATH_CONFIG, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
-
+ filerr = file.open(machine->basename(), ".cfg");
if (filerr == FILERR_NONE)
- {
config_save_xml(machine, file, CONFIG_TYPE_GAME);
- mame_fclose(file);
- }
/* loop over all registrants and call their final function */
for (type = typelist; type; type = type->next)
@@ -197,7 +178,7 @@ void config_save_settings(running_machine *machine)
*
*************************************/
-static int config_load_xml(running_machine *machine, mame_file *file, int which_type)
+static int config_load_xml(running_machine *machine, emu_file &file, int which_type)
{
xml_data_node *root, *confignode, *systemnode;
config_type *type;
@@ -205,7 +186,7 @@ static int config_load_xml(running_machine *machine, mame_file *file, int which_
int version, count;
/* read the file */
- root = xml_file_read(mame_core_file(file), NULL);
+ root = xml_file_read(file, NULL);
if (!root)
goto error;
@@ -298,7 +279,7 @@ error:
*
*************************************/
-static int config_save_xml(running_machine *machine, mame_file *file, int which_type)
+static int config_save_xml(running_machine *machine, emu_file &file, int which_type)
{
xml_data_node *root = xml_file_create();
xml_data_node *confignode, *systemnode;
@@ -335,7 +316,7 @@ static int config_save_xml(running_machine *machine, mame_file *file, int which_
}
/* flush the file */
- xml_file_write(root, mame_core_file(file));
+ xml_file_write(root, file);
/* free and get out of here */
xml_file_free(root);
diff --git a/src/emu/crsshair.c b/src/emu/crsshair.c
index 58493fb5e78..2c3d377259b 100644
--- a/src/emu/crsshair.c
+++ b/src/emu/crsshair.c
@@ -158,21 +158,22 @@ static void create_bitmap(running_machine *machine, int player)
global_free(global.bitmap[player]);
machine->render().texture_free(global.texture[player]);
+ emu_file crossfile(machine->options(), OPTION_CROSSHAIRPATH, OPEN_FLAG_READ);
if (global.name[player][0] != 0)
{
/* look for user specified file */
sprintf(filename, "%s.png", global.name[player]);
- global.bitmap[player] = render_load_png(OPTION_CROSSHAIRPATH, NULL, filename, NULL, NULL);
+ global.bitmap[player] = render_load_png(crossfile, NULL, filename, NULL, NULL);
}
else
{
/* look for default cross?.png in crsshair\game dir */
sprintf(filename, "cross%d.png", player + 1);
- global.bitmap[player] = render_load_png(OPTION_CROSSHAIRPATH, machine->gamedrv->name, filename, NULL, NULL);
+ global.bitmap[player] = render_load_png(crossfile, machine->gamedrv->name, filename, NULL, NULL);
/* look for default cross?.png in crsshair dir */
if (global.bitmap[player] == NULL)
- global.bitmap[player] = render_load_png(OPTION_CROSSHAIRPATH, NULL, filename, NULL, NULL);
+ global.bitmap[player] = render_load_png(crossfile, NULL, filename, NULL, NULL);
}
/* if that didn't work, use the built-in one */
diff --git a/src/emu/debug/debugcmd.c b/src/emu/debug/debugcmd.c
index 4a9e5eeae75..823abab8927 100644
--- a/src/emu/debug/debugcmd.c
+++ b/src/emu/debug/debugcmd.c
@@ -372,7 +372,7 @@ void debug_command_init(running_machine *machine)
machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_command_exit);
/* set up the initial debugscript if specified */
- name = options_get_string(machine->options(), OPTION_DEBUGSCRIPT);
+ name = options_get_string(&machine->options(), OPTION_DEBUGSCRIPT);
if (name[0] != 0)
debug_cpu_source_script(machine, name);
}
@@ -2489,8 +2489,6 @@ static void execute_snap(running_machine *machine, int ref, int params, const ch
/* otherwise, we have to open the file ourselves */
else
{
- file_error filerr;
- mame_file *fp;
const char *filename = param[0];
int scrnum = (params > 1) ? atoi(param[1]) : 0;
@@ -2505,7 +2503,8 @@ static void execute_snap(running_machine *machine, int ref, int params, const ch
astring fname(filename);
if (fname.find(0, ".png") == -1)
fname.cat(".png");
- filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp);
+ emu_file file(machine->options(), SEARCHPATH_SCREENSHOT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(fname);
if (filerr != FILERR_NONE)
{
@@ -2513,8 +2512,7 @@ static void execute_snap(running_machine *machine, int ref, int params, const ch
return;
}
- screen->machine->video().save_snapshot(screen, *fp);
- mame_fclose(fp);
+ screen->machine->video().save_snapshot(screen, file);
debug_console_printf(machine, "Saved screen #%d snapshot as '%s'\n", scrnum, filename);
}
}
diff --git a/src/emu/debug/debugcpu.c b/src/emu/debug/debugcpu.c
index 36ffd230268..f959d20edc6 100644
--- a/src/emu/debug/debugcpu.c
+++ b/src/emu/debug/debugcpu.c
@@ -359,15 +359,10 @@ bool debug_comment_save(running_machine *machine)
// flush the file
if (found_comments)
{
- astring fname(machine->basename(), ".cmt");
- mame_file *fp;
- file_error filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp);
-
+ emu_file file(machine->options(), SEARCHPATH_COMMENT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(machine->basename(), ".cmt");
if (filerr == FILERR_NONE)
- {
- xml_file_write(root, mame_core_file(fp));
- mame_fclose(fp);
- }
+ xml_file_write(root, file);
}
}
catch (emu_exception &)
@@ -390,16 +385,15 @@ bool debug_comment_save(running_machine *machine)
bool debug_comment_load(running_machine *machine)
{
// open the file
- astring fname(machine->basename(), ".cmt");
- mame_file *fp;
- file_error filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_READ, &fp);
+ emu_file file(machine->options(), SEARCHPATH_COMMENT, OPEN_FLAG_READ);
+ file_error filerr = file.open(machine->basename(), ".cmt");
// if an error, just return false
if (filerr != FILERR_NONE)
return false;
// wrap in a try/catch to handle errors
- xml_data_node *root = xml_file_read(mame_core_file(fp), NULL);
+ xml_data_node *root = xml_file_read(file, NULL);
try
{
// read the file
@@ -436,13 +430,11 @@ bool debug_comment_load(running_machine *machine)
// clean up in case of error
if (root != NULL)
xml_file_free(root);
- mame_fclose(fp);
return false;
}
// free the parser
xml_file_free(root);
- mame_fclose(fp);
return true;
}
diff --git a/src/emu/devimage.c b/src/emu/devimage.c
index e1cb51a49fa..7161849506f 100644
--- a/src/emu/devimage.c
+++ b/src/emu/devimage.c
@@ -325,7 +325,7 @@ bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_ent
// " swlist % clonename % parentname "
// below, we have 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(m_machine.options(), swlist, FALSE, NULL);
if (software_list_ptr)
{
for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; )
@@ -337,7 +337,7 @@ bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_ent
locationtag.cat(breakstr);
//printf("%s\n", locationtag.cstr());
}
- const char *parentname = software_get_clone(swlist, swinfo->shortname);
+ const char *parentname = software_get_clone(m_machine.options(), swlist, swinfo->shortname);
if (parentname != NULL)
swinfo = software_list_find(software_list_ptr, parentname, NULL);
else
@@ -348,10 +348,10 @@ bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_ent
software_list_close(software_list_ptr);
}
- if (software_get_support(swlist, swname) == SOFTWARE_SUPPORTED_PARTIAL)
+ if (software_get_support(m_machine.options(), swlist, swname) == SOFTWARE_SUPPORTED_PARTIAL)
mame_printf_error("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist);
- if (software_get_support(swlist, swname) == SOFTWARE_SUPPORTED_NO)
+ if (software_get_support(m_machine.options(), swlist, swname) == SOFTWARE_SUPPORTED_NO)
mame_printf_error("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist);
// check if locationtag actually contains two locations separated by '%'
@@ -381,20 +381,20 @@ bool legacy_image_device_base::load_software(char *swlist, char *swname, rom_ent
// - if we are using lists, we have: list/clonename, list/parentname, clonename, parentname
// try to load from list/setname
if ((m_mame_file == NULL) && (tag2.cstr() != NULL))
- filerr = common_process_file(tag2.cstr(), has_crc, crc, romp, &m_mame_file);
+ filerr = common_process_file(m_machine.options(), tag2.cstr(), has_crc, crc, romp, &m_mame_file);
// try to load from list/parentname
if ((m_mame_file == NULL) && (tag3.cstr() != NULL))
- filerr = common_process_file(tag3.cstr(), has_crc, crc, romp, &m_mame_file);
+ filerr = common_process_file(m_machine.options(), tag3.cstr(), has_crc, crc, romp, &m_mame_file);
// try to load from setname
if ((m_mame_file == NULL) && (tag4.cstr() != NULL))
- filerr = common_process_file(tag4.cstr(), has_crc, crc, romp, &m_mame_file);
+ filerr = common_process_file(m_machine.options(), tag4.cstr(), has_crc, crc, romp, &m_mame_file);
// try to load from parentname
if ((m_mame_file == NULL) && (tag5.cstr() != NULL))
- filerr = common_process_file(tag5.cstr(), has_crc, crc, romp, &m_mame_file);
+ filerr = common_process_file(m_machine.options(), tag5.cstr(), has_crc, crc, romp, &m_mame_file);
if (filerr == FILERR_NONE)
{
- m_file = mame_core_file(m_mame_file);
+ m_file = *m_mame_file;
retVal = TRUE;
}
@@ -588,7 +588,7 @@ void legacy_image_device_base::clear()
{
if (m_mame_file)
{
- mame_fclose(m_mame_file);
+ global_free(m_mame_file);
m_mame_file = NULL;
m_file = NULL;
} else {
diff --git a/src/emu/devintrf.c b/src/emu/devintrf.c
index 3fc292e60e0..cf1f26a6e4f 100644
--- a/src/emu/devintrf.c
+++ b/src/emu/devintrf.c
@@ -269,7 +269,7 @@ void device_config_interface::interface_config_complete()
// constructed
//-------------------------------------------------
-bool device_config_interface::interface_validity_check(const game_driver &driver) const
+bool device_config_interface::interface_validity_check(core_options &options, const game_driver &driver) const
{
return false;
}
@@ -336,17 +336,17 @@ void device_config::config_complete()
// configuration has been constructed
//-------------------------------------------------
-bool device_config::validity_check(const game_driver &driver) const
+bool device_config::validity_check(core_options &options, const game_driver &driver) const
{
bool error = false;
// validate via the interfaces
for (device_config_interface *intf = m_interface_list; intf != NULL; intf = intf->interface_next())
- if (intf->interface_validity_check(driver))
+ if (intf->interface_validity_check(options, driver))
error = true;
// let the device itself validate
- if (device_validity_check(driver))
+ if (device_validity_check(options, driver))
error = true;
return error;
@@ -370,7 +370,7 @@ void device_config::device_config_complete()
// the configuration has been constructed
//-------------------------------------------------
-bool device_config::device_validity_check(const game_driver &driver) const
+bool device_config::device_validity_check(core_options &options, const game_driver &driver) const
{
// indicate no error by default
return false;
diff --git a/src/emu/devintrf.h b/src/emu/devintrf.h
index f1d18c40339..79b84a0da37 100644
--- a/src/emu/devintrf.h
+++ b/src/emu/devintrf.h
@@ -291,7 +291,7 @@ public:
// methods that wrap both interface-level and device-level behavior
void config_complete();
- bool validity_check(const game_driver &driver) const;
+ bool validity_check(core_options &options, const game_driver &driver) const;
// configuration helpers
static void static_set_clock(device_config *device, UINT32 clock) { device->m_clock = clock; }
@@ -305,7 +305,7 @@ public:
// optional operation overrides
protected:
virtual void device_config_complete();
- virtual bool device_validity_check(const game_driver &driver) const;
+ virtual bool device_validity_check(core_options &options, const game_driver &driver) const;
public:
// optional information overrides
@@ -359,7 +359,7 @@ public:
// optional operation overrides
virtual void interface_config_complete();
- virtual bool interface_validity_check(const game_driver &driver) const;
+ virtual bool interface_validity_check(core_options &options, const game_driver &driver) const;
protected:
const device_config & m_device_config;
diff --git a/src/emu/devlegcy.c b/src/emu/devlegcy.c
index f6b73aba3f2..1af3c5d46c0 100644
--- a/src/emu/devlegcy.c
+++ b/src/emu/devlegcy.c
@@ -192,11 +192,11 @@ void legacy_device_config_base::static_set_inline_float(device_config *device, U
// checks on a device configuration
//-------------------------------------------------
-bool legacy_device_config_base::device_validity_check(const game_driver &driver) const
+bool legacy_device_config_base::device_validity_check(core_options &options, const game_driver &driver) const
{
device_validity_check_func validity_func = reinterpret_cast<device_validity_check_func>(get_legacy_config_fct(DEVINFO_FCT_VALIDITY_CHECK));
if (validity_func != NULL)
- return (*validity_func)(&driver, this);
+ return (*validity_func)(&driver, this, options);
return false;
}
@@ -402,7 +402,7 @@ void legacy_nvram_device_base::nvram_default()
// nvram_read - read NVRAM from the given file
//-------------------------------------------------
-void legacy_nvram_device_base::nvram_read(mame_file &file)
+void legacy_nvram_device_base::nvram_read(emu_file &file)
{
device_nvram_func nvram_func = reinterpret_cast<device_nvram_func>(m_config.get_legacy_config_fct(DEVINFO_FCT_NVRAM));
(*nvram_func)(this, &file, FALSE);
@@ -413,7 +413,7 @@ void legacy_nvram_device_base::nvram_read(mame_file &file)
// nvram_write - write NVRAM to the given file
//-------------------------------------------------
-void legacy_nvram_device_base::nvram_write(mame_file &file)
+void legacy_nvram_device_base::nvram_write(emu_file &file)
{
device_nvram_func nvram_func = reinterpret_cast<device_nvram_func>(m_config.get_legacy_config_fct(DEVINFO_FCT_NVRAM));
(*nvram_func)(this, &file, TRUE);
diff --git a/src/emu/devlegcy.h b/src/emu/devlegcy.h
index 4ad8e3f434a..f7a960d0d42 100644
--- a/src/emu/devlegcy.h
+++ b/src/emu/devlegcy.h
@@ -247,7 +247,7 @@ const device_type name = configclass::static_alloc_device_config
#define DEVICE_GET_INFO_CALL(name) DEVICE_GET_INFO_NAME(name)(device, state, info)
#define DEVICE_VALIDITY_CHECK_NAME(name) device_validity_check_##name
-#define DEVICE_VALIDITY_CHECK(name) int DEVICE_VALIDITY_CHECK_NAME(name)(const game_driver *driver, const device_config *device)
+#define DEVICE_VALIDITY_CHECK(name) int DEVICE_VALIDITY_CHECK_NAME(name)(const game_driver *driver, const device_config *device, core_options &options)
#define DEVICE_VALIDITY_CHECK_CALL(name) DEVICE_VALIDITY_CHECK_NAME(name)(driver, device)
#define DEVICE_START_NAME(name) device_start_##name
@@ -267,7 +267,7 @@ const device_type name = configclass::static_alloc_device_config
#define DEVICE_EXECUTE_CALL(name) DEVICE_EXECUTE_NAME(name)(device, clocks)
#define DEVICE_NVRAM_NAME(name) device_nvram_##name
-#define DEVICE_NVRAM(name) void DEVICE_NVRAM_NAME(name)(device_t *device, mame_file *file, int read_or_write)
+#define DEVICE_NVRAM(name) void DEVICE_NVRAM_NAME(name)(device_t *device, emu_file *file, int read_or_write)
#define DEVICE_NVRAM_CALL(name) DEVICE_NVRAM_NAME(name)(device, file, read_or_write)
@@ -382,13 +382,13 @@ resource_pool &machine_get_pool(running_machine &machine);
// device interface function types
typedef void (*device_get_config_func)(const device_config *device, UINT32 state, deviceinfo *info);
-typedef int (*device_validity_check_func)(const game_driver *driver, const device_config *device);
+typedef int (*device_validity_check_func)(const game_driver *driver, const device_config *device, core_options &options);
typedef void (*device_start_func)(device_t *device);
typedef void (*device_stop_func)(device_t *device);
typedef INT32 (*device_execute_func)(device_t *device, INT32 clocks);
typedef void (*device_reset_func)(device_t *device);
-typedef void (*device_nvram_func)(device_t *device, mame_file *file, int read_or_write);
+typedef void (*device_nvram_func)(device_t *device, emu_file *file, int read_or_write);
// the actual deviceinfo union
union deviceinfo
@@ -447,7 +447,7 @@ public:
protected:
// overrides
- virtual bool device_validity_check(const game_driver &driver) const;
+ virtual bool device_validity_check(core_options &options, const game_driver &driver) const;
// access to legacy configuration info
INT64 get_legacy_config_int(UINT32 state) const;
@@ -577,8 +577,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
};
// ======================> legacy_image_device_config
diff --git a/src/emu/diexec.c b/src/emu/diexec.c
index cf1404d8abe..43f28ecc8ba 100644
--- a/src/emu/diexec.c
+++ b/src/emu/diexec.c
@@ -211,7 +211,7 @@ UINT32 device_config_execute_interface::execute_default_irq_vector() const
// constructed
//-------------------------------------------------
-bool device_config_execute_interface::interface_validity_check(const game_driver &driver) const
+bool device_config_execute_interface::interface_validity_check(core_options &options, const game_driver &driver) const
{
const device_config *devconfig = crosscast<const device_config *>(this);
bool error = false;
diff --git a/src/emu/diexec.h b/src/emu/diexec.h
index c0904631fb6..9404c6e85de 100644
--- a/src/emu/diexec.h
+++ b/src/emu/diexec.h
@@ -177,7 +177,7 @@ protected:
virtual UINT32 execute_default_irq_vector() const;
// optional operation overrides
- virtual bool interface_validity_check(const game_driver &driver) const;
+ virtual bool interface_validity_check(core_options &options, const game_driver &driver) const;
bool m_disabled;
device_interrupt_func m_vblank_interrupt; // for interrupts tied to VBLANK
diff --git a/src/emu/diimage.c b/src/emu/diimage.c
index 7d126aa06bd..af385d482b1 100644
--- a/src/emu/diimage.c
+++ b/src/emu/diimage.c
@@ -531,7 +531,7 @@ int device_image_interface::read_hash_config(const char *sysname)
const hash_info *info = NULL;
/* open the hash file */
- hashfile = hashfile_open(sysname, FALSE, NULL);
+ hashfile = hashfile_open(device().machine->options(), sysname, FALSE, NULL);
if (!hashfile)
goto done;
@@ -652,7 +652,7 @@ void device_image_interface::battery_load(void *buffer, int length, int fill)
{
astring *fname = astring_assemble_4(astring_alloc(), device().machine->gamedrv->name, PATH_SEPARATOR, m_basename_noext, ".nv");
- image_battery_load_by_name(astring_c(fname), buffer, length, fill);
+ image_battery_load_by_name(device().machine->options(), astring_c(fname), buffer, length, fill);
astring_free(fname);
}
@@ -666,7 +666,7 @@ void device_image_interface::battery_save(const void *buffer, int length)
{
astring *fname = astring_assemble_4(astring_alloc(), device().machine->gamedrv->name, PATH_SEPARATOR, m_basename_noext, ".nv");
- image_battery_save_by_name(astring_c(fname), buffer, length);
+ image_battery_save_by_name(device().machine->options(), astring_c(fname), buffer, length);
astring_free(fname);
}
diff --git a/src/emu/diimage.h b/src/emu/diimage.h
index 6c2c54ee2aa..66cce47ced9 100644
--- a/src/emu/diimage.h
+++ b/src/emu/diimage.h
@@ -295,7 +295,7 @@ protected:
/* variables that are only non-zero when an image is mounted */
core_file *m_file;
- mame_file *m_mame_file;
+ emu_file *m_mame_file;
astring m_name;
astring m_basename;
astring m_basename_noext;
diff --git a/src/emu/dimemory.c b/src/emu/dimemory.c
index f120f64aa00..88845dac57a 100644
--- a/src/emu/dimemory.c
+++ b/src/emu/dimemory.c
@@ -164,7 +164,7 @@ void device_config_memory_interface::static_set_addrmap(device_config *device, i
// checks on the memory configuration
//-------------------------------------------------
-bool device_config_memory_interface::interface_validity_check(const game_driver &driver) const
+bool device_config_memory_interface::interface_validity_check(core_options &options, const game_driver &driver) const
{
const device_config *devconfig = crosscast<const device_config *>(this);
bool detected_overlap = DETECT_OVERLAPPING_MEMORY ? false : true;
diff --git a/src/emu/dimemory.h b/src/emu/dimemory.h
index 9ee9b0847dd..5cdbc12c544 100644
--- a/src/emu/dimemory.h
+++ b/src/emu/dimemory.h
@@ -123,7 +123,7 @@ protected:
virtual const address_space_config *memory_space_config(int spacenum) const = 0;
// optional operation overrides
- virtual bool interface_validity_check(const game_driver &driver) const;
+ virtual bool interface_validity_check(core_options &options, const game_driver &driver) const;
address_map_constructor m_address_map[ADDRESS_SPACES]; // address maps for each address space
};
diff --git a/src/emu/dinvram.h b/src/emu/dinvram.h
index ec7babd3bad..f1051dce25d 100644
--- a/src/emu/dinvram.h
+++ b/src/emu/dinvram.h
@@ -80,14 +80,14 @@ public:
// public accessors... for now
void nvram_reset() { nvram_default(); }
- void nvram_load(mame_file &file) { nvram_read(file); }
- void nvram_save(mame_file &file) { nvram_write(file); }
+ void nvram_load(emu_file &file) { nvram_read(file); }
+ void nvram_save(emu_file &file) { nvram_write(file); }
protected:
// derived class overrides
virtual void nvram_default() = 0;
- virtual void nvram_read(mame_file &file) = 0;
- virtual void nvram_write(mame_file &file) = 0;
+ virtual void nvram_read(emu_file &file) = 0;
+ virtual void nvram_write(emu_file &file) = 0;
// configuration
const device_config_nvram_interface &m_nvram_config; // reference to our device_config_execute_interface
diff --git a/src/emu/disound.c b/src/emu/disound.c
index 839de2b8a0c..e4ca9e4e1c7 100644
--- a/src/emu/disound.c
+++ b/src/emu/disound.c
@@ -104,7 +104,7 @@ void device_config_sound_interface::static_reset_routes(device_config *device)
// constructed
//-------------------------------------------------
-bool device_config_sound_interface::interface_validity_check(const game_driver &driver) const
+bool device_config_sound_interface::interface_validity_check(core_options &options, const game_driver &driver) const
{
bool error = false;
diff --git a/src/emu/disound.h b/src/emu/disound.h
index c4373bd066a..c51ec68439f 100644
--- a/src/emu/disound.h
+++ b/src/emu/disound.h
@@ -127,7 +127,7 @@ public:
protected:
// optional operation overrides
- virtual bool interface_validity_check(const game_driver &driver) const;
+ virtual bool interface_validity_check(core_options &options, const game_driver &driver) const;
// internal state
simple_list<sound_route> m_route_list; // list of sound routes
diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c
index 30c5df10bfa..4f1f677126d 100644
--- a/src/emu/emuopts.c
+++ b/src/emu/emuopts.c
@@ -213,10 +213,10 @@ const char *image_get_device_option(device_image_interface *image)
{
const char *result = NULL;
- if (options_get_bool(image->device().machine->options(), OPTION_ADDED_DEVICE_OPTIONS))
+ if (options_get_bool(&image->device().machine->options(), OPTION_ADDED_DEVICE_OPTIONS))
{
/* access the option */
- result = options_get_string_priority(image->device().machine->options(), image->image_config().instance_name(), OPTION_PRIORITY_DRIVER_INI);
+ result = options_get_string_priority(&image->device().machine->options(), image->image_config().instance_name(), OPTION_PRIORITY_DRIVER_INI);
}
return result;
}
diff --git a/src/emu/fileio.c b/src/emu/fileio.c
index d81b914db7c..975346f2c90 100644
--- a/src/emu/fileio.c
+++ b/src/emu/fileio.c
@@ -4,8 +4,36 @@
File access functions.
- Copyright Nicola Salmoria and the MAME Team.
- Visit http://mamedev.org for licensing and usage restrictions.
+****************************************************************************
+
+ Copyright Aaron Giles
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name 'MAME' nor the names of its contributors may be
+ used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
@@ -16,884 +44,688 @@
#include "fileio.h"
-/***************************************************************************
- CONSTANTS
-***************************************************************************/
-
-#define PLAIN_FILE 0
-#define ZIPPED_FILE 1
-
-#define OPEN_FLAG_HAS_CRC 0x10000
+const UINT32 OPEN_FLAG_HAS_CRC = 0x10000;
-#ifdef MAME_DEBUG
-#define DEBUG_COOKIE 0xbaadf00d
-#endif
+//**************************************************************************
+// PATH ITERATOR
+//**************************************************************************
-/***************************************************************************
- TYPE DEFINITIONS
-***************************************************************************/
+//-------------------------------------------------
+// path_iterator - constructor
+//-------------------------------------------------
-typedef struct _path_iterator path_iterator;
-struct _path_iterator
+path_iterator::path_iterator(core_options &opts, const char *searchpath)
+ : m_base((searchpath != NULL && !osd_is_absolute_path(searchpath)) ? options_get_string(&opts, searchpath) : ""),
+ m_current(m_base),
+ m_index(0)
{
- const char * base;
- const char * cur;
- int index;
-};
+}
-/* typedef struct _mame_file mame_file -- declared in fileio.h */
-struct _mame_file
-{
-#ifdef DEBUG_COOKIE
- UINT32 debug_cookie; /* sanity checking for debugging */
-#endif
- astring filename; /* full filename */
- core_file * file; /* core file pointer */
- path_iterator iterator; /* iterator for paths */
- UINT32 openflags; /* flags we used for the open */
- char hash[HASH_BUF_SIZE]; /* hash data for the file */
- zip_file * zipfile; /* ZIP file pointer */
- UINT8 * zipdata; /* ZIP file data */
- UINT64 ziplength; /* ZIP file length */
-};
+//-------------------------------------------------
+// path_iterator_get_next - get the next entry
+// in a multipath sequence
+//-------------------------------------------------
-
-/* typedef struct _mame_path mame_path -- declared in fileio.h */
-struct _mame_path
+bool path_iterator::next(astring &buffer)
{
- path_iterator iterator;
- osd_directory * curdir;
- astring pathbuffer;
- int buflen;
-};
-
-
-
-/***************************************************************************
- FUNCTION PROTOTYPES
-***************************************************************************/
-
-/* core functions */
-static void fileio_exit(running_machine &machine);
+ // if none left, return FALSE to indicate we are done
+ if (m_index != 0 && *m_current == 0)
+ return false;
-/* file open/close */
-static file_error fopen_internal(core_options *opts, path_iterator *iterator, const char *filename, UINT32 crc, UINT32 flags, mame_file **file);
-static file_error fopen_attempt_zipped(astring &fullname, UINT32 crc, UINT32 openflags, mame_file *file);
+ // copy up to the next semicolon
+ const char *semi = strchr(m_current, ';');
+ if (semi == NULL)
+ semi = m_current + strlen(m_current);
+ buffer.cpy(m_current, semi - m_current);
+ m_current = (*semi == 0) ? semi : semi + 1;
-/* path iteration */
-static void path_iterator_init(path_iterator *iterator, core_options *opts, const char *searchpath);
-static int path_iterator_get_next(path_iterator *iterator, astring &buffer);
+ // bump the index and return TRUE
+ m_index++;
+ return true;
+}
-/* misc helpers */
-static file_error load_zipped_file(mame_file *file);
-static int zip_filename_match(const zip_file_header *header, const astring &afilename);
-static int zip_header_is_path(const zip_file_header *header);
+//**************************************************************************
+// FILE ENUMERATOR
+//**************************************************************************
-/***************************************************************************
- CORE FUNCTIONS
-***************************************************************************/
+//-------------------------------------------------
+// file_enumerator - constructor
+//-------------------------------------------------
-/*-------------------------------------------------
- fileio_init - initialize the internal file
- I/O system; note that the OS layer is free to
- call mame_fopen before fileio_init
--------------------------------------------------*/
-
-void fileio_init(running_machine *machine)
+file_enumerator::file_enumerator(core_options &options, const char *searchpath)
+ : m_iterator(options, searchpath),
+ m_curdir(NULL),
+ m_buflen(0)
{
- machine->add_notifier(MACHINE_NOTIFY_EXIT, fileio_exit);
}
-/*-------------------------------------------------
- fileio_exit - clean up behind ourselves
--------------------------------------------------*/
+//-------------------------------------------------
+// ~file_enumerator - destructor
+//-------------------------------------------------
-static void fileio_exit(running_machine &machine)
+file_enumerator::~file_enumerator()
{
- zip_file_cache_clear();
+ // close anything open
+ if (m_curdir != NULL)
+ osd_closedir(m_curdir);
}
+//-------------------------------------------------
+// next - return information about the next file
+// in the search path
+//-------------------------------------------------
-/***************************************************************************
- FILE OPEN/CLOSE
-***************************************************************************/
-
-/*-------------------------------------------------
- mame_fopen - open a file for access and
- return an error code
--------------------------------------------------*/
-
-file_error mame_fopen(const char *searchpath, const char *filename, UINT32 openflags, mame_file **file)
+const osd_directory_entry *file_enumerator::next()
{
- path_iterator iterator;
- path_iterator_init(&iterator, mame_options(), searchpath);
- return fopen_internal(mame_options(), &iterator, filename, 0, openflags, file);
-}
+ // loop over potentially empty directories
+ while (1)
+ {
+ // if no open directory, get the next path
+ while (m_curdir == NULL)
+ {
+ // if we fail to get anything more, we're done
+ if (!m_iterator.next(m_pathbuffer))
+ return NULL;
+ // open the path
+ m_curdir = osd_opendir(m_pathbuffer);
+ }
-/*-------------------------------------------------
- mame_fopen_crc - open a file by name or CRC
- and return an error code
--------------------------------------------------*/
+ // get the next entry from the current directory
+ const osd_directory_entry *result = osd_readdir(m_curdir);
+ if (result != NULL)
+ return result;
-file_error mame_fopen_crc(const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
-{
- path_iterator iterator;
- path_iterator_init(&iterator, mame_options(), searchpath);
- return mame_fopen_crc_options(mame_options(), searchpath, filename, crc, openflags, file);
+ // we're done; close this directory
+ osd_closedir(m_curdir);
+ m_curdir = NULL;
+ }
}
-/*-------------------------------------------------
- mame_fopen_options - open a file for access and
- return an error code
--------------------------------------------------*/
-
-file_error mame_fopen_options(core_options *opts, const char *searchpath, const char *filename, UINT32 openflags, mame_file **file)
-{
- path_iterator iterator;
- path_iterator_init(&iterator, opts, searchpath);
- return fopen_internal(opts, &iterator, filename, 0, openflags, file);
-}
+//**************************************************************************
+// EMU FILE
+//**************************************************************************
-/*-------------------------------------------------
- mame_fopen_crc_options - open a file by name
- or CRC and return an error code
--------------------------------------------------*/
+//-------------------------------------------------
+// emu_file - constructor
+//-------------------------------------------------
-file_error mame_fopen_crc_options(core_options *opts, const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
+emu_file::emu_file(core_options &options, const char *searchpath, UINT32 openflags)
+ : m_file(NULL),
+ m_iterator(options, searchpath),
+ m_crc(0),
+ m_openflags(openflags),
+ m_zipfile(NULL),
+ m_zipdata(NULL),
+ m_ziplength(0),
+ m_remove_on_close(false)
{
- path_iterator iterator;
- path_iterator_init(&iterator, opts, searchpath);
- return fopen_internal(opts, &iterator, filename, crc, openflags | OPEN_FLAG_HAS_CRC, file);
+ // sanity check the open flags
+ if ((m_openflags & OPEN_FLAG_HAS_CRC) && (m_openflags & OPEN_FLAG_WRITE))
+ throw emu_fatalerror("Attempted to open a file for write with OPEN_FLAG_HAS_CRC");
}
-/*-------------------------------------------------
- mame_fopen_ram - open a "file" which is
- actually just an array of data in RAM
--------------------------------------------------*/
+//-------------------------------------------------
+// ~emu_file - destructor
+//-------------------------------------------------
-file_error mame_fopen_ram(const void *data, UINT32 length, UINT32 openflags, mame_file **file)
+emu_file::~emu_file()
{
- file_error filerr;
+ // close in the standard way
+ close();
+}
- /* allocate the file itself */
- *file = global_alloc_clear(mame_file);
- /* reset the file handle */
- (*file)->openflags = openflags;
-#ifdef DEBUG_COOKIE
- (*file)->debug_cookie = DEBUG_COOKIE;
-#endif
+//-------------------------------------------------
+// operator core_file - automatically convert
+// ourselves to a core_file pointer
+//-------------------------------------------------
- /* attempt to open the file directly */
- filerr = core_fopen_ram(data, length, openflags, &(*file)->file);
- if (filerr == FILERR_NONE)
- goto error;
+emu_file::operator core_file *()
+{
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return NULL;
- /* handle errors and return */
-error:
- if (filerr != FILERR_NONE)
- {
- mame_fclose(*file);
- *file = NULL;
- }
- return filerr;
+ // return the core file
+ return m_file;
}
-/*-------------------------------------------------
- fopen_internal - open a file
--------------------------------------------------*/
+//-------------------------------------------------
+// hash - returns the hash for a file
+//-------------------------------------------------
-static file_error fopen_internal(core_options *opts, path_iterator *iterator, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
+const char *emu_file::hash_string(UINT32 functions)
{
- file_error filerr = FILERR_NOT_FOUND;
-
- /* can either have a hash or open for write, but not both */
- if ((openflags & OPEN_FLAG_HAS_CRC) && (openflags & OPEN_FLAG_WRITE))
- return FILERR_INVALID_ACCESS;
+ // if we already have the functions we need, just return
+ UINT32 wehave = hash_data_used_functions(m_hash);
+ if ((wehave & functions) == functions)
+ return m_hash;
- /* allocate the file itself */
- *file = global_alloc_clear(mame_file);
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return m_hash;
+ if (m_file == NULL)
+ return m_hash;
- /* reset the file handle */
- (*file)->openflags = openflags;
-#ifdef DEBUG_COOKIE
- (*file)->debug_cookie = DEBUG_COOKIE;
-#endif
+ // read the data if we can
+ const UINT8 *filedata = (const UINT8 *)core_fbuffer(m_file);
+ if (filedata == NULL)
+ return m_hash;
- /* loop over paths */
- while (path_iterator_get_next(iterator, (*file)->filename))
- {
- /* compute the full pathname */
- if ((*file)->filename.len() > 0)
- (*file)->filename.cat(PATH_SEPARATOR);
- (*file)->filename.cat(filename);
+ // compute the hash
+ hash_compute(m_hash, filedata, core_fsize(m_file), wehave | functions);
+ return m_hash;
+}
- /* attempt to open the file directly */
- filerr = core_fopen((*file)->filename, openflags, &(*file)->file);
- if (filerr == FILERR_NONE)
- break;
- /* if we're opening for read-only we have other options */
- if ((openflags & (OPEN_FLAG_READ | OPEN_FLAG_WRITE)) == OPEN_FLAG_READ)
- {
- filerr = fopen_attempt_zipped((*file)->filename, crc, openflags, *file);
- if (filerr == FILERR_NONE)
- break;
- }
- }
+//-------------------------------------------------
+// open - open a file by searching paths
+//-------------------------------------------------
- /* if we succeeded, save the iterator */
- if (filerr == FILERR_NONE)
- (*file)->iterator = *iterator;
+file_error emu_file::open(const char *name)
+{
+ // remember the filename and CRC info
+ m_filename = name;
+ m_crc = 0;
+ m_openflags &= ~OPEN_FLAG_HAS_CRC;
- /* handle errors and return */
- else
- {
- mame_fclose(*file);
- *file = NULL;
- }
- return filerr;
+ // reset the iterator and open_next
+ m_iterator.reset();
+ return open_next();
}
+file_error emu_file::open(const char *name1, const char *name2)
+{
+ // concatenate the strings and do a standard open
+ astring name(name1, name2);
+ return open(name);
+}
-/*-------------------------------------------------
- fopen_attempt_zipped - attempt to open a
- ZIPped file
--------------------------------------------------*/
-
-static file_error fopen_attempt_zipped(astring &fullname, UINT32 crc, UINT32 openflags, mame_file *file)
+file_error emu_file::open(const char *name1, const char *name2, const char *name3)
{
- astring filename;
- zip_error ziperr;
- zip_file *zip;
+ // concatenate the strings and do a standard open
+ astring name(name1, name2, name3);
+ return open(name);
+}
- /* loop over directory parts up to the start of filename */
- while (1)
- {
- const zip_file_header *header;
- int dirsep;
+file_error emu_file::open(const char *name1, const char *name2, const char *name3, const char *name4)
+{
+ // concatenate the strings and do a standard open
+ astring name(name1, name2, name3, name4);
+ return open(name);
+}
- /* find the final path separator */
- dirsep = fullname.rchr(0, PATH_SEPARATOR[0]);
- if (dirsep == -1)
- return FILERR_NOT_FOUND;
+file_error emu_file::open(const char *name, UINT32 crc)
+{
+ // remember the filename and CRC info
+ m_filename = name;
+ m_crc = crc;
+ m_openflags |= OPEN_FLAG_HAS_CRC;
- /* insert the part from the right of the separator into the head of the filename */
- if (filename.len() > 0)
- filename.ins(0, "/");
- filename.inssubstr(0, fullname, dirsep + 1, -1);
+ // reset the iterator and open_next
+ m_iterator.reset();
+ return open_next();
+}
- /* remove this part of the filename and append a .zip extension */
- fullname.substr(0, dirsep).cat(".zip");
+file_error emu_file::open(const char *name1, const char *name2, UINT32 crc)
+{
+ // concatenate the strings and do a standard open
+ astring name(name1, name2);
+ return open(name, crc);
+}
- /* attempt to open the ZIP file */
- ziperr = zip_file_open(fullname, &zip);
+file_error emu_file::open(const char *name1, const char *name2, const char *name3, UINT32 crc)
+{
+ // concatenate the strings and do a standard open
+ astring name(name1, name2, name3);
+ return open(name, crc);
+}
- /* chop the .zip back off the filename before continuing */
- fullname.substr(0, dirsep);
+file_error emu_file::open(const char *name1, const char *name2, const char *name3, const char *name4, UINT32 crc)
+{
+ // concatenate the strings and do a standard open
+ astring name(name1, name2, name3, name4);
+ return open(name, crc);
+}
- /* if we failed to open this file, continue scanning */
- if (ziperr != ZIPERR_NONE)
- continue;
- /* see if we can find a file with the right name and (if available) crc */
- for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip))
- if (zip_filename_match(header, filename) && (!(openflags & OPEN_FLAG_HAS_CRC) || header->crc == crc))
- break;
+//-------------------------------------------------
+// open_next - open the next file that matches
+// the filename by iterating over paths
+//-------------------------------------------------
- /* if that failed, look for a file with the right crc, but the wrong filename */
- if (header == NULL && (openflags & OPEN_FLAG_HAS_CRC))
- for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip))
- if (header->crc == crc && (!zip_header_is_path(header)))
- break;
+file_error emu_file::open_next()
+{
+ // if we're open from a previous attempt, close up now
+ if (m_file != NULL)
+ close();
+
+ // loop over paths
+ file_error filerr = FILERR_NOT_FOUND;
+ while (m_iterator.next(m_fullpath))
+ {
+ // compute the full pathname
+ if (m_fullpath.len() > 0)
+ m_fullpath.cat(PATH_SEPARATOR);
+ m_fullpath.cat(m_filename);
- /* if that failed, look for a file with the right name; reporting a bad checksum */
- /* is more helpful and less confusing than reporting "rom not found" */
- if (header == NULL)
- for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip))
- if (zip_filename_match(header, filename))
- break;
+ // attempt to open the file directly
+ filerr = core_fopen(m_fullpath, m_openflags, &m_file);
+ if (filerr == FILERR_NONE)
+ break;
- /* if we got it, read the data */
- if (header != NULL)
+ // if we're opening for read-only we have other options
+ if ((m_openflags & (OPEN_FLAG_READ | OPEN_FLAG_WRITE)) == OPEN_FLAG_READ)
{
- UINT8 crcs[4];
-
- file->zipfile = zip;
- file->ziplength = header->uncompressed_length;
-
- /* build a hash with just the CRC */
- hash_data_clear(file->hash);
- crcs[0] = header->crc >> 24;
- crcs[1] = header->crc >> 16;
- crcs[2] = header->crc >> 8;
- crcs[3] = header->crc >> 0;
- hash_data_insert_binary_checksum(file->hash, HASH_CRC, crcs);
-
- if (openflags & OPEN_FLAG_NO_PRELOAD)
- return FILERR_NONE;
- else
- return load_zipped_file(file);
+ filerr = attempt_zipped();
+ if (filerr == FILERR_NONE)
+ break;
}
-
- /* close up the ZIP file and try the next level */
- zip_file_close(zip);
}
+ return filerr;
}
-/*-------------------------------------------------
- mame_fclose - closes a file
--------------------------------------------------*/
+//-------------------------------------------------
+// open_ram - open a "file" which is actually
+// just an array of data in RAM
+//-------------------------------------------------
-void mame_fclose(mame_file *file)
+file_error emu_file::open_ram(const void *data, UINT32 length)
{
-#ifdef DEBUG_COOKIE
- assert(file->debug_cookie == DEBUG_COOKIE);
- file->debug_cookie = 0;
-#endif
-
- /* close files and free memory */
- if (file->zipfile != NULL)
- zip_file_close(file->zipfile);
- if (file->file != NULL)
- core_fclose(file->file);
- if (file->zipdata != NULL)
- global_free(file->zipdata);
- global_free(file);
+ // set a fake filename and CRC
+ m_filename = "RAM";
+ m_crc = 0;
+
+ // use the core_file's built-in RAM support
+ return core_fopen_ram(data, length, m_openflags, &m_file);
}
-/*-------------------------------------------------
- mame_fclose_and_open_next - close an open
- file, and open the next entry in the original
- searchpath
--------------------------------------------------*/
+//-------------------------------------------------
+// close - close a file and free all data; also
+// remove the file if requested
+//-------------------------------------------------
-file_error mame_fclose_and_open_next(mame_file **file, const char *filename, UINT32 openflags)
+void emu_file::close()
{
- path_iterator iterator = (*file)->iterator;
- mame_fclose(*file);
- *file = NULL;
- return fopen_internal(mame_options(), &iterator, filename, 0, openflags, file);
+ // close files and free memory
+ if (m_zipfile != NULL)
+ zip_file_close(m_zipfile);
+ m_zipfile = NULL;
+
+ if (m_file != NULL)
+ core_fclose(m_file);
+ m_file = NULL;
+
+ if (m_zipdata != NULL)
+ global_free(m_zipdata);
+ m_zipdata = NULL;
+
+ if (m_remove_on_close)
+ osd_rmfile(m_fullpath);
+ m_remove_on_close = false;
}
-/*-------------------------------------------------
- mame_fcompress - enable/disable streaming file
- compression via zlib; level is 0 to disable
- compression, or up to 9 for max compression
--------------------------------------------------*/
+//-------------------------------------------------
+// compress - enable/disable streaming file
+// compression via zlib; level is 0 to disable
+// compression, or up to 9 for max compression
+//-------------------------------------------------
-file_error mame_fcompress(mame_file *file, int level)
+file_error emu_file::compress(int level)
{
- return core_fcompress(file->file, level);
+ return core_fcompress(m_file, level);
}
+//-------------------------------------------------
+// seek - seek within a file
+//-------------------------------------------------
-/***************************************************************************
- FILE POSITIONING
-***************************************************************************/
-
-/*-------------------------------------------------
- mame_fseek - seek within a file
--------------------------------------------------*/
-
-int mame_fseek(mame_file *file, INT64 offset, int whence)
+int emu_file::seek(INT64 offset, int whence)
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return 1;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return 1;
- /* seek if we can */
- if (file->file != NULL)
- return core_fseek(file->file, offset, whence);
+ // seek if we can
+ if (m_file != NULL)
+ return core_fseek(m_file, offset, whence);
return 1;
}
-/*-------------------------------------------------
- mame_ftell - return the current file position
--------------------------------------------------*/
+//-------------------------------------------------
+// tell - return the current file position
+//-------------------------------------------------
-UINT64 mame_ftell(mame_file *file)
+UINT64 emu_file::tell()
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return 0;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return 0;
- /* tell if we can */
- if (file->file != NULL)
- return core_ftell(file->file);
+ // tell if we can
+ if (m_file != NULL)
+ return core_ftell(m_file);
return 0;
}
-/*-------------------------------------------------
- mame_feof - return 1 if we're at the end
- of file
--------------------------------------------------*/
+//-------------------------------------------------
+// eof - return true if we're at the end of file
+//-------------------------------------------------
-int mame_feof(mame_file *file)
+bool emu_file::eof()
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return 0;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return 0;
- /* return EOF if we can */
- if (file->file != NULL)
- return core_feof(file->file);
+ // return EOF if we can
+ if (m_file != NULL)
+ return core_feof(m_file);
return 0;
}
-/*-------------------------------------------------
- mame_fsize - returns the size of a file
--------------------------------------------------*/
+//-------------------------------------------------
+// size - returns the size of a file
+//-------------------------------------------------
-UINT64 mame_fsize(mame_file *file)
+UINT64 emu_file::size()
{
- /* use the ZIP length if present */
- if (file->zipfile != NULL)
- return file->ziplength;
+ // use the ZIP length if present
+ if (m_zipfile != NULL)
+ return m_ziplength;
- /* return length if we can */
- if (file->file != NULL)
- return core_fsize(file->file);
+ // return length if we can
+ if (m_file != NULL)
+ return core_fsize(m_file);
return 0;
}
+//-------------------------------------------------
+// read - read from a file
+//-------------------------------------------------
-/***************************************************************************
- FILE READ
-***************************************************************************/
-
-/*-------------------------------------------------
- mame_fread - read from a file
--------------------------------------------------*/
-
-UINT32 mame_fread(mame_file *file, void *buffer, UINT32 length)
+UINT32 emu_file::read(void *buffer, UINT32 length)
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return 0;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return 0;
- /* read the data if we can */
- if (file->file != NULL)
- return core_fread(file->file, buffer, length);
+ // read the data if we can
+ if (m_file != NULL)
+ return core_fread(m_file, buffer, length);
return 0;
}
-/*-------------------------------------------------
- mame_fgetc - read a character from a file
--------------------------------------------------*/
+//-------------------------------------------------
+// getc - read a character from a file
+//-------------------------------------------------
-int mame_fgetc(mame_file *file)
+int emu_file::getc()
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return EOF;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return EOF;
- /* read the data if we can */
- if (file->file != NULL)
- return core_fgetc(file->file);
+ // read the data if we can
+ if (m_file != NULL)
+ return core_fgetc(m_file);
return EOF;
}
-/*-------------------------------------------------
- mame_ungetc - put back a character read from
- a file
--------------------------------------------------*/
+//-------------------------------------------------
+// ungetc - put back a character read from a file
+//-------------------------------------------------
-int mame_ungetc(int c, mame_file *file)
+int emu_file::ungetc(int c)
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return 1;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return 1;
- /* read the data if we can */
- if (file->file != NULL)
- return core_ungetc(c, file->file);
+ // read the data if we can
+ if (m_file != NULL)
+ return core_ungetc(c, m_file);
return 1;
}
-/*-------------------------------------------------
- mame_fgets - read a line from a text file
--------------------------------------------------*/
+//-------------------------------------------------
+// gets - read a line from a text file
+//-------------------------------------------------
-char *mame_fgets(char *s, int n, mame_file *file)
+char *emu_file::gets(char *s, int n)
{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return NULL;
- }
+ // load the ZIP file now if we haven't yet
+ if (m_zipfile != NULL && load_zipped_file() != FILERR_NONE)
+ return NULL;
- /* read the data if we can */
- if (file->file != NULL)
- return core_fgets(s, n, file->file);
+ // read the data if we can
+ if (m_file != NULL)
+ return core_fgets(s, n, m_file);
return NULL;
}
+//-------------------------------------------------
+// write - write to a file
+//-------------------------------------------------
-/***************************************************************************
- FILE WRITE
-***************************************************************************/
-
-/*-------------------------------------------------
- mame_fwrite - write to a file
--------------------------------------------------*/
-
-UINT32 mame_fwrite(mame_file *file, const void *buffer, UINT32 length)
+UINT32 emu_file::write(const void *buffer, UINT32 length)
{
- /* write the data if we can */
- if (file->file != NULL)
- return core_fwrite(file->file, buffer, length);
+ // write the data if we can
+ if (m_file != NULL)
+ return core_fwrite(m_file, buffer, length);
return 0;
}
-/*-------------------------------------------------
- mame_fputs - write a line to a text file
--------------------------------------------------*/
+//-------------------------------------------------
+// puts - write a line to a text file
+//-------------------------------------------------
-int mame_fputs(mame_file *file, const char *s)
+int emu_file::puts(const char *s)
{
- /* write the data if we can */
- if (file->file != NULL)
- return core_fputs(file->file, s);
+ // write the data if we can
+ if (m_file != NULL)
+ return core_fputs(m_file, s);
return 0;
}
-/*-------------------------------------------------
- mame_vfprintf - vfprintf to a text file
--------------------------------------------------*/
-
-static int mame_vfprintf(mame_file *file, const char *fmt, va_list va)
-{
- /* write the data if we can */
- return (file->file != NULL) ? core_vfprintf(file->file, fmt, va) : 0;
-}
-
-
-/*-------------------------------------------------
- mame_fprintf - vfprintf to a text file
--------------------------------------------------*/
+//-------------------------------------------------
+// printf - vfprintf to a text file
+//-------------------------------------------------
-int CLIB_DECL mame_fprintf(mame_file *file, const char *fmt, ...)
+int CLIB_DECL emu_file::printf(const char *fmt, ...)
{
int rc;
va_list va;
va_start(va, fmt);
- rc = mame_vfprintf(file, fmt, va);
+ rc = vprintf(fmt, va);
va_end(va);
return rc;
}
+//-------------------------------------------------
+// mame_vfprintf - vfprintf to a text file
+//-------------------------------------------------
-/***************************************************************************
- FILE ENUMERATION
-***************************************************************************/
-
-/*-------------------------------------------------
- mame_openpath - open a search path (multiple
- directories) for iteration
--------------------------------------------------*/
-
-mame_path *mame_openpath(core_options *opts, const char *searchpath)
+int emu_file::vprintf(const char *fmt, va_list va)
{
- mame_path *path;
-
- /* allocate a new mame_path */
- path = global_alloc_clear(mame_path);
-
- /* initialize the iterator */
- path_iterator_init(&path->iterator, opts, searchpath);
-
- return path;
+ // write the data if we can
+ return (m_file != NULL) ? core_vfprintf(m_file, fmt, va) : 0;
}
-/*-------------------------------------------------
- mame_readpath - return information about the
- next file in the search path
--------------------------------------------------*/
-const osd_directory_entry *mame_readpath(mame_path *path)
+//-------------------------------------------------
+// attempt_zipped - attempt to open a ZIPped file
+//-------------------------------------------------
+
+file_error emu_file::attempt_zipped()
{
- const osd_directory_entry *result;
+ astring filename;
- /* loop over potentially empty directories */
+ // loop over directory parts up to the start of filename
while (1)
{
- /* if no open directory, get the next path */
- while (path->curdir == NULL)
- {
- /* if we fail to get anything more, we're done */
- if (!path_iterator_get_next(&path->iterator, path->pathbuffer))
- return NULL;
-
- /* open the path */
- path->curdir = osd_opendir(path->pathbuffer);
- }
-
- /* get the next entry from the current directory */
- result = osd_readdir(path->curdir);
- if (result != NULL)
- return result;
-
- /* we're done; close this directory */
- osd_closedir(path->curdir);
- path->curdir = NULL;
- }
-}
-
-
-/*-------------------------------------------------
- mame_closepath - close an open seach path
--------------------------------------------------*/
-
-void mame_closepath(mame_path *path)
-{
- /* close anything open */
- if (path->curdir != NULL)
- osd_closedir(path->curdir);
-
- /* free memory */
- global_free(path);
-}
-
-
+ // find the final path separator
+ int dirsep = m_fullpath.rchr(0, PATH_SEPARATOR[0]);
+ if (dirsep == -1)
+ return FILERR_NOT_FOUND;
-/***************************************************************************
- MISCELLANEOUS
-***************************************************************************/
+ // insert the part from the right of the separator into the head of the filename
+ if (filename.len() > 0)
+ filename.ins(0, "/");
+ filename.inssubstr(0, m_fullpath, dirsep + 1, -1);
-/*-------------------------------------------------
- mame_core_file - return the core_file
- underneath the mame_file
--------------------------------------------------*/
+ // remove this part of the filename and append a .zip extension
+ m_fullpath.substr(0, dirsep).cat(".zip");
-core_file *mame_core_file(mame_file *file)
-{
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return NULL;
- }
+ // attempt to open the ZIP file
+ zip_file *zip;
+ zip_error ziperr = zip_file_open(m_fullpath, &zip);
- /* return the core file */
- return file->file;
-}
+ // chop the .zip back off the filename before continuing
+ m_fullpath.substr(0, dirsep);
+ // if we failed to open this file, continue scanning
+ if (ziperr != ZIPERR_NONE)
+ continue;
-/*-------------------------------------------------
- mame_file_full_name - return the full filename
- for a given mame_file
--------------------------------------------------*/
+ // see if we can find a file with the right name and (if available) crc
+ const zip_file_header *header;
+ for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip))
+ if (zip_filename_match(*header, filename) && (!(m_openflags & OPEN_FLAG_HAS_CRC) || header->crc == m_crc))
+ break;
-const astring &mame_file_full_name(mame_file *file)
-{
- return file->filename;
-}
+ // if that failed, look for a file with the right crc, but the wrong filename
+ if (header == NULL && (m_openflags & OPEN_FLAG_HAS_CRC))
+ for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip))
+ if (header->crc == m_crc && !zip_header_is_path(*header))
+ break;
+ // if that failed, look for a file with the right name; reporting a bad checksum
+ // is more helpful and less confusing than reporting "rom not found"
+ if (header == NULL)
+ for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip))
+ if (zip_filename_match(*header, filename))
+ break;
-/*-------------------------------------------------
- mame_fhash - returns the hash for a file
--------------------------------------------------*/
+ // if we got it, read the data
+ if (header != NULL)
+ {
+ m_zipfile = zip;
+ m_ziplength = header->uncompressed_length;
-const char *mame_fhash(mame_file *file, UINT32 functions)
-{
- const UINT8 *filedata;
- UINT32 wehave;
+ // build a hash with just the CRC
+ hash_data_clear(m_hash);
+ UINT8 crcs[4];
+ crcs[0] = header->crc >> 24;
+ crcs[1] = header->crc >> 16;
+ crcs[2] = header->crc >> 8;
+ crcs[3] = header->crc >> 0;
+ hash_data_insert_binary_checksum(m_hash, HASH_CRC, crcs);
- /* if we already have the functions we need, just return */
- wehave = hash_data_used_functions(file->hash);
- if ((wehave & functions) == functions)
- return file->hash;
+ return (m_openflags & OPEN_FLAG_NO_PRELOAD) ? FILERR_NONE : load_zipped_file();
+ }
- /* load the ZIP file now if we haven't yet */
- if (file->zipfile != NULL)
- {
- if (load_zipped_file(file) != FILERR_NONE)
- return file->hash;
+ // close up the ZIP file and try the next level
+ zip_file_close(zip);
}
- if (file->file == NULL)
- return file->hash;
-
- /* read the data if we can */
- filedata = (const UINT8 *)core_fbuffer(file->file);
- if (filedata == NULL)
- return file->hash;
-
- /* compute the hash */
- hash_compute(file->hash, filedata, core_fsize(file->file), wehave | functions);
- return file->hash;
}
+//-------------------------------------------------
+// load_zipped_file - load a ZIPped file
+//-------------------------------------------------
-/***************************************************************************
- PATH ITERATION
-***************************************************************************/
-
-/*-------------------------------------------------
- path_iterator_init - prepare to iterate over
- a given path type
--------------------------------------------------*/
-
-static void path_iterator_init(path_iterator *iterator, core_options *opts, const char *searchpath)
+file_error emu_file::load_zipped_file()
{
- /* reset the structure */
- iterator->base = (searchpath != NULL && !osd_is_absolute_path(searchpath)) ? options_get_string(opts, searchpath) : "";
- iterator->cur = iterator->base;
- iterator->index = 0;
-}
+ assert(m_file == NULL);
+ assert(m_zipdata == NULL);
+ assert(m_zipfile != NULL);
+ // allocate some memory
+ m_zipdata = global_alloc_array(UINT8, m_ziplength);
-/*-------------------------------------------------
- path_iterator_get_next - get the next entry
- in a multipath sequence
--------------------------------------------------*/
-
-static int path_iterator_get_next(path_iterator *iterator, astring &buffer)
-{
- const char *semi;
-
- /* if none left, return FALSE to indicate we are done */
- if (iterator->index != 0 && *iterator->cur == 0)
- return FALSE;
-
- /* copy up to the next semicolon */
- semi = strchr(iterator->cur, ';');
- if (semi == NULL)
- semi = iterator->cur + strlen(iterator->cur);
- buffer.cpy(iterator->cur, semi - iterator->cur);
- iterator->cur = (*semi == 0) ? semi : semi + 1;
-
- /* bump the index and return TRUE */
- iterator->index++;
- return TRUE;
-}
-
-
-
-/***************************************************************************
- MISC HELPERS
-***************************************************************************/
-
-/*-------------------------------------------------
- load_zipped_file - load a ZIPped file
--------------------------------------------------*/
-
-static file_error load_zipped_file(mame_file *file)
-{
- file_error filerr;
- zip_error ziperr;
-
- assert(file->file == NULL);
- assert(file->zipdata == NULL);
- assert(file->zipfile != NULL);
-
- /* allocate some memory */
- file->zipdata = global_alloc_array(UINT8, file->ziplength);
-
- /* read the data into our buffer and return */
- ziperr = zip_file_decompress(file->zipfile, file->zipdata, file->ziplength);
+ // read the data into our buffer and return
+ zip_error ziperr = zip_file_decompress(m_zipfile, m_zipdata, m_ziplength);
if (ziperr != ZIPERR_NONE)
{
- global_free(file->zipdata);
- file->zipdata = NULL;
+ global_free(m_zipdata);
+ m_zipdata = NULL;
return FILERR_FAILURE;
}
- /* convert to RAM file */
- filerr = core_fopen_ram(file->zipdata, file->ziplength, file->openflags, &file->file);
+ // convert to RAM file
+ file_error filerr = core_fopen_ram(m_zipdata, m_ziplength, m_openflags, &m_file);
if (filerr != FILERR_NONE)
{
- global_free(file->zipdata);
- file->zipdata = NULL;
+ global_free(m_zipdata);
+ m_zipdata = NULL;
return FILERR_FAILURE;
}
- /* close out the ZIP file */
- zip_file_close(file->zipfile);
- file->zipfile = NULL;
+ // close out the ZIP file
+ zip_file_close(m_zipfile);
+ m_zipfile = NULL;
return FILERR_NONE;
}
-/*-------------------------------------------------
- zip_filename_match - compare zip filename
- to expected filename, ignoring any directory
--------------------------------------------------*/
+//-------------------------------------------------
+// zip_filename_match - compare zip filename
+// to expected filename, ignoring any directory
+//-------------------------------------------------
-static int zip_filename_match(const zip_file_header *header, const astring &filename)
+bool emu_file::zip_filename_match(const zip_file_header &header, const astring &filename)
{
- const char *zipfile = header->filename + header->filename_length - filename.len();
-
- return (zipfile >= header->filename && filename.icmp(zipfile) == 0 &&
- (zipfile == header->filename || zipfile[-1] == '/'));
+ const char *zipfile = header.filename + header.filename_length - filename.len();
+ return (zipfile >= header.filename && filename.icmp(zipfile) == 0 && (zipfile == header.filename || zipfile[-1] == '/'));
}
-/*-------------------------------------------------
- zip_header_is_path - check whether filename
- in header is a path
- -------------------------------------------------*/
-static int zip_header_is_path(const zip_file_header *header)
-{
- const char *zipfile = header->filename + header->filename_length - 1;
+//-------------------------------------------------
+// zip_header_is_path - check whether filename
+// in header is a path
+//-------------------------------------------------
- return (zipfile >= header->filename && zipfile[0] == '/');
+bool emu_file::zip_header_is_path(const zip_file_header &header)
+{
+ const char *zipfile = header.filename + header.filename_length - 1;
+ return (zipfile >= header.filename && zipfile[0] == '/');
}
diff --git a/src/emu/fileio.h b/src/emu/fileio.h
index 56840f970d1..b4a441c4b39 100644
--- a/src/emu/fileio.h
+++ b/src/emu/fileio.h
@@ -4,8 +4,36 @@
Core file I/O interface functions and definitions.
- Copyright Nicola Salmoria and the MAME Team.
- Visit http://mamedev.org for licensing and usage restrictions.
+****************************************************************************
+
+ Copyright Aaron Giles
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ * Neither the name 'MAME' nor the names of its contributors may be
+ used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
@@ -15,14 +43,15 @@
#define __FILEIO_H__
#include "corefile.h"
+#include "hash.h"
-/***************************************************************************
- CONSTANTS
-***************************************************************************/
+//**************************************************************************
+// CONSTANTS
+//**************************************************************************
-/* search paths */
+// search paths
#define SEARCHPATH_RAW NULL
#define SEARCHPATH_LANGUAGE NULL
#define SEARCHPATH_DEBUGLOG NULL
@@ -50,126 +79,136 @@
-/***************************************************************************
- TYPE DEFINITIONS
-***************************************************************************/
-
-typedef struct _mame_file mame_file;
-typedef struct _mame_path mame_path;
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
+// forward declarations
typedef struct _core_options core_options;
-
-
-
-/***************************************************************************
- FUNCTION PROTOTYPES
-***************************************************************************/
-
-
-/* ----- core initialization ----- */
-
-/* initialize the fileio system */
-void fileio_init(running_machine *machine);
-
-
-
-/* ----- file open/close ----- */
-
-/* open a file in the given search path with the specified filename */
-file_error mame_fopen(const char *searchpath, const char *filename, UINT32 openflags, mame_file **file);
-
-/* open a file in the given search path with the specified filename or a matching CRC */
-file_error mame_fopen_crc(const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file);
-
-/* open a file in the given search path with the specified filename, using the specified options */
-file_error mame_fopen_options(core_options *opts, const char *searchpath, const char *filename, UINT32 openflags, mame_file **file);
-
-/* open a file in the given search path with the specified filename or a matching CRC, using the specified options */
-file_error mame_fopen_crc_options(core_options *opts, const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file);
-
-/* open a "file" which is actually data in RAM */
-file_error mame_fopen_ram(const void *data, UINT32 length, UINT32 openflags, mame_file **file);
-
-/* close an open file */
-void mame_fclose(mame_file *file);
-
-/* close an open file, and open the next entry in the original searchpath*/
-file_error mame_fclose_and_open_next(mame_file **file, const char *filename, UINT32 openflags);
-
-/* enable/disable streaming file compression via zlib; level is 0 to disable compression, or up to 9 for max compression */
-file_error mame_fcompress(mame_file *file, int compress);
-
-
-
-/* ----- file positioning ----- */
-
-/* adjust the file pointer within the file */
-int mame_fseek(mame_file *file, INT64 offset, int whence);
-
-/* return the current file pointer */
-UINT64 mame_ftell(mame_file *file);
-
-/* return true if we are at the EOF */
-int mame_feof(mame_file *file);
-
-/* return the total size of the file */
-UINT64 mame_fsize(mame_file *file);
-
-
-
-/* ----- file read ----- */
-
-/* standard binary read from a file */
-UINT32 mame_fread(mame_file *file, void *buffer, UINT32 length);
-
-/* read one character from the file */
-int mame_fgetc(mame_file *file);
-
-/* put back one character from the file */
-int mame_ungetc(int c, mame_file *file);
-
-/* read a full line of text from the file */
-char *mame_fgets(char *s, int n, mame_file *file);
-
-
-
-/* ----- file write ----- */
-
-/* standard binary write to a file */
-UINT32 mame_fwrite(mame_file *file, const void *buffer, UINT32 length);
-
-/* write a line of text to the file */
-int mame_fputs(mame_file *f, const char *s);
-
-/* printf-style text write to a file */
-int CLIB_DECL mame_fprintf(mame_file *f, const char *fmt, ...) ATTR_PRINTF(2,3);
-
-
-
-/* ----- file enumeration ----- */
-
-/* open a search path (multiple directories) for iteration */
-mame_path *mame_openpath(core_options *opts, const char *searchpath);
-
-/* return information about the next file in the search path */
-const osd_directory_entry *mame_readpath(mame_path *path);
-
-/* close an open seach path */
-void mame_closepath(mame_path *path);
-
-
-
-/* ----- file misc ----- */
-
-/* return the core_file underneath the mame_file */
-core_file *mame_core_file(mame_file *file);
-
-/* return the full filename for a given mame_file */
-const astring &mame_file_full_name(mame_file *file);
-
-/* return a hash string for the file with the given functions */
-const char *mame_fhash(mame_file *file, UINT32 functions);
-
+typedef struct _zip_file_header zip_file_header;
+typedef struct _zip_file zip_file;
+
+
+// ======================> path_iterator
+
+// helper class for iterating over configured paths
+class path_iterator
+{
+public:
+ // construction/destruction
+ path_iterator(core_options &options, const char *searchpath = "");
+
+ // getters
+ bool next(astring &buffer);
+
+ // reset
+ void reset() { m_current = m_base; m_index = 0; }
+
+private:
+ // internal state
+ const char * m_base;
+ const char * m_current;
+ int m_index;
+};
+
+
+
+// ======================> file_enumerator
+
+// iterate over all files in all paths specified in the searchpath
+class file_enumerator
+{
+public:
+ // construction/destruction
+ file_enumerator(core_options &opts, const char *searchpath);
+ ~file_enumerator();
+
+ // iterator
+ const osd_directory_entry *next();
+
+private:
+ // internal state
+ path_iterator m_iterator;
+ osd_directory * m_curdir;
+ astring m_pathbuffer;
+ int m_buflen;
+};
+
+
+
+// ======================> emu_file
+
+class emu_file
+{
+public:
+ // file open/creation
+ emu_file(core_options &options, const char *searchpath, UINT32 openflags);
+ virtual ~emu_file();
+
+ // getters
+ operator core_file *();
+ bool open() const { return (m_file != NULL); }
+ const char *filename() const { return m_filename; }
+ const char *fullpath() const { return m_fullpath; }
+ UINT32 openflags() const { return m_openflags; }
+ const char *hash_string(UINT32 functions);
+
+ // setters
+ void remove_on_close() { m_remove_on_close = true; }
+ void set_openflags(UINT32 openflags) { assert(m_file == NULL); m_openflags = openflags; }
+
+ // open/close
+ file_error open(const char *name);
+ file_error open(const char *name1, const char *name2);
+ file_error open(const char *name1, const char *name2, const char *name3);
+ file_error open(const char *name1, const char *name2, const char *name3, const char *name4);
+ file_error open(const char *name, UINT32 crc);
+ file_error open(const char *name1, const char *name2, UINT32 crc);
+ file_error open(const char *name1, const char *name2, const char *name3, UINT32 crc);
+ file_error open(const char *name1, const char *name2, const char *name3, const char *name4, UINT32 crc);
+ file_error open_next();
+ file_error open_ram(const void *data, UINT32 length);
+ void close();
+
+ // control
+ file_error compress(int compress);
+ int seek(INT64 offset, int whence);
+ UINT64 tell();
+ bool eof();
+ UINT64 size();
+
+ // reading
+ UINT32 read(void *buffer, UINT32 length);
+ int getc();
+ int ungetc(int c);
+ char *gets(char *s, int n);
+
+ // writing
+ UINT32 write(const void *buffer, UINT32 length);
+ int puts(const char *s);
+ int vprintf(const char *fmt, va_list va);
+ int printf(const char *fmt, ...);
+
+private:
+ // internal helpers
+ file_error attempt_zipped();
+ file_error load_zipped_file();
+ bool zip_filename_match(const zip_file_header &header, const astring &filename);
+ bool zip_header_is_path(const zip_file_header &header);
+
+ // internal state
+ astring m_filename; // original filename provided
+ astring m_fullpath; // full filename
+ core_file * m_file; // core file pointer
+ path_iterator m_iterator; // iterator for paths
+ UINT32 m_crc; // iterator for paths
+ UINT32 m_openflags; // flags we used for the open
+ char m_hash[HASH_BUF_SIZE]; // hash data for the file
+ zip_file * m_zipfile; // ZIP file pointer
+ UINT8 * m_zipdata; // ZIP file data
+ UINT64 m_ziplength; // ZIP file length
+ bool m_remove_on_close; // flag: remove the file when closing
+};
#endif /* __FILEIO_H__ */
diff --git a/src/emu/hashfile.c b/src/emu/hashfile.c
index 021c1cc21ef..e8bb9d8b76c 100644
--- a/src/emu/hashfile.c
+++ b/src/emu/hashfile.c
@@ -16,7 +16,7 @@
struct _hash_file
{
- mame_file *file;
+ emu_file *file;
object_pool *pool;
unsigned int functions[IO_COUNT];
@@ -341,7 +341,7 @@ static void hashfile_parse(hash_file *hashfile,
UINT32 len;
XML_Memory_Handling_Suite memcallbacks;
- mame_fseek(hashfile->file, 0, SEEK_SET);
+ hashfile->file->seek(0, SEEK_SET);
memset(&state, 0, sizeof(state));
state.hashfile = hashfile;
@@ -364,8 +364,8 @@ static void hashfile_parse(hash_file *hashfile,
while(!state.done)
{
- len = mame_fread(hashfile->file, buf, sizeof(buf));
- state.done = mame_feof(hashfile->file);
+ len = hashfile->file->read(buf, sizeof(buf));
+ state.done = hashfile->file->eof();
if (XML_Parse(state.parser, buf, len, state.done) == XML_STATUS_ERROR)
{
parse_error(&state, "[%lu:%lu]: %s\n",
@@ -403,16 +403,15 @@ static void preload_use_proc(hash_file *hashfile, void *param, hash_info *hi)
/*-------------------------------------------------
- hashfile_open_options
+ hashfile_open
-------------------------------------------------*/
-hash_file *hashfile_open_options(core_options *opts, const char *sysname, int is_preload,
+hash_file *hashfile_open(core_options &options, const char *sysname, int is_preload,
void (*error_proc)(const char *message))
{
- file_error filerr;
- astring *fname;
hash_file *hashfile = NULL;
object_pool *pool = NULL;
+ file_error filerr;
/* create a pool for this hash file */
pool = pool_alloc_lib(error_proc);
@@ -430,12 +429,14 @@ hash_file *hashfile_open_options(core_options *opts, const char *sysname, int is
hashfile->error_proc = error_proc;
/* open a file */
- fname = astring_assemble_2(astring_alloc(), sysname, ".hsi");
- filerr = mame_fopen_options(opts, SEARCHPATH_HASH, astring_c(fname), OPEN_FLAG_READ, &hashfile->file);
- astring_free(fname);
-
+ hashfile->file = global_alloc(emu_file(options, SEARCHPATH_HASH, OPEN_FLAG_READ));
+ filerr = hashfile->file->open(sysname, ".hsi");
if (filerr != FILERR_NONE)
+ {
+ global_free(hashfile->file);
+ hashfile->file = NULL;
goto error;
+ }
if (is_preload)
hashfile_parse(hashfile, NULL, preload_use_proc, hashfile->error_proc, NULL);
@@ -451,25 +452,12 @@ error:
/*-------------------------------------------------
- hashfile_open
--------------------------------------------------*/
-
-hash_file *hashfile_open(const char *sysname, int is_preload,
- void (*error_proc)(const char *message))
-{
- return hashfile_open_options(mame_options(), sysname, is_preload, error_proc);
-}
-
-
-
-/*-------------------------------------------------
hashfile_close
-------------------------------------------------*/
void hashfile_close(hash_file *hashfile)
{
- if (hashfile->file)
- mame_fclose(hashfile->file);
+ global_free(hashfile->file);
pool_free_lib(hashfile->pool);
}
@@ -548,11 +536,11 @@ unsigned int hashfile_functions_used(hash_file *hashfile, iodevice_t devtype)
hashfile_verify
-------------------------------------------------*/
-int hashfile_verify(const char *sysname, void (*my_error_proc)(const char *message))
+int hashfile_verify(core_options &options, const char *sysname, void (*my_error_proc)(const char *message))
{
hash_file *hashfile;
- hashfile = hashfile_open(sysname, FALSE, my_error_proc);
+ hashfile = hashfile_open(options, sysname, FALSE, my_error_proc);
if (!hashfile)
return -1;
diff --git a/src/emu/hashfile.h b/src/emu/hashfile.h
index 23467d17b5d..31f203455fe 100644
--- a/src/emu/hashfile.h
+++ b/src/emu/hashfile.h
@@ -40,11 +40,7 @@ typedef void (*hashfile_error_func)(const char *message);
***************************************************************************/
/* opens a hash file; if is_preload is non-zero, the entire file is preloaded */
-hash_file *hashfile_open(const char *sysname, int is_preload, hashfile_error_func error_proc);
-
-/* opens a hash file; if is_preload is non-zero, the entire file is preloaded */
-hash_file *hashfile_open_options(core_options *opts, const char *sysname, int is_preload,
- hashfile_error_func error_proc);
+hash_file *hashfile_open(core_options &options, const char *sysname, int is_preload, hashfile_error_func error_proc);
/* closes a hash file and associated resources */
void hashfile_close(hash_file *hashfile);
diff --git a/src/emu/image.c b/src/emu/image.c
index 94122955dcd..d026724ef33 100644
--- a/src/emu/image.c
+++ b/src/emu/image.c
@@ -125,10 +125,8 @@ static void image_dirs_save(running_machine *machine, int config_type, xml_data_
INI files
-------------------------------------------------*/
-static int write_config(const char *filename, const game_driver *gamedrv)
+static int write_config(core_options &options, const char *filename, const game_driver *gamedrv)
{
- file_error filerr;
- mame_file *f;
char buffer[128];
int retval = 1;
@@ -138,16 +136,13 @@ static int write_config(const char *filename, const game_driver *gamedrv)
filename = buffer;
}
- filerr = mame_fopen(SEARCHPATH_INI, buffer, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &f);
- if (filerr != FILERR_NONE)
- goto done;
-
- options_output_ini_file(mame_options(), mame_core_file(f));
- retval = 0;
-
-done:
- if (f != NULL)
- mame_fclose(f);
+ emu_file file(options, SEARCHPATH_INI, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE);
+ file_error filerr = file.open(filename);
+ if (filerr == FILERR_NONE)
+ {
+ options_output_ini_file(&options, file);
+ retval = 0;
+ }
return retval;
}
@@ -159,7 +154,7 @@ done:
static void image_options_extract(running_machine *machine)
{
/* only extract the device options if we've added them */
- if (options_get_bool(machine->options(), OPTION_ADDED_DEVICE_OPTIONS)) {
+ if (options_get_bool(&machine->options(), OPTION_ADDED_DEVICE_OPTIONS)) {
int index = 0;
device_image_interface *image = NULL;
@@ -168,15 +163,15 @@ static void image_options_extract(running_machine *machine)
const char *filename = image->filename();
/* and set the option */
- options_set_string(machine->options(), image->image_config().instance_name() , filename ? filename : "", OPTION_PRIORITY_CMDLINE);
+ options_set_string(&machine->options(), image->image_config().instance_name() , filename ? filename : "", OPTION_PRIORITY_CMDLINE);
index++;
}
}
/* write the config, if appropriate */
- if (options_get_bool(machine->options(), OPTION_WRITECONFIG))
- write_config(NULL, machine->gamedrv);
+ if (options_get_bool(&machine->options(), OPTION_WRITECONFIG))
+ write_config(machine->options(), NULL, machine->gamedrv);
}
/*-------------------------------------------------
@@ -303,18 +298,6 @@ void image_init(running_machine *machine)
image; typically for cartridges.
****************************************************************************/
-/*-------------------------------------------------
- open_battery_file_by_name - opens the battery backed
- NVRAM file for an image
--------------------------------------------------*/
-
-static file_error open_battery_file_by_name(const char *filename, UINT32 openflags, mame_file **file)
-{
- file_error filerr;
- filerr = mame_fopen(SEARCHPATH_NVRAM, filename, openflags, file);
- return filerr;
-}
-
static char *stripspace(const char *src)
{
static char buff[512];
@@ -444,21 +427,18 @@ astring *image_info_astring(running_machine *machine, astring *string)
to the function.
-------------------------------------------------*/
-void image_battery_load_by_name(const char *filename, void *buffer, int length, int fill)
+void image_battery_load_by_name(core_options &options, const char *filename, void *buffer, int length, int fill)
{
file_error filerr;
- mame_file *file;
int bytes_read = 0;
assert_always(buffer && (length > 0), "Must specify sensical buffer/length");
/* try to open the battery file and read it in, if possible */
- filerr = open_battery_file_by_name(filename, OPEN_FLAG_READ, &file);
+ emu_file file(options, SEARCHPATH_NVRAM, OPEN_FLAG_READ);
+ filerr = file.open(filename);
if (filerr == FILERR_NONE)
- {
- bytes_read = mame_fread(file, buffer, length);
- mame_fclose(file);
- }
+ bytes_read = file.read(buffer, length);
/* fill remaining bytes (if necessary) */
memset(((char *) buffer) + bytes_read, fill, length - bytes_read);
@@ -469,20 +449,15 @@ void image_battery_load_by_name(const char *filename, void *buffer, int length,
backed RAM for an image. A filename may be supplied
to the function.
-------------------------------------------------*/
-void image_battery_save_by_name(const char *filename, const void *buffer, int length)
+void image_battery_save_by_name(core_options &options, const char *filename, const void *buffer, int length)
{
- file_error filerr;
- mame_file *file;
-
assert_always(buffer && (length > 0), "Must specify sensical buffer/length");
/* try to open the battery file and write it out, if possible */
- filerr = open_battery_file_by_name(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ emu_file file(options, SEARCHPATH_NVRAM, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(filename);
if (filerr == FILERR_NONE)
- {
- mame_fwrite(file, buffer, length);
- mame_fclose(file);
- }
+ file.write(buffer, length);
}
/*-------------------------------------------------
diff --git a/src/emu/image.h b/src/emu/image.h
index d7d1d3f3d22..1cca37b3a82 100644
--- a/src/emu/image.h
+++ b/src/emu/image.h
@@ -25,8 +25,8 @@ void image_postdevice_init(running_machine *machine);
extern struct io_procs image_ioprocs;
-void image_battery_load_by_name(const char *filename, void *buffer, int length, int fill);
-void image_battery_save_by_name(const char *filename, const void *buffer, int length);
+void image_battery_load_by_name(core_options &options, const char *filename, void *buffer, int length, int fill);
+void image_battery_save_by_name(core_options &options, const char *filename, const void *buffer, int length);
astring *image_info_astring(running_machine *machine, astring *string);
diff --git a/src/emu/imagedev/multcart.c b/src/emu/imagedev/multcart.c
index 1c0eb9f3d41..d788e031217 100644
--- a/src/emu/imagedev/multcart.c
+++ b/src/emu/imagedev/multcart.c
@@ -258,7 +258,7 @@ static multicart_open_error load_ram_resource(multicart_load_state *state, xml_d
if (resource->filename == NULL)
return MCERR_OUT_OF_MEMORY;
- image_battery_load_by_name(resource->filename, resource->ptr, resource->length, 0x00);
+ image_battery_load_by_name(*mame_options(), resource->filename, resource->ptr, resource->length, 0x00);
}
/* else this type is volatile, in which case we just have
a memory expansion */
@@ -362,7 +362,7 @@ static multicart_open_error save_ram_resources(multicart_t *cart)
{
if ((resource->type == MULTICART_RESOURCE_TYPE_RAM) && (resource->filename != NULL))
{
- image_battery_save_by_name(resource->filename, resource->ptr, resource->length);
+ image_battery_save_by_name(*mame_options(), resource->filename, resource->ptr, resource->length);
}
}
return MCERR_NONE;
diff --git a/src/emu/inptport.c b/src/emu/inptport.c
index 0f19db036c2..f29384f709e 100644
--- a/src/emu/inptport.c
+++ b/src/emu/inptport.c
@@ -288,8 +288,8 @@ struct _input_port_private
attoseconds_t last_delta_nsec; /* nanoseconds that passed since the previous callback */
/* playback/record information */
- mame_file * record_file; /* recording file (NULL if not recording) */
- mame_file * playback_file; /* playback file (NULL if not recording) */
+ emu_file * record_file; /* recording file (NULL if not recording) */
+ emu_file * playback_file; /* playback file (NULL if not recording) */
UINT64 playback_accumulated_speed;/* accumulated speed during playback */
UINT32 playback_accumulated_frames;/* accumulated frames during playback */
@@ -776,7 +776,7 @@ static INT32 apply_analog_settings(INT32 current, analog_field_state *analog);
/* initialization helpers */
static void init_port_types(running_machine *machine);
static void init_port_state(running_machine *machine);
-static void init_autoselect_devices(const ioport_list &portlist, int type1, int type2, int type3, const char *option, const char *ananame);
+static void init_autoselect_devices(running_machine &machine, int type1, int type2, int type3, const char *option, const char *ananame);
static device_field_info *init_field_device_info(const input_field_config *field,const char *device_name);
static analog_field_state *init_field_analog_state(const input_field_config *field);
@@ -2012,7 +2012,7 @@ static astring *get_keyboard_key_name(const input_field_config *field)
static void init_port_state(running_machine *machine)
{
- const char *joystick_map_default = options_get_string(machine->options(), OPTION_JOYSTICK_MAP);
+ const char *joystick_map_default = options_get_string(&machine->options(), OPTION_JOYSTICK_MAP);
input_port_private *portdata = machine->input_port_data;
const input_field_config *field;
const input_port_config *port;
@@ -2094,14 +2094,14 @@ static void init_port_state(running_machine *machine)
}
/* handle autoselection of devices */
- init_autoselect_devices(machine->m_portlist, IPT_PADDLE, IPT_PADDLE_V, 0, OPTION_PADDLE_DEVICE, "paddle");
- init_autoselect_devices(machine->m_portlist, IPT_AD_STICK_X, IPT_AD_STICK_Y, IPT_AD_STICK_Z, OPTION_ADSTICK_DEVICE, "analog joystick");
- init_autoselect_devices(machine->m_portlist, IPT_LIGHTGUN_X, IPT_LIGHTGUN_Y, 0, OPTION_LIGHTGUN_DEVICE, "lightgun");
- init_autoselect_devices(machine->m_portlist, IPT_PEDAL, IPT_PEDAL2, IPT_PEDAL3, OPTION_PEDAL_DEVICE, "pedal");
- init_autoselect_devices(machine->m_portlist, IPT_DIAL, IPT_DIAL_V, 0, OPTION_DIAL_DEVICE, "dial");
- init_autoselect_devices(machine->m_portlist, IPT_TRACKBALL_X, IPT_TRACKBALL_Y, 0, OPTION_TRACKBALL_DEVICE, "trackball");
- init_autoselect_devices(machine->m_portlist, IPT_POSITIONAL, IPT_POSITIONAL_V, 0, OPTION_POSITIONAL_DEVICE, "positional");
- init_autoselect_devices(machine->m_portlist, IPT_MOUSE_X, IPT_MOUSE_Y, 0, OPTION_MOUSE_DEVICE, "mouse");
+ init_autoselect_devices(*machine, IPT_PADDLE, IPT_PADDLE_V, 0, OPTION_PADDLE_DEVICE, "paddle");
+ init_autoselect_devices(*machine, IPT_AD_STICK_X, IPT_AD_STICK_Y, IPT_AD_STICK_Z, OPTION_ADSTICK_DEVICE, "analog joystick");
+ init_autoselect_devices(*machine, IPT_LIGHTGUN_X, IPT_LIGHTGUN_Y, 0, OPTION_LIGHTGUN_DEVICE, "lightgun");
+ init_autoselect_devices(*machine, IPT_PEDAL, IPT_PEDAL2, IPT_PEDAL3, OPTION_PEDAL_DEVICE, "pedal");
+ init_autoselect_devices(*machine, IPT_DIAL, IPT_DIAL_V, 0, OPTION_DIAL_DEVICE, "dial");
+ init_autoselect_devices(*machine, IPT_TRACKBALL_X, IPT_TRACKBALL_Y, 0, OPTION_TRACKBALL_DEVICE, "trackball");
+ init_autoselect_devices(*machine, IPT_POSITIONAL, IPT_POSITIONAL_V, 0, OPTION_POSITIONAL_DEVICE, "positional");
+ init_autoselect_devices(*machine, IPT_MOUSE_X, IPT_MOUSE_Y, 0, OPTION_MOUSE_DEVICE, "mouse");
/* look for 4-way joysticks and change the default map if we find any */
if (joystick_map_default[0] == 0 || strcmp(joystick_map_default, "auto") == 0)
@@ -2121,9 +2121,10 @@ static void init_port_state(running_machine *machine)
in and the corresponding option
-------------------------------------------------*/
-static void init_autoselect_devices(const ioport_list &portlist, int type1, int type2, int type3, const char *option, const char *ananame)
+static void init_autoselect_devices(running_machine &machine, int type1, int type2, int type3, const char *option, const char *ananame)
{
- const char *stemp = options_get_string(mame_options(), option);
+ const ioport_list &portlist = machine.m_portlist;
+ const char *stemp = options_get_string(&machine.options(), option);
input_device_class autoenable = DEVICE_CLASS_KEYBOARD;
const char *autostring = "keyboard";
const input_field_config *field;
@@ -2846,7 +2847,7 @@ static int frame_get_digital_field_state(const input_field_config *field, int mo
}
/* skip locked-out coin inputs */
- if (curstate && field->type >= IPT_COIN1 && field->type <= IPT_COIN12 && coin_lockout_get_state(field->port->machine, field->type - IPT_COIN1) && options_get_bool(mame_options(), OPTION_COIN_LOCKOUT))
+ if (curstate && field->type >= IPT_COIN1 && field->type <= IPT_COIN12 && coin_lockout_get_state(field->port->machine, field->type - IPT_COIN1) && options_get_bool(&field->port->machine->options(), OPTION_COIN_LOCKOUT))
{
ui_popup_time(3, "Coinlock disabled %s.", input_field_name(field));
return FALSE;
@@ -4324,7 +4325,7 @@ static UINT8 playback_read_uint8(running_machine *machine)
return 0;
/* read the value; if we fail, end playback */
- if (mame_fread(portdata->playback_file, &result, sizeof(result)) != sizeof(result))
+ if (portdata->playback_file->read(&result, sizeof(result)) != sizeof(result))
{
playback_end(machine, "End of file");
return 0;
@@ -4350,7 +4351,7 @@ static UINT32 playback_read_uint32(running_machine *machine)
return 0;
/* read the value; if we fail, end playback */
- if (mame_fread(portdata->playback_file, &result, sizeof(result)) != sizeof(result))
+ if (portdata->playback_file->read(&result, sizeof(result)) != sizeof(result))
{
playback_end(machine, "End of file");
return 0;
@@ -4376,7 +4377,7 @@ static UINT64 playback_read_uint64(running_machine *machine)
return 0;
/* read the value; if we fail, end playback */
- if (mame_fread(portdata->playback_file, &result, sizeof(result)) != sizeof(result))
+ if (portdata->playback_file->read(&result, sizeof(result)) != sizeof(result))
{
playback_end(machine, "End of file");
return 0;
@@ -4393,10 +4394,9 @@ static UINT64 playback_read_uint64(running_machine *machine)
static time_t playback_init(running_machine *machine)
{
- const char *filename = options_get_string(machine->options(), OPTION_PLAYBACK);
+ const char *filename = options_get_string(&machine->options(), OPTION_PLAYBACK);
input_port_private *portdata = machine->input_port_data;
UINT8 header[INP_HEADER_SIZE];
- file_error filerr;
time_t basetime;
/* if no file, nothing to do */
@@ -4404,11 +4404,12 @@ static time_t playback_init(running_machine *machine)
return 0;
/* open the playback file */
- filerr = mame_fopen(SEARCHPATH_INPUTLOG, filename, OPEN_FLAG_READ, &portdata->playback_file);
+ portdata->playback_file = auto_alloc(machine, emu_file(machine->options(), SEARCHPATH_INPUTLOG, OPEN_FLAG_READ));
+ file_error filerr = portdata->playback_file->open(filename);
assert_always(filerr == FILERR_NONE, "Failed to open file for playback");
/* read the header and verify that it is a modern version; if not, print an error */
- if (mame_fread(portdata->playback_file, header, sizeof(header)) != sizeof(header))
+ if (portdata->playback_file->read(header, sizeof(header)) != sizeof(header))
fatalerror("Input file is corrupt or invalid (missing header)");
if (memcmp(header, "MAMEINP\0", 8) != 0)
fatalerror("Input file invalid or in an older, unsupported format");
@@ -4428,7 +4429,7 @@ static time_t playback_init(running_machine *machine)
mame_printf_info("Input file is for " GAMENOUN " '%s', not for current " GAMENOUN " '%s'\n", header + 0x14, machine->gamedrv->name);
/* enable compression */
- mame_fcompress(portdata->playback_file, FCOMPRESS_MEDIUM);
+ portdata->playback_file->compress(FCOMPRESS_MEDIUM);
return basetime;
}
@@ -4446,7 +4447,7 @@ static void playback_end(running_machine *machine, const char *message)
if (portdata->playback_file != NULL)
{
/* close the file */
- mame_fclose(portdata->playback_file);
+ auto_free(machine, portdata->playback_file);
portdata->playback_file = NULL;
/* pop a message */
@@ -4540,7 +4541,7 @@ static void record_write_uint8(running_machine *machine, UINT8 data)
return;
/* read the value; if we fail, end playback */
- if (mame_fwrite(portdata->record_file, &result, sizeof(result)) != sizeof(result))
+ if (portdata->record_file->write(&result, sizeof(result)) != sizeof(result))
record_end(machine, "Out of space");
}
@@ -4560,7 +4561,7 @@ static void record_write_uint32(running_machine *machine, UINT32 data)
return;
/* read the value; if we fail, end playback */
- if (mame_fwrite(portdata->record_file, &result, sizeof(result)) != sizeof(result))
+ if (portdata->record_file->write(&result, sizeof(result)) != sizeof(result))
record_end(machine, "Out of space");
}
@@ -4580,7 +4581,7 @@ static void record_write_uint64(running_machine *machine, UINT64 data)
return;
/* read the value; if we fail, end playback */
- if (mame_fwrite(portdata->record_file, &result, sizeof(result)) != sizeof(result))
+ if (portdata->record_file->write(&result, sizeof(result)) != sizeof(result))
record_end(machine, "Out of space");
}
@@ -4591,18 +4592,18 @@ static void record_write_uint64(running_machine *machine, UINT64 data)
static void record_init(running_machine *machine)
{
- const char *filename = options_get_string(machine->options(), OPTION_RECORD);
+ const char *filename = options_get_string(&machine->options(), OPTION_RECORD);
input_port_private *portdata = machine->input_port_data;
UINT8 header[INP_HEADER_SIZE];
system_time systime;
- file_error filerr;
/* if no file, nothing to do */
if (filename[0] == 0)
return;
/* open the record file */
- filerr = mame_fopen(SEARCHPATH_INPUTLOG, filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &portdata->record_file);
+ portdata->record_file = auto_alloc(machine, emu_file(machine->options(), SEARCHPATH_INPUTLOG, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS));
+ file_error filerr = portdata->record_file->open(filename);
assert_always(filerr == FILERR_NONE, "Failed to open file for recording");
/* get the base time */
@@ -4625,10 +4626,10 @@ static void record_init(running_machine *machine)
sprintf((char *)header + 0x20, APPNAME " %s", build_version);
/* write it */
- mame_fwrite(portdata->record_file, header, sizeof(header));
+ portdata->record_file->write(header, sizeof(header));
/* enable compression */
- mame_fcompress(portdata->record_file, FCOMPRESS_MEDIUM);
+ portdata->record_file->compress(FCOMPRESS_MEDIUM);
}
@@ -4644,7 +4645,7 @@ static void record_end(running_machine *machine, const char *message)
if (portdata->record_file != NULL)
{
/* close the file */
- mame_fclose(portdata->record_file);
+ auto_free(machine, portdata->record_file);
portdata->record_file = NULL;
/* pop a message */
diff --git a/src/emu/input.c b/src/emu/input.c
index 2127de21b00..7f6a681abee 100644
--- a/src/emu/input.c
+++ b/src/emu/input.c
@@ -591,24 +591,24 @@ void input_init(running_machine *machine)
/* read input enable options */
device_list[DEVICE_CLASS_KEYBOARD].enabled = TRUE;
- device_list[DEVICE_CLASS_MOUSE].enabled = options_get_bool(machine->options(), OPTION_MOUSE);
- device_list[DEVICE_CLASS_LIGHTGUN].enabled = options_get_bool(machine->options(), OPTION_LIGHTGUN);
- device_list[DEVICE_CLASS_JOYSTICK].enabled = options_get_bool(machine->options(), OPTION_JOYSTICK);
+ device_list[DEVICE_CLASS_MOUSE].enabled = options_get_bool(&machine->options(), OPTION_MOUSE);
+ device_list[DEVICE_CLASS_LIGHTGUN].enabled = options_get_bool(&machine->options(), OPTION_LIGHTGUN);
+ device_list[DEVICE_CLASS_JOYSTICK].enabled = options_get_bool(&machine->options(), OPTION_JOYSTICK);
/* read input device multi options */
- device_list[DEVICE_CLASS_KEYBOARD].multi = options_get_bool(machine->options(), OPTION_MULTIKEYBOARD);
- device_list[DEVICE_CLASS_MOUSE].multi = options_get_bool(machine->options(), OPTION_MULTIMOUSE);
+ device_list[DEVICE_CLASS_KEYBOARD].multi = options_get_bool(&machine->options(), OPTION_MULTIKEYBOARD);
+ device_list[DEVICE_CLASS_MOUSE].multi = options_get_bool(&machine->options(), OPTION_MULTIMOUSE);
device_list[DEVICE_CLASS_LIGHTGUN].multi = TRUE;
device_list[DEVICE_CLASS_JOYSTICK].multi = TRUE;
/* read other input options */
- state->steadykey_enabled = options_get_bool(machine->options(), OPTION_STEADYKEY);
- state->lightgun_reload_button = options_get_bool(machine->options(), OPTION_OFFSCREEN_RELOAD);
- state->joystick_deadzone = (INT32)(options_get_float(machine->options(), OPTION_JOYSTICK_DEADZONE) * INPUT_ABSOLUTE_MAX);
- state->joystick_saturation = (INT32)(options_get_float(machine->options(), OPTION_JOYSTICK_SATURATION) * INPUT_ABSOLUTE_MAX);
+ state->steadykey_enabled = options_get_bool(&machine->options(), OPTION_STEADYKEY);
+ state->lightgun_reload_button = options_get_bool(&machine->options(), OPTION_OFFSCREEN_RELOAD);
+ state->joystick_deadzone = (INT32)(options_get_float(&machine->options(), OPTION_JOYSTICK_DEADZONE) * INPUT_ABSOLUTE_MAX);
+ state->joystick_saturation = (INT32)(options_get_float(&machine->options(), OPTION_JOYSTICK_SATURATION) * INPUT_ABSOLUTE_MAX);
/* get the default joystick map */
- state->joystick_map_default = options_get_string(machine->options(), OPTION_JOYSTICK_MAP);
+ state->joystick_map_default = options_get_string(&machine->options(), OPTION_JOYSTICK_MAP);
if (state->joystick_map_default[0] == 0 || strcmp(state->joystick_map_default, "auto") == 0)
state->joystick_map_default = joystick_map_8way;
if (!joystick_map_parse(state->joystick_map_default, &map))
diff --git a/src/emu/machine.c b/src/emu/machine.c
index 4365f59bdb3..2ed94eaea23 100644
--- a/src/emu/machine.c
+++ b/src/emu/machine.c
@@ -114,6 +114,7 @@
#include "uiinput.h"
#include "crsshair.h"
#include "validity.h"
+#include "unzip.h"
#include "debug/debugcon.h"
#include <time.h>
@@ -260,7 +261,6 @@ const char *running_machine::describe_context()
void running_machine::start()
{
// initialize basic can't-fail systems here
- fileio_init(this);
config_init(this);
input_init(this);
output_init(this);
@@ -361,7 +361,8 @@ int running_machine::run(bool firstrun)
// if we have a logfile, set up the callback
if (options_get_bool(&m_options, OPTION_LOG))
{
- file_error filerr = mame_fopen(SEARCHPATH_DEBUGLOG, "error.log", OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &m_logfile);
+ m_logfile = auto_alloc(this, emu_file(m_options, SEARCHPATH_DEBUGLOG, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS));
+ file_error filerr = m_logfile->open("error.log");
assert_always(filerr == FILERR_NONE, "unable to open log file");
add_logerror_callback(logfile_callback);
}
@@ -429,10 +430,10 @@ int running_machine::run(bool firstrun)
// call all exit callbacks registered
call_notifiers(MACHINE_NOTIFY_EXIT);
+ zip_file_cache_clear();
// close the logfile
- if (m_logfile != NULL)
- mame_fclose(m_logfile);
+ auto_free(this, m_logfile);
return error;
}
@@ -770,6 +771,7 @@ void running_machine::handle_saveload()
file_error filerr = FILERR_NONE;
// if no name, bail
+ emu_file file(m_options, m_saveload_searchpath, openflags);
if (!m_saveload_pending_file)
goto cancel;
@@ -787,12 +789,9 @@ void running_machine::handle_saveload()
}
// open the file
- mame_file *file;
- filerr = mame_fopen(m_saveload_searchpath, m_saveload_pending_file, openflags, &file);
+ filerr = file.open(m_saveload_pending_file);
if (filerr == FILERR_NONE)
{
- astring fullname(mame_file_full_name(file));
-
// read/write the save state
state_save_error staterr = (m_saveload_schedule == SLS_LOAD) ? m_state.read_file(file) : m_state.write_file(file);
@@ -828,9 +827,8 @@ void running_machine::handle_saveload()
}
// close and perhaps delete the file
- mame_fclose(file);
if (staterr != STATERR_NONE && m_saveload_schedule == SLS_SAVE)
- osd_rmfile(fullname);
+ file.remove_on_close();
}
else
popmessage("Error: Failed to open file for %s operation.", opname);
@@ -871,7 +869,7 @@ void running_machine::soft_reset(running_machine &machine, int param)
void running_machine::logfile_callback(running_machine &machine, const char *buffer)
{
if (machine.m_logfile != NULL)
- mame_fputs(machine.m_logfile, buffer);
+ machine.m_logfile->puts(buffer);
}
diff --git a/src/emu/machine.h b/src/emu/machine.h
index 153ebc016b1..3bd28db7084 100644
--- a/src/emu/machine.h
+++ b/src/emu/machine.h
@@ -347,7 +347,7 @@ public:
// getters
const char *basename() const { return m_basename; }
- core_options *options() const { return &m_options; }
+ core_options &options() const { return m_options; }
machine_phase phase() const { return m_current_phase; }
bool paused() const { return m_paused || (m_current_phase != MACHINE_PHASE_RUNNING); }
bool scheduled_event_pending() const { return m_exit_pending || m_hard_reset_pending; }
@@ -500,7 +500,7 @@ private:
bool m_exit_to_game_select;
const game_driver * m_new_driver_pending;
emu_timer * m_soft_reset_timer;
- mame_file * m_logfile;
+ emu_file * m_logfile;
// load/save
enum saveload_schedule
diff --git a/src/emu/machine/at28c16.c b/src/emu/machine/at28c16.c
index 673a1026932..7c3e84a03b5 100644
--- a/src/emu/machine/at28c16.c
+++ b/src/emu/machine/at28c16.c
@@ -84,7 +84,7 @@ void at28c16_device_config::device_config_complete()
// on this device
//-------------------------------------------------
-bool at28c16_device_config::device_validity_check( const game_driver &driver ) const
+bool at28c16_device_config::device_validity_check( core_options &options, const game_driver &driver ) const
{
return false;
}
@@ -185,11 +185,11 @@ void at28c16_device::nvram_default()
// .nv file
//-------------------------------------------------
-void at28c16_device::nvram_read( mame_file &file )
+void at28c16_device::nvram_read( emu_file &file )
{
UINT8 *buffer = auto_alloc_array( &m_machine, UINT8, AT28C16_TOTAL_BYTES );
- mame_fread( &file, buffer, AT28C16_TOTAL_BYTES );
+ file.read( buffer, AT28C16_TOTAL_BYTES );
for( offs_t offs = 0; offs < AT28C16_TOTAL_BYTES; offs++ )
{
@@ -204,7 +204,7 @@ void at28c16_device::nvram_read( mame_file &file )
// .nv file
//-------------------------------------------------
-void at28c16_device::nvram_write( mame_file &file )
+void at28c16_device::nvram_write( emu_file &file )
{
UINT8 *buffer = auto_alloc_array( &m_machine, UINT8, AT28C16_TOTAL_BYTES );
@@ -213,7 +213,7 @@ void at28c16_device::nvram_write( mame_file &file )
buffer[ offs ] = m_addrspace[ 0 ]->read_byte( offs );
}
- mame_fwrite( &file, buffer, AT28C16_TOTAL_BYTES );
+ file.write( buffer, AT28C16_TOTAL_BYTES );
auto_free( &m_machine, buffer );
}
diff --git a/src/emu/machine/at28c16.h b/src/emu/machine/at28c16.h
index 6fb4765313e..32a1846fa31 100644
--- a/src/emu/machine/at28c16.h
+++ b/src/emu/machine/at28c16.h
@@ -58,7 +58,7 @@ public:
protected:
// device_config overrides
virtual void device_config_complete();
- virtual bool device_validity_check( const game_driver &driver ) const;
+ virtual bool device_validity_check( core_options &options, const game_driver &driver ) const;
// device_config_memory_interface overrides
virtual const address_space_config *memory_space_config( int spacenum = 0 ) const;
@@ -94,8 +94,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read( mame_file &file );
- virtual void nvram_write( mame_file &file );
+ virtual void nvram_read( emu_file &file );
+ virtual void nvram_write( emu_file &file );
// internal helpers
static TIMER_CALLBACK( write_finished );
diff --git a/src/emu/machine/ds2404.c b/src/emu/machine/ds2404.c
index f5a0c7c3bd9..e834744d557 100644
--- a/src/emu/machine/ds2404.c
+++ b/src/emu/machine/ds2404.c
@@ -409,9 +409,9 @@ void ds2404_device::nvram_default()
// .nv file
//-------------------------------------------------
-void ds2404_device::nvram_read(mame_file &file)
+void ds2404_device::nvram_read(emu_file &file)
{
- mame_fread(&file, m_sram, sizeof(m_sram));
+ file.read(m_sram, sizeof(m_sram));
}
@@ -420,7 +420,7 @@ void ds2404_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void ds2404_device::nvram_write(mame_file &file)
+void ds2404_device::nvram_write(emu_file &file)
{
- mame_fwrite(&file, m_sram, sizeof(m_sram));
+ file.write(m_sram, sizeof(m_sram));
}
diff --git a/src/emu/machine/ds2404.h b/src/emu/machine/ds2404.h
index 06c8c6b90f1..60f508e6dcd 100644
--- a/src/emu/machine/ds2404.h
+++ b/src/emu/machine/ds2404.h
@@ -102,8 +102,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
static TIMER_CALLBACK( ds2404_tick_callback );
diff --git a/src/emu/machine/eeprom.c b/src/emu/machine/eeprom.c
index f3bac1f6674..ad94ee2e1f7 100644
--- a/src/emu/machine/eeprom.c
+++ b/src/emu/machine/eeprom.c
@@ -164,7 +164,7 @@ void eeprom_device_config::static_set_default_value(device_config *device, UINT1
// on this device
//-------------------------------------------------
-bool eeprom_device_config::device_validity_check(const game_driver &driver) const
+bool eeprom_device_config::device_validity_check(core_options &options, const game_driver &driver) const
{
bool error = false;
@@ -297,13 +297,13 @@ void eeprom_device::nvram_default()
// .nv file
//-------------------------------------------------
-void eeprom_device::nvram_read(mame_file &file)
+void eeprom_device::nvram_read(emu_file &file)
{
UINT32 eeprom_length = 1 << m_config.m_address_bits;
UINT32 eeprom_bytes = eeprom_length * m_config.m_data_bits / 8;
UINT8 *buffer = auto_alloc_array(&m_machine, UINT8, eeprom_bytes);
- mame_fread(&file, buffer, eeprom_bytes);
+ file.read(buffer, eeprom_bytes);
for (offs_t offs = 0; offs < eeprom_bytes; offs++)
m_addrspace[0]->write_byte(offs, buffer[offs]);
auto_free(&m_machine, buffer);
@@ -315,7 +315,7 @@ void eeprom_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void eeprom_device::nvram_write(mame_file &file)
+void eeprom_device::nvram_write(emu_file &file)
{
UINT32 eeprom_length = 1 << m_config.m_address_bits;
UINT32 eeprom_bytes = eeprom_length * m_config.m_data_bits / 8;
@@ -323,7 +323,7 @@ void eeprom_device::nvram_write(mame_file &file)
UINT8 *buffer = auto_alloc_array(&m_machine, UINT8, eeprom_bytes);
for (offs_t offs = 0; offs < eeprom_bytes; offs++)
buffer[offs] = m_addrspace[0]->read_byte(offs);
- mame_fwrite(&file, buffer, eeprom_bytes);
+ file.write(buffer, eeprom_bytes);
auto_free(&m_machine, buffer);
}
diff --git a/src/emu/machine/eeprom.h b/src/emu/machine/eeprom.h
index 97463bbe025..4f5f3949143 100644
--- a/src/emu/machine/eeprom.h
+++ b/src/emu/machine/eeprom.h
@@ -83,7 +83,7 @@ public:
protected:
// device_config overrides
- virtual bool device_validity_check(const game_driver &driver) const;
+ virtual bool device_validity_check(core_options &options, const game_driver &driver) const;
// device_config_memory_interface overrides
virtual const address_space_config *memory_space_config(int spacenum = 0) const;
@@ -123,8 +123,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// internal helpers
void write(int bit);
diff --git a/src/emu/machine/er2055.c b/src/emu/machine/er2055.c
index 4594f9ff7b2..a5a356d842b 100644
--- a/src/emu/machine/er2055.c
+++ b/src/emu/machine/er2055.c
@@ -167,10 +167,10 @@ void er2055_device::nvram_default()
// .nv file
//-------------------------------------------------
-void er2055_device::nvram_read(mame_file &file)
+void er2055_device::nvram_read(emu_file &file)
{
UINT8 buffer[SIZE_DATA];
- mame_fread(&file, buffer, sizeof(buffer));
+ file.read(buffer, sizeof(buffer));
for (int byte = 0; byte < SIZE_DATA; byte++)
m_addrspace[0]->write_byte(byte, buffer[byte]);
}
@@ -181,12 +181,12 @@ void er2055_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void er2055_device::nvram_write(mame_file &file)
+void er2055_device::nvram_write(emu_file &file)
{
UINT8 buffer[SIZE_DATA];
for (int byte = 0; byte < SIZE_DATA; byte++)
buffer[byte] = m_addrspace[0]->read_byte(byte);
- mame_fwrite(&file, buffer, sizeof(buffer));
+ file.write(buffer, sizeof(buffer));
}
diff --git a/src/emu/machine/er2055.h b/src/emu/machine/er2055.h
index 656cfc08df2..c23294dc51d 100644
--- a/src/emu/machine/er2055.h
+++ b/src/emu/machine/er2055.h
@@ -109,8 +109,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
static const int SIZE_DATA = 0x40;
diff --git a/src/emu/machine/generic.c b/src/emu/machine/generic.c
index d8478ea6f39..3562640138f 100644
--- a/src/emu/machine/generic.c
+++ b/src/emu/machine/generic.c
@@ -312,22 +312,6 @@ void coin_lockout_global_w(running_machine *machine, int on)
***************************************************************************/
/*-------------------------------------------------
- nvram_fopen - open an NVRAM file directly
--------------------------------------------------*/
-
-mame_file *nvram_fopen(running_machine *machine, UINT32 openflags)
-{
- file_error filerr;
- mame_file *file;
-
- astring fname(machine->basename(), ".nv");
- filerr = mame_fopen(SEARCHPATH_NVRAM, fname, openflags, &file);
-
- return (filerr == FILERR_NONE) ? file : NULL;
-}
-
-
-/*-------------------------------------------------
nvram_load - load a system's NVRAM
-------------------------------------------------*/
@@ -339,19 +323,16 @@ void nvram_load(running_machine *machine)
return;
// open the file; if it exists, call everyone to read from it
- mame_file *nvram_file = nvram_fopen(machine, OPEN_FLAG_READ);
- if (nvram_file != NULL)
+ emu_file file(machine->options(), SEARCHPATH_NVRAM, OPEN_FLAG_READ);
+ if (file.open(machine->basename(), ".nv") == FILERR_NONE)
{
// read data from general NVRAM handler first
if (machine->config->m_nvram_handler != NULL)
- (*machine->config->m_nvram_handler)(machine, nvram_file, FALSE);
+ (*machine->config->m_nvram_handler)(machine, &file, FALSE);
// find all devices with NVRAM handlers, and read from them next
for (bool gotone = (nvram != NULL); gotone; gotone = nvram->next(nvram))
- nvram->nvram_load(*nvram_file);
-
- // close the file
- mame_fclose(nvram_file);
+ nvram->nvram_load(file);
}
// otherwise, tell everyone to initialize their NVRAM areas
@@ -380,19 +361,16 @@ void nvram_save(running_machine *machine)
return;
// open the file; if it exists, call everyone to read from it
- mame_file *nvram_file = nvram_fopen(machine, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
- if (nvram_file != NULL)
+ emu_file file(machine->options(), SEARCHPATH_NVRAM, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ if (file.open(machine->basename(), ".nv") == FILERR_NONE)
{
// write data via general NVRAM handler first
if (machine->config->m_nvram_handler != NULL)
- (*machine->config->m_nvram_handler)(machine, nvram_file, TRUE);
+ (*machine->config->m_nvram_handler)(machine, &file, TRUE);
// find all devices with NVRAM handlers, and tell them to write next
for (bool gotone = (nvram != NULL); gotone; gotone = nvram->next(nvram))
- nvram->nvram_save(*nvram_file);
-
- // close the file
- mame_fclose(nvram_file);
+ nvram->nvram_save(file);
}
}
@@ -420,8 +398,6 @@ INLINE void memcard_name(int index, char *buffer)
int memcard_create(running_machine *machine, int index, int overwrite)
{
- file_error filerr;
- mame_file *file;
char name[16];
/* create a name */
@@ -431,16 +407,14 @@ int memcard_create(running_machine *machine, int index, int overwrite)
astring fname(machine->basename(), PATH_SEPARATOR, name);
if (!overwrite)
{
- filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_READ, &file);
- if (filerr == FILERR_NONE)
- {
- mame_fclose(file);
+ emu_file testfile(machine->options(), SEARCHPATH_MEMCARD, OPEN_FLAG_READ);
+ if (testfile.open(fname) == FILERR_NONE)
return 1;
- }
}
/* create a new file */
- filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ emu_file file(machine->options(), SEARCHPATH_MEMCARD, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(fname);
if (filerr != FILERR_NONE)
return 1;
@@ -449,7 +423,6 @@ int memcard_create(running_machine *machine, int index, int overwrite)
(*machine->config->m_memcard_handler)(machine, file, MEMCARD_CREATE);
/* close the file */
- mame_fclose(file);
return 0;
}
@@ -462,8 +435,6 @@ int memcard_create(running_machine *machine, int index, int overwrite)
int memcard_insert(running_machine *machine, int index)
{
generic_machine_private *state = machine->generic_machine_data;
- file_error filerr;
- mame_file *file;
char name[16];
/* if a card is already inserted, eject it first */
@@ -473,10 +444,10 @@ int memcard_insert(running_machine *machine, int index)
/* create a name */
memcard_name(index, name);
- astring fname(machine->basename(), PATH_SEPARATOR, name);
/* open the file; if we can't, it's an error */
- filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_READ, &file);
+ emu_file file(machine->options(), SEARCHPATH_MEMCARD, OPEN_FLAG_READ);
+ file_error filerr = file.open(machine->basename(), PATH_SEPARATOR, name);
if (filerr != FILERR_NONE)
return 1;
@@ -485,7 +456,6 @@ int memcard_insert(running_machine *machine, int index)
(*machine->config->m_memcard_handler)(machine, file, MEMCARD_INSERT);
/* close the file */
- mame_fclose(file);
state->memcard_inserted = index;
return 0;
}
@@ -499,8 +469,6 @@ int memcard_insert(running_machine *machine, int index)
void memcard_eject(running_machine &machine)
{
generic_machine_private *state = machine.generic_machine_data;
- file_error filerr;
- mame_file *file;
char name[16];
/* if no card is preset, just ignore */
@@ -509,22 +477,18 @@ void memcard_eject(running_machine &machine)
/* create a name */
memcard_name(state->memcard_inserted, name);
- astring fname(machine.basename(), PATH_SEPARATOR, name);
/* open the file; if we can't, it's an error */
- filerr = mame_fopen(SEARCHPATH_MEMCARD, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ emu_file file(machine.options(), SEARCHPATH_MEMCARD, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(machine.basename(), PATH_SEPARATOR, name);
if (filerr != FILERR_NONE)
- {
- mame_fclose(file);
return;
- }
/* initialize and then load the card */
if (machine.m_config.m_memcard_handler)
(*machine.m_config.m_memcard_handler)(&machine, file, MEMCARD_EJECT);
/* close the file */
- mame_fclose(file);
state->memcard_inserted = -1;
}
diff --git a/src/emu/machine/generic.h b/src/emu/machine/generic.h
index 5ea3de5f285..565a14ff679 100644
--- a/src/emu/machine/generic.h
+++ b/src/emu/machine/generic.h
@@ -73,9 +73,6 @@ void coin_lockout_global_w(running_machine *machine, int on);
/* ----- NVRAM management ----- */
-/* open an NVRAM file directly */
-mame_file *nvram_fopen(running_machine *machine, UINT32 openflags);
-
/* load NVRAM from a file */
void nvram_load(running_machine *machine);
diff --git a/src/emu/machine/i2cmem.c b/src/emu/machine/i2cmem.c
index d27547a191e..9e9f96aae32 100644
--- a/src/emu/machine/i2cmem.c
+++ b/src/emu/machine/i2cmem.c
@@ -139,7 +139,7 @@ void i2cmem_device_config::device_config_complete()
// on this device
//-------------------------------------------------
-bool i2cmem_device_config::device_validity_check( const game_driver &driver ) const
+bool i2cmem_device_config::device_validity_check( core_options &options, const game_driver &driver ) const
{
bool error = false;
return error;
@@ -259,12 +259,12 @@ void i2cmem_device::nvram_default()
// .nv file
//-------------------------------------------------
-void i2cmem_device::nvram_read( mame_file &file )
+void i2cmem_device::nvram_read( emu_file &file )
{
int i2cmem_bytes = m_config.m_data_size;
UINT8 *buffer = auto_alloc_array( &m_machine, UINT8, i2cmem_bytes );
- mame_fread( &file, buffer, i2cmem_bytes );
+ file.read( buffer, i2cmem_bytes );
for( offs_t offs = 0; offs < i2cmem_bytes; offs++ )
{
@@ -279,7 +279,7 @@ void i2cmem_device::nvram_read( mame_file &file )
// .nv file
//-------------------------------------------------
-void i2cmem_device::nvram_write( mame_file &file )
+void i2cmem_device::nvram_write( emu_file &file )
{
int i2cmem_bytes = m_config.m_data_size;
UINT8 *buffer = auto_alloc_array( &m_machine, UINT8, i2cmem_bytes );
@@ -289,7 +289,7 @@ void i2cmem_device::nvram_write( mame_file &file )
buffer[ offs ] = m_addrspace[ 0 ]->read_byte( offs );
}
- mame_fwrite( &file, buffer, i2cmem_bytes );
+ file.write( buffer, i2cmem_bytes );
auto_free( &m_machine, buffer );
}
diff --git a/src/emu/machine/i2cmem.h b/src/emu/machine/i2cmem.h
index db564625347..5b997d570b8 100644
--- a/src/emu/machine/i2cmem.h
+++ b/src/emu/machine/i2cmem.h
@@ -67,7 +67,7 @@ public:
protected:
// device_config overrides
virtual void device_config_complete();
- virtual bool device_validity_check( const game_driver &driver ) const;
+ virtual bool device_validity_check( core_options &options, const game_driver &driver ) const;
// device_config_memory_interface overrides
virtual const address_space_config *memory_space_config( int spacenum = 0 ) const;
@@ -107,8 +107,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read( mame_file &file );
- virtual void nvram_write( mame_file &file );
+ virtual void nvram_read( emu_file &file );
+ virtual void nvram_write( emu_file &file );
// internal helpers
int address_mask();
diff --git a/src/emu/machine/intelfsh.c b/src/emu/machine/intelfsh.c
index aec0c7bac68..9b814eae618 100644
--- a/src/emu/machine/intelfsh.c
+++ b/src/emu/machine/intelfsh.c
@@ -333,10 +333,10 @@ void intelfsh_device::nvram_default()
// .nv file
//-------------------------------------------------
-void intelfsh_device::nvram_read(mame_file &file)
+void intelfsh_device::nvram_read(emu_file &file)
{
UINT8 *buffer = global_alloc_array(UINT8, m_config.m_size);
- mame_fread(&file, buffer, m_config.m_size);
+ file.read(buffer, m_config.m_size);
for (int byte = 0; byte < m_config.m_size; byte++)
m_addrspace[0]->write_byte(byte, buffer[byte]);
global_free(buffer);
@@ -348,12 +348,12 @@ void intelfsh_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void intelfsh_device::nvram_write(mame_file &file)
+void intelfsh_device::nvram_write(emu_file &file)
{
UINT8 *buffer = global_alloc_array(UINT8, m_config.m_size);
for (int byte = 0; byte < m_config.m_size; byte++)
buffer[byte] = m_addrspace[0]->read_byte(byte);
- mame_fwrite(&file, buffer, m_config.m_size);
+ file.write(buffer, m_config.m_size);
global_free(buffer);
}
diff --git a/src/emu/machine/intelfsh.h b/src/emu/machine/intelfsh.h
index 1a8ec03c9f7..242c0098c28 100644
--- a/src/emu/machine/intelfsh.h
+++ b/src/emu/machine/intelfsh.h
@@ -116,8 +116,8 @@ protected:
// device_config_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// derived helpers
UINT32 read_full(UINT32 offset);
diff --git a/src/emu/machine/mb3773.c b/src/emu/machine/mb3773.c
index b5664bee263..721fce80772 100644
--- a/src/emu/machine/mb3773.c
+++ b/src/emu/machine/mb3773.c
@@ -76,7 +76,7 @@ void mb3773_device_config::device_config_complete()
// on this device
//-------------------------------------------------
-bool mb3773_device_config::device_validity_check( const game_driver &driver ) const
+bool mb3773_device_config::device_validity_check( core_options &options, const game_driver &driver ) const
{
return false;
}
diff --git a/src/emu/machine/mb3773.h b/src/emu/machine/mb3773.h
index c3be2d91086..6a2e25f8dec 100644
--- a/src/emu/machine/mb3773.h
+++ b/src/emu/machine/mb3773.h
@@ -38,7 +38,7 @@ public:
protected:
// device_config overrides
virtual void device_config_complete();
- virtual bool device_validity_check( const game_driver &driver ) const;
+ virtual bool device_validity_check( core_options &options, const game_driver &driver ) const;
};
diff --git a/src/emu/machine/mc146818.c b/src/emu/machine/mc146818.c
index ab6da420424..926818829cc 100644
--- a/src/emu/machine/mc146818.c
+++ b/src/emu/machine/mc146818.c
@@ -348,9 +348,9 @@ void mc146818_device::nvram_default()
// .nv file
//-------------------------------------------------
-void mc146818_device::nvram_read(mame_file &file)
+void mc146818_device::nvram_read(emu_file &file)
{
- mame_fread(&file, m_data, sizeof(m_data));
+ file.read(m_data, sizeof(m_data));
set_base_datetime();
}
@@ -360,9 +360,9 @@ void mc146818_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void mc146818_device::nvram_write(mame_file &file)
+void mc146818_device::nvram_write(emu_file &file)
{
- mame_fwrite(&file, m_data, sizeof(m_data));
+ file.write(m_data, sizeof(m_data));
}
diff --git a/src/emu/machine/mc146818.h b/src/emu/machine/mc146818.h
index 7d4ce43134e..50ad18f69db 100644
--- a/src/emu/machine/mc146818.h
+++ b/src/emu/machine/mc146818.h
@@ -87,8 +87,8 @@ protected:
// device_mc146818_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// internal helpers
int dec_2_local(int a);
diff --git a/src/emu/machine/nvram.c b/src/emu/machine/nvram.c
index be30ff82002..bd3154c46e2 100644
--- a/src/emu/machine/nvram.c
+++ b/src/emu/machine/nvram.c
@@ -196,12 +196,12 @@ void nvram_device::nvram_default()
// .nv file
//-------------------------------------------------
-void nvram_device::nvram_read(mame_file &file)
+void nvram_device::nvram_read(emu_file &file)
{
// make sure we have a valid base pointer
determine_final_base();
- mame_fread(&file, m_base, m_length);
+ file.read(m_base, m_length);
}
@@ -210,9 +210,9 @@ void nvram_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void nvram_device::nvram_write(mame_file &file)
+void nvram_device::nvram_write(emu_file &file)
{
- mame_fwrite(&file, m_base, m_length);
+ file.write(m_base, m_length);
}
diff --git a/src/emu/machine/nvram.h b/src/emu/machine/nvram.h
index b652ca427cd..0fc03c82552 100644
--- a/src/emu/machine/nvram.h
+++ b/src/emu/machine/nvram.h
@@ -150,8 +150,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// internal helpers
void determine_final_base();
diff --git a/src/emu/machine/ram.c b/src/emu/machine/ram.c
index c659e6e9b4a..397b04e6e3c 100644
--- a/src/emu/machine/ram.c
+++ b/src/emu/machine/ram.c
@@ -100,7 +100,7 @@ static DEVICE_START( ram )
/* the device named 'ram' can get ram options from command line */
if (strcmp(device->tag(), RAM_TAG) == 0)
{
- const char *ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE);
+ const char *ramsize_string = options_get_string(&device->machine->options(), OPTION_RAMSIZE);
if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
ram->size = ram_parse_string(ramsize_string);
@@ -140,10 +140,9 @@ static DEVICE_VALIDITY_CHECK( ram )
/* command line options are only parsed for the device named RAM_TAG */
if (device->tag()!=NULL && strcmp(device->tag(), RAM_TAG) == 0)
{
- if (mame_options()==NULL) return FALSE;
/* verify command line ram option */
- ramsize_string = options_get_string(mame_options(), OPTION_RAMSIZE);
- gamename_option = options_get_string(mame_options(), OPTION_GAMENAME);
+ ramsize_string = options_get_string(&options, OPTION_RAMSIZE);
+ gamename_option = options_get_string(&options, OPTION_GAMENAME);
if ((ramsize_string != NULL) && (ramsize_string[0] != '\0'))
{
diff --git a/src/emu/machine/rtc65271.c b/src/emu/machine/rtc65271.c
index b8bfe86e979..3ed46197e8b 100644
--- a/src/emu/machine/rtc65271.c
+++ b/src/emu/machine/rtc65271.c
@@ -193,40 +193,40 @@ static UINT8 BCD_to_binary(UINT8 data)
/*
load the SRAM and register contents from file
*/
-static int rtc65271_file_load(device_t *device, mame_file *file)
+static int rtc65271_file_load(device_t *device, emu_file &file)
{
rtc65271_state *state = get_safe_token(device);
UINT8 buf;
/* version flag */
- if (mame_fread(file, & buf, 1) != 1)
+ if (file.read(&buf, 1) != 1)
return 1;
if (buf != 0)
return 1;
/* control registers */
- if (mame_fread(file, &buf, 1) != 1)
+ if (file.read(&buf, 1) != 1)
return 1;
state->regs[reg_A] = buf & (reg_A_DV /*| reg_A_RS*/);
- if (mame_fread(file, &buf, 1) != 1)
+ if (file.read(&buf, 1) != 1)
return 1;
state->regs[reg_B] = buf & (reg_B_SET | reg_B_DM | reg_B_24h | reg_B_DSE);
/* alarm registers */
- if (mame_fread(file, &state->regs[reg_alarm_second], 1) != 1)
+ if (file.read(&state->regs[reg_alarm_second], 1) != 1)
return 1;
- if (mame_fread(file, &state->regs[reg_alarm_minute], 1) != 1)
+ if (file.read(&state->regs[reg_alarm_minute], 1) != 1)
return 1;
- if (mame_fread(file, &state->regs[reg_alarm_hour], 1) != 1)
+ if (file.read(&state->regs[reg_alarm_hour], 1) != 1)
return 1;
/* user RAM */
- if (mame_fread(file, state->regs+14, 50) != 50)
+ if (file.read(state->regs+14, 50) != 50)
return 1;
/* extended RAM */
- if (mame_fread(file, state->xram, 4096) != 4096)
+ if (file.read(state->xram, 4096) != 4096)
return 1;
state->regs[reg_D] |= reg_D_VRT; /* the data was backed up successfully */
@@ -277,7 +277,7 @@ static int rtc65271_file_load(device_t *device, mame_file *file)
/*
save the SRAM and register contents to file
*/
-static int rtc65271_file_save(device_t *device, mame_file *file)
+static int rtc65271_file_save(device_t *device, emu_file &file)
{
rtc65271_state *state = get_safe_token(device);
UINT8 buf;
@@ -285,31 +285,31 @@ static int rtc65271_file_save(device_t *device, mame_file *file)
/* version flag */
buf = 0;
- if (mame_fwrite(file, & buf, 1) != 1)
+ if (file.write(& buf, 1) != 1)
return 1;
/* control registers */
buf = state->regs[reg_A] & (reg_A_DV | reg_A_RS);
- if (mame_fwrite(file, &buf, 1) != 1)
+ if (file.write(&buf, 1) != 1)
return 1;
buf = state->regs[reg_B] & (reg_B_SET | reg_B_DM | reg_B_24h | reg_B_DSE);
- if (mame_fwrite(file, &buf, 1) != 1)
+ if (file.write(&buf, 1) != 1)
return 1;
/* alarm registers */
- if (mame_fwrite(file, &state->regs[reg_alarm_second], 1) != 1)
+ if (file.write(&state->regs[reg_alarm_second], 1) != 1)
return 1;
- if (mame_fwrite(file, &state->regs[reg_alarm_minute], 1) != 1)
+ if (file.write(&state->regs[reg_alarm_minute], 1) != 1)
return 1;
- if (mame_fwrite(file, &state->regs[reg_alarm_hour], 1) != 1)
+ if (file.write(&state->regs[reg_alarm_hour], 1) != 1)
return 1;
/* user RAM */
- if (mame_fwrite(file, state->regs+14, 50) != 50)
+ if (file.write(state->regs+14, 50) != 50)
return 1;
/* extended RAM */
- if (mame_fwrite(file, state->xram, 4096) != 4096)
+ if (file.write(state->xram, 4096) != 4096)
return 1;
return 0;
@@ -704,9 +704,9 @@ static DEVICE_START( rtc65271 )
static DEVICE_NVRAM( rtc65271 )
{
if (read_or_write)
- rtc65271_file_save(device, file);
+ rtc65271_file_save(device, *file);
else if (file)
- rtc65271_file_load(device, file);
+ rtc65271_file_load(device, *file);
}
diff --git a/src/emu/machine/timekpr.c b/src/emu/machine/timekpr.c
index 895b162854b..efb042ba5ac 100644
--- a/src/emu/machine/timekpr.c
+++ b/src/emu/machine/timekpr.c
@@ -471,9 +471,9 @@ void timekeeper_device::nvram_default()
// .nv file
//-------------------------------------------------
-void timekeeper_device::nvram_read(mame_file &file)
+void timekeeper_device::nvram_read(emu_file &file)
{
- mame_fread( &file, m_data, m_size );
+ file.read( m_data, m_size );
counters_to_ram();
}
@@ -484,9 +484,9 @@ void timekeeper_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void timekeeper_device::nvram_write(mame_file &file)
+void timekeeper_device::nvram_write(emu_file &file)
{
- mame_fwrite( &file, m_data, m_size );
+ file.write( m_data, m_size );
}
diff --git a/src/emu/machine/timekpr.h b/src/emu/machine/timekpr.h
index 09374ab73db..e80211a7f26 100644
--- a/src/emu/machine/timekpr.h
+++ b/src/emu/machine/timekpr.h
@@ -100,8 +100,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// internal state
const timekeeper_device_config &m_config;
diff --git a/src/emu/machine/x2212.c b/src/emu/machine/x2212.c
index cc79b1be176..e51625bc52e 100644
--- a/src/emu/machine/x2212.c
+++ b/src/emu/machine/x2212.c
@@ -155,10 +155,10 @@ void x2212_device::nvram_default()
// .nv file
//-------------------------------------------------
-void x2212_device::nvram_read(mame_file &file)
+void x2212_device::nvram_read(emu_file &file)
{
UINT8 buffer[SIZE_DATA];
- mame_fread(&file, buffer, sizeof(buffer));
+ file.read(buffer, sizeof(buffer));
for (int byte = 0; byte < SIZE_DATA; byte++)
{
m_sram->write_byte(byte, 0xff);
@@ -172,7 +172,7 @@ void x2212_device::nvram_read(mame_file &file)
// .nv file
//-------------------------------------------------
-void x2212_device::nvram_write(mame_file &file)
+void x2212_device::nvram_write(emu_file &file)
{
// auto-save causes an implicit store prior to exiting (writing)
if (m_config.m_auto_save)
@@ -181,7 +181,7 @@ void x2212_device::nvram_write(mame_file &file)
UINT8 buffer[SIZE_DATA];
for (int byte = 0; byte < SIZE_DATA; byte++)
buffer[byte] = m_e2prom->read_byte(byte);
- mame_fwrite(&file, buffer, sizeof(buffer));
+ file.write(buffer, sizeof(buffer));
}
diff --git a/src/emu/machine/x2212.h b/src/emu/machine/x2212.h
index aa47e398057..fcfb1f89508 100644
--- a/src/emu/machine/x2212.h
+++ b/src/emu/machine/x2212.h
@@ -94,8 +94,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
static const int SIZE_DATA = 0x100;
diff --git a/src/emu/machine/x76f041.c b/src/emu/machine/x76f041.c
index faf89aad0ea..9da2a847728 100644
--- a/src/emu/machine/x76f041.c
+++ b/src/emu/machine/x76f041.c
@@ -410,22 +410,22 @@ void x76f041_device::sda_1()
}
}
-void x76f041_device::nvram_read(mame_file &file)
+void x76f041_device::nvram_read(emu_file &file)
{
- mame_fread(&file, response_to_reset, SIZE_RESPONSE_TO_RESET);
- mame_fread(&file, write_password, SIZE_WRITE_PASSWORD);
- mame_fread(&file, read_password, SIZE_READ_PASSWORD);
- mame_fread(&file, configuration_password, SIZE_CONFIGURATION_PASSWORD);
- mame_fread(&file, configuration_registers, SIZE_CONFIGURATION_REGISTERS);
- mame_fread(&file, data, SIZE_DATA);
+ file.read(response_to_reset, SIZE_RESPONSE_TO_RESET);
+ file.read(write_password, SIZE_WRITE_PASSWORD);
+ file.read(read_password, SIZE_READ_PASSWORD);
+ file.read(configuration_password, SIZE_CONFIGURATION_PASSWORD);
+ file.read(configuration_registers, SIZE_CONFIGURATION_REGISTERS);
+ file.read(data, SIZE_DATA);
}
-void x76f041_device::nvram_write(mame_file &file)
+void x76f041_device::nvram_write(emu_file &file)
{
- mame_fwrite(&file, response_to_reset, SIZE_RESPONSE_TO_RESET);
- mame_fwrite(&file, write_password, SIZE_WRITE_PASSWORD);
- mame_fwrite(&file, read_password, SIZE_READ_PASSWORD);
- mame_fwrite(&file, configuration_password, SIZE_CONFIGURATION_PASSWORD);
- mame_fwrite(&file, configuration_registers, SIZE_CONFIGURATION_REGISTERS);
- mame_fwrite(&file, data, SIZE_DATA);
+ file.write(response_to_reset, SIZE_RESPONSE_TO_RESET);
+ file.write(write_password, SIZE_WRITE_PASSWORD);
+ file.write(read_password, SIZE_READ_PASSWORD);
+ file.write(configuration_password, SIZE_CONFIGURATION_PASSWORD);
+ file.write(configuration_registers, SIZE_CONFIGURATION_REGISTERS);
+ file.write(data, SIZE_DATA);
}
diff --git a/src/emu/machine/x76f041.h b/src/emu/machine/x76f041.h
index 9122f00b6c9..88c492a359a 100644
--- a/src/emu/machine/x76f041.h
+++ b/src/emu/machine/x76f041.h
@@ -40,8 +40,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// device_secure_serial_flash implementations
virtual void cs_0();
diff --git a/src/emu/machine/x76f100.c b/src/emu/machine/x76f100.c
index 76b81061d3f..cfa436758a7 100644
--- a/src/emu/machine/x76f100.c
+++ b/src/emu/machine/x76f100.c
@@ -326,18 +326,18 @@ void x76f100_device::sda_1()
sdar = false;
}
-void x76f100_device::nvram_read(mame_file &file)
+void x76f100_device::nvram_read(emu_file &file)
{
- mame_fread(&file, response_to_reset, SIZE_RESPONSE_TO_RESET);
- mame_fread(&file, write_password, SIZE_WRITE_PASSWORD);
- mame_fread(&file, read_password, SIZE_READ_PASSWORD);
- mame_fread(&file, data, SIZE_DATA);
+ file.read(response_to_reset, SIZE_RESPONSE_TO_RESET);
+ file.read(write_password, SIZE_WRITE_PASSWORD);
+ file.read(read_password, SIZE_READ_PASSWORD);
+ file.read(data, SIZE_DATA);
}
-void x76f100_device::nvram_write(mame_file &file)
+void x76f100_device::nvram_write(emu_file &file)
{
- mame_fwrite(&file, response_to_reset, SIZE_RESPONSE_TO_RESET);
- mame_fwrite(&file, write_password, SIZE_WRITE_PASSWORD);
- mame_fwrite(&file, read_password, SIZE_READ_PASSWORD);
- mame_fwrite(&file, data, SIZE_DATA);
+ file.write(response_to_reset, SIZE_RESPONSE_TO_RESET);
+ file.write(write_password, SIZE_WRITE_PASSWORD);
+ file.write(read_password, SIZE_READ_PASSWORD);
+ file.write(data, SIZE_DATA);
}
diff --git a/src/emu/machine/x76f100.h b/src/emu/machine/x76f100.h
index 04d17673474..92cbaaf8ecb 100644
--- a/src/emu/machine/x76f100.h
+++ b/src/emu/machine/x76f100.h
@@ -40,8 +40,8 @@ protected:
// device_nvram_interface overrides
virtual void nvram_default();
- virtual void nvram_read(mame_file &file);
- virtual void nvram_write(mame_file &file);
+ virtual void nvram_read(emu_file &file);
+ virtual void nvram_write(emu_file &file);
// device_secure_serial_flash implementations
virtual void cs_0();
diff --git a/src/emu/mame.c b/src/emu/mame.c
index 7e57b71b47c..62a2afe05fe 100644
--- a/src/emu/mame.c
+++ b/src/emu/mame.c
@@ -175,7 +175,7 @@ int mame_execute(osd_interface &osd, core_options *options)
}
// otherwise, perform validity checks before anything else
- else if (mame_validitychecks(driver) != 0)
+ else if (mame_validitychecks(*options, driver) != 0)
return MAMERR_FAILED_VALIDITY;
firstgame = false;
@@ -567,27 +567,22 @@ void mame_parse_ini_files(core_options *options, const game_driver *driver)
static int parse_ini_file(core_options *options, const char *name, int priority)
{
- file_error filerr;
- mame_file *file;
-
/* update game name so depending callback options could be added */
- if (priority==OPTION_PRIORITY_DRIVER_INI || priority==OPTION_PRIORITY_SOURCE_INI) {
+ if (priority == OPTION_PRIORITY_DRIVER_INI || priority == OPTION_PRIORITY_SOURCE_INI)
options_force_option_callback(options, OPTION_GAMENAME, name, priority);
- }
/* don't parse if it has been disabled */
if (!options_get_bool(options, OPTION_READCONFIG))
return FALSE;
/* open the file; if we fail, that's ok */
- astring fname(name, ".ini");
- filerr = mame_fopen_options(options, SEARCHPATH_INI, fname, OPEN_FLAG_READ, &file);
+ emu_file file(*options, SEARCHPATH_INI, OPEN_FLAG_READ);
+ file_error filerr = file.open(name, ".ini");
if (filerr != FILERR_NONE)
return FALSE;
/* parse the file and close it */
mame_printf_verbose("Parsing %s.ini\n", name);
- options_parse_ini_file(options, mame_core_file(file), priority, OPTION_PRIORITY_DRIVER_INI);
- mame_fclose(file);
+ options_parse_ini_file(options, file, priority, OPTION_PRIORITY_DRIVER_INI);
return TRUE;
}
diff --git a/src/emu/mconfig.h b/src/emu/mconfig.h
index bac647a4889..fa5f019d773 100644
--- a/src/emu/mconfig.h
+++ b/src/emu/mconfig.h
@@ -84,11 +84,11 @@
#define NVRAM_HANDLER_NAME(name) nvram_handler_##name
-#define NVRAM_HANDLER(name) void NVRAM_HANDLER_NAME(name)(running_machine *machine, mame_file *file, int read_or_write)
+#define NVRAM_HANDLER(name) void NVRAM_HANDLER_NAME(name)(running_machine *machine, emu_file *file, int read_or_write)
#define NVRAM_HANDLER_CALL(name) NVRAM_HANDLER_NAME(name)(machine, file, read_or_write)
#define MEMCARD_HANDLER_NAME(name) memcard_handler_##name
-#define MEMCARD_HANDLER(name) void MEMCARD_HANDLER_NAME(name)(running_machine *machine, mame_file *file, int action)
+#define MEMCARD_HANDLER(name) void MEMCARD_HANDLER_NAME(name)(running_machine *machine, emu_file &file, int action)
#define MEMCARD_HANDLER_CALL(name) MEMCARD_HANDLER_NAME(name)(machine, file, action)
@@ -110,8 +110,8 @@ class screen_device_config;
// various callback functions
-typedef void (*nvram_handler_func)(running_machine *machine, mame_file *file, int read_or_write);
-typedef void (*memcard_handler_func)(running_machine *machine, mame_file *file, int action);
+typedef void (*nvram_handler_func)(running_machine *machine, emu_file *file, int read_or_write);
+typedef void (*memcard_handler_func)(running_machine *machine, emu_file &file, int action);
diff --git a/src/emu/render.c b/src/emu/render.c
index 5f348ae5861..94824986872 100644
--- a/src/emu/render.c
+++ b/src/emu/render.c
@@ -721,9 +721,9 @@ render_container::render_container(render_manager &manager, screen_device *scree
{
// set the initial orientation and brightness/contrast/gamma
m_user.m_orientation = manager.machine().gamedrv->flags & ORIENTATION_MASK;
- m_user.m_brightness = options_get_float(manager.machine().options(), OPTION_BRIGHTNESS);
- m_user.m_contrast = options_get_float(manager.machine().options(), OPTION_CONTRAST);
- m_user.m_gamma = options_get_float(manager.machine().options(), OPTION_GAMMA);
+ m_user.m_brightness = options_get_float(&manager.machine().options(), OPTION_BRIGHTNESS);
+ m_user.m_contrast = options_get_float(&manager.machine().options(), OPTION_CONTRAST);
+ m_user.m_gamma = options_get_float(&manager.machine().options(), OPTION_GAMMA);
}
// allocate a client to the main palette
@@ -1066,26 +1066,26 @@ render_target::render_target(render_manager &manager, const char *layoutfile, UI
m_debug_containers(manager.machine().m_respool)
{
// determine the base layer configuration based on options
- m_base_layerconfig.set_backdrops_enabled(options_get_bool(manager.machine().options(), OPTION_USE_BACKDROPS));
- m_base_layerconfig.set_overlays_enabled(options_get_bool(manager.machine().options(), OPTION_USE_OVERLAYS));
- m_base_layerconfig.set_bezels_enabled(options_get_bool(manager.machine().options(), OPTION_USE_BEZELS));
- m_base_layerconfig.set_zoom_to_screen(options_get_bool(manager.machine().options(), OPTION_ARTWORK_CROP));
+ m_base_layerconfig.set_backdrops_enabled(options_get_bool(&manager.machine().options(), OPTION_USE_BACKDROPS));
+ m_base_layerconfig.set_overlays_enabled(options_get_bool(&manager.machine().options(), OPTION_USE_OVERLAYS));
+ m_base_layerconfig.set_bezels_enabled(options_get_bool(&manager.machine().options(), OPTION_USE_BEZELS));
+ m_base_layerconfig.set_zoom_to_screen(options_get_bool(&manager.machine().options(), OPTION_ARTWORK_CROP));
// determine the base orientation based on options
m_orientation = ROT0;
- if (!options_get_bool(manager.machine().options(), OPTION_ROTATE))
+ if (!options_get_bool(&manager.machine().options(), OPTION_ROTATE))
m_base_orientation = orientation_reverse(manager.machine().gamedrv->flags & ORIENTATION_MASK);
// rotate left/right
- if (options_get_bool(manager.machine().options(), OPTION_ROR) || (options_get_bool(manager.machine().options(), OPTION_AUTOROR) && (manager.machine().gamedrv->flags & ORIENTATION_SWAP_XY)))
+ if (options_get_bool(&manager.machine().options(), OPTION_ROR) || (options_get_bool(&manager.machine().options(), OPTION_AUTOROR) && (manager.machine().gamedrv->flags & ORIENTATION_SWAP_XY)))
m_base_orientation = orientation_add(ROT90, m_base_orientation);
- if (options_get_bool(manager.machine().options(), OPTION_ROL) || (options_get_bool(manager.machine().options(), OPTION_AUTOROL) && (manager.machine().gamedrv->flags & ORIENTATION_SWAP_XY)))
+ if (options_get_bool(&manager.machine().options(), OPTION_ROL) || (options_get_bool(&manager.machine().options(), OPTION_AUTOROL) && (manager.machine().gamedrv->flags & ORIENTATION_SWAP_XY)))
m_base_orientation = orientation_add(ROT270, m_base_orientation);
// flip X/Y
- if (options_get_bool(manager.machine().options(), OPTION_FLIPX))
+ if (options_get_bool(&manager.machine().options(), OPTION_FLIPX))
m_base_orientation ^= ORIENTATION_FLIP_X;
- if (options_get_bool(manager.machine().options(), OPTION_FLIPY))
+ if (options_get_bool(&manager.machine().options(), OPTION_FLIPY))
m_base_orientation ^= ORIENTATION_FLIP_Y;
// set the orientation and layerconfig equal to the base
@@ -1680,14 +1680,13 @@ bool render_target::load_layout_file(const char *dirname, const char *filename)
fname.ins(0, PATH_SEPARATOR).ins(0, dirname);
// attempt to open the file; bail if we can't
- mame_file *layoutfile;
- file_error filerr = mame_fopen(SEARCHPATH_ARTWORK, fname, OPEN_FLAG_READ, &layoutfile);
+ emu_file layoutfile(manager().machine().options(), SEARCHPATH_ARTWORK, OPEN_FLAG_READ);
+ file_error filerr = layoutfile.open(fname);
if (filerr != FILERR_NONE)
return false;
// read the file
- rootnode = xml_file_read(mame_core_file(layoutfile), NULL);
- mame_fclose(layoutfile);
+ rootnode = xml_file_read(layoutfile, NULL);
}
// if we didn't get a properly-formatted XML file, record a warning and exit
@@ -2797,19 +2796,19 @@ void render_manager::config_save(int config_type, xml_data_node *parentnode)
container->get_user_settings(settings);
// output the color controls
- if (settings.m_brightness != options_get_float(m_machine.options(), OPTION_BRIGHTNESS))
+ if (settings.m_brightness != options_get_float(&m_machine.options(), OPTION_BRIGHTNESS))
{
xml_set_attribute_float(screennode, "brightness", settings.m_brightness);
changed = true;
}
- if (settings.m_contrast != options_get_float(m_machine.options(), OPTION_CONTRAST))
+ if (settings.m_contrast != options_get_float(&m_machine.options(), OPTION_CONTRAST))
{
xml_set_attribute_float(screennode, "contrast", settings.m_contrast);
changed = true;
}
- if (settings.m_gamma != options_get_float(m_machine.options(), OPTION_GAMMA))
+ if (settings.m_gamma != options_get_float(&m_machine.options(), OPTION_GAMMA))
{
xml_set_attribute_float(screennode, "gamma", settings.m_gamma);
changed = true;
diff --git a/src/emu/rendfont.c b/src/emu/rendfont.c
index 6961a115120..327332b5365 100644
--- a/src/emu/rendfont.c
+++ b/src/emu/rendfont.c
@@ -139,13 +139,10 @@ render_font::render_font(render_manager &manager, const char *filename)
return;
// load the raw data instead
- mame_file *ramfile;
- file_error filerr = mame_fopen_ram(font_uismall, sizeof(font_uismall), OPEN_FLAG_READ, &ramfile);
+ emu_file ramfile(manager.machine().options(), NULL, OPEN_FLAG_READ);
+ file_error filerr = ramfile.open_ram(font_uismall, sizeof(font_uismall));
if (filerr == FILERR_NONE)
- {
load_cached(ramfile, 0);
- mame_fclose(ramfile);
- }
}
@@ -415,22 +412,19 @@ float render_font::utf8string_width(float height, float aspect, const char *utf8
bool render_font::load_cached_bdf(const char *filename)
{
// first try to open the BDF itself
- mame_file *file;
- file_error filerr = mame_fopen(SEARCHPATH_FONT, filename, OPEN_FLAG_READ, &file);
+ emu_file file(manager().machine().options(), SEARCHPATH_FONT, OPEN_FLAG_READ);
+ file_error filerr = file.open(filename);
if (filerr != FILERR_NONE)
return false;
// determine the file size and allocate memory
- m_rawsize = mame_fsize(file);
+ m_rawsize = file.size();
char *data = auto_alloc_array_clear(&m_manager.machine(), char, m_rawsize + 1);
// read the first chunk
- UINT32 bytes = mame_fread(file, data, MIN(CACHED_BDF_HASH_SIZE, m_rawsize));
+ UINT32 bytes = file.read(data, MIN(CACHED_BDF_HASH_SIZE, m_rawsize));
if (bytes != MIN(CACHED_BDF_HASH_SIZE, m_rawsize))
- {
- mame_fclose(file);
return false;
- }
// has the chunk
UINT32 hash = crc32(0, (const UINT8 *)data, bytes) ^ (UINT32)m_rawsize;
@@ -440,30 +434,29 @@ bool render_font::load_cached_bdf(const char *filename)
cachedname.del(cachedname.len() - 3, 3).cat("bdc");
// attempt to open the cached version of the font
- mame_file *cachefile;
- filerr = mame_fopen(SEARCHPATH_FONT, cachedname, OPEN_FLAG_READ, &cachefile);
- if (filerr == FILERR_NONE)
{
- // if we have a cached version, load it
- bool result = load_cached(cachefile, hash);
- mame_fclose(cachefile);
-
- // if that worked, we're done
- if (result)
+ emu_file cachefile(manager().machine().options(), SEARCHPATH_FONT, OPEN_FLAG_READ);
+ filerr = cachefile.open(cachedname);
+ if (filerr == FILERR_NONE)
{
- mame_fclose(file);
- auto_free(&m_manager.machine(), data);
- return true;
+ // if we have a cached version, load it
+ bool result = load_cached(cachefile, hash);
+
+ // if that worked, we're done
+ if (result)
+ {
+ auto_free(&m_manager.machine(), data);
+ return true;
+ }
}
}
// read in the rest of the font
if (bytes < m_rawsize)
{
- UINT32 read = mame_fread(file, data + bytes, m_rawsize - bytes);
+ UINT32 read = file.read(data + bytes, m_rawsize - bytes);
if (read != m_rawsize - bytes)
{
- mame_fclose(file);
auto_free(&m_manager.machine(), data);
return false;
}
@@ -481,7 +474,6 @@ bool render_font::load_cached_bdf(const char *filename)
save_cached(cachedname, hash);
// close the file
- mame_fclose(file);
return result;
}
@@ -604,14 +596,14 @@ bool render_font::load_bdf()
// load_cached - load a font in cached format
//-------------------------------------------------
-bool render_font::load_cached(mame_file *file, UINT32 hash)
+bool render_font::load_cached(emu_file &file, UINT32 hash)
{
// get the file size
- UINT64 filesize = mame_fsize(file);
+ UINT64 filesize = file.size();
// first read the header
UINT8 header[CACHED_HEADER_SIZE];
- UINT32 bytes_read = mame_fread(file, header, CACHED_HEADER_SIZE);
+ UINT32 bytes_read = file.read(header, CACHED_HEADER_SIZE);
if (bytes_read != CACHED_HEADER_SIZE)
return false;
@@ -629,7 +621,7 @@ bool render_font::load_cached(mame_file *file, UINT32 hash)
// now read the rest of the data
UINT8 *data = auto_alloc_array(&m_manager.machine(), UINT8, filesize - CACHED_HEADER_SIZE);
- bytes_read = mame_fread(file, data, filesize - CACHED_HEADER_SIZE);
+ bytes_read = file.read(data, filesize - CACHED_HEADER_SIZE);
if (bytes_read != filesize - CACHED_HEADER_SIZE)
{
auto_free(&m_manager.machine(), data);
@@ -681,8 +673,8 @@ bool render_font::save_cached(const char *filename, UINT32 hash)
mame_printf_warning("Generating cached BDF font...\n");
// attempt to open the file
- mame_file *file;
- file_error filerr = mame_fopen(SEARCHPATH_FONT, filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
+ emu_file file(manager().machine().options(), SEARCHPATH_FONT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE);
+ file_error filerr = file.open(filename);
if (filerr != FILERR_NONE)
return false;
@@ -728,12 +720,12 @@ bool render_font::save_cached(const char *filename, UINT32 hash)
*dest++ = numchars >> 8;
*dest++ = numchars & 0xff;
assert(dest - tempbuffer == CACHED_HEADER_SIZE);
- UINT32 bytes_written = mame_fwrite(file, tempbuffer, dest - tempbuffer);
+ UINT32 bytes_written = file.write(tempbuffer, dest - tempbuffer);
if (bytes_written != dest - tempbuffer)
throw emu_fatalerror("Error writing cached file");
// write the empty table to the beginning of the file
- bytes_written = mame_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE);
+ bytes_written = file.write(chartable, numchars * CACHED_CHAR_SIZE);
if (bytes_written != numchars * CACHED_CHAR_SIZE)
throw emu_fatalerror("Error writing cached file");
@@ -775,7 +767,7 @@ bool render_font::save_cached(const char *filename, UINT32 hash)
*dest++ = accum;
// write the data
- bytes_written = mame_fwrite(file, tempbuffer, dest - tempbuffer);
+ bytes_written = file.write(tempbuffer, dest - tempbuffer);
if (bytes_written != dest - tempbuffer)
throw emu_fatalerror("Error writing cached file");
@@ -804,21 +796,19 @@ bool render_font::save_cached(const char *filename, UINT32 hash)
}
// seek back to the beginning and rewrite the table
- mame_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
- bytes_written = mame_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE);
+ file.seek(CACHED_HEADER_SIZE, SEEK_SET);
+ bytes_written = file.write(chartable, numchars * CACHED_CHAR_SIZE);
if (bytes_written != numchars * CACHED_CHAR_SIZE)
throw emu_fatalerror("Error writing cached file");
// all done
- mame_fclose(file);
auto_free(&m_manager.machine(), tempbuffer);
auto_free(&m_manager.machine(), chartable);
return true;
}
catch (...)
{
- mame_fclose(file);
- osd_rmfile(filename);
+ file.remove_on_close();
auto_free(&m_manager.machine(), tempbuffer);
auto_free(&m_manager.machine(), chartable);
return false;
diff --git a/src/emu/rendfont.h b/src/emu/rendfont.h
index ad930f63fb8..8d8ad66a450 100644
--- a/src/emu/rendfont.h
+++ b/src/emu/rendfont.h
@@ -101,7 +101,7 @@ private:
void char_expand(unicode_char chnum, glyph &ch);
bool load_cached_bdf(const char *filename);
bool load_bdf();
- bool load_cached(mame_file *file, UINT32 hash);
+ bool load_cached(emu_file &file, UINT32 hash);
bool save_cached(const char *filename, UINT32 hash);
// internal state
diff --git a/src/emu/rendlay.c b/src/emu/rendlay.c
index deb4b8a0893..6b2f09ab623 100644
--- a/src/emu/rendlay.c
+++ b/src/emu/rendlay.c
@@ -596,6 +596,7 @@ layout_element::component::component(running_machine &machine, xml_data_node &co
m_type(CTYPE_INVALID),
m_state(0),
m_bitmap(NULL),
+ m_file(NULL),
m_hasalpha(false)
{
// fetch common data
@@ -610,6 +611,7 @@ layout_element::component::component(running_machine &machine, xml_data_node &co
m_dirname = dirname;
m_imagefile = xml_get_attribute_string_with_subst(machine, compnode, "file", "");
m_alphafile = xml_get_attribute_string_with_subst(machine, compnode, "alphafile", "");
+ m_file = global_alloc(emu_file(machine.options(), OPTION_ARTPATH, OPEN_FLAG_READ));
}
// text nodes
@@ -663,6 +665,7 @@ layout_element::component::component(running_machine &machine, xml_data_node &co
layout_element::component::~component()
{
+ global_free(m_file);
global_free(m_bitmap);
}
@@ -898,11 +901,12 @@ void layout_element::component::draw_text(running_machine &machine, bitmap_t &de
bitmap_t *layout_element::component::load_bitmap()
{
// load the basic bitmap
- bitmap_t *bitmap = render_load_png(OPTION_ARTPATH, m_dirname, m_imagefile, NULL, &m_hasalpha);
+ assert(m_file != NULL);
+ bitmap_t *bitmap = render_load_png(*m_file, m_dirname, m_imagefile, NULL, &m_hasalpha);
if (bitmap != NULL && m_alphafile)
// load the alpha bitmap if specified
- if (render_load_png(OPTION_ARTPATH, m_dirname, m_alphafile, bitmap, &m_hasalpha) == NULL)
+ if (render_load_png(*m_file, m_dirname, m_alphafile, bitmap, &m_hasalpha) == NULL)
{
global_free(bitmap);
bitmap = NULL;
diff --git a/src/emu/rendlay.h b/src/emu/rendlay.h
index beed528923e..94afb5292c9 100644
--- a/src/emu/rendlay.h
+++ b/src/emu/rendlay.h
@@ -152,6 +152,7 @@ private:
astring m_string; // string for text components
bitmap_t * m_bitmap; // source bitmap for images
astring m_dirname; // directory name of image file (for lazy loading)
+ emu_file * m_file; // file object for reading image/alpha files
astring m_imagefile; // name of the image file (for lazy loading)
astring m_alphafile; // name of the alpha file (for lazy loading)
bool m_hasalpha; // is there any alpha component present?
diff --git a/src/emu/rendutil.c b/src/emu/rendutil.c
index c6c9dea23fc..bb8b414907d 100644
--- a/src/emu/rendutil.c
+++ b/src/emu/rendutil.c
@@ -560,11 +560,9 @@ void render_line_to_quad(const render_bounds *bounds, float width, render_bounds
bitmap_t
-------------------------------------------------*/
-bitmap_t *render_load_png(const char *path, const char *dirname, const char *filename, bitmap_t *alphadest, bool *hasalpha)
+bitmap_t *render_load_png(emu_file &file, const char *dirname, const char *filename, bitmap_t *alphadest, bool *hasalpha)
{
bitmap_t *bitmap = NULL;
- file_error filerr;
- mame_file *file;
png_info png;
png_error result;
@@ -574,13 +572,13 @@ bitmap_t *render_load_png(const char *path, const char *dirname, const char *fil
fname.cpy(filename);
else
fname.cpy(dirname).cat(PATH_SEPARATOR).cat(filename);
- filerr = mame_fopen(path, fname, OPEN_FLAG_READ, &file);
+ file_error filerr = file.open(fname);
if (filerr != FILERR_NONE)
return NULL;
/* read the PNG data */
- result = png_read_file(mame_core_file(file), &png);
- mame_fclose(file);
+ result = png_read_file(file, &png);
+ file.close();
if (result != PNGERR_NONE)
return NULL;
diff --git a/src/emu/rendutil.h b/src/emu/rendutil.h
index e6d1a423842..8e7b012f126 100644
--- a/src/emu/rendutil.h
+++ b/src/emu/rendutil.h
@@ -28,7 +28,7 @@ void render_resample_argb_bitmap_hq(void *dest, UINT32 drowpixels, UINT32 dwidth
int render_clip_line(render_bounds *bounds, const render_bounds *clip);
int render_clip_quad(render_bounds *bounds, const render_bounds *clip, render_quad_texuv *texcoords);
void render_line_to_quad(const render_bounds *bounds, float width, render_bounds *bounds0, render_bounds *bounds1);
-bitmap_t *render_load_png(const char *path, const char *dirname, const char *filename, bitmap_t *alphadest, bool *hasalpha);
+bitmap_t *render_load_png(emu_file &file, const char *dirname, const char *filename, bitmap_t *alphadest, bool *hasalpha);
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);
}
}
diff --git a/src/emu/romload.h b/src/emu/romload.h
index b4d8584f7f2..cab3a18cf95 100644
--- a/src/emu/romload.h
+++ b/src/emu/romload.h
@@ -285,8 +285,8 @@ int rom_load_knownbad(running_machine *machine);
/* ----- Helpers ----- */
-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(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, const char *ext, const rom_entry *romp, emu_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);
/* ----- ROM iteration ----- */
@@ -323,16 +323,13 @@ astring &rom_region_name(astring &result, const game_driver *drv, const rom_sour
/* ----- disk handling ----- */
/* 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);
-
-/* 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);
/* return a pointer to the CHD file associated with the given region */
chd_file *get_disk_handle(running_machine *machine, const char *region);
/* set a pointer to the CHD file associated with the given region */
-void set_disk_handle(running_machine *machine, const char *region, mame_file *file, chd_file *chd);
+void set_disk_handle(running_machine &machine, const char *region, emu_file &file, chd_file &chdfile);
void load_software_part_region(device_t *device, char *swlist, char *swname, rom_entry *start_region);
diff --git a/src/emu/screen.c b/src/emu/screen.c
index 9f3cba08710..37005cb91ca 100644
--- a/src/emu/screen.c
+++ b/src/emu/screen.c
@@ -226,7 +226,7 @@ void screen_device_config::static_set_default_position(device_config *device, do
// configuration
//-------------------------------------------------
-bool screen_device_config::device_validity_check(const game_driver &driver) const
+bool screen_device_config::device_validity_check(core_options &options, const game_driver &driver) const
{
bool error = false;
@@ -363,10 +363,10 @@ void screen_device::device_start()
m_scanline_timer->adjust(time_until_pos(0));
// create burn-in bitmap
- if (options_get_int(machine->options(), OPTION_BURNIN) > 0)
+ if (options_get_int(&machine->options(), OPTION_BURNIN) > 0)
{
int width, height;
- if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0)
+ if (sscanf(options_get_string(&machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0)
width = height = 300;
m_burnin = auto_alloc(machine, bitmap_t(width, height, BITMAP_FORMAT_INDEXED64));
if (m_burnin == NULL)
@@ -375,7 +375,7 @@ void screen_device::device_start()
}
// load the effect overlay
- const char *overname = options_get_string(machine->options(), OPTION_EFFECT);
+ const char *overname = options_get_string(&machine->options(), OPTION_EFFECT);
if (overname != NULL && strcmp(overname, "none") != 0)
load_effect_overlay(overname);
@@ -1027,10 +1027,8 @@ void screen_device::finalize_burnin()
// write the final PNG
// compute the name and create the file
- astring fname;
- fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename(), tag());
- mame_file *file;
- file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ emu_file file(m_machine.options(), SEARCHPATH_SCREENSHOT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(machine->basename(), PATH_SEPARATOR "burnin-", tag());
if (filerr == FILERR_NONE)
{
png_info pnginfo = { 0 };
@@ -1044,11 +1042,10 @@ void screen_device::finalize_burnin()
png_add_text(&pnginfo, "System", text);
// now do the actual work
- pngerr = png_write_bitmap(mame_core_file(file), &pnginfo, finalmap, 0, NULL);
+ pngerr = png_write_bitmap(file, &pnginfo, finalmap, 0, NULL);
// free any data allocated
png_free(&pnginfo);
- mame_fclose(file);
}
}
@@ -1067,7 +1064,8 @@ void screen_device::load_effect_overlay(const char *filename)
fullname.cat(".png");
// load the file
- m_screen_overlay_bitmap = render_load_png(OPTION_ARTPATH, NULL, fullname, NULL, NULL);
+ emu_file file(m_machine.options(), OPTION_ARTPATH, OPEN_FLAG_READ);
+ m_screen_overlay_bitmap = render_load_png(file, NULL, fullname, NULL, NULL);
if (m_screen_overlay_bitmap != NULL)
m_container->set_overlay(m_screen_overlay_bitmap);
else
diff --git a/src/emu/screen.h b/src/emu/screen.h
index 26e11adaafe..2177b6dd732 100644
--- a/src/emu/screen.h
+++ b/src/emu/screen.h
@@ -120,7 +120,7 @@ public:
private:
// device_config overrides
- virtual bool device_validity_check(const game_driver &driver) const;
+ virtual bool device_validity_check(core_options &options, const game_driver &driver) const;
// inline configuration data
screen_type_enum m_type; // type of screen
diff --git a/src/emu/softlist.c b/src/emu/softlist.c
index f354f97527b..dbe04b01ad2 100644
--- a/src/emu/softlist.c
+++ b/src/emu/softlist.c
@@ -41,7 +41,7 @@ typedef struct _parse_state
struct _software_list
{
- mame_file *file;
+ emu_file *file;
object_pool *pool;
parse_state state;
const char *description;
@@ -824,9 +824,9 @@ static int software_list_get_count(software_list *swlist)
parent software, if any
-------------------------------------------------*/
-const char *software_get_clone(char *swlist, const char *swname)
+const char *software_get_clone(core_options &options, char *swlist, const char *swname)
{
- software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL);
+ software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL);
const char *retval = NULL;
if (software_list_ptr)
{
@@ -844,9 +844,9 @@ const char *software_get_clone(char *swlist, const char *swname)
the software
-------------------------------------------------*/
-UINT32 software_get_support(char *swlist, const char *swname)
+UINT32 software_get_support(core_options &options, char *swlist, const char *swname)
{
- software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL);
+ software_list *software_list_ptr = software_list_open(options, swlist, FALSE, NULL);
UINT32 retval = 0;
if (software_list_ptr)
@@ -872,7 +872,7 @@ void software_list_parse(software_list *swlist,
UINT32 len;
XML_Memory_Handling_Suite memcallbacks;
- mame_fseek(swlist->file, 0, SEEK_SET);
+ swlist->file->seek(0, SEEK_SET);
memset(&swlist->state, 0, sizeof(swlist->state));
swlist->state.error_proc = error_proc;
@@ -892,8 +892,8 @@ void software_list_parse(software_list *swlist,
while(!swlist->state.done)
{
- len = mame_fread(swlist->file, buf, sizeof(buf));
- swlist->state.done = mame_feof(swlist->file);
+ len = swlist->file->read(buf, sizeof(buf));
+ swlist->state.done = swlist->file->eof();
if (XML_Parse(swlist->state.parser, buf, len, swlist->state.done) == XML_STATUS_ERROR)
{
parse_error(&swlist->state, "[%lu:%lu]: %s\n",
@@ -917,13 +917,12 @@ done:
software_list_open
-------------------------------------------------*/
-software_list *software_list_open(core_options *options, const char *listname, int is_preload,
+software_list *software_list_open(core_options &options, const char *listname, int is_preload,
void (*error_proc)(const char *message))
{
- file_error filerr;
- astring *fname;
software_list *swlist = NULL;
object_pool *pool = NULL;
+ file_error filerr;
/* create a pool for this software list file */
pool = pool_alloc_lib(error_proc);
@@ -941,10 +940,8 @@ software_list *software_list_open(core_options *options, const char *listname, i
swlist->error_proc = error_proc;
/* open a file */
- fname = astring_assemble_2(astring_alloc(), listname, ".xml");
- filerr = mame_fopen_options(options, SEARCHPATH_HASH, astring_c(fname), OPEN_FLAG_READ, &swlist->file);
- astring_free(fname);
-
+ swlist->file = global_alloc(emu_file(options, SEARCHPATH_HASH, OPEN_FLAG_READ));
+ filerr = swlist->file->open(listname, ".xml");
if (filerr != FILERR_NONE)
goto error;
@@ -972,8 +969,8 @@ void software_list_close(software_list *swlist)
if (swlist == NULL)
return;
- if (swlist->file)
- mame_fclose(swlist->file);
+ if (swlist->file != NULL)
+ global_free(swlist->file);
pool_free_lib(swlist->pool);
}
@@ -1290,7 +1287,7 @@ bool load_software_part(device_image_interface *image, const char *path, softwar
if ( swlist_name )
{
/* Try to open the software list xml file explicitly named by the user */
- software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL );
+ software_list_ptr = software_list_open( image->device().machine->options(), swlist_name, FALSE, NULL );
if ( software_list_ptr )
{
@@ -1562,10 +1559,7 @@ static DEVICE_VALIDITY_CHECK( software_list )
{
if (swlist->list_name[i])
{
- if (mame_options() == NULL)
- return FALSE;
-
- software_list *list = software_list_open(mame_options(), swlist->list_name[i], FALSE, NULL);
+ software_list *list = software_list_open(options, swlist->list_name[i], FALSE, NULL);
/* if no .xml list is found, then return (this happens e.g. if you moved/renamed the xml list) */
if (list == NULL)
@@ -1904,7 +1898,7 @@ void ui_mess_menu_software_list(running_machine *machine, ui_menu *menu, void *p
{
device_image_interface *image = sw_state->image;
software_entry_state *entry = (software_entry_state *) event->itemref;
- software_list *tmp_list = software_list_open(mame_options(), sw_state->list_name, FALSE, NULL);
+ software_list *tmp_list = software_list_open(machine->options(), sw_state->list_name, FALSE, NULL);
software_info *tmp_info = software_list_find(tmp_list, entry->short_name, NULL);
// if the selected software has multiple parts that can be loaded, open the submenu
@@ -1944,7 +1938,7 @@ static void ui_mess_menu_populate_software_list(running_machine *machine, ui_men
{
if (swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM))
{
- software_list *list = software_list_open(mame_options(), swlist->list_name[i], FALSE, NULL);
+ software_list *list = software_list_open(machine->options(), swlist->list_name[i], FALSE, NULL);
if (list)
{
@@ -1974,7 +1968,7 @@ static void ui_mess_menu_populate_software_list(running_machine *machine, ui_men
{
if (swlist->list_name[i] && (swlist->list_type == SOFTWARE_LIST_COMPATIBLE_SYSTEM))
{
- software_list *list = software_list_open(mame_options(), swlist->list_name[i], FALSE, NULL);
+ software_list *list = software_list_open(machine->options(), swlist->list_name[i], FALSE, NULL);
if (list)
{
diff --git a/src/emu/softlist.h b/src/emu/softlist.h
index c1d406e865c..88e9ae95203 100644
--- a/src/emu/softlist.h
+++ b/src/emu/softlist.h
@@ -55,7 +55,7 @@ struct software_info
typedef struct _software_list software_list;
/* Handling a software list */
-software_list *software_list_open(core_options *options, const char *listname, int is_preload, void (*error_proc)(const char *message));
+software_list *software_list_open(core_options &options, const char *listname, int is_preload, void (*error_proc)(const char *message));
void software_list_close(software_list *swlist);
software_info *software_list_find(software_list *swlist, const char *look_for, software_info *prev);
const char *software_list_get_description(software_list *swlist);
@@ -65,8 +65,8 @@ software_part *software_find_part(software_info *sw, const char *partname, const
software_part *software_part_next(software_part *part);
/* helpers */
-const char *software_get_clone(char *swlist, const char *swname);
-UINT32 software_get_support(char *swlist, const char *swname);
+const char *software_get_clone(core_options &options, char *swlist, const char *swname);
+UINT32 software_get_support(core_options &options, char *swlist, const char *swname);
const char *software_part_get_feature(software_part *part, const char *feature_name);
bool load_software_part(device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name);
diff --git a/src/emu/sound.c b/src/emu/sound.c
index ef850023afc..56bcb780adb 100644
--- a/src/emu/sound.c
+++ b/src/emu/sound.c
@@ -773,15 +773,15 @@ sound_manager::sound_manager(running_machine &machine)
m_rightmix(NULL),
m_muted(0),
m_attenuation(0),
- m_nosound_mode(!options_get_bool(machine.options(), OPTION_SOUND)),
+ m_nosound_mode(!options_get_bool(&machine.options(), OPTION_SOUND)),
m_wavfile(NULL),
m_stream_list(machine.m_respool),
m_update_attoseconds(STREAMS_UPDATE_ATTOTIME.attoseconds),
m_last_update(attotime::zero)
{
// get filename for WAV file or AVI file if specified
- const char *wavfile = options_get_string(machine.options(), OPTION_WAVWRITE);
- const char *avifile = options_get_string(machine.options(), OPTION_AVIWRITE);
+ const char *wavfile = options_get_string(&machine.options(), OPTION_WAVWRITE);
+ const char *avifile = options_get_string(&machine.options(), OPTION_AVIWRITE);
// handle -nosound and lower sample rate if not recording WAV or AVI
if (m_nosound_mode && wavfile[0] == 0 && avifile[0] == 0)
@@ -809,7 +809,7 @@ sound_manager::sound_manager(running_machine &machine)
state_save_register_global(&machine, m_last_update);
// set the starting attenuation
- set_attenuation(options_get_int(machine.options(), OPTION_VOLUME));
+ set_attenuation(options_get_int(&machine.options(), OPTION_VOLUME));
// start the periodic update flushing timer
m_update_timer->adjust(STREAMS_UPDATE_ATTOTIME, 0, STREAMS_UPDATE_ATTOTIME);
diff --git a/src/emu/sound/samples.c b/src/emu/sound/samples.c
index 81f61b57b02..07d8754ba1b 100644
--- a/src/emu/sound/samples.c
+++ b/src/emu/sound/samples.c
@@ -48,7 +48,7 @@ INLINE samples_info *get_safe_token(device_t *device)
read_wav_sample - read a WAV file as a sample
-------------------------------------------------*/
-static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample *sample)
+static int read_wav_sample(running_machine *machine, emu_file &file, loaded_sample *sample)
{
unsigned long offset = 0;
UINT32 length, rate, filesize;
@@ -57,20 +57,20 @@ static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample
UINT32 sindex;
/* read the core header and make sure it's a WAVE file */
- offset += mame_fread(f, buf, 4);
+ offset += file.read(buf, 4);
if (offset < 4)
return 0;
if (memcmp(&buf[0], "RIFF", 4) != 0)
return 0;
/* get the total size */
- offset += mame_fread(f, &filesize, 4);
+ offset += file.read(&filesize, 4);
if (offset < 8)
return 0;
filesize = LITTLE_ENDIANIZE_INT32(filesize);
/* read the RIFF file type and make sure it's a WAVE file */
- offset += mame_fread(f, buf, 4);
+ offset += file.read(buf, 4);
if (offset < 12)
return 0;
if (memcmp(&buf[0], "WAVE", 4) != 0)
@@ -79,59 +79,59 @@ static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample
/* seek until we find a format tag */
while (1)
{
- offset += mame_fread(f, buf, 4);
- offset += mame_fread(f, &length, 4);
+ offset += file.read(buf, 4);
+ offset += file.read(&length, 4);
length = LITTLE_ENDIANIZE_INT32(length);
if (memcmp(&buf[0], "fmt ", 4) == 0)
break;
/* seek to the next block */
- mame_fseek(f, length, SEEK_CUR);
+ file.seek(length, SEEK_CUR);
offset += length;
if (offset >= filesize)
return 0;
}
/* read the format -- make sure it is PCM */
- offset += mame_fread(f, &temp16, 2);
+ offset += file.read(&temp16, 2);
temp16 = LITTLE_ENDIANIZE_INT16(temp16);
if (temp16 != 1)
return 0;
/* number of channels -- only mono is supported */
- offset += mame_fread(f, &temp16, 2);
+ offset += file.read(&temp16, 2);
temp16 = LITTLE_ENDIANIZE_INT16(temp16);
if (temp16 != 1)
return 0;
/* sample rate */
- offset += mame_fread(f, &rate, 4);
+ offset += file.read(&rate, 4);
rate = LITTLE_ENDIANIZE_INT32(rate);
/* bytes/second and block alignment are ignored */
- offset += mame_fread(f, buf, 6);
+ offset += file.read(buf, 6);
/* bits/sample */
- offset += mame_fread(f, &bits, 2);
+ offset += file.read(&bits, 2);
bits = LITTLE_ENDIANIZE_INT16(bits);
if (bits != 8 && bits != 16)
return 0;
/* seek past any extra data */
- mame_fseek(f, length - 16, SEEK_CUR);
+ file.seek(length - 16, SEEK_CUR);
offset += length - 16;
/* seek until we find a data tag */
while (1)
{
- offset += mame_fread(f, buf, 4);
- offset += mame_fread(f, &length, 4);
+ offset += file.read(buf, 4);
+ offset += file.read(&length, 4);
length = LITTLE_ENDIANIZE_INT32(length);
if (memcmp(&buf[0], "data", 4) == 0)
break;
/* seek to the next block */
- mame_fseek(f, length, SEEK_CUR);
+ file.seek(length, SEEK_CUR);
offset += length;
if (offset >= filesize)
return 0;
@@ -152,7 +152,7 @@ static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample
int sindex;
sample->data = auto_alloc_array(machine, INT16, length);
- mame_fread(f, sample->data, length);
+ file.read(sample->data, length);
/* convert 8-bit data to signed samples */
tempptr = (unsigned char *)sample->data;
@@ -163,7 +163,7 @@ static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample
{
/* 16-bit data is fine as-is */
sample->data = auto_alloc_array(machine, INT16, length/2);
- mame_fread(f, sample->data, length);
+ file.read(sample->data, length);
sample->length /= 2;
if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE)
for (sindex = 0; sindex < sample->length; sindex++)
@@ -184,7 +184,7 @@ loaded_samples *readsamples(running_machine *machine, const char *const *samplen
int i;
/* if the user doesn't want to use samples, bail */
- if (!options_get_bool(machine->options(), OPTION_SAMPLES))
+ if (!options_get_bool(&machine->options(), OPTION_SAMPLES))
return NULL;
if (samplenames == 0 || samplenames[0] == 0)
return NULL;
@@ -206,22 +206,14 @@ loaded_samples *readsamples(running_machine *machine, const char *const *samplen
for (i = 0; i < samples->total; i++)
if (samplenames[i+skipfirst][0])
{
- file_error filerr;
- mame_file *f;
-
- astring fname(basename, PATH_SEPARATOR, samplenames[i+skipfirst]);
- filerr = mame_fopen(SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ, &f);
+ emu_file file(machine->options(), SEARCHPATH_SAMPLE, OPEN_FLAG_READ);
+ file_error filerr = file.open(basename, PATH_SEPARATOR, samplenames[i+skipfirst]);
if (filerr != FILERR_NONE && skipfirst)
- {
- astring fname(samplenames[0] + 1, PATH_SEPARATOR, samplenames[i+skipfirst]);
- filerr = mame_fopen(SEARCHPATH_SAMPLE, fname, OPEN_FLAG_READ, &f);
- }
+ filerr = file.open(samplenames[0] + 1, PATH_SEPARATOR, samplenames[i+skipfirst]);
+
if (filerr == FILERR_NONE)
- {
- read_wav_sample(machine, f, &samples->sample[i]);
- mame_fclose(f);
- }
+ read_wav_sample(machine, file, &samples->sample[i]);
}
return samples;
diff --git a/src/emu/state.c b/src/emu/state.c
index 9759223044d..728e89762fb 100644
--- a/src/emu/state.c
+++ b/src/emu/state.c
@@ -237,7 +237,7 @@ void state_manager::save_memory(const char *module, const char *tag, UINT32 inde
// state
//-------------------------------------------------
-state_save_error state_manager::check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...))
+state_save_error state_manager::check_file(running_machine *machine, emu_file &file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...))
{
// if we want to validate the signature, compute it
UINT32 sig = 0;
@@ -245,10 +245,10 @@ state_save_error state_manager::check_file(running_machine *machine, mame_file *
sig = machine->state().signature();
// seek to the beginning and read the header
- mame_fcompress(file, FCOMPRESS_NONE);
- mame_fseek(file, 0, SEEK_SET);
+ file.compress(FCOMPRESS_NONE);
+ file.seek(0, SEEK_SET);
UINT8 header[HEADER_SIZE];
- if (mame_fread(file, header, sizeof(header)) != sizeof(header))
+ if (file.read(header, sizeof(header)) != sizeof(header))
{
if (errormsg != NULL)
(*errormsg)("Could not read " APPNAME " save file header");
@@ -264,19 +264,19 @@ state_save_error state_manager::check_file(running_machine *machine, mame_file *
// read_file - read the data from a file
//-------------------------------------------------
-state_save_error state_manager::read_file(mame_file *file)
+state_save_error state_manager::read_file(emu_file &file)
{
// if we have illegal registrations, return an error
if (m_illegal_regs > 0)
return STATERR_ILLEGAL_REGISTRATIONS;
// read the header and turn on compression for the rest of the file
- mame_fcompress(file, FCOMPRESS_NONE);
- mame_fseek(file, 0, SEEK_SET);
+ file.compress(FCOMPRESS_NONE);
+ file.seek(0, SEEK_SET);
UINT8 header[HEADER_SIZE];
- if (mame_fread(file, header, sizeof(header)) != sizeof(header))
+ if (file.read(header, sizeof(header)) != sizeof(header))
return STATERR_READ_ERROR;
- mame_fcompress(file, FCOMPRESS_MEDIUM);
+ file.compress(FCOMPRESS_MEDIUM);
// verify the header and report an error if it doesn't match
UINT32 sig = signature();
@@ -290,7 +290,7 @@ state_save_error state_manager::read_file(mame_file *file)
for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
{
UINT32 totalsize = entry->m_typesize * entry->m_typecount;
- if (mame_fread(file, entry->m_data, totalsize) != totalsize)
+ if (file.read(entry->m_data, totalsize) != totalsize)
return STATERR_READ_ERROR;
// handle flipping
@@ -310,7 +310,7 @@ state_save_error state_manager::read_file(mame_file *file)
// write_file - writes the data to a file
//-------------------------------------------------
-state_save_error state_manager::write_file(mame_file *file)
+state_save_error state_manager::write_file(emu_file &file)
{
// if we have illegal registrations, return an error
if (m_illegal_regs > 0)
@@ -326,11 +326,11 @@ state_save_error state_manager::write_file(mame_file *file)
*(UINT32 *)&header[0x1c] = LITTLE_ENDIANIZE_INT32(sig);
// write the header and turn on compression for the rest of the file
- mame_fcompress(file, FCOMPRESS_NONE);
- mame_fseek(file, 0, SEEK_SET);
- if (mame_fwrite(file, header, sizeof(header)) != sizeof(header))
+ file.compress(FCOMPRESS_NONE);
+ file.seek(0, SEEK_SET);
+ if (file.write(header, sizeof(header)) != sizeof(header))
return STATERR_WRITE_ERROR;
- mame_fcompress(file, FCOMPRESS_MEDIUM);
+ file.compress(FCOMPRESS_MEDIUM);
// call the pre-save functions
for (state_callback *func = m_presave_list.first(); func != NULL; func = func->next())
@@ -340,7 +340,7 @@ state_save_error state_manager::write_file(mame_file *file)
for (state_entry *entry = m_entry_list.first(); entry != NULL; entry = entry->next())
{
UINT32 totalsize = entry->m_typesize * entry->m_typecount;
- if (mame_fwrite(file, entry->m_data, totalsize) != totalsize)
+ if (file.write(entry->m_data, totalsize) != totalsize)
return STATERR_WRITE_ERROR;
}
return STATERR_NONE;
diff --git a/src/emu/state.h b/src/emu/state.h
index 65a5d619801..8b22f1b990c 100644
--- a/src/emu/state.h
+++ b/src/emu/state.h
@@ -202,9 +202,9 @@ public:
void save_pointer(T *value, const char *valname, UINT32 count, int index = 0) { save_pointer("global", NULL, index, value, valname, count); }
// file processing
- static state_save_error check_file(running_machine *machine, mame_file *file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...));
- state_save_error write_file(mame_file *file);
- state_save_error read_file(mame_file *file);
+ static state_save_error check_file(running_machine *machine, emu_file &file, const char *gamename, void (CLIB_DECL *errormsg)(const char *fmt, ...));
+ state_save_error write_file(emu_file &file);
+ state_save_error read_file(emu_file &file);
private:
// internal helpers
diff --git a/src/emu/timer.c b/src/emu/timer.c
index 698f01345fc..fbc1b132f67 100644
--- a/src/emu/timer.c
+++ b/src/emu/timer.c
@@ -200,7 +200,7 @@ void timer_device_config::static_set_ptr(device_config *device, void *ptr)
// configuration
//-------------------------------------------------
-bool timer_device_config::device_validity_check(const game_driver &driver) const
+bool timer_device_config::device_validity_check(core_options &options, const game_driver &driver) const
{
bool error = false;
diff --git a/src/emu/timer.h b/src/emu/timer.h
index 4e1c9bb36a4..d488ea25fab 100644
--- a/src/emu/timer.h
+++ b/src/emu/timer.h
@@ -128,7 +128,7 @@ public:
private:
// device_config overrides
- virtual bool device_validity_check(const game_driver &driver) const;
+ virtual bool device_validity_check(core_options &options, const game_driver &driver) const;
// timer types
enum timer_type
diff --git a/src/emu/ui.c b/src/emu/ui.c
index 0b1642c1336..847e4315093 100644
--- a/src/emu/ui.c
+++ b/src/emu/ui.c
@@ -247,7 +247,7 @@ int ui_init(running_machine *machine)
single_step = FALSE;
ui_set_handler(handler_messagebox, 0);
/* retrieve options */
- ui_use_natural_keyboard = options_get_bool(machine->options(), OPTION_NATURAL_KEYBOARD);
+ ui_use_natural_keyboard = options_get_bool(&machine->options(), OPTION_NATURAL_KEYBOARD);
return 0;
}
@@ -273,8 +273,8 @@ static void ui_exit(running_machine &machine)
int ui_display_startup_screens(running_machine *machine, int first_time, int show_disclaimer)
{
const int maxstate = 3;
- int str = options_get_int(machine->options(), OPTION_SECONDS_TO_RUN);
- int show_gameinfo = !options_get_bool(machine->options(), OPTION_SKIP_GAMEINFO);
+ int str = options_get_int(&machine->options(), OPTION_SECONDS_TO_RUN);
+ int show_gameinfo = !options_get_bool(&machine->options(), OPTION_SKIP_GAMEINFO);
int show_warnings = TRUE;
int state;
@@ -375,7 +375,7 @@ void ui_update_and_render(running_machine *machine, render_container *container)
/* if we're paused, dim the whole screen */
if (machine->phase() >= MACHINE_PHASE_RESET && (single_step || machine->paused()))
{
- int alpha = (1.0f - options_get_float(machine->options(), OPTION_PAUSE_BRIGHTNESS)) * 255.0f;
+ int alpha = (1.0f - options_get_float(&machine->options(), OPTION_PAUSE_BRIGHTNESS)) * 255.0f;
if (ui_menu_is_force_game_select())
alpha = 255;
if (alpha > 255)
@@ -412,7 +412,7 @@ render_font *ui_get_font(running_machine &machine)
{
/* allocate the font and messagebox string */
if (ui_font == NULL)
- ui_font = machine.render().font_alloc(options_get_string(machine.options(), OPTION_UI_FONT));
+ ui_font = machine.render().font_alloc(options_get_string(&machine.options(), OPTION_UI_FONT));
return ui_font;
}
@@ -1640,7 +1640,7 @@ static slider_state *slider_init(running_machine *machine)
}
/* add CPU overclocking (cheat only) */
- if (options_get_bool(machine->options(), OPTION_CHEAT))
+ if (options_get_bool(&machine->options(), OPTION_CHEAT))
{
device_execute_interface *exec = NULL;
for (bool gotone = machine->m_devicelist.first(exec); gotone; gotone = exec->next(exec))
@@ -1662,7 +1662,7 @@ static slider_state *slider_init(running_machine *machine)
void *param = (void *)screen;
/* add refresh rate tweaker */
- if (options_get_bool(machine->options(), OPTION_CHEAT))
+ if (options_get_bool(&machine->options(), OPTION_CHEAT))
{
string.printf("%s Refresh Rate", slider_get_screen_desc(*screen));
*tailptr = slider_alloc(machine, string, -10000, 0, 10000, 1000, slider_refresh, param);
@@ -2214,6 +2214,6 @@ int ui_get_use_natural_keyboard(running_machine *machine)
void ui_set_use_natural_keyboard(running_machine *machine, int use_natural_keyboard)
{
ui_use_natural_keyboard = use_natural_keyboard;
- options_set_bool(machine->options(), OPTION_NATURAL_KEYBOARD, use_natural_keyboard, OPTION_PRIORITY_CMDLINE);
+ options_set_bool(&machine->options(), OPTION_NATURAL_KEYBOARD, use_natural_keyboard, OPTION_PRIORITY_CMDLINE);
}
diff --git a/src/emu/uimenu.c b/src/emu/uimenu.c
index 70a7b5240a0..eebd2ff9c68 100644
--- a/src/emu/uimenu.c
+++ b/src/emu/uimenu.c
@@ -1405,7 +1405,7 @@ UINT32 ui_slider_ui_handler(running_machine *machine, render_container *containe
void ui_menu_force_game_select(running_machine *machine, render_container *container)
{
- char *gamename = (char *)options_get_string(machine->options(), OPTION_GAMENAME);
+ char *gamename = (char *)options_get_string(&machine->options(), OPTION_GAMENAME);
/* reset the menu stack */
ui_menu_stack_reset(machine);
@@ -1570,7 +1570,7 @@ static void menu_main_populate(running_machine *machine, ui_menu *menu, void *st
ui_menu_item_append(menu, "Crosshair Options", NULL, 0, (void *)menu_crosshair);
/* add cheat menu */
- if (options_get_bool(machine->options(), OPTION_CHEAT) && machine->cheat().first() != NULL)
+ if (options_get_bool(&machine->options(), OPTION_CHEAT) && machine->cheat().first() != NULL)
ui_menu_item_append(menu, "Cheat", NULL, 0, (void *)menu_cheat);
/* add memory card menu */
@@ -3254,7 +3254,6 @@ static void menu_crosshair_populate(running_machine *machine, ui_menu *menu)
int player;
UINT8 use_auto = FALSE;
UINT32 flags = 0;
- mame_path *path;
/* loop over player and add the manual items */
for (player = 0; player < MAX_PLAYERS; player++)
@@ -3300,76 +3299,72 @@ static void menu_crosshair_populate(running_machine *machine, ui_menu *menu)
/* search for crosshair graphics */
/* open a path to the crosshairs */
- path = mame_openpath(machine->options(), OPTION_CROSSHAIRPATH);
- if (path != NULL)
+ file_enumerator path(machine->options(), OPTION_CROSSHAIRPATH);
+ const osd_directory_entry *dir;
+ /* reset search flags */
+ int using_default = FALSE;
+ int finished = FALSE;
+ int found = FALSE;
+
+ /* if we are using the default, then we just need to find the first in the list */
+ if (strlen(settings.name) == 0)
+ using_default = TRUE;
+
+ /* look for the current name, then remember the name before */
+ /* and find the next name */
+ while (((dir = path.next()) != NULL) && !finished)
{
- const osd_directory_entry *dir;
+ int length = strlen(dir->name);
- /* reset search flags */
- int using_default = FALSE;
- int finished = FALSE;
- int found = FALSE;
+ /* look for files ending in .png with a name not larger then 9 chars*/
+ if ((length > 4) && (length <= CROSSHAIR_PIC_NAME_LENGTH + 4) &&
+ dir->name[length - 4] == '.' &&
+ tolower((UINT8)dir->name[length - 3]) == 'p' &&
+ tolower((UINT8)dir->name[length - 2]) == 'n' &&
+ tolower((UINT8)dir->name[length - 1]) == 'g')
- /* if we are using the default, then we just need to find the first in the list */
- if (strlen(settings.name) == 0)
- using_default = TRUE;
-
- /* look for the current name, then remember the name before */
- /* and find the next name */
- while (((dir = mame_readpath(path)) != NULL) && !finished)
{
- int length = strlen(dir->name);
-
- /* look for files ending in .png with a name not larger then 9 chars*/
- if ((length > 4) && (length <= CROSSHAIR_PIC_NAME_LENGTH + 4) &&
- dir->name[length - 4] == '.' &&
- tolower((UINT8)dir->name[length - 3]) == 'p' &&
- tolower((UINT8)dir->name[length - 2]) == 'n' &&
- tolower((UINT8)dir->name[length - 1]) == 'g')
+ /* remove .png from length */
+ length -= 4;
+ if (found || using_default)
{
- /* remove .png from length */
- length -= 4;
-
- if (found || using_default)
- {
- /* get the next name */
- strncpy(data->next_name, dir->name, length);
- data->next_name[length] = 0;
- finished = TRUE;
- }
- else if (!strncmp(dir->name, settings.name, length))
- {
- /* we found the current name */
- /* so loop once more to find the next name */
- found = TRUE;
- }
- else
- /* remember last name */
- /* we will do it here in case files get added to the directory */
- {
- strncpy(data->last_name, dir->name, length);
- data->last_name[length] = 0;
- }
+ /* get the next name */
+ strncpy(data->next_name, dir->name, length);
+ data->next_name[length] = 0;
+ finished = TRUE;
+ }
+ else if (!strncmp(dir->name, settings.name, length))
+ {
+ /* we found the current name */
+ /* so loop once more to find the next name */
+ found = TRUE;
+ }
+ else
+ /* remember last name */
+ /* we will do it here in case files get added to the directory */
+ {
+ strncpy(data->last_name, dir->name, length);
+ data->last_name[length] = 0;
}
}
- /* if name not found then next item is DEFAULT */
- if (!found && !using_default)
- {
- data->next_name[0] = 0;
- finished = TRUE;
- }
- /* setup the selection flags */
- flags = 0;
- if (finished)
- flags |= MENU_FLAG_RIGHT_ARROW;
- if (found)
- flags |= MENU_FLAG_LEFT_ARROW;
-
- /* add CROSSHAIR_ITEM_PIC menu */
- sprintf(temp_text, "P%d Crosshair", player + 1);
- ui_menu_item_append(menu, temp_text, using_default ? "DEFAULT" : settings.name, flags, data);
}
+ /* if name not found then next item is DEFAULT */
+ if (!found && !using_default)
+ {
+ data->next_name[0] = 0;
+ finished = TRUE;
+ }
+ /* setup the selection flags */
+ flags = 0;
+ if (finished)
+ flags |= MENU_FLAG_RIGHT_ARROW;
+ if (found)
+ flags |= MENU_FLAG_LEFT_ARROW;
+
+ /* add CROSSHAIR_ITEM_PIC menu */
+ sprintf(temp_text, "P%d Crosshair", player + 1);
+ ui_menu_item_append(menu, temp_text, using_default ? "DEFAULT" : settings.name, flags, data);
}
}
if (use_auto)
@@ -3467,7 +3462,7 @@ static void menu_select_game(running_machine *machine, ui_menu *menu, void *para
int audit_result;
/* audit the game first to see if we're going to work */
- audit_records = audit_images(menu->machine->options(), driver, AUDIT_VALIDATE_FAST, &audit);
+ audit_records = audit_images(&menu->machine->options(), driver, AUDIT_VALIDATE_FAST, &audit);
audit_result = audit_summary(driver, audit_records, audit, FALSE);
if (audit_records > 0)
global_free(audit);
@@ -3608,7 +3603,6 @@ static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state
{
int driver_count = driver_list_get_count(drivers);
int drivnum, listnum;
- mame_path *path;
UINT8 *found;
/* create a sorted copy of the main driver list */
@@ -3620,39 +3614,35 @@ static void menu_select_game_build_driver_list(ui_menu *menu, select_game_state
memset(found, 0, (driver_count + 7) / 8);
/* open a path to the ROMs and find them in the array */
- path = mame_openpath(menu->machine->options(), OPTION_ROMPATH);
- if (path != NULL)
- {
- const osd_directory_entry *dir;
-
- /* iterate while we get new objects */
- while ((dir = mame_readpath(path)) != NULL)
+ file_enumerator path(menu->machine->options(), OPTION_ROMPATH);
+ const osd_directory_entry *dir;
+
+ /* iterate while we get new objects */
+ while ((dir = path.next()) != NULL)
+ {
+ game_driver tempdriver;
+ game_driver *tempdriver_ptr;
+ const game_driver **found_driver;
+ char drivername[50];
+ char *dst = drivername;
+ const char *src;
+
+ /* build a name for it */
+ for (src = dir->name; *src != 0 && *src != '.' && dst < &drivername[ARRAY_LENGTH(drivername) - 1]; src++)
+ *dst++ = tolower((UINT8)*src);
+ *dst = 0;
+
+ /* find it in the array */
+ tempdriver.name = drivername;
+ tempdriver_ptr = &tempdriver;
+ found_driver = (const game_driver **)bsearch(&tempdriver_ptr, menustate->driverlist, driver_count, sizeof(*menustate->driverlist), menu_select_game_driver_compare);
+
+ /* if found, mark the corresponding entry in the array */
+ if (found_driver != NULL)
{
- game_driver tempdriver;
- game_driver *tempdriver_ptr;
- const game_driver **found_driver;
- char drivername[50];
- char *dst = drivername;
- const char *src;
-
- /* build a name for it */
- for (src = dir->name; *src != 0 && *src != '.' && dst < &drivername[ARRAY_LENGTH(drivername) - 1]; src++)
- *dst++ = tolower((UINT8)*src);
- *dst = 0;
-
- /* find it in the array */
- tempdriver.name = drivername;
- tempdriver_ptr = &tempdriver;
- found_driver = (const game_driver **)bsearch(&tempdriver_ptr, menustate->driverlist, driver_count, sizeof(*menustate->driverlist), menu_select_game_driver_compare);
-
- /* if found, mark the corresponding entry in the array */
- if (found_driver != NULL)
- {
- int index = found_driver - menustate->driverlist;
- found[index / 8] |= 1 << (index % 8);
- }
+ int index = found_driver - menustate->driverlist;
+ found[index / 8] |= 1 << (index % 8);
}
- mame_closepath(path);
}
/* now build the final list */
diff --git a/src/emu/validity.c b/src/emu/validity.c
index d1d32c80df3..4b4571c5688 100644
--- a/src/emu/validity.c
+++ b/src/emu/validity.c
@@ -1077,7 +1077,7 @@ static bool validate_inputs(const machine_config &config, int_map &defstr_map, i
checks
-------------------------------------------------*/
-static bool validate_devices(const machine_config &config, const ioport_list &portlist, region_array *rgninfo)
+static bool validate_devices(const machine_config &config, const ioport_list &portlist, region_array *rgninfo, core_options &options)
{
bool error = false;
const game_driver &driver = config.gamedrv();
@@ -1100,7 +1100,7 @@ static bool validate_devices(const machine_config &config, const ioport_list &po
mame_printf_warning("Device %s does not have short name defined\n", devconfig->name());
}
/* check for device-specific validity check */
- if (devconfig->validity_check(driver))
+ if (devconfig->validity_check(options, driver))
error = true;
}
@@ -1112,7 +1112,7 @@ static bool validate_devices(const machine_config &config, const ioport_list &po
mame_validitychecks - master validity checker
-------------------------------------------------*/
-bool mame_validitychecks(const game_driver *curdriver)
+bool mame_validitychecks(core_options &options, const game_driver *curdriver)
{
osd_ticks_t prep = 0;
osd_ticks_t expansion = 0;
@@ -1219,7 +1219,7 @@ bool mame_validitychecks(const game_driver *curdriver)
/* validate devices */
device_checks -= get_profile_ticks();
- error = validate_devices(config, portlist, &rgninfo) || error;
+ error = validate_devices(config, portlist, &rgninfo, options) || error;
device_checks += get_profile_ticks();
}
catch (emu_fatalerror &err)
diff --git a/src/emu/validity.h b/src/emu/validity.h
index 39013d674e7..71bcfaa8085 100644
--- a/src/emu/validity.h
+++ b/src/emu/validity.h
@@ -14,7 +14,7 @@
#ifndef __VALIDITY_H__
#define __VALIDITY_H__
-bool mame_validitychecks(const game_driver *driver);
+bool mame_validitychecks(core_options &options, const game_driver *driver);
bool validate_tag(const game_driver &driver, const char *object, const char *tag);
#endif
diff --git a/src/emu/video.c b/src/emu/video.c
index 4405c963b77..af5a4fbea28 100644
--- a/src/emu/video.c
+++ b/src/emu/video.c
@@ -112,13 +112,13 @@ video_manager::video_manager(running_machine &machine)
m_overall_real_ticks(0),
m_overall_emutime(attotime::zero),
m_overall_valid_counter(0),
- m_throttle(options_get_bool(machine.options(), OPTION_THROTTLE)),
+ m_throttle(options_get_bool(&machine.options(), OPTION_THROTTLE)),
m_fastforward(false),
- m_seconds_to_run(options_get_int(machine.options(), OPTION_SECONDS_TO_RUN)),
- m_auto_frameskip(options_get_bool(machine.options(), OPTION_AUTOFRAMESKIP)),
+ m_seconds_to_run(options_get_int(&machine.options(), OPTION_SECONDS_TO_RUN)),
+ m_auto_frameskip(options_get_bool(&machine.options(), OPTION_AUTOFRAMESKIP)),
m_speed(original_speed_setting()),
m_empty_skip_count(0),
- m_frameskip_level(options_get_int(machine.options(), OPTION_FRAMESKIP)),
+ m_frameskip_level(options_get_int(&machine.options(), OPTION_FRAMESKIP)),
m_frameskip_counter(0),
m_frameskip_adjust(0),
m_skipping_this_frame(false),
@@ -142,7 +142,7 @@ video_manager::video_manager(running_machine &machine)
update_refresh_speed();
// create a render target for snapshots
- const char *viewname = options_get_string(machine.options(), OPTION_SNAPVIEW);
+ const char *viewname = options_get_string(&machine.options(), OPTION_SNAPVIEW);
m_snap_native = (machine.primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0));
// the native target is hard-coded to our internal layout and has all options disabled
@@ -165,15 +165,15 @@ video_manager::video_manager(running_machine &machine)
}
// extract snap resolution if present
- if (sscanf(options_get_string(machine.options(), OPTION_SNAPSIZE), "%dx%d", &m_snap_width, &m_snap_height) != 2)
+ if (sscanf(options_get_string(&machine.options(), OPTION_SNAPSIZE), "%dx%d", &m_snap_width, &m_snap_height) != 2)
m_snap_width = m_snap_height = 0;
// start recording movie if specified
- const char *filename = options_get_string(machine.options(), OPTION_MNGWRITE);
+ const char *filename = options_get_string(&machine.options(), OPTION_MNGWRITE);
if (filename[0] != 0)
begin_recording(filename, MF_MNG);
- filename = options_get_string(machine.options(), OPTION_AVIWRITE);
+ filename = options_get_string(&machine.options(), OPTION_AVIWRITE);
if (filename[0] != 0)
begin_recording(filename, MF_AVI);
@@ -220,7 +220,7 @@ void video_manager::frame_update(bool debug)
// only render sound and video if we're in the running phase
int phase = m_machine.phase();
bool skipped_it = m_skipping_this_frame;
- if (phase == MACHINE_PHASE_RUNNING && (!m_machine.paused() || options_get_bool(m_machine.options(), OPTION_UPDATEINPAUSE)))
+ if (phase == MACHINE_PHASE_RUNNING && (!m_machine.paused() || options_get_bool(&m_machine.options(), OPTION_UPDATEINPAUSE)))
{
bool anything_changed = finish_screen_updates();
@@ -325,7 +325,7 @@ astring &video_manager::speed_text(astring &string)
// file handle
//-------------------------------------------------
-void video_manager::save_snapshot(screen_device *screen, mame_file &fp)
+void video_manager::save_snapshot(screen_device *screen, emu_file &file)
{
// validate
assert(!m_snap_native || screen != NULL);
@@ -342,7 +342,7 @@ void video_manager::save_snapshot(screen_device *screen, mame_file &fp)
// now do the actual work
const rgb_t *palette = (m_machine.palette != NULL) ? palette_entry_list_adjusted(m_machine.palette) : NULL;
- png_error error = png_write_bitmap(mame_core_file(&fp), &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette);
+ png_error error = png_write_bitmap(file, &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette);
if (error != PNGERR_NONE)
mame_printf_error("Error generating PNG for snapshot: png_error = %d\n", error);
@@ -365,26 +365,20 @@ void video_manager::save_active_screen_snapshots()
for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
if (m_machine.render().is_live(*screen))
{
- mame_file *fp;
- file_error filerr = mame_fopen_next(SEARCHPATH_SCREENSHOT, "png", fp);
+ emu_file file(m_machine.options(), SEARCHPATH_SCREENSHOT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = open_next(file, "png");
if (filerr == FILERR_NONE)
- {
- save_snapshot(screen, *fp);
- mame_fclose(fp);
- }
+ save_snapshot(screen, file);
}
}
// otherwise, just write a single snapshot
else
{
- mame_file *fp;
- file_error filerr = mame_fopen_next(SEARCHPATH_SCREENSHOT, "png", fp);
+ emu_file file(m_machine.options(), SEARCHPATH_SCREENSHOT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = open_next(file, "png");
if (filerr == FILERR_NONE)
- {
- save_snapshot(NULL, *fp);
- mame_fclose(fp);
- }
+ save_snapshot(NULL, file);
}
}
@@ -427,24 +421,27 @@ void video_manager::begin_recording(const char *name, movie_format format)
info.audio_samplerate = m_machine.sample_rate;
// create a new temporary movie file
- mame_file *tempfile;
file_error filerr;
- if (name != NULL)
- filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &tempfile);
- else
- filerr = mame_fopen_next(SEARCHPATH_MOVIE, "avi", tempfile);
+ astring fullpath;
+ {
+ emu_file tempfile(m_machine.options(), SEARCHPATH_MOVIE, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ if (name != NULL)
+ filerr = tempfile.open(name);
+ else
+ filerr = open_next(tempfile, "avi");
+
+ // compute the frame time
+ m_movie_frame_period = attotime::from_seconds(1000) / info.video_timescale;
- // compute the frame time
- m_movie_frame_period = attotime::from_seconds(1000) / info.video_timescale;
+ // if we succeeded, make a copy of the name and create the real file over top
+ if (filerr == FILERR_NONE)
+ fullpath = tempfile.fullpath();
+ }
- // if we succeeded, make a copy of the name and create the real file over top
if (filerr == FILERR_NONE)
{
- astring fullname(mame_file_full_name(tempfile));
- mame_fclose(tempfile);
-
// create the file and free the string
- avi_error avierr = avi_create(fullname, &info, &m_avifile);
+ avi_error avierr = avi_create(fullpath, &info, &m_avifile);
if (avierr != AVIERR_NONE)
mame_printf_error("Error creating AVI: %s\n", avi_error_string(avierr));
}
@@ -454,20 +451,30 @@ void video_manager::begin_recording(const char *name, movie_format format)
else if (format == MF_MNG)
{
// create a new movie file and start recording
+ m_mngfile = auto_alloc(&m_machine, emu_file(m_machine.options(), SEARCHPATH_MOVIE, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS));
file_error filerr;
if (name != NULL)
- filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &m_mngfile);
+ filerr = m_mngfile->open(name);
else
- filerr = mame_fopen_next(SEARCHPATH_MOVIE, "mng", m_mngfile);
-
- // start the capture
- int rate = (m_machine.primary_screen != NULL) ? ATTOSECONDS_TO_HZ(m_machine.primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE;
- png_error pngerr = mng_capture_start(mame_core_file(m_mngfile), m_snap_bitmap, rate);
- if (pngerr != PNGERR_NONE)
- return end_recording();
+ filerr = open_next(*m_mngfile, "mng");
+
+ if (filerr == FILERR_NONE)
+ {
+ // start the capture
+ int rate = (m_machine.primary_screen != NULL) ? ATTOSECONDS_TO_HZ(m_machine.primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE;
+ png_error pngerr = mng_capture_start(*m_mngfile, m_snap_bitmap, rate);
+ if (pngerr != PNGERR_NONE)
+ return end_recording();
- // compute the frame time
- m_movie_frame_period = attotime::from_hz(rate);
+ // compute the frame time
+ m_movie_frame_period = attotime::from_hz(rate);
+ }
+ else
+ {
+ mame_printf_error("Error creating MNG\n");
+ global_free(m_mngfile);
+ m_mngfile = NULL;
+ }
}
}
@@ -488,8 +495,8 @@ void video_manager::end_recording()
// close the file if it exists
if (m_mngfile != NULL)
{
- mng_capture_stop(mame_core_file(m_mngfile));
- mame_fclose(m_mngfile);
+ mng_capture_stop(*m_mngfile);
+ auto_free(&m_machine, m_mngfile);
m_mngfile = NULL;
}
@@ -642,7 +649,7 @@ inline bool video_manager::effective_throttle() const
inline int video_manager::original_speed_setting() const
{
- return options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5;
+ return options_get_float(&m_machine.options(), OPTION_SPEED) * 100.0 + 0.5;
}
@@ -842,7 +849,7 @@ osd_ticks_t video_manager::throttle_until_ticks(osd_ticks_t target_ticks)
// we're allowed to sleep via the OSD code only if we're configured to do so
// and we're not frameskipping due to autoframeskip, or if we're paused
bool allowed_to_sleep = false;
- if (options_get_bool(m_machine.options(), OPTION_SLEEP) && (!effective_autoframeskip() || effective_frameskip() == 0))
+ if (options_get_bool(&m_machine.options(), OPTION_SLEEP) && (!effective_autoframeskip() || effective_frameskip() == 0))
allowed_to_sleep = true;
if (m_machine.paused())
allowed_to_sleep = true;
@@ -948,7 +955,7 @@ void video_manager::update_frameskip()
void video_manager::update_refresh_speed()
{
// only do this if the refreshspeed option is used
- if (options_get_bool(m_machine.options(), OPTION_REFRESHSPEED))
+ if (options_get_bool(&m_machine.options(), OPTION_REFRESHSPEED))
{
float minrefresh = m_machine.render().max_update_rate();
if (minrefresh != 0)
@@ -1034,16 +1041,11 @@ void video_manager::recompute_speed(attotime emutime)
{
if (m_machine.primary_screen != NULL)
{
- astring fname(m_machine.basename(), PATH_SEPARATOR "final.png");
-
// create a final screenshot
- mame_file *file;
- file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ emu_file file(m_machine.options(), SEARCHPATH_SCREENSHOT, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
+ file_error filerr = file.open(m_machine.basename(), PATH_SEPARATOR "final.png");
if (filerr == FILERR_NONE)
- {
- save_snapshot(m_machine.primary_screen, *file);
- mame_fclose(file);
- }
+ save_snapshot(m_machine.primary_screen, file);
}
// schedule our demise
@@ -1092,15 +1094,17 @@ void video_manager::create_snapshot_bitmap(device_t *screen)
//-------------------------------------------------
-// mame_fopen_next - open the next non-existing
-// file of type filetype according to our
-// numbering scheme
+// open_next - open the next non-existing file of
+// type filetype according to our numbering
+// scheme
//-------------------------------------------------
-file_error video_manager::mame_fopen_next(const char *pathoption, const char *extension, mame_file *&file)
+file_error video_manager::open_next(emu_file &file, const char *extension)
{
+ UINT32 origflags = file.openflags();
+
// handle defaults
- const char *snapname = options_get_string(m_machine.options(), OPTION_SNAPNAME);
+ const char *snapname = options_get_string(&m_machine.options(), OPTION_SNAPNAME);
if (snapname == NULL || snapname[0] == 0)
snapname = "%g/%i";
@@ -1204,15 +1208,16 @@ file_error video_manager::mame_fopen_next(const char *pathoption, const char *ex
fname.cpy(snapstr).replace(0, "%i", seqtext.format("%04d", seq).cstr());
// try to open the file; stop when we fail
- file_error filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, &file);
+ file.set_openflags(OPEN_FLAG_READ);
+ file_error filerr = file.open(fname);
if (filerr != FILERR_NONE)
break;
- mame_fclose(file);
}
}
// create the final file
- return mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
+ file.set_openflags(origflags);
+ return file.open(fname);
}
@@ -1264,7 +1269,7 @@ void video_manager::record_frame()
// write the next frame
const rgb_t *palette = (m_machine.palette != NULL) ? palette_entry_list_adjusted(m_machine.palette) : NULL;
- png_error error = mng_capture_frame(mame_core_file(m_mngfile), &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette);
+ png_error error = mng_capture_frame(*m_mngfile, &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette);
png_free(&pnginfo);
if (error != PNGERR_NONE)
{
diff --git a/src/emu/video.h b/src/emu/video.h
index 677f34157eb..e83e06d96f3 100644
--- a/src/emu/video.h
+++ b/src/emu/video.h
@@ -107,7 +107,7 @@ public:
double speed_percent() const { return m_speed_percent; }
// snapshots
- void save_snapshot(screen_device *screen, mame_file &file);
+ void save_snapshot(screen_device *screen, emu_file &file);
void save_active_screen_snapshots();
// movies
@@ -138,7 +138,7 @@ private:
// snapshot/movie helpers
void create_snapshot_bitmap(device_t *screen);
- file_error mame_fopen_next(const char *pathoption, const char *extension, mame_file *&file);
+ file_error open_next(emu_file &file, const char *extension);
void record_frame();
// internal state
@@ -187,7 +187,7 @@ private:
INT32 m_snap_height; // height of snapshots (0 == auto)
// movie recording
- mame_file * m_mngfile; // handle to the open movie file
+ emu_file * m_mngfile; // handle to the open movie file
avi_file * m_avifile; // handle to the open movie file
attotime m_movie_frame_period; // period of a single movie frame
attotime m_movie_next_frame_time; // time of next frame
diff --git a/src/emu/video/vector.c b/src/emu/video/vector.c
index c3d8bdda79a..3f49048344a 100644
--- a/src/emu/video/vector.c
+++ b/src/emu/video/vector.c
@@ -175,10 +175,10 @@ float vector_get_beam(void)
VIDEO_START( vector )
{
- beam_width = options_get_float(machine->options(), OPTION_BEAM);
+ beam_width = options_get_float(&machine->options(), OPTION_BEAM);
/* Grab the settings for this session */
- vector_set_flicker(options_get_float(machine->options(), OPTION_FLICKER));
+ vector_set_flicker(options_get_float(&machine->options(), OPTION_FLICKER));
vector_index = 0;
@@ -256,7 +256,7 @@ void vector_clear_list (void)
VIDEO_UPDATE( vector )
{
- UINT32 flags = PRIMFLAG_ANTIALIAS(options_get_bool(screen->machine->options(), OPTION_ANTIALIAS) ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD);
+ UINT32 flags = PRIMFLAG_ANTIALIAS(options_get_bool(&screen->machine->options(), OPTION_ANTIALIAS) ? 1 : 0) | PRIMFLAG_BLENDMODE(BLENDMODE_ADD);
const rectangle &visarea = screen->visible_area();
float xscale = 1.0f / (65536 * (visarea.max_x - visarea.min_x));
float yscale = 1.0f / (65536 * (visarea.max_y - visarea.min_y));