From a6e434586370cce9284771f0f12eb12117b4e68c Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 25 Sep 2022 20:07:21 -0500 Subject: [PATCH] PLENTY OF TODO WHEN I COME BACK CRASHES EVERYWHERE --- src/engine/platform/msm6258.cpp | 1 - src/engine/platform/msm6295.cpp | 13 +++++++----- src/engine/platform/nes.cpp | 6 +++--- src/engine/platform/nes.h | 1 + src/engine/platform/opl.cpp | 15 +++++++------- src/engine/platform/opl.h | 1 + src/engine/platform/qsound.cpp | 11 +++++----- src/engine/platform/qsound.h | 3 +++ src/engine/platform/rf5c68.cpp | 8 ++++++-- src/engine/platform/rf5c68.h | 1 + src/engine/platform/segapcm.cpp | 32 +++++++++++++++++------------- src/engine/platform/segapcm.h | 3 +++ src/engine/platform/snes.cpp | 6 ++++-- src/engine/platform/snes.h | 1 + src/engine/platform/su.cpp | 12 ++++++----- src/engine/platform/su.h | 1 + src/engine/platform/x1_010.cpp | 19 +++++++++--------- src/engine/platform/x1_010.h | 1 + src/engine/platform/ym2608.cpp | 15 +++++++------- src/engine/platform/ym2608.h | 1 + src/engine/platform/ym2610.cpp | 24 +++++++++++----------- src/engine/platform/ym2610b.cpp | 24 +++++++++++----------- src/engine/platform/ym2610shared.h | 9 +++++++-- src/engine/platform/ymz280b.cpp | 6 ++++-- src/engine/platform/ymz280b.h | 1 + src/engine/sample.h | 20 +------------------ src/engine/vgmOps.cpp | 16 ++++++++++++--- src/gui/debugWindow.cpp | 17 ---------------- 28 files changed, 141 insertions(+), 127 deletions(-) diff --git a/src/engine/platform/msm6258.cpp b/src/engine/platform/msm6258.cpp index ded3899ef..05465bbed 100644 --- a/src/engine/platform/msm6258.cpp +++ b/src/engine/platform/msm6258.cpp @@ -382,7 +382,6 @@ void DivPlatformMSM6258::renderSamples() { } else { memcpy(adpcmMem+memPos,s->dataVOX,paddedLen); } - s->offVOX=memPos; memPos+=paddedLen; } adpcmMemLen=memPos+256; diff --git a/src/engine/platform/msm6295.cpp b/src/engine/platform/msm6295.cpp index a898ba150..8b9c573d4 100644 --- a/src/engine/platform/msm6295.cpp +++ b/src/engine/platform/msm6295.cpp @@ -336,7 +336,10 @@ size_t DivPlatformMSM6295::getSampleMemUsage(int index) { } void DivPlatformMSM6295::renderSamples() { + unsigned int sampleOffVOX[256]; + memset(adpcmMem,0,getSampleMemCapacity(0)); + memset(sampleOffVOX,0,256*sizeof(unsigned int)); // sample data size_t memPos=128*8; @@ -355,7 +358,7 @@ void DivPlatformMSM6295::renderSamples() { } else { memcpy(adpcmMem+memPos,s->dataVOX,paddedLen); } - s->offVOX=memPos; + sampleOffVOX[i]=memPos; memPos+=paddedLen; } adpcmMemLen=memPos+256; @@ -363,10 +366,10 @@ void DivPlatformMSM6295::renderSamples() { // phrase book for (int i=0; isong.sample[i]; - int endPos=s->offVOX+s->lengthVOX; - adpcmMem[i*8]=(s->offVOX>>16)&0xff; - adpcmMem[1+i*8]=(s->offVOX>>8)&0xff; - adpcmMem[2+i*8]=(s->offVOX)&0xff; + int endPos=sampleOffVOX[i]+s->lengthVOX; + adpcmMem[i*8]=(sampleOffVOX[i]>>16)&0xff; + adpcmMem[1+i*8]=(sampleOffVOX[i]>>8)&0xff; + adpcmMem[2+i*8]=(sampleOffVOX[i])&0xff; adpcmMem[3+i*8]=(endPos>>16)&0xff; adpcmMem[4+i*8]=(endPos>>8)&0xff; adpcmMem[5+i*8]=(endPos)&0xff; diff --git a/src/engine/platform/nes.cpp b/src/engine/platform/nes.cpp index 06962d351..d087ac810 100644 --- a/src/engine/platform/nes.cpp +++ b/src/engine/platform/nes.cpp @@ -317,7 +317,7 @@ void DivPlatformNES::tick(bool sysTick) { dacRate=MIN(chan[4].freq*off,32000); if (chan[4].keyOn) { if (dpcmMode && !skipRegisterWrites && dacSample>=0 && dacSamplesong.sampleLen) { - unsigned int dpcmAddr=parent->getSample(dacSample)->offDPCM; + unsigned int dpcmAddr=sampleOffDPCM[dacSample]; unsigned int dpcmLen=(parent->getSample(dacSample)->lengthDPCM+15)>>4; if (dpcmLen>255) dpcmLen=255; goingToLoop=parent->getSample(dacSample)->isLoopable(); @@ -383,7 +383,7 @@ int DivPlatformNES::dispatch(DivCommand c) { if (dumpWrites && !dpcmMode) addWrite(0xffff0001,dacRate); chan[c.chan].furnaceDac=false; if (dpcmMode && !skipRegisterWrites) { - unsigned int dpcmAddr=parent->getSample(dacSample)->offDPCM; + unsigned int dpcmAddr=sampleOffDPCM[dacSample]; unsigned int dpcmLen=(parent->getSample(dacSample)->lengthDPCM+15)>>4; if (dpcmLen>255) dpcmLen=255; goingToLoop=parent->getSample(dacSample)->isLoopable(); @@ -724,7 +724,7 @@ void DivPlatformNES::renderSamples() { } else { memcpy(dpcmMem+memPos,s->dataDPCM,MIN(s->lengthDPCM,paddedLen)); } - s->offDPCM=memPos; + sampleOffDPCM[i]=memPos; memPos+=paddedLen; } dpcmMemLen=memPos; diff --git a/src/engine/platform/nes.h b/src/engine/platform/nes.h index 2a9923fa6..e8e04e9e9 100644 --- a/src/engine/platform/nes.h +++ b/src/engine/platform/nes.h @@ -78,6 +78,7 @@ class DivPlatformNES: public DivDispatch { xgm::NES_APU* nes1_NP; xgm::NES_DMC* nes2_NP; unsigned char regPool[128]; + unsigned int sampleOffDPCM[256]; friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); diff --git a/src/engine/platform/opl.cpp b/src/engine/platform/opl.cpp index 5d81f0834..76adeafdc 100644 --- a/src/engine/platform/opl.cpp +++ b/src/engine/platform/opl.cpp @@ -690,9 +690,9 @@ int DivPlatformOPL::dispatch(DivCommand c) { if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); immWrite(8,0); - immWrite(9,(s->offB>>2)&0xff); - immWrite(10,(s->offB>>10)&0xff); - int end=s->offB+s->lengthB-1; + immWrite(9,(sampleOffB[chan[c.chan].sample]>>2)&0xff); + immWrite(10,(sampleOffB[chan[c.chan].sample]>>10)&0xff); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(11,(end>>2)&0xff); immWrite(12,(end>>10)&0xff); if (c.value!=DIV_NOTE_NULL) { @@ -721,9 +721,9 @@ int DivPlatformOPL::dispatch(DivCommand c) { if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(12*sampleBank+c.value%12); immWrite(8,0); - immWrite(9,(s->offB>>2)&0xff); - immWrite(10,(s->offB>>10)&0xff); - int end=s->offB+s->lengthB-1; + immWrite(9,(sampleOffB[chan[c.chan].sample]>>2)&0xff); + immWrite(10,(sampleOffB[chan[c.chan].sample]>>10)&0xff); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(11,(end>>2)&0xff); immWrite(12,(end>>10)&0xff); int freq=(65536.0*(double)s->rate)/(double)chipRateBase; @@ -1760,6 +1760,7 @@ size_t DivPlatformOPL::getSampleMemUsage(int index) { void DivPlatformOPL::renderSamples() { if (adpcmChan<0) return; memset(adpcmBMem,0,getSampleMemCapacity(0)); + memset(sampleOffB,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -1778,7 +1779,7 @@ void DivPlatformOPL::renderSamples() { } else { memcpy(adpcmBMem+memPos,s->dataB,paddedLen); } - s->offB=memPos; + sampleOffB[i]=memPos; memPos+=paddedLen; } adpcmBMemLen=memPos+256; diff --git a/src/engine/platform/opl.h b/src/engine/platform/opl.h index 43f02790f..41be2c896 100644 --- a/src/engine/platform/opl.h +++ b/src/engine/platform/opl.h @@ -90,6 +90,7 @@ class DivPlatformOPL: public DivDispatch { unsigned char* adpcmBMem; size_t adpcmBMemLen; DivOPLAInterface iface; + unsigned int sampleOffB[256]; ymfm::adpcm_b_engine* adpcmB; const unsigned char** slotsNonDrums; diff --git a/src/engine/platform/qsound.cpp b/src/engine/platform/qsound.cpp index 4f7d2545f..2b54a90a6 100644 --- a/src/engine/platform/qsound.cpp +++ b/src/engine/platform/qsound.cpp @@ -286,8 +286,8 @@ void DivPlatformQSound::tick(bool sysTick) { uint16_t qsound_end = 0; if (chan[i].sample>=0 && chan[i].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[i].sample); - qsound_bank = 0x8000 | (s->offQSound >> 16); - qsound_addr = s->offQSound & 0xffff; + qsound_bank = 0x8000 | (offPCM[chan[i].sample] >> 16); + qsound_addr = offPCM[chan[i].sample] & 0xffff; int loopStart=s->loopStart; int length = s->loopEnd; @@ -295,10 +295,10 @@ void DivPlatformQSound::tick(bool sysTick) { length = 65536 - 16; } if (loopStart == -1 || loopStart >= length) { - qsound_end = s->offQSound + length + 15; + qsound_end = offPCM[chan[i].sample] + length + 15; qsound_loop = 15; } else { - qsound_end = s->offQSound + length; + qsound_end = offPCM[chan[i].sample] + length; qsound_loop = length - loopStart; } } @@ -644,6 +644,7 @@ size_t DivPlatformQSound::getSampleMemUsage(int index) { return index == 0 ? sampleMemLen : 0; } +// TODO: ADPCM... come on... void DivPlatformQSound::renderSamples() { memset(sampleMem,0,getSampleMemCapacity()); @@ -671,7 +672,7 @@ void DivPlatformQSound::renderSamples() { sampleMem[(memPos+i)^0x8000]=s->data8[i]; } } - s->offQSound=memPos^0x8000; + offPCM[i]=memPos^0x8000; memPos+=length+16; } sampleMemLen=memPos+256; diff --git a/src/engine/platform/qsound.h b/src/engine/platform/qsound.h index 5e2a32fc7..7743e5943 100644 --- a/src/engine/platform/qsound.h +++ b/src/engine/platform/qsound.h @@ -72,6 +72,9 @@ class DivPlatformQSound: public DivDispatch { struct qsound_chip chip; unsigned short regPool[512]; + unsigned int offPCM[256]; + unsigned int offBS[256]; + friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); diff --git a/src/engine/platform/rf5c68.cpp b/src/engine/platform/rf5c68.cpp index 86d373722..e462e3d8b 100644 --- a/src/engine/platform/rf5c68.cpp +++ b/src/engine/platform/rf5c68.cpp @@ -122,6 +122,9 @@ void DivPlatformRF5C68::tick(bool sysTick) { } else { chan[i].audPos=0; } + // TODO: BANG BANG BANG + // AAAAAAAAAAAAAAAAAAA + // ASGDJFJFSDGL;ASDHFKJLSHFLKAJSFHKLJVSJ if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { unsigned char keyon=regPool[8]&~(1<calcFreq(chan[i].baseFreq,chan[i].pitch,false,2,chan[i].pitch2,chipClock,CHIP_FREQBASE)); if (chan[i].freq>65535) chan[i].freq=65535; if (chan[i].keyOn) { - unsigned int start=s->offRF5C68; + unsigned int start=sampleOffRFC[chan[i].sample]; unsigned int loop=start+s->length8; if (chan[i].audPos>0) { start=start+MIN(chan[i].audPos,s->length8); @@ -383,6 +386,7 @@ size_t DivPlatformRF5C68::getSampleMemUsage(int index) { void DivPlatformRF5C68::renderSamples() { memset(sampleMem,0,getSampleMemCapacity()); + memset(sampleOffRFC,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -390,7 +394,7 @@ void DivPlatformRF5C68::renderSamples() { int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT); int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-31,length); if (actualLength>0) { - s->offRF5C68=memPos; + sampleOffRFC[i]=memPos; for (int j=0; jdata8[j]; diff --git a/src/engine/platform/rf5c68.h b/src/engine/platform/rf5c68.h index bcbb3da2e..840ece46a 100644 --- a/src/engine/platform/rf5c68.h +++ b/src/engine/platform/rf5c68.h @@ -66,6 +66,7 @@ class DivPlatformRF5C68: public DivDispatch { bool isMuted[8]; int chipType; unsigned char curChan; + unsigned int sampleOffRFC[256]; unsigned char* sampleMem; size_t sampleMemLen; diff --git a/src/engine/platform/segapcm.cpp b/src/engine/platform/segapcm.cpp index 650f54c91..5cd4a8e8d 100644 --- a/src/engine/platform/segapcm.cpp +++ b/src/engine/platform/segapcm.cpp @@ -159,17 +159,17 @@ void DivPlatformSegaPCM::tick(bool sysTick) { int loopStart=s->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT); int actualLength=(s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)); if (actualLength>0xfeff) actualLength=0xfeff; - addWrite(0x10086+(i<<3),3+((s->offSegaPCM>>16)<<3)); - addWrite(0x10084+(i<<3),(s->offSegaPCM)&0xff); - addWrite(0x10085+(i<<3),(s->offSegaPCM>>8)&0xff); - addWrite(0x10006+(i<<3),MIN(255,((s->offSegaPCM&0xffff)+actualLength-1)>>8)); + addWrite(0x10086+(i<<3),3+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3)); + addWrite(0x10084+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample])&0xff); + addWrite(0x10085+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample]>>8)&0xff); + addWrite(0x10006+(i<<3),MIN(255,((sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+actualLength-1)>>8)); if (loopStart<0 || loopStart>=actualLength) { - addWrite(0x10086+(i<<3),2+((s->offSegaPCM>>16)<<3)); + addWrite(0x10086+(i<<3),2+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3)); } else { - int loopPos=(s->offSegaPCM&0xffff)+loopStart+s->loopOffP; + int loopPos=(sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+loopStart+s->loopOffP; addWrite(0x10004+(i<<3),loopPos&0xff); addWrite(0x10005+(i<<3),(loopPos>>8)&0xff); - addWrite(0x10086+(i<<3),((s->offSegaPCM>>16)<<3)); + addWrite(0x10086+(i<<3),((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3)); } } } else { @@ -178,17 +178,17 @@ void DivPlatformSegaPCM::tick(bool sysTick) { int loopStart=s->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT); int actualLength=(s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)); if (actualLength>65536) actualLength=65536; - addWrite(0x10086+(i<<3),3+((s->offSegaPCM>>16)<<3)); - addWrite(0x10084+(i<<3),(s->offSegaPCM)&0xff); - addWrite(0x10085+(i<<3),(s->offSegaPCM>>8)&0xff); - addWrite(0x10006+(i<<3),MIN(255,((s->offSegaPCM&0xffff)+actualLength-1)>>8)); + addWrite(0x10086+(i<<3),3+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3)); + addWrite(0x10084+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample])&0xff); + addWrite(0x10085+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample]>>8)&0xff); + addWrite(0x10006+(i<<3),MIN(255,((sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+actualLength-1)>>8)); if (loopStart<0 || loopStart>=actualLength) { - addWrite(0x10086+(i<<3),2+((s->offSegaPCM>>16)<<3)); + addWrite(0x10086+(i<<3),2+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3)); } else { - int loopPos=(s->offSegaPCM&0xffff)+loopStart+s->loopOffP; + int loopPos=(sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+loopStart+s->loopOffP; addWrite(0x10004+(i<<3),loopPos&0xff); addWrite(0x10005+(i<<3),(loopPos>>8)&0xff); - addWrite(0x10086+(i<<3),((s->offSegaPCM>>16)<<3)); + addWrite(0x10086+(i<<3),((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3)); } addWrite(0x10007+(i<<3),chan[i].pcm.freq); } @@ -451,6 +451,10 @@ void DivPlatformSegaPCM::reset() { } } + void DivPlatformSegaPCM::renderSamples() { + // TODO: THIS MESS + } + void DivPlatformSegaPCM::setFlags(unsigned int flags) { chipClock=8000000.0; rate=31250; diff --git a/src/engine/platform/segapcm.h b/src/engine/platform/segapcm.h index 888a33848..2a76143b4 100644 --- a/src/engine/platform/segapcm.h +++ b/src/engine/platform/segapcm.h @@ -91,6 +91,8 @@ class DivPlatformSegaPCM: public DivDispatch { short oldWrites[256]; short pendingWrites[256]; + + unsigned int sampleOffSegaPCM[256]; friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); @@ -108,6 +110,7 @@ class DivPlatformSegaPCM: public DivDispatch { void tick(bool sysTick=true); void muteChannel(int ch, bool mute); void notifyInsChange(int ins); + void renderSamples(); void setFlags(unsigned int flags); bool isStereo(); void poke(unsigned int addr, unsigned short val); diff --git a/src/engine/platform/snes.cpp b/src/engine/platform/snes.cpp index 7e0996d98..3686980f2 100644 --- a/src/engine/platform/snes.cpp +++ b/src/engine/platform/snes.cpp @@ -178,6 +178,7 @@ void DivPlatformSNES::tick(bool sysTick) { updateWave(i); } } + // TODO: THIS WILL CRASH IF THE SAMPLE IS INVALID!!! if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { DivSample* s=parent->getSample(chan[i].sample); double off=(s->centerRate>=1)?((double)s->centerRate/8363.0):1.0; @@ -191,7 +192,7 @@ void DivPlatformSNES::tick(bool sysTick) { start=waveTableAddr(i); loop=start; } else { - start=s->offSNES; + start=sampleOff[chan[i].sample]; end=MIN(start+MAX(s->lengthBRR,1),getSampleMemCapacity()); loop=MAX(start,end-1); if (chan[i].audPos>0) { @@ -567,6 +568,7 @@ size_t DivPlatformSNES::getSampleMemUsage(int index) { void DivPlatformSNES::renderSamples() { memset(sampleMem,0,getSampleMemCapacity()); + memset(sampleOff,0,256*sizeof(unsigned int)); // skip past sample table and wavetable buffer size_t memPos=sampleTableBase+8*4+8*9*16; @@ -575,7 +577,7 @@ void DivPlatformSNES::renderSamples() { int length=s->lengthBRR; int actualLength=MIN((int)(getSampleMemCapacity()-memPos)/9*9,length); if (actualLength>0) { - s->offSNES=memPos; + sampleOff[i]=memPos; memcpy(&sampleMem[memPos],s->dataBRR,actualLength); memPos+=actualLength; } diff --git a/src/engine/platform/snes.h b/src/engine/platform/snes.h index 7ac5d5243..ad8048f3c 100644 --- a/src/engine/platform/snes.h +++ b/src/engine/platform/snes.h @@ -92,6 +92,7 @@ class DivPlatformSNES: public DivDispatch { signed char sampleMem[65536]; size_t sampleMemLen; + unsigned int sampleOff[256]; unsigned char regPool[0x80]; SPC_DSP dsp; friend void putDispatchChan(void*,int,int); diff --git a/src/engine/platform/su.cpp b/src/engine/platform/su.cpp index e36b424f4..25fefa200 100644 --- a/src/engine/platform/su.cpp +++ b/src/engine/platform/su.cpp @@ -161,10 +161,11 @@ void DivPlatformSoundUnit::tick(bool sysTick) { if (chan[i].keyOn) { if (chan[i].pcm) { DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_SU); - DivSample* sample=parent->getSample(ins->amiga.getSample(chan[i].note)); + int sNum=ins->amiga.getSample(chan[i].note); + DivSample* sample=parent->getSample(sNum); if (sample!=NULL) { - unsigned int sampleEnd=sample->offSU+(sample->getLoopEndPosition()); - unsigned int off=sample->offSU+chan[i].hasOffset; + unsigned int sampleEnd=sampleOffSU[sNum]+(sample->getLoopEndPosition()); + unsigned int off=sampleOffSU[sNum]+chan[i].hasOffset; chan[i].hasOffset=0; if (sampleEnd>=getSampleMemCapacity(0)) sampleEnd=getSampleMemCapacity(0)-1; chWrite(i,0x0a,off&0xff); @@ -172,7 +173,7 @@ void DivPlatformSoundUnit::tick(bool sysTick) { chWrite(i,0x0c,sampleEnd&0xff); chWrite(i,0x0d,sampleEnd>>8); if (sample->isLoopable()) { - unsigned int sampleLoop=sample->offSU+sample->getLoopStartPosition(); + unsigned int sampleLoop=sampleOffSU[sNum]+sample->getLoopStartPosition(); if (sampleLoop>=getSampleMemCapacity(0)) sampleLoop=getSampleMemCapacity(0)-1; chWrite(i,0x0e,sampleLoop&0xff); chWrite(i,0x0f,sampleLoop>>8); @@ -547,6 +548,7 @@ size_t DivPlatformSoundUnit::getSampleMemUsage(int index) { void DivPlatformSoundUnit::renderSamples() { memset(su->pcm,0,getSampleMemCapacity(0)); + memset(sampleOffSU,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -563,7 +565,7 @@ void DivPlatformSoundUnit::renderSamples() { } else { memcpy(su->pcm+memPos,s->data8,paddedLen); } - s->offSU=memPos; + sampleOffSU[i]=memPos; memPos+=paddedLen; } sampleMemLen=memPos; diff --git a/src/engine/platform/su.h b/src/engine/platform/su.h index d94df8eac..784186c66 100644 --- a/src/engine/platform/su.h +++ b/src/engine/platform/su.h @@ -101,6 +101,7 @@ class DivPlatformSoundUnit: public DivDispatch { unsigned char ilCtrl, ilSize, fil1; unsigned char initIlCtrl, initIlSize, initFil1; signed char echoVol, initEchoVol; + unsigned int sampleOffSU[256]; int cycles, curChan, delay; short tempL; diff --git a/src/engine/platform/x1_010.cpp b/src/engine/platform/x1_010.cpp index 1c04267bd..5f71b8fd8 100644 --- a/src/engine/platform/x1_010.cpp +++ b/src/engine/platform/x1_010.cpp @@ -541,14 +541,14 @@ int DivPlatformX1_010::dispatch(DivCommand c) { DivSample* s=parent->getSample(chan[c.chan].sample); if (isBanked) { chan[c.chan].bankSlot=ins->x1_010.bankSlot; - bankSlot[chan[c.chan].bankSlot]=s->offX1_010>>17; - unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(s->offX1_010&0x1ffff); + bankSlot[chan[c.chan].bankSlot]=sampleOffX1[chan[c.chan].sample]>>17; + unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(sampleOffX1[chan[c.chan].sample]&0x1ffff); chWrite(c.chan,4,(bankedOffs>>12)&0xff); int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded chWrite(c.chan,5,(0x100-(end>>12))&0xff); } else { - chWrite(c.chan,4,(s->offX1_010>>12)&0xff); - int end=(s->offX1_010+s->length8+0xfff)&~0xfff; // padded + chWrite(c.chan,4,(sampleOffX1[chan[c.chan].sample]>>12)&0xff); + int end=(sampleOffX1[chan[c.chan].sample]+s->length8+0xfff)&~0xfff; // padded chWrite(c.chan,5,(0x100-(end>>12))&0xff); } if (c.value!=DIV_NOTE_NULL) { @@ -581,14 +581,14 @@ int DivPlatformX1_010::dispatch(DivCommand c) { } DivSample* s=parent->getSample(12*sampleBank+c.value%12); if (isBanked) { - bankSlot[chan[c.chan].bankSlot]=s->offX1_010>>17; - unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(s->offX1_010&0x1ffff); + bankSlot[chan[c.chan].bankSlot]=sampleOffX1[chan[c.chan].sample]>>17; + unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(sampleOffX1[chan[c.chan].sample]&0x1ffff); chWrite(c.chan,4,(bankedOffs>>12)&0xff); int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded chWrite(c.chan,5,(0x100-(end>>12))&0xff); } else { - chWrite(c.chan,4,(s->offX1_010>>12)&0xff); - int end=(s->offX1_010+s->length8+0xfff)&~0xfff; // padded + chWrite(c.chan,4,(sampleOffX1[chan[c.chan].sample]>>12)&0xff); + int end=(sampleOffX1[chan[c.chan].sample]+s->length8+0xfff)&~0xfff; // padded chWrite(c.chan,5,(0x100-(end>>12))&0xff); } chan[c.chan].baseFreq=(((unsigned int)s->rate)<<4)/(chipClock/512); @@ -945,6 +945,7 @@ size_t DivPlatformX1_010::getSampleMemUsage(int index) { void DivPlatformX1_010::renderSamples() { memset(sampleMem,0,getSampleMemCapacity()); + memset(sampleOffX1,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -969,7 +970,7 @@ void DivPlatformX1_010::renderSamples() { } else { memcpy(sampleMem+memPos,s->data8,paddedLen); } - s->offX1_010=memPos; + sampleOffX1[i]=memPos; memPos+=paddedLen; } sampleMemLen=memPos+256; diff --git a/src/engine/platform/x1_010.h b/src/engine/platform/x1_010.h index 19fb91350..ce3e86c18 100644 --- a/src/engine/platform/x1_010.h +++ b/src/engine/platform/x1_010.h @@ -115,6 +115,7 @@ class DivPlatformX1_010: public DivDispatch, public vgsound_emu_mem_intf { bool isBanked=false; unsigned int bankSlot[8]; + unsigned int sampleOffX1[256]; unsigned char regPool[0x2000]; double NoteX1_010(int ch, int note); diff --git a/src/engine/platform/ym2608.cpp b/src/engine/platform/ym2608.cpp index 82a130ac0..b247be449 100644 --- a/src/engine/platform/ym2608.cpp +++ b/src/engine/platform/ym2608.cpp @@ -684,9 +684,9 @@ int DivPlatformYM2608::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.getSample(c.value); if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); - immWrite(0x102,(s->offB>>5)&0xff); - immWrite(0x103,(s->offB>>13)&0xff); - int end=s->offB+s->lengthB-1; + immWrite(0x102,(sampleOffB[chan[c.chan].sample]>>5)&0xff); + immWrite(0x103,(sampleOffB[chan[c.chan].sample]>>13)&0xff); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(0x104,(end>>5)&0xff); immWrite(0x105,(end>>13)&0xff); immWrite(0x101,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|2); @@ -715,9 +715,9 @@ int DivPlatformYM2608::dispatch(DivCommand c) { chan[c.chan].sample=12*sampleBank+c.value%12; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); - immWrite(0x102,(s->offB>>5)&0xff); - immWrite(0x103,(s->offB>>13)&0xff); - int end=s->offB+s->lengthB-1; + immWrite(0x102,(sampleOffB[chan[c.chan].sample]>>5)&0xff); + immWrite(0x103,(sampleOffB[chan[c.chan].sample]>>13)&0xff); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(0x104,(end>>5)&0xff); immWrite(0x105,(end>>13)&0xff); immWrite(0x101,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|2); @@ -1334,6 +1334,7 @@ size_t DivPlatformYM2608::getSampleMemUsage(int index) { void DivPlatformYM2608::renderSamples() { memset(adpcmBMem,0,getSampleMemCapacity(0)); + memset(sampleOffB,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -1352,7 +1353,7 @@ void DivPlatformYM2608::renderSamples() { } else { memcpy(adpcmBMem+memPos,s->dataB,paddedLen); } - s->offB=memPos; + sampleOffB[i]=memPos; memPos+=paddedLen; } adpcmBMemLen=memPos+256; diff --git a/src/engine/platform/ym2608.h b/src/engine/platform/ym2608.h index 073e381d8..a1b523208 100644 --- a/src/engine/platform/ym2608.h +++ b/src/engine/platform/ym2608.h @@ -99,6 +99,7 @@ class DivPlatformYM2608: public DivPlatformOPN { unsigned char* adpcmBMem; size_t adpcmBMemLen; DivYM2608Interface iface; + unsigned int sampleOffB[256]; DivPlatformAY8910* ay; unsigned char sampleBank; diff --git a/src/engine/platform/ym2610.cpp b/src/engine/platform/ym2610.cpp index 9e8f1847c..794fc7d95 100644 --- a/src/engine/platform/ym2610.cpp +++ b/src/engine/platform/ym2610.cpp @@ -623,9 +623,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.getSample(c.value); if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); - immWrite(0x12,(s->offB>>8)&0xff); - immWrite(0x13,s->offB>>16); - int end=s->offB+s->lengthB-1; + immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff); + immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(0x14,(end>>8)&0xff); immWrite(0x15,end>>16); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); @@ -654,9 +654,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) { chan[c.chan].sample=12*sampleBank+c.value%12; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(12*sampleBank+c.value%12); - immWrite(0x12,(s->offB>>8)&0xff); - immWrite(0x13,s->offB>>16); - int end=s->offB+s->lengthB-1; + immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff); + immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(0x14,(end>>8)&0xff); immWrite(0x15,end>>16); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); @@ -694,9 +694,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.getSample(c.value); if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); - immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); - immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); - int end=s->offA+s->lengthA-1; + immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff); + immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16); + int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1; immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); @@ -725,9 +725,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) { chan[c.chan].sample=12*sampleBank+c.value%12; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(12*sampleBank+c.value%12); - immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); - immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); - int end=s->offA+s->lengthA-1; + immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff); + immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16); + int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1; immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); diff --git a/src/engine/platform/ym2610b.cpp b/src/engine/platform/ym2610b.cpp index bf854f36f..941cee22e 100644 --- a/src/engine/platform/ym2610b.cpp +++ b/src/engine/platform/ym2610b.cpp @@ -686,9 +686,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.getSample(c.value); if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); - immWrite(0x12,(s->offB>>8)&0xff); - immWrite(0x13,s->offB>>16); - int end=s->offB+s->lengthB-1; + immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff); + immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(0x14,(end>>8)&0xff); immWrite(0x15,end>>16); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); @@ -717,9 +717,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) { chan[c.chan].sample=12*sampleBank+c.value%12; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(12*sampleBank+c.value%12); - immWrite(0x12,(s->offB>>8)&0xff); - immWrite(0x13,s->offB>>16); - int end=s->offB+s->lengthB-1; + immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff); + immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16); + int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1; immWrite(0x14,(end>>8)&0xff); immWrite(0x15,end>>16); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); @@ -757,9 +757,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) { chan[c.chan].sample=ins->amiga.getSample(c.value); if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(chan[c.chan].sample); - immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); - immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); - int end=s->offA+s->lengthA-1; + immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff); + immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16); + int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1; immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); @@ -788,9 +788,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) { chan[c.chan].sample=12*sampleBank+c.value%12; if (chan[c.chan].sample>=0 && chan[c.chan].samplesong.sampleLen) { DivSample* s=parent->getSample(12*sampleBank+c.value%12); - immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); - immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); - int end=s->offA+s->lengthA-1; + immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff); + immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16); + int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1; immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); diff --git a/src/engine/platform/ym2610shared.h b/src/engine/platform/ym2610shared.h index e8bbd16f9..920cf499b 100644 --- a/src/engine/platform/ym2610shared.h +++ b/src/engine/platform/ym2610shared.h @@ -136,6 +136,9 @@ template class DivPlatformYM2610Base: public DivPlatformOPN { size_t adpcmBMemLen; DivYM2610Interface iface; + unsigned int sampleOffA[256]; + unsigned int sampleOffB[256]; + unsigned char sampleBank; bool extMode; @@ -207,6 +210,8 @@ template class DivPlatformYM2610Base: public DivPlatformOPN { void renderSamples() { memset(adpcmAMem,0,getSampleMemCapacity(0)); + memset(sampleOffA,0,256*sizeof(unsigned int)); + memset(sampleOffB,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -225,7 +230,7 @@ template class DivPlatformYM2610Base: public DivPlatformOPN { } else { memcpy(adpcmAMem+memPos,s->dataA,paddedLen); } - s->offA=memPos; + sampleOffA[i]=memPos; memPos+=paddedLen; } adpcmAMemLen=memPos+256; @@ -249,7 +254,7 @@ template class DivPlatformYM2610Base: public DivPlatformOPN { } else { memcpy(adpcmBMem+memPos,s->dataB,paddedLen); } - s->offB=memPos; + sampleOffB[i]=memPos; memPos+=paddedLen; } adpcmBMemLen=memPos+256; diff --git a/src/engine/platform/ymz280b.cpp b/src/engine/platform/ymz280b.cpp index 143124b5d..2e617c761 100644 --- a/src/engine/platform/ymz280b.cpp +++ b/src/engine/platform/ymz280b.cpp @@ -145,8 +145,9 @@ void DivPlatformYMZ280B::tick(bool sysTick) { // ADPCM has half the range if (s->depth==DIV_SAMPLE_DEPTH_YMZ_ADPCM && chan[i].freq>255) chan[i].freq=255; ctrl|=(chan[i].active?0x80:0)|((s->isLoopable())?0x10:0)|(chan[i].freq>>8); + // TODO: AGAIN THIS WILL CRASH IF THE SAMPLE IS INVALID!!! if (chan[i].keyOn) { - unsigned int start=s->offYMZ280B; + unsigned int start=sampleOff[chan[i].sample]; unsigned int loopStart=0; unsigned int loopEnd=0; unsigned int end=MIN(start+s->getCurBufLen(),getSampleMemCapacity()-1); @@ -418,6 +419,7 @@ size_t DivPlatformYMZ280B::getSampleMemUsage(int index) { void DivPlatformYMZ280B::renderSamples() { memset(sampleMem,0,getSampleMemCapacity()); + memset(sampleOff,0,256*sizeof(unsigned int)); size_t memPos=0; for (int i=0; isong.sampleLen; i++) { @@ -427,7 +429,7 @@ void DivPlatformYMZ280B::renderSamples() { int actualLength=MIN((int)(getSampleMemCapacity()-memPos),length); if (actualLength>0) { memcpy(&sampleMem[memPos],src,actualLength); - s->offYMZ280B=memPos; + sampleOff[i]=memPos; memPos+=length; } if (actualLengthinit(); @@ -1501,12 +1504,16 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p unsigned int songOff=w->tell(); + // initialize sample offsets + memset(sampleOff8,0,256*sizeof(unsigned int)); + memset(sampleOffSegaPCM,0,256*sizeof(unsigned int)); + // write samples unsigned int sampleSeek=0; for (int i=0; ioff8=sampleSeek; + sampleOff8[i]=sampleSeek; sampleSeek+=sample->length8; } @@ -1556,7 +1563,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p } logV("- sample %d will be at %x with length %x",i,memPos,alignedSize); if (memPos>=16777216) break; - sample->offSegaPCM=memPos; + sampleOffSegaPCM[i]=memPos; unsigned int readPos=0; for (unsigned int j=0; j=(unsigned int)sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)) { @@ -1661,6 +1668,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p size_t sampleMemLen=writeZ280[i]->getSampleMemUsage(); unsigned char* sampleMem=new unsigned char[sampleMemLen]; memcpy(sampleMem,writeZ280[i]->getSampleMem(),sampleMemLen); + // TODO: please fix this later + /* for (int i=0; idepth==DIV_SAMPLE_DEPTH_16BIT) { @@ -1673,6 +1682,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p } } } + */ w->writeC(0x67); w->writeC(0x66); w->writeC(0x86); @@ -1900,7 +1910,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p if (sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)) { w->writeC(0x93); w->writeC(nextToTouch); - w->writeI(sample->off8+sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)); + w->writeI(sampleOff8[loopSample[nextToTouch]]+sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)); w->writeC(0x81); w->writeI(sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)-sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)); } diff --git a/src/gui/debugWindow.cpp b/src/gui/debugWindow.cpp index d3ecbc98e..2c507bb47 100644 --- a/src/gui/debugWindow.cpp +++ b/src/gui/debugWindow.cpp @@ -191,23 +191,6 @@ void FurnaceGUI::drawDebug() { ImGui::Text("lengthBRR: %d",sample->lengthBRR); ImGui::Text("lengthVOX: %d",sample->lengthVOX); - ImGui::Text("off8: %x",sample->off8); - ImGui::Text("off16: %x",sample->off16); - ImGui::Text("off1: %x",sample->off1); - ImGui::Text("offDPCM: %x",sample->offDPCM); - ImGui::Text("offZ: %x",sample->offZ); - ImGui::Text("offQSoundA: %x",sample->offQSoundA); - ImGui::Text("offA: %x",sample->offA); - ImGui::Text("offB: %x",sample->offB); - ImGui::Text("offBRR: %x",sample->offBRR); - ImGui::Text("offVOX: %x",sample->offVOX); - ImGui::Text("offSegaPCM: %x",sample->offSegaPCM); - ImGui::Text("offQSound: %x",sample->offQSound); - ImGui::Text("offX1_010: %x",sample->offX1_010); - ImGui::Text("offSU: %x",sample->offSU); - ImGui::Text("offYMZ280B: %x",sample->offYMZ280B); - ImGui::Text("offRF5C68: %x",sample->offRF5C68); - ImGui::Text("samples: %d",sample->samples); ImGui::TreePop(); }