summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/40105.cpp
blob: 8364f5dbf5ddb79f69b1f1194a16a3c926467a0b (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    CMOS 40105 FIFO Register emulation

**********************************************************************/

#include "40105.h"



//**************************************************************************
//  MACROS / CONSTANTS
//**************************************************************************

#define LOG 0



//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

const device_type CMOS_40105 = &device_creator<cmos_40105_device>;



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  cmos_40105_device - constructor
//-------------------------------------------------

cmos_40105_device::cmos_40105_device(const machine_config &mconfig, std::string tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, CMOS_40105, "40105", tag, owner, clock, "40105", __FILE__),
		m_write_dir(*this),
		m_write_dor(*this), m_d(0), m_q(0), m_dir(0), m_dor(0), m_si(0), m_so(0)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void cmos_40105_device::device_start()
{
	// resolve callbacks
	m_write_dir.resolve_safe();
	m_write_dor.resolve_safe();

	// state saving
	save_item(NAME(m_d));
	save_item(NAME(m_q));
	save_item(NAME(m_dir));
	save_item(NAME(m_dor));
	save_item(NAME(m_si));
	save_item(NAME(m_so));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void cmos_40105_device::device_reset()
{
	m_fifo = std::queue<UINT8>();

	m_dir = 1;
	m_dor = 0;
	m_si = 0;

	m_write_dir(m_dir);
	m_write_dor(m_dor);
}


//-------------------------------------------------
//  read - read Q
//-------------------------------------------------

UINT8 cmos_40105_device::read()
{
	return m_q;
}


//-------------------------------------------------
//  write - write D
//-------------------------------------------------

void cmos_40105_device::write(UINT8 data)
{
	m_d = data & 0x0f;
}


//-------------------------------------------------
//  si_w - shift in write
//-------------------------------------------------

WRITE_LINE_MEMBER( cmos_40105_device::si_w )
{
	if (m_dir && !m_si && state)
	{
		m_fifo.push(m_d);

		if (m_fifo.size() == 16)
		{
			m_dir = 0;
			m_write_dir(m_dir);
		}

		if (!m_dor)
		{
			m_dor = 1;
			m_write_dor(m_dor);
		}

	}

	m_si = state;
}


//-------------------------------------------------
//  so_w - shift out write
//-------------------------------------------------

WRITE_LINE_MEMBER( cmos_40105_device::so_w )
{
	if (m_dor && m_so && !m_so)
	{
		m_dor = 0;
		m_write_dor(m_dor);

		m_q = m_fifo.front();
		m_fifo.pop();

		if (m_fifo.size() > 0)
		{
			m_dor = 1;
			m_write_dor(m_dor);
		}
	}

	m_so = state;
}


//-------------------------------------------------
//  dir_r - data in ready read
//-------------------------------------------------

READ_LINE_MEMBER( cmos_40105_device::dir_r )
{
	return m_dir;
}


//-------------------------------------------------
//  dor_r - data out ready read
//-------------------------------------------------

READ_LINE_MEMBER( cmos_40105_device::dor_r )
{
	return m_dor;
}