From 2ba3fe29c12d79aa67e9b71a516acf9175b78464 Mon Sep 17 00:00:00 2001 From: wilbertpol Date: Mon, 28 Oct 2024 15:29:47 +0000 Subject: [PATCH] sound/upd1771.cpp: Improve check for end of adpcm stream when the stream contains multiple samples. (#12913) * Fixes SCV Star Speeder. --- src/devices/sound/upd1771.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/devices/sound/upd1771.cpp b/src/devices/sound/upd1771.cpp index 6b0ef06b884..b08ced8779f 100644 --- a/src/devices/sound/upd1771.cpp +++ b/src/devices/sound/upd1771.cpp @@ -432,15 +432,30 @@ void upd1771c_device::write(uint8_t data) //6Khz(ish) DIGI playback //end capture - if (m_index >= 2 && m_packet[m_index - 2] == 0xfe && m_packet[m_index - 1] == 0x00) { - //TODO play capture! - m_index = 0; - m_packet[0] = 0; - m_state = STATE_ADPCM; + bool have_all_data = false; + if (m_index >= 2 && m_packet[m_index - 2] == 0xfe && m_packet[m_index - 1] == 0x00) + { + //TODO play capture! + if (m_index >= 6) + { + // offsets 2 and 3 in the transferred pcm data seem to contain the number of samples + uint16_t count = (m_packet[4] << 8) | m_packet[3]; + count--; + m_packet[3] = count & 0xff; + m_packet[4] = (count >> 8); + if (count == 0) + { + m_index = 0; + m_packet[0] = 0; + m_state = STATE_ADPCM; + have_all_data = true; + } + } + } + if (!have_all_data) + m_timer->adjust(attotime::from_ticks(512, clock())); } - else - m_timer->adjust(attotime::from_ticks(512, clock())); break; //garbage: wipe stack