h8_timer: fix edge with compare match if both tt and tgr are larger than counter_cycle,

h8325: mask unused iscr/ier bits
This commit is contained in:
hap 2024-03-02 01:43:34 +01:00
parent c0a2d62733
commit f154215cee
4 changed files with 9 additions and 7 deletions

View file

@ -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) {

View file

@ -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));

View file

@ -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");

View file

@ -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();