Debian Codegraph @

src/engine/platform/sound/ymfm/ymfm_adpcm.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_adpcm.h"
32
33 namespace ymfm
34 {
35
36 //*********************************************************
37 // ADPCM "A" REGISTERS
38 //*********************************************************
39
40 //-------------------------------------------------
41 // reset - reset the register state
42 //-------------------------------------------------
43
44 void adpcm_a_registers::reset()
45 {
46 std::fill_n(&m_regdata[0], REGISTERS, 0);
47
48 // initialize the pans to on by default, and max instrument volume;
49 // some neogeo homebrews (for example ffeast) rely on this
50 m_regdata[0x08] = m_regdata[0x09] = m_regdata[0x0a] =
51 m_regdata[0x0b] = m_regdata[0x0c] = m_regdata[0x0d] = 0xdf;
52 }
53
54
55 //-------------------------------------------------
56 // save_restore - save or restore the data
57 //-------------------------------------------------
58
59 void adpcm_a_registers::save_restore(ymfm_saved_state &state)
60 {
61 state.save_restore(m_regdata);
62 }
63
64
65 //*********************************************************
66 // ADPCM "A" CHANNEL
67 //*********************************************************
68
69 //-------------------------------------------------
70 // adpcm_a_channel - constructor
71 //-------------------------------------------------
72
73 adpcm_a_channel::adpcm_a_channel(adpcm_a_engine &owner, uint32_t choffs, uint32_t addrshift) :
74 m_choffs(choffs),
75 m_address_shift(addrshift),
76 m_playing(0),
77 m_curnibble(0),
78 m_curbyte(0),
79 m_curaddress(0),
80 m_accumulator(0),
81 m_step_index(0),
82 m_regs(owner.regs()),
83 m_owner(owner)
84 {
85 }
86
87
88 //-------------------------------------------------
89 // reset - reset the channel state
90 //-------------------------------------------------
91
92 void adpcm_a_channel::reset()
93 {
94 m_playing = 0;
95 m_curnibble = 0;
96 m_curbyte = 0;
97 m_curaddress = 0;
98 m_accumulator = 0;
99 m_step_index = 0;
100 }
101
102
103 //-------------------------------------------------
104 // save_restore - save or restore the data
105 //-------------------------------------------------
106
107 void adpcm_a_channel::save_restore(ymfm_saved_state &state)
108 {
109 state.save_restore(m_playing);
110 state.save_restore(m_curnibble);
111 state.save_restore(m_curbyte);
112 state.save_restore(m_curaddress);
113 state.save_restore(m_accumulator);
114 state.save_restore(m_step_index);
115 }
116
117
118 //-------------------------------------------------
119 // keyonoff - signal key on/off
120 //-------------------------------------------------
121
122 void adpcm_a_channel::keyonoff(bool on)
123 {
124 // QUESTION: repeated key ons restart the sample?
125 m_playing = on;
126 if (m_playing)
127 {
128 m_curaddress = m_regs.ch_start(m_choffs) << m_address_shift;
129 m_curnibble = 0;
130 m_curbyte = 0;
131 m_accumulator = 0;
132 m_step_index = 0;
133
134 // don't log masked channels
135 if (((debug::GLOBAL_ADPCM_A_CHANNEL_MASK >> m_choffs) & 1) != 0)
136 debug::log_keyon("KeyOn ADPCM-A%d: pan=%d%d start=%04X end=%04X level=%02X\n",
137 m_choffs,
138 m_regs.ch_pan_left(m_choffs),
139 m_regs.ch_pan_right(m_choffs),
140 m_regs.ch_start(m_choffs),
141 m_regs.ch_end(m_choffs),
142 m_regs.ch_instrument_level(m_choffs));
143 }
144 }
145
146
147 //-------------------------------------------------
148 // clock - master clocking function
149 //-------------------------------------------------
150
151 bool adpcm_a_channel::clock()
152 {
153 // if not playing, just output 0
154 if (m_playing == 0)
155 {
156 m_accumulator = 0;
157 return false;
158 }
159
160 // if we're about to read nibble 0, fetch the data
161 uint8_t data;
162 if (m_curnibble == 0)
163 {
164 // stop when we hit the end address; apparently only low 20 bits are used for
165 // comparison on the YM2610: this affects sample playback in some games, for
166 // example twinspri character select screen music will skip some samples if
167 // this is not correct
168 //
169 // note also: end address is inclusive, so wait until we are about to fetch
170 // the sample just after the end before stopping; this is needed for nitd's
171 // jump sound, for example
172 uint32_t end = (m_regs.ch_end(m_choffs) + 1) << m_address_shift;
173 if (((m_curaddress ^ end) & 0xfffff) == 0)
174 {
175 m_playing = m_accumulator = 0;
176 return true;
177 }
178
179 m_curbyte = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_A, m_curaddress++);
180 data = m_curbyte >> 4;
181 m_curnibble = 1;
182 }
183
184 // otherwise just extract from the previosuly-fetched byte
185 else
186 {
187 data = m_curbyte & 0xf;
188 m_curnibble = 0;
189 }
190
191 // compute the ADPCM delta
192 static uint16_t const s_steps[49] =
193 {
194 16, 17, 19, 21, 23, 25, 28,
195 31, 34, 37, 41, 45, 50, 55,
196 60, 66, 73, 80, 88, 97, 107,
197 118, 130, 143, 157, 173, 190, 209,
198 230, 253, 279, 307, 337, 371, 408,
199 449, 494, 544, 598, 658, 724, 796,
200 876, 963, 1060, 1166, 1282, 1411, 1552
201 };
202 int32_t delta = (2 * bitfield(data, 0, 3) + 1) * s_steps[m_step_index] / 8;
203 if (bitfield(data, 3))
204 delta = -delta;
205
206 // the 12-bit accumulator wraps on the ym2610 and ym2608 (like the msm5205)
207 m_accumulator = (m_accumulator + delta) & 0xfff;
208
209 // adjust ADPCM step
210 static int8_t const s_step_inc[8] = { -1, -1, -1, -1, 2, 5, 7, 9 };
211 m_step_index = clamp(m_step_index + s_step_inc[bitfield(data, 0, 3)], 0, 48);
212
213 return false;
214 }
215
216
217 //-------------------------------------------------
218 // output - return the computed output value, with
219 // panning applied
220 //-------------------------------------------------
221
222 template<int NumOutputs>
223 void adpcm_a_channel::output(ymfm_output<NumOutputs> &output)
224 {
225 // volume combines instrument and total levels
226 int vol = (m_regs.ch_instrument_level(m_choffs) ^ 0x1f) + (m_regs.total_level() ^ 0x3f);
227
228 // if combined is maximum, don't add to outputs
229 if (vol >= 63)
230 return;
231
232 // convert into a shift and a multiplier
233 // QUESTION: verify this from other sources
234 int8_t mul = 15 - (vol & 7);
235 uint8_t shift = 4 + 1 + (vol >> 3);
236
237 // m_accumulator is a 12-bit value; shift up to sign-extend;
238 // the downshift is incorporated into 'shift'
239 int16_t value = ((int16_t(m_accumulator << 4) * mul) >> shift) & ~3;
240
241 // apply to left/right as appropriate
242 if (NumOutputs == 1 || m_regs.ch_pan_left(m_choffs)) {
243 output.data[0] += value;
244 m_lastOut[0] = value;
245 }
246 if (NumOutputs > 1 && m_regs.ch_pan_right(m_choffs)) {
247 output.data[1] += value;
248 m_lastOut[1] = value;
249 }
250 }
251
252 template void adpcm_a_channel::output<1>(ymfm_output<1> &output);
253 template void adpcm_a_channel::output<2>(ymfm_output<2> &output);
254
255
256 //*********************************************************
257 // ADPCM "A" ENGINE
258 //*********************************************************
259
260 //-------------------------------------------------
261 // adpcm_a_engine - constructor
262 //-------------------------------------------------
263
264 adpcm_a_engine::adpcm_a_engine(ymfm_interface &intf, uint32_t addrshift) :
265 m_intf(intf)
266 {
267 // create the channels
268 for (int chnum = 0; chnum < CHANNELS; chnum++)
269 m_channel[chnum] = std::make_unique<adpcm_a_channel>(*this, chnum, addrshift);
270 }
271
272
273 //-------------------------------------------------
274 // reset - reset the engine state
275 //-------------------------------------------------
276
277 void adpcm_a_engine::reset()
278 {
279 // reset register state
280 m_regs.reset();
281
282 // reset each channel
283 for (auto &chan : m_channel)
284 chan->reset();
285 }
286
287
288 //-------------------------------------------------
289 // save_restore - save or restore the data
290 //-------------------------------------------------
291
292 void adpcm_a_engine::save_restore(ymfm_saved_state &state)
293 {
294 // save register state
295 m_regs.save_restore(state);
296
297 // save channel state
298 for (int chnum = 0; chnum < CHANNELS; chnum++)
299 m_channel[chnum]->save_restore(state);
300 }
301
302
303 //-------------------------------------------------
304 // clock - master clocking function
305 //-------------------------------------------------
306
307 uint32_t adpcm_a_engine::clock(uint32_t chanmask)
308 {
309 // clock each channel, setting a bit in result if it finished
310 uint32_t result = 0;
311 for (int chnum = 0; chnum < CHANNELS; chnum++)
312 if (bitfield(chanmask, chnum))
313 if (m_channel[chnum]->clock())
314 result |= 1 << chnum;
315
316 // return the bitmask of completed samples
317 return result;
318 }
319
320
321 //-------------------------------------------------
322 // update - master update function
323 //-------------------------------------------------
324
325 template<int NumOutputs>
326 void adpcm_a_engine::output(ymfm_output<NumOutputs> &output, uint32_t chanmask)
327 {
328 // mask out some channels for debug purposes
329 chanmask &= debug::GLOBAL_ADPCM_A_CHANNEL_MASK;
330
331 // compute the output of each channel
332 for (int chnum = 0; chnum < CHANNELS; chnum++)
333 if (bitfield(chanmask, chnum))
334 m_channel[chnum]->output(output);
335 }
336
337 template void adpcm_a_engine::output<1>(ymfm_output<1> &output, uint32_t chanmask);
338 template void adpcm_a_engine::output<2>(ymfm_output<2> &output, uint32_t chanmask);
339
340
341 //-------------------------------------------------
342 // write - handle writes to the ADPCM-A registers
343 //-------------------------------------------------
344
345 void adpcm_a_engine::write(uint32_t regnum, uint8_t data)
346 {
347 // store the raw value to the register array;
348 // most writes are passive, consumed only when needed
349 m_regs.write(regnum, data);
350
351 // actively handle writes to the control register
352 if (regnum == 0x00)
353 for (int chnum = 0; chnum < CHANNELS; chnum++)
354 if (bitfield(data, chnum))
355 m_channel[chnum]->keyonoff(bitfield(~data, 7));
356 }
357
358
359
360 //*********************************************************
361 // ADPCM "B" REGISTERS
362 //*********************************************************
363
364 //-------------------------------------------------
365 // reset - reset the register state
366 //-------------------------------------------------
367
368 void adpcm_b_registers::reset()
369 {
370 std::fill_n(&m_regdata[0], REGISTERS, 0);
371
372 // default limit to wide open
373 m_regdata[0x0c] = m_regdata[0x0d] = 0xff;
374 }
375
376
377 //-------------------------------------------------
378 // save_restore - save or restore the data
379 //-------------------------------------------------
380
381 void adpcm_b_registers::save_restore(ymfm_saved_state &state)
382 {
383 state.save_restore(m_regdata);
384 }
385
386
387
388 //*********************************************************
389 // ADPCM "B" CHANNEL
390 //*********************************************************
391
392 //-------------------------------------------------
393 // adpcm_b_channel - constructor
394 //-------------------------------------------------
395
396 adpcm_b_channel::adpcm_b_channel(adpcm_b_engine &owner, uint32_t addrshift) :
397 m_address_shift(addrshift),
398 m_status(STATUS_BRDY),
399 m_curnibble(0),
400 m_curbyte(0),
401 m_dummy_read(0),
402 m_position(0),
403 m_curaddress(0),
404 m_accumulator(0),
405 m_prev_accum(0),
406 m_adpcm_step(STEP_MIN),
407 m_regs(owner.regs()),
408 m_owner(owner)
409 {
410 }
411
412
413 //-------------------------------------------------
414 // reset - reset the channel state
415 //-------------------------------------------------
416
417 void adpcm_b_channel::reset()
418 {
419 m_status = STATUS_BRDY;
420 m_curnibble = 0;
421 m_curbyte = 0;
422 m_dummy_read = 0;
423 m_position = 0;
424 m_curaddress = 0;
425 m_accumulator = 0;
426 m_prev_accum = 0;
427 m_adpcm_step = STEP_MIN;
428 }
429
430
431 //-------------------------------------------------
432 // save_restore - save or restore the data
433 //-------------------------------------------------
434
435 void adpcm_b_channel::save_restore(ymfm_saved_state &state)
436 {
437 state.save_restore(m_status);
438 state.save_restore(m_curnibble);
439 state.save_restore(m_curbyte);
440 state.save_restore(m_dummy_read);
441 state.save_restore(m_position);
442 state.save_restore(m_curaddress);
443 state.save_restore(m_accumulator);
444 state.save_restore(m_prev_accum);
445 state.save_restore(m_adpcm_step);
446 }
447
448
449 //-------------------------------------------------
450 // clock - master clocking function
451 //-------------------------------------------------
452
453 void adpcm_b_channel::clock()
454 {
455 // only process if active and not recording (which we don't support)
456 if (!m_regs.execute() || m_regs.record() || (m_status & STATUS_PLAYING) == 0)
457 {
458 m_status &= ~STATUS_PLAYING;
459 return;
460 }
461
462 // otherwise, advance the step
463 uint32_t position = m_position + m_regs.delta_n();
464 m_position = uint16_t(position);
465 if (position < 0x10000)
466 return;
467
468 // if we're about to process nibble 0, fetch sample
469 if (m_curnibble == 0)
470 {
471 // playing from RAM/ROM
472 if (m_regs.external())
473 m_curbyte = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress);
474 }
475
476 // extract the nibble from our current byte
477 uint8_t data = uint8_t(m_curbyte << (4 * m_curnibble)) >> 4;
478 m_curnibble ^= 1;
479
480 // we just processed the last nibble
481 if (m_curnibble == 0)
482 {
483 // if playing from RAM/ROM, check the end/limit address or advance
484 if (m_regs.external())
485 {
486 // handle the sample end, either repeating or stopping
487 if (at_end())
488 {
489 // if repeating, go back to the start
490 if (m_regs.repeat())
491 load_start();
492
493 // otherwise, done; set the EOS bit
494 else
495 {
496 m_accumulator = 0;
497 m_prev_accum = 0;
498 m_status = (m_status & ~STATUS_PLAYING) | STATUS_EOS;
499 debug::log_keyon("%s\n", "ADPCM EOS");
500 return;
501 }
502 }
503
504 // wrap at the limit address
505 else if (at_limit())
506 m_curaddress = 0;
507
508 // otherwise, advance the current address
509 else
510 {
511 m_curaddress++;
512 m_curaddress &= 0xffffff;
513 }
514 }
515
516 // if CPU-driven, copy the next byte and request more
517 else
518 {
519 m_curbyte = m_regs.cpudata();
520 m_status |= STATUS_BRDY;
521 }
522 }
523
524 // remember previous value for interpolation
525 m_prev_accum = m_accumulator;
526
527 // forecast to next forecast: 1/8, 3/8, 5/8, 7/8, 9/8, 11/8, 13/8, 15/8
528 int32_t delta = (2 * bitfield(data, 0, 3) + 1) * m_adpcm_step / 8;
529 if (bitfield(data, 3))
530 delta = -delta;
531
532 // add and clamp to 16 bits
533 m_accumulator = clamp(m_accumulator + delta, -32768, 32767);
534
535 // scale the ADPCM step: 0.9, 0.9, 0.9, 0.9, 1.2, 1.6, 2.0, 2.4
536 static uint8_t const s_step_scale[8] = { 57, 57, 57, 57, 77, 102, 128, 153 };
537 m_adpcm_step = clamp((m_adpcm_step * s_step_scale[bitfield(data, 0, 3)]) / 64, STEP_MIN, STEP_MAX);
538 }
539
540
541 //-------------------------------------------------
542 // output - return the computed output value, with
543 // panning applied
544 //-------------------------------------------------
545
546 template<int NumOutputs>
547 void adpcm_b_channel::output(ymfm_output<NumOutputs> &output, uint32_t rshift)
548 {
549 // mask out some channels for debug purposes
550 if ((debug::GLOBAL_ADPCM_B_CHANNEL_MASK & 1) == 0)
551 return;
552
553 // do a linear interpolation between samples
554 int32_t result = (m_prev_accum * int32_t((m_position ^ 0xffff) + 1) + m_accumulator * int32_t(m_position)) >> 16;
555
556 // apply volume (level) in a linear fashion and reduce
557 result = (result * int32_t(m_regs.level())) >> (8 + rshift);
558
559 // apply to left/right
560 if (NumOutputs == 1 || m_regs.pan_left()) {
561 m_lastOut[0] = result;
562 output.data[0] += result;
563 }
564 if (NumOutputs > 1 && m_regs.pan_right()) {
565 m_lastOut[1] = result;
566 output.data[1] += result;
567 }
568 }
569
570
571 //-------------------------------------------------
572 // read - handle special register reads
573 //-------------------------------------------------
574
575 uint8_t adpcm_b_channel::read(uint32_t regnum)
576 {
577 uint8_t result = 0;
578
579 // register 8 reads over the bus under some conditions
580 if (regnum == 0x08 && !m_regs.execute() && !m_regs.record() && m_regs.external())
581 {
582 // two dummy reads are consumed first
583 if (m_dummy_read != 0)
584 {
585 load_start();
586 m_dummy_read--;
587 }
588
589 // read the data
590 else
591 {
592 // read from outside of the chip
593 result = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress++);
594
595 // did we hit the end? if so, signal EOS
596 if (at_end())
597 {
598 m_status = STATUS_EOS | STATUS_BRDY;
599 debug::log_keyon("%s\n", "ADPCM EOS");
600 }
601 else
602 {
603 // signal ready
604 m_status = STATUS_BRDY;
605 }
606
607 // wrap at the limit address
608 if (at_limit())
609 m_curaddress = 0;
610 }
611 }
612 return result;
613 }
614
615
616 //-------------------------------------------------
617 // write - handle special register writes
618 //-------------------------------------------------
619
620 void adpcm_b_channel::write(uint32_t regnum, uint8_t value)
621 {
622 // register 0 can do a reset; also use writes here to reset the
623 // dummy read counter
624 if (regnum == 0x00)
625 {
626 if (m_regs.execute())
627 {
628 load_start();
629
630 // don't log masked channels
631 if ((debug::GLOBAL_ADPCM_B_CHANNEL_MASK & 1) != 0)
632 debug::log_keyon("KeyOn ADPCM-B: rep=%d spk=%d pan=%d%d dac=%d 8b=%d rom=%d ext=%d rec=%d start=%04X end=%04X pre=%04X dn=%04X lvl=%02X lim=%04X\n",
633 m_regs.repeat(),
634 m_regs.speaker(),
635 m_regs.pan_left(),
636 m_regs.pan_right(),
637 m_regs.dac_enable(),
638 m_regs.dram_8bit(),
639 m_regs.rom_ram(),
640 m_regs.external(),
641 m_regs.record(),
642 m_regs.start(),
643 m_regs.end(),
644 m_regs.prescale(),
645 m_regs.delta_n(),
646 m_regs.level(),
647 m_regs.limit());
648 }
649 else
650 m_status &= ~STATUS_EOS;
651 if (m_regs.resetflag())
652 reset();
653 if (m_regs.external())
654 m_dummy_read = 2;
655 }
656
657 // register 8 writes over the bus under some conditions
658 else if (regnum == 0x08)
659 {
660 // if writing from the CPU during execute, clear the ready flag
661 if (m_regs.execute() && !m_regs.record() && !m_regs.external())
662 m_status &= ~STATUS_BRDY;
663
664 // if writing during "record", pass through as data
665 else if (!m_regs.execute() && m_regs.record() && m_regs.external())
666 {
667 // clear out dummy reads and set start address
668 if (m_dummy_read != 0)
669 {
670 load_start();
671 m_dummy_read = 0;
672 }
673
674 // did we hit the end? if so, signal EOS
675 if (at_end())
676 {
677 debug::log_keyon("%s\n", "ADPCM EOS");
678 m_status = STATUS_EOS | STATUS_BRDY;
679 }
680
681 // otherwise, write the data and signal ready
682 else
683 {
684 m_owner.intf().ymfm_external_write(ACCESS_ADPCM_B, m_curaddress++, value);
685 m_status = STATUS_BRDY;
686 }
687 }
688 }
689 }
690
691
692 //-------------------------------------------------
693 // address_shift - compute the current address
694 // shift amount based on register settings
695 //-------------------------------------------------
696
697 uint32_t adpcm_b_channel::address_shift() const
698 {
699 // if a constant address shift, just provide that
700 if (m_address_shift != 0)
701 return m_address_shift;
702
703 // if ROM or 8-bit DRAM, shift is 5 bits
704 if (m_regs.rom_ram())
705 return 5;
706 if (m_regs.dram_8bit())
707 return 5;
708
709 // otherwise, shift is 2 bits
710 return 2;
711 }
712
713
714 //-------------------------------------------------
715 // load_start - load the start address and
716 // initialize the state
717 //-------------------------------------------------
718
719 void adpcm_b_channel::load_start()
720 {
721 m_status = (m_status & ~STATUS_EOS) | STATUS_PLAYING;
722 m_curaddress = m_regs.external() ? (m_regs.start() << address_shift()) : 0;
723 m_curnibble = 0;
724 m_curbyte = 0;
725 m_position = 0;
726 m_accumulator = 0;
727 m_prev_accum = 0;
728 m_adpcm_step = STEP_MIN;
729 }
730
731
732
733 //*********************************************************
734 // ADPCM "B" ENGINE
735 //*********************************************************
736
737 //-------------------------------------------------
738 // adpcm_b_engine - constructor
739 //-------------------------------------------------
740
741 adpcm_b_engine::adpcm_b_engine(ymfm_interface &intf, uint32_t addrshift) :
742 m_intf(intf)
743 {
744 // create the channel (only one supported for now, but leaving possibilities open)
745 m_channel = std::make_unique<adpcm_b_channel>(*this, addrshift);
746 }
747
748
749 //-------------------------------------------------
750 // reset - reset the engine state
751 //-------------------------------------------------
752
753 void adpcm_b_engine::reset()
754 {
755 // reset registers
756 m_regs.reset();
757
758 // reset each channel
759 m_channel->reset();
760 }
761
762
763 //-------------------------------------------------
764 // save_restore - save or restore the data
765 //-------------------------------------------------
766
767 void adpcm_b_engine::save_restore(ymfm_saved_state &state)
768 {
769 // save our state
770 m_regs.save_restore(state);
771
772 // save channel state
773 m_channel->save_restore(state);
774 }
775
776
777 //-------------------------------------------------
778 // clock - master clocking function
779 //-------------------------------------------------
780
781 void adpcm_b_engine::clock()
782 {
783 // clock each channel, setting a bit in result if it finished
784 m_channel->clock();
785 }
786
787
788 //-------------------------------------------------
789 // output - master output function
790 //-------------------------------------------------
791
792 template<int NumOutputs>
793 void adpcm_b_engine::output(ymfm_output<NumOutputs> &output, uint32_t rshift)
794 {
795 // compute the output of each channel
796 m_channel->output(output, rshift);
797 }
798
799 template void adpcm_b_engine::output<1>(ymfm_output<1> &output, uint32_t rshift);
800 template void adpcm_b_engine::output<2>(ymfm_output<2> &output, uint32_t rshift);
801
802
803 //-------------------------------------------------
804 // write - handle writes to the ADPCM-B registers
805 //-------------------------------------------------
806
807 void adpcm_b_engine::write(uint32_t regnum, uint8_t data)
808 {
809 // store the raw value to the register array;
810 // most writes are passive, consumed only when needed
811 m_regs.write(regnum, data);
812
813 // let the channel handle any special writes
814 m_channel->write(regnum, data);
815 }
816
817 }