summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/h8/h8_timer8.cpp
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2024-03-19 01:26:23 +0100
committer hap <happppp@users.noreply.github.com>2024-03-19 01:26:35 +0100
commitc545ac9eb6407348fe28f2cc3f70d07dcece915c (patch)
tree16cdba3f563d1b972a4ef6fb84eb281ce38e79dd /src/devices/cpu/h8/h8_timer8.cpp
parent3b7969802f84e98d53456403931d94338962b007 (diff)
h8_timer: compare match event was off by 1
Diffstat (limited to 'src/devices/cpu/h8/h8_timer8.cpp')
-rw-r--r--src/devices/cpu/h8/h8_timer8.cpp32
1 files changed, 17 insertions, 15 deletions
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;