Skip to content

Commit

Permalink
CDVD: Only take ADR and track index/num from host IOCTL SUBQ
Browse files Browse the repository at this point in the history
Fixes the OSDSYS CD player minute:second counter
  • Loading branch information
F0bes committed Nov 25, 2024
1 parent 849fa57 commit c9642b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
30 changes: 19 additions & 11 deletions pcsx2/CDVD/CDVDdiscReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void cdvdParseTOC()
tracks[track].type = CDVD_AUDIO_TRACK;
}
#ifdef PCSX2_DEBUG
DevCon.Write("cdvdParseTOC: Track %u: LBA %u, Type %u\n", track, tracks[track].start_lba, tracks[track].type);
DevCon.Write("cdvdParseTOC: Track %u: LBA %u, Type %u\n", track, tracks[track].start_lba, tracks[track].type);
#endif
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ static void keepAliveThread()
std::unique_lock<std::mutex> guard(s_keepalive_lock);

while (!s_keepalive_cv.wait_for(guard, std::chrono::seconds(30),
[]() { return !s_keepalive_is_open; }))
[]() { return !s_keepalive_is_open; }))
{

//printf(" * keepAliveThread: polling drive.\n");
Expand Down Expand Up @@ -273,20 +273,28 @@ static s32 DISCreadSubQ(u32 lsn, cdvdSubQ* subq)

memset(subq, 0, sizeof(cdvdSubQ));

if (!src->ReadTrackSubQ(subq))
{
lsn_to_msf(&subq->discM, &subq->discS, &subq->discF, lsn + 150);
lsn_to_msf(&subq->discM, &subq->discS, &subq->discF, lsn + 150);

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;
lsn_to_msf(&subq->trackM, &subq->trackS, &subq->trackF, lsn);

lsn_to_msf(&subq->trackM, &subq->trackS, &subq->trackF, lsn);
subq->ctrl = tracks[i].type;

// It's important to note that we do _not_ use the current MSF values
// from the host's device. We use the MSF values from the lsn.
// An easy way to test an implementation is to see if the OSDSYS
// CD player can display the correct minute and second values.
// From my testing, the IOCTL returns 0 for ctrl. This also breaks
// the OSDSYS player. The only "safe" values to receive from the IOCTL
// are ADR, trackNum and trackIndex.
if (!src->ReadTrackSubQ(subq))
{
subq->adr = 1;
subq->ctrl = tracks[i].type;
subq->trackNum = i;
subq->trackIndex = 1;
}
Expand Down
10 changes: 0 additions & 10 deletions pcsx2/CDVD/Linux/IOCtlSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,8 @@ bool IOCtlSrc::ReadTrackSubQ(cdvdSubQ* subQ) const
}

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;
}

Expand Down
9 changes: 0 additions & 9 deletions pcsx2/CDVD/Windows/IOCtlSrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,8 @@ bool IOCtlSrc::ReadTrackSubQ(cdvdSubQ* subQ) const
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;
Expand Down

0 comments on commit c9642b7

Please sign in to comment.