From 37e50c62f048a4e5821d818898a1f97b7e1b4566 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 29 Jun 2021 19:29:58 +1000 Subject: [PATCH] CDROM: Fix intermediate seek->read status transition --- src/core/cdrom.cpp | 18 ++++++------------ src/core/cdrom.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 42403dca9..5729a9ee5 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -1749,8 +1749,6 @@ void CDROM::BeginReading(TickCount ticks_late /* = 0 */, bool after_seek /* = fa const TickCount ticks = GetTicksForRead(); const TickCount first_sector_ticks = ticks + (after_seek ? 0 : GetTicksForSeek(m_current_lba)) - ticks_late; - m_secondary_status.ClearActiveBits(); - m_secondary_status.motor_on = true; ResetAudioDecoder(); m_drive_state = DriveState::Reading; @@ -1792,9 +1790,6 @@ void CDROM::BeginPlaying(u8 track, TickCount ticks_late /* = 0 */, bool after_se const TickCount ticks = GetTicksForRead(); const TickCount first_sector_ticks = ticks + (after_seek ? 0 : GetTicksForSeek(m_current_lba, true)) - ticks_late; - m_secondary_status.ClearActiveBits(); - m_secondary_status.motor_on = true; - m_secondary_status.playing_cdda = true; ClearSectorBuffers(); ResetAudioDecoder(); @@ -1824,9 +1819,7 @@ void CDROM::BeginSeeking(bool logical, bool read_after_seek, bool play_after_see const CDImage::LBA seek_lba = m_setloc_position.ToLBA(); const TickCount seek_time = GetTicksForSeek(seek_lba, play_after_seek); - m_secondary_status.ClearActiveBits(); - m_secondary_status.motor_on = true; - m_secondary_status.seeking = true; + m_secondary_status.SetSeeking(); m_last_sector_header_valid = false; ResetAudioDecoder(); @@ -1983,7 +1976,6 @@ bool CDROM::CompleteSeek() { const bool logical = (m_drive_state == DriveState::SeekingLogical); ClearDriveState(); - m_secondary_status.ClearActiveBits(); bool seek_okay = m_reader.WaitForReadToComplete(); if (seek_okay) @@ -2057,6 +2049,7 @@ void CDROM::DoSeekComplete(TickCount ticks_late) } else { + m_secondary_status.ClearActiveBits(); m_async_response_fifo.Push(m_secondary_status.bits); SetAsyncInterrupt(Interrupt::Complete); } @@ -2066,6 +2059,8 @@ void CDROM::DoSeekComplete(TickCount ticks_late) CDImage::Position pos(CDImage::Position::FromLBA(m_reader.GetLastReadSector())); Log_WarningPrintf("%s seek to [%02u:%02u:%02u] failed", logical ? "Logical" : "Physical", pos.minute, pos.second, pos.frame); + + m_secondary_status.ClearActiveBits(); SendAsyncErrorResponse(STAT_SEEK_ERROR, 0x04); m_last_sector_header_valid = false; } @@ -2212,6 +2207,8 @@ void CDROM::DoSectorRead() m_physical_lba_update_tick = TimingEvents::GetGlobalTickCounter(); m_physical_lba_update_carry = 0; + m_secondary_status.SetReadingBits(m_drive_state == DriveState::Playing); + const CDImage::SubChannelQ& subq = m_reader.GetSectorSubQ(); const bool subq_valid = subq.IsCRCValid(); if (subq_valid) @@ -2296,9 +2293,6 @@ void CDROM::ProcessDataSector(const u8* raw_sector, const CDImage::SubChannelQ& ZeroExtend32(m_last_sector_header.sector_mode), ZeroExtend32(m_last_sector_subheader.submode.bits), sb_num); - // The reading bit shouldn't be set until the first sector is processed. - m_secondary_status.reading = true; - if (m_mode.xa_enable && m_last_sector_header.sector_mode == 2) { if (m_last_sector_subheader.submode.realtime && m_last_sector_subheader.submode.audio) diff --git a/src/core/cdrom.h b/src/core/cdrom.h index ae61a2d2e..240a7e984 100644 --- a/src/core/cdrom.h +++ b/src/core/cdrom.h @@ -200,6 +200,19 @@ private: /// Clears the CDDA/seeking bits. ALWAYS_INLINE void ClearActiveBits() { bits &= ~(STAT_SEEKING | STAT_READING | STAT_PLAYING_CDDA); } + + /// Sets the bits for seeking. + ALWAYS_INLINE void SetSeeking() + { + bits = (bits & ~(STAT_READING | STAT_PLAYING_CDDA)) | (STAT_MOTOR_ON | STAT_SEEKING); + } + + /// Sets the bits for reading/playing. + ALWAYS_INLINE void SetReadingBits(bool audio) + { + bits = (bits & ~(STAT_SEEKING | STAT_READING | STAT_PLAYING_CDDA)) | + ((audio) ? (STAT_MOTOR_ON | STAT_PLAYING_CDDA) : (STAT_MOTOR_ON | STAT_READING)); + } }; union ModeRegister