// SPDX-License-Identifier: GPL-3.0-or-later #include #include "internal.h" // Load one timed event into sound buffer 0, a silent event on the same // channel, then the terminator and Execute Buffer 0 command. The firmware // would otherwise continue playing the last event beyond its duration. static unsigned char play_event(unsigned char operation, unsigned int period, unsigned char volume, unsigned char duration, unsigned int poll_limit) { unsigned char packet[11]; unsigned char i = 0; packet[i++] = 0x98; packet[i++] = operation | volume; if (!(operation & 0x80)) packet[i++] = (unsigned char)(period >> 8); packet[i++] = (unsigned char)period; packet[i++] = duration; packet[i++] = operation; if (!(operation & 0x80)) packet[i++] = (unsigned char)(period >> 8); packet[i++] = (unsigned char)period; packet[i++] = 0; packet[i++] = 0xFF; packet[i++] = 0xD8; return ssc_write_bytes(packet, i, poll_limit); } unsigned char ssc_play_effect(unsigned char channel, unsigned int period, unsigned char volume, unsigned char duration, unsigned int poll_limit) { if (channel > 2 || !period || period > 4095 || volume > 15) return SSC_INVALID; return play_event(channel << 5, period, volume, duration, poll_limit); } unsigned char ssc_play_noise(unsigned char channel, unsigned char period, unsigned char volume, unsigned char duration, unsigned int poll_limit) { if (channel > 2 || period > 31 || volume > 15) return SSC_INVALID; return play_event(0x80 | (channel << 5), period, volume, duration, poll_limit); }