From 85c01f572160407cf3eea0e4744c8c41cff01314 Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Mon, 15 May 2017 23:23:03 +0200 Subject: [PATCH] New device: SN54/74166 8-Bit Parallel-In/Serial-Out Shift Register --- scripts/src/machine.lua | 12 ++++ src/devices/machine/74166.cpp | 128 ++++++++++++++++++++++++++++++++++ src/devices/machine/74166.h | 88 +++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 src/devices/machine/74166.cpp create mode 100644 src/devices/machine/74166.h diff --git a/scripts/src/machine.lua b/scripts/src/machine.lua index d38706a4e16..e52bb8e43bb 100644 --- a/scripts/src/machine.lua +++ b/scripts/src/machine.lua @@ -391,6 +391,18 @@ if (MACHINES["TTL74161"]~=null) then } end +--------------------------------------------------- +-- +--@src/devices/machine/74166.h,MACHINES["TTL74166"] = true +--------------------------------------------------- + +if (MACHINES["TTL74166"]~=null) then + files { + MAME_DIR .. "src/devices/machine/74166.cpp", + MAME_DIR .. "src/devices/machine/74166.h", + } +end + --------------------------------------------------- -- --@src/devices/machine/74175.h,MACHINES["TTL74175"] = true diff --git a/src/devices/machine/74166.cpp b/src/devices/machine/74166.cpp new file mode 100644 index 00000000000..3a793feda5b --- /dev/null +++ b/src/devices/machine/74166.cpp @@ -0,0 +1,128 @@ +// license: BSD-3-Clause +// copyright-holders: Dirk Best +/*************************************************************************** + + SN54/74166 + + 8-Bit Parallel-In/Serial-Out Shift Register + +***************************************************************************/ + +#include "emu.h" +#include "74166.h" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +DEFINE_DEVICE_TYPE(TTL166, ttl166_device, "ttl166", "SN54/74166") + +//------------------------------------------------- +// machine_config_additions - device-specific +// machine configurations +//------------------------------------------------- + +static MACHINE_CONFIG_FRAGMENT( ttl166 ) + MCFG_TIMER_DRIVER_ADD("timer", ttl166_device, qh_output) +MACHINE_CONFIG_END + +machine_config_constructor ttl166_device::device_mconfig_additions() const +{ + return MACHINE_CONFIG_NAME( ttl166 ); +} + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// ttl153_device - constructor +//------------------------------------------------- + +ttl166_device::ttl166_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : + device_t(mconfig, TTL166, 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 ttl166_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 ttl166_device::device_reset() +{ + m_data = 0x00; + m_ser = 0; + m_clk = 0; + m_shld = 0; +} + + +//************************************************************************** +// IMPLEMENTATION +//************************************************************************** + +TIMER_DEVICE_CALLBACK_MEMBER( ttl166_device::qh_output ) +{ + m_qh_cb(param); +} + + +//************************************************************************** +// INTERFACE +//************************************************************************** + +WRITE_LINE_MEMBER( ttl166_device::serial_w ) +{ + m_ser = state; +} + +WRITE_LINE_MEMBER( ttl166_device::clock_w ) +{ + if (m_clk == 0 && state == 1) + { + if (m_shld) + { + // shift next bit + m_data <<= 1; + m_data |= m_ser; + } + else + { + // load external data + m_data = m_data_cb(0); + } + + // we need to delay the output a bit to allow for serial input + m_timer->adjust(attotime::from_nsec(25), BIT(m_data, 7)); + } + + m_clk = state; +} + +WRITE_LINE_MEMBER( ttl166_device::shift_load_w ) +{ + m_shld = state; +} diff --git a/src/devices/machine/74166.h b/src/devices/machine/74166.h new file mode 100644 index 00000000000..605cfc77ac1 --- /dev/null +++ b/src/devices/machine/74166.h @@ -0,0 +1,88 @@ +// license: BSD-3-Clause +// copyright-holders: Dirk Best +/*************************************************************************** + + SN54/74166 + + 8-Bit Parallel-In/Serial-Out Shift Register + + ___ ___ + SER 1 |* u | 16 VCC + A 2 | | 15 SH//LD + B 3 | | 14 H + C 4 | | 13 QH + D 5 | | 12 G + CLK INH 6 | | 11 F + CLK 7 | | 10 E + GND 8 |_______| 9 /CLR + +***************************************************************************/ + +#ifndef MAME_DEVICES_MACHINE_74166_H +#define MAME_DEVICES_MACHINE_74166_H + +#pragma once + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_TTL166_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, TTL166, 0) + +#define MCFG_TTL166_DATA_CB(_devcb) \ + devcb = &ttl166_device::set_data_callback(*device, DEVCB_##_devcb); + +#define MCFG_TTL166_QH_CB(_devcb) \ + devcb = &ttl166_device::set_qh_callback(*device, DEVCB_##_devcb); + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +class ttl166_device : public device_t +{ +public: + // construction/destruction + ttl166_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + + // configuration + template static devcb_base &set_data_callback(device_t &device, Object &&cb) + { return downcast(device).m_data_cb.set_callback(std::forward(cb)); } + + template static devcb_base &set_qh_callback(device_t &device, Object &&cb) + { return downcast(device).m_qh_cb.set_callback(std::forward(cb)); } + + DECLARE_WRITE_LINE_MEMBER(serial_w); + DECLARE_WRITE_LINE_MEMBER(clock_w); + DECLARE_WRITE_LINE_MEMBER(shift_load_w); + + TIMER_DEVICE_CALLBACK_MEMBER(qh_output); + +protected: + // device-level overrides + virtual machine_config_constructor device_mconfig_additions() const override; + virtual void device_start() override; + virtual void device_reset() override; + +private: + required_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; +}; + + +// device type definition +DECLARE_DEVICE_TYPE(TTL166, ttl166_device) + +#endif // MAME_DEVICES_MACHINE_74166_H