Skip to content

Commit

Permalink
PCE: Fixed endless intro restart bug in Tenshi no Uta 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SourMesen committed Nov 19, 2023
1 parent 5f48a82 commit 2926a49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Core/PCE/CdRom/PceCdAudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void PceCdAudioPlayer::Play(uint32_t startSector, bool pause)

void PceCdAudioPlayer::SetEndPosition(uint32_t endSector, CdPlayEndBehavior endBehavior)
{
if(endSector >= _disc->DiscSectorCount) {
endSector = _disc->DiscSectorCount - 1;
}

_state.EndSector = endSector;
_state.EndBehavior = endBehavior;
_state.Status = CdAudioStatus::Playing;
Expand All @@ -53,6 +57,9 @@ void PceCdAudioPlayer::PlaySample()
_state.CurrentSector++;

if(_state.CurrentSector > _state.EndSector) {
if(_state.CurrentSector >= _disc->DiscSectorCount) {
_state.CurrentSector = _disc->DiscSectorCount - 1;
}
switch(_state.EndBehavior) {
case CdPlayEndBehavior::Stop: _state.Status = CdAudioStatus::Stopped; break;
case CdPlayEndBehavior::Loop: _state.CurrentSector = _state.StartSector; break;
Expand Down
6 changes: 6 additions & 0 deletions Core/Shared/CdReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ struct DiscInfo
{
if(track < Tracks.size()) {
return Tracks[track].FirstSector;
} else if(track > 0 && track == Tracks.size()) {
//Tenshi no Uta 2 intro sets the end of the audio playback to track 0x35, but the last track is 0x34
//The expected behavior is probably that audio should end at the of track 0x34
//Without this code, the end gets set to sector 0, which immediately triggers an IRQ and restarts the
//intro sequence early, making it impossible to start playing the game.
return Tracks[track - 1].LastSector;
}
return -1;
}
Expand Down

0 comments on commit 2926a49

Please sign in to comment.