unsigned char Track;
boolean Play, Muted;
int CurTrack;
- int Mode, File, Channel;
+ unsigned char Mode;
+ unsigned char FileChannelSelected;
+ unsigned char CurFile, CurChannel;
+ int FilterFile, FilterChannel;
unsigned char LocL[8];
- int FirstSector;
+ int unused4;
xa_decode_t Xa;
u16 CmdInProgress;
u8 Irq1Pending;
- u8 unused5;
+ u8 AdpcmActive;
u32 LastReadSeekCycles;
u8 unused7;
if (!cdr.Muted && cdr.Play && !Config.Cdda) {
cdrPrepCdda(read_buf, CD_FRAMESIZE_RAW / 4);
cdrAttenuate(read_buf, CD_FRAMESIZE_RAW / 4, 1);
- SPU_playCDDAchannel(read_buf, CD_FRAMESIZE_RAW, psxRegs.cycle, cdr.FirstSector);
- cdr.FirstSector = 0;
+ SPU_playCDDAchannel(read_buf, CD_FRAMESIZE_RAW, psxRegs.cycle, 0);
}
msfiAdd(cdr.SetSectorPlay, 1);
cdr.LocL[0] = LOCL_INVALID;
cdr.SubqForwardSectors = 1;
cdr.TrackChanged = FALSE;
- cdr.FirstSector = 1;
+ cdr.FileChannelSelected = 0;
+ cdr.AdpcmActive = 0;
cdr.ReportDelay = 60;
cdr.sectorsRead = 0;
break;
case CdlSetfilter:
- cdr.File = cdr.Param[0];
- cdr.Channel = cdr.Param[1];
+ cdr.FilterFile = cdr.Param[0];
+ cdr.FilterChannel = cdr.Param[1];
break;
case CdlSetmode:
SetResultSize(5);
cdr.Result[1] = cdr.Mode;
cdr.Result[2] = 0;
- cdr.Result[3] = cdr.File;
- cdr.Result[4] = cdr.Channel;
+ cdr.Result[3] = cdr.FilterFile;
+ cdr.Result[4] = cdr.FilterChannel;
break;
case CdlGetlocL:
cdr.SetlocPending = 0;
}
cdr.Reading = 1;
- cdr.FirstSector = 1;
+ cdr.FileChannelSelected = 0;
+ cdr.AdpcmActive = 0;
// Fighting Force 2 - update subq time immediately
// - fixes new game
static void cdrReadInterrupt(void)
{
- u8 *buf = NULL, *hdr;
+ const struct { u8 file, chan, mode, coding; } *subhdr;
+ const u8 *buf = NULL;
+ int deliver_data = 1;
u8 subqPos[3];
int read_ok;
if (!cdr.Stat && !cdr.Irq1Pending)
cdrUpdateTransferBuf(buf);
- if ((!cdr.Muted) && (cdr.Mode & MODE_STRSND) && (!Config.Xa) && (cdr.FirstSector != -1)) { // CD-XA
- hdr = buf + 4;
- // Firemen 2: Multi-XA files - briefings, cutscenes
- if( cdr.FirstSector == 1 && (cdr.Mode & MODE_SF)==0 ) {
- cdr.File = hdr[0];
- cdr.Channel = hdr[1];
+ subhdr = (void *)(buf + 4);
+ do {
+ // try to process as adpcm
+ if (!(cdr.Mode & MODE_STRSND))
+ break;
+ if (buf[3] != 2 || (subhdr->mode & 0x44) != 0x44) // or 0x64?
+ break;
+ CDR_LOG("f=%d m=%d %d,%3d | %d,%2d | %d,%2d\n", !!(cdr.Mode & MODE_SF), cdr.Muted,
+ subhdr->file, subhdr->chan, cdr.CurFile, cdr.CurChannel, cdr.FilterFile, cdr.FilterChannel);
+ if ((cdr.Mode & MODE_SF) && (subhdr->file != cdr.FilterFile || subhdr->chan != cdr.FilterChannel))
+ break;
+ if (subhdr->chan & 0xe0) { // ?
+ if (subhdr->chan != 0xff)
+ log_unhandled("adpcm %d:%d\n", subhdr->file, subhdr->chan);
+ break;
+ }
+ if (!cdr.FileChannelSelected) {
+ cdr.CurFile = subhdr->file;
+ cdr.CurChannel = subhdr->chan;
+ cdr.FileChannelSelected = 1;
}
+ else if (subhdr->file != cdr.CurFile || subhdr->chan != cdr.CurChannel)
+ break;
- /* Gameblabla
- * Skips playing on channel 255.
- * Fixes missing audio in Blue's Clues : Blue's Big Musical. (Should also fix Taxi 2)
- * TODO : Check if this is the proper behaviour.
- * */
- if ((hdr[2] & 0x4) && hdr[0] == cdr.File && hdr[1] == cdr.Channel && cdr.Channel != 255) {
- int ret = xa_decode_sector(&cdr.Xa, buf + 4, cdr.FirstSector);
- if (!ret) {
- cdrAttenuate(cdr.Xa.pcm, cdr.Xa.nsamples, cdr.Xa.stereo);
- SPU_playADPCMchannel(&cdr.Xa, psxRegs.cycle, cdr.FirstSector);
- cdr.FirstSector = 0;
- }
- else cdr.FirstSector = -1;
+ // accepted as adpcm
+ deliver_data = 0;
+
+ if (Config.Xa)
+ break;
+ if (!cdr.Muted && cdr.AdpcmActive) {
+ cdrAttenuate(cdr.Xa.pcm, cdr.Xa.nsamples, cdr.Xa.stereo);
+ SPU_playADPCMchannel(&cdr.Xa, psxRegs.cycle, 0);
}
- }
+ // decode next
+ cdr.AdpcmActive = !xa_decode_sector(&cdr.Xa, buf + 4, !cdr.AdpcmActive);
+ } while (0);
+
+ if ((cdr.Mode & MODE_SF) && (subhdr->mode & 0x44) == 0x44) // according to nocash
+ deliver_data = 0;
/*
Croc 2: $40 - only FORM1 (*)
Sim Theme Park - no adpcm at all (zero)
*/
- if (!(cdr.Mode & MODE_STRSND) || !(buf[4+2] & 0x4))
+ if (deliver_data)
cdrReadInterruptSetResult(cdr.StatP);
msfiAdd(cdr.SetSectorPlay, 1);
/*
cdrRead0:
- bit 0,1 - mode
- bit 2 - unknown
- bit 3 - unknown
- bit 4 - unknown
+ bit 0,1 - reg index
+ bit 2 - adpcm active
bit 5 - 1 result ready
bit 6 - 1 dma ready
bit 7 - 1 command being processed
*/
unsigned char cdrRead0(void) {
- if (cdr.ResultReady)
- cdr.Ctrl |= 0x20;
- else
- cdr.Ctrl &= ~0x20;
+ cdr.Ctrl &= ~0x24;
+ cdr.Ctrl |= cdr.AdpcmActive << 2;
+ cdr.Ctrl |= cdr.ResultReady << 5;
cdr.Ctrl |= 0x40; // data fifo not empty
void cdrReset() {
memset(&cdr, 0, sizeof(cdr));
cdr.CurTrack = 1;
- cdr.File = 1;
- cdr.Channel = 1;
+ cdr.FilterFile = 0;
+ cdr.FilterChannel = 0;
cdr.Reg2 = 0x1f;
cdr.Stat = NoIntr;
cdr.FifoOffset = DATA_SIZE; // fifo empty
static int headtable[4] = {0,2,8,10};
//===========================================
-static void xa_decode_data( xa_decode_t *xdp, unsigned char *srcp ) {
+static void xa_decode_data( xa_decode_t *xdp, const unsigned char *srcp ) {
const u8 *sound_groupsp;
const u8 *sound_datap, *sound_datap2;
int i, j, k, nbits;
//============================================
static int parse_xa_audio_sector( xa_decode_t *xdp,
- xa_subheader_t *subheadp,
- unsigned char *sectorp,
+ const xa_subheader_t *subheadp,
+ const unsigned char *sectorp,
int is_first_sector ) {
if ( is_first_sector ) {
switch ( AUDIO_CODING_GET_FREQ(subheadp->coding) ) {
//=== - 0 for any other successive sector
//=== return -1 if error
//================================================================
-s32 xa_decode_sector( xa_decode_t *xdp,
- unsigned char *sectorp, int is_first_sector ) {
+s32 xa_decode_sector( xa_decode_t *xdp, const unsigned char *sectorp, int is_first_sector ) {
if (parse_xa_audio_sector(xdp, (xa_subheader_t *)sectorp, sectorp + sizeof(xa_subheader_t), is_first_sector))
return -1;
// XA AUDIO
-void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap, unsigned int cycle, int is_start)
+void CALLBACK SPUplayADPCMchannel(xa_decode_t *xap, unsigned int cycle, int unused)
{
if(!xap) return;
if(!xap->freq) return; // no xa freq ? bye
- if (is_start)
+ if (spu.XAPlay == spu.XAFeed)
do_samples(cycle, 1); // catch up to prevent source underflows later
FeedXA(xap); // call main XA feeder
}
// CDDA AUDIO
-int CALLBACK SPUplayCDDAchannel(short *pcm, int nbytes, unsigned int cycle, int is_start)
+int CALLBACK SPUplayCDDAchannel(short *pcm, int nbytes, unsigned int cycle, int unused)
{
if (!pcm) return -1;
if (nbytes<=0) return -1;
- if (is_start)
+ if (spu.CDDAPlay == spu.CDDAFeed)
do_samples(cycle, 1); // catch up to prevent source underflows later
FeedCDDA((unsigned char *)pcm, nbytes);