mirror of
https://github.com/holub/mame
synced 2025-07-05 01:48:29 +03:00
image.c: Added support for loading a default battery, instead of a fixed fill value, when no
battery is found. This allows for loading factory formatted sram/nvram from softlist. [Fabio Priuli] (MESS) nes.c: Fixed Silva Saga, which relies on SRAM not being 0x00 filled from factory, with many thanks to naruko for investigating the problem. [Fabio Priuli]
This commit is contained in:
parent
018102f077
commit
593b53d73b
690
hash/nes.xml
690
hash/nes.xml
File diff suppressed because it is too large
Load Diff
@ -579,7 +579,20 @@ void nes_cart_slot_device::call_load_pcb()
|
||||
{
|
||||
UINT32 tot_size = battery_size + mapper_sram_size;
|
||||
dynamic_buffer temp_nvram(tot_size);
|
||||
battery_load(temp_nvram, tot_size, 0x00);
|
||||
|
||||
// some games relies on specific battery patterns to work
|
||||
// (e.g. Silva Saga does not work with SRAM fully initialized to 0x00)
|
||||
// and we use the info from xml here to prepare a default NVRAM
|
||||
dynamic_buffer default_nvram(tot_size);
|
||||
if (battery_size)
|
||||
memcpy(default_nvram, get_software_region("bwram"), battery_size);
|
||||
if (mapper_sram_size)
|
||||
memset(default_nvram + battery_size, 0, mapper_sram_size);
|
||||
|
||||
// load battery (using default if no battery exists)
|
||||
battery_load(temp_nvram, tot_size, default_nvram);
|
||||
|
||||
// copy battery into PCB arrays
|
||||
if (battery_size)
|
||||
{
|
||||
m_cart->battery_alloc(battery_size);
|
||||
|
@ -500,10 +500,15 @@ UINT32 device_image_interface::crc()
|
||||
void device_image_interface::battery_load(void *buffer, int length, int fill)
|
||||
{
|
||||
astring fname(device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
|
||||
|
||||
image_battery_load_by_name(device().machine().options(), fname, buffer, length, fill);
|
||||
}
|
||||
|
||||
void device_image_interface::battery_load(void *buffer, int length, void *def_buffer)
|
||||
{
|
||||
astring fname(device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
|
||||
image_battery_load_by_name(device().machine().options(), fname, buffer, length, def_buffer);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
battery_save - stores the battery
|
||||
backed RAM for an image. The file name is
|
||||
|
@ -219,6 +219,7 @@ public:
|
||||
hash_collection& hash() { return m_hash; }
|
||||
|
||||
void battery_load(void *buffer, int length, int fill);
|
||||
void battery_load(void *buffer, int length, void *def_buffer);
|
||||
void battery_save(const void *buffer, int length);
|
||||
|
||||
const char *image_type_name() const { return device_typename(image_type()); }
|
||||
|
@ -310,6 +310,12 @@ void image_init(running_machine &machine)
|
||||
image_battery_load_by_name - retrieves the battery
|
||||
backed RAM for an image. A filename may be supplied
|
||||
to the function.
|
||||
|
||||
The function comes in two flavors, depending on
|
||||
what should happen when no battery is available:
|
||||
we could fill the memory with a given value, or
|
||||
pass a default battery (for a pre-initialized
|
||||
battery from factory)
|
||||
-------------------------------------------------*/
|
||||
|
||||
void image_battery_load_by_name(emu_options &options, const char *filename, void *buffer, int length, int fill)
|
||||
@ -329,6 +335,24 @@ void image_battery_load_by_name(emu_options &options, const char *filename, void
|
||||
memset(((char *) buffer) + bytes_read, fill, length - bytes_read);
|
||||
}
|
||||
|
||||
void image_battery_load_by_name(emu_options &options, const char *filename, void *buffer, int length, void *def_buffer)
|
||||
{
|
||||
file_error filerr;
|
||||
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 */
|
||||
emu_file file(options.nvram_directory(), OPEN_FLAG_READ);
|
||||
filerr = file.open(filename);
|
||||
if (filerr == FILERR_NONE)
|
||||
bytes_read = file.read(buffer, length);
|
||||
|
||||
/* if no file was present, copy the default battery */
|
||||
if (bytes_read == 0 && def_buffer)
|
||||
memcpy((char *) buffer, (char *) def_buffer, length);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
image_battery_save_by_name - stores the battery
|
||||
backed RAM for an image. A filename may be supplied
|
||||
|
@ -24,6 +24,7 @@ void image_postdevice_init(running_machine &machine);
|
||||
extern struct io_procs image_ioprocs;
|
||||
|
||||
void image_battery_load_by_name(emu_options &options, const char *filename, void *buffer, int length, int fill);
|
||||
void image_battery_load_by_name(emu_options &options, const char *filename, void *buffer, int length, void *def_buffer);
|
||||
void image_battery_save_by_name(emu_options &options, const char *filename, const void *buffer, int length);
|
||||
|
||||
#endif /* __IMAGE_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user