Skip to content

Commit fe362ff

Browse files
committed
Improve physical CD track boundary. #117
1 parent 0f2ae37 commit fe362ff

3 files changed

Lines changed: 21 additions & 44 deletions

File tree

src/cdrom_media.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,7 @@ s32 CdRomMedia::GetTrackFromLBA(u32 lba)
204204

205205
bool CdRomMedia::IsCdRomUriPath(const char* path)
206206
{
207-
static const char* cdrom_uri_prefix = "cdrom://";
208-
209-
if (!IsValidPointer(path))
210-
return false;
211-
212-
for (int i = 0; cdrom_uri_prefix[i] != 0; i++)
213-
{
214-
if (path[i] != cdrom_uri_prefix[i])
215-
return false;
216-
}
217-
218-
return true;
207+
return IsValidPointer(path) && (strncmp(path, "cdrom://", 8) == 0);
219208
}
220209

221210
///////////////////////////////////////////////////////////////

src/cdrom_physical_image.cpp

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -301,44 +301,33 @@ void CdRomPhysicalImage::NormalizeTrackBoundaries()
301301
if (next_track.start_lba == 0)
302302
continue;
303303

304+
static const u32 audio_pregap_lengths[] = { CDROM_PHYSICAL_STANDARD_PREGAP_SECTORS, (2 * 75) + 74, 75 * 3, 75 * 4 };
305+
static const u32 data_pregap_lengths[] = { (2 * 75) + 74, CDROM_PHYSICAL_STANDARD_PREGAP_SECTORS, 75 * 3, 75 * 4 };
306+
307+
const u32* pregap_lengths = (next_track.type == GG_CDROM_AUDIO_TRACK) ? audio_pregap_lengths : data_pregap_lengths;
308+
u32 pregap_count = (u32)((next_track.type == GG_CDROM_AUDIO_TRACK) ?
309+
(sizeof(audio_pregap_lengths) / sizeof(audio_pregap_lengths[0])) :
310+
(sizeof(data_pregap_lengths) / sizeof(data_pregap_lengths[0])));
304311
u32 lead_in_lba = next_track.start_lba;
305312

306-
if (next_track.type == GG_CDROM_AUDIO_TRACK)
313+
for (u32 j = 0; j < pregap_count; j++)
307314
{
308-
static const u32 pregap_lengths[] = { CDROM_PHYSICAL_STANDARD_PREGAP_SECTORS, 75 * 3, 75 * 4 };
309-
310-
for (size_t j = 0; j < sizeof(pregap_lengths) / sizeof(pregap_lengths[0]); j++)
311-
{
312-
u32 pregap_length = pregap_lengths[j];
313-
if (next_track.start_lba <= pregap_length)
314-
continue;
315+
u32 pregap_length = pregap_lengths[j];
316+
if (next_track.start_lba <= pregap_length)
317+
continue;
315318

316-
u32 pregap_lba = next_track.start_lba - pregap_length;
317-
if ((pregap_lba <= track.start_lba) || (pregap_lba > track.end_lba))
318-
continue;
319+
u32 pregap_lba = next_track.start_lba - pregap_length;
320+
if ((pregap_lba <= track.start_lba) || (pregap_lba > track.end_lba))
321+
continue;
319322

320-
if (IsMode1DataSector(pregap_lba))
321-
continue;
322-
323-
if (!IsMode1DataSector(pregap_lba - 1))
324-
continue;
325-
326-
lead_in_lba = pregap_lba;
327-
break;
328-
}
329-
}
330-
else
331-
{
332-
u32 max_scan = MIN((u32)CDROM_PHYSICAL_MAX_PREGAP_SECTORS, next_track.start_lba - track.start_lba);
323+
if (!SectorMatchesTrackType(pregap_lba, next_track.type))
324+
continue;
333325

334-
while ((lead_in_lba > track.start_lba) && ((next_track.start_lba - lead_in_lba) < max_scan))
335-
{
336-
u32 probe_lba = lead_in_lba - 1;
337-
if (!SectorMatchesTrackType(probe_lba, next_track.type))
338-
break;
326+
if (SectorMatchesTrackType(pregap_lba - 1, next_track.type))
327+
continue;
339328

340-
lead_in_lba = probe_lba;
341-
}
329+
lead_in_lba = pregap_lba;
330+
break;
342331
}
343332

344333
if (lead_in_lba == next_track.start_lba)

src/cdrom_physical_image.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#define CDROM_PHYSICAL_REQUEST_QUEUE_SIZE 64
3939
#define CDROM_PHYSICAL_PREFETCH_BLOCKS 16
4040
#define CDROM_PHYSICAL_STANDARD_PREGAP_SECTORS 150
41-
#define CDROM_PHYSICAL_MAX_PREGAP_SECTORS (75 * 4)
4241

4342
class CdRomPhysicalImage : public CdRomImage
4443
{

0 commit comments

Comments
 (0)