ics2115: Cleanup timer code

This commit is contained in:
Olivier Galibert 2022-06-15 15:23:56 +02:00
parent 1ded6ae6d6
commit 67dee6278c

View File

@ -1105,22 +1105,14 @@ TIMER_CALLBACK_MEMBER( ics2115_device::timer_cb_1 )
void ics2115_device::recalc_timer(int timer)
{
//Old regression-based formula (minus constant)
//u64 period = m_timer[timer].preset * (m_timer[timer].scale << 16) / 60;
//New formula based on O.Galibert's reverse engineering of ICS2115 card firmware
// TODO : Related to input clock?
u64 period = ((m_timer[timer].scale & 0x1f) + 1) * (m_timer[timer].preset + 1);
period = (period << (4 + (m_timer[timer].scale >> 5)))*78125/2646;
period = period << (4 + (m_timer[timer].scale >> 5));
if (m_timer[timer].period != period)
{
logerror("Timer %d period %dns (%dHz)\n", timer, period, 1e9/period);
attotime tp = attotime::from_ticks(period, clock());
logerror("Timer %d period %dns (%dHz)\n", timer, int(tp.as_double()*1e9), int(1/tp.as_double()));
m_timer[timer].period = period;
// Adjust the timer lengths
if (period) // Reset the length
m_timer[timer].timer->adjust(attotime::from_nsec(period), 0, attotime::from_nsec(period));
else // Kill the timer if length == 0
m_timer[timer].timer->adjust(attotime::never);
m_timer[timer].timer->adjust(tp, 0, tp);
}
}