path: root/src/emu/device.h
diff options
author Vas Crabb <>2018-07-07 02:40:29 +1000
committer Vas Crabb <>2018-07-07 02:40:29 +1000
commitc3fb11c2c98a5c28ece6a27093a0f9def350ac64 (patch)
treec68b38f05ed1d32358add721fda7f45e8803479f /src/emu/device.h
parent5d9e33b786d7ef452317439359f3cbd8cc920513 (diff)
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/emu/device.h')
1 files changed, 3 insertions, 6 deletions
diff --git a/src/emu/device.h b/src/emu/device.h
index 8b3b2c94574..e9d91bf4cf4 100644
--- a/src/emu/device.h
+++ b/src/emu/device.h
@@ -374,8 +374,7 @@ class device_t : public delegate_late_bind
friend class simple_list<device_t>;
friend class running_machine;
friend class finder_base;
- friend class devcb_read_base;
- friend class devcb_write_base;
+ friend class devcb_base;
class subdevice_list
@@ -523,8 +522,6 @@ public:
// owned object helpers
subdevice_list &subdevices() { return m_subdevices; }
const subdevice_list &subdevices() const { return m_subdevices; }
- const std::list<devcb_read_base *> input_callbacks() const { return m_input_callbacks; }
- const std::list<devcb_write_base *> output_callbacks() const { return m_output_callbacks; }
// device-relative tag lookups
std::string subtag(const char *tag) const;
@@ -597,6 +594,7 @@ protected:
void post_load();
void notify_clock_changed();
finder_base *register_auto_finder(finder_base &autodev);
+ void register_callback(devcb_base &callback);
//------------------- begin derived class overrides
@@ -658,8 +656,7 @@ private:
bool m_started; // true if the start function has succeeded
finder_base * m_auto_finder_list; // list of objects to auto-find
mutable std::vector<rom_entry> m_rom_entries;
- std::list<devcb_read_base *> m_input_callbacks;
- std::list<devcb_write_base *> m_output_callbacks;
+ std::list<devcb_base *> m_callbacks;
// string formatting buffer for logerror
mutable util::ovectorstream m_string_buffer;