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(0x4013,dpcmLen&0xff);
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 {
if (nextDPCMFreq>=0) {
@ -425,7 +429,11 @@ int DivPlatformNES::dispatch(DivCommand c) {
rWrite(0x4012,(dpcmAddr>>6)&0xff);
rWrite(0x4013,dpcmLen&0xff);
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;
@ -854,6 +862,7 @@ int DivPlatformNES::init(DivEngine* p, int channels, int sugRate, const DivConfi
dpcmMem=new unsigned char[262144];
dpcmMemLen=0;
dpcmBank=0;
if (dumpWrites) addWrite(0xffff0004,dpcmBank);
init_nla_table(500,500);
reset();

View file

@ -1054,6 +1054,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
bool willExport[DIV_MAX_CHIPS];
bool isSecond[DIV_MAX_CHIPS];
int streamIDs[DIV_MAX_CHIPS];
double loopTimer[DIV_MAX_CHANS];
double loopFreq[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* writeNES[2]={NULL,NULL};
size_t bankOffsetNESCurrent=0;
size_t bankOffsetNES[2]={0,0};
for (int i=0; i<song.systemLen; i++) {
willExport[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++) {
w->writeC(((unsigned char)sample->data8[j]+0x80)>>1);
}
bankOffsetNESCurrent+=sample->length8;
}
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
if (writeNES[i]!=NULL && writeNES[i]->getSampleMemUsage()>0) {
size_t howMuchWillBeWritten=writeNES[i]->getSampleMemUsage();
w->writeC(0x67);
w->writeC(0x66);
w->writeC(0x07);
w->writeI((writeNES[i]->getSampleMemUsage()+8)|(i*0x80000000));
w->writeI(writeNES[i]->getSampleMemCapacity());
w->writeI(0);
w->write(writeNES[i]->getSampleMem(),writeNES[i]->getSampleMemUsage());
w->writeC(7);
w->writeI(howMuchWillBeWritten);
w->write(writeNES[i]->getSampleMem(),howMuchWillBeWritten);
bankOffsetNES[i]=bankOffsetNESCurrent;
bankOffsetNESCurrent+=howMuchWillBeWritten;
}
}
@ -2231,6 +2237,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
}
// write write
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++;
}
sortedWrites.clear();