From 5244513210c725793077e5e9b7f32d9265a60146 Mon Sep 17 00:00:00 2001 From: hap Date: Thu, 8 Feb 2024 14:35:00 +0100 Subject: h8/325: add md pins callback, h8: fix V flag with INC opcodes --- src/devices/cpu/h8/h8.cpp | 16 +++++----------- src/devices/cpu/h8/h8325.cpp | 16 ++++++++++++++-- src/devices/cpu/h8/h8325.h | 7 +++++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/devices/cpu/h8/h8.cpp b/src/devices/cpu/h8/h8.cpp index 338023eab12..608e1627bfb 100644 --- a/src/devices/cpu/h8/h8.cpp +++ b/src/devices/cpu/h8/h8.cpp @@ -530,7 +530,6 @@ uint8_t h8_device::do_addx8(uint8_t v1, uint8_t v2) if(res & 0x100) m_CCR |= F_C; return res; - } uint8_t h8_device::do_subx8(uint8_t v1, uint8_t v2) @@ -552,7 +551,6 @@ uint8_t h8_device::do_subx8(uint8_t v1, uint8_t v2) if(res & 0x100) m_CCR |= F_C; return res; - } uint8_t h8_device::do_inc8(uint8_t v1, uint8_t v2) @@ -563,7 +561,7 @@ uint8_t h8_device::do_inc8(uint8_t v1, uint8_t v2) m_CCR |= F_Z; else if(int8_t(res) < 0) m_CCR |= F_N; - if((v1^v2) & (v1^res) & 0x80) + if(~(v1^v2) & (v1^res) & 0x80) m_CCR |= F_V; return res; } @@ -576,7 +574,7 @@ uint16_t h8_device::do_inc16(uint16_t v1, uint16_t v2) m_CCR |= F_Z; else if(int16_t(res) < 0) m_CCR |= F_N; - if((v1^v2) & (v1^res) & 0x8000) + if(~(v1^v2) & (v1^res) & 0x8000) m_CCR |= F_V; return res; } @@ -589,7 +587,7 @@ uint32_t h8_device::do_inc32(uint32_t v1, uint32_t v2) m_CCR |= F_Z; else if(int32_t(res) < 0) m_CCR |= F_N; - if((v1^v2) & (v1^res) & 0x80000000) + if(~(v1^v2) & (v1^res) & 0x80000000) m_CCR |= F_V; return res; } @@ -613,7 +611,6 @@ uint8_t h8_device::do_add8(uint8_t v1, uint8_t v2) if(res & 0x100) m_CCR |= F_C; return res; - } uint16_t h8_device::do_add16(uint16_t v1, uint16_t v2) @@ -635,7 +632,6 @@ uint16_t h8_device::do_add16(uint16_t v1, uint16_t v2) if(res & 0x10000) m_CCR |= F_C; return res; - } uint32_t h8_device::do_add32(uint32_t v1, uint32_t v2) @@ -654,7 +650,7 @@ uint32_t h8_device::do_add32(uint32_t v1, uint32_t v2) m_CCR |= F_N; if(~(v1^v2) & (v1^res) & 0x80000000) m_CCR |= F_V; - if(res & 0x100000000U) + if(res & 0x100000000ULL) m_CCR |= F_C; return res; } @@ -717,7 +713,6 @@ uint8_t h8_device::do_sub8(uint8_t v1, uint8_t v2) if(res & 0x100) m_CCR |= F_C; return res; - } uint16_t h8_device::do_sub16(uint16_t v1, uint16_t v2) @@ -739,7 +734,6 @@ uint16_t h8_device::do_sub16(uint16_t v1, uint16_t v2) if(res & 0x10000) m_CCR |= F_C; return res; - } uint32_t h8_device::do_sub32(uint32_t v1, uint32_t v2) @@ -758,7 +752,7 @@ uint32_t h8_device::do_sub32(uint32_t v1, uint32_t v2) m_CCR |= F_N; if((v1^v2) & (v1^res) & 0x80000000) m_CCR |= F_V; - if(res & 0x100000000U) + if(res & 0x100000000ULL) m_CCR |= F_C; return res; } diff --git a/src/devices/cpu/h8/h8325.cpp b/src/devices/cpu/h8/h8325.cpp index 28efafd6ce4..e2cc665405d 100644 --- a/src/devices/cpu/h8/h8325.cpp +++ b/src/devices/cpu/h8/h8325.cpp @@ -7,7 +7,12 @@ H8/325 family emulation TODO: - - serial controllers are slightly different + - nvram and standby emulation, but that's a thing for more H8 types? + - serial controllers are slightly different, has 3 interrupt sources + instead of 4 + - SYSCR register (RAM disable, NMI edge invert, standby) + - HCSR register @ 0xfffe (port 3 handshake) + - FNCR register @ 0xffff (16-bit timer noise canceler) ***************************************************************************/ @@ -36,7 +41,9 @@ h8325_device::h8325_device(const machine_config &mconfig, device_type type, cons m_timer8_1(*this, "timer8_1"), m_timer16(*this, "timer16"), m_timer16_0(*this, "timer16:0"), + m_read_md(*this, 3), m_syscr(0), + m_mds(0), m_ram_start(start) { } @@ -101,6 +108,7 @@ void h8325_device::map(address_map &map) map(0xffc5, 0xffc5).r(FUNC(h8325_device::mdcr_r)); map(0xffc6, 0xffc6).rw(m_intc, FUNC(h8_intc_device::iscr_r), FUNC(h8_intc_device::iscr_w)); map(0xffc7, 0xffc7).rw(m_intc, FUNC(h8_intc_device::ier_r), FUNC(h8_intc_device::ier_w)); + 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)); map(0xffca, 0xffcb).rw(m_timer8_0, FUNC(h8_timer8_channel_device::tcor_r), FUNC(h8_timer8_channel_device::tcor_w)); @@ -181,13 +189,17 @@ void h8325_device::internal_update(uint64_t current_time) void h8325_device::device_start() { h8_device::device_start(); + save_item(NAME(m_syscr)); + save_item(NAME(m_mds)); } void h8325_device::device_reset() { h8_device::device_reset(); + m_syscr = 0x01; + m_mds = m_read_md() & 3; } uint8_t h8325_device::syscr_r() @@ -205,5 +217,5 @@ uint8_t h8325_device::mdcr_r() { if(!machine().side_effects_disabled()) logerror("mdcr_r\n"); - return 0xe7; + return m_mds | 0xe4; } diff --git a/src/devices/cpu/h8/h8325.h b/src/devices/cpu/h8/h8325.h index 235d5a2838e..5c18b2e1cbf 100644 --- a/src/devices/cpu/h8/h8325.h +++ b/src/devices/cpu/h8/h8325.h @@ -34,6 +34,7 @@ class h8325_device : public h8_device { public: h8325_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + // I/O ports auto read_port1() { return m_read_port [PORT_1].bind(); } auto write_port1() { return m_write_port[PORT_1].bind(); } auto read_port2() { return m_read_port [PORT_2].bind(); } @@ -49,6 +50,9 @@ public: auto read_port7() { return m_read_port [PORT_7].bind(); } auto write_port7() { return m_write_port[PORT_7].bind(); } + // MD pins, default mode 3 (single chip) + auto read_md() { return m_read_md.bind(); } + uint8_t syscr_r(); void syscr_w(uint8_t data); uint8_t mdcr_r(); @@ -69,7 +73,10 @@ protected: required_device m_timer16; required_device m_timer16_0; + devcb_read8 m_read_md; + uint8_t m_syscr; + uint8_t m_mds; uint32_t m_ram_start; virtual void update_irq_filter() override; -- cgit v1.2.3