summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/nvram.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/nvram.cpp')
-rw-r--r--src/devices/machine/nvram.cpp53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/devices/machine/nvram.cpp b/src/devices/machine/nvram.cpp
index b2949c1e837..3a6f24c593c 100644
--- a/src/devices/machine/nvram.cpp
+++ b/src/devices/machine/nvram.cpp
@@ -2,14 +2,14 @@
// copyright-holders:Aaron Giles
/***************************************************************************
- nvram.c
+ nvram.cpp
Generic non-volatile RAM.
***************************************************************************/
#include "emu.h"
-#include "machine/nvram.h"
+#include "nvram.h"
//**************************************************************************
// LIVE DEVICE
@@ -22,13 +22,14 @@ DEFINE_DEVICE_TYPE(NVRAM, nvram_device, "nvram", "NVRAM")
// nvram_device - constructor
//-------------------------------------------------
-nvram_device::nvram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
- : device_t(mconfig, NVRAM, tag, owner, clock),
- device_nvram_interface(mconfig, *this),
- m_region(*this, DEVICE_SELF),
- m_default_value(DEFAULT_ALL_1),
- m_base(nullptr),
- m_length(0)
+nvram_device::nvram_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
+ device_t(mconfig, NVRAM, tag, owner, clock),
+ device_nvram_interface(mconfig, *this),
+ m_region(*this, DEVICE_SELF),
+ m_default_value(DEFAULT_ALL_1),
+ m_custom_handler(*this),
+ m_base(nullptr),
+ m_length(0)
{
}
@@ -40,7 +41,7 @@ nvram_device::nvram_device(const machine_config &mconfig, const char *tag, devic
void nvram_device::device_start()
{
// bind our handler
- m_custom_handler.bind_relative_to(*owner());
+ m_custom_handler.resolve();
}
@@ -77,12 +78,12 @@ void nvram_device::nvram_default()
// random values
case DEFAULT_RANDOM:
- {
- uint8_t *nvram = reinterpret_cast<uint8_t *>(m_base);
- for (int index = 0; index < m_length; index++)
- nvram[index] = machine().rand();
+ {
+ uint8_t *nvram = reinterpret_cast<uint8_t *>(m_base);
+ for (int index = 0; index < m_length; index++)
+ nvram[index] = machine().rand();
+ }
break;
- }
// custom handler
case DEFAULT_CUSTOM:
@@ -101,12 +102,14 @@ void nvram_device::nvram_default()
// .nv file
//-------------------------------------------------
-void nvram_device::nvram_read(emu_file &file)
+bool nvram_device::nvram_read(util::read_stream &file)
{
// make sure we have a valid base pointer
determine_final_base();
- file.read(m_base, m_length);
+ // FIXME: consider width/Endianness
+ auto const [err, actual] = read(file, m_base, m_length);
+ return !err && (actual == m_length);
}
@@ -115,9 +118,11 @@ void nvram_device::nvram_read(emu_file &file)
// .nv file
//-------------------------------------------------
-void nvram_device::nvram_write(emu_file &file)
+bool nvram_device::nvram_write(util::write_stream &file)
{
- file.write(m_base, m_length);
+ // FIXME: consider width/Endianness
+ auto const [err, actual] = write(file, m_base, m_length);
+ return !err;
}
@@ -130,16 +135,16 @@ void nvram_device::nvram_write(emu_file &file)
void nvram_device::determine_final_base()
{
// find our shared pointer with the target RAM
- if (m_base == nullptr)
+ if (!m_base)
{
- memory_share *share = owner()->memshare(tag());
- if (share == nullptr)
- throw emu_fatalerror("NVRAM device '%s' has no corresponding AM_SHARE region", tag());
+ memory_share *const share = owner()->memshare(tag());
+ if (!share)
+ throw emu_fatalerror("NVRAM device '%s' has no corresponding share() region", tag());
m_base = share->ptr();
m_length = share->bytes();
}
// if we are region-backed for the default, find it now and make sure it's the right size
if (m_region.found() && m_region->bytes() != m_length)
- throw emu_fatalerror("%s",string_format("NVRAM device '%s' has a default region, but it should be 0x%X bytes", tag(), m_length).c_str());
+ throw emu_fatalerror("%s",string_format("NVRAM device '%s' has a default region, but it should be 0x%X bytes", tag(), m_length));
}