summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/devices/nld_74125.cpp
blob: d803b80d984d61ee7e4dae39137232d777b01419 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * nld_74125.cpp
 *
 */

#include "nld_74125.h"
#include "nl_base.h"

#include <type_traits>

namespace netlist
{
	template <typename T>
	struct uptr : public unique_pool_ptr<T>
	{
		uptr() = default;

		using base_type = unique_pool_ptr<T>;

		template<typename O, typename... Args>
		uptr(O &owner, const pstring &name, Args&&... args)
		: unique_pool_ptr<T>(owner.template make_pool_object<T>(owner, name, std::forward<Args>(args)...))
		{ }

		constexpr auto operator ()() noexcept -> decltype((*unique_pool_ptr<T>::get())()) { return (*this->get())(); }
		constexpr auto operator ()() const noexcept -> const decltype((*unique_pool_ptr<T>::get())()) { return (*this->get())(); }
	};

	namespace devices
	{

	template <typename D>
	NETLIB_OBJECT(74125_base)
	{
		NETLIB_CONSTRUCTOR(74125_base)
		, m_TE(*this, "FORCE_TRISTATE_LOGIC", 0)
		, m_A(*this, "A", NETLIB_DELEGATE(A))
		, m_G(*this, pstring(D::invert_g::value ? "GQ" : "G"), NETLIB_DELEGATE(G))
		, m_Y(*this, "Y", m_TE())
		//, m_Y(*this, "Y")
		, m_power_pins(*this)
		{
		}

	private:
		NETLIB_RESETI()
		{
		}

		NETLIB_UPDATEI()
		{
			// this one is only called during startup. Ensure all outputs
			// are in a consistent state.
			m_Y.set_tristate(m_G() ^ D::invert_g::value,
				D::ts_off_on::value(), D::ts_on_off::value());
			m_Y.push(m_A(), m_A() ? D::sig_off_on::value() : D::sig_on_off::value());
		}

		NETLIB_HANDLERI(A)
		{
			m_Y.push(m_A(), m_A() ? D::sig_off_on::value() : D::sig_on_off::value());
		}

		NETLIB_HANDLERI(G)
		{
			m_Y.set_tristate(m_G() ^ D::invert_g::value,
				D::ts_off_on::value(), D::ts_on_off::value());
		}

		param_logic_t      m_TE;
		logic_input_t      m_A;
		uptr<logic_input_t>      m_G;
		tristate_output_t  m_Y;
		nld_power_pins     m_power_pins;
	};

	struct desc_74125 : public desc_base
	{
		using invert_g = desc_const<1>;
		using ts_off_on = time_ns<11>;
		using ts_on_off = time_ns<13>;
		using sig_off_on = time_ns<8>;
		using sig_on_off = time_ns<12>;
	};

	struct desc_74126 : public desc_74125
	{
		using invert_g = desc_const<0>;
	};

	using NETLIB_NAME(74125) = NETLIB_NAME(74125_base)<desc_74125>;
	using NETLIB_NAME(74126) = NETLIB_NAME(74125_base)<desc_74126>;

	NETLIB_DEVICE_IMPL(74125,     "TTL_74125_GATE",     "")
	NETLIB_DEVICE_IMPL(74126,     "TTL_74126_GATE",     "")

	} //namespace devices
} // namespace netlist