From 89d21d87d3a42f36a0dd125a0f6db04cefcc2fd6 Mon Sep 17 00:00:00 2001 From: angelosa Date: Tue, 27 Sep 2016 13:19:52 +0200 Subject: [PATCH 1/5] Opening up a new branch for sh7604 rewrite. --- src/devices/cpu/sh2/sh2comn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/cpu/sh2/sh2comn.cpp b/src/devices/cpu/sh2/sh2comn.cpp index 2fbeff0fa9d..b5d8e43aaa3 100644 --- a/src/devices/cpu/sh2/sh2comn.cpp +++ b/src/devices/cpu/sh2/sh2comn.cpp @@ -725,7 +725,7 @@ READ32_MEMBER( sh2_device::sh7604_r ) return (m_m[0x38] & 0x7fffffff) | (m_nmi_line_state == ASSERT_LINE ? 0 : 0x80000000); case 0x78: // BCR1 - return m_is_slave ? 0x00008000 : 0; + return (m_is_slave ? 0x00008000 : 0) | (m_m[0x78] & 0x7fff); case 0x41: // dvdntl mirrors case 0x47: From f6ad513ab0238fae93afe0d2e0d08a51b5e242ac Mon Sep 17 00:00:00 2001 From: angelosa Date: Tue, 27 Sep 2016 16:21:54 +0200 Subject: [PATCH 2/5] Written stub SH7604 BUS device (not hooked up to SH2 yet). --- scripts/src/cpu.lua | 2 + src/devices/cpu/sh2/sh7604_bus.cpp | 181 +++++++++++++++++++++++++++++ src/devices/cpu/sh2/sh7604_bus.h | 87 ++++++++++++++ src/mame/etc/template_device.cpp | 10 +- src/mame/etc/template_device.h | 6 +- 5 files changed, 274 insertions(+), 12 deletions(-) create mode 100644 src/devices/cpu/sh2/sh7604_bus.cpp create mode 100644 src/devices/cpu/sh2/sh7604_bus.h diff --git a/scripts/src/cpu.lua b/scripts/src/cpu.lua index a9dfe0ecd70..9c81a05051c 100644 --- a/scripts/src/cpu.lua +++ b/scripts/src/cpu.lua @@ -646,6 +646,8 @@ if (CPUS["SH2"]~=null) then MAME_DIR .. "src/devices/cpu/sh2/sh2.cpp", MAME_DIR .. "src/devices/cpu/sh2/sh2.h", MAME_DIR .. "src/devices/cpu/sh2/sh2fe.cpp", + MAME_DIR .. "src/devices/cpu/sh2/sh7604_bus.cpp", + MAME_DIR .. "src/devices/cpu/sh2/sh7604_bus.h", --MAME_DIR .. "src/devices/cpu/sh2/sh2comn.cpp", --MAME_DIR .. "src/devices/cpu/sh2/sh2comn.h", --MAME_DIR .. "src/devices/cpu/sh2/sh2drc.cpp", diff --git a/src/devices/cpu/sh2/sh7604_bus.cpp b/src/devices/cpu/sh2/sh7604_bus.cpp new file mode 100644 index 00000000000..47c7cdccefd --- /dev/null +++ b/src/devices/cpu/sh2/sh7604_bus.cpp @@ -0,0 +1,181 @@ +// license:BSD-3-Clause +// copyright-holders:Angelo Salese +/*************************************************************************** + + SH7604 BUS Controller + + Lies at 0xffffffe0-0xffffffff + + + + TODO: + - Host CPU setter (is_slave and clock are needed); + - timer clock emulation; + - fix fatalerrors; + - bus control stuff, someday; + +***************************************************************************/ + +#include "emu.h" +#include "sh7604_bus.h" + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// device type definition +const device_type SH7604_BUS = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +READ16_MEMBER(sh7604_bus_device::bus_control_1_r) +{ + return (m_bcr1 & 0x1ff7) | (m_is_slave == true ? 0x8000 : 0); +} + +WRITE16_MEMBER(sh7604_bus_device::bus_control_1_w) +{ + COMBINE_DATA(&m_bcr1); + if(m_bcr1 & 0x1000) // ENDIAN + throw emu_fatalerror("%s: enabled little endian for Area 2\n", tag()); + if(m_bcr1 & 0x0800) // PSHR + throw emu_fatalerror("%s: enabled partial space share mode\n", tag()); +} + +READ16_MEMBER(sh7604_bus_device::bus_control_2_r) { return m_bcr2 & 0x00fc; } +WRITE16_MEMBER(sh7604_bus_device::bus_control_2_w) +{ + COMBINE_DATA(&m_bcr2); + if(m_bcr2 != 0x00fc) + throw emu_fatalerror("%s: unexpected bus size register set %04x\n", tag(),data); +} + +READ16_MEMBER(sh7604_bus_device::wait_control_r) { return m_wcr; } +WRITE16_MEMBER(sh7604_bus_device::wait_control_w) { COMBINE_DATA(&m_wcr); } + +READ16_MEMBER(sh7604_bus_device::memory_control_r) { return m_mcr & 0xfefc; } +WRITE16_MEMBER(sh7604_bus_device::memory_control_w) { COMBINE_DATA(&m_mcr); } + +READ16_MEMBER(sh7604_bus_device::refresh_timer_status_r) +{ + return m_rtcsr & 0x00f8; +} + +WRITE16_MEMBER(sh7604_bus_device::refresh_timer_control_w) +{ + COMBINE_DATA(&m_rtcsr); + + if(m_rtcsr & 0x40) + throw emu_fatalerror("%s: enabled timer irq register with clock setting = %02x\n",tag(),data & 0x38); +} + +READ16_MEMBER(sh7604_bus_device::refresh_timer_counter_r) +{ + throw emu_fatalerror("%s: reading timer counter!\n",tag()); + return 0; +} + +WRITE16_MEMBER(sh7604_bus_device::refresh_timer_counter_w) +{ + throw emu_fatalerror("%s: writing timer counter %04x\n",tag(),data); + //COMBINE_DATA(&m_rtcnt); +} + +READ16_MEMBER(sh7604_bus_device::refresh_timer_constant_r) +{ + return m_rtcor & 0xff; +} + +WRITE16_MEMBER(sh7604_bus_device::refresh_timer_constant_w) +{ + COMBINE_DATA(&m_rtcor); +} + +static ADDRESS_MAP_START( bus_regs, AS_0, 16, sh7604_bus_device ) + AM_RANGE(0x00, 0x01) AM_READWRITE(bus_control_1_r, bus_control_1_w) + AM_RANGE(0x02, 0x03) AM_READWRITE(bus_control_2_r, bus_control_2_w) + AM_RANGE(0x04, 0x05) AM_READWRITE(wait_control_r, wait_control_w) + AM_RANGE(0x06, 0x07) AM_READWRITE(memory_control_r, memory_control_w) + AM_RANGE(0x08, 0x09) AM_READWRITE(refresh_timer_status_r, refresh_timer_control_w) + AM_RANGE(0x0a, 0x0b) AM_READWRITE(refresh_timer_counter_r, refresh_timer_counter_w) + AM_RANGE(0x0c, 0x0d) AM_READWRITE(refresh_timer_constant_r, refresh_timer_constant_w) +// AM_RANGE(0x0e, 0x0f) unmapped, mirror? +ADDRESS_MAP_END + +//------------------------------------------------- +// sh7604_bus_device - constructor +//------------------------------------------------- + +sh7604_bus_device::sh7604_bus_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, SH7604_BUS, "sh7604_bus_longname", tag, owner, clock, "sh7604_bus", __FILE__), + device_memory_interface(mconfig, *this), + m_space_config("regs", ENDIANNESS_BIG, 16, 4, 0, nullptr, *ADDRESS_MAP_NAME(bus_regs)) +{ +} + + +const address_space_config *sh7604_bus_device::memory_space_config(address_spacenum spacenum) const +{ + return (spacenum == AS_0) ? &m_space_config : nullptr; +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void sh7604_bus_device::device_start() +{ +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void sh7604_bus_device::device_reset() +{ + m_bcr1 = 0x03f0; + m_bcr2 = 0x00fc; + m_wcr = 0xaaff; + m_mcr = 0x0000; + m_rtcsr = 0x0000; + m_rtcor = 0x0000; +} + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +inline void sh7604_bus_device::writeword(offs_t address, UINT16 data) +{ + space().write_word(address, data); +} + +inline UINT16 sh7604_bus_device::readword(offs_t address) +{ + return space().read_word(address); +} + +READ32_MEMBER( sh7604_bus_device::read ) +{ + // 16 bit access only, TODO + return readword(offset); +} + +WRITE32_MEMBER( sh7604_bus_device::write ) +{ + // TODO: 8 bit access is invalid + // if accessing bits 16-31, one must write ID = 0xa55a + if(ACCESSING_BITS_16_31) + { + // throw fatalerror if something trips it, presumably the write is going to be ignored + if((data & 0xffff0000) != 0xa55a0000) + throw emu_fatalerror("%s: making bus write with ID signature = %04x!\n", tag(),data >> 16); + } + + writeword(offset,data & 0xffff); +} diff --git a/src/devices/cpu/sh2/sh7604_bus.h b/src/devices/cpu/sh2/sh7604_bus.h new file mode 100644 index 00000000000..cd97e9064c6 --- /dev/null +++ b/src/devices/cpu/sh2/sh7604_bus.h @@ -0,0 +1,87 @@ +// license:BSD-3-Clause +// copyright-holders: +/*************************************************************************** + +Template for skeleton device + +***************************************************************************/ + +#pragma once + +#ifndef __SH7604_BUSDEV_H__ +#define __SH7604_BUSDEV_H__ + + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_SH7604_BUS_ADD(_tag,_freq) \ + MCFG_DEVICE_ADD(_tag, SH7604_BUS, _freq) + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> sh7604_bus_device + +class sh7604_bus_device : public device_t, + public device_memory_interface +{ +public: + // construction/destruction + sh7604_bus_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // I/O operations + DECLARE_WRITE32_MEMBER( write ); + DECLARE_READ32_MEMBER( read ); + DECLARE_READ16_MEMBER( bus_control_1_r ); + DECLARE_WRITE16_MEMBER( bus_control_1_w ); + DECLARE_READ16_MEMBER( bus_control_2_r ); + DECLARE_WRITE16_MEMBER( bus_control_2_w ); + DECLARE_READ16_MEMBER( wait_control_r ); + DECLARE_WRITE16_MEMBER( wait_control_w ); + DECLARE_READ16_MEMBER( memory_control_r ); + DECLARE_WRITE16_MEMBER( memory_control_w ); + DECLARE_READ16_MEMBER( refresh_timer_status_r ); + DECLARE_WRITE16_MEMBER( refresh_timer_control_w ); + DECLARE_READ16_MEMBER( refresh_timer_counter_r ); + DECLARE_WRITE16_MEMBER( refresh_timer_counter_w ); + DECLARE_READ16_MEMBER( refresh_timer_constant_r ); + DECLARE_WRITE16_MEMBER( refresh_timer_constant_w ); + virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override; + +protected: + // device-level overrides + //virtual void device_validity_check(validity_checker &valid) const; + virtual void device_start() override; + virtual void device_reset() override; + +private: + bool m_is_slave; + const address_space_config m_space_config; + void writeword(offs_t address, UINT16 data); + UINT16 readword(offs_t address); + + UINT16 m_bcr1; + UINT16 m_bcr2; + UINT16 m_wcr; + UINT16 m_mcr; + UINT16 m_rtcsr; + UINT16 m_rtcor; +}; + + +// device type definition +extern const device_type SH7604_BUS; + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + + + +#endif diff --git a/src/mame/etc/template_device.cpp b/src/mame/etc/template_device.cpp index 2e325d909d3..903a2c63c73 100644 --- a/src/mame/etc/template_device.cpp +++ b/src/mame/etc/template_device.cpp @@ -7,7 +7,7 @@ Template for skeleton device ***************************************************************************/ #include "emu.h" -#include "machine/xxx.h" +#include "xxx.h" @@ -33,14 +33,6 @@ xxx_device::xxx_device(const machine_config &mconfig, const char *tag, device_t } -//------------------------------------------------- -// device_validity_check - perform validity checks -// on this device -//------------------------------------------------- - -void xxx_device::device_validity_check(validity_checker &valid) const -{ -} //------------------------------------------------- diff --git a/src/mame/etc/template_device.h b/src/mame/etc/template_device.h index 2173165181c..748e7e34e46 100644 --- a/src/mame/etc/template_device.h +++ b/src/mame/etc/template_device.h @@ -38,9 +38,9 @@ public: protected: // device-level overrides - virtual void device_validity_check(validity_checker &valid) const; - virtual void device_start(); - virtual void device_reset(); +// virtual void device_validity_check(validity_checker &valid) const; + virtual void device_start() override; + virtual void device_reset() override; }; From 1c12f1f20d077c7c8536744c3bd30ccab4aecd42 Mon Sep 17 00:00:00 2001 From: angelosa Date: Tue, 27 Sep 2016 16:53:38 +0200 Subject: [PATCH 3/5] Don't need a trampoline for these and added bare-bones SCI --- src/devices/cpu/sh2/sh7604_bus.cpp | 14 +----- src/devices/cpu/sh2/sh7604_bus.h | 2 - src/devices/cpu/sh2/sh7604_sci.cpp | 78 ++++++++++++++++++++++++++++++ src/devices/cpu/sh2/sh7604_sci.h | 62 ++++++++++++++++++++++++ 4 files changed, 142 insertions(+), 14 deletions(-) create mode 100644 src/devices/cpu/sh2/sh7604_sci.cpp create mode 100644 src/devices/cpu/sh2/sh7604_sci.h diff --git a/src/devices/cpu/sh2/sh7604_bus.cpp b/src/devices/cpu/sh2/sh7604_bus.cpp index 47c7cdccefd..70705931d7f 100644 --- a/src/devices/cpu/sh2/sh7604_bus.cpp +++ b/src/devices/cpu/sh2/sh7604_bus.cpp @@ -150,20 +150,10 @@ void sh7604_bus_device::device_reset() // READ/WRITE HANDLERS //************************************************************************** -inline void sh7604_bus_device::writeword(offs_t address, UINT16 data) -{ - space().write_word(address, data); -} - -inline UINT16 sh7604_bus_device::readword(offs_t address) -{ - return space().read_word(address); -} - READ32_MEMBER( sh7604_bus_device::read ) { // 16 bit access only, TODO - return readword(offset); + return space.read_word(offset) & 0xffff; } WRITE32_MEMBER( sh7604_bus_device::write ) @@ -177,5 +167,5 @@ WRITE32_MEMBER( sh7604_bus_device::write ) throw emu_fatalerror("%s: making bus write with ID signature = %04x!\n", tag(),data >> 16); } - writeword(offset,data & 0xffff); + space.write_word(offset,data & 0xffff); } diff --git a/src/devices/cpu/sh2/sh7604_bus.h b/src/devices/cpu/sh2/sh7604_bus.h index cd97e9064c6..b663b4ee4de 100644 --- a/src/devices/cpu/sh2/sh7604_bus.h +++ b/src/devices/cpu/sh2/sh7604_bus.h @@ -61,8 +61,6 @@ protected: private: bool m_is_slave; const address_space_config m_space_config; - void writeword(offs_t address, UINT16 data); - UINT16 readword(offs_t address); UINT16 m_bcr1; UINT16 m_bcr2; diff --git a/src/devices/cpu/sh2/sh7604_sci.cpp b/src/devices/cpu/sh2/sh7604_sci.cpp new file mode 100644 index 00000000000..b341c88f509 --- /dev/null +++ b/src/devices/cpu/sh2/sh7604_sci.cpp @@ -0,0 +1,78 @@ +// license:BSD-3-Clause +// copyright-holders: +/*************************************************************************** + +Template for skeleton device + +***************************************************************************/ + +#include "emu.h" +#include "sh7604_sci.h" + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// device type definition +const device_type SH7604_SCI = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +static ADDRESS_MAP_START( sci_regs, AS_0, 8, sh7604_sci_device ) + +ADDRESS_MAP_END + +//------------------------------------------------- +// sh7604_sci_device - constructor +//------------------------------------------------- + +sh7604_sci_device::sh7604_sci_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, SH7604_SCI, "sh7604_sci_longname", tag, owner, clock, "sh7604_sci", __FILE__), + device_memory_interface(mconfig, *this), + m_space_config("regs", ENDIANNESS_BIG, 8, 4, 0, nullptr, *ADDRESS_MAP_NAME(sci_regs)) + +{ +} + + +const address_space_config *sh7604_sci_device::memory_space_config(address_spacenum spacenum) const +{ + return (spacenum == AS_0) ? &m_space_config : nullptr; +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void sh7604_sci_device::device_start() +{ +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void sh7604_sci_device::device_reset() +{ +} + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +READ8_MEMBER( sh7604_sci_device::read ) +{ + return space.read_byte(offset); +} + +WRITE8_MEMBER( sh7604_sci_device::write ) +{ + space.write_byte(offset,data); +} diff --git a/src/devices/cpu/sh2/sh7604_sci.h b/src/devices/cpu/sh2/sh7604_sci.h new file mode 100644 index 00000000000..a666d5c64e4 --- /dev/null +++ b/src/devices/cpu/sh2/sh7604_sci.h @@ -0,0 +1,62 @@ +// license:BSD-3-Clause +// copyright-holders: +/*************************************************************************** + +Template for skeleton device + +***************************************************************************/ + +#pragma once + +#ifndef __SH7604_SCIDEV_H__ +#define __SH7604_SCIDEV_H__ + + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_SH7604_SCI_ADD(_tag,_freq) \ + MCFG_DEVICE_ADD(_tag, SH7604_SCI, _freq) + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> sh7604_sci_device + +class sh7604_sci_device : public device_t, + public device_memory_interface +{ +public: + // construction/destruction + sh7604_sci_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // I/O operations + DECLARE_WRITE8_MEMBER( write ); + DECLARE_READ8_MEMBER( read ); + + virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override; +protected: + // device-level overrides +// virtual void device_validity_check(validity_checker &valid) const; + virtual void device_start() override; + virtual void device_reset() override; +private: + const address_space_config m_space_config; +}; + + +// device type definition +extern const device_type SH7604_SCI; + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + + + +#endif From c8b7b13ca5a9eecb6d0dd1c7b1653eb8266a4d54 Mon Sep 17 00:00:00 2001 From: angelosa Date: Tue, 27 Sep 2016 17:41:24 +0200 Subject: [PATCH 4/5] More meat to SCI --- src/devices/cpu/sh2/sh7604_bus.cpp | 1 - src/devices/cpu/sh2/sh7604_bus.h | 4 +- src/devices/cpu/sh2/sh7604_sci.cpp | 91 +++++++++++++++++++++++++++++- src/devices/cpu/sh2/sh7604_sci.h | 32 ++++++++++- 4 files changed, 120 insertions(+), 8 deletions(-) diff --git a/src/devices/cpu/sh2/sh7604_bus.cpp b/src/devices/cpu/sh2/sh7604_bus.cpp index 70705931d7f..19b0df01740 100644 --- a/src/devices/cpu/sh2/sh7604_bus.cpp +++ b/src/devices/cpu/sh2/sh7604_bus.cpp @@ -5,7 +5,6 @@ SH7604 BUS Controller Lies at 0xffffffe0-0xffffffff - TODO: diff --git a/src/devices/cpu/sh2/sh7604_bus.h b/src/devices/cpu/sh2/sh7604_bus.h index b663b4ee4de..df796fa371f 100644 --- a/src/devices/cpu/sh2/sh7604_bus.h +++ b/src/devices/cpu/sh2/sh7604_bus.h @@ -1,8 +1,8 @@ // license:BSD-3-Clause -// copyright-holders: +// copyright-holders:Angelo Salese /*************************************************************************** -Template for skeleton device + SH7604 BUS Controller ***************************************************************************/ diff --git a/src/devices/cpu/sh2/sh7604_sci.cpp b/src/devices/cpu/sh2/sh7604_sci.cpp index b341c88f509..21b06b7bc7c 100644 --- a/src/devices/cpu/sh2/sh7604_sci.cpp +++ b/src/devices/cpu/sh2/sh7604_sci.cpp @@ -1,8 +1,14 @@ // license:BSD-3-Clause -// copyright-holders: +// copyright-holders:Angelo Salese /*************************************************************************** -Template for skeleton device + SH7604 SCI Controller + + Lies at 0xfffffe00-0xfffffe0f + + TODO: + - diserial; + - CPU callbacks for RX and TX; ***************************************************************************/ @@ -23,8 +29,83 @@ const device_type SH7604_SCI = &device_creator; // LIVE DEVICE //************************************************************************** -static ADDRESS_MAP_START( sci_regs, AS_0, 8, sh7604_sci_device ) +READ8_MEMBER(sh7604_sci_device::serial_mode_r) +{ + return m_smr; +} +WRITE8_MEMBER(sh7604_sci_device::serial_mode_w) +{ + m_smr = data; + + logerror("%s: serial mode set:\n",tag()); + logerror("\tCommunication Mode: %s mode\n",data & 0x80 ? "clocked synchronous" : "asynchronous"); + logerror("\tCharacter Length: %s mode\n",data & 0x40 ? "7-bit" : "8-bit"); + logerror("\tParity Enable: %s\n",data & 0x20 ? "yes" : "no"); + logerror("\tParity Mode: %s\n",data & 0x10 ? "Odd" : "Even"); + logerror("\tStop bits: %s\n",data & 0x08 ? "2" : "1"); + logerror("\tMultiprocessor mode: %s\n",data & 0x04 ? "yes" : "no"); + logerror("\tClock select: clock/%d\n",4 << ((data & 0x03)*2)); +} + +READ8_MEMBER(sh7604_sci_device::serial_control_r) +{ + return m_scr; +} + +WRITE8_MEMBER(sh7604_sci_device::serial_control_w) +{ + m_scr = data; + + if(data & 0x30) + throw emu_fatalerror("%s: enabled serial control %02x\n", tag(),data); +} + +READ8_MEMBER(sh7604_sci_device::serial_status_r) +{ + return m_ssr; +} + +WRITE8_MEMBER(sh7604_sci_device::serial_ack_w) +{ + // TODO: verify this + m_ssr = (m_ssr & 0x06) | (m_ssr & data & 0xf9); +} + +READ8_MEMBER(sh7604_sci_device::bitrate_r ) +{ + return m_brr; +} + +WRITE8_MEMBER(sh7604_sci_device::bitrate_w ) +{ + m_brr = data; +} + +READ8_MEMBER(sh7604_sci_device::transmit_data_r) +{ + // ... + return 0; +} + +WRITE8_MEMBER(sh7604_sci_device::transmit_data_w) +{ + // ... +} + +READ8_MEMBER(sh7604_sci_device::receive_data_r) +{ + // ... + return 0; +} + +static ADDRESS_MAP_START( sci_regs, AS_0, 8, sh7604_sci_device ) + AM_RANGE(0x00, 0x00) AM_READWRITE(serial_mode_r, serial_mode_w) + AM_RANGE(0x01, 0x01) AM_READWRITE(bitrate_r, bitrate_w) + AM_RANGE(0x02, 0x02) AM_READWRITE(serial_control_r,serial_control_w) + AM_RANGE(0x03, 0x03) AM_READWRITE(transmit_data_r, transmit_data_w) + AM_RANGE(0x04, 0x04) AM_READWRITE(serial_status_r, serial_ack_w) + AM_RANGE(0x05, 0x05) AM_READ(receive_data_r) ADDRESS_MAP_END //------------------------------------------------- @@ -60,6 +141,10 @@ void sh7604_sci_device::device_start() void sh7604_sci_device::device_reset() { + m_smr = 0; + m_scr = 0; + m_ssr = STATUS_TDRE|STATUS_TEND; //0x84; + m_brr = 0xff; } diff --git a/src/devices/cpu/sh2/sh7604_sci.h b/src/devices/cpu/sh2/sh7604_sci.h index a666d5c64e4..66e364f0cfe 100644 --- a/src/devices/cpu/sh2/sh7604_sci.h +++ b/src/devices/cpu/sh2/sh7604_sci.h @@ -1,8 +1,8 @@ // license:BSD-3-Clause -// copyright-holders: +// copyright-holders:Angelo Salese /*************************************************************************** -Template for skeleton device + SH7604 SCI Controller ***************************************************************************/ @@ -11,6 +11,17 @@ Template for skeleton device #ifndef __SH7604_SCIDEV_H__ #define __SH7604_SCIDEV_H__ +enum { + STATUS_MPBT = 1 << 0, + STATUS_MPB = 1 << 1, + STATUS_TEND = 1 << 2, + STATUS_PER = 1 << 3, + STATUS_FER = 1 << 4, + STATUS_ORER = 1 << 5, + STATUS_RDRF = 1 << 6, + STATUS_TDRE = 1 << 7 +}; + //************************************************************************** @@ -36,6 +47,19 @@ public: // I/O operations DECLARE_WRITE8_MEMBER( write ); DECLARE_READ8_MEMBER( read ); + + DECLARE_READ8_MEMBER( serial_mode_r ); + DECLARE_WRITE8_MEMBER( serial_mode_w ); + DECLARE_READ8_MEMBER( bitrate_r ); + DECLARE_WRITE8_MEMBER( bitrate_w ); + DECLARE_READ8_MEMBER( serial_control_r ); + DECLARE_WRITE8_MEMBER( serial_control_w ); + + DECLARE_READ8_MEMBER( transmit_data_r ); + DECLARE_WRITE8_MEMBER( transmit_data_w ); + DECLARE_READ8_MEMBER( serial_status_r ); + DECLARE_WRITE8_MEMBER( serial_ack_w ); + DECLARE_READ8_MEMBER( receive_data_r ); virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override; protected: @@ -45,6 +69,10 @@ protected: virtual void device_reset() override; private: const address_space_config m_space_config; + UINT8 m_smr; + UINT8 m_scr; + UINT8 m_ssr; + UINT8 m_brr; }; From f4749d03f7f65cabde47aa8b62cd5776cf3b0140 Mon Sep 17 00:00:00 2001 From: angelosa Date: Tue, 27 Sep 2016 18:36:59 +0200 Subject: [PATCH 5/5] Base WatchDog Timer device --- scripts/src/cpu.lua | 4 ++ src/devices/cpu/sh2/sh7604_wdt.cpp | 86 ++++++++++++++++++++++++++++++ src/devices/cpu/sh2/sh7604_wdt.h | 62 +++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 src/devices/cpu/sh2/sh7604_wdt.cpp create mode 100644 src/devices/cpu/sh2/sh7604_wdt.h diff --git a/scripts/src/cpu.lua b/scripts/src/cpu.lua index 9c81a05051c..315412fb946 100644 --- a/scripts/src/cpu.lua +++ b/scripts/src/cpu.lua @@ -648,6 +648,10 @@ if (CPUS["SH2"]~=null) then MAME_DIR .. "src/devices/cpu/sh2/sh2fe.cpp", MAME_DIR .. "src/devices/cpu/sh2/sh7604_bus.cpp", MAME_DIR .. "src/devices/cpu/sh2/sh7604_bus.h", + MAME_DIR .. "src/devices/cpu/sh2/sh7604_sci.cpp", + MAME_DIR .. "src/devices/cpu/sh2/sh7604_sci.h", + MAME_DIR .. "src/devices/cpu/sh2/sh7604_wdt.cpp", + MAME_DIR .. "src/devices/cpu/sh2/sh7604_wdt.h", --MAME_DIR .. "src/devices/cpu/sh2/sh2comn.cpp", --MAME_DIR .. "src/devices/cpu/sh2/sh2comn.h", --MAME_DIR .. "src/devices/cpu/sh2/sh2drc.cpp", diff --git a/src/devices/cpu/sh2/sh7604_wdt.cpp b/src/devices/cpu/sh2/sh7604_wdt.cpp new file mode 100644 index 00000000000..722a7d59db2 --- /dev/null +++ b/src/devices/cpu/sh2/sh7604_wdt.cpp @@ -0,0 +1,86 @@ +// license:BSD-3-Clause +// copyright-holders:Angelo Salese +/*************************************************************************** + + SH7604 Watchdog Timer Controller + + TODO: + - Host CPU setter (clock and callback for irq and reset lines); + - memory map (needs to verify if ID write is ok); + +***************************************************************************/ + +#include "emu.h" +#include "sh7604_wdt.h" + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// device type definition +const device_type SH7604_WDT = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +static ADDRESS_MAP_START( wdt_regs, AS_0, 8, sh7604_wdt_device ) +// AM_RANGE(0x00, 0x00) timer control/status +// AM_RANGE(0x01, 0x01) timer counter +// AM_RANGE(0x02, 0x02) write only, reset control register +// AM_RANGE(0x03, 0x03) read status register, write reset status register +ADDRESS_MAP_END + +//------------------------------------------------- +// sh7604_wdt_device - constructor +//------------------------------------------------- + +sh7604_wdt_device::sh7604_wdt_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, SH7604_WDT, "sh7604_wdt_longname", tag, owner, clock, "sh7604_wdt", __FILE__), + device_memory_interface(mconfig, *this), + m_space_config("regs", ENDIANNESS_BIG, 8, 4, 0, nullptr, *ADDRESS_MAP_NAME(wdt_regs)) + +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void sh7604_wdt_device::device_start() +{ +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void sh7604_wdt_device::device_reset() +{ +} + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +READ8_MEMBER( sh7604_wdt_device::read ) +{ + return space.read_byte(offset); +} + +WRITE16_MEMBER( sh7604_wdt_device::write ) +{ + UINT8 id_param = data >> 8; + switch(id_param) + { + case 0xa5: space.write_byte(offset*2+0,data & 0xff); break; + case 0x5a: space.write_byte(offset*2+1,data & 0xff); break; + default: throw emu_fatalerror("%s: invalid id param write = %02x\n",tag(),id_param); + } +} diff --git a/src/devices/cpu/sh2/sh7604_wdt.h b/src/devices/cpu/sh2/sh7604_wdt.h new file mode 100644 index 00000000000..e9d69f00227 --- /dev/null +++ b/src/devices/cpu/sh2/sh7604_wdt.h @@ -0,0 +1,62 @@ +// license:BSD-3-Clause +// copyright-holders:Angelo Salese +/*************************************************************************** + + SH7604 Watchdog Timer Controller + +***************************************************************************/ + +#pragma once + +#ifndef __SH7604_WDTDEV_H__ +#define __SH7604_WDTDEV_H__ + + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_SH7604_WDT_ADD(_tag,_freq) \ + MCFG_DEVICE_ADD(_tag, SH7604_WDT, _freq) + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> sh7604_wdt_device + +class sh7604_wdt_device : public device_t, + public device_memory_interface +{ +public: + // construction/destruction + sh7604_wdt_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // I/O operations + DECLARE_WRITE16_MEMBER( write ); + DECLARE_READ8_MEMBER( read ); + + virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override; +protected: + // device-level overrides +// virtual void device_validity_check(validity_checker &valid) const; + virtual void device_start() override; + virtual void device_reset() override; +private: + const address_space_config m_space_config; +}; + + +// device type definition +extern const device_type SH7604_WDT; + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + + + +#endif