VGM export: implement sys selection/loop options

the final thing to do is dual chip support, but I wanna get 0.5
out already
This commit is contained in:
tildearrow 2022-01-27 02:46:40 -05:00
parent 3ed738dd6a
commit c577eeafac
3 changed files with 20 additions and 9 deletions

View File

@ -2406,7 +2406,7 @@ void DivEngine::walkSong(int& loopOrder, int& loopRow, int& loopEnd) {
}
}
SafeWriter* DivEngine::saveVGM() {
SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop) {
stop();
setOrder(0);
isBusy.lock();
@ -2509,6 +2509,9 @@ SafeWriter* DivEngine::saveVGM() {
for (int i=0; i<song.systemLen; i++) {
willExport[i]=false;
streamIDs[i]=0;
if (sysToExport!=NULL) {
if (!sysToExport[i]) continue;
}
switch (song.system[i]) {
case DIV_SYSTEM_GENESIS:
case DIV_SYSTEM_GENESIS_EXT:
@ -2887,6 +2890,12 @@ SafeWriter* DivEngine::saveVGM() {
}
if (nextTick()) {
done=true;
if (!loop) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].dispatch->getRegisterWrites().clear();
}
break;
}
// stop all streams
for (int i=0; i<streamID; i++) {
w->writeC(0x94);
@ -3019,11 +3028,13 @@ SafeWriter* DivEngine::saveVGM() {
w->seek(0x14,SEEK_SET);
w->writeI(gd3Off-0x14);
w->writeI(tickCount);
// loop not handled for now
printf("writing loop pos: %d\n",loopPos-0x1c);
printf("writing tick count: %d\n",(int)(tickCount-loopTick));
w->writeI(loopPos-0x1c);
w->writeI(tickCount-loopTick-1);
if (loop) {
w->writeI(loopPos-0x1c);
w->writeI(tickCount-loopTick-1);
} else {
w->writeI(0);
w->writeI(0);
}
remainingLoops=-1;
playing=false;

View File

@ -222,8 +222,8 @@ class DivEngine {
// build a ROM file (TODO).
// specify system to build ROM for.
SafeWriter* buildROM(int sys);
// dump to VGM (TODO).
SafeWriter* saveVGM();
// dump to VGM.
SafeWriter* saveVGM(bool* sysToExport=NULL, bool loop=true);
// export to an audio file
bool saveAudio(const char* path, int loops, DivAudioExportModes mode);
// wait for audio export to finish

View File

@ -4628,7 +4628,7 @@ bool FurnaceGUI::loop() {
modified=true;
break;
case GUI_FILE_EXPORT_VGM: {
SafeWriter* w=e->saveVGM();
SafeWriter* w=e->saveVGM(willExport,vgmExportLoop);
if (w!=NULL) {
FILE* f=fopen(copyOfName.c_str(),"wb");
if (f!=NULL) {