From 8df0496dc1729c513cf8adebc58970d202bdbb9b Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Sun, 11 Apr 2021 12:35:24 +1000
Subject: [PATCH] CDROM: Store last subq even when auto-pausing

Fixes track looping in Fighting Force PAL.
---
 src/core/cdrom.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp
index 977b88028..073b9868a 100644
--- a/src/core/cdrom.cpp
+++ b/src/core/cdrom.cpp
@@ -1921,13 +1921,20 @@ void CDROM::StopReadingWithDataEnd()
 void CDROM::DoSectorRead()
 {
   // TODO: Queue the next read here and swap the buffer.
+  // TODO: Error handling
   if (!m_reader.WaitForReadToComplete())
     Panic("Sector read failed");
 
-  // TODO: Error handling
+  m_current_lba = m_reader.GetLastReadSector();
+  ResetPhysicalPosition();
+
   const CDImage::SubChannelQ& subq = m_reader.GetSectorSubQ();
   const bool subq_valid = subq.IsCRCValid();
-  if (!subq_valid)
+  if (subq_valid)
+  {
+    m_last_subq = subq;
+  }
+  else
   {
     const CDImage::Position pos(CDImage::Position::FromLBA(m_current_lba));
     Log_DevPrintf("Sector %u [%02u:%02u:%02u] has invalid subchannel Q", m_current_lba, pos.minute, pos.second,
@@ -1964,11 +1971,6 @@ void CDROM::DoSectorRead()
     ProcessDataSectorHeader(m_reader.GetSectorBuffer().data());
   }
 
-  m_current_lba = m_reader.GetLastReadSector();
-  ResetPhysicalPosition();
-  if (subq_valid)
-    m_last_subq = subq;
-
   u32 next_sector = m_current_lba + 1u;
   if (is_data_sector && m_drive_state == DriveState::Reading)
   {