summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/74165.cpp
blob: 9ba4415d56ca8d1c399d9d5c7b91cd7839580317 (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
124
125
126
127
// 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
//-------------------------------------------------

void ttl165_device::device_add_mconfig(machine_config &config)
{
	TIMER(config, m_timer).configure_generic(FUNC(ttl165_device::qh_output));
}


//**************************************************************************
//  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;
}