Skip to content

Commit

Permalink
avr8: some registers were missing from addressmap,
Browse files Browse the repository at this point in the history
avr8: fix regression with C flag on SBIW opcode, fix V flag on DEC/SBIW opcodes
  • Loading branch information
happppp committed Mar 24, 2024
1 parent 639ec00 commit fbabb96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/devices/cpu/avr8/avr8.cpp
Expand Up @@ -566,6 +566,9 @@ void avr8_device<NumTimers>::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));
Expand Down
38 changes: 19 additions & 19 deletions src/devices/cpu/avr8/avr8ops.hxx
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -1135,21 +1133,20 @@ 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;
}

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;
}
Expand Down Expand Up @@ -1234,18 +1231,21 @@ 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))
m_r[SREG] |= SREG_MASK_V;
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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mame/homebrew/lft_phasor.cpp
Expand Up @@ -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;
}

//**************************************************************************
Expand Down

0 comments on commit fbabb96

Please sign in to comment.