mirror of
https://github.com/holub/mame
synced 2025-04-21 07:52:35 +03:00
Let running_machine handle nvram save/load (nw)
This commit is contained in:
parent
8d5dea174a
commit
c5495da07e
@ -398,7 +398,7 @@ int running_machine::run(bool firstrun)
|
||||
|
||||
// load the configuration settings and NVRAM
|
||||
bool settingsloaded = config_load_settings(*this);
|
||||
nvram_load(*this);
|
||||
nvram_load();
|
||||
sound().ui_mute(false);
|
||||
|
||||
// initialize ui lists
|
||||
@ -441,7 +441,7 @@ int running_machine::run(bool firstrun)
|
||||
|
||||
// save the NVRAM and configuration
|
||||
sound().ui_mute(true);
|
||||
nvram_save(*this);
|
||||
nvram_save();
|
||||
config_save_settings(*this);
|
||||
}
|
||||
catch (emu_fatalerror &fatal)
|
||||
@ -1220,6 +1220,119 @@ void running_machine::postload_all_devices()
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
NVRAM MANAGEMENT
|
||||
***************************************************************************/
|
||||
|
||||
const char *running_machine::image_parent_basename(device_t *device)
|
||||
{
|
||||
device_t *dev = device;
|
||||
while(dev != &root_device())
|
||||
{
|
||||
device_image_interface *intf = NULL;
|
||||
if (dev!=NULL && dev->interface(intf))
|
||||
{
|
||||
return intf->basename_noext();
|
||||
}
|
||||
dev = dev->owner();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
nvram_filename - returns filename of system's
|
||||
NVRAM depending of selected BIOS
|
||||
-------------------------------------------------*/
|
||||
|
||||
astring &running_machine::nvram_filename(astring &result, device_t &device)
|
||||
{
|
||||
// start with either basename or basename_biosnum
|
||||
result.cpy(basename());
|
||||
if (root_device().system_bios() != 0 && root_device().default_bios() != root_device().system_bios())
|
||||
result.catprintf("_%d", root_device().system_bios() - 1);
|
||||
|
||||
// device-based NVRAM gets its own name in a subdirectory
|
||||
if (&device != &root_device())
|
||||
{
|
||||
// add per software nvrams into one folder
|
||||
const char *software = image_parent_basename(&device);
|
||||
if (software!=NULL && strlen(software)>0)
|
||||
{
|
||||
result.cat('\\').cat(software);
|
||||
}
|
||||
astring tag(device.tag());
|
||||
tag.del(0, 1).replacechr(':', '_');
|
||||
result.cat('\\').cat(tag);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
nvram_load - load a system's NVRAM
|
||||
-------------------------------------------------*/
|
||||
|
||||
void running_machine::nvram_load()
|
||||
{
|
||||
if (config().m_nvram_handler != NULL)
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(options().nvram_directory(), OPEN_FLAG_READ);
|
||||
if (file.open(nvram_filename(filename, root_device()), ".nv") == FILERR_NONE)
|
||||
{
|
||||
(*config().m_nvram_handler)(*this, &file, FALSE);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
(*config().m_nvram_handler)(*this, NULL, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
nvram_interface_iterator iter(root_device());
|
||||
for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next())
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(options().nvram_directory(), OPEN_FLAG_READ);
|
||||
if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE)
|
||||
{
|
||||
nvram->nvram_load(file);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
nvram->nvram_reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
nvram_save - save a system's NVRAM
|
||||
-------------------------------------------------*/
|
||||
|
||||
void running_machine::nvram_save()
|
||||
{
|
||||
if (config().m_nvram_handler != NULL)
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
|
||||
if (file.open(nvram_filename(filename, root_device()), ".nv") == FILERR_NONE)
|
||||
{
|
||||
(*config().m_nvram_handler)(*this, &file, TRUE);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
nvram_interface_iterator iter(root_device());
|
||||
for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next())
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
|
||||
if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE)
|
||||
{
|
||||
nvram->nvram_save(file);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//**************************************************************************
|
||||
// CALLBACK ITEMS
|
||||
|
@ -297,6 +297,10 @@ private:
|
||||
void soft_reset(void *ptr = NULL, INT32 param = 0);
|
||||
void watchdog_fired(void *ptr = NULL, INT32 param = 0);
|
||||
void watchdog_vblank(screen_device &screen, bool vblank_state);
|
||||
const char *image_parent_basename(device_t *device);
|
||||
astring &nvram_filename(astring &result, device_t &device);
|
||||
void nvram_load();
|
||||
void nvram_save();
|
||||
|
||||
// internal callbacks
|
||||
static void logfile_callback(running_machine &machine, const char *buffer);
|
||||
|
@ -271,125 +271,6 @@ void coin_lockout_global_w(running_machine &machine, int on)
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
NVRAM MANAGEMENT
|
||||
***************************************************************************/
|
||||
|
||||
static const char *image_parent_basename(device_t *device)
|
||||
{
|
||||
running_machine &machine = device->machine();
|
||||
device_t *dev = device;
|
||||
while(dev != &machine.root_device())
|
||||
{
|
||||
device_image_interface *intf = NULL;
|
||||
if (dev!=NULL && dev->interface(intf))
|
||||
{
|
||||
return intf->basename_noext();
|
||||
}
|
||||
dev = dev->owner();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
nvram_filename - returns filename of system's
|
||||
NVRAM depending of selected BIOS
|
||||
-------------------------------------------------*/
|
||||
|
||||
static astring &nvram_filename(astring &result, device_t &device)
|
||||
{
|
||||
running_machine &machine = device.machine();
|
||||
|
||||
// start with either basename or basename_biosnum
|
||||
result.cpy(machine.basename());
|
||||
if (device.machine().root_device().system_bios() != 0 && device.machine().root_device().default_bios() != device.machine().root_device().system_bios())
|
||||
result.catprintf("_%d", device.machine().root_device().system_bios() - 1);
|
||||
|
||||
// device-based NVRAM gets its own name in a subdirectory
|
||||
if (&device != &device.machine().root_device())
|
||||
{
|
||||
// add per software nvrams into one folder
|
||||
const char *software = image_parent_basename(&device);
|
||||
if (software!=NULL && strlen(software)>0)
|
||||
{
|
||||
result.cat('\\').cat(software);
|
||||
}
|
||||
astring tag(device.tag());
|
||||
tag.del(0, 1).replacechr(':', '_');
|
||||
result.cat('\\').cat(tag);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
nvram_load - load a system's NVRAM
|
||||
-------------------------------------------------*/
|
||||
|
||||
void nvram_load(running_machine &machine)
|
||||
{
|
||||
if (machine.config().m_nvram_handler != NULL)
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ);
|
||||
if (file.open(nvram_filename(filename, machine.root_device()), ".nv") == FILERR_NONE)
|
||||
{
|
||||
(*machine.config().m_nvram_handler)(machine, &file, FALSE);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
(*machine.config().m_nvram_handler)(machine, NULL, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
nvram_interface_iterator iter(machine.root_device());
|
||||
for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next())
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ);
|
||||
if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE)
|
||||
{
|
||||
nvram->nvram_load(file);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
nvram->nvram_reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------
|
||||
nvram_save - save a system's NVRAM
|
||||
-------------------------------------------------*/
|
||||
|
||||
void nvram_save(running_machine &machine)
|
||||
{
|
||||
if (machine.config().m_nvram_handler != NULL)
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
|
||||
if (file.open(nvram_filename(filename, machine.root_device()), ".nv") == FILERR_NONE)
|
||||
{
|
||||
(*machine.config().m_nvram_handler)(machine, &file, TRUE);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
nvram_interface_iterator iter(machine.root_device());
|
||||
for (device_nvram_interface *nvram = iter.first(); nvram != NULL; nvram = iter.next())
|
||||
{
|
||||
astring filename;
|
||||
emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
|
||||
if (file.open(nvram_filename(filename, nvram->device())) == FILERR_NONE)
|
||||
{
|
||||
nvram->nvram_save(file);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
MEMORY CARD MANAGEMENT
|
||||
***************************************************************************/
|
||||
|
@ -70,17 +70,6 @@ int coin_lockout_get_state(running_machine &machine, int num);
|
||||
void coin_lockout_global_w(running_machine &machine, int on);
|
||||
|
||||
|
||||
|
||||
/* ----- NVRAM management ----- */
|
||||
|
||||
/* load NVRAM from a file */
|
||||
void nvram_load(running_machine &machine);
|
||||
|
||||
/* save NVRAM to a file */
|
||||
void nvram_save(running_machine &machine);
|
||||
|
||||
|
||||
|
||||
/* ----- memory card management ----- */
|
||||
|
||||
/* create a new memory card with the given index */
|
||||
|
Loading…
Reference in New Issue
Block a user