From 2926a49dbe49f713ee1ecf6831626cb155fa171c Mon Sep 17 00:00:00 2001 From: Sour Date: Sun, 19 Nov 2023 23:39:54 +0900 Subject: [PATCH] PCE: Fixed endless intro restart bug in Tenshi no Uta 2 --- Core/PCE/CdRom/PceCdAudioPlayer.cpp | 7 +++++++ Core/Shared/CdReader.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/Core/PCE/CdRom/PceCdAudioPlayer.cpp b/Core/PCE/CdRom/PceCdAudioPlayer.cpp index 2be374e6a..22b176d7f 100644 --- a/Core/PCE/CdRom/PceCdAudioPlayer.cpp +++ b/Core/PCE/CdRom/PceCdAudioPlayer.cpp @@ -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; @@ -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; diff --git a/Core/Shared/CdReader.h b/Core/Shared/CdReader.h index 3ab5608fd..4a348ea4f 100644 --- a/Core/Shared/CdReader.h +++ b/Core/Shared/CdReader.h @@ -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; }