diff options
Diffstat (limited to 'src/emu/device.h')
-rw-r--r-- | src/emu/device.h | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/src/emu/device.h b/src/emu/device.h index 77c12cb2d56..87736144292 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -37,19 +37,6 @@ //************************************************************************** -// DEVICE CONFIGURATION MACROS -//************************************************************************** - -// configure devices - -#define DECLARE_READ_LINE_MEMBER(name) int name() -#define READ_LINE_MEMBER(name) int name() -#define DECLARE_WRITE_LINE_MEMBER(name) void name([[maybe_unused]] int state) -#define WRITE_LINE_MEMBER(name) void name([[maybe_unused]] int state) - - - -//************************************************************************** // GLOBAL VARIABLES //************************************************************************** @@ -210,7 +197,7 @@ private: assert(!owner); assert(!clock); - return make_unique_clear<DriverClass>(mconfig, type, tag); + return std::make_unique<DriverClass>(mconfig, type, tag); } create_func const m_creator; @@ -468,10 +455,6 @@ constexpr auto driver_device_creator = &emu::detail::driver_tag_func<DriverClass class device_missing_dependencies : public emu_exception { }; -// timer IDs for devices -typedef u32 device_timer_id; - - /// \brief Base class for devices /// /// The base class for all device implementations in MAME's modular @@ -482,8 +465,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_base; + friend class device_resolver_base; class subdevice_list { @@ -651,8 +633,8 @@ public: // interface helpers interface_list &interfaces() { return m_interfaces; } const interface_list &interfaces() const { return m_interfaces; } - template<class DeviceClass> bool interface(DeviceClass *&intf) { intf = dynamic_cast<DeviceClass *>(this); return (intf != nullptr); } - template<class DeviceClass> bool interface(DeviceClass *&intf) const { intf = dynamic_cast<const DeviceClass *>(this); return (intf != nullptr); } + template <class DeviceClass> bool interface(DeviceClass *&intf) { intf = dynamic_cast<DeviceClass *>(this); return (intf != nullptr); } + template <class DeviceClass> bool interface(DeviceClass *&intf) const { intf = dynamic_cast<const DeviceClass *>(this); return (intf != nullptr); } // specialized helpers for common core interfaces bool interface(device_execute_interface *&intf) { intf = m_interfaces.m_execute; return (intf != nullptr); } @@ -675,8 +657,42 @@ public: ioport_port *ioport(std::string_view tag) const; device_t *subdevice(std::string_view tag) const; device_t *siblingdevice(std::string_view tag) const; - template<class DeviceClass> DeviceClass *subdevice(std::string_view tag) const { return downcast<DeviceClass *>(subdevice(tag)); } - template<class DeviceClass> DeviceClass *siblingdevice(std::string_view tag) const { return downcast<DeviceClass *>(siblingdevice(tag)); } + template <class DeviceClass> + DeviceClass *subdevice(std::string_view tag) const + { + device_t *const found = subdevice(tag); + if constexpr (std::is_base_of_v<device_t, DeviceClass>) + { + return downcast<DeviceClass *>(found); + } + else + { + auto const result = dynamic_cast<DeviceClass *>(found); +#if defined(MAME_DEBUG) + if (found && !result) + report_bad_device_cast(found, typeid(device_t), typeid(DeviceClass)); +#endif + return result; + } + } + template <class DeviceClass> + DeviceClass *siblingdevice(std::string_view tag) const + { + device_t *const found = siblingdevice(tag); + if constexpr (std::is_base_of_v<device_t, DeviceClass>) + { + return downcast<DeviceClass *>(found); + } + else + { + auto const result = dynamic_cast<DeviceClass *>(found); +#if defined(MAME_DEBUG) + if (found && !result) + report_bad_device_cast(found, typeid(device_t), typeid(DeviceClass)); +#endif + return result; + } + } std::string parameter(std::string_view tag) const; // configuration helpers @@ -696,19 +712,17 @@ public: // clock/timing accessors u32 clock() const { return m_clock; } u32 unscaled_clock() const { return m_unscaled_clock; } - void set_unscaled_clock(u32 clock); - void set_unscaled_clock(const XTAL &xtal) { set_unscaled_clock(xtal.value()); } - void set_unscaled_clock_int(u32 clock) { set_unscaled_clock(clock); } // non-overloaded name because binding to overloads is ugly + void set_unscaled_clock(u32 clock, bool sync_on_new_clock_domain = false); + void set_unscaled_clock(const XTAL &xtal, bool sync_on_new_clock_domain = false) { set_unscaled_clock(xtal.value(), sync_on_new_clock_domain); } + void set_unscaled_clock_int(u32 clock) { set_unscaled_clock(clock, false); } // non-overloaded name because binding to overloads is ugly + void set_unscaled_clock_int_sync(u32 clock) { set_unscaled_clock(clock, true); } // non-overloaded name because binding to overloads is ugly double clock_scale() const { return m_clock_scale; } void set_clock_scale(double clockscale); attotime clocks_to_attotime(u64 clocks) const noexcept; u64 attotime_to_clocks(const attotime &duration) const noexcept; // timer interfaces - emu_timer *timer_alloc(device_timer_id id = 0, void *ptr = nullptr); - void timer_set(const attotime &duration, device_timer_id id = 0, int param = 0, void *ptr = nullptr); - void synchronize(device_timer_id id = 0, int param = 0, void *ptr = nullptr) { timer_set(attotime::zero, id, param, ptr); } - void timer_expired(emu_timer &timer, device_timer_id id, int param, void *ptr) { device_timer(timer, id, param, ptr); } + template <typename... T> emu_timer *timer_alloc(T &&... args); /// \brief Register data for save states /// @@ -777,7 +791,7 @@ public: /// \param [in] index A numeric value to distinguish between saved /// items with the same name. /// \sa save_item - template<typename ItemType> + template <typename ItemType> void ATTR_COLD save_pointer(ItemType &&value, const char *valname, u32 count, int index = 0) { assert(m_save); @@ -806,7 +820,7 @@ public: /// \param [in] index A numeric value to distinguish between saved /// items with the same name. /// \sa save_item - template<typename ItemType, typename StructType, typename ElementType> + template <typename ItemType, typename StructType, typename ElementType> void ATTR_COLD save_pointer(ItemType &&value, ElementType StructType::*element, const char *valname, u32 count, int index = 0) { assert(m_save); @@ -834,9 +848,8 @@ protected: void debug_setup(); void pre_save(); void post_load(); - void notify_clock_changed(); - finder_base *register_auto_finder(finder_base &autodev); - void register_callback(devcb_base &callback); + void notify_clock_changed(bool sync_on_new_clock_domain = false); + device_resolver_base *register_auto_finder(device_resolver_base &autodev); //------------------- begin derived class overrides @@ -976,7 +989,6 @@ protected: virtual void device_clock_changed(); virtual void device_debug_setup(); - virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); //------------------- end derived class overrides @@ -1016,9 +1028,8 @@ private: std::string m_basetag; // base part of the tag bool m_config_complete; // have we completed our configuration? bool m_started; // true if the start function has succeeded - finder_base * m_auto_finder_list; // list of objects to auto-find + device_resolver_base * m_auto_finder_list; // list of objects to auto-find mutable std::vector<rom_entry> m_rom_entries; - std::list<devcb_base *> m_callbacks; std::vector<memory_view *> m_viewlist; // list of views // string formatting buffer for logerror @@ -1182,7 +1193,7 @@ public: /// \sa interface_pre_save device_t::device_post_load virtual void interface_post_load() ATTR_COLD; - virtual void interface_clock_changed(); + virtual void interface_clock_changed(bool sync_on_new_clock_domain); virtual void interface_debug_setup(); private: |