From fbabb96113d690ea562a3258cdf52823d799c1e2 Mon Sep 17 00:00:00 2001 From: hap Date: Sun, 24 Mar 2024 21:59:14 +0100 Subject: avr8: some registers were missing from addressmap, avr8: fix regression with C flag on SBIW opcode, fix V flag on DEC/SBIW opcodes --- src/devices/cpu/avr8/avr8.cpp | 3 +++ src/devices/cpu/avr8/avr8ops.hxx | 38 +++++++++++++++++++------------------- src/mame/homebrew/lft_phasor.cpp | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/devices/cpu/avr8/avr8.cpp b/src/devices/cpu/avr8/avr8.cpp index f949ed0ef03..7779648d057 100644 --- a/src/devices/cpu/avr8/avr8.cpp +++ b/src/devices/cpu/avr8/avr8.cpp @@ -566,6 +566,9 @@ void avr8_device::base_internal_map(address_map &map) map(0x003f, 0x003f).w(FUNC(avr8_device::eecr_w)); map(0x0043, 0x0043).w(FUNC(avr8_device::gtccr_w)); map(0x0044, 0x0044).w(FUNC(avr8_device::tccr0a_w)); + map(0x0045, 0x0045).w(FUNC(avr8_device::tccr0b_w)); + map(0x0047, 0x0047).w(FUNC(avr8_device::ocr0a_w)); + map(0x0048, 0x0048).w(FUNC(avr8_device::ocr0b_w)); map(0x004a, 0x004a).w(FUNC(avr8_device::gpior1_w)); map(0x004b, 0x004b).w(FUNC(avr8_device::gpior2_w)); map(0x004c, 0x004c).w(FUNC(avr8_device::spcr_w)); diff --git a/src/devices/cpu/avr8/avr8ops.hxx b/src/devices/cpu/avr8/avr8ops.hxx index 07fb035c7c7..0ac10342616 100644 --- a/src/devices/cpu/avr8/avr8ops.hxx +++ b/src/devices/cpu/avr8/avr8ops.hxx @@ -1047,9 +1047,7 @@ void avr8_base_device::op_neg(uint16_t op) const uint8_t res = 0 - rd; m_r[SREG] &= ~(SREG_MASK_C | SREG_MASK_Z | SREG_MASK_N | SREG_MASK_V | SREG_MASK_S | SREG_MASK_H); if (res == 0) - { m_r[SREG] |= SREG_MASK_Z; - } else { m_r[SREG] |= SREG_MASK_C; @@ -1122,7 +1120,7 @@ void avr8_base_device::op_clrf(uint16_t op) void avr8_base_device::op_ijmp(uint16_t op) { - m_pc = (ZREG - 1) << 1; + m_pc = (ZREG << 1) - 2; } void avr8_base_device::op_eijmp(uint16_t op) @@ -1135,12 +1133,12 @@ void avr8_base_device::op_dec(uint16_t op) const uint8_t rd = m_r[RD5(op)]; const uint8_t res = rd - 1; m_r[SREG] &= ~(SREG_MASK_V | SREG_MASK_N | SREG_MASK_S | SREG_MASK_Z); - if (rd == 0x7f) + if (res == 0) + m_r[SREG] |= SREG_MASK_Z; + else if (res == 0x7f) m_r[SREG] |= SREG_MASK_V | SREG_MASK_S; else if (BIT(res, 7)) m_r[SREG] |= SREG_MASK_N | SREG_MASK_S; - else if (res == 0) - m_r[SREG] |= SREG_MASK_Z; m_r[RD5(op)] = res; } @@ -1148,8 +1146,7 @@ void avr8_base_device::op_jmp(uint16_t op) { uint32_t offs = KCONST22(op) << 16; m_pc += 2; - uint16_t wordval = m_program->read_word(m_pc); - offs |= wordval; + offs |= m_program->read_word(m_pc); m_pc = offs << 1; m_pc -= 2; } @@ -1234,9 +1231,7 @@ void avr8_base_device::op_adiw(uint16_t op) const uint8_t rr = m_r[25 + (DCONST(op) << 1)]; const uint16_t pd = ((rr << 8) | rd) + KCONST6(op); m_r[SREG] &= ~(SREG_MASK_V | SREG_MASK_N | SREG_MASK_S | SREG_MASK_Z | SREG_MASK_C); - if (pd == 0) - m_r[SREG] |= SREG_MASK_Z; - else if (BIT(pd, 15)) + if (BIT(pd, 15)) { m_r[SREG] |= SREG_MASK_N; if (!BIT(rr, 7)) @@ -1244,8 +1239,13 @@ void avr8_base_device::op_adiw(uint16_t op) else m_r[SREG] |= SREG_MASK_S; } - if (BIT(rr, 7) && !BIT(pd, 15)) - m_r[SREG] |= SREG_MASK_C; + else + { + if (pd == 0) + m_r[SREG] |= SREG_MASK_Z; + if (BIT(rr, 7)) + m_r[SREG] |= SREG_MASK_C; + } m_r[24 + (DCONST(op) << 1)] = pd & 0x00ff; m_r[25 + (DCONST(op) << 1)] = (pd >> 8) & 0x00ff; } @@ -1256,16 +1256,16 @@ void avr8_base_device::op_sbiw(uint16_t op) const uint8_t rr = m_r[25 + (DCONST(op) << 1)]; const uint16_t pd = ((rr << 8) | rd) - KCONST6(op); m_r[SREG] &= ~(SREG_MASK_V | SREG_MASK_N | SREG_MASK_S | SREG_MASK_Z | SREG_MASK_C); - m_r[SREG] |= (pd == 0) ? SREG_MASK_Z : 0; if (BIT(pd, 15)) { - if (BIT(rr, 7)) - m_r[SREG] |= SREG_MASK_N | SREG_MASK_S | SREG_MASK_C; + m_r[SREG] |= SREG_MASK_N; + if (!BIT(rr, 7)) + m_r[SREG] |= SREG_MASK_V | SREG_MASK_C; else - m_r[SREG] |= SREG_MASK_N | SREG_MASK_S; + m_r[SREG] |= SREG_MASK_S; } - else if (BIT(rr, 7)) - m_r[SREG] |= SREG_MASK_V | SREG_MASK_S; + else if (pd == 0) + m_r[SREG] |= SREG_MASK_Z; m_r[24 + (DCONST(op) << 1)] = pd & 0x00ff; m_r[25 + (DCONST(op) << 1)] = (pd >> 8) & 0x00ff; } diff --git a/src/mame/homebrew/lft_phasor.cpp b/src/mame/homebrew/lft_phasor.cpp index 365ea9a0293..c6a4acc61f8 100644 --- a/src/mame/homebrew/lft_phasor.cpp +++ b/src/mame/homebrew/lft_phasor.cpp @@ -86,8 +86,8 @@ void lft_phasor_state::data_map(address_map &map) void lft_phasor_state::port_b_w(uint8_t data) { - m_gpio_b = data; video_update(); + m_gpio_b = data; } //************************************************************************** -- cgit v1.2.3