Merge pull request #370 from AYCEdemo/vgmfix

VGM: Support ROM data in the second chip
This commit is contained in:
tildearrow 2022-04-17 01:19:21 -05:00 committed by GitHub
commit 496031a41f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 48 deletions

View File

@ -713,10 +713,10 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
bool writeDACSamples=false; bool writeDACSamples=false;
bool writeNESSamples=false; bool writeNESSamples=false;
bool writePCESamples=false; bool writePCESamples=false;
bool writeADPCM=false; int writeADPCM=0;
bool writeSegaPCM=false; int writeSegaPCM=0;
bool writeX1010=false; int writeX1010=0;
bool writeQSound=false; int writeQSound=0;
for (int i=0; i<song.systemLen; i++) { for (int i=0; i<song.systemLen; i++) {
willExport[i]=false; willExport[i]=false;
@ -792,10 +792,11 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
if (!hasSegaPCM) { if (!hasSegaPCM) {
hasSegaPCM=4000000; hasSegaPCM=4000000;
willExport[i]=true; willExport[i]=true;
writeSegaPCM=true; writeSegaPCM=1;
} else if (!(hasSegaPCM&0x40000000)) { } else if (!(hasSegaPCM&0x40000000)) {
isSecond[i]=true; isSecond[i]=true;
willExport[i]=true; willExport[i]=true;
writeSegaPCM=2;
hasSegaPCM|=0x40000000; hasSegaPCM|=0x40000000;
howManyChips++; howManyChips++;
} }
@ -804,10 +805,11 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
if (!hasX1) { if (!hasX1) {
hasX1=disCont[i].dispatch->chipClock; hasX1=disCont[i].dispatch->chipClock;
willExport[i]=true; willExport[i]=true;
writeX1010=true; writeX1010=1;
} else if (!(hasX1&0x40000000)) { } else if (!(hasX1&0x40000000)) {
isSecond[i]=true; isSecond[i]=true;
willExport[i]=true; willExport[i]=true;
writeX1010=2;
hasX1|=0x40000000; hasX1|=0x40000000;
howManyChips++; howManyChips++;
} }
@ -821,10 +823,11 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
if (!hasOPNB) { if (!hasOPNB) {
hasOPNB=disCont[i].dispatch->chipClock; hasOPNB=disCont[i].dispatch->chipClock;
willExport[i]=true; willExport[i]=true;
writeADPCM=true; writeADPCM=1;
} else if (!(hasOPNB&0x40000000)) { } else if (!(hasOPNB&0x40000000)) {
isSecond[i]=true; isSecond[i]=true;
willExport[i]=true; willExport[i]=true;
writeADPCM=2;
hasOPNB|=0x40000000; hasOPNB|=0x40000000;
howManyChips++; howManyChips++;
} }
@ -926,10 +929,11 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
// not be able to handle the 64kb sample bank trick // not be able to handle the 64kb sample bank trick
hasQSound=disCont[i].dispatch->chipClock; hasQSound=disCont[i].dispatch->chipClock;
willExport[i]=true; willExport[i]=true;
writeQSound=true; writeQSound=1;
} else if (!(hasQSound&0x40000000)) { } else if (!(hasQSound&0x40000000)) {
isSecond[i]=true; isSecond[i]=true;
willExport[i]=false; willExport[i]=false;
writeQSound=2;
addWarning("dual QSound is not supported by the VGM format"); addWarning("dual QSound is not supported by the VGM format");
} }
break; break;
@ -1200,7 +1204,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
} }
} }
if (writeSegaPCM) { if (writeSegaPCM>0) {
unsigned char* pcmMem=new unsigned char[16777216]; unsigned char* pcmMem=new unsigned char[16777216];
size_t memPos=0; size_t memPos=0;
@ -1232,60 +1236,70 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version) {
if (memPos>=16777216) break; if (memPos>=16777216) break;
} }
w->writeC(0x67); for (int i=0; i<writeSegaPCM; i++) {
w->writeC(0x66); w->writeC(0x67);
w->writeC(0x80); w->writeC(0x66);
w->writeI(memPos+8); w->writeC(0x80);
w->writeI(memPos); w->writeI((memPos+8)|(i*0x80000000));
w->writeI(0); w->writeI(memPos);
w->write(pcmMem,memPos); w->writeI(0);
w->write(pcmMem,memPos);
}
delete[] pcmMem; delete[] pcmMem;
} }
if (writeADPCM && adpcmAMemLen>0) { if (adpcmAMemLen>0) {
w->writeC(0x67); for (int i=0; i<writeADPCM; i++) {
w->writeC(0x66); w->writeC(0x67);
w->writeC(0x82); w->writeC(0x66);
w->writeI(adpcmAMemLen+8); w->writeC(0x82);
w->writeI(adpcmAMemLen); w->writeI((adpcmAMemLen+8)|(i*0x80000000));
w->writeI(0); w->writeI(adpcmAMemLen);
w->write(adpcmAMem,adpcmAMemLen); w->writeI(0);
w->write(adpcmAMem,adpcmAMemLen);
}
} }
if (writeADPCM && adpcmBMemLen>0) { if (adpcmBMemLen>0) {
w->writeC(0x67); for (int i=0; i<writeADPCM; i++) {
w->writeC(0x66); w->writeC(0x67);
w->writeC(0x83); w->writeC(0x66);
w->writeI(adpcmBMemLen+8); w->writeC(0x83);
w->writeI(adpcmBMemLen); w->writeI((adpcmBMemLen+8)|(i*0x80000000));
w->writeI(0); w->writeI(adpcmBMemLen);
w->write(adpcmBMem,adpcmBMemLen); w->writeI(0);
w->write(adpcmBMem,adpcmBMemLen);
}
} }
if (writeQSound && qsoundMemLen>0) { if (qsoundMemLen>0) {
// always write a whole bank // always write a whole bank
unsigned int blockSize=(qsoundMemLen+0xffff)&(~0xffff); unsigned int blockSize=(qsoundMemLen+0xffff)&(~0xffff);
if (blockSize > 0x1000000) { if (blockSize > 0x1000000) {
blockSize = 0x1000000; blockSize = 0x1000000;
} }
w->writeC(0x67); for (int i=0; i<writeQSound; i++) {
w->writeC(0x66); w->writeC(0x67);
w->writeC(0x8F); w->writeC(0x66);
w->writeI(blockSize+8); w->writeC(0x8F);
w->writeI(0x1000000); w->writeI((blockSize+8)|(i*0x80000000));
w->writeI(0); w->writeI(0x1000000);
w->write(qsoundMem,blockSize); w->writeI(0);
w->write(qsoundMem,blockSize);
}
} }
if (writeX1010 && x1_010MemLen>0) { if (x1_010MemLen>0) {
w->writeC(0x67); for (int i=0; i<writeX1010; i++) {
w->writeC(0x66); w->writeC(0x67);
w->writeC(0x91); w->writeC(0x66);
w->writeI(x1_010MemLen+8); w->writeC(0x91);
w->writeI(x1_010MemLen); w->writeI((x1_010MemLen+8)|(i*0x80000000));
w->writeI(0); w->writeI(x1_010MemLen);
w->write(x1_010Mem,x1_010MemLen); w->writeI(0);
w->write(x1_010Mem,x1_010MemLen);
}
} }
// initialize streams // initialize streams