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

View file

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