summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/spectrum/ay/slot.cpp
blob: 442244d7bdd1b4752c27505b7bb76782b029c508 (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
// license:BSD-3-Clause
// copyright-holders:Andrei I. Holub
/**********************************************************************
    AY Slot for ZX Spectrum

    Supports variates AY8910 sound chips
**********************************************************************/

#include "emu.h"
#include "slot.h"

DEFINE_DEVICE_TYPE(AY_SLOT, ay_slot_device, "ay_slot", "AY Slot")

ay_slot_device::ay_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: ay_slot_device(mconfig, AY_SLOT, tag, owner, clock)
{
}

ay_slot_device::ay_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_single_card_slot_interface<device_ay_slot_interface>(mconfig, *this)
	, device_mixer_interface(mconfig, *this)
	, m_dev(nullptr)
{
}

ay_slot_device::~ay_slot_device()
{
}

void ay_slot_device::device_start()
{
	m_dev = get_card_device();
}

u8 ay_slot_device::data_r()
{
	return m_dev ? m_dev->data_r() : 0xff;
};

void ay_slot_device::data_w(u8 data)
{
	if (m_dev) m_dev->data_w(data);
};

void ay_slot_device::address_w(u8 data)
{
	if (m_dev) m_dev->address_w(data);
};


device_ay_slot_interface::device_ay_slot_interface(const machine_config &mconfig, device_t &device)
	: device_interface(device, "ay")
{
	m_slot = dynamic_cast<ay_slot_device *>(device.owner());
}

device_ay_slot_interface::~device_ay_slot_interface()
{
}


spectrum_ay_device::spectrum_ay_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_ay_slot_interface(mconfig, *this)
	, m_ay0(*this, "ay0")
	, m_ay1(*this, "ay1")
{
}

u8 spectrum_ay_device::data_r()
{
	if (m_ay_selected)
		return m_ay1->data_r();
	else
		return m_ay0->data_r();
}

void spectrum_ay_device::data_w(u8 data)
{
	if (m_ay_selected)
		return m_ay1->data_w(data);
	else
		return m_ay0->data_w(data);
}

void spectrum_ay_device::address_w(u8 data)
{
	if (m_ay1 &&  ((data & 0xfe) == 0xfe))
		m_ay_selected = data & 1;
	else if (m_ay_selected)
		m_ay1->address_w(data);
	else
		m_ay0->address_w(data);
}

void spectrum_ay_device::device_start()
{
	save_item(NAME(m_ay_selected));
}

void spectrum_ay_device::device_reset()
{
	m_ay_selected = 0;
}

void spectrum_ay_device::device_add_mconfig(machine_config &config)
{
	m_ay0->add_route(0, DEVICE_SELF_OWNER, 1.0, 0)
		.add_route(1, DEVICE_SELF_OWNER, 1.0, 1)
		.add_route(2, DEVICE_SELF_OWNER, 1.0, 2);
	if (m_ay1)
	{
		m_ay1->add_route(0, DEVICE_SELF_OWNER, 1.0, 0)
			.add_route(1, DEVICE_SELF_OWNER, 1.0, 1)
			.add_route(2, DEVICE_SELF_OWNER, 1.0, 2);
	}
}


#include "cards.h"

template class device_finder<device_ay_slot_interface, false>;
template class device_finder<device_ay_slot_interface, true>;

void default_ay_slot_devices(device_slot_interface &device)
{
	device.option_add("ay_ay8912",     AY_SLOT_AY8912);
	device.option_add("ay_turbosound", AY_SLOT_TURBOSOUND);
	device.option_add("ay_ym2149",     AY_SLOT_YM2149);
}