315_5338a: Improve and clean up

This commit is contained in:
Dirk Best 2018-04-29 16:06:42 +02:00
parent 03fcfe9622
commit 84cbea836e
2 changed files with 72 additions and 88 deletions

View File

@ -33,16 +33,11 @@ DEFINE_DEVICE_TYPE(SEGA_315_5338A, sega_315_5338a_device, "315_5338a", "Sega 315
sega_315_5338a_device::sega_315_5338a_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, SEGA_315_5338A, tag, owner, clock),
m_read_cb(*this), m_write_cb(*this),
m_out0_cb(*this),
m_in1_cb(*this),
m_in2_cb(*this),
m_in3_cb(*this),
m_in4_cb(*this),
m_out4_cb(*this),
m_out5_cb(*this),
m_in6_cb(*this),
m_port0(0xff), m_config(0), m_serial_output(0), m_address(0)
m_in_port_cb{ {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this} },
m_out_port_cb{ {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this} },
m_port_config(0), m_serial_output(0), m_address(0)
{
std::fill(std::begin(m_port_value), std::end(m_port_value), 0xff);
}
//-------------------------------------------------
@ -54,18 +49,16 @@ void sega_315_5338a_device::device_start()
// resolve callbacks
m_read_cb.resolve_safe(0xff);
m_write_cb.resolve_safe();
m_out0_cb.resolve_safe();
m_in1_cb.resolve_safe(0xff);
m_in2_cb.resolve_safe(0xff);
m_in3_cb.resolve_safe(0xff);
m_in4_cb.resolve_safe(0xff);
m_out4_cb.resolve_safe();
m_out5_cb.resolve_safe();
m_in6_cb.resolve_safe(0xff);
for (unsigned i = 0; i < 7; i++)
{
m_in_port_cb[i].resolve_safe(0xff);
m_out_port_cb[i].resolve_safe();
}
// register for save states
save_item(NAME(m_port0));
save_item(NAME(m_config));
save_pointer(NAME(m_port_value), 7);
save_item(NAME(m_port_config));
save_item(NAME(m_serial_output));
save_item(NAME(m_address));
}
@ -81,19 +74,19 @@ READ8_MEMBER( sega_315_5338a_device::read )
switch (offset)
{
// return output latch
case 0x00: data = m_port0; break;
// standard input ports
case 0x01: data = m_in1_cb(0); break;
case 0x02: data = m_in2_cb(0); break;
case 0x03: data = m_in3_cb(0); break;
// input/output port
case 0x04: data = m_in4_cb(0); break;
// input port
case 0x06: data = m_in6_cb(0); break;
// port 0 to 6
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
if (BIT(m_port_config, offset))
data = m_in_port_cb[offset](0);
else
data = m_port_value[offset];
break;
// serial data read back?
case 0x0a: data = m_serial_output; break;
@ -122,23 +115,21 @@ WRITE8_MEMBER( sega_315_5338a_device::write )
switch (offset)
{
// latched output port
case 0x00: m_port0 = data; m_out0_cb(data); break;
// input/output port
case 0x04: m_out4_cb(data); break;
// output port
case 0x05: m_out5_cb(data); break;
// config register?
case 0x08:
// 765----- unknown
// ---4---- port 4 direction (0 = output, 1 = input)
// ----3210 unknown
m_config = data;
// port 0 to 6
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
m_port_value[offset] = data;
m_out_port_cb[offset](data);
break;
// port direction register (0 = output, 1 = input)
case 0x08: m_port_config = data; break;
// command register
case 0x09:
switch (data)

View File

@ -34,29 +34,47 @@
#define MCFG_315_5338A_WRITE_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_write_callback(DEVCB_##_devcb);
#define MCFG_315_5338A_IN0_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<0>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT0_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out0_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<0>(DEVCB_##_devcb);
#define MCFG_315_5338A_IN1_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in1_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<1>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT1_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<1>(DEVCB_##_devcb);
#define MCFG_315_5338A_IN2_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in2_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<2>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT2_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<2>(DEVCB_##_devcb);
#define MCFG_315_5338A_IN3_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in3_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<3>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT3_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<3>(DEVCB_##_devcb);
#define MCFG_315_5338A_IN4_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in4_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<4>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT4_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out4_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<4>(DEVCB_##_devcb);
#define MCFG_315_5338A_IN5_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<5>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT5_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out5_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<5>(DEVCB_##_devcb);
#define MCFG_315_5338A_IN6_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_in6_callback(DEVCB_##_devcb);
devcb = &downcast<sega_315_5338a_device &>(*device).set_in_callback<6>(DEVCB_##_devcb);
#define MCFG_315_5338A_OUT6_CB(_devcb) \
devcb = &downcast<sega_315_5338a_device &>(*device).set_out_callback<6>(DEVCB_##_devcb);
//**************************************************************************
@ -76,29 +94,11 @@ public:
template <class Object> devcb_base &set_write_callback(Object &&cb)
{ return m_write_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_out0_callback(Object &&cb)
{ return m_out0_cb.set_callback(std::forward<Object>(cb)); }
template <int Port, class Object> devcb_base &set_out_callback(Object &&cb)
{ return m_out_port_cb[Port].set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_in1_callback(Object &&cb)
{ return m_in1_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_in2_callback(Object &&cb)
{ return m_in2_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_in3_callback(Object &&cb)
{ return m_in3_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_in4_callback(Object &&cb)
{ return m_in4_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_out4_callback(Object &&cb)
{ return m_out4_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_out5_callback(Object &&cb)
{ return m_out5_cb.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_in6_callback(Object &&cb)
{ return m_in6_cb.set_callback(std::forward<Object>(cb)); }
template <int Port, class Object> devcb_base &set_in_callback(Object &&cb)
{ return m_in_port_cb[Port].set_callback(std::forward<Object>(cb)); }
DECLARE_READ8_MEMBER(read);
DECLARE_WRITE8_MEMBER(write);
@ -111,18 +111,11 @@ private:
// callbacks
devcb_read8 m_read_cb;
devcb_write8 m_write_cb;
devcb_read8 m_in_port_cb[7];
devcb_write8 m_out_port_cb[7];
devcb_write8 m_out0_cb;
devcb_read8 m_in1_cb;
devcb_read8 m_in2_cb;
devcb_read8 m_in3_cb;
devcb_read8 m_in4_cb;
devcb_write8 m_out4_cb;
devcb_write8 m_out5_cb;
devcb_read8 m_in6_cb;
uint8_t m_port0;
uint8_t m_config;
uint8_t m_port_value[7];
uint8_t m_port_config;
uint8_t m_serial_output;
uint16_t m_address;
};