diff --git a/src/emu/machine/generic.c b/src/emu/machine/generic.c index b2d2f6ee15e..9db55bdbd38 100644 --- a/src/emu/machine/generic.c +++ b/src/emu/machine/generic.c @@ -326,41 +326,60 @@ static astring nvram_filename(running_machine &machine, astring &result) return result; } +/*------------------------------------------------- + nvram_filename - returns filename of system's + NVRAM depending of selected BIOS +-------------------------------------------------*/ + +static astring nvram_filename(device_t &device, astring &result) +{ + running_machine &machine = device.machine(); + if (rom_system_bios(machine) == 0 || rom_default_bios(machine) == rom_system_bios(machine)) { + result.printf("%s\\%s",machine.basename(),device.tag()); + } else { + result.printf("%s_%d\\%s",machine.basename(),rom_system_bios(machine) - 1,device.tag()); + } + return result; +} + /*------------------------------------------------- nvram_load - load a system's NVRAM -------------------------------------------------*/ void nvram_load(running_machine &machine) { - // only need to do something if we have an NVRAM device or an nvram_handler - device_nvram_interface *nvram = NULL; - if (!machine.devicelist().first(nvram) && machine.config().m_nvram_handler == NULL) - return; - - // open the file; if it exists, call everyone to read from it - astring filename; - emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); - if (file.open(nvram_filename(machine,filename), ".nv") == FILERR_NONE) + if (machine.config().m_nvram_handler != NULL) { - // read data from general NVRAM handler first - if (machine.config().m_nvram_handler != NULL) + astring filename; + emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); + if (file.open(nvram_filename(machine,filename),".nv") == FILERR_NONE) + { (*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(file); + file.close(); + } + else + { + (*machine.config().m_nvram_handler)(machine, NULL, FALSE); + } } - // otherwise, tell everyone to initialize their NVRAM areas - else + device_nvram_interface *nvram = NULL; + if (machine.devicelist().first(nvram)) { - // initialize via the general NVRAM handler first - if (machine.config().m_nvram_handler != NULL) - (*machine.config().m_nvram_handler)(machine, NULL, FALSE); - - // find all devices with NVRAM handlers, and read from them next for (bool gotone = (nvram != NULL); gotone; gotone = nvram->next(nvram)) - nvram->nvram_reset(); + { + astring filename; + emu_file file(machine.options().nvram_directory(), OPEN_FLAG_READ); + if (file.open(nvram_filename(nvram->device(),filename)) == FILERR_NONE) + { + nvram->nvram_load(file); + file.close(); + } + else + { + nvram->nvram_reset(); + } + } } } @@ -371,23 +390,30 @@ void nvram_load(running_machine &machine) void nvram_save(running_machine &machine) { - // only need to do something if we have an NVRAM device or an nvram_handler - device_nvram_interface *nvram = NULL; - if (!machine.devicelist().first(nvram) && machine.config().m_nvram_handler == NULL) - return; - - // open the file; if it exists, call everyone to read from it - astring filename; - emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(nvram_filename(machine,filename), ".nv") == FILERR_NONE) + if (machine.config().m_nvram_handler != NULL) { - // write data via general NVRAM handler first - 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(machine,filename), ".nv") == FILERR_NONE) + { (*machine.config().m_nvram_handler)(machine, &file, TRUE); + file.close(); + } + } - // find all devices with NVRAM handlers, and tell them to write next + device_nvram_interface *nvram = NULL; + if (machine.devicelist().first(nvram)) + { for (bool gotone = (nvram != NULL); gotone; gotone = nvram->next(nvram)) - nvram->nvram_save(file); + { + astring filename; + emu_file file(machine.options().nvram_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + if (file.open(nvram_filename(nvram->device(),filename)) == FILERR_NONE) + { + nvram->nvram_save(file); + file.close(); + } + } } }