From 1a4a25599af2eb6168d0645b4581b6d2a9829ef1 Mon Sep 17 00:00:00 2001 From: weirdbeardgame Date: Sun, 8 Sep 2024 17:12:29 -0700 Subject: [PATCH] CDVD: Added cdvdTrack, cdvdTrackIndex used IOCtl SubQ reads to get proper control register Added Checks for Control fields. --- pcsx2/CDVD/CDVDcommon.h | 52 ++++++++++++++++++++++++++++----- pcsx2/CDVD/CDVDdiscReader.cpp | 35 +++++++++++++++------- pcsx2/CDVD/CDVDdiscReader.h | 10 ++----- pcsx2/CDVD/CDVDisoReader.cpp | 2 +- pcsx2/CDVD/Darwin/IOCtlSrc.cpp | 5 ++++ pcsx2/CDVD/Linux/IOCtlSrc.cpp | 30 +++++++++++++++++++ pcsx2/CDVD/Windows/IOCtlSrc.cpp | 32 ++++++++++++++++++++ 7 files changed, 139 insertions(+), 27 deletions(-) diff --git a/pcsx2/CDVD/CDVDcommon.h b/pcsx2/CDVD/CDVDcommon.h index f1e0efbc8f87b3..0e214c6cf5c1a0 100644 --- a/pcsx2/CDVD/CDVDcommon.h +++ b/pcsx2/CDVD/CDVDcommon.h @@ -10,19 +10,49 @@ class Error; class ProgressCallback; +typedef struct _cdvdTrackIndex +{ + bool isPregap; + u8 trackM; // current minute offset from first track (BCD encoded) + u8 trackS; // current sector offset from first track (BCD encoded) + u8 trackF; // current frame offset from first track (BCD encoded) + u8 discM; // current minute location on the disc (BCD encoded) + u8 discS; // current sector location on the disc (BCD encoded) + u8 discF; // current frame location on the disc (BCD encoded) + +} cdvdTrackIndex; + + +typedef struct _cdvdTrack +{ + u32 start_lba; // Starting lba of track, note that some formats will be missing 2 seconds, cue, bin + u8 type; // Track Type + u8 trackNum; // current track number (1 to 99) + u8 trackIndex; // current index within track (0 to 99) + u8 trackM; // current minute offset from first track (BCD encoded) + u8 trackS; // current sector offset from first track (BCD encoded) + u8 trackF; // current frame offset from first track (BCD encoded) + u8 discM; // current minute location on the disc (BCD encoded) + u8 discS; // current sector location on the disc (BCD encoded) + u8 discF; // current frame location on the disc (BCD encoded) + + // 0 is pregap, 1 is data + _cdvdTrackIndex index[2]; +} cdvdTrack; + typedef struct _cdvdSubQ { - u8 ctrl : 4; // control and mode bits - u8 mode : 4; // control and mode bits + u8 ctrl : 4; // control and adr bits + u8 adr : 4; // control and adr bits, note that adr determines what SubQ info we're recieving. u8 trackNum; // current track number (1 to 99) u8 trackIndex; // current index within track (0 to 99) - u8 trackM; // current minute location on the disc (BCD encoded) - u8 trackS; // current sector location on the disc (BCD encoded) - u8 trackF; // current frame location on the disc (BCD encoded) + u8 trackM; // current minute offset from first track (BCD encoded) + u8 trackS; // current sector offset from first track (BCD encoded) + u8 trackF; // current frame offset from first track (BCD encoded) u8 pad; // unused - u8 discM; // current minute offset from first track (BCD encoded) - u8 discS; // current sector offset from first track (BCD encoded) - u8 discF; // current frame offset from first track (BCD encoded) + u8 discM; // current minute location on the disc (BCD encoded) + u8 discS; // current sector location on the disc (BCD encoded) + u8 discF; // current frame location on the disc (BCD encoded) } cdvdSubQ; typedef struct _cdvdTD @@ -65,6 +95,12 @@ typedef struct _cdvdTN #define CDVD_TYPE_DETCT 0x01 // Detecting #define CDVD_TYPE_NODISC 0x00 // No Disc +// SUBQ CONTROL: +#define AUDIO_PREEMPHASIS(control) ((control & (4 << 1))) +#define DIGITAL_COPY(control) ((control & (5 << 1))) +#define DATA(control) ((control & (6 << 1))) // Detects if track is Data or Audio +#define QUADRAPHONIC_AUDIO(control) ((control & (7 << 1))) + // CDVDgetTrayStatus returns: #define CDVD_TRAY_CLOSE 0x00 #define CDVD_TRAY_OPEN 0x01 diff --git a/pcsx2/CDVD/CDVDdiscReader.cpp b/pcsx2/CDVD/CDVDdiscReader.cpp index 02eccc5eedf25c..edab05fe22d163 100644 --- a/pcsx2/CDVD/CDVDdiscReader.cpp +++ b/pcsx2/CDVD/CDVDdiscReader.cpp @@ -4,6 +4,7 @@ #include "CDVDdiscReader.h" #include "CDVD/CDVD.h" #include "Host.h" +#include "common/Console.h" #include "common/Error.h" @@ -25,7 +26,7 @@ static std::thread s_keepalive_thread; u8 strack; u8 etrack; -track tracks[100]; +cdvdTrack tracks[100]; int curDiskType; int curTrayStatus; @@ -270,20 +271,32 @@ static s32 DISCreadSubQ(u32 lsn, cdvdSubQ* subq) memset(subq, 0, sizeof(cdvdSubQ)); - lsn_to_msf(&subq->discM, &subq->discS, &subq->discF, lsn + 150); + if (src->ReadTrackSubQ(subq)) + { + u8 i = strack; + while (i < etrack && lsn >= tracks[i + 1].start_lba) + ++i; - u8 i = strack; - while (i < etrack && lsn >= tracks[i + 1].start_lba) - ++i; + lsn -= tracks[i].start_lba; + } - lsn -= tracks[i].start_lba; + else + { + lsn_to_msf(&subq->discM, &subq->discS, &subq->discF, lsn + 150); - lsn_to_msf(&subq->trackM, &subq->trackS, &subq->trackF, lsn); + u8 i = strack; + while (i < etrack && lsn >= tracks[i + 1].start_lba) + ++i; - subq->mode = 1; - subq->ctrl = tracks[i].type; - subq->trackNum = i; - subq->trackIndex = 1; + lsn -= tracks[i].start_lba; + + lsn_to_msf(&subq->trackM, &subq->trackS, &subq->trackF, lsn); + + subq->adr = 1; + subq->ctrl = tracks[i].type; + subq->trackNum = i; + subq->trackIndex = 1; + } return 0; } diff --git a/pcsx2/CDVD/CDVDdiscReader.h b/pcsx2/CDVD/CDVDdiscReader.h index 38e23ad4928dbc..d8b4c236bd8adb 100644 --- a/pcsx2/CDVD/CDVDdiscReader.h +++ b/pcsx2/CDVD/CDVDdiscReader.h @@ -7,6 +7,7 @@ #include "common/RedtapeWindows.h" #endif +#include "CDVDcommon.h" #include "common/Pcsx2Defs.h" #include @@ -17,15 +18,9 @@ class Error; -struct track -{ - u32 start_lba; - u8 type; -}; - extern u8 strack; extern u8 etrack; -extern track tracks[100]; +extern cdvdTrack tracks[100]; extern int curDiskType; extern int curTrayStatus; @@ -70,6 +65,7 @@ class IOCtlSrc const std::vector& ReadTOC() const; bool ReadSectors2048(u32 sector, u32 count, u8* buffer) const; bool ReadSectors2352(u32 sector, u32 count, u8* buffer) const; + bool ReadTrackSubQ(cdvdSubQ* subq) const; u32 GetLayerBreakAddress() const; s32 GetMediaType() const; void SetSpindleSpeed(bool restore_defaults) const; diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp index 43a64733278af4..f15064f5b5b5e6 100644 --- a/pcsx2/CDVD/CDVDisoReader.cpp +++ b/pcsx2/CDVD/CDVDisoReader.cpp @@ -65,7 +65,7 @@ static s32 ISOreadSubQ(u32 lsn, cdvdSubQ* subq) // fake it u8 min, sec, frm; subq->ctrl = 4; - subq->mode = 1; + subq->adr = 1; subq->trackNum = itob(1); subq->trackIndex = itob(1); diff --git a/pcsx2/CDVD/Darwin/IOCtlSrc.cpp b/pcsx2/CDVD/Darwin/IOCtlSrc.cpp index 86f66c59908de8..9fce3a72de2566 100644 --- a/pcsx2/CDVD/Darwin/IOCtlSrc.cpp +++ b/pcsx2/CDVD/Darwin/IOCtlSrc.cpp @@ -241,6 +241,11 @@ bool IOCtlSrc::ReadCDInfo() #endif } +bool IOCtlSrc::ReadTrackSubQ(cdvdSubQ* subQ) const +{ + return false; +} + bool IOCtlSrc::DiscReady() { #ifdef __APPLE__ diff --git a/pcsx2/CDVD/Linux/IOCtlSrc.cpp b/pcsx2/CDVD/Linux/IOCtlSrc.cpp index fced12ee8991ae..cb79222446c2c1 100644 --- a/pcsx2/CDVD/Linux/IOCtlSrc.cpp +++ b/pcsx2/CDVD/Linux/IOCtlSrc.cpp @@ -5,6 +5,7 @@ #include "CDVD/CDVD.h" #include "common/Error.h" +#include "common/Console.h" #include #include @@ -194,6 +195,35 @@ bool IOCtlSrc::ReadCDInfo() return true; } +bool IOCtlSrc::ReadTrackSubQ(cdvdSubQ* subQ) const +{ + cdrom_subchnl osSubQ; + + osSubQ.cdsc_format = CDROM_MSF; + + if (ioctl(m_device, CDROMSUBCHNL, &osSubQ) == -1) + { + Console.Error("SUB CHANNEL READ ERROR: %s\n", strerror(errno)); + return false; + } + + subQ->adr = osSubQ.cdsc_adr; + subQ->ctrl = osSubQ.cdsc_ctrl; + subQ->trackNum = osSubQ.cdsc_trk; + subQ->trackIndex = osSubQ.cdsc_ind; + + subQ->discM = osSubQ.cdsc_absaddr.msf.minute; + subQ->discS = osSubQ.cdsc_absaddr.msf.second; + subQ->discF = osSubQ.cdsc_absaddr.msf.frame; + + subQ->trackM = osSubQ.cdsc_reladdr.msf.minute; + subQ->trackS = osSubQ.cdsc_reladdr.msf.second; + subQ->trackF = osSubQ.cdsc_reladdr.msf.frame; + + return true; +} + + bool IOCtlSrc::DiscReady() { if (m_device == -1) diff --git a/pcsx2/CDVD/Windows/IOCtlSrc.cpp b/pcsx2/CDVD/Windows/IOCtlSrc.cpp index 3188a5d98c2a8c..073a70a4ed30fc 100644 --- a/pcsx2/CDVD/Windows/IOCtlSrc.cpp +++ b/pcsx2/CDVD/Windows/IOCtlSrc.cpp @@ -303,6 +303,38 @@ bool IOCtlSrc::ReadCDInfo() return true; } +bool IOCtlSrc::ReadTrackSubQ(cdvdSubQ* subQ) const +{ + CDROM_SUB_Q_DATA_FORMAT format; + SUB_Q_CHANNEL_DATA osSubQ{}; + DWORD unused; + + format.Format = IOCTL_CDROM_CURRENT_POSITION; + + if (!DeviceIoControl(m_device, IOCTL_CDROM_READ_Q_CHANNEL, &format, sizeof(format), &osSubQ, sizeof(osSubQ), &unused, nullptr)) + { + Console.Error("Subchannel Q reads failed"); + return false; + } + else + { + subQ->adr = osSubQ.CurrentPosition.ADR; + subQ->ctrl = osSubQ.CurrentPosition.Control; + subQ->trackNum = osSubQ.CurrentPosition.TrackNumber; + subQ->trackIndex = osSubQ.CurrentPosition.IndexNumber; + + subQ->trackM = osSubQ.CurrentPosition.TrackRelativeAddress[0]; + subQ->trackS = osSubQ.CurrentPosition.TrackRelativeAddress[1]; + subQ->trackF = osSubQ.CurrentPosition.TrackRelativeAddress[2]; + + subQ->discM = osSubQ.CurrentPosition.AbsoluteAddress[0]; + subQ->discS = osSubQ.CurrentPosition.AbsoluteAddress[1]; + subQ->discF = osSubQ.CurrentPosition.AbsoluteAddress[2]; + } + + return true; +} + bool IOCtlSrc::DiscReady() { if (m_device == INVALID_HANDLE_VALUE)