VGM export: prepare for NES DPCM

This commit is contained in:
tildearrow 2023-06-22 04:55:12 -05:00
parent ef57ad531d
commit 0bcd1b74ac
2 changed files with 24 additions and 7 deletions

View File

@ -346,7 +346,11 @@ void DivPlatformNES::tick(bool sysTick) {
rWrite(0x4012,(dpcmAddr>>6)&0xff); rWrite(0x4012,(dpcmAddr>>6)&0xff);
rWrite(0x4013,dpcmLen&0xff); rWrite(0x4013,dpcmLen&0xff);
rWrite(0x4015,31); rWrite(0x4015,31);
dpcmBank=dpcmAddr>>14; if (dpcmBank!=(dpcmAddr>>14)) {
dpcmBank=dpcmAddr>>14;
logV("switching bank to %d",dpcmBank);
if (dumpWrites) addWrite(0xffff0004,dpcmBank);
}
} }
} else { } else {
if (nextDPCMFreq>=0) { if (nextDPCMFreq>=0) {
@ -425,7 +429,11 @@ int DivPlatformNES::dispatch(DivCommand c) {
rWrite(0x4012,(dpcmAddr>>6)&0xff); rWrite(0x4012,(dpcmAddr>>6)&0xff);
rWrite(0x4013,dpcmLen&0xff); rWrite(0x4013,dpcmLen&0xff);
rWrite(0x4015,31); rWrite(0x4015,31);
dpcmBank=dpcmAddr>>14; if (dpcmBank!=(dpcmAddr>>14)) {
dpcmBank=dpcmAddr>>14;
logV("switching bank to %d",dpcmBank);
if (dumpWrites) addWrite(0xffff0004,dpcmBank);
}
} }
} }
break; break;
@ -854,6 +862,7 @@ int DivPlatformNES::init(DivEngine* p, int channels, int sugRate, const DivConfi
dpcmMem=new unsigned char[262144]; dpcmMem=new unsigned char[262144];
dpcmMemLen=0; dpcmMemLen=0;
dpcmBank=0; dpcmBank=0;
if (dumpWrites) addWrite(0xffff0004,dpcmBank);
init_nla_table(500,500); init_nla_table(500,500);
reset(); reset();

View File

@ -1054,6 +1054,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
bool willExport[DIV_MAX_CHIPS]; bool willExport[DIV_MAX_CHIPS];
bool isSecond[DIV_MAX_CHIPS]; bool isSecond[DIV_MAX_CHIPS];
int streamIDs[DIV_MAX_CHIPS]; int streamIDs[DIV_MAX_CHIPS];
double loopTimer[DIV_MAX_CHANS]; double loopTimer[DIV_MAX_CHANS];
double loopFreq[DIV_MAX_CHANS]; double loopFreq[DIV_MAX_CHANS];
int loopSample[DIV_MAX_CHANS]; int loopSample[DIV_MAX_CHANS];
@ -1096,6 +1097,9 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
DivDispatch* writeGA20[2]={NULL,NULL}; DivDispatch* writeGA20[2]={NULL,NULL};
DivDispatch* writeNES[2]={NULL,NULL}; DivDispatch* writeNES[2]={NULL,NULL};
size_t bankOffsetNESCurrent=0;
size_t bankOffsetNES[2]={0,0};
for (int i=0; i<song.systemLen; i++) { for (int i=0; i<song.systemLen; i++) {
willExport[i]=false; willExport[i]=false;
isSecond[i]=false; isSecond[i]=false;
@ -1837,6 +1841,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
for (unsigned int j=0; j<sample->length8; j++) { for (unsigned int j=0; j<sample->length8; j++) {
w->writeC(((unsigned char)sample->data8[j]+0x80)>>1); w->writeC(((unsigned char)sample->data8[j]+0x80)>>1);
} }
bankOffsetNESCurrent+=sample->length8;
} }
if (writePCESamples && !directStream) for (int i=0; i<song.sampleLen; i++) { if (writePCESamples && !directStream) for (int i=0; i<song.sampleLen; i++) {
@ -1973,13 +1978,14 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
} }
// TODO // TODO
if (writeNES[i]!=NULL && writeNES[i]->getSampleMemUsage()>0) { if (writeNES[i]!=NULL && writeNES[i]->getSampleMemUsage()>0) {
size_t howMuchWillBeWritten=writeNES[i]->getSampleMemUsage();
w->writeC(0x67); w->writeC(0x67);
w->writeC(0x66); w->writeC(0x66);
w->writeC(0x07); w->writeC(7);
w->writeI((writeNES[i]->getSampleMemUsage()+8)|(i*0x80000000)); w->writeI(howMuchWillBeWritten);
w->writeI(writeNES[i]->getSampleMemCapacity()); w->write(writeNES[i]->getSampleMem(),howMuchWillBeWritten);
w->writeI(0); bankOffsetNES[i]=bankOffsetNESCurrent;
w->write(writeNES[i]->getSampleMem(),writeNES[i]->getSampleMemUsage()); bankOffsetNESCurrent+=howMuchWillBeWritten;
} }
} }
@ -2231,6 +2237,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
} }
// write write // write write
performVGMWrite(w,song.system[i.first],i.second.write,streamIDs[i.first],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i.first],pendingFreq,playingSample,directStream); performVGMWrite(w,song.system[i.first],i.second.write,streamIDs[i.first],loopTimer,loopFreq,loopSample,sampleDir,isSecond[i.first],pendingFreq,playingSample,directStream);
// handle global Furnace commands
writeCount++; writeCount++;
} }
sortedWrites.clear(); sortedWrites.clear();