diff options
Diffstat (limited to 'src/emu/schedule.h')
-rw-r--r-- | src/emu/schedule.h | 111 |
1 files changed, 47 insertions, 64 deletions
diff --git a/src/emu/schedule.h b/src/emu/schedule.h index f5631a6f816..b8515c0a00d 100644 --- a/src/emu/schedule.h +++ b/src/emu/schedule.h @@ -22,18 +22,7 @@ // MACROS //************************************************************************** -#define TIMER_CALLBACK_MEMBER(name) void name(void *ptr, s32 param) - -// macro for the RC time constant on a 74LS123 with C > 1000pF -// R is in ohms, C is in farads -#define TIME_OF_74LS123(r,c) (0.45 * (double)(r) * (double)(c)) - -// macros for the RC time constant on a 555 timer IC -// R is in ohms, C is in farads -#define PERIOD_OF_555_MONOSTABLE_NSEC(r,c) ((attoseconds_t)(1100000000 * (double)(r) * (double)(c))) -#define PERIOD_OF_555_ASTABLE_NSEC(r1,r2,c) ((attoseconds_t)( 693000000 * ((double)(r1) + 2.0 * (double)(r2)) * (double)(c))) -#define PERIOD_OF_555_MONOSTABLE(r,c) attotime::from_nsec(PERIOD_OF_555_MONOSTABLE_NSEC(r,c)) -#define PERIOD_OF_555_ASTABLE(r1,r2,c) attotime::from_nsec(PERIOD_OF_555_ASTABLE_NSEC(r1,r2,c)) +#define TIMER_CALLBACK_MEMBER(name) void name(s32 param) //************************************************************************** @@ -41,70 +30,66 @@ //************************************************************************** // timer callbacks look like this -typedef named_delegate<void (void *, s32)> timer_expired_delegate; +typedef named_delegate<void (s32)> timer_expired_delegate; // ======================> emu_timer class emu_timer { - friend class device_scheduler; - friend class simple_list<emu_timer>; - friend class fixed_allocator<emu_timer>; - friend class resource_pool_object<emu_timer>; - - // construction/destruction - emu_timer(); - ~emu_timer(); - - // allocation and re-use - emu_timer &init(running_machine &machine, timer_expired_delegate callback, void *ptr, bool temporary); - emu_timer &init(device_t &device, device_timer_id id, void *ptr, bool temporary); - emu_timer &release(); - public: // getters - emu_timer *next() const { return m_next; } - running_machine &machine() const { assert(m_machine != nullptr); return *m_machine; } - bool enabled() const { return m_enabled; } - int param() const { return m_param; } - void *ptr() const { return m_ptr; } + bool enabled() const noexcept { return m_enabled; } + s32 param() const noexcept { return m_param; } // setters - bool enable(bool enable = true); - void set_param(int param) { m_param = param; } - void set_ptr(void *ptr) { m_ptr = ptr; } + bool enable(bool enable = true) noexcept; + void set_param(s32 param) noexcept { m_param = param; } // control - void reset(const attotime &duration = attotime::never) { adjust(duration, m_param, m_period); } - void adjust(attotime start_delay, s32 param = 0, const attotime &periodicity = attotime::never); + void reset(const attotime &duration = attotime::never) noexcept { adjust(duration, m_param, m_period); } + void adjust(attotime start_delay, s32 param = 0, const attotime &periodicity = attotime::never) noexcept; // timing queries - attotime elapsed() const; - attotime remaining() const; - attotime start() const { return m_start; } - attotime expire() const { return m_expire; } - attotime period() const { return m_period; } + attotime elapsed() const noexcept; + attotime remaining() const noexcept; + attotime start() const noexcept { return m_start; } + attotime expire() const noexcept { return m_expire; } + attotime period() const noexcept { return m_period; } private: + // construction/destruction + emu_timer() noexcept; + ~emu_timer(); + + // allocation and re-use + emu_timer &init( + running_machine &machine, + timer_expired_delegate &&callback, + attotime start_delay, + s32 param, + bool temporary); + // internal helpers - void register_save(); - void schedule_next_period(); + void register_save(save_manager &manager) ATTR_COLD; + void schedule_next_period() noexcept; void dump() const; // internal state - running_machine * m_machine; // reference to the owning machine + device_scheduler * m_scheduler; // reference to the owning machine emu_timer * m_next; // next timer in order in the list emu_timer * m_prev; // previous timer in order in the list timer_expired_delegate m_callback; // callback function s32 m_param; // integer parameter - void * m_ptr; // pointer parameter bool m_enabled; // is the timer enabled? bool m_temporary; // is the timer temporary? attotime m_period; // the repeat frequency of the timer attotime m_start; // time when the timer was started attotime m_expire; // time when the timer will expire - device_t * m_device; // for device timers, a pointer to the device - device_timer_id m_id; // for device timers, the ID of the timer + u32 m_index; // needed to restore timers scheduled at the same time in correct order + + friend class device_scheduler; + friend class fixed_allocator<emu_timer>; + friend class simple_list<emu_timer>; // FIXME: fixed_allocator requires this }; @@ -121,27 +106,25 @@ public: ~device_scheduler(); // getters - running_machine &machine() const { return m_machine; } - attotime time() const; - emu_timer *first_timer() const { return m_timer_list; } - device_execute_interface *currently_executing() const { return m_executing_device; } + running_machine &machine() const noexcept { return m_machine; } + attotime time() const noexcept; + emu_timer *first_timer() const noexcept { return m_timer_list; } + device_execute_interface *currently_executing() const noexcept { return m_executing_device; } bool can_save() const; // execution void timeslice(); - void abort_timeslice(); + void abort_timeslice() noexcept; void trigger(int trigid, const attotime &after = attotime::zero); - void boost_interleave(const attotime ×lice_time, const attotime &boost_duration); + void add_quantum(const attotime &quantum, const attotime &duration); + void perfect_quantum(const attotime &duration); void suspend_resume_changed() { m_suspend_changes_pending = true; } // timers, specified by callback/name - emu_timer *timer_alloc(timer_expired_delegate callback, void *ptr = nullptr); - void timer_set(const attotime &duration, timer_expired_delegate callback, int param = 0, void *ptr = nullptr); - void synchronize(timer_expired_delegate callback = timer_expired_delegate(), int param = 0, void *ptr = nullptr) { timer_set(attotime::zero, callback, param, ptr); } - - // timers, specified by device/id; generally devices should use the device_t methods instead - emu_timer *timer_alloc(device_t &device, device_timer_id id = 0, void *ptr = nullptr); - void timer_set(const attotime &duration, device_t &device, device_timer_id id = 0, int param = 0, void *ptr = nullptr); + emu_timer *timer_alloc(timer_expired_delegate callback); + [[deprecated("timer_set is deprecated; please avoid anonymous timers. Use an allocated emu_timer instead.")]] + void timer_set(const attotime &duration, timer_expired_delegate callback, s32 param = 0); + void synchronize(timer_expired_delegate callback = timer_expired_delegate(), s32 param = 0); // debugging void dump_timers() const; @@ -151,7 +134,7 @@ public: private: // callbacks - void timed_trigger(void *ptr, s32 param); + void timed_trigger(s32 param); void presave(); void postload(); @@ -159,10 +142,9 @@ private: void compute_perfect_interleave(); void rebuild_execute_list(); void apply_suspend_changes(); - void add_scheduling_quantum(const attotime &quantum, const attotime &duration); // timer helpers - emu_timer &timer_list_insert(emu_timer &timer); + template <bool CheckIndex = false> emu_timer &timer_list_insert(emu_timer &timer); emu_timer &timer_list_remove(emu_timer &timer); void execute_timers(); @@ -174,6 +156,7 @@ private: // list of active timers emu_timer * m_timer_list; // head of the active list + emu_timer * m_inactive_timers; // head of the inactive timer list fixed_allocator<emu_timer> m_timer_allocator; // allocator for timers // other internal states |