From f26b6fd08c7717d7401b8b25a1c9952d5d112848 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Thu, 10 Jun 2010 08:01:06 +0000 Subject: [PATCH] Fix several timing problems: * suspend-until-time was broken (CPU would be suspended and never resumed) * timer devices would fire an initial callback even if not set up with a time yet * triggers requested after a time would fire twice; once right away and once at the target time Fixes many regressions. --- src/emu/diexec.c | 4 +++- src/emu/schedule.c | 5 +++-- src/emu/timer.c | 15 +++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/emu/diexec.c b/src/emu/diexec.c index 47fb9f0e826..147f04b357d 100644 --- a/src/emu/diexec.c +++ b/src/emu/diexec.c @@ -427,7 +427,7 @@ void device_execute_interface::spin_until_time(attotime duration) suspend_until_trigger(TRIGGER_SUSPENDTIME + timetrig, true); // then set a timer for it - timer_set(&m_machine, duration, this, timetrig, static_timed_trigger_callback); + timer_set(&m_machine, duration, this, TRIGGER_SUSPENDTIME + timetrig, static_timed_trigger_callback); timetrig = (timetrig + 1) % 256; } @@ -868,6 +868,8 @@ void device_execute_interface::device_input::set_state_synced(int state, int vec { LOG(("set_state_synced('%s',%d,%d,%02x)\n", m_device->tag(), m_linenum, state, vector)); + assert(state == ASSERT_LINE || state == HOLD_LINE || state == CLEAR_LINE || state == PULSE_LINE); + // treat PULSE_LINE as ASSERT+CLEAR if (state == PULSE_LINE) { diff --git a/src/emu/schedule.c b/src/emu/schedule.c index 5fa3a3a677b..c1e9ca0b3fe 100644 --- a/src/emu/schedule.c +++ b/src/emu/schedule.c @@ -288,8 +288,9 @@ void device_scheduler::trigger(int trigid, attotime after) timer_set(&m_machine, after, (void *)this, trigid, static_timed_trigger); // send the trigger to everyone who cares - for (device_execute_interface *exec = m_execute_list; exec != NULL; exec = exec->m_nextexec) - exec->trigger(trigid); + else + for (device_execute_interface *exec = m_execute_list; exec != NULL; exec = exec->m_nextexec) + exec->trigger(trigid); } diff --git a/src/emu/timer.c b/src/emu/timer.c index d8ea26dbc1b..9084170c3f2 100644 --- a/src/emu/timer.c +++ b/src/emu/timer.c @@ -34,6 +34,7 @@ #define DEFAULT_MINIMUM_QUANTUM ATTOSECONDS_IN_MSEC(100) + /*************************************************************************** TYPE DEFINITIONS ***************************************************************************/ @@ -1096,15 +1097,17 @@ void timer_device::device_reset() // convert the period into attotime attotime period = attotime_never; if (m_config.m_period > 0) + { period = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_period); - // convert the start_delay into attotime - attotime start_delay = attotime_zero; - if (m_config.m_start_delay > 0) - start_delay = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_start_delay); + // convert the start_delay into attotime + attotime start_delay = attotime_zero; + if (m_config.m_start_delay > 0) + start_delay = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_start_delay); - // allocate and start the backing timer - timer_adjust_periodic(m_timer, start_delay, m_config.m_param, period); + // allocate and start the backing timer + timer_adjust_periodic(m_timer, start_delay, m_config.m_param, period); + } break; }