summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2018-06-15 13:41:44 -0400
committer AJR <ajrhacker@users.noreply.github.com>2018-06-15 13:41:44 -0400
commit9adf39ca97cc006f67023667c42f449edf29df5f (patch)
tree06f89e610b985fdaaddb91ff89f9fbd158aee4e6 /src/devices/machine
parent0ebf0f0103585ca68b1e61b759fc980f43bf7c00 (diff)
x2212: Remove memory interface and clean up code
Diffstat (limited to 'src/devices/machine')
-rw-r--r--src/devices/machine/x2212.cpp82
-rw-r--r--src/devices/machine/x2212.h34
2 files changed, 29 insertions, 87 deletions
diff --git a/src/devices/machine/x2212.cpp b/src/devices/machine/x2212.cpp
index 155208352bc..ab3adce12a6 100644
--- a/src/devices/machine/x2212.cpp
+++ b/src/devices/machine/x2212.cpp
@@ -10,22 +10,7 @@
#include "emu.h"
#include "machine/x2212.h"
-
-
-//**************************************************************************
-// GLOBAL VARIABLES
-//**************************************************************************
-
-void x2212_device::x2212_sram_map(address_map &map)
-{
- map(0x0000, 0x00ff).ram();
-}
-
-void x2212_device::x2212_e2prom_map(address_map &map)
-{
- map(0x0000, 0x00ff).ram();
-}
-
+#include <algorithm>
//**************************************************************************
@@ -40,18 +25,15 @@ DEFINE_DEVICE_TYPE(X2210, x2210_device, "x2210", "Xicor X2210 64x4 NOVRAM")
// x2212_device - constructor
//-------------------------------------------------
-x2212_device::x2212_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+x2212_device::x2212_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: x2212_device(mconfig, X2212, tag, owner, clock, 0x100)
{
}
-x2212_device::x2212_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int size_data)
+x2212_device::x2212_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int size_data)
: device_t(mconfig, type, tag, owner, clock)
- , device_memory_interface(mconfig, *this)
, device_nvram_interface(mconfig, *this)
, m_auto_save(false)
- , m_sram_space_config("SRAM", ENDIANNESS_BIG, 8, 8, 0, address_map_constructor(FUNC(x2212_device::x2212_sram_map), this))
- , m_e2prom_space_config("E2PROM", ENDIANNESS_BIG, 8, 8, 0, address_map_constructor(FUNC(x2212_device::x2212_e2prom_map), this))
, m_store(false)
, m_array_recall(false)
, m_size_data(size_data)
@@ -65,24 +47,14 @@ x2212_device::x2212_device(const machine_config &mconfig, device_type type, cons
void x2212_device::device_start()
{
+ m_sram = std::make_unique<u8[]>(m_size_data);
+ m_e2prom = std::make_unique<u8[]>(m_size_data);
+ std::fill_n(&m_sram[0], m_size_data, 0xff);
+
save_item(NAME(m_store));
save_item(NAME(m_array_recall));
- m_sram = &space(0);
- m_e2prom = &space(1);
-}
-
-
-//-------------------------------------------------
-// memory_space_config - return a description of
-// any address spaces owned by this device
-//-------------------------------------------------
-
-device_memory_interface::space_config_vector x2212_device::memory_space_config() const
-{
- return space_config_vector {
- std::make_pair(0, &m_sram_space_config),
- std::make_pair(1, &m_e2prom_space_config)
- };
+ save_pointer(NAME(m_sram.get()), m_size_data);
+ save_pointer(NAME(m_e2prom.get()), m_size_data);
}
@@ -94,18 +66,11 @@ device_memory_interface::space_config_vector x2212_device::memory_space_config()
void x2212_device::nvram_default()
{
// default to all-0xff
- for (int byte = 0; byte < m_size_data; byte++)
- {
- m_sram->write_byte(byte, 0xff);
- m_e2prom->write_byte(byte, 0xff);
- }
+ std::fill_n(&m_e2prom[0], m_size_data, 0xff);
// populate from a memory region if present
if (m_default_data.found())
- {
- for (int byte = 0; byte < m_size_data; byte++)
- m_e2prom->write_byte(byte, m_default_data[byte]);
- }
+ std::copy_n(&m_default_data[0], m_size_data, &m_e2prom[0]);
}
@@ -116,13 +81,7 @@ void x2212_device::nvram_default()
void x2212_device::nvram_read(emu_file &file)
{
- auto buffer = std::make_unique<uint8_t[]>(m_size_data);
- file.read(buffer.get(), m_size_data);
- for (int byte = 0; byte < m_size_data; byte++)
- {
- m_sram->write_byte(byte, 0xff);
- m_e2prom->write_byte(byte, buffer[byte]);
- }
+ file.read(&m_e2prom[0], m_size_data);
}
@@ -137,10 +96,7 @@ void x2212_device::nvram_write(emu_file &file)
if (m_auto_save)
do_store();
- uint8_t *buffer = (uint8_t *) alloca(m_size_data);
- for (int byte = 0; byte < m_size_data; byte++)
- buffer[byte] = m_e2prom->read_byte(byte);
- file.write(buffer, m_size_data);
+ file.write(&m_e2prom[0], m_size_data);
}
@@ -156,8 +112,7 @@ void x2212_device::nvram_write(emu_file &file)
void x2212_device::do_store()
{
- for (int byte = 0; byte < m_size_data; byte++)
- m_e2prom->write_byte(byte, m_sram->read_byte(byte));
+ std::copy_n(&m_sram[0], m_size_data, &m_e2prom[0]);
}
@@ -168,8 +123,7 @@ void x2212_device::do_store()
void x2212_device::do_recall()
{
- for (int byte = 0; byte < m_size_data; byte++)
- m_sram->write_byte(byte, m_e2prom->read_byte(byte));
+ std::copy_n(&m_e2prom[0], m_size_data, &m_sram[0]);
}
@@ -184,7 +138,7 @@ void x2212_device::do_recall()
WRITE8_MEMBER( x2212_device::write )
{
- m_sram->write_byte(offset, data & 0x0f);
+ m_sram[offset] = data & 0x0f;
}
@@ -194,7 +148,7 @@ WRITE8_MEMBER( x2212_device::write )
READ8_MEMBER( x2212_device::read )
{
- return (m_sram->read_byte(offset) & 0x0f) | (space.unmap() & 0xf0);
+ return (m_sram[offset] & 0x0f) | (space.unmap() & 0xf0);
}
@@ -224,7 +178,7 @@ WRITE_LINE_MEMBER( x2212_device::recall )
}
-x2210_device::x2210_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+x2210_device::x2210_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: x2212_device(mconfig, X2210, tag, owner, clock, 0x40)
{
}
diff --git a/src/devices/machine/x2212.h b/src/devices/machine/x2212.h
index 988d87a1a60..df0797e9549 100644
--- a/src/devices/machine/x2212.h
+++ b/src/devices/machine/x2212.h
@@ -20,18 +20,18 @@
//**************************************************************************
#define MCFG_X2212_ADD(_tag) \
- MCFG_DEVICE_ADD(_tag, X2212, 0)
+ MCFG_DEVICE_ADD(_tag, X2212)
// some systems (like many early Atari games) wire up the /STORE signal
// to fire on power-down, effectively creating an "auto-save" functionality
#define MCFG_X2212_ADD_AUTOSAVE(_tag) \
- MCFG_DEVICE_ADD(_tag, X2212, 0) \
+ MCFG_DEVICE_ADD(_tag, X2212) \
downcast<x2212_device &>(*device).set_auto_save(true);
#define MCFG_X2210_ADD(_tag) \
- MCFG_DEVICE_ADD(_tag, X2210, 0)
+ MCFG_DEVICE_ADD(_tag, X2210)
#define MCFG_X2210_ADD_AUTOSAVE(_tag) \
- MCFG_DEVICE_ADD(_tag, X2210, 0) \
+ MCFG_DEVICE_ADD(_tag, X2210) \
downcast<x2212_device &>(*device).set_auto_save(true);
@@ -42,13 +42,11 @@
// ======================> x2212_device
-class x2212_device : public device_t,
- public device_memory_interface,
- public device_nvram_interface
+class x2212_device : public device_t, public device_nvram_interface
{
public:
// construction/destruction
- x2212_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+ x2212_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
// inline configuration helpers
void set_auto_save(bool auto_save) { m_auto_save = auto_save; }
@@ -61,14 +59,11 @@ public:
DECLARE_WRITE_LINE_MEMBER( recall );
protected:
- x2212_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int size_data);
+ x2212_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int size_data);
// device-level overrides
virtual void device_start() override;
- // device_memory_interface overrides
- virtual space_config_vector memory_space_config() const override;
-
// device_nvram_interface overrides
virtual void nvram_default() override;
virtual void nvram_read(emu_file &file) override;
@@ -78,32 +73,25 @@ private:
// configuration state
bool m_auto_save;
- // device-specific configuration
- address_space_config m_sram_space_config;
- address_space_config m_e2prom_space_config;
-
// internal state
- address_space * m_sram;
- address_space * m_e2prom;
+ std::unique_ptr<u8[]> m_sram;
+ std::unique_ptr<u8[]> m_e2prom;
bool m_store;
bool m_array_recall;
int const m_size_data;
- optional_region_ptr<uint8_t> m_default_data;
+ optional_region_ptr<u8> m_default_data;
// internal helpers
void do_store();
void do_recall();
-
- void x2212_e2prom_map(address_map &map);
- void x2212_sram_map(address_map &map);
};
class x2210_device : public x2212_device
{
public:
- x2210_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+ x2210_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock = 0);
};