Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include <vcc/ssc.h>
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#ifndef VCC_SSC_INTERNAL_H
|
||||
#define VCC_SSC_INTERNAL_H
|
||||
|
||||
// Prevalidated packet or portion of a packet. Each byte gets its own budget.
|
||||
unsigned char ssc_write_bytes(const unsigned char *bytes, unsigned int count,
|
||||
unsigned int poll_limit);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include <vcc/ssc.h>
|
||||
#include "internal.h"
|
||||
|
||||
unsigned char ssc_begin_phrase(ssc_phrase *phrase, const char *text)
|
||||
{
|
||||
unsigned char length = 0;
|
||||
if (!phrase || !text)
|
||||
return SSC_INVALID;
|
||||
while (text[length]) {
|
||||
unsigned char c = text[length];
|
||||
if (length >= SSC_MAX_TEXT || c < 32 || c > 126)
|
||||
return SSC_INVALID;
|
||||
++length;
|
||||
}
|
||||
if (!length)
|
||||
return SSC_INVALID;
|
||||
phrase->next = text;
|
||||
phrase->remaining = length + 2;
|
||||
return SSC_OK;
|
||||
}
|
||||
|
||||
unsigned char ssc_service(ssc_phrase *phrase)
|
||||
{
|
||||
unsigned char value;
|
||||
if (!phrase || phrase->remaining > SSC_MAX_TEXT + 2)
|
||||
return SSC_INVALID;
|
||||
if (!phrase->remaining)
|
||||
return SSC_OK;
|
||||
if (phrase->remaining > 2) {
|
||||
value = *phrase->next;
|
||||
if (value >= 'a' && value <= 'z')
|
||||
value -= 'a' - 'A';
|
||||
} else {
|
||||
value = phrase->remaining == 2 ? ' ' : 13;
|
||||
}
|
||||
if (ssc_try_write(value)) {
|
||||
if (phrase->remaining > 2)
|
||||
++phrase->next;
|
||||
--phrase->remaining;
|
||||
}
|
||||
return phrase->remaining ? SSC_PENDING : SSC_OK;
|
||||
}
|
||||
|
||||
static unsigned char submit_phrase(ssc_phrase *phrase, unsigned int poll_limit)
|
||||
{
|
||||
unsigned int budget = poll_limit;
|
||||
while (budget) {
|
||||
unsigned char before = phrase->remaining;
|
||||
if (ssc_service(phrase) == SSC_OK)
|
||||
return SSC_OK;
|
||||
if (before == phrase->remaining)
|
||||
--budget;
|
||||
else
|
||||
budget = poll_limit;
|
||||
}
|
||||
return SSC_TIMEOUT;
|
||||
}
|
||||
|
||||
unsigned char ssc_say(const char *text, unsigned int poll_limit)
|
||||
{
|
||||
ssc_phrase phrase;
|
||||
unsigned char result = ssc_begin_phrase(&phrase, text);
|
||||
if (result != SSC_OK)
|
||||
return result;
|
||||
return submit_phrase(&phrase, poll_limit);
|
||||
}
|
||||
|
||||
unsigned char ssc_store_phrase(unsigned char slot, const char *text,
|
||||
unsigned int poll_limit)
|
||||
{
|
||||
ssc_phrase phrase;
|
||||
unsigned char command;
|
||||
if (slot > 7 || ssc_begin_phrase(&phrase, text) != SSC_OK)
|
||||
return SSC_INVALID;
|
||||
command = 0x90 + slot;
|
||||
if (ssc_write_bytes(&command, 1, poll_limit) != SSC_OK)
|
||||
return SSC_TIMEOUT;
|
||||
return submit_phrase(&phrase, poll_limit);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include <vcc/ssc.h>
|
||||
#include "internal.h"
|
||||
|
||||
// CMOC accepts volatile but does not implement its C semantics. Use one
|
||||
// explicit bus read per poll; a second read must never reuse the first value.
|
||||
asm unsigned char ssc_status(void)
|
||||
{
|
||||
asm {
|
||||
ldb $FF7E
|
||||
andb #$E0
|
||||
}
|
||||
}
|
||||
|
||||
asm unsigned char ssc_try_write(unsigned char value)
|
||||
{
|
||||
asm {
|
||||
tst $FF7E
|
||||
bpl @busy
|
||||
ldb 3,s ; low byte of first CMOC argument
|
||||
stb $FF7E
|
||||
ldb #1
|
||||
bra @done
|
||||
@busy clrb
|
||||
@done
|
||||
}
|
||||
}
|
||||
|
||||
asm void ssc_reset(void)
|
||||
{
|
||||
asm {
|
||||
ldb #1
|
||||
stb $FF7D
|
||||
clrb
|
||||
stb $FF7D
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char ssc_write_bytes(const unsigned char *bytes, unsigned int count,
|
||||
unsigned int poll_limit)
|
||||
{
|
||||
while (count) {
|
||||
unsigned int remaining = poll_limit;
|
||||
while (remaining && !ssc_try_write(*bytes))
|
||||
--remaining;
|
||||
if (!remaining)
|
||||
return SSC_TIMEOUT;
|
||||
++bytes;
|
||||
--count;
|
||||
}
|
||||
return SSC_OK;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include <vcc/ssc.h>
|
||||
|
||||
// C2 mode and level occupy bits 5..3. Bits 2..0 select the PIA data
|
||||
// register, interrupt edge and interrupt enable. Bits 7..6 are IRQ flags.
|
||||
#define PIA_MUX_LOW (*(unsigned char *)0xFF01)
|
||||
#define PIA_MUX_HIGH (*(unsigned char *)0xFF03)
|
||||
#define PIA_SOUND (*(unsigned char *)0xFF23)
|
||||
#define C2_LOW 0x30
|
||||
#define C2_HIGH 0x38
|
||||
|
||||
unsigned int ssc_route_audio(void)
|
||||
{
|
||||
unsigned char flags, low, high, sound;
|
||||
unsigned int saved;
|
||||
// Keep an interrupt handler from changing a control register between our
|
||||
// read and write. The exact incoming interrupt masks are restored.
|
||||
asm {
|
||||
tfr cc,a
|
||||
orcc #$50
|
||||
sta :flags
|
||||
}
|
||||
low = PIA_MUX_LOW;
|
||||
high = PIA_MUX_HIGH;
|
||||
sound = PIA_SOUND;
|
||||
saved = ((unsigned int)(low & 0x38) << 3) | (high & 0x38) | ((sound & 0x38) >> 3);
|
||||
PIA_MUX_LOW = (low & 7) | C2_LOW;
|
||||
PIA_MUX_HIGH = (high & 7) | C2_HIGH;
|
||||
PIA_SOUND = (sound & 7) | C2_HIGH;
|
||||
asm {
|
||||
lda :flags
|
||||
tfr a,cc
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
void ssc_restore_audio(unsigned int saved)
|
||||
{
|
||||
unsigned char flags;
|
||||
asm {
|
||||
tfr cc,a
|
||||
orcc #$50
|
||||
sta :flags
|
||||
}
|
||||
PIA_MUX_LOW = (PIA_MUX_LOW & 7) | (unsigned char)((saved >> 3) & 0x38);
|
||||
PIA_MUX_HIGH = (PIA_MUX_HIGH & 7) | (unsigned char)(saved & 0x38);
|
||||
PIA_SOUND = (PIA_SOUND & 7) | (unsigned char)((saved << 3) & 0x38);
|
||||
asm {
|
||||
lda :flags
|
||||
tfr a,cc
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#include <vcc/ssc.h>
|
||||
#include "internal.h"
|
||||
|
||||
static unsigned char play_slot(unsigned char command, unsigned char slot,
|
||||
unsigned int poll_limit)
|
||||
{
|
||||
if (slot > 7)
|
||||
return SSC_INVALID;
|
||||
command += slot;
|
||||
return ssc_write_bytes(&command, 1, poll_limit);
|
||||
}
|
||||
|
||||
unsigned char ssc_play_phrase(unsigned char slot, unsigned int poll_limit)
|
||||
{
|
||||
return play_slot(0xD0, slot, poll_limit);
|
||||
}
|
||||
|
||||
unsigned char ssc_store_allophones(unsigned char slot, const unsigned char *codes,
|
||||
unsigned int count, unsigned int poll_limit)
|
||||
{
|
||||
static const unsigned char end[] = {SSC_AL_PA1, 0xFF};
|
||||
unsigned char command;
|
||||
unsigned int i;
|
||||
if (slot > 7 || !codes || !count || count > SSC_MAX_ALLOPHONES)
|
||||
return SSC_INVALID;
|
||||
for (i = 0; i < count; ++i)
|
||||
if (codes[i] > SSC_AL_BB2)
|
||||
return SSC_INVALID;
|
||||
|
||||
command = 0xB0 + slot;
|
||||
if (ssc_write_bytes(&command, 1, poll_limit) != SSC_OK ||
|
||||
ssc_write_bytes(codes, count, poll_limit) != SSC_OK)
|
||||
return SSC_TIMEOUT;
|
||||
return ssc_write_bytes(end, sizeof(end), poll_limit);
|
||||
}
|
||||
|
||||
unsigned char ssc_play_allophones(unsigned char slot, unsigned int poll_limit)
|
||||
{
|
||||
return play_slot(0xF0, slot, poll_limit);
|
||||
}
|
||||
|
||||
unsigned char ssc_store_enveloped_tone(unsigned char slot, unsigned char channel,
|
||||
unsigned int tone_period, unsigned char shape,
|
||||
unsigned int envelope_period, unsigned char duration,
|
||||
unsigned int poll_limit)
|
||||
{
|
||||
unsigned char packet[18];
|
||||
if (slot > 7 || channel > 2 || !tone_period || tone_period > 4095 ||
|
||||
shape > 15 || !envelope_period)
|
||||
return SSC_INVALID;
|
||||
|
||||
packet[0] = 0x98 + slot;
|
||||
// The PIC writes the shape before the period. On a cold cartridge a
|
||||
// one-shot can finish at the old period before the PIC enables the tone.
|
||||
// Prime the generator and retrigger with the tone gate already open.
|
||||
packet[1] = 0x60 | shape;
|
||||
packet[2] = (unsigned char)(envelope_period >> 8);
|
||||
packet[3] = (unsigned char)envelope_period;
|
||||
packet[4] = 0;
|
||||
packet[5] = (channel << 5) | 0x10;
|
||||
packet[6] = (unsigned char)(tone_period >> 8);
|
||||
packet[7] = (unsigned char)tone_period;
|
||||
packet[8] = duration; // The tone's timer schedules the silence.
|
||||
packet[9] = packet[1];
|
||||
packet[10] = packet[2];
|
||||
packet[11] = packet[3];
|
||||
packet[12] = 0;
|
||||
packet[13] = channel << 5; // Final event selects fixed amplitude zero.
|
||||
packet[14] = packet[6];
|
||||
packet[15] = packet[7];
|
||||
packet[16] = 0;
|
||||
packet[17] = 0xFF;
|
||||
return ssc_write_bytes(packet, sizeof(packet), poll_limit);
|
||||
}
|
||||
|
||||
unsigned char ssc_play_stored_effect(unsigned char slot, unsigned int poll_limit)
|
||||
{
|
||||
return play_slot(0xD8, slot, poll_limit);
|
||||
}
|
||||
Reference in new issue
Block a user