summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/devices/nld_74194.cpp
blob: d531e792885da8a4c971660558a4fd57b1070089 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/*
 * nld_74194.cpp
 *
 */

#include "nld_74194.h"
#include "../nl_base.h"

namespace netlist
{
	namespace devices
	{
	NETLIB_OBJECT(74194)
	{
		NETLIB_CONSTRUCTOR(74194)
		, m_DATA(*this, {{"D", "C", "B", "A"}})
		, m_SLIN(*this, "SLIN")
		, m_SRIN(*this, "SRIN")
		, m_CLK(*this, "CLK")
		, m_S0(*this, "S0")
		, m_S1(*this, "S1")
		, m_CLRQ(*this, "CLRQ")
		, m_Q(*this, {{"QD", "QC", "QB", "QA"}})
		, m_last_CLK(*this, "m_last_CLK", 0)
		, m_last_Q(*this, "m_last_Q", 0)
		{
		}

		NETLIB_RESETI();
		NETLIB_UPDATEI();

	protected:
		object_array_t<logic_input_t, 4> m_DATA;
		logic_input_t m_SLIN;
		logic_input_t m_SRIN;
		logic_input_t m_CLK;
		logic_input_t m_S0;
		logic_input_t m_S1;
		logic_input_t m_CLRQ;
		object_array_t<logic_output_t, 4> m_Q;

		state_var<unsigned> m_last_CLK;
		state_var<unsigned> m_last_Q;
	};

	NETLIB_OBJECT_DERIVED(74194_dip, 74194)
	{
		NETLIB_CONSTRUCTOR_DERIVED(74194_dip, 74194)
		{
			register_subalias("1", m_CLRQ);
			register_subalias("2", m_SRIN);
			register_subalias("3", m_DATA[3]);
			register_subalias("4", m_DATA[2]);
			register_subalias("5", m_DATA[1]);
			register_subalias("6", m_DATA[0]);
			register_subalias("7", m_SLIN);

			register_subalias("9",  m_S0);
			register_subalias("10", m_S1);
			register_subalias("11", m_CLK);
			register_subalias("12", m_Q[0]);
			register_subalias("13", m_Q[1]);
			register_subalias("14", m_Q[2]);
			register_subalias("15", m_Q[3]);

		}
	};

	NETLIB_RESET(74194)
	{
		m_last_CLK = 0;
		m_last_Q = 0;
	}

	// FIXME: Timing
	NETLIB_UPDATE(74194)
	{
		unsigned q = m_last_Q;

		if (!m_CLRQ())
		{
			q = 0;
		}
		else
		{
			if (!m_last_CLK && m_CLK())
			{
				unsigned s = (m_S1() << 1) | m_S0();
				switch (s)
				{
					case 0: // LL: Keep old value
						break;
					case 1: // LH: Shift right
						q >>= 1;
						q |= m_SRIN() ? 8 : 0;
						break;
					case 2:
						q <<= 1;
						q |= m_SLIN() ? 1 : 0;
						break;
					case 3:
						q = 0;
						for (std::size_t i=0; i<4; i++)
							q |= m_DATA[i]() << i;
						break;
				}
			}
		}

		m_last_Q = q;
		m_last_CLK = m_CLK();

		for (std::size_t i=0; i<4; i++)
			m_Q[i].push((q >> i) & 1, NLTIME_FROM_NS(26)); // FIXME: Timing
	}

	NETLIB_DEVICE_IMPL(74194)
	NETLIB_DEVICE_IMPL(74194_dip)

	} //namespace devices
} // namespace netlist