summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/ti8x/teeconn.cpp
blob: ce2e4f2a35aac3a278d8336dff9618afe53c0886 (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
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
/*
 A T-connector, strangely enough.
 */

#include "emu.h"
#include "teeconn.h"


namespace {

class tee_connector_device : public device_t, public device_ti8x_link_port_interface
{
public:
	tee_connector_device(machine_config const &mconfig, char const *tag, device_t *owner, const XTAL &clock);

protected:
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;

	virtual DECLARE_WRITE_LINE_MEMBER(input_tip) override;
	virtual DECLARE_WRITE_LINE_MEMBER(input_ring) override;

	DECLARE_WRITE_LINE_MEMBER(tip_a_w);
	DECLARE_WRITE_LINE_MEMBER(ring_a_w);
	DECLARE_WRITE_LINE_MEMBER(tip_b_w);
	DECLARE_WRITE_LINE_MEMBER(ring_b_w);

	required_device<ti8x_link_port_device>  m_port_a;
	required_device<ti8x_link_port_device>  m_port_b;

	bool    m_tip_host, m_tip_a, m_tip_b;
	bool    m_ring_host, m_ring_a, m_ring_b;
};


tee_connector_device::tee_connector_device(
		machine_config const &mconfig,
		char const *tag,
		device_t *owner,
		uint32_t clock)
	: device_t(mconfig, TI8X_TEE_CONNECTOR, tag, owner, clock)
	, device_ti8x_link_port_interface(mconfig, *this)
	, m_port_a(*this, "a")
	, m_port_b(*this, "b")
	, m_tip_host(true)
	, m_tip_a(true)
	, m_tip_b(true)
	, m_ring_host(true)
	, m_ring_a(true)
	, m_ring_b(true)
{
}


WRITE_LINE_MEMBER(tee_connector_device::tip_a_w)
{
	m_tip_a = bool(state);
	output_tip((m_tip_a && m_tip_b) ? 1 : 0);
	m_port_b->tip_w((m_tip_host && m_tip_a) ? 1 : 0);
}


WRITE_LINE_MEMBER(tee_connector_device::ring_a_w)
{
	m_ring_a = bool(state);
	output_ring((m_ring_a && m_ring_b) ? 1 : 0);
	m_port_b->ring_w((m_ring_host && m_ring_a) ? 1 : 0);
}


WRITE_LINE_MEMBER(tee_connector_device::tip_b_w)
{
	m_tip_b = bool(state);
	output_tip((m_tip_a && m_tip_b) ? 1 : 0);
	m_port_a->tip_w((m_tip_host && m_tip_b) ? 1 : 0);
}


WRITE_LINE_MEMBER(tee_connector_device::ring_b_w)
{
	m_ring_b = bool(state);
	output_ring((m_ring_a && m_ring_b) ? 1 : 0);
	m_port_a->ring_w((m_ring_host && m_ring_b) ? 1 : 0);
}


void tee_connector_device::device_add_mconfig(machine_config &config)
{
	TI8X_LINK_PORT(config, m_port_a, default_ti8x_link_devices, nullptr);
	m_port_a->tip_handler().set(FUNC(tee_connector_device::tip_a_w));
	m_port_a->ring_handler().set(FUNC(tee_connector_device::ring_a_w));

	TI8X_LINK_PORT(config, m_port_b, default_ti8x_link_devices, nullptr);
	m_port_b->tip_handler().set(FUNC(tee_connector_device::tip_b_w));
	m_port_b->ring_handler().set(FUNC(tee_connector_device::ring_b_w));
}


void tee_connector_device::device_start()
{
	save_item(NAME(m_tip_host));
	save_item(NAME(m_tip_a));
	save_item(NAME(m_tip_b));
	save_item(NAME(m_ring_host));
	save_item(NAME(m_ring_a));
	save_item(NAME(m_ring_b));

	m_tip_host = m_tip_a = m_tip_b = true;
	m_ring_host = m_ring_a = m_ring_b = true;
}


WRITE_LINE_MEMBER(tee_connector_device::input_tip)
{
	m_tip_host = bool(state);
	m_port_a->tip_w((m_tip_host && m_tip_b) ? 1 : 0);
	m_port_b->tip_w((m_tip_host && m_tip_a) ? 1 : 0);
}


WRITE_LINE_MEMBER(tee_connector_device::input_ring)
{
	m_ring_host = bool(state);
	m_port_a->ring_w((m_ring_host && m_ring_b) ? 1 : 0);
	m_port_b->ring_w((m_ring_host && m_ring_a) ? 1 : 0);
}

} // anonymous namespace


DEFINE_DEVICE_TYPE_PRIVATE(TI8X_TEE_CONNECTOR, device_ti8x_link_port_interface, tee_connector_device, "ti8x_tconn", "TI-8x T-connector")