Skip to content

Commit de8e51a

Browse files
committed
sinclair/spec128.cpp: Supported varieties of AY devices through configurable slot
1 parent 00fd57b commit de8e51a

File tree

19 files changed

+407
-198
lines changed

19 files changed

+407
-198
lines changed

scripts/src/bus.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4925,6 +4925,20 @@ if (BUSES["SPECTRUM"]~=null) then
49254925
}
49264926
end
49274927

4928+
---------------------------------------------------
4929+
--
4930+
--@src/devices/bus/spectrum/ay/slot.h,BUSES["AY_SLOT"] = true
4931+
---------------------------------------------------
4932+
4933+
if (BUSES["AY_SLOT"]~=null) then
4934+
files {
4935+
MAME_DIR .. "src/devices/bus/spectrum/ay/slot.cpp",
4936+
MAME_DIR .. "src/devices/bus/spectrum/ay/slot.h",
4937+
MAME_DIR .. "src/devices/bus/spectrum/ay/cards.cpp",
4938+
MAME_DIR .. "src/devices/bus/spectrum/ay/cards.h",
4939+
}
4940+
end
4941+
49284942
---------------------------------------------------
49294943
--
49304944
--@src/devices/bus/spectrum/zxbus.h,BUSES["ZXBUS"] = true

src/devices/bus/spectrum/ay/cards.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Andrei I. Holub
3+
4+
#include "emu.h"
5+
#include "cards.h"
6+
7+
namespace bus::spectrum::ay_slot {
8+
9+
namespace {
10+
11+
class ay8912_device : public spectrum_ay_device
12+
{
13+
public:
14+
ay8912_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
15+
: spectrum_ay_device(mconfig, AY_SLOT_AY8912, tag, owner, clock)
16+
{ }
17+
18+
protected:
19+
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
20+
};
21+
22+
void ay8912_device::device_add_mconfig(machine_config &config)
23+
{
24+
AY8912(config, m_ay0, clock());
25+
spectrum_ay_device::device_add_mconfig(config);
26+
}
27+
28+
29+
class turbosound_device : public spectrum_ay_device
30+
{
31+
public:
32+
turbosound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
33+
: spectrum_ay_device(mconfig, AY_SLOT_TURBOSOUND, tag, owner, clock)
34+
{ }
35+
36+
protected:
37+
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
38+
};
39+
40+
void turbosound_device::device_add_mconfig(machine_config &config)
41+
{
42+
YM2149(config, m_ay0, clock());
43+
YM2149(config, m_ay1, clock());
44+
spectrum_ay_device::device_add_mconfig(config);
45+
}
46+
47+
48+
class ym2149_device : public spectrum_ay_device
49+
{
50+
public:
51+
ym2149_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
52+
: spectrum_ay_device(mconfig, AY_SLOT_YM2149, tag, owner, clock)
53+
{ }
54+
55+
protected:
56+
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
57+
};
58+
59+
void ym2149_device::device_add_mconfig(machine_config &config)
60+
{
61+
YM2149(config, m_ay0, clock());
62+
spectrum_ay_device::device_add_mconfig(config);
63+
}
64+
65+
} // anonymous namespace
66+
67+
} // namespace bus::spectrum::ay_slot
68+
69+
DEFINE_DEVICE_TYPE_PRIVATE(AY_SLOT_AY8912, device_ay_slot_interface, bus::spectrum::ay_slot::ay8912_device, "ay_ay8912", "AY8912")
70+
DEFINE_DEVICE_TYPE_PRIVATE(AY_SLOT_TURBOSOUND, device_ay_slot_interface, bus::spectrum::ay_slot::turbosound_device, "ay_turbosound", "TURBOSOUND")
71+
DEFINE_DEVICE_TYPE_PRIVATE(AY_SLOT_YM2149, device_ay_slot_interface, bus::spectrum::ay_slot::ym2149_device, "ay_ym2149", "YM2149")

src/devices/bus/spectrum/ay/cards.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Andrei I. Holub
3+
4+
#ifndef MAME_BUS_SPECTRUM_AY_CARDS_H
5+
#define MAME_BUS_SPECTRUM_AY_CARDS_H
6+
7+
#pragma once
8+
9+
#include "slot.h"
10+
11+
12+
DECLARE_DEVICE_TYPE(AY_SLOT_AY8912, device_ay_slot_interface)
13+
DECLARE_DEVICE_TYPE(AY_SLOT_YM2149, device_ay_slot_interface)
14+
DECLARE_DEVICE_TYPE(AY_SLOT_TURBOSOUND, device_ay_slot_interface)
15+
16+
#endif // MAME_BUS_SPECTRUM_AY_CARDS_H

