Debian Codegraph @

src/engine/platform/sound/ymfm/ymfm_opl.cpp

raw
1 // BSD 3-Clause License
2 //
3 // Copyright (c) 2021, Aaron Giles
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this
10 // list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice,
13 // this list of conditions and the following disclaimer in the documentation
14 // and/or other materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #include "ymfm_opl.h"
32 #include "ymfm_fm.ipp"
33
34 namespace ymfm
35 {
36
37 //-------------------------------------------------
38 // opl_key_scale_atten - converts an
39 // OPL concatenated block (3 bits) and fnum
40 // (10 bits) into an attenuation offset; values
41 // here are for 6dB/octave, in 0.75dB units
42 // (matching total level LSB)
43 //-------------------------------------------------
44
45 inline uint32_t opl_key_scale_atten(uint32_t block, uint32_t fnum_4msb)
46 {
47 // this table uses the top 4 bits of FNUM and are the maximal values
48 // (for when block == 7). Values for other blocks can be computed by
49 // subtracting 8 for each block below 7.
50 static uint8_t const fnum_to_atten[16] = { 0,24,32,37,40,43,45,47,48,50,51,52,53,54,55,56 };
51 int32_t result = fnum_to_atten[fnum_4msb] - 8 * (block ^ 7);
52 return std::max<int32_t>(0, result);
53 }
54
55
56 //*********************************************************
57 // OPL REGISTERS
58 //*********************************************************
59
60 //-------------------------------------------------
61 // opl_registers_base - constructor
62 //-------------------------------------------------
63
64 template<int Revision>
65 opl_registers_base<Revision>::opl_registers_base() :
66 m_lfo_am_counter(0),
67 m_lfo_pm_counter(0),
68 m_noise_lfsr(1),
69 m_lfo_am(0)
70 {
71 // create these pointers to appease overzealous compilers checking array
72 // bounds in unreachable code (looking at you, clang)
73 uint16_t *wf0 = &m_waveform[0][0];
74 uint16_t *wf1 = &m_waveform[1 % WAVEFORMS][0];
75 uint16_t *wf2 = &m_waveform[2 % WAVEFORMS][0];
76 uint16_t *wf3 = &m_waveform[3 % WAVEFORMS][0];
77 uint16_t *wf4 = &m_waveform[4 % WAVEFORMS][0];
78 uint16_t *wf5 = &m_waveform[5 % WAVEFORMS][0];
79 uint16_t *wf6 = &m_waveform[6 % WAVEFORMS][0];
80 uint16_t *wf7 = &m_waveform[7 % WAVEFORMS][0];
81
82 // create the waveforms
83 for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++)
84 wf0[index] = abs_sin_attenuation(index) | (bitfield(index, 9) << 15);
85
86 if (WAVEFORMS >= 4)
87 {
88 uint16_t zeroval = wf0[0];
89 for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++)
90 {
91 wf1[index] = bitfield(index, 9) ? zeroval : wf0[index];
92 wf2[index] = wf0[index] & 0x7fff;
93 wf3[index] = bitfield(index, 8) ? zeroval : (wf0[index] & 0x7fff);
94 if (WAVEFORMS >= 8)
95 {
96 wf4[index] = bitfield(index, 9) ? zeroval : wf0[index * 2];
97 wf5[index] = bitfield(index, 9) ? zeroval : wf0[(index * 2) & 0x1ff];
98 wf6[index] = bitfield(index, 9) << 15;
99 wf7[index] = (bitfield(index, 9) ? (index ^ 0x13ff) : index) << 3;
100 }
101 }
102 }
103
104 // OPL3/OPL4 have dynamic operators, so initialize the fourop_enable value here
105 // since operator_map() is called right away, prior to reset()
106 if (Revision > 2)
107 m_regdata[0x104 % REGISTERS] = 0;
108 }
109
110
111 //-------------------------------------------------
112 // reset - reset to initial state
113 //-------------------------------------------------
114
115 template<int Revision>
116 void opl_registers_base<Revision>::reset()
117 {
118 std::fill_n(&m_regdata[0], REGISTERS, 0);
119 }
120
121
122 //-------------------------------------------------
123 // save_restore - save or restore the data
124 //-------------------------------------------------
125
126 template<int Revision>
127 void opl_registers_base<Revision>::save_restore(ymfm_saved_state &state)
128 {
129 state.save_restore(m_lfo_am_counter);
130 state.save_restore(m_lfo_pm_counter);
131 state.save_restore(m_lfo_am);
132 state.save_restore(m_noise_lfsr);
133 state.save_restore(m_regdata);
134 }
135
136
137 //-------------------------------------------------
138 // operator_map - return an array of operator
139 // indices for each channel; for OPL this is fixed
140 //-------------------------------------------------
141
142 template<int Revision>
143 void opl_registers_base<Revision>::operator_map(operator_mapping &dest) const
144 {
145 if (Revision <= 2)
146 {
147 // OPL/OPL2 has a fixed map, all 2 operators
148 static const operator_mapping s_fixed_map =
149 { {
150 operator_list( 0, 3 ), // Channel 0 operators
151 operator_list( 1, 4 ), // Channel 1 operators
152 operator_list( 2, 5 ), // Channel 2 operators
153 operator_list( 6, 9 ), // Channel 3 operators
154 operator_list( 7, 10 ), // Channel 4 operators
155 operator_list( 8, 11 ), // Channel 5 operators
156 operator_list( 12, 15 ), // Channel 6 operators
157 operator_list( 13, 16 ), // Channel 7 operators
158 operator_list( 14, 17 ), // Channel 8 operators
159 } };
160 dest = s_fixed_map;
161 }
162 else
163 {
164 // OPL3/OPL4 can be configured for 2 or 4 operators
165 uint32_t fourop = fourop_enable();
166
167 dest.chan[ 0] = bitfield(fourop, 0) ? operator_list( 0, 3, 6, 9 ) : operator_list( 0, 3 );
168 dest.chan[ 1] = bitfield(fourop, 1) ? operator_list( 1, 4, 7, 10 ) : operator_list( 1, 4 );
169 dest.chan[ 2] = bitfield(fourop, 2) ? operator_list( 2, 5, 8, 11 ) : operator_list( 2, 5 );
170 dest.chan[ 3] = bitfield(fourop, 0) ? operator_list() : operator_list( 6, 9 );
171 dest.chan[ 4] = bitfield(fourop, 1) ? operator_list() : operator_list( 7, 10 );
172 dest.chan[ 5] = bitfield(fourop, 2) ? operator_list() : operator_list( 8, 11 );
173 dest.chan[ 6] = operator_list( 12, 15 );
174 dest.chan[ 7] = operator_list( 13, 16 );
175 dest.chan[ 8] = operator_list( 14, 17 );
176
177 dest.chan[ 9] = bitfield(fourop, 3) ? operator_list( 18, 21, 24, 27 ) : operator_list( 18, 21 );
178 dest.chan[10] = bitfield(fourop, 4) ? operator_list( 19, 22, 25, 28 ) : operator_list( 19, 22 );
179 dest.chan[11] = bitfield(fourop, 5) ? operator_list( 20, 23, 26, 29 ) : operator_list( 20, 23 );
180 dest.chan[12] = bitfield(fourop, 3) ? operator_list() : operator_list( 24, 27 );
181 dest.chan[13] = bitfield(fourop, 4) ? operator_list() : operator_list( 25, 28 );
182 dest.chan[14] = bitfield(fourop, 5) ? operator_list() : operator_list( 26, 29 );
183 dest.chan[15] = operator_list( 30, 33 );
184 dest.chan[16] = operator_list( 31, 34 );
185 dest.chan[17] = operator_list( 32, 35 );
186 }
187 }
188
189
190 //-------------------------------------------------
191 // write - handle writes to the register array
192 //-------------------------------------------------
193
194 template<int Revision>
195 bool opl_registers_base<Revision>::write(uint16_t index, uint8_t data, uint32_t &channel, uint32_t &opmask)
196 {
197 assert(index < REGISTERS);
198
199 // writes to the mode register with high bit set ignore the low bits
200 if (index == REG_MODE && bitfield(data, 7) != 0)
201 m_regdata[index] |= 0x80;
202 else
203 m_regdata[index] = data;
204
205 // handle writes to the rhythm keyons
206 if (index == 0xbd)
207 {
208 channel = RHYTHM_CHANNEL;
209 opmask = bitfield(data, 5) ? bitfield(data, 0, 5) : 0;
210 return true;
211 }
212
213 // handle writes to the channel keyons
214 if ((index & 0xf0) == 0xb0)
215 {
216 channel = index & 0x0f;
217 if (channel < 9)
218 {
219 if (IsOpl3Plus)
220 channel += 9 * bitfield(index, 8);
221 opmask = bitfield(data, 5) ? 15 : 0;
222 return true;
223 }
224 }
225 return false;
226 }
227
228
229 //-------------------------------------------------
230 // clock_noise_and_lfo - clock the noise and LFO,
231 // handling clock division, depth, and waveform
232 // computations
233 //-------------------------------------------------
234
235 static int32_t opl_clock_noise_and_lfo(uint32_t &noise_lfsr, uint16_t &lfo_am_counter, uint16_t &lfo_pm_counter, uint8_t &lfo_am, uint32_t am_depth, uint32_t pm_depth)
236 {
237 // OPL has a 23-bit noise generator for the rhythm section, running at
238 // a constant rate, used only for percussion input
239 noise_lfsr <<= 1;
240 noise_lfsr |= bitfield(noise_lfsr, 23) ^ bitfield(noise_lfsr, 9) ^ bitfield(noise_lfsr, 8) ^ bitfield(noise_lfsr, 1);
241
242 // OPL has two fixed-frequency LFOs, one for AM, one for PM
243
244 // the AM LFO has 210*64 steps; at a nominal 50kHz output,
245 // this equates to a period of 50000/(210*64) = 3.72Hz
246 uint32_t am_counter = lfo_am_counter++;
247 if (am_counter >= 210*64 - 1)
248 lfo_am_counter = 0;
249
250 // low 8 bits are fractional; depth 0 is divided by 2, while depth 1 is times 2
251 int shift = 9 - 2 * am_depth;
252
253 // AM value is the upper bits of the value, inverted across the midpoint
254 // to produce a triangle
255 lfo_am = ((am_counter < 105*64) ? am_counter : (210*64+63 - am_counter)) >> shift;
256
257 // the PM LFO has 8192 steps, or a nominal period of 6.1Hz
258 uint32_t pm_counter = lfo_pm_counter++;
259
260 // PM LFO is broken into 8 chunks, each lasting 1024 steps; the PM value
261 // depends on the upper bits of FNUM, so this value is a fraction and
262 // sign to apply to that value, as a 1.3 value
263 static int8_t const pm_scale[8] = { 8, 4, 0, -4, -8, -4, 0, 4 };
264 return pm_scale[bitfield(pm_counter, 10, 3)] >> (pm_depth ^ 1);
265 }
266
267 template<int Revision>
268 int32_t opl_registers_base<Revision>::clock_noise_and_lfo()
269 {
270 return opl_clock_noise_and_lfo(m_noise_lfsr, m_lfo_am_counter, m_lfo_pm_counter, m_lfo_am, lfo_am_depth(), lfo_pm_depth());
271 }
272
273
274 //-------------------------------------------------
275 // cache_operator_data - fill the operator cache
276 // with prefetched data; note that this code is
277 // also used by ymopna_registers, so it must
278 // handle upper channels cleanly
279 //-------------------------------------------------
280
281 template<int Revision>
282 void opl_registers_base<Revision>::cache_operator_data(uint32_t choffs, uint32_t opoffs, opdata_cache &cache)
283 {
284 // set up the easy stuff
285 cache.waveform = &m_waveform[op_waveform(opoffs) % WAVEFORMS][0];
286
287 // get frequency from the channel
288 uint32_t block_freq = cache.block_freq = ch_block_freq(choffs);
289
290 // compute the keycode: block_freq is:
291 //
292 // 111 |
293 // 21098|76543210
294 // BBBFF|FFFFFFFF
295 // ^^^??
296 //
297 // the 4-bit keycode uses the top 3 bits plus one of the next two bits
298 uint32_t keycode = bitfield(block_freq, 10, 3) << 1;
299
300 // lowest bit is determined by note_select(); note that it is
301 // actually reversed from what the manual says, however
302 keycode |= bitfield(block_freq, 9 - note_select(), 1);
303
304 // no detune adjustment on OPL
305 cache.detune = 0;
306
307 // multiple value, as an x.1 value (0 means 0.5)
308 // replace the low bit with a table lookup to give 0,1,2,3,4,5,6,7,8,9,10,10,12,12,15,15
309 uint32_t multiple = op_multiple(opoffs);
310 cache.multiple = ((multiple & 0xe) | bitfield(0xc2aa, multiple)) * 2;
311 if (cache.multiple == 0)
312 cache.multiple = 1;
313
314 // phase step, or PHASE_STEP_DYNAMIC if PM is active; this depends on block_freq, detune,
315 // and multiple, so compute it after we've done those
316 if (op_lfo_pm_enable(opoffs) == 0)
317 cache.phase_step = compute_phase_step(choffs, opoffs, cache, 0);
318 else
319 cache.phase_step = opdata_cache::PHASE_STEP_DYNAMIC;
320
321 // total level, scaled by 8
322 cache.total_level = op_total_level(opoffs) << 3;
323
324 // pre-add key scale level
325 uint32_t ksl = op_ksl(opoffs);
326 if (ksl != 0)
327 cache.total_level += opl_key_scale_atten(bitfield(block_freq, 10, 3), bitfield(block_freq, 6, 4)) << ksl;
328
329 // 4-bit sustain level, but 15 means 31 so effectively 5 bits
330 cache.eg_sustain = op_sustain_level(opoffs);
331 cache.eg_sustain |= (cache.eg_sustain + 1) & 0x10;
332 cache.eg_sustain <<= 5;
333
334 // determine KSR adjustment for enevlope rates
335 uint32_t ksrval = keycode >> (2 * (op_ksr(opoffs) ^ 1));
336 cache.eg_rate[EG_ATTACK] = effective_rate(op_attack_rate(opoffs) * 4, ksrval);
337 cache.eg_rate[EG_DECAY] = effective_rate(op_decay_rate(opoffs) * 4, ksrval);
338 cache.eg_rate[EG_SUSTAIN] = op_eg_sustain(opoffs) ? 0 : effective_rate(op_release_rate(opoffs) * 4, ksrval);
339 cache.eg_rate[EG_RELEASE] = effective_rate(op_release_rate(opoffs) * 4, ksrval);
340 cache.eg_rate[EG_DEPRESS] = 0x3f;
341 }
342
343
344 //-------------------------------------------------
345 // compute_phase_step - compute the phase step
346 //-------------------------------------------------
347
348 static uint32_t opl_compute_phase_step(uint32_t block_freq, uint32_t multiple, int32_t lfo_raw_pm)
349 {
350 // OPL phase calculation has no detuning, but uses FNUMs like
351 // the OPN version, and computes PM a bit differently
352
353 // extract frequency number as a 12-bit fraction
354 uint32_t fnum = bitfield(block_freq, 0, 10) << 2;
355
356 // apply the phase adjustment based on the upper 3 bits
357 // of FNUM and the PM depth parameters
358 fnum += (lfo_raw_pm * bitfield(block_freq, 7, 3)) >> 1;
359
360 // keep fnum to 12 bits
361 fnum &= 0xfff;
362
363 // apply block shift to compute phase step
364 uint32_t block = bitfield(block_freq, 10, 3);
365 uint32_t phase_step = (fnum << block) >> 2;
366
367 // apply frequency multiplier (which is cached as an x.1 value)
368 return (phase_step * multiple) >> 1;
369 }
370
371 template<int Revision>
372 uint32_t opl_registers_base<Revision>::compute_phase_step(uint32_t choffs, uint32_t opoffs, opdata_cache const &cache, int32_t lfo_raw_pm)
373 {
374 return opl_compute_phase_step(cache.block_freq, cache.multiple, op_lfo_pm_enable(opoffs) ? lfo_raw_pm : 0);
375 }
376
377
378 //-------------------------------------------------
379 // log_keyon - log a key-on event
380 //-------------------------------------------------
381
382 template<int Revision>
383 std::string opl_registers_base<Revision>::log_keyon(uint32_t choffs, uint32_t opoffs)
384 {
385 return "";
386 }
387
388
389 //*********************************************************
390 // OPLL SPECIFICS
391 //*********************************************************
392
393 //-------------------------------------------------
394 // opll_registers - constructor
395 //-------------------------------------------------
396
397 opll_registers::opll_registers() :
398 m_lfo_am_counter(0),
399 m_lfo_pm_counter(0),
400 m_noise_lfsr(1),
401 m_lfo_am(0)
402 {
403 // create the waveforms
404 for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++)
405 m_waveform[0][index] = abs_sin_attenuation(index) | (bitfield(index, 9) << 15);
406
407 uint16_t zeroval = m_waveform[0][0];
408 for (uint32_t index = 0; index < WAVEFORM_LENGTH; index++)
409 m_waveform[1][index] = bitfield(index, 9) ? zeroval : m_waveform[0][index];
410
411 // initialize the instruments to something sane
412 for (uint32_t choffs = 0; choffs < CHANNELS; choffs++)
413 m_chinst[choffs] = &m_regdata[0];
414 for (uint32_t opoffs = 0; opoffs < OPERATORS; opoffs++)
415 m_opinst[opoffs] = &m_regdata[bitfield(opoffs, 0)];
416 }
417
418
419 //-------------------------------------------------
420 // reset - reset to initial state
421 //-------------------------------------------------
422
423 void opll_registers::reset()
424 {
425 std::fill_n(&m_regdata[0], REGISTERS, 0);
426 }
427
428
429 //-------------------------------------------------
430 // save_restore - save or restore the data
431 //-------------------------------------------------
432
433 void opll_registers::save_restore(ymfm_saved_state &state)
434 {
435 state.save_restore(m_lfo_am_counter);
436 state.save_restore(m_lfo_pm_counter);
437 state.save_restore(m_lfo_am);
438 state.save_restore(m_noise_lfsr);
439 state.save_restore(m_regdata);
440 }
441
442
443 //-------------------------------------------------
444 // operator_map - return an array of operator
445 // indices for each channel; for OPLL this is fixed
446 //-------------------------------------------------
447
448 void opll_registers::operator_map(operator_mapping &dest) const
449 {
450 static const operator_mapping s_fixed_map =
451 { {
452 operator_list( 0, 1 ), // Channel 0 operators
453 operator_list( 2, 3 ), // Channel 1 operators
454 operator_list( 4, 5 ), // Channel 2 operators
455 operator_list( 6, 7 ), // Channel 3 operators
456 operator_list( 8, 9 ), // Channel 4 operators
457 operator_list( 10, 11 ), // Channel 5 operators
458 operator_list( 12, 13 ), // Channel 6 operators
459 operator_list( 14, 15 ), // Channel 7 operators
460 operator_list( 16, 17 ), // Channel 8 operators
461 } };
462 dest = s_fixed_map;
463 }
464
465
466 //-------------------------------------------------
467 // write - handle writes to the register array;
468 // note that this code is also used by
469 // ymopl3_registers, so it must handle upper
470 // channels cleanly
471 //-------------------------------------------------
472
473 bool opll_registers::write(uint16_t index, uint8_t data, uint32_t &channel, uint32_t &opmask)
474 {
475 // unclear the address is masked down to 6 bits or if writes above
476 // the register top are ignored; assuming the latter for now
477 if (index >= REGISTERS)
478 return false;
479
480 // write the new data
481 m_regdata[index] = data;
482
483 // handle writes to the rhythm keyons
484 if (index == 0x0e)
485 {
486 channel = RHYTHM_CHANNEL;
487 opmask = bitfield(data, 5) ? bitfield(data, 0, 5) : 0;
488 return true;
489 }
490
491 // handle writes to the channel keyons
492 if ((index & 0xf0) == 0x20)
493 {
494 channel = index & 0x0f;
495 if (channel < CHANNELS)
496 {
497 opmask = bitfield(data, 4) ? 3 : 0;
498 return true;
499 }
500 }
501 return false;
502 }
503
504
505 //-------------------------------------------------
506 // clock_noise_and_lfo - clock the noise and LFO,
507 // handling clock division, depth, and waveform
508 // computations
509 //-------------------------------------------------
510
511 int32_t opll_registers::clock_noise_and_lfo()
512 {
513 // implementation is the same as OPL with fixed depths
514 return opl_clock_noise_and_lfo(m_noise_lfsr, m_lfo_am_counter, m_lfo_pm_counter, m_lfo_am, 1, 1);
515 }
516
517
518 //-------------------------------------------------
519 // cache_operator_data - fill the operator cache
520 // with prefetched data; note that this code is
521 // also used by ymopna_registers, so it must
522 // handle upper channels cleanly
523 //-------------------------------------------------
524
525 void opll_registers::cache_operator_data(uint32_t choffs, uint32_t opoffs, opdata_cache &cache)
526 {
527 // first set up the instrument data
528 uint32_t instrument = ch_instrument(choffs);
529 if (rhythm_enable() && choffs >= 6)
530 m_chinst[choffs] = &m_instdata[8 * (15 + (choffs - 6))];
531 else
532 m_chinst[choffs] = (instrument == 0) ? &m_regdata[0] : &m_instdata[8 * (instrument - 1)];
533 m_opinst[opoffs] = m_chinst[choffs] + bitfield(opoffs, 0);
534
535 // set up the easy stuff
536 cache.waveform = &m_waveform[op_waveform(opoffs) % WAVEFORMS][0];
537
538 // get frequency from the channel
539 uint32_t block_freq = cache.block_freq = ch_block_freq(choffs);
540
541 // compute the keycode: block_freq is:
542 //
543 // 11 |
544 // 1098|76543210
545 // BBBF|FFFFFFFF
546 // ^^^^
547 //
548 // the 4-bit keycode uses the top 4 bits
549 uint32_t keycode = bitfield(block_freq, 8, 4);
550
551 // no detune adjustment on OPLL
552 cache.detune = 0;
553
554 // multiple value, as an x.1 value (0 means 0.5)
555 // replace the low bit with a table lookup to give 0,1,2,3,4,5,6,7,8,9,10,10,12,12,15,15
556 uint32_t multiple = op_multiple(opoffs);
557 cache.multiple = ((multiple & 0xe) | bitfield(0xc2aa, multiple)) * 2;
558 if (cache.multiple == 0)
559 cache.multiple = 1;
560
561 // phase step, or PHASE_STEP_DYNAMIC if PM is active; this depends on
562 // block_freq, detune, and multiple, so compute it after we've done those
563 if (op_lfo_pm_enable(opoffs) == 0)
564 cache.phase_step = compute_phase_step(choffs, opoffs, cache, 0);
565 else
566 cache.phase_step = opdata_cache::PHASE_STEP_DYNAMIC;
567
568 // total level, scaled by 8; for non-rhythm operator 0, this is the total
569 // level from the instrument data; for other operators it is 4*volume
570 if (bitfield(opoffs, 0) == 1 || (rhythm_enable() && choffs >= 7))
571 cache.total_level = op_volume(opoffs) * 4;
572 else
573 cache.total_level = ch_total_level(choffs);
574 cache.total_level <<= 3;
575
576 // pre-add key scale level
577 uint32_t ksl = op_ksl(opoffs);
578 if (ksl != 0)
579 cache.total_level += opl_key_scale_atten(bitfield(block_freq, 9, 3), bitfield(block_freq, 5, 4)) << ksl;
580
581 // 4-bit sustain level, but 15 means 31 so effectively 5 bits
582 cache.eg_sustain = op_sustain_level(opoffs);
583 cache.eg_sustain |= (cache.eg_sustain + 1) & 0x10;
584 cache.eg_sustain <<= 5;
585
586 // The envelope diagram in the YM2413 datasheet gives values for these
587 // in ms from 0->48dB. The attack/decay tables give values in ms from
588 // 0->96dB, so to pick an equivalent decay rate, we want to find the
589 // closest match that is 2x the 0->48dB value:
590 //
591 // DP = 10ms (0->48db) -> 20ms (0->96db); decay of 12 gives 19.20ms
592 // RR = 310ms (0->48db) -> 620ms (0->96db); decay of 7 gives 613.76ms
593 // RS = 1200ms (0->48db) -> 2400ms (0->96db); decay of 5 gives 2455.04ms
594 //
595 // The envelope diagram for percussive sounds (eg_sustain() == 0) also uses
596 // "RR" to mean both the constant RR above and the Release Rate specified in
597 // the instrument data. In this case, Relief Pitcher's credit sound bears out
598 // that the Release Rate is used during sustain, and that the constant RR
599 // (or RS) is used during the release phase.
600 constexpr uint8_t DP = 12 * 4;
601 constexpr uint8_t RR = 7 * 4;
602 constexpr uint8_t RS = 5 * 4;
603
604 // determine KSR adjustment for envelope rates
605 uint32_t ksrval = keycode >> (2 * (op_ksr(opoffs) ^ 1));
606 cache.eg_rate[EG_DEPRESS] = DP;
607 cache.eg_rate[EG_ATTACK] = effective_rate(op_attack_rate(opoffs) * 4, ksrval);
608 cache.eg_rate[EG_DECAY] = effective_rate(op_decay_rate(opoffs) * 4, ksrval);
609 if (op_eg_sustain(opoffs))
610 {
611 cache.eg_rate[EG_SUSTAIN] = 0;
612 cache.eg_rate[EG_RELEASE] = ch_sustain(choffs) ? RS : effective_rate(op_release_rate(opoffs) * 4, ksrval);
613 }
614 else
615 {
616 cache.eg_rate[EG_SUSTAIN] = effective_rate(op_release_rate(opoffs) * 4, ksrval);
617 cache.eg_rate[EG_RELEASE] = ch_sustain(choffs) ? RS : RR;
618 }
619 }
620
621
622 //-------------------------------------------------
623 // compute_phase_step - compute the phase step
624 //-------------------------------------------------
625
626 uint32_t opll_registers::compute_phase_step(uint32_t choffs, uint32_t opoffs, opdata_cache const &cache, int32_t lfo_raw_pm)
627 {
628 // phase step computation is the same as OPL but the block_freq has one
629 // more bit, which we shift in
630 return opl_compute_phase_step(cache.block_freq << 1, cache.multiple, op_lfo_pm_enable(opoffs) ? lfo_raw_pm : 0);
631 }
632
633
634 //-------------------------------------------------
635 // log_keyon - log a key-on event
636 //-------------------------------------------------
637
638 std::string opll_registers::log_keyon(uint32_t choffs, uint32_t opoffs)
639 {
640 return "";
641 }
642
643
644
645 //*********************************************************
646 // YM3526
647 //*********************************************************
648
649 //-------------------------------------------------
650 // ym3526 - constructor
651 //-------------------------------------------------
652
653 ym3526::ym3526(ymfm_interface &intf) :
654 m_address(0),
655 m_fm(intf)
656 {
657 }
658
659
660 //-------------------------------------------------
661 // reset - reset the system
662 //-------------------------------------------------
663
664 void ym3526::reset()
665 {
666 // reset the engines
667 m_fm.reset();
668 }
669
670
671 //-------------------------------------------------
672 // save_restore - save or restore the data
673 //-------------------------------------------------
674
675 void ym3526::save_restore(ymfm_saved_state &state)
676 {
677 state.save_restore(m_address);
678 m_fm.save_restore(state);
679 }
680
681
682 //-------------------------------------------------
683 // read_status - read the status register
684 //-------------------------------------------------
685
686 uint8_t ym3526::read_status()
687 {
688 return m_fm.status() | 0x06;
689 }
690
691
692 //-------------------------------------------------
693 // read - handle a read from the device
694 //-------------------------------------------------
695
696 uint8_t ym3526::read(uint32_t offset)
697 {
698 uint8_t result = 0xff;
699 switch (offset & 1)
700 {
701 case 0: // status port
702 result = read_status();
703 break;
704
705 case 1: // when A0=1 datasheet says "the data on the bus are not guaranteed"
706 break;
707 }
708 return result;
709 }
710
711
712 //-------------------------------------------------
713 // write_address - handle a write to the address
714 // register
715 //-------------------------------------------------
716
717 void ym3526::write_address(uint8_t data)
718 {
719 // YM3526 doesn't expose a busy signal, and the datasheets don't indicate
720 // delays, but all other OPL chips need 12 cycles for address writes
721 m_fm.intf().ymfm_set_busy_end(12 * m_fm.clock_prescale());
722
723 // just set the address
724 m_address = data;
725 }
726
727
728 //-------------------------------------------------
729 // write - handle a write to the register
730 // interface
731 //-------------------------------------------------
732
733 void ym3526::write_data(uint8_t data)
734 {
735 // YM3526 doesn't expose a busy signal, and the datasheets don't indicate
736 // delays, but all other OPL chips need 84 cycles for data writes
737 m_fm.intf().ymfm_set_busy_end(84 * m_fm.clock_prescale());
738
739 // write to FM
740 m_fm.write(m_address, data);
741 }
742
743
744 //-------------------------------------------------
745 // write - handle a write to the register
746 // interface
747 //-------------------------------------------------
748
749 void ym3526::write(uint32_t offset, uint8_t data)
750 {
751 switch (offset & 1)
752 {
753 case 0: // address port
754 write_address(data);
755 break;
756
757 case 1: // data port
758 write_data(data);
759 break;
760 }
761 }
762
763
764 //-------------------------------------------------
765 // generate - generate samples of sound
766 //-------------------------------------------------
767
768 void ym3526::generate(output_data *output, uint32_t numsamples)
769 {
770 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
771 {
772 // clock the system
773 m_fm.clock(fm_engine::ALL_CHANNELS);
774
775 // update the FM content; mixing details for YM3526 need verification
776 m_fm.output(output->clear(), 1, 32767, fm_engine::ALL_CHANNELS);
777
778 // YM3526 uses an external DAC (YM3014) with mantissa/exponent format
779 // convert to 10.3 floating point value and back to simulate truncation
780 output->roundtrip_fp();
781 }
782 }
783
784
785
786 //*********************************************************
787 // Y8950
788 //*********************************************************
789
790 //-------------------------------------------------
791 // y8950 - constructor
792 //-------------------------------------------------
793
794 y8950::y8950(ymfm_interface &intf) :
795 m_address(0),
796 m_io_ddr(0),
797 m_fm(intf),
798 m_adpcm_b(intf)
799 {
800 }
801
802
803 //-------------------------------------------------
804 // reset - reset the system
805 //-------------------------------------------------
806
807 void y8950::reset()
808 {
809 // reset the engines
810 m_fm.reset();
811 m_adpcm_b.reset();
812 }
813
814
815 //-------------------------------------------------
816 // save_restore - save or restore the data
817 //-------------------------------------------------
818
819 void y8950::save_restore(ymfm_saved_state &state)
820 {
821 state.save_restore(m_address);
822 state.save_restore(m_io_ddr);
823 m_fm.save_restore(state);
824 }
825
826
827 //-------------------------------------------------
828 // read_status - read the status register
829 //-------------------------------------------------
830
831 uint8_t y8950::read_status()
832 {
833 // start with current FM status, masking out bits we might set
834 uint8_t status = m_fm.status() & ~(STATUS_ADPCM_B_EOS | STATUS_ADPCM_B_BRDY | STATUS_ADPCM_B_PLAYING);
835
836 // insert the live ADPCM status bits
837 uint8_t adpcm_status = m_adpcm_b.status();
838 if ((adpcm_status & adpcm_b_channel::STATUS_EOS) != 0)
839 status |= STATUS_ADPCM_B_EOS;
840 if ((adpcm_status & adpcm_b_channel::STATUS_BRDY) != 0)
841 status |= STATUS_ADPCM_B_BRDY;
842 if ((adpcm_status & adpcm_b_channel::STATUS_PLAYING) != 0)
843 status |= STATUS_ADPCM_B_PLAYING;
844
845 // run it through the FM engine to handle interrupts for us
846 return m_fm.set_reset_status(status, ~status);
847 }
848
849
850 //-------------------------------------------------
851 // read_data - read the data port
852 //-------------------------------------------------
853
854 uint8_t y8950::read_data()
855 {
856 uint8_t result = 0xff;
857 switch (m_address)
858 {
859 case 0x05: // keyboard in
860 result = m_fm.intf().ymfm_external_read(ACCESS_IO, 1);
861 break;
862
863 case 0x09: // ADPCM data
864 case 0x1a:
865 result = m_adpcm_b.read(m_address - 0x07);
866 break;
867
868 case 0x19: // I/O data
869 result = m_fm.intf().ymfm_external_read(ACCESS_IO, 0);
870 break;
871
872 default:
873 debug::log_unexpected_read_write("Unexpected read from Y8950 data port %02X\n", m_address);
874 break;
875 }
876 return result;
877 }
878
879
880 //-------------------------------------------------
881 // read - handle a read from the device
882 //-------------------------------------------------
883
884 uint8_t y8950::read(uint32_t offset)
885 {
886 uint8_t result = 0xff;
887 switch (offset & 1)
888 {
889 case 0: // status port
890 result = read_status();
891 break;
892
893 case 1: // when A0=1 datasheet says "the data on the bus are not guaranteed"
894 result = read_data();
895 break;
896 }
897 return result;
898 }
899
900
901 //-------------------------------------------------
902 // write_address - handle a write to the address
903 // register
904 //-------------------------------------------------
905
906 void y8950::write_address(uint8_t data)
907 {
908 // Y8950 doesn't expose a busy signal, but it does indicate that
909 // address writes should be no faster than every 12 clocks
910 m_fm.intf().ymfm_set_busy_end(12 * m_fm.clock_prescale());
911
912 // just set the address
913 m_address = data;
914 }
915
916
917 //-------------------------------------------------
918 // write - handle a write to the register
919 // interface
920 //-------------------------------------------------
921
922 void y8950::write_data(uint8_t data)
923 {
924 // Y8950 doesn't expose a busy signal, but it does indicate that
925 // data writes should be no faster than every 12 clocks for
926 // registers 00-1A, or every 84 clocks for other registers
927 m_fm.intf().ymfm_set_busy_end(((m_address <= 0x1a) ? 12 : 84) * m_fm.clock_prescale());
928
929 // handle special addresses
930 switch (m_address)
931 {
932 case 0x04: // IRQ control
933 m_fm.write(m_address, data);
934 read_status();
935 break;
936
937 case 0x06: // keyboard out
938 m_fm.intf().ymfm_external_write(ACCESS_IO, 1, data);
939 break;
940
941 case 0x08: // split FM/ADPCM-B
942 m_adpcm_b.write(m_address - 0x07, (data & 0x0f) | 0x80);
943 m_fm.write(m_address, data & 0xc0);
944 break;
945
946 case 0x07: // ADPCM-B registers
947 case 0x09:
948 case 0x0a:
949 case 0x0b:
950 case 0x0c:
951 case 0x0d:
952 case 0x0e:
953 case 0x0f:
954 case 0x10:
955 case 0x11:
956 case 0x12:
957 case 0x15:
958 case 0x16:
959 case 0x17:
960 m_adpcm_b.write(m_address - 0x07, data);
961 break;
962
963 case 0x18: // I/O direction
964 m_io_ddr = data & 0x0f;
965 break;
966
967 case 0x19: // I/O data
968 m_fm.intf().ymfm_external_write(ACCESS_IO, 0, data & m_io_ddr);
969 break;
970
971 default: // everything else to FM
972 m_fm.write(m_address, data);
973 break;
974 }
975 }
976
977
978 //-------------------------------------------------
979 // write - handle a write to the register
980 // interface
981 //-------------------------------------------------
982
983 void y8950::write(uint32_t offset, uint8_t data)
984 {
985 switch (offset & 1)
986 {
987 case 0: // address port
988 write_address(data);
989 break;
990
991 case 1: // data port
992 write_data(data);
993 break;
994 }
995 }
996
997
998 //-------------------------------------------------
999 // generate - generate samples of sound
1000 //-------------------------------------------------
1001
1002 void y8950::generate(output_data *output, uint32_t numsamples)
1003 {
1004 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
1005 {
1006 // clock the system
1007 m_fm.clock(fm_engine::ALL_CHANNELS);
1008 m_adpcm_b.clock();
1009
1010 // update the FM content; clipping need verification
1011 m_fm.output(output->clear(), 1, 32767, fm_engine::ALL_CHANNELS);
1012
1013 // mix in the ADPCM; ADPCM-B is stereo, but only one channel
1014 // not sure how it's wired up internally
1015 m_adpcm_b.output(*output, 3);
1016
1017 // Y8950 uses an external DAC (YM3014) with mantissa/exponent format
1018 // convert to 10.3 floating point value and back to simulate truncation
1019 output->roundtrip_fp();
1020 }
1021 }
1022
1023
1024
1025 //*********************************************************
1026 // YM3812
1027 //*********************************************************
1028
1029 //-------------------------------------------------
1030 // ym3812 - constructor
1031 //-------------------------------------------------
1032
1033 ym3812::ym3812(ymfm_interface &intf) :
1034 m_address(0),
1035 m_fm(intf)
1036 {
1037 }
1038
1039
1040 //-------------------------------------------------
1041 // reset - reset the system
1042 //-------------------------------------------------
1043
1044 void ym3812::reset()
1045 {
1046 // reset the engines
1047 m_fm.reset();
1048 }
1049
1050
1051 //-------------------------------------------------
1052 // save_restore - save or restore the data
1053 //-------------------------------------------------
1054
1055 void ym3812::save_restore(ymfm_saved_state &state)
1056 {
1057 state.save_restore(m_address);
1058 m_fm.save_restore(state);
1059 }
1060
1061
1062 //-------------------------------------------------
1063 // read_status - read the status register
1064 //-------------------------------------------------
1065
1066 uint8_t ym3812::read_status()
1067 {
1068 return m_fm.status() | 0x06;
1069 }
1070
1071
1072 //-------------------------------------------------
1073 // read - handle a read from the device
1074 //-------------------------------------------------
1075
1076 uint8_t ym3812::read(uint32_t offset)
1077 {
1078 uint8_t result = 0xff;
1079 switch (offset & 1)
1080 {
1081 case 0: // status port
1082 result = read_status();
1083 break;
1084
1085 case 1: // "inhibit" according to datasheet
1086 break;
1087 }
1088 return result;
1089 }
1090
1091
1092 //-------------------------------------------------
1093 // write_address - handle a write to the address
1094 // register
1095 //-------------------------------------------------
1096
1097 void ym3812::write_address(uint8_t data)
1098 {
1099 // YM3812 doesn't expose a busy signal, but it does indicate that
1100 // address writes should be no faster than every 12 clocks
1101 m_fm.intf().ymfm_set_busy_end(12 * m_fm.clock_prescale());
1102
1103 // just set the address
1104 m_address = data;
1105 }
1106
1107
1108 //-------------------------------------------------
1109 // write - handle a write to the register
1110 // interface
1111 //-------------------------------------------------
1112
1113 void ym3812::write_data(uint8_t data)
1114 {
1115 // YM3812 doesn't expose a busy signal, but it does indicate that
1116 // data writes should be no faster than every 84 clocks
1117 m_fm.intf().ymfm_set_busy_end(84 * m_fm.clock_prescale());
1118
1119 // write to FM
1120 m_fm.write(m_address, data);
1121 }
1122
1123
1124 //-------------------------------------------------
1125 // write - handle a write to the register
1126 // interface
1127 //-------------------------------------------------
1128
1129 void ym3812::write(uint32_t offset, uint8_t data)
1130 {
1131 switch (offset & 1)
1132 {
1133 case 0: // address port
1134 write_address(data);
1135 break;
1136
1137 case 1: // data port
1138 write_data(data);
1139 break;
1140 }
1141 }
1142
1143
1144 //-------------------------------------------------
1145 // generate - generate samples of sound
1146 //-------------------------------------------------
1147
1148 void ym3812::generate(output_data *output, uint32_t numsamples)
1149 {
1150 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
1151 {
1152 // clock the system
1153 m_fm.clock(fm_engine::ALL_CHANNELS);
1154
1155 // update the FM content; mixing details for YM3812 need verification
1156 m_fm.output(output->clear(), 1, 32767, fm_engine::ALL_CHANNELS);
1157
1158 // YM3812 uses an external DAC (YM3014) with mantissa/exponent format
1159 // convert to 10.3 floating point value and back to simulate truncation
1160 output->roundtrip_fp();
1161 }
1162 }
1163
1164
1165
1166 //*********************************************************
1167 // YMF262
1168 //*********************************************************
1169
1170 //-------------------------------------------------
1171 // ymf262 - constructor
1172 //-------------------------------------------------
1173
1174 ymf262::ymf262(ymfm_interface &intf) :
1175 m_address(0),
1176 m_fm(intf)
1177 {
1178 }
1179
1180
1181 //-------------------------------------------------
1182 // reset - reset the system
1183 //-------------------------------------------------
1184
1185 void ymf262::reset()
1186 {
1187 // reset the engines
1188 m_fm.reset();
1189 }
1190
1191
1192 //-------------------------------------------------
1193 // save_restore - save or restore the data
1194 //-------------------------------------------------
1195
1196 void ymf262::save_restore(ymfm_saved_state &state)
1197 {
1198 state.save_restore(m_address);
1199 m_fm.save_restore(state);
1200 }
1201
1202
1203 //-------------------------------------------------
1204 // read_status - read the status register
1205 //-------------------------------------------------
1206
1207 uint8_t ymf262::read_status()
1208 {
1209 return m_fm.status();
1210 }
1211
1212
1213 //-------------------------------------------------
1214 // read - handle a read from the device
1215 //-------------------------------------------------
1216
1217 uint8_t ymf262::read(uint32_t offset)
1218 {
1219 uint8_t result = 0xff;
1220 switch (offset & 3)
1221 {
1222 case 0: // status port
1223 result = read_status();
1224 break;
1225
1226 case 1:
1227 case 2:
1228 case 3:
1229 debug::log_unexpected_read_write("Unexpected read from YMF262 offset %d\n", offset & 3);
1230 break;
1231 }
1232 return result;
1233 }
1234
1235
1236 //-------------------------------------------------
1237 // write_address - handle a write to the address
1238 // register
1239 //-------------------------------------------------
1240
1241 void ymf262::write_address(uint8_t data)
1242 {
1243 // YMF262 doesn't expose a busy signal, but it does indicate that
1244 // address writes should be no faster than every 32 clocks
1245 m_fm.intf().ymfm_set_busy_end(32 * m_fm.clock_prescale());
1246
1247 // just set the address
1248 m_address = data;
1249 }
1250
1251
1252 //-------------------------------------------------
1253 // write_data - handle a write to the data
1254 // register
1255 //-------------------------------------------------
1256
1257 void ymf262::write_data(uint8_t data)
1258 {
1259 // YMF262 doesn't expose a busy signal, but it does indicate that
1260 // data writes should be no faster than every 32 clocks
1261 m_fm.intf().ymfm_set_busy_end(32 * m_fm.clock_prescale());
1262
1263 // write to FM
1264 m_fm.write(m_address, data);
1265 }
1266
1267
1268 //-------------------------------------------------
1269 // write_address_hi - handle a write to the upper
1270 // address register
1271 //-------------------------------------------------
1272
1273 void ymf262::write_address_hi(uint8_t data)
1274 {
1275 // YMF262 doesn't expose a busy signal, but it does indicate that
1276 // address writes should be no faster than every 32 clocks
1277 m_fm.intf().ymfm_set_busy_end(32 * m_fm.clock_prescale());
1278
1279 // just set the address
1280 m_address = data | 0x100;
1281
1282 // tests reveal that in compatibility mode, upper bit is masked
1283 // except for register 0x105
1284 if (m_fm.regs().newflag() == 0 && m_address != 0x105)
1285 m_address &= 0xff;
1286 }
1287
1288
1289 //-------------------------------------------------
1290 // write - handle a write to the register
1291 // interface
1292 //-------------------------------------------------
1293
1294 void ymf262::write(uint32_t offset, uint8_t data)
1295 {
1296 switch (offset & 3)
1297 {
1298 case 0: // address port
1299 write_address(data);
1300 break;
1301
1302 case 1: // data port
1303 write_data(data);
1304 break;
1305
1306 case 2: // address port
1307 write_address_hi(data);
1308 break;
1309
1310 case 3: // data port
1311 write_data(data);
1312 break;
1313 }
1314 }
1315
1316
1317 //-------------------------------------------------
1318 // generate - generate samples of sound
1319 //-------------------------------------------------
1320
1321 void ymf262::generate(output_data *output, uint32_t numsamples)
1322 {
1323 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
1324 {
1325 // clock the system
1326 m_fm.clock(fm_engine::ALL_CHANNELS);
1327
1328 // update the FM content; mixing details for YMF262 need verification
1329 m_fm.output(output->clear(), 0, 32767, fm_engine::ALL_CHANNELS);
1330
1331 // YMF262 output is 16-bit offset serial via YAC512 DAC
1332 output->clamp16();
1333 }
1334 }
1335
1336
1337
1338 //*********************************************************
1339 // YMF289B
1340 //*********************************************************
1341
1342 // YMF289B is a YMF262 with the following changes:
1343 // * "Power down" mode added
1344 // * Bulk register clear added
1345 // * Busy flag added to the status register
1346 // * Shorter busy times
1347 // * All registers can be read
1348 // * Only 2 outputs exposed
1349
1350 //-------------------------------------------------
1351 // ymf289b - constructor
1352 //-------------------------------------------------
1353
1354 ymf289b::ymf289b(ymfm_interface &intf) :
1355 m_address(0),
1356 m_fm(intf)
1357 {
1358 }
1359
1360
1361 //-------------------------------------------------
1362 // reset - reset the system
1363 //-------------------------------------------------
1364
1365 void ymf289b::reset()
1366 {
1367 // reset the engines
1368 m_fm.reset();
1369 }
1370
1371
1372 //-------------------------------------------------
1373 // save_restore - save or restore the data
1374 //-------------------------------------------------
1375
1376 void ymf289b::save_restore(ymfm_saved_state &state)
1377 {
1378 state.save_restore(m_address);
1379 m_fm.save_restore(state);
1380 }
1381
1382
1383 //-------------------------------------------------
1384 // read_status - read the status register
1385 //-------------------------------------------------
1386
1387 uint8_t ymf289b::read_status()
1388 {
1389 uint8_t result = m_fm.status();
1390
1391 // YMF289B adds a busy flag
1392 if (ymf289b_mode() && m_fm.intf().ymfm_is_busy())
1393 result |= STATUS_BUSY_FLAGS;
1394 return result;
1395 }
1396
1397
1398 //-------------------------------------------------
1399 // read_data - read the data register
1400 //-------------------------------------------------
1401
1402 uint8_t ymf289b::read_data()
1403 {
1404 uint8_t result = 0xff;
1405
1406 // YMF289B can read register data back
1407 if (ymf289b_mode())
1408 result = m_fm.regs().read(m_address);
1409 return result;
1410 }
1411
1412
1413 //-------------------------------------------------
1414 // read - handle a read from the device
1415 //-------------------------------------------------
1416
1417 uint8_t ymf289b::read(uint32_t offset)
1418 {
1419 uint8_t result = 0xff;
1420 switch (offset & 3)
1421 {
1422 case 0: // status port
1423 result = read_status();
1424 break;
1425
1426 case 1: // data port
1427 result = read_data();
1428 break;
1429
1430 case 2:
1431 case 3:
1432 debug::log_unexpected_read_write("Unexpected read from YMF289B offset %d\n", offset & 3);
1433 break;
1434 }
1435 return result;
1436 }
1437
1438
1439 //-------------------------------------------------
1440 // write_address - handle a write to the address
1441 // register
1442 //-------------------------------------------------
1443
1444 void ymf289b::write_address(uint8_t data)
1445 {
1446 m_address = data;
1447
1448 // count busy time
1449 m_fm.intf().ymfm_set_busy_end(56);
1450 }
1451
1452
1453 //-------------------------------------------------
1454 // write_data - handle a write to the data
1455 // register
1456 //-------------------------------------------------
1457
1458 void ymf289b::write_data(uint8_t data)
1459 {
1460 // write to FM
1461 m_fm.write(m_address, data);
1462
1463 // writes to 0x108 with the CLR flag set clear the registers
1464 if (m_address == 0x108 && bitfield(data, 2) != 0)
1465 m_fm.regs().reset();
1466
1467 // count busy time
1468 m_fm.intf().ymfm_set_busy_end(56);
1469 }
1470
1471
1472 //-------------------------------------------------
1473 // write_address_hi - handle a write to the upper
1474 // address register
1475 //-------------------------------------------------
1476
1477 void ymf289b::write_address_hi(uint8_t data)
1478 {
1479 // just set the address
1480 m_address = data | 0x100;
1481
1482 // tests reveal that in compatibility mode, upper bit is masked
1483 // except for register 0x105
1484 if (m_fm.regs().newflag() == 0 && m_address != 0x105)
1485 m_address &= 0xff;
1486
1487 // count busy time
1488 m_fm.intf().ymfm_set_busy_end(56);
1489 }
1490
1491
1492 //-------------------------------------------------
1493 // write - handle a write to the register
1494 // interface
1495 //-------------------------------------------------
1496
1497 void ymf289b::write(uint32_t offset, uint8_t data)
1498 {
1499 switch (offset & 3)
1500 {
1501 case 0: // address port
1502 write_address(data);
1503 break;
1504
1505 case 1: // data port
1506 write_data(data);
1507 break;
1508
1509 case 2: // address port
1510 write_address_hi(data);
1511 break;
1512
1513 case 3: // data port
1514 write_data(data);
1515 break;
1516 }
1517 }
1518
1519
1520 //-------------------------------------------------
1521 // generate - generate samples of sound
1522 //-------------------------------------------------
1523
1524 void ymf289b::generate(output_data *output, uint32_t numsamples)
1525 {
1526 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
1527 {
1528 // clock the system
1529 m_fm.clock(fm_engine::ALL_CHANNELS);
1530
1531 // update the FM content; mixing details for YMF262 need verification
1532 fm_engine::output_data full;
1533 m_fm.output(full.clear(), 0, 32767, fm_engine::ALL_CHANNELS);
1534
1535 // YMF278B output is 16-bit offset serial via YAC512 DAC, but
1536 // only 2 of the 4 outputs are exposed
1537 output->data[0] = full.data[0];
1538 output->data[1] = full.data[1];
1539 output->clamp16();
1540 }
1541 }
1542
1543
1544
1545 //*********************************************************
1546 // YMF278B
1547 //*********************************************************
1548
1549 //-------------------------------------------------
1550 // ymf278b - constructor
1551 //-------------------------------------------------
1552
1553 ymf278b::ymf278b(ymfm_interface &intf) :
1554 m_address(0),
1555 m_fm_pos(0),
1556 m_load_remaining(0),
1557 m_next_status_id(false),
1558 m_fm(intf),
1559 m_pcm(intf)
1560 {
1561 }
1562
1563
1564 //-------------------------------------------------
1565 // reset - reset the system
1566 //-------------------------------------------------
1567
1568 void ymf278b::reset()
1569 {
1570 // reset the engines
1571 m_fm.reset();
1572 m_pcm.reset();
1573
1574 // next status read will return ID
1575 m_next_status_id = true;
1576 }
1577
1578
1579 //-------------------------------------------------
1580 // save_restore - save or restore the data
1581 //-------------------------------------------------
1582
1583 void ymf278b::save_restore(ymfm_saved_state &state)
1584 {
1585 state.save_restore(m_address);
1586 state.save_restore(m_fm_pos);
1587 state.save_restore(m_load_remaining);
1588 state.save_restore(m_next_status_id);
1589 m_fm.save_restore(state);
1590 m_pcm.save_restore(state);
1591 }
1592
1593
1594 //-------------------------------------------------
1595 // read_status - read the status register
1596 //-------------------------------------------------
1597
1598 uint8_t ymf278b::read_status()
1599 {
1600 uint8_t result;
1601
1602 // first status read after initialization returns a chip ID, which
1603 // varies based on the "new" flags, indicating the mode
1604 if (m_next_status_id)
1605 {
1606 if (m_fm.regs().new2flag())
1607 result = 0x02;
1608 else if (m_fm.regs().newflag())
1609 result = 0x00;
1610 else
1611 result = 0x06;
1612 m_next_status_id = false;
1613 }
1614 else
1615 {
1616 result = m_fm.status();
1617 if (m_fm.intf().ymfm_is_busy())
1618 result |= STATUS_BUSY;
1619 if (m_load_remaining != 0)
1620 result |= STATUS_LD;
1621
1622 // if new2 flag is not set, we're in OPL2 or OPL3 mode
1623 if (!m_fm.regs().new2flag())
1624 result &= ~(STATUS_BUSY | STATUS_LD);
1625 }
1626 return result;
1627 }
1628
1629
1630 //-------------------------------------------------
1631 // write_data_pcm - handle a write to the PCM data
1632 // register
1633 //-------------------------------------------------
1634
1635 uint8_t ymf278b::read_data_pcm()
1636 {
1637 // read from PCM
1638 if (bitfield(m_address, 9) != 0)
1639 {
1640 uint8_t result = m_pcm.read(m_address & 0xff);
1641 if ((m_address & 0xff) == 0x02)
1642 result |= 0x20;
1643
1644 return result;
1645 }
1646 return 0;
1647 }
1648
1649
1650 //-------------------------------------------------
1651 // read - handle a read from the device
1652 //-------------------------------------------------
1653
1654 uint8_t ymf278b::read(uint32_t offset)
1655 {
1656 uint8_t result = 0xff;
1657 switch (offset & 7)
1658 {
1659 case 0: // status port
1660 result = read_status();
1661 break;
1662
1663 case 5: // PCM data port
1664 result = read_data_pcm();
1665 break;
1666
1667 default:
1668 debug::log_unexpected_read_write("Unexpected read from ymf278b offset %d\n", offset & 3);
1669 break;
1670 }
1671 return result;
1672 }
1673
1674
1675 //-------------------------------------------------
1676 // write_address - handle a write to the address
1677 // register
1678 //-------------------------------------------------
1679
1680 void ymf278b::write_address(uint8_t data)
1681 {
1682 // just set the address
1683 m_address = data;
1684 }
1685
1686
1687 //-------------------------------------------------
1688 // write_data - handle a write to the data
1689 // register
1690 //-------------------------------------------------
1691
1692 void ymf278b::write_data(uint8_t data)
1693 {
1694 // write to FM
1695 if (bitfield(m_address, 9) == 0)
1696 {
1697 uint8_t old = m_fm.regs().new2flag();
1698 m_fm.write(m_address, data);
1699
1700 // changing NEW2 from 0->1 causes the next status read to
1701 // return the chip ID
1702 if (old == 0 && m_fm.regs().new2flag() != 0)
1703 m_next_status_id = true;
1704 }
1705
1706 // BUSY goes for 56 clocks on FM writes
1707 m_fm.intf().ymfm_set_busy_end(56);
1708 }
1709
1710
1711 //-------------------------------------------------
1712 // write_address_hi - handle a write to the upper
1713 // address register
1714 //-------------------------------------------------
1715
1716 void ymf278b::write_address_hi(uint8_t data)
1717 {
1718 // just set the address
1719 m_address = data | 0x100;
1720
1721 // YMF262, in compatibility mode, treats the upper bit as masked
1722 // except for register 0x105; assuming YMF278B works the same way?
1723 if (m_fm.regs().newflag() == 0 && m_address != 0x105)
1724 m_address &= 0xff;
1725 }
1726
1727
1728 //-------------------------------------------------
1729 // write_address_pcm - handle a write to the upper
1730 // address register
1731 //-------------------------------------------------
1732
1733 void ymf278b::write_address_pcm(uint8_t data)
1734 {
1735 // just set the address
1736 m_address = data | 0x200;
1737 }
1738
1739
1740 //-------------------------------------------------
1741 // write_data_pcm - handle a write to the PCM data
1742 // register
1743 //-------------------------------------------------
1744
1745 void ymf278b::write_data_pcm(uint8_t data)
1746 {
1747 // ignore data writes if new2 is not yet set
1748 if (m_fm.regs().new2flag() == 0)
1749 return;
1750
1751 // write to FM
1752 if (bitfield(m_address, 9) != 0)
1753 {
1754 uint8_t addr = m_address & 0xff;
1755 m_pcm.write(addr, data);
1756
1757 // writes to the waveform number cause loads to happen for "about 300usec"
1758 // which is ~13 samples at the nominal output frequency of 44.1kHz
1759 if (addr >= 0x08 && addr <= 0x1f)
1760 m_load_remaining = 13;
1761 }
1762
1763 // BUSY goes for 88 clocks on PCM writes
1764 m_fm.intf().ymfm_set_busy_end(88);
1765 }
1766
1767
1768 //-------------------------------------------------
1769 // write - handle a write to the register
1770 // interface
1771 //-------------------------------------------------
1772
1773 void ymf278b::write(uint32_t offset, uint8_t data)
1774 {
1775 switch (offset & 7)
1776 {
1777 case 0: // address port
1778 write_address(data);
1779 break;
1780
1781 case 1: // data port
1782 write_data(data);
1783 break;
1784
1785 case 2: // address port
1786 write_address_hi(data);
1787 break;
1788
1789 case 3: // data port
1790 write_data(data);
1791 break;
1792
1793 case 4: // PCM address port
1794 write_address_pcm(data);
1795 break;
1796
1797 case 5: // PCM address port
1798 write_data_pcm(data);
1799 break;
1800
1801 default:
1802 debug::log_unexpected_read_write("Unexpected write to ymf278b offset %d\n", offset & 7);
1803 break;
1804 }
1805 }
1806
1807
1808 //-------------------------------------------------
1809 // generate - generate one sample of sound
1810 //-------------------------------------------------
1811
1812 void ymf278b::generate(output_data *output, uint32_t numsamples)
1813 {
1814 static const int16_t s_mix_scale[8] = { 0x7fa, 0x5a4, 0x3fd, 0x2d2, 0x1fe, 0x169, 0xff, 0 };
1815 int32_t const pcm_l = s_mix_scale[m_pcm.regs().mix_pcm_l()];
1816 int32_t const pcm_r = s_mix_scale[m_pcm.regs().mix_pcm_r()];
1817 int32_t const fm_l = s_mix_scale[m_pcm.regs().mix_fm_l()];
1818 int32_t const fm_r = s_mix_scale[m_pcm.regs().mix_fm_r()];
1819 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
1820 {
1821 // clock the system
1822 m_fm_pos += FM_EXTRA_SAMPLE_STEP;
1823 if (m_fm_pos >= FM_EXTRA_SAMPLE_THRESH)
1824 {
1825 m_fm.clock(fm_engine::ALL_CHANNELS);
1826 m_fm_pos -= FM_EXTRA_SAMPLE_THRESH;
1827 }
1828 m_fm.clock(fm_engine::ALL_CHANNELS);
1829 m_pcm.clock(pcm_engine::ALL_CHANNELS);
1830
1831 // update the FM content; mixing details for YMF278B need verification
1832 fm_engine::output_data fmout;
1833 m_fm.output(fmout.clear(), 0, 32767, fm_engine::ALL_CHANNELS);
1834
1835 // update the PCM content
1836 pcm_engine::output_data pcmout;
1837 m_pcm.output(pcmout.clear(), pcm_engine::ALL_CHANNELS);
1838
1839 // DO0 output: FM channels 2+3 only
1840 output->data[0] = fmout.data[2];
1841 output->data[1] = fmout.data[3];
1842
1843 // DO1 output: wavetable channels 2+3 only
1844 output->data[2] = pcmout.data[2];
1845 output->data[3] = pcmout.data[3];
1846
1847 // DO2 output: mixed FM channels 0+1 and wavetable channels 0+1
1848 output->data[4] = (fmout.data[0] * fm_l + pcmout.data[0] * pcm_l) >> 11;
1849 output->data[5] = (fmout.data[1] * fm_r + pcmout.data[1] * pcm_r) >> 11;
1850
1851 // YMF278B output is 16-bit 2s complement serial
1852 output->clamp16();
1853 }
1854
1855 // decrement the load waiting count
1856 if (m_load_remaining > 0)
1857 m_load_remaining -= std::min(m_load_remaining, numsamples);
1858 }
1859
1860
1861
1862 //*********************************************************
1863 // OPLL BASE
1864 //*********************************************************
1865
1866 //-------------------------------------------------
1867 // opll_base - constructor
1868 //-------------------------------------------------
1869
1870 opll_base::opll_base(ymfm_interface &intf, uint8_t const *instrument_data) :
1871 m_address(0),
1872 m_fm(intf)
1873 {
1874 m_fm.regs().set_instrument_data(instrument_data);
1875 }
1876
1877
1878 //-------------------------------------------------
1879 // reset - reset the system
1880 //-------------------------------------------------
1881
1882 void opll_base::reset()
1883 {
1884 // reset the engines
1885 m_fm.reset();
1886 }
1887
1888
1889 //-------------------------------------------------
1890 // save_restore - save or restore the data
1891 //-------------------------------------------------
1892
1893 void opll_base::save_restore(ymfm_saved_state &state)
1894 {
1895 state.save_restore(m_address);
1896 m_fm.save_restore(state);
1897 }
1898
1899
1900 //-------------------------------------------------
1901 // write_address - handle a write to the address
1902 // register
1903 //-------------------------------------------------
1904
1905 void opll_base::write_address(uint8_t data)
1906 {
1907 // OPLL doesn't expose a busy signal, but datasheets are pretty consistent
1908 // in indicating that address writes should be no faster than every 12 clocks
1909 m_fm.intf().ymfm_set_busy_end(12);
1910
1911 // just set the address
1912 m_address = data;
1913 }
1914
1915
1916 //-------------------------------------------------
1917 // write - handle a write to the register
1918 // interface
1919 //-------------------------------------------------
1920
1921 void opll_base::write_data(uint8_t data)
1922 {
1923 // OPLL doesn't expose a busy signal, but datasheets are pretty consistent
1924 // in indicating that address writes should be no faster than every 84 clocks
1925 m_fm.intf().ymfm_set_busy_end(84);
1926
1927 // write to FM
1928 m_fm.write(m_address, data);
1929 }
1930
1931
1932 //-------------------------------------------------
1933 // write - handle a write to the register
1934 // interface
1935 //-------------------------------------------------
1936
1937 void opll_base::write(uint32_t offset, uint8_t data)
1938 {
1939 switch (offset & 1)
1940 {
1941 case 0: // address port
1942 write_address(data);
1943 break;
1944
1945 case 1: // data port
1946 write_data(data);
1947 break;
1948 }
1949 }
1950
1951
1952 //-------------------------------------------------
1953 // generate - generate one sample of sound
1954 //-------------------------------------------------
1955
1956 void opll_base::generate(output_data *output, uint32_t numsamples)
1957 {
1958 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
1959 {
1960 // clock the system
1961 m_fm.clock(fm_engine::ALL_CHANNELS);
1962
1963 // update the FM content; OPLL has a built-in 9-bit DAC
1964 m_fm.output(output->clear(), 5, 256, fm_engine::ALL_CHANNELS);
1965
1966 // final output is multiplexed; we don't simulate that here except
1967 // to average over everything
1968 output->data[0] = (output->data[0] * 128) / 9;
1969 output->data[1] = (output->data[1] * 128) / 9;
1970 }
1971 }
1972
1973
1974
1975 //*********************************************************
1976 // YM2413
1977 //*********************************************************
1978
1979 //-------------------------------------------------
1980 // ym2413 - constructor
1981 //-------------------------------------------------
1982
1983 ym2413::ym2413(ymfm_interface &intf, uint8_t const *instrument_data) :
1984 opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments)
1985 {
1986 };
1987
1988 // table below taken from https://github.com/plgDavid/misc/wiki/Copyright-free-OPLL(x)-ROM-patches
1989 uint8_t const ym2413::s_default_instruments[] =
1990 {
1991 //April 2015 David Viens, tweaked May 19-21th 2015 Hubert Lamontagne
1992 0x71, 0x61, 0x1E, 0x17, 0xEF, 0x7F, 0x00, 0x17, //Violin
1993 0x13, 0x41, 0x1A, 0x0D, 0xF8, 0xF7, 0x23, 0x13, //Guitar
1994 0x13, 0x01, 0x99, 0x00, 0xF2, 0xC4, 0x11, 0x23, //Piano
1995 0x31, 0x61, 0x0E, 0x07, 0x98, 0x64, 0x70, 0x27, //Flute
1996 0x22, 0x21, 0x1E, 0x06, 0xBF, 0x76, 0x00, 0x28, //Clarinet
1997 0x31, 0x22, 0x16, 0x05, 0xE0, 0x71, 0x0F, 0x18, //Oboe
1998 0x21, 0x61, 0x1D, 0x07, 0x82, 0x8F, 0x10, 0x07, //Trumpet
1999 0x23, 0x21, 0x2D, 0x14, 0xFF, 0x7F, 0x00, 0x07, //Organ
2000 0x41, 0x61, 0x1B, 0x06, 0x64, 0x65, 0x10, 0x17, //Horn
2001 0x61, 0x61, 0x0B, 0x18, 0x85, 0xFF, 0x81, 0x07, //Synthesizer
2002 0x13, 0x01, 0x83, 0x11, 0xFA, 0xE4, 0x10, 0x04, //Harpsichord
2003 0x17, 0x81, 0x23, 0x07, 0xF8, 0xF8, 0x22, 0x12, //Vibraphone
2004 0x61, 0x50, 0x0C, 0x05, 0xF2, 0xF5, 0x29, 0x42, //Synthesizer Bass
2005 0x01, 0x01, 0x54, 0x03, 0xC3, 0x92, 0x03, 0x02, //Acoustic Bass
2006 0x41, 0x41, 0x89, 0x03, 0xF1, 0xE5, 0x11, 0x13, //Electric Guitar
2007 0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, //rhythm 1
2008 0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, //rhythm 2
2009 0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 //rhythm 3
2010 };
2011
2012
2013
2014 //*********************************************************
2015 // YM2423
2016 //*********************************************************
2017
2018 //-------------------------------------------------
2019 // ym2423 - constructor
2020 //-------------------------------------------------
2021
2022 ym2423::ym2423(ymfm_interface &intf, uint8_t const *instrument_data) :
2023 opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments)
2024 {
2025 };
2026
2027 // table below taken from https://github.com/plgDavid/misc/wiki/Copyright-free-OPLL(x)-ROM-patches
2028 uint8_t const ym2423::s_default_instruments[] =
2029 {
2030 // May 4-6 2016 Hubert Lamontagne
2031 // Doesn't seem to have any diff between opllx-x and opllx-y
2032 // Drums seem identical to regular opll
2033 0x61, 0x61, 0x1B, 0x07, 0x94, 0x5F, 0x10, 0x06, //1 Strings Saw wave with vibrato Violin
2034 0x93, 0xB1, 0x51, 0x04, 0xF3, 0xF2, 0x70, 0xFB, //2 Guitar Jazz GuitarPiano
2035 0x41, 0x21, 0x11, 0x85, 0xF2, 0xF2, 0x70, 0x75, //3 Electric Guitar Same as OPLL No.15 Synth
2036 0x93, 0xB2, 0x28, 0x07, 0xF3, 0xF2, 0x70, 0xB4, //4 Electric Piano 2 Slow attack, tremoloDing-a-ling
2037 0x72, 0x31, 0x97, 0x05, 0x51, 0x6F, 0x60, 0x09, //5 Flute Same as OPLL No.4Clarinet
2038 0x13, 0x30, 0x18, 0x06, 0xF7, 0xF4, 0x50, 0x85, //6 Marimba Also be used as steel drumXyophone
2039 0x51, 0x31, 0x1C, 0x07, 0x51, 0x71, 0x20, 0x26, //7 Trumpet Same as OPLL No.7Trumpet
2040 0x41, 0xF4, 0x1B, 0x07, 0x74, 0x34, 0x00, 0x06, //8 Harmonica Harmonica synth
2041 0x50, 0x30, 0x4D, 0x03, 0x42, 0x65, 0x20, 0x06, //9 Tuba Tuba
2042 0x40, 0x20, 0x10, 0x85, 0xF3, 0xF5, 0x20, 0x04, //10 Synth Brass 2 Synth sweep
2043 0x61, 0x61, 0x1B, 0x07, 0xC5, 0x96, 0xF3, 0xF6, //11 Short Saw Saw wave with short envelopeSynth hit
2044 0xF9, 0xF1, 0xDC, 0x00, 0xF5, 0xF3, 0x77, 0xF2, //12 Vibraphone Bright vibraphoneVibes
2045 0x60, 0xA2, 0x91, 0x03, 0x94, 0xC1, 0xF7, 0xF7, //13 Electric Guitar 2 Clean guitar with feedbackHarmonic bass
2046 0x30, 0x30, 0x17, 0x06, 0xF3, 0xF1, 0xB7, 0xFC, //14 Synth Bass 2Snappy bass
2047 0x31, 0x36, 0x0D, 0x05, 0xF2, 0xF4, 0x27, 0x9C, //15 Sitar Also be used as ShamisenBanjo
2048 0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, //rhythm 1
2049 0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, //rhythm 2
2050 0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 //rhythm 3
2051 };
2052
2053
2054
2055 //*********************************************************
2056 // YMF281
2057 //*********************************************************
2058
2059 //-------------------------------------------------
2060 // ymf281 - constructor
2061 //-------------------------------------------------
2062
2063 ymf281::ymf281(ymfm_interface &intf, uint8_t const *instrument_data) :
2064 opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments)
2065 {
2066 };
2067
2068 // table below taken from https://github.com/plgDavid/misc/wiki/Copyright-free-OPLL(x)-ROM-patches
2069 uint8_t const ymf281::s_default_instruments[] =
2070 {
2071 // May 14th 2015 Hubert Lamontagne
2072 0x72, 0x21, 0x1A, 0x07, 0xF6, 0x64, 0x01, 0x16, // Clarinet ~~ Electric String Square wave with vibrato
2073 0x00, 0x10, 0x45, 0x00, 0xF6, 0x83, 0x73, 0x63, // Synth Bass ~~ Bow wow Triangular wave
2074 0x13, 0x01, 0x96, 0x00, 0xF1, 0xF4, 0x31, 0x23, // Piano ~~ Electric Guitar Despite of its name, same as Piano of YM2413.
2075 0x71, 0x21, 0x0B, 0x0F, 0xF9, 0x64, 0x70, 0x17, // Flute ~~ Organ Sine wave
2076 0x02, 0x21, 0x1E, 0x06, 0xF9, 0x76, 0x00, 0x28, // Square Wave ~~ Clarinet Same as ones of YM2413.
2077 0x00, 0x61, 0x82, 0x0E, 0xF9, 0x61, 0x20, 0x27, // Space Oboe ~~ Saxophone Saw wave with vibrato
2078 0x21, 0x61, 0x1B, 0x07, 0x84, 0x8F, 0x10, 0x07, // Trumpet ~~ Trumpet Same as ones of YM2413.
2079 0x37, 0x32, 0xCA, 0x02, 0x66, 0x64, 0x47, 0x29, // Wow Bell ~~ Street Organ Calliope
2080 0x41, 0x41, 0x07, 0x03, 0xF5, 0x70, 0x51, 0xF5, // Electric Guitar ~~ Synth Brass Same as Synthesizer of YM2413.
2081 0x36, 0x01, 0x5E, 0x07, 0xF2, 0xF3, 0xF7, 0xF7, // Vibes ~~ Electric Piano Simulate of Rhodes Piano
2082 0x00, 0x00, 0x18, 0x06, 0xC5, 0xF3, 0x20, 0xF2, // Bass ~~ Bass Electric bass
2083 0x17, 0x81, 0x25, 0x07, 0xF7, 0xF3, 0x21, 0xF7, // Vibraphone ~~ Vibraphone Same as ones of YM2413.
2084 0x35, 0x64, 0x00, 0x00, 0xFF, 0xF3, 0x77, 0xF5, // Vibrato Bell ~~ Chime Bell
2085 0x11, 0x31, 0x00, 0x07, 0xDD, 0xF3, 0xFF, 0xFB, // Click Sine ~~ Tom Tom II Tom
2086 0x3A, 0x21, 0x00, 0x07, 0x95, 0x84, 0x0F, 0xF5, // Noise and Tone ~~ Noise for S.E.
2087 0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, //rhythm 1
2088 0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, //rhythm 2
2089 0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 //rhythm 3
2090 };
2091
2092
2093
2094 //*********************************************************
2095 // DS1001
2096 //*********************************************************
2097
2098 //-------------------------------------------------
2099 // ds1001 - constructor
2100 //-------------------------------------------------
2101
2102 ds1001::ds1001(ymfm_interface &intf, uint8_t const *instrument_data) :
2103 opll_base(intf, (instrument_data != nullptr) ? instrument_data : s_default_instruments)
2104 {
2105 };
2106
2107 // table below taken from https://github.com/plgDavid/misc/wiki/Copyright-free-OPLL(x)-ROM-patches
2108 uint8_t const ds1001::s_default_instruments[] =
2109 {
2110 // May 15th 2015 Hubert Lamontagne & David Viens
2111 0x03, 0x21, 0x05, 0x06, 0xC8, 0x81, 0x42, 0x27, // Buzzy Bell
2112 0x13, 0x41, 0x14, 0x0D, 0xF8, 0xF7, 0x23, 0x12, // Guitar
2113 0x31, 0x11, 0x08, 0x08, 0xFA, 0xC2, 0x28, 0x22, // Wurly
2114 0x31, 0x61, 0x0C, 0x07, 0xF8, 0x64, 0x60, 0x27, // Flute
2115 0x22, 0x21, 0x1E, 0x06, 0xFF, 0x76, 0x00, 0x28, // Clarinet
2116 0x02, 0x01, 0x05, 0x00, 0xAC, 0xF2, 0x03, 0x02, // Synth
2117 0x21, 0x61, 0x1D, 0x07, 0x82, 0x8F, 0x10, 0x07, // Trumpet
2118 0x23, 0x21, 0x22, 0x17, 0xFF, 0x73, 0x00, 0x17, // Organ
2119 0x15, 0x11, 0x25, 0x00, 0x41, 0x71, 0x00, 0xF1, // Bells
2120 0x95, 0x01, 0x10, 0x0F, 0xB8, 0xAA, 0x50, 0x02, // Vibes
2121 0x17, 0xC1, 0x5E, 0x07, 0xFA, 0xF8, 0x22, 0x12, // Vibraphone
2122 0x71, 0x23, 0x11, 0x06, 0x65, 0x74, 0x10, 0x16, // Tutti
2123 0x01, 0x02, 0xD3, 0x05, 0xF3, 0x92, 0x83, 0xF2, // Fretless
2124 0x61, 0x63, 0x0C, 0x00, 0xA4, 0xFF, 0x30, 0x06, // Synth Bass
2125 0x21, 0x62, 0x0D, 0x00, 0xA1, 0xFF, 0x50, 0x08, // Sweep
2126 0x01, 0x01, 0x18, 0x0F, 0xDF, 0xF8, 0x6A, 0x6D, //rhythm 1
2127 0x01, 0x01, 0x00, 0x00, 0xC8, 0xD8, 0xA7, 0x48, //rhythm 2
2128 0x05, 0x01, 0x00, 0x00, 0xF8, 0xAA, 0x59, 0x55 //rhythm 3
2129 };
2130
2131
2132 //*********************************************************
2133 // EXPLICIT INSTANTIATION
2134 //*********************************************************
2135
2136 template class opl_registers_base<4>;
2137 template class fm_engine_base<opl_registers_base<4>>;
2138
2139 }