From bd4f346ed100c8a08c4c8b9f9b0a6a9b5fed41a2 Mon Sep 17 00:00:00 2001 From: hap Date: Wed, 28 Feb 2024 12:18:05 +0100 Subject: h8_intc: don't detect an nmi at power-on when initial pin state is 'ASSERT_LINE', h8_timer: prevent multiple interrupts when timer wasn't clocked --- src/devices/cpu/h8/h83217.cpp | 7 ++++--- src/devices/cpu/h8/h8_intc.cpp | 18 +++++++++--------- src/devices/cpu/h8/h8_timer16.cpp | 21 ++++++++++++--------- src/devices/cpu/h8/h8_timer8.cpp | 4 +++- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/devices/cpu/h8/h83217.cpp b/src/devices/cpu/h8/h83217.cpp index 82f960ecdaf..225fd6888fb 100644 --- a/src/devices/cpu/h8/h83217.cpp +++ b/src/devices/cpu/h8/h83217.cpp @@ -186,9 +186,10 @@ void h83217_device::internal_update(u64 current_time) add_event(event_time, m_sci[0]->internal_update(current_time)); add_event(event_time, m_sci[1]->internal_update(current_time)); - add_event(event_time, m_timer8[0]->internal_update(current_time)); - add_event(event_time, m_timer8[1]->internal_update(current_time)); - add_event(event_time, m_timer8[2]->internal_update(current_time)); + + for (auto & timer8 : m_timer8) + add_event(event_time, timer8->internal_update(current_time)); + add_event(event_time, m_timer16_0->internal_update(current_time)); add_event(event_time, m_watchdog->internal_update(current_time)); diff --git a/src/devices/cpu/h8/h8_intc.cpp b/src/devices/cpu/h8/h8_intc.cpp index 8a85f5802ec..c84a0faa4a4 100644 --- a/src/devices/cpu/h8/h8_intc.cpp +++ b/src/devices/cpu/h8/h8_intc.cpp @@ -98,7 +98,7 @@ void h8_intc_device::set_input(int inputnum, int state) default: assert(0); break; } m_nmi_input = state == ASSERT_LINE; - if(set) { + if(machine().time() > attotime::zero && set) { m_pending_irqs[0] |= 1 << m_irq_vector_nmi; update_irq_state(); } @@ -148,7 +148,7 @@ void h8_intc_device::ier_w(u8 data) void h8_intc_device::check_level_irqs(bool update) { bool set = false; - for(int i=0; i> i) & 1) { case 0: m_irq_type[i] = LEVEL_LOW; @@ -189,7 +189,7 @@ void h8_intc_device::update_irq_types() void h8_intc_device::update_irq_state() { if(m_irq_vector_count > 0) { - const unsigned mask = (1 << m_irq_vector_count) - 1; + const u32 mask = (1 << m_irq_vector_count) - 1; m_pending_irqs[0] &= ~(mask << m_irq_vector_base); m_pending_irqs[0] |= (m_isr & m_ier & mask) << m_irq_vector_base; @@ -198,10 +198,10 @@ void h8_intc_device::update_irq_state() int cur_vector = 0; int cur_level = -1; - for(int i=0; i(m_iscr >> i,0,4)) { case 0: case 1: m_irq_type[i] = LEVEL_LOW; @@ -407,7 +407,7 @@ void h8s_intc_device::iscrl_w(u8 data) void h8s_intc_device::update_irq_types() { - for(int i=0; i> (2*i)) & 3) { case 0: m_irq_type[i] = LEVEL_LOW; diff --git a/src/devices/cpu/h8/h8_timer16.cpp b/src/devices/cpu/h8/h8_timer16.cpp index 20ef62a7fbd..cc40af2595b 100644 --- a/src/devices/cpu/h8/h8_timer16.cpp +++ b/src/devices/cpu/h8/h8_timer16.cpp @@ -163,7 +163,7 @@ void h8_timer16_channel_device::tgr_w(offs_t offset, u16 data, u16 mem_mask) u16 h8_timer16_channel_device::tbr_r(offs_t offset) { - return m_tgr[offset+m_tgr_count]; + return m_tgr[offset + m_tgr_count]; } void h8_timer16_channel_device::tbr_w(offs_t offset, u16 data, u16 mem_mask) @@ -242,11 +242,14 @@ void h8_timer16_channel_device::update_counter(u64 cur_time) base_time = (base_time + m_phase) >> m_clock_divider; new_time = (new_time + m_phase) >> m_clock_divider; } + if (new_time == base_time) + return; + if(m_counter_incrementing) { - int tt = m_tcnt + new_time - base_time; + u64 tt = m_tcnt + new_time - base_time; m_tcnt = tt % m_counter_cycle; - for(int i=0; i m_tcnt) { @@ -342,7 +345,7 @@ void h8_timer16_device::device_start() void h8_timer16_device::device_reset() { m_tstr = m_default_tstr; - for(int i=0; iset_enable((m_tstr >> i) & 1); } @@ -356,7 +359,7 @@ void h8_timer16_device::tstr_w(u8 data) { if(V>=1) logerror("tstr_w %02x\n", data); m_tstr = data; - for(int i=0; iset_enable((m_tstr >> i) & 1); } @@ -413,9 +416,9 @@ void h8_timer16_device::tocr_w(u8 data) u8 h8_timer16_device::tisr_r(offs_t offset) { u8 r = 0; - for(int i=0; itisr_r(offset) << i; - for(int i=m_timer_count; i<4; i++) + for(int i = m_timer_count; i < 4; i++) r |= 0x11 <=1) logerror("tisr%c_r %02x\n", 'a'+offset, r); @@ -426,7 +429,7 @@ u8 h8_timer16_device::tisr_r(offs_t offset) void h8_timer16_device::tisr_w(offs_t offset, u8 data) { if(V>=1) logerror("tisr%c_w %02x\n", 'a'+offset, data); - for(int i=0; itisr_w(offset, data >> i); } diff --git a/src/devices/cpu/h8/h8_timer8.cpp b/src/devices/cpu/h8/h8_timer8.cpp index 1af76263a71..883c3f6ac1c 100644 --- a/src/devices/cpu/h8/h8_timer8.cpp +++ b/src/devices/cpu/h8/h8_timer8.cpp @@ -222,8 +222,10 @@ void h8_timer8_channel_device::update_counter(u64 cur_time) u64 base_time = (m_last_clock_update + m_clock_divider/2) / m_clock_divider; u64 new_time = (cur_time + m_clock_divider/2) / m_clock_divider; + if (new_time == base_time) + return; - int tt = m_tcnt + new_time - base_time; + u64 tt = m_tcnt + new_time - base_time; m_tcnt = tt % m_counter_cycle; if(tt == m_tcor[0] || m_tcnt == m_tcor[0]) { -- cgit v1.2.3