summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/output_latch.cpp
blob: 7ed407d68f88294edcbb6fc939c9df897026f3f8 (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
// 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)
	, m_bits{ -1, -1, -1, -1, -1, -1, -1, -1 }
{
}

void output_latch_device::device_resolve_objects()
{
	m_bit_handlers.resolve_all_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);
		}
	}
}