summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/latch.cpp
blob: 8f70ff582abb223f4adeea95e7b60234fa8d2f79 (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
// license:BSD-3-Clause
// copyright-holders:smf
#include "emu.h"
#include "latch.h"

const device_type OUTPUT_LATCH = &device_creator<output_latch_device>;

output_latch_device::output_latch_device(const machine_config &mconfig, std::string tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, OUTPUT_LATCH, "Output Latch", tag, owner, clock, "output_latch", __FILE__),
	m_resolved(false),
	m_bit0(-1),
	m_bit1(-1),
	m_bit2(-1),
	m_bit3(-1),
	m_bit4(-1),
	m_bit5(-1),
	m_bit6(-1),
	m_bit7(-1),
	m_bit0_handler(*this),
	m_bit1_handler(*this),
	m_bit2_handler(*this),
	m_bit3_handler(*this),
	m_bit4_handler(*this),
	m_bit5_handler(*this),
	m_bit6_handler(*this),
	m_bit7_handler(*this)
{
}

void output_latch_device::device_start()
{
	save_item(NAME(m_bit0));
	save_item(NAME(m_bit1));
	save_item(NAME(m_bit2));
	save_item(NAME(m_bit3));
	save_item(NAME(m_bit4));
	save_item(NAME(m_bit5));
	save_item(NAME(m_bit6));
	save_item(NAME(m_bit7));
}

void output_latch_device::write(UINT8 data)
{
	if (!m_resolved)
	{
		// HACK: move to device_config_complete() when devcb supports that
		m_bit0_handler.resolve_safe();
		m_bit1_handler.resolve_safe();
		m_bit2_handler.resolve_safe();
		m_bit3_handler.resolve_safe();
		m_bit4_handler.resolve_safe();
		m_bit5_handler.resolve_safe();
		m_bit6_handler.resolve_safe();
		m_bit7_handler.resolve_safe();

		m_resolved = true;
	}

	int bit0 = (data >> 0) & 1;
	if (m_bit0 != bit0)
	{
		m_bit0 = bit0;
		if (!m_bit0_handler.isnull())
			m_bit0_handler(bit0);
	}

	int bit1 = (data >> 1) & 1;
	if (m_bit1 != bit1)
	{
		m_bit1 = bit1;
		if (!m_bit1_handler.isnull())
			m_bit1_handler(bit1);
	}

	int bit2 = (data >> 2) & 1;
	if (m_bit2 != bit2)
	{
		m_bit2 = bit2;
		if (!m_bit2_handler.isnull())
			m_bit2_handler(bit2);
	}

	int bit3 = (data >> 3) & 1;
	if (m_bit3 != bit3)
	{
		m_bit3 = bit3;
		if (!m_bit3_handler.isnull())
			m_bit3_handler(bit3);
	}

	int bit4 = (data >> 4) & 1;
	if (m_bit4 != bit4)
	{
		m_bit4 = bit4;
		if (!m_bit4_handler.isnull())
			m_bit4_handler(bit4);
	}

	int bit5 = (data >> 5) & 1;
	if (m_bit5 != bit5)
	{
		m_bit5 = bit5;
		if (!m_bit5_handler.isnull())
			m_bit5_handler(bit5);
	}

	int bit6 = (data >> 6) & 1;
	if (m_bit6 != bit6)
	{
		m_bit6 = bit6;
		if (!m_bit6_handler.isnull())
			m_bit6_handler(bit6);
	}

	int bit7 = (data >> 7) & 1;
	if (m_bit7 != bit7)
	{
		m_bit7 = bit7;
		if (!m_bit7_handler.isnull())
			m_bit7_handler(bit7);
	}
}