diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index f5c38fbbf..9ded86a4b 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2294,8 +2294,21 @@ SafeWriter* DivEngine::saveVGM() { } } - if (writePCESamples) { - // TODO + if (writePCESamples) for (int i=0; iwriteC(0x67); + w->writeC(0x66); + w->writeC(5); + w->writeI(sample->rendLength); + if (sample->depth==8) { + for (unsigned int j=0; jrendLength; j++) { + w->writeC(((unsigned char)sample->rendData[j]+0x80)>>3); + } + } else { + for (unsigned int j=0; jrendLength; j++) { + w->writeC(((unsigned short)sample->rendData[j]+0x8000)>>11); + } + } } if (writeSegaPCM) { @@ -2412,6 +2425,26 @@ SafeWriter* DivEngine::saveVGM() { w->writeI(32000); // default streamID++; break; + case DIV_SYSTEM_PCE: + for (int j=0; j<6; j++) { + w->writeC(0x90); + w->writeC(streamID); + w->writeC(27); + w->writeC(j); // port + w->writeC(0x06); // select+DAC + + w->writeC(0x91); + w->writeC(streamID); + w->writeC(5); + w->writeC(1); + w->writeC(0); + + w->writeC(0x92); + w->writeC(streamID); + w->writeI(32000); // default + streamID++; + } + break; default: logW("what? trying to play sample on unsupported system\n"); break; diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index a87e4c708..e56bcac15 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -133,6 +133,7 @@ void DivPlatformPCE::tick() { chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].furnaceDac) { chan[i].dacRate=chan[i].freq; + if (dumpWrites) addWrite(0xffff0001+(i<<8),1789773/chan[i].dacRate); } if (chan[i].freq>4095) chan[i].freq=4095; if (chan[i].note>0x5d) chan[i].freq=0x01; @@ -170,7 +171,13 @@ int DivPlatformPCE::dispatch(DivCommand c) { chan[c.chan].dacSample=ins->amiga.initSample; if (chan[c.chan].dacSample<0 || chan[c.chan].dacSample>=parent->song.sampleLen) { chan[c.chan].dacSample=-1; + if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); break; + } else { + if (dumpWrites) { + chWrite(c.chan,0x04,0xdf); + addWrite(0xffff0000+(c.chan<<8),chan[c.chan].dacSample); + } } chan[c.chan].dacPos=0; chan[c.chan].dacPeriod=0; @@ -186,11 +193,18 @@ int DivPlatformPCE::dispatch(DivCommand c) { chan[c.chan].dacSample=12*sampleBank+c.value%12; if (chan[c.chan].dacSample>=parent->song.sampleLen) { chan[c.chan].dacSample=-1; + if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); break; + } else { + if (dumpWrites) addWrite(0xffff0000+(c.chan<<8),chan[c.chan].dacSample); } chan[c.chan].dacPos=0; chan[c.chan].dacPeriod=0; chan[c.chan].dacRate=1789773/parent->song.sample[chan[c.chan].dacSample]->rate; + if (dumpWrites) { + chWrite(c.chan,0x04,0xdf); + addWrite(0xffff0001+(c.chan<<8),1789773/chan[c.chan].dacRate); + } chan[c.chan].furnaceDac=false; } break; @@ -209,6 +223,7 @@ int DivPlatformPCE::dispatch(DivCommand c) { } case DIV_CMD_NOTE_OFF: chan[c.chan].dacSample=-1; + if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); chan[c.chan].pcm=false; chan[c.chan].active=false; chan[c.chan].keyOff=true;