src/devices/bus/spectrum/ay/slot.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Andrei I. Holub
3+
/**********************************************************************
4+
AY Slot for ZX Spectrum
5+
6+
Supports variates AY8910 sound chips
7+
**********************************************************************/
8+
9+
#include "emu.h"
10+
#include "slot.h"
11+
12+
DEFINE_DEVICE_TYPE(AY_SLOT, ay_slot_device, "ay_slot", "AY Slot")
13+
14+
ay_slot_device::ay_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
15+
: ay_slot_device(mconfig, AY_SLOT, tag, owner, clock)
16+
{
17+
}
18+
19+
ay_slot_device::ay_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
20+
: device_t(mconfig, type, tag, owner, clock)
21+
, device_single_card_slot_interface<device_ay_slot_interface>(mconfig, *this)
22+
, device_mixer_interface(mconfig, *this)
23+
, m_dev(nullptr)
24+
{
25+
}
26+
27+
ay_slot_device::~ay_slot_device()
28+
{
29+
}
30+
31+
void ay_slot_device::device_start()
32+
{
33+
m_dev = get_card_device();
34+
}
35+
36+
u8 ay_slot_device::data_r()
37+
{
38+
return m_dev ? m_dev->data_r() : 0xff;
39+
};
40+
41+
void ay_slot_device::data_w(u8 data)
42+
{
43+
if (m_dev) m_dev->data_w(data);
44+
};
45+
46+
void ay_slot_device::address_w(u8 data)
47+
{
48+
if (m_dev) m_dev->address_w(data);
49+
};
50+
51+
52+
device_ay_slot_interface::device_ay_slot_interface(const machine_config &mconfig, device_t &device)
53+
: device_interface(device, "ay")
54+
{
55+
m_slot = dynamic_cast<ay_slot_device *>(device.owner());
56+
}
57+
58+
device_ay_slot_interface::~device_ay_slot_interface()
59+
{
60+
}
61+
62+
63+
spectrum_ay_device::spectrum_ay_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
64+
: device_t(mconfig, type, tag, owner, clock)
65+
, device_ay_slot_interface(mconfig, *this)
66+
, m_ay0(*this, "ay0")
67+
, m_ay1(*this, "ay1")
68+
{
69+
}
70+
71+
u8 spectrum_ay_device::data_r()
72+
{
73+
if (m_ay_selected)
74+
return m_ay1->data_r();
75+
else
76+
return m_ay0->data_r();
77+
}
78+
79+
void spectrum_ay_device::data_w(u8 data)
80+
{
81+
if (m_ay_selected)
82+
return m_ay1->data_w(data);
83+
else
84+
return m_ay0->data_w(data);
85+
}
86+
87+
void spectrum_ay_device::address_w(u8 data)
88+
{
89+
if (m_ay1 && ((data & 0xfe) == 0xfe))
90+
m_ay_selected = data & 1;
91+
else if (m_ay_selected)
92+
m_ay1->address_w(data);
93+
else
94+
m_ay0->address_w(data);
95+
}
96+
97+
void spectrum_ay_device::device_start()
98+
{
99+
save_item(NAME(m_ay_selected));
100+
}
101+
102+
void spectrum_ay_device::device_reset()
103+
{
104+
m_ay_selected = 0;
105+
}
106+
107+
void spectrum_ay_device::device_add_mconfig(machine_config &config)
108+
{
109+
m_ay0
110+
.add_route(0, DEVICE_SELF_OWNER, 1.0, 0)
111+
.add_route(1, DEVICE_SELF_OWNER, 1.0, 1)
112+
.add_route(2, DEVICE_SELF_OWNER, 1.0, 2);
113+
if (m_ay1)
114+
{
115+
m_ay1->add_route(0, DEVICE_SELF_OWNER, 1.0, 0)
116+
.add_route(1, DEVICE_SELF_OWNER, 1.0, 1)
117+
.add_route(2, DEVICE_SELF_OWNER, 1.0, 2);
118+
}
119+
}
120+
121+
122+
#include "cards.h"
123+
124+
template class device_finder<device_ay_slot_interface, false>;
125+
template class device_finder<device_ay_slot_interface, true>;
126+
127+
void default_ay_slot_devices(device_slot_interface &device)
128+
{
129+
device.option_add("ay_ay8912", AY_SLOT_AY8912);
130+
device.option_add("ay_turbosound", AY_SLOT_TURBOSOUND);
131+
device.option_add("ay_ym2149", AY_SLOT_YM2149);
132+
}

