summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/cpu/h8/h8_timer16.cpp26
-rw-r--r--src/devices/cpu/h8/h8_timer8.cpp32
2 files changed, 31 insertions, 27 deletions
diff --git a/src/devices/cpu/h8/h8_timer16.cpp b/src/devices/cpu/h8/h8_timer16.cpp
index e76f6bd60ca..263168909d6 100644
--- a/src/devices/cpu/h8/h8_timer16.cpp
+++ b/src/devices/cpu/h8/h8_timer16.cpp
@@ -275,13 +275,14 @@ void h8_timer16_channel_device::update_counter(u64 cur_time)
m_tcnt = tt % m_counter_cycle;
for(int i = 0; i < m_tgr_count; i++) {
- bool match = m_tcnt == m_tgr[i] || (tt == m_tgr[i] && tt == m_counter_cycle);
+ u16 cmp = m_tgr[i] + 1;
+ bool match = m_tcnt == cmp || (tt == cmp && tt == m_counter_cycle);
if(!match) {
// Need to do additional checks here for software that polls the flags with interrupts disabled, since recalc_event only schedules IRQ events.
if(prev >= m_counter_cycle)
- match = (m_tgr[i] > prev && tt >= m_tgr[i]) || (m_tgr[i] <= m_counter_cycle && m_tcnt < m_counter_cycle && (delta - (0x10000 - prev)) >= m_tgr[i]);
- else if(m_tgr[i] <= m_counter_cycle)
- match = delta >= m_counter_cycle || (prev < m_tgr[i] && tt >= m_tgr[i]) || (m_tcnt <= prev && m_tcnt >= m_tgr[i]);
+ match = (cmp > prev && tt >= cmp) || (cmp <= m_counter_cycle && m_tcnt < m_counter_cycle && (delta - (0x10000 - prev)) >= cmp);
+ else if(cmp <= m_counter_cycle)
+ match = delta >= m_counter_cycle || (prev < cmp && tt >= cmp) || (m_tcnt <= prev && m_tcnt >= cmp);
if(match && BIT(m_ier, i) && m_interrupt[i] != -1)
logerror("update_counter unexpected TGR %d IRQ\n, i");
@@ -327,8 +328,8 @@ void h8_timer16_channel_device::recalc_event(u64 cur_time)
if(m_counter_incrementing) {
u32 event_delay = 0xffffffff;
- if(m_tgr_clearing >= 0 && m_tgr[m_tgr_clearing])
- m_counter_cycle = m_tgr[m_tgr_clearing];
+ if(m_tgr_clearing >= 0)
+ m_counter_cycle = m_tgr[m_tgr_clearing] + 1;
else
m_counter_cycle = 0x10000;
if((m_ier & IRQ_V && m_interrupt[4] != -1) && (m_counter_cycle == 0x10000 || m_tcnt >= m_counter_cycle))
@@ -337,14 +338,15 @@ void h8_timer16_channel_device::recalc_event(u64 cur_time)
for(int i = 0; i < m_tgr_count; i++)
if(BIT(m_ier, i) && m_interrupt[i] != -1) {
u32 new_delay = 0xffffffff;
- if(m_tgr[i] > m_tcnt) {
- if(m_tcnt >= m_counter_cycle || m_tgr[i] <= m_counter_cycle)
- new_delay = m_tgr[i] - m_tcnt;
- } else if(m_tgr[i] <= m_counter_cycle) {
+ u16 cmp = m_tgr[i] + 1;
+ if(cmp > m_tcnt) {
+ if(m_tcnt >= m_counter_cycle || cmp <= m_counter_cycle)
+ new_delay = cmp - m_tcnt;
+ } else if(cmp <= m_counter_cycle) {
if(m_tcnt < m_counter_cycle)
- new_delay = (m_counter_cycle - m_tcnt) + m_tgr[i];
+ new_delay = (m_counter_cycle - m_tcnt) + cmp;
else
- new_delay = (0x10000 - m_tcnt) + m_tgr[i];
+ new_delay = (0x10000 - m_tcnt) + cmp;
}
if(event_delay > new_delay)
diff --git a/src/devices/cpu/h8/h8_timer8.cpp b/src/devices/cpu/h8/h8_timer8.cpp
index f96a7c8b938..16f0ee757a1 100644
--- a/src/devices/cpu/h8/h8_timer8.cpp
+++ b/src/devices/cpu/h8/h8_timer8.cpp
@@ -265,10 +265,9 @@ void h8_timer8_channel_device::update_counter(u64 cur_time, u64 delta)
} else
m_tcnt = tt % m_counter_cycle;
- if(m_tcnt == m_tcor[0] || (tt == m_tcor[0] && tt == m_counter_cycle)) {
+ if(u8 cmp = m_tcor[0] + 1; m_tcnt == cmp || (tt == cmp && tt == m_counter_cycle)) {
if(m_chained_timer)
m_chained_timer->chained_timer_tcora();
-
if(!(m_tcsr & TCSR_CMFA)) {
m_tcsr |= TCSR_CMFA;
if(m_tcr & TCR_CMIEA)
@@ -276,10 +275,12 @@ void h8_timer8_channel_device::update_counter(u64 cur_time, u64 delta)
}
}
- if(!(m_tcsr & TCSR_CMFB) && (tt == m_tcor[1] || m_tcnt == m_tcor[1])) {
- m_tcsr |= TCSR_CMFB;
- if(m_tcr & TCR_CMIEB)
- m_intc->internal_interrupt(m_irq_cb);
+ if(u8 cmp = m_tcor[1] + 1; m_tcnt == cmp || (tt == cmp && tt == m_counter_cycle)) {
+ if(!(m_tcsr & TCSR_CMFB)) {
+ m_tcsr |= TCSR_CMFB;
+ if(m_tcr & TCR_CMIEB)
+ m_intc->internal_interrupt(m_irq_cb);
+ }
}
if(tt >= 0x100 && (m_counter_cycle == 0x100 || prev >= m_counter_cycle)) {
@@ -309,23 +310,24 @@ void h8_timer8_channel_device::recalc_event(u64 cur_time)
cur_time = m_cpu->total_cycles();
u32 event_delay = 0xffffffff;
- if((m_clear_type == CLEAR_A || m_clear_type == CLEAR_B) && m_tcor[m_clear_type - CLEAR_A])
- m_counter_cycle = m_tcor[m_clear_type - CLEAR_A];
+ if(m_clear_type == CLEAR_A || m_clear_type == CLEAR_B)
+ m_counter_cycle = m_tcor[m_clear_type - CLEAR_A] + 1;
else
m_counter_cycle = 0x100;
if(m_counter_cycle == 0x100 || m_tcnt >= m_counter_cycle)
event_delay = 0x100 - m_tcnt;
- for(auto &elem : m_tcor) {
+ for(auto &tcor : m_tcor) {
u32 new_delay = 0xffffffff;
- if(elem > m_tcnt) {
- if(m_tcnt >= m_counter_cycle || elem <= m_counter_cycle)
- new_delay = elem - m_tcnt;
- } else if(elem <= m_counter_cycle) {
+ u8 cmp = tcor + 1;
+ if(cmp > m_tcnt) {
+ if(m_tcnt >= m_counter_cycle || cmp <= m_counter_cycle)
+ new_delay = cmp - m_tcnt;
+ } else if(cmp <= m_counter_cycle) {
if(m_tcnt < m_counter_cycle)
- new_delay = (m_counter_cycle - m_tcnt) + elem;
+ new_delay = (m_counter_cycle - m_tcnt) + cmp;
else
- new_delay = (0x100 - m_tcnt) + elem;
+ new_delay = (0x100 - m_tcnt) + cmp;
}
if(event_delay > new_delay)
event_delay = new_delay;