Implement QSound support

This commit is contained in:
Ian Karlsson 2022-02-22 10:01:57 +01:00
parent 721445cf07
commit b3908216f8
17 changed files with 1746 additions and 15 deletions

View file

@ -260,6 +260,28 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write
w->writeC(0);
}
break;
case DIV_SYSTEM_QSOUND:
for(int i=0; i<16; i++) {
w->writeC(0xc4);
w->writeC(0);
w->writeC(0);
w->writeC(2+(i*8));
w->writeC(0xc4);
w->writeC(0);
w->writeC(0);
w->writeC(6+(i*8));
}
for(int i=0; i<3; i++) {
w->writeC(0xc4);
w->writeC(0);
w->writeC(0);
w->writeC(0xcd+(i*4));
w->writeC(0xc4);
w->writeC(0x00);
w->writeC(0x01);
w->writeC(0xd6+i);
}
break;
default:
break;
}
@ -377,6 +399,12 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write
w->writeC((isSecond?0x80:0)|(write.addr&0xff));
w->writeC(write.val);
break;
case DIV_SYSTEM_QSOUND:
w->writeC(0xc4);
w->writeC((write.val >> 8)&0xff);
w->writeC(write.val&0xff);
w->writeC(write.addr&0xff);
break;
default:
logW("write not handled!\n");
break;
@ -489,6 +517,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) {
bool writePCESamples=false;
bool writeADPCM=false;
bool writeSegaPCM=false;
bool writeQSound=false;
for (int i=0; i<song.systemLen; i++) {
willExport[i]=false;
@ -668,6 +697,20 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) {
howManyChips++;
}
break;
case DIV_SYSTEM_QSOUND:
if (!hasQSound) {
// could set chipClock to 4000000 here for compatibility
// However I think it it not necessary because old VGM players will still
// not be able to handle the 64kb sample bank trick
hasQSound=disCont[i].dispatch->chipClock;
willExport[i]=true;
writeQSound=true;
} else if (!(hasQSound&0x40000000)) {
isSecond[i]=true;
willExport[i]=false;
addWarning("dual QSound is not supported by the VGM format");
}
break;
default:
break;
}
@ -900,6 +943,20 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) {
w->write(adpcmMem,adpcmMemLen);
}
if (writeQSound && 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);
}
// initialize streams
int streamID=0;
for (int i=0; i<song.systemLen; i++) {