From f154215ceee7031b6dc3d48a2b87748c09bf2e13 Mon Sep 17 00:00:00 2001 From: hap Date: Sat, 2 Mar 2024 01:43:34 +0100 Subject: [PATCH] h8_timer: fix edge with compare match if both tt and tgr are larger than counter_cycle, h8325: mask unused iscr/ier bits --- src/devices/cpu/h8/h8.cpp | 4 ++-- src/devices/cpu/h8/h8325.cpp | 6 ++++-- src/devices/cpu/h8/h8_timer16.cpp | 4 ++-- src/devices/cpu/h8/h8_timer8.cpp | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/devices/cpu/h8/h8.cpp b/src/devices/cpu/h8/h8.cpp index b9bb981b95b..fa6985f1e98 100644 --- a/src/devices/cpu/h8/h8.cpp +++ b/src/devices/cpu/h8/h8.cpp @@ -612,7 +612,7 @@ int h8_device::trapa_setup() u8 h8_device::do_addx8(u8 v1, u8 v2) { - u8 c = (m_CCR & F_C) ? 1 : 0; + u8 c = m_CCR & F_C ? 1 : 0; u16 res = v1 + v2 + c; m_CCR &= ~(F_N|F_V|F_C); if(m_has_hc) { @@ -634,7 +634,7 @@ u8 h8_device::do_addx8(u8 v1, u8 v2) u8 h8_device::do_subx8(u8 v1, u8 v2) { - u8 c = (m_CCR & F_C) ? 1 : 0; + u8 c = m_CCR & F_C ? 1 : 0; u16 res = v1 - v2 - c; m_CCR &= ~(F_N|F_V|F_C); if(m_has_hc) { diff --git a/src/devices/cpu/h8/h8325.cpp b/src/devices/cpu/h8/h8325.cpp index cbed3c0321f..ff566aae1a2 100644 --- a/src/devices/cpu/h8/h8325.cpp +++ b/src/devices/cpu/h8/h8325.cpp @@ -97,8 +97,10 @@ void h8325_device::map(address_map &map) map(0xffc4, 0xffc4).rw(FUNC(h8325_device::syscr_r), FUNC(h8325_device::syscr_w)); map(0xffc5, 0xffc5).r(FUNC(h8325_device::mdcr_r)); - map(0xffc6, 0xffc6).rw(m_intc, FUNC(h8325_intc_device::iscr_r), FUNC(h8325_intc_device::iscr_w)); - map(0xffc7, 0xffc7).rw(m_intc, FUNC(h8325_intc_device::ier_r), FUNC(h8325_intc_device::ier_w)); + map(0xffc6, 0xffc6).lr8(NAME([this]() { return m_intc->iscr_r() | ~0x77; })); + map(0xffc6, 0xffc6).lw8(NAME([this](u8 data) { m_intc->iscr_w(data & 0x77); })); + map(0xffc7, 0xffc7).lr8(NAME([this]() { return m_intc->ier_r() | ~0x07; })); + map(0xffc7, 0xffc7).lw8(NAME([this](u8 data) { m_intc->ier_w(data & 0x07); })); map(0xffc8, 0xffc8).rw(m_timer8[0], FUNC(h8_timer8_channel_device::tcr_r), FUNC(h8_timer8_channel_device::tcr_w)); map(0xffc9, 0xffc9).rw(m_timer8[0], FUNC(h8_timer8_channel_device::tcsr_r), FUNC(h8_timer8_channel_device::tcsr_w)); diff --git a/src/devices/cpu/h8/h8_timer16.cpp b/src/devices/cpu/h8/h8_timer16.cpp index 25cc6ac9fa5..f5c16c6f691 100644 --- a/src/devices/cpu/h8/h8_timer16.cpp +++ b/src/devices/cpu/h8/h8_timer16.cpp @@ -261,14 +261,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 = (tt == m_tgr[i] || m_tcnt == m_tgr[i]); + bool match = m_tcnt == m_tgr[i] || (tt == m_tgr[i] && 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 = delta >= m_counter_cycle || (prev < m_tgr[i] && tt >= m_tgr[i]) || (m_tcnt <= prev && m_tcnt >= m_tgr[i]); if(match && BIT(m_ier, i) && m_interrupt[i] != -1) logerror("update_counter unexpected TGR %d IRQ\n, i"); diff --git a/src/devices/cpu/h8/h8_timer8.cpp b/src/devices/cpu/h8/h8_timer8.cpp index 33202c442c7..af0e1a27859 100644 --- a/src/devices/cpu/h8/h8_timer8.cpp +++ b/src/devices/cpu/h8/h8_timer8.cpp @@ -238,7 +238,7 @@ void h8_timer8_channel_device::update_counter(u64 cur_time) else m_tcnt = tt % m_counter_cycle; - if(tt == m_tcor[0] || m_tcnt == m_tcor[0]) { + if(m_tcnt == m_tcor[0] || (tt == m_tcor[0] && tt == m_counter_cycle)) { if(m_chained_timer) m_chained_timer->chained_timer_tcora();