if (val == 0 && (r & 0xff8) == 0xd88)\r
return;\r
\r
- do_samples_if_needed(cycles, 0);\r
+ do_samples_if_needed(cycles, 0, 16);\r
\r
if(r>=0x0c00 && r<0x0d80) // some channel info?\r
{\r
//-------------------------------------------------//\r
case H_SPUaddr:\r
spu.spuAddr = (unsigned long) val<<3;\r
+ //check_irq_io(spu.spuAddr);\r
break;\r
//-------------------------------------------------//\r
case H_SPUdata:\r
*(unsigned short *)(spu.spuMemC + spu.spuAddr) = HTOLE16(val);\r
spu.spuAddr += 2;\r
spu.spuAddr &= 0x7fffe;\r
+ check_irq_io(spu.spuAddr);\r
break;\r
//-------------------------------------------------//\r
case H_SPUctrl:\r
case H_SPUirqAddr:\r
//if (val & 1)\r
// log_unhandled("w irq with lsb: %08lx %04x\n", reg, val);\r
- spu.pSpuIrq=spu.spuMemC+(((unsigned long) val<<3)&~0xf);\r
+ spu.pSpuIrq = spu.spuMemC + (((int)val << 3) & ~0xf);\r
+ //check_irq_io(spu.spuAddr);\r
goto upd_irq;\r
//-------------------------------------------------//\r
case H_SPUrvolL:\r
- spu.rvb->VolLeft=val;\r
+ spu.rvb->VolLeft = (int16_t)val;\r
break;\r
//-------------------------------------------------//\r
case H_SPUrvolR:\r
- spu.rvb->VolRight=val;\r
+ spu.rvb->VolRight = (int16_t)val;\r
break;\r
//-------------------------------------------------//\r
\r
*/\r
//-------------------------------------------------//\r
case H_SPUon1:\r
+ spu.last_keyon_cycles = cycles;\r
+ do_samples_if_needed(cycles, 0, 2);\r
SoundOn(0,16,val);\r
break;\r
//-------------------------------------------------//\r
- case H_SPUon2:\r
+ case H_SPUon2:\r
+ spu.last_keyon_cycles = cycles;\r
+ do_samples_if_needed(cycles, 0, 2);\r
SoundOn(16,24,val);\r
break;\r
//-------------------------------------------------//\r
case H_SPUoff1:\r
+ if (cycles - spu.last_keyon_cycles < 786u) {\r
+ if (val & regAreaGet(H_SPUon1))\r
+ log_unhandled("koff1 %04x %d\n", val, cycles - spu.last_keyon_cycles);\r
+ val &= ~regAreaGet(H_SPUon1);\r
+ }\r
SoundOff(0,16,val);\r
break;\r
//-------------------------------------------------//\r
case H_SPUoff2:\r
+ if (cycles - spu.last_keyon_cycles < 786u) {\r
+ if (val & regAreaGet(H_SPUon1))\r
+ log_unhandled("koff2 %04x %d\n", val, cycles - spu.last_keyon_cycles);\r
+ val &= ~regAreaGet(H_SPUon2);\r
+ }\r
SoundOff(16,24,val);\r
break;\r
//-------------------------------------------------//\r
case H_CDLeft:\r
spu.iLeftXAVol=(int16_t)val;\r
- if(spu.cddavCallback) spu.cddavCallback(0,(int16_t)val);\r
+ //if(spu.cddavCallback) spu.cddavCallback(0,(int16_t)val);\r
break;\r
case H_CDRight:\r
spu.iRightXAVol=(int16_t)val;\r
- if(spu.cddavCallback) spu.cddavCallback(1,(int16_t)val);\r
+ //if(spu.cddavCallback) spu.cddavCallback(1,(int16_t)val);\r
break;\r
//-------------------------------------------------//\r
case H_FMod1:\r
// READ REGISTER: called by main emu\r
////////////////////////////////////////////////////////////////////////\r
\r
-unsigned short CALLBACK SPUreadRegister(unsigned long reg)\r
+unsigned short CALLBACK SPUreadRegister(unsigned long reg, unsigned int cycles)\r
{\r
const unsigned long r = reg & 0xffe;\r
\r
{\r
case 12: // get adsr vol\r
{\r
- const int ch=(r>>4)-0xc0;\r
- if(spu.dwNewChannel&(1<<ch)) return 1; // we are started, but not processed? return 1\r
- if((spu.dwChannelsAudible&(1<<ch)) && // same here... we haven't decoded one sample yet, so no envelope yet. return 1 as well\r
- !spu.s_chan[ch].ADSRX.EnvelopeVol)\r
- return 1;\r
- return (unsigned short)(spu.s_chan[ch].ADSRX.EnvelopeVol>>16);\r
+ // this used to return 1 immediately after keyon to deal with\r
+ // some poor timing, but that causes Rayman 2 to lose track of\r
+ // it's channels on busy scenes and start looping some of them forever\r
+ const int ch = (r>>4) - 0xc0;\r
+ if (spu.s_chan[ch].bStarting)\r
+ do_samples_if_needed(cycles, 0, 2);\r
+ return (unsigned short)(spu.s_chan[ch].ADSRX.EnvelopeVol >> 16);\r
}\r
\r
case 14: // get loop address\r
case H_SPUaddr:\r
return (unsigned short)(spu.spuAddr>>3);\r
\r
+ // this reportedly doesn't work on real hw\r
case H_SPUdata:\r
{\r
unsigned short s = LE16TOH(*(unsigned short *)(spu.spuMemC + spu.spuAddr));\r
spu.spuAddr += 2;\r
spu.spuAddr &= 0x7fffe;\r
+ //check_irq_io(spu.spuAddr);\r
return s;\r
}\r
\r
if((val&1) && regAreaGetCh(ch, 6)) // mmm... start has to be set before key on !?!\r
{\r
spu.s_chan[ch].bIgnoreLoop = 0;\r
+ spu.s_chan[ch].bStarting = 1;\r
spu.dwNewChannel|=(1<<ch);\r
}\r
}\r
static void SoundOff(int start,int end,unsigned short val)\r
{\r
int ch;\r
- for(ch=start;ch<end;ch++,val>>=1) // loop channels\r
+ for (ch = start; val && ch < end; ch++, val >>= 1) // loop channels\r
{\r
if(val&1)\r
{\r
spu.s_chan[ch].iRawPitch = NP;\r
spu.s_chan[ch].sinc = NP << 4;\r
spu.s_chan[ch].sinc_inv = 0;\r
- spu.s_chan[ch].bNewPitch = 1;\r
\r
// don't mess spu.dwChannelsAudible as adsr runs independently\r
}\r
spu.s_chan[ch].bReverb=val&1; // -> reverb on/off\r
}\r
}\r
+\r
+// vim:shiftwidth=1:expandtab\r