1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     Sega vector hardware
6 
7 *************************************************************************/
8 
9 #include "emu.h"
10 
11 #include "audio/segag80.h"
12 #include "audio/nl_astrob.h"
13 #include "audio/nl_elim.h"
14 #include "audio/nl_spacfury.h"
15 #include "includes/segag80v.h"
16 #include "sound/samples.h"
17 
18 
19 
20 /*************************************
21  *
22  *  Base class
23  *
24  *************************************/
25 
segag80_audio_device_base(const machine_config & mconfig,device_type type,const char * tag,device_t * owner,u32 clock,u8 lomask,u8 himask,bool haspsg,netlist_ptr netlist,double output_scale)26 segag80_audio_device_base::segag80_audio_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u8 lomask, u8 himask, bool haspsg, netlist_ptr netlist, double output_scale) :
27 	device_t(mconfig, type, tag, owner, clock),
28 	device_mixer_interface(mconfig, *this),
29 	m_lo_input(*this, "sound_nl:lo_%u", 0),
30 	m_hi_input(*this, "sound_nl:hi_%u", 0),
31 	m_psg(*this, "psg"),
32 	m_lo_mask(lomask),
33 	m_hi_mask(himask),
34 	m_has_psg(haspsg),
35 	m_netlist(netlist),
36 	m_output_scale(output_scale)
37 {
38 }
39 
device_add_mconfig(machine_config & config)40 void segag80_audio_device_base::device_add_mconfig(machine_config &config)
41 {
42 	NETLIST_SOUND(config, "sound_nl", 48000)
43 		.set_source(m_netlist)
44 		.add_route(ALL_OUTPUTS, *this, 1.0);
45 
46 	if (BIT(m_lo_mask, 0))
47 		NETLIST_LOGIC_INPUT(config, m_lo_input[0], "I_LO_D0.IN", 0);
48 	if (BIT(m_lo_mask, 1))
49 		NETLIST_LOGIC_INPUT(config, m_lo_input[1], "I_LO_D1.IN", 0);
50 	if (BIT(m_lo_mask, 2))
51 		NETLIST_LOGIC_INPUT(config, m_lo_input[2], "I_LO_D2.IN", 0);
52 	if (BIT(m_lo_mask, 3))
53 		NETLIST_LOGIC_INPUT(config, m_lo_input[3], "I_LO_D3.IN", 0);
54 	if (BIT(m_lo_mask, 4))
55 		NETLIST_LOGIC_INPUT(config, m_lo_input[4], "I_LO_D4.IN", 0);
56 	if (BIT(m_lo_mask, 5))
57 		NETLIST_LOGIC_INPUT(config, m_lo_input[5], "I_LO_D5.IN", 0);
58 	if (BIT(m_lo_mask, 6))
59 		NETLIST_LOGIC_INPUT(config, m_lo_input[6], "I_LO_D6.IN", 0);
60 	if (BIT(m_lo_mask, 7))
61 		NETLIST_LOGIC_INPUT(config, m_lo_input[7], "I_LO_D7.IN", 0);
62 
63 	if (BIT(m_hi_mask, 0))
64 		NETLIST_LOGIC_INPUT(config, m_hi_input[0], "I_HI_D0.IN", 0);
65 	if (BIT(m_hi_mask, 1))
66 		NETLIST_LOGIC_INPUT(config, m_hi_input[1], "I_HI_D1.IN", 0);
67 	if (BIT(m_hi_mask, 2))
68 		NETLIST_LOGIC_INPUT(config, m_hi_input[2], "I_HI_D2.IN", 0);
69 	if (BIT(m_hi_mask, 3))
70 		NETLIST_LOGIC_INPUT(config, m_hi_input[3], "I_HI_D3.IN", 0);
71 	if (BIT(m_hi_mask, 4))
72 		NETLIST_LOGIC_INPUT(config, m_hi_input[4], "I_HI_D4.IN", 0);
73 	if (BIT(m_hi_mask, 5))
74 		NETLIST_LOGIC_INPUT(config, m_hi_input[5], "I_HI_D5.IN", 0);
75 	if (BIT(m_hi_mask, 6))
76 		NETLIST_LOGIC_INPUT(config, m_hi_input[6], "I_HI_D6.IN", 0);
77 	if (BIT(m_hi_mask, 7))
78 		NETLIST_LOGIC_INPUT(config, m_hi_input[7], "I_HI_D7.IN", 0);
79 
80 	if (m_has_psg)
81 	{
82 		AY8912(config, m_psg, VIDEO_CLOCK/4/2);
83 		m_psg->set_flags(AY8910_RESISTOR_OUTPUT);
84 		m_psg->set_resistors_load(10000.0, 10000.0, 10000.0);
85 		m_psg->add_route(0, "sound_nl", 1.0, 0);
86 		m_psg->add_route(1, "sound_nl", 1.0, 1);
87 		m_psg->add_route(2, "sound_nl", 1.0, 2);
88 
89 		NETLIST_STREAM_INPUT(config, "sound_nl:cin0", 0, "R_PSG_1.R");
90 		NETLIST_STREAM_INPUT(config, "sound_nl:cin1", 1, "R_PSG_2.R");
91 		NETLIST_STREAM_INPUT(config, "sound_nl:cin2", 2, "R_PSG_3.R");
92 	}
93 
94 	NETLIST_STREAM_OUTPUT(config, "sound_nl:cout0", 0, "OUTPUT").set_mult_offset(m_output_scale, 0.0);
95 }
96 
device_start()97 void segag80_audio_device_base::device_start()
98 {
99 }
100 
write(offs_t addr,uint8_t data)101 void segag80_audio_device_base::write(offs_t addr, uint8_t data)
102 {
103 	addr &= 1;
104 
105 	auto &inputs = (addr == 0) ? m_lo_input : m_hi_input;
106 	auto &mask = (addr == 0) ? m_lo_mask : m_hi_mask;
107 
108 	for (int bit = 0; bit < 8; bit++)
109 		if (BIT(mask, bit))
110 			inputs[bit]->write_line(BIT(data, bit));
111 }
112 
write_ay(offs_t addr,uint8_t data)113 void segag80_audio_device_base::write_ay(offs_t addr, uint8_t data)
114 {
115 	assert(m_has_psg);
116 	m_psg->address_data_w(addr, data);
117 }
118 
119 
120 
121 /*************************************
122  *
123  *  Eliminator
124  *
125  *************************************/
126 
127 DEFINE_DEVICE_TYPE(ELIMINATOR_AUDIO, elim_audio_device, "elim_audio", "Eliminator Sound Board")
128 
elim_audio_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)129 elim_audio_device::elim_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
130 	segag80_audio_device_base(mconfig, ELIMINATOR_AUDIO, tag, owner, clock, 0xfe, 0xff, false, NETLIST_NAME(elim), 0.15)
131 {
132 }
133 
134 
135 
136 /*************************************
137  *
138  *  Zektor
139  *
140  *************************************/
141 
142 DEFINE_DEVICE_TYPE(ZEKTOR_AUDIO, zektor_audio_device, "zektor_audio", "Zektor Sound Board")
143 
zektor_audio_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)144 zektor_audio_device::zektor_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
145 	segag80_audio_device_base(mconfig, ZEKTOR_AUDIO, tag, owner, clock, 0xfe, 0xff, true, NETLIST_NAME(zektor), 0.15)
146 {
147 }
148 
149 
150 
151 /*************************************
152  *
153  *  Space Fury
154  *
155  *************************************/
156 
157 DEFINE_DEVICE_TYPE(SPACE_FURY_AUDIO, spacfury_audio_device, "spcfury_audio", "Space Fury Sound Board")
158 
spacfury_audio_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)159 spacfury_audio_device::spacfury_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
160 	segag80_audio_device_base(mconfig, SPACE_FURY_AUDIO, tag, owner, clock, 0xc7, 0x3f, false, NETLIST_NAME(spacfury), 2.0)
161 {
162 }
163 
164 
165 
166 /*************************************
167  *
168  *  Astro Blaster
169  *
170  *************************************/
171 
172 DEFINE_DEVICE_TYPE(ASTRO_BLASTER_AUDIO, astrob_audio_device, "astrob_audio", "Astro Blaster Sound Board")
173 
astrob_audio_device(const machine_config & mconfig,const char * tag,device_t * owner,u32 clock)174 astrob_audio_device::astrob_audio_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
175 	segag80_audio_device_base(mconfig, ASTRO_BLASTER_AUDIO, tag, owner, clock, 0xff, 0xff, false, NETLIST_NAME(astrob), 1.0)
176 {
177 }
178