Skip to content

Commit

Permalink
Revert moving media size/type detection to cdvdman
Browse files Browse the repository at this point in the history
  • Loading branch information
rickgaiser committed Mar 13, 2024
1 parent 47dcf7a commit 931dc53
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
22 changes: 21 additions & 1 deletion ee/loader/src/main.c
Expand Up @@ -1110,6 +1110,7 @@ int main(int argc, char *argv[])
* Enable DVD emulation
*/
if (sDVDFile != NULL) {
uint32_t layer1_lba_start = 0;
int fd_iso = 0;

if (set_fhi_bd_defrag == NULL && set_fhi_file == NULL) {
Expand Down Expand Up @@ -1153,10 +1154,28 @@ int main(int argc, char *argv[])
printf("File is not a valid ISO\n");
return -1;
}
// Get ISO layer0 size
uint32_t layer0_lba_size;
lseek64(fd_iso, 16 * 2048 + 80, SEEK_SET);
if (read(fd_iso, &layer0_lba_size, sizeof(layer0_lba_size)) != sizeof(layer0_lba_size)) {
printf("ISO invalid\n");
return -1;
}
// Try to get ISO layer1 size
layer1_lba_start = 0;
lseek64(fd_iso, (uint64_t)layer0_lba_size * 2048, SEEK_SET);
if (read(fd_iso, buffer, sizeof(buffer)) == sizeof(buffer)) {
if ((buffer[0x00] == 1) && (!strncmp(&buffer[0x01], "CD001", 5))) {
layer1_lba_start = layer0_lba_size - 16;
printf("- DVD-DL detected\n");
}
}

if (eMediaType == SCECdNODISC)
eMediaType = iso_size <= (333000 * 2048) ? SCECdPS2CD : SCECdPS2DVD;

const char *sMT;
switch (eMediaType) {
case SCECdNODISC: sMT = "ps2 cd/dvd auto detect"; break;
case SCECdPS2CDDA: sMT = "ps2 cdda"; break;
case SCECdPS2CD: sMT = "ps2 cd"; break;
case SCECdDVDV: sMT = "dvd video"; break;
Expand All @@ -1176,6 +1195,7 @@ int main(int argc, char *argv[])
close(fd_iso);

set_cdvdman->media = eMediaType;
set_cdvdman->layer1_start = layer1_lba_start;
set_cdvdman->fs_sectors = sys.fs_sectors;
if (sys.ilink_id_int != 0) {
printf("Overriding i.Link ID: %2x %2x %2x %2x %2x %2x %2x %2x\n"
Expand Down
49 changes: 26 additions & 23 deletions iop/cdvdman_emu/src/searchfile.c
Expand Up @@ -222,35 +222,38 @@ int sceCdLayerSearchFile(sceCdlFILE *fp, const char *name, int layer)
//-------------------------------------------------------------------------
void cdvdman_searchfile_init(void)
{
// Read the volume descriptor of first layer
// Read the volume descriptor
sceCdRead_internal(16, 1, cdvdman_buf, NULL, ECS_SEARCHFILE);
sceCdSync(0);

struct dirTocEntry *tocEntryPointer = (struct dirTocEntry *)&cdvdman_buf[0x9c];
layer_info[0].rootDirtocLBA = tocEntryPointer->fileLBA;
layer_info[0].rootDirtocLength = tocEntryPointer->fileSize;

// Number of sectors on first layer
u32 lsn0 = *(u32 *)&cdvdman_buf[0x50];

// Auto detect CD/DVD based on number of sectors
if (cdvdman_settings.media == SCECdNODISC)
cdvdman_settings.media = lsn0 <= 333000 ? SCECdPS2CD : SCECdPS2DVD;

// Read the volume descriptor of second layer
sceCdRead_internal(lsn0, 1, cdvdman_buf, NULL, ECS_SEARCHFILE);
sceCdSync(0);

if ((sceCdGetError() == SCECdErNO) && (cdvdman_buf[0x00] == 1) && (!strncmp(&((char*)cdvdman_buf)[0x01], "CD001", 5))) {
M_DEBUG("%s: Dual Layer DVD detected @ lsn = %d\n", __FUNCTION__, lsn0 - 16);

cdvdman_settings.layer1_start = lsn0 - 16;

tocEntryPointer = (struct dirTocEntry *)&cdvdman_buf[0x9c];
layer_info[1].rootDirtocLBA = cdvdman_settings.layer1_start + tocEntryPointer->fileLBA;
layer_info[1].rootDirtocLength = tocEntryPointer->fileSize;
}
else {
M_DEBUG("%s: Single Layer %s detected\n", __FUNCTION__, cdvdman_settings.media == SCECdPS2CD ? "CD" : "DVD");
// PVD Volume Space Size field
//mediaLsnCount = *(u32 *)&cdvdman_buf[0x50];
//M_DEBUG("cdvdman_searchfile_init mediaLsnCount=%d\n", mediaLsnCount);

// DVD DL support
if (!(cdvdman_settings.flags & IOPCORE_COMPAT_EMU_DVDDL)) {
int on_dual;
u32 layer1_start;
sceCdReadDvdDualInfo(&on_dual, &layer1_start);
if (on_dual) {
//u32 lsn0 = mediaLsnCount;
// So that CdRead below can read more than first layer.
//mediaLsnCount = 0;
sceCdRead_internal(layer1_start + 16, 1, cdvdman_buf, NULL, ECS_SEARCHFILE);
sceCdSync(0);
tocEntryPointer = (struct dirTocEntry *)&cdvdman_buf[0x9c];
layer_info[1].rootDirtocLBA = layer1_start + tocEntryPointer->fileLBA;
layer_info[1].rootDirtocLength = tocEntryPointer->fileSize;

//u32 lsn1 = *(u32 *)&cdvdman_buf[0x50];
//M_DEBUG("cdvdman_searchfile_init DVD9 L0 mediaLsnCount=%d \n", lsn0);
//M_DEBUG("cdvdman_searchfile_init DVD9 L1 mediaLsnCount=%d \n", lsn1);
//mediaLsnCount = lsn0 + lsn1 - 16;
//M_DEBUG("cdvdman_searchfile_init DVD9 mediaLsnCount=%d\n", mediaLsnCount);
}
}
}

0 comments on commit 931dc53

Please sign in to comment.