X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fdfsound%2Fregisters.c;h=e0693064db57616b716464fdd304ec2d1359f42b;hb=HEAD;hp=bcac4d9ad63d8e95e4d7b48204447482d8125819;hpb=3c7a8977ddbdbfb4a8840a487fadade29bd939d6;p=pcsx_rearmed.git diff --git a/plugins/dfsound/registers.c b/plugins/dfsound/registers.c index bcac4d9a..6d72d3ca 100644 --- a/plugins/dfsound/registers.c +++ b/plugins/dfsound/registers.c @@ -60,7 +60,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, if (val == 0 && (r & 0xff8) == 0xd88) return; - do_samples_if_needed(cycles, 0); + do_samples_if_needed(cycles, 0, 16); if(r>=0x0c00 && r<0x0d80) // some channel info? { @@ -132,7 +132,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, { //-------------------------------------------------// case H_SPUaddr: - spu.spuAddr = (unsigned long) val<<3; + spu.spuAddr = (unsigned int)val << 3; //check_irq_io(spu.spuAddr); break; //-------------------------------------------------// @@ -144,8 +144,9 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, break; //-------------------------------------------------// case H_SPUctrl: + spu.spuStat = (spu.spuStat & ~0xbf) | (val & 0x3f) | ((val << 2) & 0x80); + spu.spuStat &= ~STAT_IRQ | val; if (!(spu.spuCtrl & CTRL_IRQ)) { - spu.spuStat&=~STAT_IRQ; if (val & CTRL_IRQ) schedule_next_irq(); } @@ -153,7 +154,7 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, break; //-------------------------------------------------// case H_SPUstat: - spu.spuStat=val&0xf800; + //spu.spuStat=val&0xf800; break; //-------------------------------------------------// case H_SPUReverbAddr: @@ -167,11 +168,11 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, goto upd_irq; //-------------------------------------------------// case H_SPUrvolL: - spu.rvb->VolLeft=val; + spu.rvb->VolLeft = (int16_t)val; break; //-------------------------------------------------// case H_SPUrvolR: - spu.rvb->VolRight=val; + spu.rvb->VolRight = (int16_t)val; break; //-------------------------------------------------// @@ -213,28 +214,44 @@ void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val, */ //-------------------------------------------------// case H_SPUon1: + spu.last_keyon_cycles = cycles; + do_samples_if_needed(cycles, 0, 2); SoundOn(0,16,val); break; //-------------------------------------------------// - case H_SPUon2: + case H_SPUon2: + spu.last_keyon_cycles = cycles; + do_samples_if_needed(cycles, 0, 2); SoundOn(16,24,val); break; //-------------------------------------------------// case H_SPUoff1: + if (cycles - spu.last_keyon_cycles < 786u) { + if (val & regAreaGet(H_SPUon1)) + log_unhandled("koff1 %04x %d\n", val, cycles - spu.last_keyon_cycles); + val &= ~regAreaGet(H_SPUon1); + } + do_samples_if_needed(cycles, 0, 2); SoundOff(0,16,val); break; //-------------------------------------------------// case H_SPUoff2: + if (cycles - spu.last_keyon_cycles < 786u) { + if (val & regAreaGet(H_SPUon1)) + log_unhandled("koff2 %04x %d\n", val, cycles - spu.last_keyon_cycles); + val &= ~regAreaGet(H_SPUon2); + } + do_samples_if_needed(cycles, 0, 2); SoundOff(16,24,val); break; //-------------------------------------------------// case H_CDLeft: spu.iLeftXAVol=(int16_t)val; - if(spu.cddavCallback) spu.cddavCallback(0,(int16_t)val); + //if(spu.cddavCallback) spu.cddavCallback(0,(int16_t)val); break; case H_CDRight: spu.iRightXAVol=(int16_t)val; - if(spu.cddavCallback) spu.cddavCallback(1,(int16_t)val); + //if(spu.cddavCallback) spu.cddavCallback(1,(int16_t)val); break; //-------------------------------------------------// case H_FMod1: @@ -309,7 +326,7 @@ rvbd: // READ REGISTER: called by main emu //////////////////////////////////////////////////////////////////////// -unsigned short CALLBACK SPUreadRegister(unsigned long reg) +unsigned short CALLBACK SPUreadRegister(unsigned long reg, unsigned int cycles) { const unsigned long r = reg & 0xffe; @@ -319,12 +336,13 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) { case 12: // get adsr vol { - const int ch=(r>>4)-0xc0; - if(spu.dwNewChannel&(1<>16); + // this used to return 1 immediately after keyon to deal with + // some poor timing, but that causes Rayman 2 to lose track of + // it's channels on busy scenes and start looping some of them forever + const int ch = (r>>4) - 0xc0; + if (spu.s_chan[ch].bStarting) + do_samples_if_needed(cycles, 0, 2); + return (unsigned short)(spu.s_chan[ch].ADSRX.EnvelopeVol >> 16); } case 14: // get loop address @@ -348,7 +366,7 @@ unsigned short CALLBACK SPUreadRegister(unsigned long reg) return spu.spuCtrl; case H_SPUstat: - return (spu.spuStat & ~0x3F) | (spu.spuCtrl & 0x3F); + return spu.spuStat; case H_SPUaddr: return (unsigned short)(spu.spuAddr>>3); @@ -404,6 +422,7 @@ static void SoundOn(int start,int end,unsigned short val) if((val&1) && regAreaGetCh(ch, 6)) // mmm... start has to be set before key on !?! { spu.s_chan[ch].bIgnoreLoop = 0; + spu.s_chan[ch].bStarting = 1; spu.dwNewChannel|=(1<>=1) // loop channels + for (ch = start; val && ch < end; ch++, val >>= 1) // loop channels { if(val&1) { @@ -542,7 +561,6 @@ static void SetPitch(int ch,unsigned short val) // SET PITCH spu.s_chan[ch].iRawPitch = NP; spu.s_chan[ch].sinc = NP << 4; spu.s_chan[ch].sinc_inv = 0; - spu.s_chan[ch].bNewPitch = 1; // don't mess spu.dwChannelsAudible as adsr runs independently } @@ -560,3 +578,5 @@ static void ReverbOn(int start,int end,unsigned short val) spu.s_chan[ch].bReverb=val&1; // -> reverb on/off } } + +// vim:shiftwidth=1:expandtab