From 01b6e1b88db5ff43249f861ea10b65f60007678c Mon Sep 17 00:00:00 2001 From: refractionpcsx2 Date: Sat, 25 Mar 2023 04:25:13 +0000 Subject: [PATCH] CDVD: Add missing TOC information --- pcsx2/CDVD/CDVDdiscReader.cpp | 39 ++++++++++++++++++++++++++++++----- pcsx2/CDVD/CDVDisoReader.cpp | 35 +++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/pcsx2/CDVD/CDVDdiscReader.cpp b/pcsx2/CDVD/CDVDdiscReader.cpp index a7cf73b6c4..44d42d0157 100644 --- a/pcsx2/CDVD/CDVDdiscReader.cpp +++ b/pcsx2/CDVD/CDVDdiscReader.cpp @@ -351,7 +351,7 @@ s32 CALLBACK DISCgetTOC(void* toc) if (mt == 0) { //single layer - // fake it + // Single Layer - Values are fixed. tocBuff[0] = 0x04; tocBuff[1] = 0x02; tocBuff[2] = 0xF2; @@ -359,14 +359,33 @@ s32 CALLBACK DISCgetTOC(void* toc) tocBuff[4] = 0x86; tocBuff[5] = 0x72; + // These values are fixed on all discs, except position 14 which is the OTP/PTP flags which are 0 in single layer. + tocBuff[12] = 0x01; + tocBuff[13] = 0x02; + tocBuff[14] = 0x01; // Single layer. + tocBuff[15] = 0x00; + + // Values are fixed. tocBuff[16] = 0x00; // first sector for layer 0 tocBuff[17] = 0x03; tocBuff[18] = 0x00; tocBuff[19] = 0x00; + + cdvdTD trackInfo; + + if (DISCgetTD(0, &trackInfo) == -1) + trackInfo.lsn = 0; + // Max LSN in the TOC is calculated as the blocks + 0x30000, then - 1. + // same as layer 1 start. + const s32 maxlsn = trackInfo.lsn + (0x30000 - 1); + tocBuff[20] = maxlsn >> 24; + tocBuff[21] = (maxlsn >> 16) & 0xff; + tocBuff[22] = (maxlsn >> 8) & 0xff; + tocBuff[23] = (maxlsn >> 0) & 0xff; } else if (mt == 1) { //PTP - u32 layer1start = src->GetLayerBreakAddress() + 0x30000; + const s32 layer1start = src->GetLayerBreakAddress() + 0x30000; // dual sided tocBuff[0] = 0x24; @@ -376,8 +395,13 @@ s32 CALLBACK DISCgetTOC(void* toc) tocBuff[4] = 0x41; tocBuff[5] = 0x95; - tocBuff[14] = 0x61; // PTP + // These values are fixed on all discs, except position 14 which is the OTP/PTP flags. + tocBuff[12] = 0x01; + tocBuff[13] = 0x02; + tocBuff[14] = 0x21; // PTP + tocBuff[15] = 0x10; + // Values are fixed. tocBuff[16] = 0x00; tocBuff[17] = 0x03; tocBuff[18] = 0x00; @@ -390,7 +414,7 @@ s32 CALLBACK DISCgetTOC(void* toc) } else { //OTP - u32 layer1start = src->GetLayerBreakAddress() + 0x30000; + const s32 layer1start = src->GetLayerBreakAddress() + 0x30000; // dual sided tocBuff[0] = 0x24; @@ -400,8 +424,13 @@ s32 CALLBACK DISCgetTOC(void* toc) tocBuff[4] = 0x41; tocBuff[5] = 0x95; - tocBuff[14] = 0x71; // OTP + // These values are fixed on all discs, except position 14 which is the OTP/PTP flags. + tocBuff[12] = 0x01; + tocBuff[13] = 0x02; + tocBuff[14] = 0x31; // OTP + tocBuff[15] = 0x10; + // Values are fixed. tocBuff[16] = 0x00; tocBuff[17] = 0x03; tocBuff[18] = 0x00; diff --git a/pcsx2/CDVD/CDVDisoReader.cpp b/pcsx2/CDVD/CDVDisoReader.cpp index 92ebfc12ca..0a6c6c509c 100644 --- a/pcsx2/CDVD/CDVDisoReader.cpp +++ b/pcsx2/CDVD/CDVDisoReader.cpp @@ -208,7 +208,7 @@ s32 CALLBACK ISOgetTOC(void* toc) if (layer1start < 0) { - // fake it + // Single Layer - Values are fixed. tocBuff[0] = 0x04; tocBuff[1] = 0x02; tocBuff[2] = 0xF2; @@ -216,15 +216,35 @@ s32 CALLBACK ISOgetTOC(void* toc) tocBuff[4] = 0x86; tocBuff[5] = 0x72; + // These values are fixed on all discs, except position 14 which is the OTP/PTP flags which are 0 in single layer. + tocBuff[12] = 0x01; + tocBuff[13] = 0x02; + tocBuff[14] = 0x01; + tocBuff[15] = 0x00; + + // Values are fixed. tocBuff[16] = 0x00; tocBuff[17] = 0x03; tocBuff[18] = 0x00; tocBuff[19] = 0x00; + + cdvdTD trackInfo; + // Get the max LSN for the track + if (ISOgetTD(0, &trackInfo) == -1) + trackInfo.lsn = 0; + + // Max LSN in the TOC is calculated as the blocks + 0x30000, then - 1. + // same as layer 1 start. + const s32 maxlsn = trackInfo.lsn + (0x30000 - 1); + tocBuff[20] = maxlsn >> 24; + tocBuff[21] = (maxlsn >> 16) & 0xff; + tocBuff[22] = (maxlsn >> 8) & 0xff; + tocBuff[23] = (maxlsn >> 0) & 0xff; return 0; } else { - // dual sided + // Dual sided - Values are fixed. tocBuff[0] = 0x24; tocBuff[1] = 0x02; tocBuff[2] = 0xF2; @@ -232,14 +252,19 @@ s32 CALLBACK ISOgetTOC(void* toc) tocBuff[4] = 0x41; tocBuff[5] = 0x95; - tocBuff[14] = 0x60; // dual sided, ptp + // These values are fixed on all discs, except position 14 which is the OTP/PTP flags. + tocBuff[12] = 0x01; + tocBuff[13] = 0x02; + tocBuff[14] = 0x21; // PTP + tocBuff[15] = 0x10; + // Values are fixed. tocBuff[16] = 0x00; tocBuff[17] = 0x03; tocBuff[18] = 0x00; tocBuff[19] = 0x00; - s32 l1s = layer1start + 0x30000 - 1; + const s32 l1s = layer1start + 0x30000 - 1; tocBuff[20] = (l1s >> 24); tocBuff[21] = (l1s >> 16) & 0xff; tocBuff[22] = (l1s >> 8) & 0xff; @@ -280,7 +305,9 @@ s32 CALLBACK ISOgetTOC(void* toc) tocBuff[22] = 0xA2; tocBuff[27] = itob(min); tocBuff[28] = itob(sec); + tocBuff[29] = itob(frm); + // TODO: When cue support is added, this will need to account for pregap. for (i = diskInfo.strack; i <= diskInfo.etrack; i++) { err = ISOgetTD(i, &trackInfo);