src/devices/bus/spectrum/ay/slot.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// license:BSD-3-Clause
2+
// copyright-holders:Andrei I. Holub
3+
#ifndef MAME_BUS_SPECTRUM_AY_SLOT_H
4+
#define MAME_BUS_SPECTRUM_AY_SLOT_H
5+
6+
#pragma once
7+
8+
#include "sound/ay8910.h"
9+
10+
11+
class device_ay_slot_interface;
12+
13+
class ay_slot_device : public device_t
14+
, public device_single_card_slot_interface<device_ay_slot_interface>
15+
, public device_mixer_interface
16+
{
17+
friend class device_ay_slot_interface;
18+
19+
public:
20+
template <typename T>
21+
ay_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock, T &&opts, const char *dflt)
22+
: ay_slot_device(mconfig, tag, owner, clock)
23+
{
24+
option_reset();
25+
opts(*this);
26+
set_default_option(dflt);
27+
set_fixed(false);
28+
}
29+
ay_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
30+
virtual ~ay_slot_device();
31+
32+
u8 data_r();
33+
void data_w(u8 data);
34+
void address_w(u8 data);
35+
36+
protected:
37+
ay_slot_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);
38+
39+
virtual void device_start() override ATTR_COLD;
40+
41+
private:
42+
device_ay_slot_interface *m_dev;
43+
};
44+
45+
class device_ay_slot_interface : public device_interface
46+
{
47+
friend class ay_slot_device;
48+
49+
public:
50+
virtual ~device_ay_slot_interface();
51+
52+
virtual u8 data_r() { return 0xff; };
53+
virtual void data_w(u8 data) {};
54+
virtual void address_w(u8 data) {};
55+
56+
protected:
57+
device_ay_slot_interface(const machine_config &mconfig, device_t &device);
58+
59+
ay_slot_device *m_slot;
60+
};
61+
62+
class spectrum_ay_device : public device_t, public device_ay_slot_interface
63+
{
64+
public:
65+
virtual u8 data_r() override;
66+
virtual void data_w(u8 data) override;
67+
virtual void address_w(u8 data) override;
68+
69+
protected:
70+
spectrum_ay_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock);
71+
72+
virtual void device_start() override ATTR_COLD;
73+
virtual void device_reset() override ATTR_COLD;
74+
virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;
75+
76+
required_device<ay8910_device> m_ay0;
77+
optional_device<ay8910_device> m_ay1;
78+
79+
u8 m_ay_selected;
80+
};
81+
82+
DECLARE_DEVICE_TYPE(AY_SLOT, ay_slot_device)
83+
84+
void default_ay_slot_devices(device_slot_interface &device);
85+
86+
#endif // MAME_BUS_SPECTRUM_AY_SLOT_H

src/mame/sinclair/atm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ MicroART ATM (clone of Spectrum)
1313
#include "emu.h"
1414
#include "atm.h"
1515

16+
#include "bus/spectrum/ay/slot.h"
1617
#include "bus/ata/atapicdr.h"
1718
#include "bus/ata/hdd.h"
18-
#include "sound/ay8910.h"
1919

2020
#define LOG_MEM (1U << 1)
2121
#define LOG_VIDEO (1U << 2)
@@ -381,8 +381,8 @@ void atm_state::atm_io(address_map &map)
381381
map(0x00fd, 0x00fd).mirror(0xff00).w(FUNC(atm_state::atm_port_7ffd_w));
382382

383383
map(0xfadf, 0xfadf).mirror(0x0500).nopr(); // TODO 0xfadf, 0xfbdf, 0xffdf Kempston Mouse
384-
map(0x8000, 0x8000).mirror(0x3ffd).w("ay8912", FUNC(ay8910_device::data_w));
385-
map(0xc000, 0xc000).mirror(0x3ffd).rw("ay8912", FUNC(ay8910_device::data_r), FUNC(ay8910_device::address_w));
384+
map(0x8000, 0x8000).mirror(0x3ffd).w("ay_slot", FUNC(ay_slot_device::data_w));
385+
map(0xc000, 0xc000).mirror(0x3ffd).rw("ay_slot", FUNC(ay_slot_device::data_r), FUNC(ay_slot_device::address_w));
386386

387387
// PORTS: Shadow
388388
map(0x0000, 0xffff).view(m_io_view);

0 commit comments

Comments
 (0)