summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/ti8x/tispeaker.cpp
blob: d64ad6ae185221d8c5ed74a70f97e70b87b108e1 (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
// license:BSD-3-Clause
// copyright-holders:Vas Crabb

#include "emu.h"
#include "tispeaker.h"

#include "sound/spkrdev.h"

#include "speaker.h"


namespace {

class stereo_speaker_device : public device_t, public device_ti8x_link_port_interface
{
public:
	stereo_speaker_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock)
		: device_t(mconfig, TI8X_SPEAKER_STEREO, tag, owner, clock)
		, device_ti8x_link_port_interface(mconfig, *this)
		, m_left_speaker(*this, "lspkr")
		, m_right_speaker(*this, "rspkr")
	{
	}

protected:
	virtual void device_add_mconfig(machine_config &config) override
	{
		SPEAKER(config, "outl").front_left();
		SPEAKER(config, "outr").front_right();

		SPEAKER_SOUND(config, m_left_speaker).add_route(ALL_OUTPUTS, "outl", 0.50);

		SPEAKER_SOUND(config, m_right_speaker).add_route(ALL_OUTPUTS, "outr", 0.50);
	}

	virtual void device_start() override
	{
	}


	virtual DECLARE_WRITE_LINE_MEMBER(input_tip) override
	{
		m_left_speaker->level_w(state);
	}

	virtual DECLARE_WRITE_LINE_MEMBER(input_ring) override
	{
		m_right_speaker->level_w(state);
	}


	required_device<speaker_sound_device> m_left_speaker;
	required_device<speaker_sound_device> m_right_speaker;
};


class mono_speaker_device : public device_t, public device_ti8x_link_port_interface
{
public:
	mono_speaker_device(
			machine_config const &mconfig,
			char const *tag,
			device_t *owner,
			uint32_t clock)
		: device_t(mconfig, TI8X_SPEAKER_MONO, tag, owner, clock)
		, device_ti8x_link_port_interface(mconfig, *this)
		, m_speaker(*this, "spkr")
		, m_tip_state(true)
		, m_ring_state(true)
	{
	}

protected:
	virtual void device_add_mconfig(machine_config &config) override
	{
		SPEAKER(config, "mono").front_center();

		SPEAKER_SOUND(config, m_speaker).add_route(ALL_OUTPUTS, "mono", 0.50);
	}

	virtual void device_start() override
	{
		save_item(NAME(m_tip_state));
		save_item(NAME(m_ring_state));

		m_tip_state = m_ring_state = true;
	}


	virtual DECLARE_WRITE_LINE_MEMBER(input_tip) override
	{
		m_tip_state = bool(state);
		m_speaker->level_w((m_tip_state || m_ring_state) ? 1 : 0);
	}

	virtual DECLARE_WRITE_LINE_MEMBER(input_ring) override
	{
		m_ring_state = bool(state);
		m_speaker->level_w((m_tip_state || m_ring_state) ? 1 : 0);
	}


	required_device<speaker_sound_device> m_speaker;

private:
	bool m_tip_state, m_ring_state;
};

} // anonymous namespace


DEFINE_DEVICE_TYPE_PRIVATE(TI8X_SPEAKER_STEREO, device_ti8x_link_port_interface, stereo_speaker_device, "ti8x_stspkr", "TI-8x Speaker (Stereo)")
DEFINE_DEVICE_TYPE_PRIVATE(TI8X_SPEAKER_MONO,   device_ti8x_link_port_interface, mono_speaker_device,   "ti8x_mspkr",  "TI-8x Speaker (Mono)")