Skip to content

Commit

Permalink
Include CD audio player state in serialized save state (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
schellingb committed Nov 29, 2023
1 parent 66f5061 commit 9ae2190
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/dbp_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ void DBPSerialize_All(DBPArchive& ar, bool dos_running, bool game_running)
Bit64s from = __rdtsc();
#endif

ar.version = 5;
ar.version = 6;
if (ar.mode != DBPArchive::MODE_ZERO)
{
Bit32u magic = 0xD05B5747;
Bit8u invalid_state = (dos_running ? 0 : 1) | (game_running ? 0 : 2);
ar << magic << ar.version << invalid_state;
if (magic != 0xD05B5747) { ar.had_error = DBPArchive::ERR_LAYOUT; return; }
if (ar.version < 1 || ar.version > 5) { DBP_ASSERT(false); ar.had_error = DBPArchive::ERR_VERSION; return; }
if (ar.version < 1 || ar.version > 6) { DBP_ASSERT(false); ar.had_error = DBPArchive::ERR_VERSION; return; }
if (ar.mode == DBPArchive::MODE_LOAD || ar.mode == DBPArchive::MODE_SAVE)
{
if (!dos_running || (invalid_state & 1)) { ar.had_error = DBPArchive::ERR_DOSNOTRUNNING; return; }
Expand Down Expand Up @@ -343,6 +343,7 @@ void DBPSerialize_All(DBPArchive& ar, bool dos_running, bool game_running)
case __LINE__: DBPSERIALIZE_GET_FUNC(DBPSerialize_MPU401 ); break;
case __LINE__: DBPSERIALIZE_GET_FUNC(DBPSerialize_PCSPEAKER ); break;
case __LINE__: DBPSERIALIZE_GET_FVER(DBPSerialize_Voodoo, >=5); break;
case __LINE__: DBPSERIALIZE_GET_FVER(DBPSerialize_CDPlayer,>=6); break;
case __LINE__: goto done; /*return;*/ default: continue;
}
size_t old_off = ar.GetOffset();
Expand Down
2 changes: 2 additions & 0 deletions src/dos/cdrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ static int refCount;
typedef std::vector<Track>::iterator track_it;
std::string mcn;
Bit8u subUnit;

friend void DBPSerialize_CDPlayer(struct DBPArchive& ar);
};

#ifdef C_DBP_NATIVE_CDROM
Expand Down
23 changes: 23 additions & 0 deletions src/dos/cdrom_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,3 +1273,26 @@ void CDROM_Image_Init(Section* section) {
section->AddDestroyFunction(CDROM_Image_Destroy, false);
#endif
}

#include <dbp_serialize.h>

void DBPSerialize_CDPlayer(DBPArchive& ar_outer)
{
DBPArchiveOptional ar(ar_outer, CDROM_Interface_Image::player.channel, (CDROM_Interface_Image::player.cd != NULL));
if (ar.IsSkip()) return;

ar << CDROM_Interface_Image::player.currFrame << CDROM_Interface_Image::player.targetFrame
<< CDROM_Interface_Image::player.isPlaying << CDROM_Interface_Image::player.isPaused
<< CDROM_Interface_Image::player.ctrlUsed;
ar.Serialize(CDROM_Interface_Image::player.ctrlData);

if (ar.mode == DBPArchive::MODE_LOAD && CDROM_Interface_Image::player.isPlaying && !CDROM_Interface_Image::player.cd)
{
CDROM_Interface_Image* img = NULL;
for (int i = 2; i != 10; i++)
if ((img = (Drives[i] && dynamic_cast<isoDrive*>(Drives[i]) ? dynamic_cast<CDROM_Interface_Image*>(((isoDrive*)Drives[i])->GetInterface()) : NULL)) != NULL)
break;
CDROM_Interface_Image::player.cd = img;
if (!img) CDROM_Interface_Image::player.isPlaying = false;
}
}

0 comments on commit 9ae2190

Please sign in to comment.