1 // license:BSD-3-Clause
2 // copyright-holders:Lee Taylor
3 /***************************************************************************
4
5 Astro Fighter hardware
6
7 ****************************************************************************/
8
9 #include "emu.h"
10 #include "includes/astrof.h"
11 #include "speaker.h"
12
13
14 /*************************************
15 *
16 * Astro Fighter
17 *
18 *************************************/
19
20 #define SAMPLE_FIRE 0
21 #define SAMPLE_EKILLED 1
22 #define SAMPLE_WAVE 2
23 #define SAMPLE_BOSSFIRE 6
24 #define SAMPLE_FUEL 7
25 #define SAMPLE_DEATH 8
26 #define SAMPLE_BOSSHIT 9
27 #define SAMPLE_BOSSKILL 10
28
29 #define CHANNEL_FIRE 0
30 #define CHANNEL_EXPLOSION 1
31 #define CHANNEL_WAVE 2 /* background humm */
32 #define CHANNEL_BOSSFIRE 2 /* there is no background humm on the boss level */
33 #define CHANNEL_FUEL 3
34
35
astrof_audio_1_w(uint8_t data)36 void astrof_state::astrof_audio_1_w(uint8_t data)
37 {
38 uint8_t rising_bits = data & ~m_port_1_last;
39
40 if (m_astrof_death_playing)
41 m_astrof_death_playing = m_samples->playing(CHANNEL_EXPLOSION);
42
43 if (m_astrof_bosskill_playing)
44 m_astrof_bosskill_playing = m_samples->playing(CHANNEL_EXPLOSION);
45
46 /* D2 - explosion */
47 if (rising_bits & 0x04)
48 {
49 /* I *know* that the effect select port will be written shortly
50 after this one, so this works */
51 m_astrof_start_explosion = 1;
52 }
53
54 /* D0,D1,D3 - background noise */
55 if ((data & 0x08) && (~m_port_1_last & 0x08))
56 {
57 int sample = SAMPLE_WAVE + (data & 3);
58 m_samples->start(CHANNEL_WAVE, sample, 1);
59 }
60
61 if ((~data & 0x08) && (m_port_1_last & 0x08))
62 m_samples->stop(CHANNEL_WAVE);
63
64 /* D4 - boss laser */
65 if ((rising_bits & 0x10) && !m_astrof_bosskill_playing)
66 m_samples->start(CHANNEL_BOSSFIRE, SAMPLE_BOSSFIRE, 0);
67
68 /* D5 - fire */
69 if ((rising_bits & 0x20) && !m_astrof_bosskill_playing)
70 m_samples->start(CHANNEL_FIRE, SAMPLE_FIRE, 0);
71
72 /* D6 - don't know. Probably something to do with the explosion sounds */
73
74 /* D7 - sound enable bit */
75 machine().sound().system_enable(data & 0x80);
76
77 m_port_1_last = data;
78 }
79
80
astrof_audio_2_w(uint8_t data)81 void astrof_state::astrof_audio_2_w(uint8_t data)
82 {
83 uint8_t rising_bits = data & ~m_port_2_last;
84
85 /* D0-D2 - explosion select (triggered by D2 of the other port */
86 if (m_astrof_start_explosion)
87 {
88 /* this is really a compound effect, made up of I believe 3 sound
89 effects, but since our sample contains them all, disable playing
90 the other effects while the explosion is playing */
91
92 logerror("Explosion: %x\n", data);
93 if (data & 0x04)
94 {
95 if (!m_astrof_bosskill_playing)
96 {
97 m_samples->start(CHANNEL_EXPLOSION, SAMPLE_BOSSKILL, 0);
98 m_astrof_bosskill_playing = 1;
99 }
100 }
101 else if (data & 0x02)
102 m_samples->start(CHANNEL_EXPLOSION, SAMPLE_BOSSHIT, 0);
103 else if (data & 0x01)
104 m_samples->start(CHANNEL_EXPLOSION, SAMPLE_EKILLED, 0);
105 else
106 {
107 if (!m_astrof_death_playing)
108 {
109 m_samples->start(CHANNEL_EXPLOSION, SAMPLE_DEATH, 0);
110 m_astrof_death_playing = 1;
111 }
112 }
113
114 m_astrof_start_explosion = 0;
115 }
116
117 /* D3 - low fuel warning */
118 if (rising_bits & 0x08)
119 m_samples->start(CHANNEL_FUEL, SAMPLE_FUEL, 0);
120
121 m_port_2_last = data;
122 }
123
124
125 static const char *const astrof_sample_names[] =
126 {
127 "*astrof",
128 "fire",
129 "ekilled",
130 "wave1",
131 "wave2",
132 "wave3",
133 "wave4",
134 "bossfire",
135 "fuel",
136 "death",
137 "bosshit",
138 "bosskill",
139 nullptr
140 };
141
astrof_audio(machine_config & config)142 void astrof_state::astrof_audio(machine_config &config)
143 {
144 SPEAKER(config, "mono").front_center();
145 SAMPLES(config, m_samples);
146 m_samples->set_channels(4);
147 m_samples->set_samples_names(astrof_sample_names);
148 m_samples->add_route(ALL_OUTPUTS, "mono", 0.50);
149 }
150
151
152
153 /*************************************
154 *
155 * Space Fighter
156 *
157 *************************************/
158
spfghmk2_audio_w(uint8_t data)159 void astrof_state::spfghmk2_audio_w(uint8_t data)
160 {
161 /* nothing yet */
162 }
163
164
spfghmk2_audio(machine_config & config)165 void astrof_state::spfghmk2_audio(machine_config &config)
166 {
167 /* nothing yet */
168 }
169
170
171
172 /*************************************
173 *
174 * Tomahawk
175 *
176 *************************************/
177
tomahawk_audio_w(uint8_t data)178 void astrof_state::tomahawk_audio_w(uint8_t data)
179 {
180 /* D0 - sonar */
181
182 /* D1 - UFO explosion */
183
184 /* D2 - morse */
185
186 /* D3 - missile */
187
188 /* D4 - UFO */
189
190 /* D5 - UFO under water */
191 m_sn->enable_w((~data >> 5) & 0x01);
192
193 /* D6 - explosion */
194
195 /* D7 - sound enable bit */
196 machine().sound().system_enable(data & 0x80);
197 }
198
199
tomahawk_audio(machine_config & config)200 void astrof_state::tomahawk_audio(machine_config &config)
201 {
202 SPEAKER(config, "mono").front_center();
203 SN76477(config, m_sn);
204 m_sn->set_noise_params(0, 0, 0);
205 m_sn->set_decay_res(0);
206 m_sn->set_attack_params(0, 0);
207 m_sn->set_amp_res(RES_K(47));
208 m_sn->set_feedback_res(RES_K(47));
209 m_sn->set_vco_params(0, CAP_U(0.033), RES_K(33));
210 m_sn->set_pitch_voltage(5.0);
211 m_sn->set_slf_params(CAP_U(2.2), RES_K(47));
212 m_sn->set_oneshot_params(0, 0);
213 m_sn->set_vco_mode(1);
214 m_sn->set_mixer_params(0, 0, 0);
215 m_sn->set_envelope_params(0, 0);
216 m_sn->set_enable(1);
217 m_sn->add_route(ALL_OUTPUTS, "mono", 1.0);
218 }
219