summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Luca Elia <lucaelia@mamedev.org>2018-01-21 22:47:21 +0100
committer Luca Elia <lucaelia@mamedev.org>2018-01-21 23:47:59 +0100
commit9eca0c6c45f43adedb6e7f20bf9b0b42f34ffb26 (patch)
treeb4f0581550f1d2bebfb075815e9f54450a985e7b
parentecffbfb247f11c291f53e6f576a9e117825487a1 (diff)
New device: SN54/74166 8-Bit Parallel-In/Serial-Out Shift Register [Dirk Best, Luca Elia]
-rw-r--r--scripts/src/machine.lua12
-rw-r--r--scripts/target/mame/arcade.lua1
-rw-r--r--src/devices/machine/74165.cpp126
-rw-r--r--src/devices/machine/74165.h91
4 files changed, 230 insertions, 0 deletions
diff --git a/scripts/src/machine.lua b/scripts/src/machine.lua
index fc1fa11d0fa..c59f39b69a6 100644
--- a/scripts/src/machine.lua
+++ b/scripts/src/machine.lua
@@ -397,6 +397,18 @@ end
---------------------------------------------------
--
+--@src/devices/machine/74165.h,MACHINES["TTL74165"] = true
+---------------------------------------------------
+
+if (MACHINES["TTL74165"]~=null) then
+ files {
+ MAME_DIR .. "src/devices/machine/74165.cpp",
+ MAME_DIR .. "src/devices/machine/74165.h",
+ }
+end
+
+---------------------------------------------------
+--
--@src/devices/machine/74166.h,MACHINES["TTL74166"] = true
---------------------------------------------------
diff --git a/scripts/target/mame/arcade.lua b/scripts/target/mame/arcade.lua
index 5d9b4cbccf9..891c98089df 100644
--- a/scripts/target/mame/arcade.lua
+++ b/scripts/target/mame/arcade.lua
@@ -374,6 +374,7 @@ MACHINES["TTL74153"] = true
MACHINES["TTL74157"] = true
--MACHINES["TTL74161"] = true
--MACHINES["TTL74164"] = true
+MACHINES["TTL74165"] = true
MACHINES["TTL74166"] = true
--MACHINES["TTL74175"] = true
MACHINES["TTL74181"] = true
diff --git a/src/devices/machine/74165.cpp b/src/devices/machine/74165.cpp
new file mode 100644
index 00000000000..d33033d5ab7
--- /dev/null
+++ b/src/devices/machine/74165.cpp
@@ -0,0 +1,126 @@
+// license: BSD-3-Clause
+// copyright-holders: Dirk Best, Luca Elia
+/***************************************************************************
+
+ SN54/74165
+
+ 8-Bit Parallel-In/Serial-Out Shift Register
+
+***************************************************************************/
+
+#include "emu.h"
+#include "74165.h"
+
+
+//**************************************************************************
+// DEVICE DEFINITIONS
+//**************************************************************************
+
+DEFINE_DEVICE_TYPE(TTL165, ttl165_device, "ttl165", "SN54/74165")
+
+//-------------------------------------------------
+// device_add_mconfig - add device configuration
+//-------------------------------------------------
+
+MACHINE_CONFIG_START(ttl165_device::device_add_mconfig)
+ MCFG_TIMER_DRIVER_ADD("timer", ttl165_device, qh_output)
+MACHINE_CONFIG_END
+
+
+//**************************************************************************
+// LIVE DEVICE
+//**************************************************************************
+
+//-------------------------------------------------
+// ttl153_device - constructor
+//-------------------------------------------------
+
+ttl165_device::ttl165_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
+ device_t(mconfig, TTL165, tag, owner, clock),
+ m_timer(*this, "timer"),
+ m_data_cb(*this), m_qh_cb(*this),
+ m_data(0x00),
+ m_ser(0), m_clk(0), m_shld(0)
+{
+}
+
+//-------------------------------------------------
+// device_start - device-specific startup
+//-------------------------------------------------
+
+void ttl165_device::device_start()
+{
+ // resolve callbacks
+ m_data_cb.resolve_safe(0x00);
+ m_qh_cb.resolve_safe();
+
+ // register for save states
+ save_item(NAME(m_data));
+ save_item(NAME(m_ser));
+ save_item(NAME(m_clk));
+ save_item(NAME(m_shld));
+}
+
+//-------------------------------------------------
+// device_reset - device-specific reset
+//-------------------------------------------------
+
+void ttl165_device::device_reset()
+{
+ m_data = 0x00;
+ m_ser = 0;
+ m_clk = 0;
+ m_shld = 0;
+}
+
+
+//**************************************************************************
+// IMPLEMENTATION
+//**************************************************************************
+
+TIMER_DEVICE_CALLBACK_MEMBER( ttl165_device::qh_output )
+{
+ m_qh_cb(param);
+}
+
+
+//**************************************************************************
+// INTERFACE
+//**************************************************************************
+
+WRITE_LINE_MEMBER( ttl165_device::serial_w )
+{
+ m_ser = state;
+}
+
+void ttl165_device::update_qh()
+{
+ // we need to delay the output a bit to allow for serial input
+ m_timer->adjust(attotime::from_nsec(25), BIT(m_data, 7));
+}
+
+WRITE_LINE_MEMBER( ttl165_device::clock_w )
+{
+ if (m_shld && !m_clk && state)
+ {
+ // shift next bit
+ m_data <<= 1;
+ m_data |= m_ser;
+
+ update_qh();
+ }
+
+ m_clk = state;
+}
+
+WRITE_LINE_MEMBER( ttl165_device::shift_load_w )
+{
+ if (!m_shld || !state)
+ {
+ // load external data
+ m_data = m_data_cb(0);
+
+ update_qh(); // FIXME: Qh should be updated continuosly while SH//LD is low
+ }
+ m_shld = state;
+}
diff --git a/src/devices/machine/74165.h b/src/devices/machine/74165.h
new file mode 100644
index 00000000000..4d3b7ed31de
--- /dev/null
+++ b/src/devices/machine/74165.h
@@ -0,0 +1,91 @@
+// license: BSD-3-Clause
+// copyright-holders: Dirk Best, Luca Elia
+/***************************************************************************
+
+ SN54/74165
+
+ 8-Bit Parallel-In/Serial-Out Shift Register
+
+ ___ ___
+ SH//LD 1 |* u | 16 VCC
+ CLK 2 | | 15 CLK INH
+ E 3 | | 14 D
+ F 4 | | 13 C
+ G 5 | | 12 B
+ H 6 | | 11 A
+ /QH 7 | | 10 SER
+ GND 8 |_______| 9 QH
+
+***************************************************************************/
+
+#ifndef MAME_DEVICES_MACHINE_74165_H
+#define MAME_DEVICES_MACHINE_74165_H
+
+#pragma once
+
+#include "machine/timer.h"
+
+
+//**************************************************************************
+// INTERFACE CONFIGURATION MACROS
+//**************************************************************************
+
+#define MCFG_TTL165_ADD(_tag) \
+ MCFG_DEVICE_ADD(_tag, TTL165, 0)
+
+#define MCFG_TTL165_DATA_CB(_devcb) \
+ devcb = &ttl165_device::set_data_callback(*device, DEVCB_##_devcb);
+
+#define MCFG_TTL165_QH_CB(_devcb) \
+ devcb = &ttl165_device::set_qh_callback(*device, DEVCB_##_devcb);
+
+
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
+
+class ttl165_device : public device_t
+{
+public:
+ // construction/destruction
+ ttl165_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+
+ // configuration
+ template <class Object> static devcb_base &set_data_callback(device_t &device, Object &&cb)
+ { return downcast<ttl165_device &>(device).m_data_cb.set_callback(std::forward<Object>(cb)); }
+
+ template <class Object> static devcb_base &set_qh_callback(device_t &device, Object &&cb)
+ { return downcast<ttl165_device &>(device).m_qh_cb.set_callback(std::forward<Object>(cb)); }
+
+ DECLARE_WRITE_LINE_MEMBER(serial_w);
+ DECLARE_WRITE_LINE_MEMBER(clock_w);
+ DECLARE_WRITE_LINE_MEMBER(shift_load_w);
+
+protected:
+ // device-level overrides
+ virtual void device_add_mconfig(machine_config &config) override;
+ virtual void device_start() override;
+ virtual void device_reset() override;
+
+private:
+ required_device<timer_device> m_timer;
+
+ // callbacks
+ devcb_read8 m_data_cb;
+ devcb_write_line m_qh_cb;
+
+ // state
+ uint8_t m_data;
+ int m_ser;
+ int m_clk;
+ int m_shld;
+
+ TIMER_DEVICE_CALLBACK_MEMBER(qh_output);
+ void update_qh();
+};
+
+
+// device type definition
+DECLARE_DEVICE_TYPE(TTL165, ttl165_device)
+
+#endif // MAME_DEVICES_MACHINE_74165_H