- Getting/setting MPEG playback position also includes the end offset. Hopefully will fix save states from crashing when reloaded sometimes in DSB1 and DSB2 games.

This commit is contained in:
Bart Trzynadlowski 2011-09-22 18:04:39 +00:00
parent a1346b57f5
commit 4527014e75
3 changed files with 50 additions and 30 deletions

View file

@ -347,20 +347,23 @@ void CDSB1::IOWrite8(UINT32 addr, UINT8 data)
UINT8 CDSB1::IORead8(UINT32 addr) UINT8 CDSB1::IORead8(UINT32 addr)
{ {
int progress; int progress, end;
switch ((addr&0xFF)) switch ((addr&0xFF))
{ {
case 0xE2: // MPEG position, high byte case 0xE2: // MPEG position, high byte
progress = MPEG_GetProgress() + mpegStart; // byte address currently playing MPEG_GetPlayPosition(&progress, &end);
progress += mpegStart; // byte address currently playing
return (progress>>16)&0xFF; return (progress>>16)&0xFF;
case 0xE3: // MPEG position, middle byte case 0xE3: // MPEG position, middle byte
progress = MPEG_GetProgress() + mpegStart; MPEG_GetPlayPosition(&progress, &end);
progress += mpegStart;
return (progress>>8)&0xFF; return (progress>>8)&0xFF;
case 0xE4: // MPEG position, low byte case 0xE4: // MPEG position, low byte
progress = MPEG_GetProgress() + mpegStart; MPEG_GetPlayPosition(&progress, &end);
progress += mpegStart;
return progress&0xFF; return progress&0xFF;
case 0xF0: // Latch case 0xF0: // Latch
@ -475,16 +478,20 @@ void CDSB1::Reset(void)
void CDSB1::SaveState(CBlockFile *StateFile) void CDSB1::SaveState(CBlockFile *StateFile)
{ {
UINT32 mpegPos; int i, j;
UINT32 playOffset, endOffset;
UINT8 isPlaying; UINT8 isPlaying;
StateFile->NewBlock("DSB1", __FILE__); StateFile->NewBlock("DSB1", __FILE__);
// MPEG playback state // MPEG playback state
isPlaying = (UINT8) MPEG_IsPlaying(); isPlaying = (UINT8) MPEG_IsPlaying();
mpegPos = MPEG_GetProgress(); MPEG_GetPlayPosition(&i, &j);
playOffset = (UINT32) i; // in case sizeof(int) != sizeof(INT32)
endOffset = (UINT32) j;
StateFile->Write(&isPlaying, sizeof(isPlaying)); StateFile->Write(&isPlaying, sizeof(isPlaying));
StateFile->Write(&mpegPos, sizeof(mpegPos)); StateFile->Write(&playOffset, sizeof(playOffset));
StateFile->Write(&endOffset, sizeof(endOffset));
StateFile->Write(&usingMPEGStart, sizeof(usingMPEGStart)); StateFile->Write(&usingMPEGStart, sizeof(usingMPEGStart));
StateFile->Write(&usingMPEGEnd, sizeof(usingMPEGEnd)); StateFile->Write(&usingMPEGEnd, sizeof(usingMPEGEnd));
StateFile->Write(&usingLoopStart, sizeof(usingLoopStart)); StateFile->Write(&usingLoopStart, sizeof(usingLoopStart));
@ -511,7 +518,7 @@ void CDSB1::SaveState(CBlockFile *StateFile)
void CDSB1::LoadState(CBlockFile *StateFile) void CDSB1::LoadState(CBlockFile *StateFile)
{ {
UINT32 mpegPos; UINT32 playOffset, endOffset;
UINT8 isPlaying; UINT8 isPlaying;
if (OKAY != StateFile->FindBlock("DSB1")) if (OKAY != StateFile->FindBlock("DSB1"))
@ -521,7 +528,8 @@ void CDSB1::LoadState(CBlockFile *StateFile)
} }
StateFile->Read(&isPlaying, sizeof(isPlaying)); StateFile->Read(&isPlaying, sizeof(isPlaying));
StateFile->Read(&mpegPos, sizeof(mpegPos)); StateFile->Read(&playOffset, sizeof(playOffset));
StateFile->Read(&endOffset, sizeof(endOffset));
StateFile->Read(&usingMPEGStart, sizeof(usingMPEGStart)); StateFile->Read(&usingMPEGStart, sizeof(usingMPEGStart));
StateFile->Read(&usingMPEGEnd, sizeof(usingMPEGEnd)); StateFile->Read(&usingMPEGEnd, sizeof(usingMPEGEnd));
StateFile->Read(&usingLoopStart, sizeof(usingLoopStart)); StateFile->Read(&usingLoopStart, sizeof(usingLoopStart));
@ -548,7 +556,7 @@ void CDSB1::LoadState(CBlockFile *StateFile)
MPEG_PlayMemory((const char *) &mpegROM[usingMPEGStart], usingMPEGEnd-usingMPEGStart); MPEG_PlayMemory((const char *) &mpegROM[usingMPEGStart], usingMPEGEnd-usingMPEGStart);
if (usingLoopEnd != 0) // only if looping was actually enabled if (usingLoopEnd != 0) // only if looping was actually enabled
MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd);
MPEG_SetOffset(mpegPos); MPEG_SetPlayPosition(playOffset, endOffset);
} }
else else
MPEG_StopPlaying(); MPEG_StopPlaying();
@ -1036,16 +1044,20 @@ void CDSB2::Reset(void)
void CDSB2::SaveState(CBlockFile *StateFile) void CDSB2::SaveState(CBlockFile *StateFile)
{ {
UINT32 mpegPos; int i, j;
UINT32 playOffset, endOffset;
UINT8 isPlaying; UINT8 isPlaying;
StateFile->NewBlock("DSB2", __FILE__); StateFile->NewBlock("DSB2", __FILE__);
// MPEG playback state // MPEG playback state
isPlaying = (UINT8) MPEG_IsPlaying(); isPlaying = (UINT8) MPEG_IsPlaying();
mpegPos = MPEG_GetProgress(); MPEG_GetPlayPosition(&i, &j);
playOffset = (UINT32) i; // in case sizeof(int) != sizeof(INT32)
endOffset = (UINT32) j;
StateFile->Write(&isPlaying, sizeof(isPlaying)); StateFile->Write(&isPlaying, sizeof(isPlaying));
StateFile->Write(&mpegPos, sizeof(mpegPos)); StateFile->Write(&playOffset, sizeof(playOffset));
StateFile->Write(&endOffset, sizeof(endOffset));
StateFile->Write(&usingMPEGStart, sizeof(usingMPEGStart)); StateFile->Write(&usingMPEGStart, sizeof(usingMPEGStart));
StateFile->Write(&usingMPEGEnd, sizeof(usingMPEGEnd)); StateFile->Write(&usingMPEGEnd, sizeof(usingMPEGEnd));
StateFile->Write(&usingLoopStart, sizeof(usingLoopStart)); StateFile->Write(&usingLoopStart, sizeof(usingLoopStart));
@ -1076,7 +1088,7 @@ void CDSB2::SaveState(CBlockFile *StateFile)
void CDSB2::LoadState(CBlockFile *StateFile) void CDSB2::LoadState(CBlockFile *StateFile)
{ {
UINT32 mpegPos; UINT32 playOffset, endOffset;
UINT8 isPlaying; UINT8 isPlaying;
if (OKAY != StateFile->FindBlock("DSB2")) if (OKAY != StateFile->FindBlock("DSB2"))
@ -1086,7 +1098,8 @@ void CDSB2::LoadState(CBlockFile *StateFile)
} }
StateFile->Read(&isPlaying, sizeof(isPlaying)); StateFile->Read(&isPlaying, sizeof(isPlaying));
StateFile->Read(&mpegPos, sizeof(mpegPos)); StateFile->Read(&playOffset, sizeof(playOffset));
StateFile->Read(&endOffset, sizeof(endOffset));
StateFile->Read(&usingMPEGStart, sizeof(usingMPEGStart)); StateFile->Read(&usingMPEGStart, sizeof(usingMPEGStart));
StateFile->Read(&usingMPEGEnd, sizeof(usingMPEGEnd)); StateFile->Read(&usingMPEGEnd, sizeof(usingMPEGEnd));
StateFile->Read(&usingLoopStart, sizeof(usingLoopStart)); StateFile->Read(&usingLoopStart, sizeof(usingLoopStart));
@ -1113,7 +1126,7 @@ void CDSB2::LoadState(CBlockFile *StateFile)
MPEG_PlayMemory((const char *) &mpegROM[usingMPEGStart], usingMPEGEnd-usingMPEGStart); MPEG_PlayMemory((const char *) &mpegROM[usingMPEGStart], usingMPEGEnd-usingMPEGStart);
if (usingLoopEnd != 0) // only if looping was actually enabled if (usingLoopEnd != 0) // only if looping was actually enabled
MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd); MPEG_SetLoop((const char *) &mpegROM[usingLoopStart], usingLoopEnd);
MPEG_SetOffset(mpegPos); MPEG_SetPlayPosition(playOffset, endOffset);
} }
else else
MPEG_StopPlaying(); MPEG_StopPlaying();

View file

@ -48,23 +48,27 @@
extern bool MPEG_IsPlaying(void); extern bool MPEG_IsPlaying(void);
/* /*
* MPEG_GetProgress(void): * MPEG_GetPlayPosition(playOffset, endOffset):
* *
* Returns: * Obtains the current playback and end offsets of the MPEG stream.
* The current byte offset within the MPEG stream, relative to the start. *
* Parameters:
* playOffset Pointer to which playback byte offset will be written.
* endOffset Pointer to which end offset will be written.
*/ */
extern int MPEG_GetProgress(void); extern void MPEG_GetPlayPosition(int *playOffset, int *endOffset);
/* /*
* MPEG_SetOffset(pos): * MPEG_SetPlayPosition(playOffset, endOffset):
* *
* Sets the playback position within an MPEG stream. * Sets the playback position within an MPEG stream.
* *
* Parameters: * Parameters:
* pos Byte offset relative to the beginning of the current MPEG * playOffset Playback byte offset (relative to beginning of the current
* stream. * MPEG stream).
* endOffset End offset.
*/ */
extern void MPEG_SetOffset(int pos); extern void MPEG_SetPlayPosition(int playOffset, int endOffset);
/* /*
* MPEG_SetLoop(loop, loopend): * MPEG_SetLoop(loop, loopend):

View file

@ -48,16 +48,19 @@
static const char *fstart, *lstart; static const char *fstart, *lstart;
static int offset, end, eof, lend; static int offset, end, eof, lend;
int MPEG_GetProgress(void) void MPEG_GetPlayPosition(int *playOffset, int *endOffset)
{ {
if (in_file) return ftell(in_file); if (in_file)
*playOffset = ftell(in_file);
return offset; else
*playOffset = offset;
*endOffset = end;
} }
void MPEG_SetOffset(int pos) void MPEG_SetPlayPosition(int playOffset, int endOffset)
{ {
offset = pos; offset = playOffset;
end = endOffset;
} }
void m1setfile(const char *mstart, int mend) void m1setfile(const char *mstart, int mend)