diff --git a/src/engine/platform/sound/ymz280b.h b/src/engine/platform/sound/ymz280b.h index 422b816c..0d632538 100644 --- a/src/engine/platform/sound/ymz280b.h +++ b/src/engine/platform/sound/ymz280b.h @@ -36,7 +36,6 @@ public: void device_start(u8 *ext_mem); void device_reset(); - void device_update(); void sound_stream_update(s16 **outputs, int samples); diff --git a/src/engine/platform/ymz280b.cpp b/src/engine/platform/ymz280b.cpp index 4f9f6a93..2d714243 100644 --- a/src/engine/platform/ymz280b.cpp +++ b/src/engine/platform/ymz280b.cpp @@ -151,13 +151,14 @@ void DivPlatformYMZ280B::tick(bool sysTick) { if (chan[i].keyOn) { unsigned int start=s->offYMZ280B; unsigned int loop=0; - unsigned int end=start+s->getCurBufLen(); + unsigned int end=MIN(start+s->getCurBufLen(),getSampleMemCapacity()-1); if (chan[i].audPos>0) { switch (s->depth) { case 3: start+=chan[i].audPos/2; break; case 8: start+=chan[i].audPos; break; case 16: start+=chan[i].audPos*2; break; } + start=MIN(start,end); } if (s->loopStart>=0) { switch (s->depth) { @@ -165,6 +166,7 @@ void DivPlatformYMZ280B::tick(bool sysTick) { case 8: loop=start+s->loopStart; break; case 16: loop=start+s->loopStart*2; break; } + loop=MIN(loop,end); } rWrite(0x01+i*4,ctrl&~0x80); // force keyoff first rWrite(0x20+i*4,(start>>16)&0xff); @@ -408,7 +410,7 @@ void DivPlatformYMZ280B::renderSamples() { DivSample* s=parent->song.sample[i]; int length=s->getCurBufLen(); unsigned char* src=(unsigned char*)s->getCurBuf(); - int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-length,length); + int actualLength=MIN((int)(getSampleMemCapacity()-memPos),length); if (actualLength>0) { memcpy(&sampleMem[memPos],src,actualLength); s->offYMZ280B=memPos;