x2212: Remove memory interface and clean up code

This commit is contained in:
AJR 2018-06-15 13:41:44 -04:00
parent 0ebf0f0103
commit 9adf39ca97
2 changed files with 29 additions and 87 deletions

View File

@ -10,22 +10,7 @@
#include "emu.h" #include "emu.h"
#include "machine/x2212.h" #include "machine/x2212.h"
#include <algorithm>
//**************************************************************************
// 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();
}
//************************************************************************** //**************************************************************************
@ -40,18 +25,15 @@ DEFINE_DEVICE_TYPE(X2210, x2210_device, "x2210", "Xicor X2210 64x4 NOVRAM")
// x2212_device - constructor // 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(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_t(mconfig, type, tag, owner, clock)
, device_memory_interface(mconfig, *this)
, device_nvram_interface(mconfig, *this) , device_nvram_interface(mconfig, *this)
, m_auto_save(false) , 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_store(false)
, m_array_recall(false) , m_array_recall(false)
, m_size_data(size_data) , 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() 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_store));
save_item(NAME(m_array_recall)); save_item(NAME(m_array_recall));
m_sram = &space(0); save_pointer(NAME(m_sram.get()), m_size_data);
m_e2prom = &space(1); save_pointer(NAME(m_e2prom.get()), m_size_data);
}
//-------------------------------------------------
// 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)
};
} }
@ -94,18 +66,11 @@ device_memory_interface::space_config_vector x2212_device::memory_space_config()
void x2212_device::nvram_default() void x2212_device::nvram_default()
{ {
// default to all-0xff // default to all-0xff
for (int byte = 0; byte < m_size_data; byte++) std::fill_n(&m_e2prom[0], m_size_data, 0xff);
{
m_sram->write_byte(byte, 0xff);
m_e2prom->write_byte(byte, 0xff);
}
// populate from a memory region if present // populate from a memory region if present
if (m_default_data.found()) if (m_default_data.found())
{ std::copy_n(&m_default_data[0], m_size_data, &m_e2prom[0]);
for (int byte = 0; byte < m_size_data; byte++)
m_e2prom->write_byte(byte, m_default_data[byte]);
}
} }
@ -116,13 +81,7 @@ void x2212_device::nvram_default()
void x2212_device::nvram_read(emu_file &file) void x2212_device::nvram_read(emu_file &file)
{ {
auto buffer = std::make_unique<uint8_t[]>(m_size_data); file.read(&m_e2prom[0], 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]);
}
} }
@ -137,10 +96,7 @@ void x2212_device::nvram_write(emu_file &file)
if (m_auto_save) if (m_auto_save)
do_store(); do_store();
uint8_t *buffer = (uint8_t *) alloca(m_size_data); file.write(&m_e2prom[0], 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);
} }
@ -156,8 +112,7 @@ void x2212_device::nvram_write(emu_file &file)
void x2212_device::do_store() void x2212_device::do_store()
{ {
for (int byte = 0; byte < m_size_data; byte++) std::copy_n(&m_sram[0], m_size_data, &m_e2prom[0]);
m_e2prom->write_byte(byte, m_sram->read_byte(byte));
} }
@ -168,8 +123,7 @@ void x2212_device::do_store()
void x2212_device::do_recall() void x2212_device::do_recall()
{ {
for (int byte = 0; byte < m_size_data; byte++) std::copy_n(&m_e2prom[0], m_size_data, &m_sram[0]);
m_sram->write_byte(byte, m_e2prom->read_byte(byte));
} }
@ -184,7 +138,7 @@ void x2212_device::do_recall()
WRITE8_MEMBER( x2212_device::write ) 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 ) 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) : x2212_device(mconfig, X2210, tag, owner, clock, 0x40)
{ {
} }

View File

@ -20,18 +20,18 @@
//************************************************************************** //**************************************************************************
#define MCFG_X2212_ADD(_tag) \ #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 // some systems (like many early Atari games) wire up the /STORE signal
// to fire on power-down, effectively creating an "auto-save" functionality // to fire on power-down, effectively creating an "auto-save" functionality
#define MCFG_X2212_ADD_AUTOSAVE(_tag) \ #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); downcast<x2212_device &>(*device).set_auto_save(true);
#define MCFG_X2210_ADD(_tag) \ #define MCFG_X2210_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, X2210, 0) MCFG_DEVICE_ADD(_tag, X2210)
#define MCFG_X2210_ADD_AUTOSAVE(_tag) \ #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); downcast<x2212_device &>(*device).set_auto_save(true);
@ -42,13 +42,11 @@
// ======================> x2212_device // ======================> x2212_device
class x2212_device : public device_t, class x2212_device : public device_t, public device_nvram_interface
public device_memory_interface,
public device_nvram_interface
{ {
public: public:
// construction/destruction // 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 // inline configuration helpers
void set_auto_save(bool auto_save) { m_auto_save = auto_save; } void set_auto_save(bool auto_save) { m_auto_save = auto_save; }
@ -61,14 +59,11 @@ public:
DECLARE_WRITE_LINE_MEMBER( recall ); DECLARE_WRITE_LINE_MEMBER( recall );
protected: 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 // device-level overrides
virtual void device_start() override; virtual void device_start() override;
// device_memory_interface overrides
virtual space_config_vector memory_space_config() const override;
// device_nvram_interface overrides // device_nvram_interface overrides
virtual void nvram_default() override; virtual void nvram_default() override;
virtual void nvram_read(emu_file &file) override; virtual void nvram_read(emu_file &file) override;
@ -78,32 +73,25 @@ private:
// configuration state // configuration state
bool m_auto_save; bool m_auto_save;
// device-specific configuration
address_space_config m_sram_space_config;
address_space_config m_e2prom_space_config;
// internal state // internal state
address_space * m_sram; std::unique_ptr<u8[]> m_sram;
address_space * m_e2prom; std::unique_ptr<u8[]> m_e2prom;
bool m_store; bool m_store;
bool m_array_recall; bool m_array_recall;
int const m_size_data; int const m_size_data;
optional_region_ptr<uint8_t> m_default_data; optional_region_ptr<u8> m_default_data;
// internal helpers // internal helpers
void do_store(); void do_store();
void do_recall(); void do_recall();
void x2212_e2prom_map(address_map &map);
void x2212_sram_map(address_map &map);
}; };
class x2210_device : public x2212_device class x2210_device : public x2212_device
{ {
public: 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);
}; };