summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/nec
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2018-07-07 02:40:29 +1000
committer Vas Crabb <vas@vastheman.com>2018-07-07 02:40:29 +1000
commitc3fb11c2c98a5c28ece6a27093a0f9def350ac64 (patch)
treec68b38f05ed1d32358add721fda7f45e8803479f /src/devices/cpu/nec
parent5d9e33b786d7ef452317439359f3cbd8cc920513 (diff)
devcb3
There are multiple issues with the current device callbacks: * They always dispatch through a pointer-to-member * Chained callbacks are a linked list so the branch unit can't predict the early * There's a runtime decision made on the left/right shift direction * There are runtime NULL checks on various objects * Binding a lambda isn't practical * Arbitrary transformations are not supported * When chaining callbacks it isn't clear what the MCFG_DEVCB_ modifiers apply to * It isn't possible to just append to a callback in derived configuration * The macros need a magic, hidden local called devcb * Moving code that uses the magic locals around is error-prone * Writing the MCFG_ macros to make a device usable is a pain * You can't discover applicable MCFG_ macros with intellisense * Macros are not scoped * Using an inappropriate macro isn't detected at compile time * Lots of other things This changeset overcomes the biggest obstacle to remving MCFG_ macros altogether. Essentially, to allow a devcb to be configured, call .bind() and expose the result (a bind target for the callback). Bind target methods starting with "set" repace the current callbacks; methods starting with "append" append to them. You can't reconfigure a callback after resolving it. There's no need to use a macro matching the handler signatures - use FUNC for everything. Current device is implied if no tag/finder is supplied (no need for explicit this). Lambdas are supported, and the memory space and offset are optional. These kinds of things work: * .read_cb().set([this] () { return something; }); * .read_cb().set([this] (offs_t offset) { return ~offset; }); * .write_cb().set([this] (offs_t offset, u8 data) { m_array[offset] = data; }); * .write_cb().set([this] (int state) { some_var = state; }); Arbitrary transforms are allowed, and they can modify offset/mask for example: * .read_cb().set(FUNC(my_state::handler)).transform([] (u8 data) { return bitswap<4>(data, 1, 3, 0, 2); }); * .read_cb().set(m_dev, FUNC(some_device::member)).transform([] (offs_t &offset, u8 data) { offset ^= 3; return data; }); It's possible to stack arbitrary transforms, at the cost of compile time (the whole transform stack gets inlined at compile time). Shifts count as an arbitrary transform, but mask/exor does not. Order of mask/shift/exor now matters. Modifications are applied in the specified order. These are NOT EQUIVALENT: * .read_cb().set(FUNC(my_state::handler)).mask(0x06).lshift(2); * .read_cb().set(FUNC(my_state::handler)).lshift(2).mask(0x06); The bit helper no longer reverses its behaviour for read callbacks, and I/O ports are no longer aware of the field mask. Binding a read callback to no-op is not supported - specify a constant. The GND and VCC aliases have been removed intentionally - they're TTL-centric, and were already being abused. Other quirks have been preserved, including write logger only logging when the data is non-zero (quite unhelpful in many of the cases where it's used). Legacy syntax is still supported for simple cases, but will be phased out. New devices should not have MCFG_ macros. I don't think I've missed any fundamental issues, but if I've broken something, let me know.
Diffstat (limited to 'src/devices/cpu/nec')
-rw-r--r--src/devices/cpu/nec/v25.h21
-rw-r--r--src/devices/cpu/nec/v53.cpp12
-rw-r--r--src/devices/cpu/nec/v53.h52
3 files changed, 44 insertions, 41 deletions
diff --git a/src/devices/cpu/nec/v25.h b/src/devices/cpu/nec/v25.h
index 9deaa0951ae..af7d5eb4d93 100644
--- a/src/devices/cpu/nec/v25.h
+++ b/src/devices/cpu/nec/v25.h
@@ -27,26 +27,26 @@ enum
#define MCFG_V25_PORT_PT_READ_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_pt_in_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_pt_in_cb(DEVCB_##_devcb);
#define MCFG_V25_PORT_P0_READ_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_p0_in_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_p0_in_cb(DEVCB_##_devcb);
#define MCFG_V25_PORT_P1_READ_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_p1_in_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_p1_in_cb(DEVCB_##_devcb);
#define MCFG_V25_PORT_P2_READ_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_p2_in_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_p2_in_cb(DEVCB_##_devcb);
#define MCFG_V25_PORT_P0_WRITE_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_p0_out_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_p0_out_cb(DEVCB_##_devcb);
#define MCFG_V25_PORT_P1_WRITE_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_p1_out_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_p1_out_cb(DEVCB_##_devcb);
#define MCFG_V25_PORT_P2_WRITE_CB(_devcb) \
- devcb = &downcast<v25_common_device &>(*device).set_p2_out_cb(DEVCB_##_devcb);
+ downcast<v25_common_device &>(*device).set_p2_out_cb(DEVCB_##_devcb);
class v25_common_device : public cpu_device
{
@@ -58,10 +58,17 @@ public:
template <class Object> devcb_base &set_p0_in_cb(Object &&cb) { return m_p0_in.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_p1_in_cb(Object &&cb) { return m_p1_in.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_p2_in_cb(Object &&cb) { return m_p2_in.set_callback(std::forward<Object>(cb)); }
+ auto pt_in_cb() { return m_pt_in.bind(); }
+ auto p0_in_cb() { return m_p0_in.bind(); }
+ auto p1_in_cb() { return m_p1_in.bind(); }
+ auto p2_in_cb() { return m_p2_in.bind(); }
template <class Object> devcb_base &set_p0_out_cb(Object &&cb) { return m_p0_out.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_p1_out_cb(Object &&cb) { return m_p1_out.set_callback(std::forward<Object>(cb)); }
template <class Object> devcb_base &set_p2_out_cb(Object &&cb) { return m_p2_out.set_callback(std::forward<Object>(cb)); }
+ auto p0_out_cb() { return m_p0_out.bind(); }
+ auto p1_out_cb() { return m_p1_out.bind(); }
+ auto p2_out_cb() { return m_p2_out.bind(); }
TIMER_CALLBACK_MEMBER(v25_timer_callback);
diff --git a/src/devices/cpu/nec/v53.cpp b/src/devices/cpu/nec/v53.cpp
index fc30638836b..d71e9d89d62 100644
--- a/src/devices/cpu/nec/v53.cpp
+++ b/src/devices/cpu/nec/v53.cpp
@@ -496,7 +496,6 @@ MACHINE_CONFIG_START(v53_base_device::device_add_mconfig)
MCFG_PIT8253_OUT1_HANDLER(WRITELINE( *this, v53_base_device, tcu_out1_trampoline_cb ))
MCFG_PIT8253_OUT2_HANDLER(WRITELINE( *this, v53_base_device, tcu_out2_trampoline_cb ))
-
MCFG_DEVICE_ADD("upd71071dma", V53_DMAU, 4000000)
MCFG_AM9517A_OUT_HREQ_CB(WRITELINE(*this, v53_base_device, hreq_trampoline_cb))
MCFG_AM9517A_OUT_EOP_CB(WRITELINE(*this, v53_base_device, eop_trampoline_cb))
@@ -515,13 +514,10 @@ MACHINE_CONFIG_START(v53_base_device::device_add_mconfig)
MCFG_AM9517A_OUT_DACK_2_CB(WRITELINE(*this, v53_base_device, dma_dack2_trampoline_w))
MCFG_AM9517A_OUT_DACK_3_CB(WRITELINE(*this, v53_base_device, dma_dack3_trampoline_w))
-
- MCFG_DEVICE_ADD("upd71059pic", PIC8259, 0)
- MCFG_PIC8259_OUT_INT_CB(WRITELINE(*this, v53_base_device, internal_irq_w))
- MCFG_PIC8259_IN_SP_CB(VCC)
- MCFG_PIC8259_CASCADE_ACK_CB(READ8(*this, v53_base_device, get_pic_ack))
-
-
+ pic8259_device &upd71059pic(PIC8259(config, "upd71059pic", 0));
+ upd71059pic.out_int_callback().set(FUNC(v53_base_device::internal_irq_w));
+ upd71059pic.in_sp_callback().set_constant(1);
+ upd71059pic.read_slave_ack_callback().set(FUNC(v53_base_device::get_pic_ack));
MCFG_DEVICE_ADD("v53scu", V53_SCU, 0)
MCFG_I8251_TXD_HANDLER(WRITELINE(*this, v53_base_device, scu_txd_trampoline_cb))
diff --git a/src/devices/cpu/nec/v53.h b/src/devices/cpu/nec/v53.h
index ef3450bb74e..536b8f8f458 100644
--- a/src/devices/cpu/nec/v53.h
+++ b/src/devices/cpu/nec/v53.h
@@ -16,25 +16,25 @@
// SCU
#define MCFG_V53_SCU_TXD_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_txd_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_txd_handler(DEVCB_##_devcb);
#define MCFG_V53_SCU_DTR_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_dtr_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_dtr_handler(DEVCB_##_devcb);
#define MCFG_V53_SCU_RTS_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_rts_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_rts_handler(DEVCB_##_devcb);
#define MCFG_V53_SCU_RXRDY_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_rxrdy_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_rxrdy_handler(DEVCB_##_devcb);
#define MCFG_V53_SCU_TXRDY_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_txrdy_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_txrdy_handler(DEVCB_##_devcb);
#define MCFG_V53_SCU_TXEMPTY_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_txempty_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_txempty_handler(DEVCB_##_devcb);
#define MCFG_V53_SCU_SYNDET_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_syndet_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_syndet_handler(DEVCB_##_devcb);
// TCU
#define MCFG_V53_TCU_CLK0(_clk) \
@@ -47,63 +47,63 @@
downcast<v53_base_device &>(*device).set_clk2(_clk);
#define MCFG_V53_TCU_OUT0_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out0_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out0_handler(DEVCB_##_devcb);
#define MCFG_V53_TCU_OUT1_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out1_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out1_handler(DEVCB_##_devcb);
#define MCFG_V53_TCU_OUT2_HANDLER(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out2_handler(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out2_handler(DEVCB_##_devcb);
// DMAU
#define MCFG_V53_DMAU_OUT_HREQ_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_hreq_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_hreq_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_EOP_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_eop_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_eop_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_IN_MEMR_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_in_memr_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_in_memr_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_MEMW_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_memw_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_memw_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_IN_IOR_0_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_in_ior_0_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_in_ior_0_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_IN_IOR_1_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_in_ior_1_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_in_ior_1_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_IN_IOR_2_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_in_ior_2_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_in_ior_2_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_IN_IOR_3_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_in_ior_3_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_in_ior_3_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_IOW_0_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_iow_0_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_iow_0_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_IOW_1_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_iow_1_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_iow_1_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_IOW_2_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_iow_2_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_iow_2_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_IOW_3_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_iow_3_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_iow_3_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_DACK_0_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_dack_0_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_dack_0_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_DACK_1_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_dack_1_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_dack_1_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_DACK_2_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_dack_2_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_dack_2_callback(DEVCB_##_devcb);
#define MCFG_V53_DMAU_OUT_DACK_3_CB(_devcb) \
- devcb = &downcast<v53_base_device &>(*device).set_out_dack_3_callback(DEVCB_##_devcb);
+ downcast<v53_base_device &>(*device).set_out_dack_3_callback(DEVCB_##_devcb);