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

DEFINE_DEVICE_TYPE(OUTPUT_LATCH, output_latch_device, "output_latch", "Output Latch")

output_latch_device::output_latch_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, OUTPUT_LATCH, tag, owner, clock)
	, m_bit_handlers{ { *this }, { *this }, { *this }, { *this }, { *this }, { *this }, { *this }, { *this } }
	, m_bits{ -1, -1, -1, -1, -1, -1, -1, -1 }
{
}

void output_latch_device::device_resolve_objects()
{
	for (devcb_write_line &handler : m_bit_handlers)
		handler.resolve_safe();
}

void output_latch_device::device_start()
{
	save_item(NAME(m_bits));
}

void output_latch_device::write(uint8_t data)
{
	for (unsigned i = 0; 8 > i; ++i)
	{
		int const bit = BIT(data, i);
		if (bit != m_bits[i])
		{
			m_bits[i] = bit;
			if (!m_bit_handlers[i].isnull())
				m_bit_handlers[i](bit);
		}
	}
}