CDVD: Minor cleanup and fix off-by-one TOC filling issue

This commit is contained in:
Ty Lamontagne 2024-11-24 15:02:47 -05:00 committed by Ty
parent 4d9cb885b2
commit 2c95ef76f1
3 changed files with 23 additions and 20 deletions

View File

@ -17,6 +17,7 @@
#include "common/ProgressCallback.h" #include "common/ProgressCallback.h"
#include "common/StringUtil.h" #include "common/StringUtil.h"
#include <array>
#include <ctype.h> #include <ctype.h>
#include <exception> #include <exception>
#include <memory> #include <memory>
@ -55,7 +56,7 @@ static OutputIsoFile blockDumpFile;
// Information about tracks on disc // Information about tracks on disc
u8 strack; u8 strack;
u8 etrack; u8 etrack;
cdvdTrack tracks[100]; std::array<cdvdTrack, 100> tracks;
// Assertion check for CDVD != NULL (in devel and debug builds), because its handier than // Assertion check for CDVD != NULL (in devel and debug builds), because its handier than
// relying on DEP exceptions -- and a little more reliable too. // relying on DEP exceptions -- and a little more reliable too.

View File

@ -10,7 +10,7 @@
class Error; class Error;
class ProgressCallback; class ProgressCallback;
typedef struct _cdvdTrackIndex struct cdvdTrackIndex
{ {
bool isPregap; bool isPregap;
u8 trackM; // current minute offset from first track (BCD encoded) u8 trackM; // current minute offset from first track (BCD encoded)
@ -20,9 +20,9 @@ typedef struct _cdvdTrackIndex
u8 discS; // current sector 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) u8 discF; // current frame location on the disc (BCD encoded)
} cdvdTrackIndex; };
typedef struct _cdvdTrack struct cdvdTrack
{ {
u32 start_lba; // Starting lba of track, note that some formats will be missing 2 seconds, cue, bin u32 start_lba; // Starting lba of track, note that some formats will be missing 2 seconds, cue, bin
u8 type; // Track Type u8 type; // Track Type
@ -36,10 +36,10 @@ typedef struct _cdvdTrack
u8 discF; // current frame location on the disc (BCD encoded) u8 discF; // current frame location on the disc (BCD encoded)
// 0 is pregap, 1 is data // 0 is pregap, 1 is data
_cdvdTrackIndex index[2]; cdvdTrackIndex index[2];
} cdvdTrack; };
typedef struct _cdvdSubQ struct cdvdSubQ
{ {
u8 ctrl : 4; // control and adr 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 adr : 4; // control and adr bits, note that adr determines what SubQ info we're recieving.
@ -52,19 +52,19 @@ typedef struct _cdvdSubQ
u8 discM; // current minute location on the disc (BCD encoded) u8 discM; // current minute location on the disc (BCD encoded)
u8 discS; // current sector 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) u8 discF; // current frame location on the disc (BCD encoded)
} cdvdSubQ; };
typedef struct _cdvdTD struct cdvdTD
{ // NOT bcd coded { // NOT bcd coded
u32 lsn; u32 lsn;
u8 type; u8 type;
} cdvdTD; };
typedef struct _cdvdTN struct cdvdTN
{ {
u8 strack; //number of the first track (usually 1) u8 strack; //number of the first track (usually 1)
u8 etrack; //number of the last track u8 etrack; //number of the last track
} cdvdTN; };
// SpindleCtrl Masks // SpindleCtrl Masks
#define CDVD_SPINDLE_SPEED 0x7 // Speed ranges from 0-3 (1, 2, 3, 4x for DVD) and 0-5 (1, 2, 4, 12, 24x for CD) #define CDVD_SPINDLE_SPEED 0x7 // Speed ranges from 0-3 (1, 2, 3, 4x for DVD) and 0-5 (1, 2, 4, 12, 24x for CD)
@ -185,7 +185,7 @@ extern const CDVD_API CDVDapi_NoDisc;
extern u8 strack; extern u8 strack;
extern u8 etrack; extern u8 etrack;
extern cdvdTrack tracks[100]; extern std::array<cdvdTrack, 100> tracks;
extern void CDVDsys_ChangeSource(CDVD_SourceType type); extern void CDVDsys_ChangeSource(CDVD_SourceType type);
extern void CDVDsys_SetFile(CDVD_SourceType srctype, std::string newfile); extern void CDVDsys_SetFile(CDVD_SourceType srctype, std::string newfile);

View File

@ -54,7 +54,7 @@ static void lsn_to_msf(u8* minute, u8* second, u8* frame, u32 lsn)
// TocStuff // TocStuff
void cdvdParseTOC() void cdvdParseTOC()
{ {
tracks[1].start_lba = 0; tracks.fill(cdvdTrack{});
if (!src->GetSectorCount()) if (!src->GetSectorCount())
{ {
@ -79,7 +79,7 @@ void cdvdParseTOC()
for (auto& entry : src->ReadTOC()) for (auto& entry : src->ReadTOC())
{ {
const u8 track = entry.track; const u8 track = entry.track;
if (track < 1 || track > 99) if (track < 1 || track >= tracks.size())
{ {
Console.Warning("CDVD: Invalid track index %u, ignoring\n", track); Console.Warning("CDVD: Invalid track index %u, ignoring\n", track);
continue; continue;
@ -472,11 +472,13 @@ static s32 DISCgetTOC(void* toc)
{ {
err = DISCgetTD(i, &trackInfo); err = DISCgetTD(i, &trackInfo);
lba_to_msf(trackInfo.lsn, &min, &sec, &frm); lba_to_msf(trackInfo.lsn, &min, &sec, &frm);
tocBuff[i * 10 + 30] = trackInfo.type;
tocBuff[i * 10 + 32] = err == -1 ? 0 : dec_to_bcd(i); //number const u8 tocIndex = i - diskInfo.strack;
tocBuff[i * 10 + 37] = dec_to_bcd(min); tocBuff[tocIndex * 10 + 30] = trackInfo.type;
tocBuff[i * 10 + 38] = dec_to_bcd(sec); tocBuff[tocIndex * 10 + 32] = err == -1 ? 0 : dec_to_bcd(i); //number
tocBuff[i * 10 + 39] = dec_to_bcd(frm); tocBuff[tocIndex * 10 + 37] = dec_to_bcd(min);
tocBuff[tocIndex * 10 + 38] = dec_to_bcd(sec);
tocBuff[tocIndex * 10 + 39] = dec_to_bcd(frm);
fprintf(stderr, "Track %u: %u mins %u secs %u frames\n", i, min, sec, frm); fprintf(stderr, "Track %u: %u mins %u secs %u frames\n", i, min, sec, frm);
} }
} }