Merge pull request #1231 from turtleli/cdvd-fixes

cdvdgigaherz: Dual layer DVD fixes
This commit is contained in:
Jonathan Li 2016-03-16 19:55:20 +00:00
commit c829826870
4 changed files with 67 additions and 124 deletions

View File

@ -290,19 +290,19 @@ s32 CALLBACK CDVDgetDualInfo(s32* dualType, u32* _layer1start)
{ {
case 1: case 1:
*dualType = 1; *dualType = 1;
*_layer1start = src->GetLayerBreakAddress(); *_layer1start = src->GetLayerBreakAddress() + 1;
return 1; return 0;
case 2: case 2:
*dualType = 2; *dualType = 2;
*_layer1start = src->GetLayerBreakAddress(); *_layer1start = src->GetLayerBreakAddress() + 1;
return 1; return 0;
case 0: case 0:
*dualType = 0; *dualType = 0;
*_layer1start = 0; *_layer1start = 0;
return 1;
}
return 0; return 0;
} }
return -1;
}
int lastReadInNewDiskCB=0; int lastReadInNewDiskCB=0;
char directReadSectorBuffer[2448]; char directReadSectorBuffer[2448];
@ -428,8 +428,6 @@ s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer)
return 0; return 0;
} }
u32 layer1start=-1;
s32 CALLBACK CDVDgetTOC(u8* tocBuff) s32 CALLBACK CDVDgetTOC(u8* tocBuff)
{ {
//return src->ReadTOC((char*)toc,2048); //return src->ReadTOC((char*)toc,2048);
@ -438,8 +436,7 @@ s32 CALLBACK CDVDgetTOC(u8* tocBuff)
if (curDiskType == CDVD_TYPE_NODISC) if (curDiskType == CDVD_TYPE_NODISC)
return -1; return -1;
if((curDiskType == CDVD_TYPE_DVDV) || if (curDiskType == CDVD_TYPE_DETCTDVDS || curDiskType == CDVD_TYPE_DETCTDVDD)
(curDiskType == CDVD_TYPE_PS2DVD))
{ {
memset(tocBuff, 0, 2048); memset(tocBuff, 0, 2048);
@ -465,7 +462,7 @@ s32 CALLBACK CDVDgetTOC(u8* tocBuff)
} }
else if(mt==1) //PTP else if(mt==1) //PTP
{ {
layer1start = src->GetLayerBreakAddress() + 0x30000; u32 layer1start = src->GetLayerBreakAddress() + 0x30000;
// dual sided // dual sided
tocBuff[ 0] = 0x24; tocBuff[ 0] = 0x24;
@ -489,7 +486,7 @@ s32 CALLBACK CDVDgetTOC(u8* tocBuff)
} }
else //OTP else //OTP
{ {
layer1start = src->GetLayerBreakAddress() + 0x30000; u32 layer1start = src->GetLayerBreakAddress() + 0x30000;
// dual sided // dual sided
tocBuff[ 0] = 0x24; tocBuff[ 0] = 0x24;
@ -512,11 +509,7 @@ s32 CALLBACK CDVDgetTOC(u8* tocBuff)
tocBuff[27] = (layer1start>> 0)&0xff; tocBuff[27] = (layer1start>> 0)&0xff;
} }
} }
else if(curDiskType == CDVD_TYPE_CDDA || else if (curDiskType == CDVD_TYPE_DETCTCD)
curDiskType == CDVD_TYPE_PS2CDDA ||
curDiskType == CDVD_TYPE_PS2CD ||
curDiskType == CDVD_TYPE_PSCDDA ||
curDiskType == CDVD_TYPE_PSCD)
{ {
// cd toc // cd toc
// (could be replaced by 1 command that reads the full toc) // (could be replaced by 1 command that reads the full toc)

View File

@ -445,8 +445,8 @@ s32 cdvdRefreshData()
switch(curDiskType) switch(curDiskType)
{ {
case CDVD_TYPE_DETCTDVDD: diskTypeName="Single-Layer DVD"; break; case CDVD_TYPE_DETCTDVDD: diskTypeName="Double-Layer DVD"; break;
case CDVD_TYPE_DETCTDVDS: diskTypeName="Double-Layer DVD"; break; case CDVD_TYPE_DETCTDVDS: diskTypeName="Single-Layer DVD"; break;
case CDVD_TYPE_DETCTCD: diskTypeName="CD-ROM"; break; case CDVD_TYPE_DETCTCD: diskTypeName="CD-ROM"; break;
case CDVD_TYPE_NODISC: diskTypeName="No Disc"; break; case CDVD_TYPE_NODISC: diskTypeName="No Disc"; break;
} }

View File

@ -37,24 +37,9 @@ s32 cdvdParseTOC()
return 0; return 0;
} }
s32 lastaddr = src->GetLayerBreakAddress(); s32 mt = src->GetMediaType();
if (mt >= 0)
if(lastaddr>=0)
{
if((lastaddr > 0)&&(tracks[0].length>lastaddr))
{
tracks[1].length=lastaddr+1;
tracks[1].type=0;
tracks[2].start_lba = tracks[1].length;
tracks[2].length = tracks[0].length-tracks[1].length;
tracks[2].type=0;
strack=1;
etrack=2;
}
else
{ {
tracks[1].length = tracks[0].length; tracks[1].length = tracks[0].length;
tracks[1].type = 0; tracks[1].type = 0;
@ -62,7 +47,6 @@ s32 cdvdParseTOC()
strack = 1; strack = 1;
etrack = 1; etrack = 1;
} }
}
else else
{ {
u8 min, sec, frm; u8 min, sec, frm;
@ -82,8 +66,6 @@ s32 cdvdParseTOC()
//return 0; //return 0;
} }
#define btoi(b) ((b>>4)*10+(b&0xF))
int length = (cdtoc.Length[0]<<8) | cdtoc.Length[1]; int length = (cdtoc.Length[0]<<8) | cdtoc.Length[1];
int descriptors = length/sizeof(cdtoc.Descriptors[0]); int descriptors = length/sizeof(cdtoc.Descriptors[0]);
for(int i=0;i<descriptors;i++) for(int i=0;i<descriptors;i++)

View File

@ -24,6 +24,7 @@
#include "rosddk/ntddscsi.h" #include "rosddk/ntddscsi.h"
#pragma warning(default:4200) #pragma warning(default:4200)
#include <stddef.h> #include <stddef.h>
#include <intrin.h>
template<class T> template<class T>
bool ApiErrorCheck(T t,T okValue,bool cmpEq) bool ApiErrorCheck(T t,T okValue,bool cmpEq)
@ -296,6 +297,8 @@ s32 IOCtlSrc::Reopen()
if(device==INVALID_HANDLE_VALUE) if(device==INVALID_HANDLE_VALUE)
return -1; return -1;
} }
// Dual layer DVDs cannot read from layer 1 without this ioctl
DeviceIoControl(device, FSCTL_ALLOW_EXTENDED_DASD_IO, nullptr, 0, nullptr, 0, &size, nullptr);
sessID=0; sessID=0;
DeviceIoControl(device,IOCTL_DVD_START_SESSION,NULL,0,&sessID,sizeof(DVD_SESSION_ID), &size, NULL); DeviceIoControl(device,IOCTL_DVD_START_SESSION,NULL,0,&sessID,sizeof(DVD_SESSION_ID), &size, NULL);
@ -394,37 +397,28 @@ s32 IOCtlSrc::GetSectorCount()
} }
} }
int sectors1=-1;
dvdrs.BlockByteOffset.QuadPart=0; dvdrs.BlockByteOffset.QuadPart=0;
dvdrs.Format=DvdPhysicalDescriptor; dvdrs.Format=DvdPhysicalDescriptor;
dvdrs.SessionId=sessID; dvdrs.SessionId=sessID;
dvdrs.LayerNumber=0; dvdrs.LayerNumber=0;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0) if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
{ {
if(dld.ld.EndLayerZeroSector>0) // OTP? s32 sectors1 = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1;
if (dld.ld.NumberOfLayers == 1) // PTP, OTP
{ {
sectors1 = dld.ld.EndLayerZeroSector - dld.ld.StartingDataSector; if (dld.ld.TrackPath == 0) // PTP
}
else //PTP or single layer
{ {
sectors1 = dld.ld.EndDataSector - dld.ld.StartingDataSector;
}
dvdrs.BlockByteOffset.QuadPart=0;
dvdrs.Format=DvdPhysicalDescriptor;
dvdrs.SessionId=sessID;
dvdrs.LayerNumber = 1; dvdrs.LayerNumber = 1;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0) if (DeviceIoControl(device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs), &dld, sizeof(dld), &size, nullptr) != 0)
{ {
// PTP second layer sectors1 += _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector) + 1;
//sectors1 += dld.ld.EndDataSector - dld.ld.StartingDataSector;
if(dld.ld.EndLayerZeroSector>0) // OTP?
{
sectors1 += dld.ld.EndLayerZeroSector - dld.ld.StartingDataSector;
} }
else //PTP }
else // OTP
{ {
sectors1 += dld.ld.EndDataSector - dld.ld.StartingDataSector; // sectors = end_sector - (~end_sector_l0 & 0xFFFFFF) + end_sector_l0 - start_sector
dld.ld.EndLayerZeroSector = _byteswap_ulong(dld.ld.EndLayerZeroSector);
sectors1 += dld.ld.EndLayerZeroSector - (~dld.ld.EndLayerZeroSector & 0x00FFFFFF) + 1;
} }
} }
@ -453,34 +447,21 @@ s32 IOCtlSrc::GetLayerBreakAddress()
dvdrs.LayerNumber=0; dvdrs.LayerNumber=0;
if(code=DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0) if(code=DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
{ {
if(dld.ld.EndLayerZeroSector>0) // OTP? if (dld.ld.NumberOfLayers == 0) // Single layer
{ {
layerBreakCached = true;
layerBreak = dld.ld.EndLayerZeroSector - dld.ld.StartingDataSector;
return layerBreak;
}
else //PTP or single layer
{
u32 s1 = dld.ld.EndDataSector - dld.ld.StartingDataSector;
dvdrs.BlockByteOffset.QuadPart=0;
dvdrs.Format=DvdPhysicalDescriptor;
dvdrs.SessionId=sessID;
dvdrs.LayerNumber=1;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
{
//PTP
layerBreakCached = true;
layerBreak = s1;
return layerBreak;
}
// single layer
layerBreakCached = true;
layerBreak = 0; layerBreak = 0;
return layerBreak;
} }
else if (dld.ld.TrackPath == 0) // PTP
{
layerBreak = _byteswap_ulong(dld.ld.EndDataSector) - _byteswap_ulong(dld.ld.StartingDataSector);
}
else // OTP
{
layerBreak = _byteswap_ulong(dld.ld.EndLayerZeroSector) - _byteswap_ulong(dld.ld.StartingDataSector);
}
layerBreakCached = true;
return layerBreak;
} }
//if not a cd, and fails, assume single layer //if not a cd, and fails, assume single layer
@ -560,34 +541,21 @@ s32 IOCtlSrc::GetMediaType()
dvdrs.LayerNumber=0; dvdrs.LayerNumber=0;
if(code=DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0) if(code=DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
{ {
if(dld.ld.EndLayerZeroSector>0) // OTP? if (dld.ld.NumberOfLayers == 0) // Single layer
{ {
mediaTypeCached = true;
mediaType = 2;
return mediaType;
}
else //PTP or single layer
{
u32 s1 = dld.ld.EndDataSector - dld.ld.StartingDataSector;
dvdrs.BlockByteOffset.QuadPart=0;
dvdrs.Format=DvdPhysicalDescriptor;
dvdrs.SessionId=sessID;
dvdrs.LayerNumber=1;
if(DeviceIoControl(device,IOCTL_DVD_READ_STRUCTURE,&dvdrs,sizeof(dvdrs),&dld, sizeof(dld), &size, NULL)!=0)
{
//PTP
mediaTypeCached = true;
mediaType = 2;
return mediaType;
}
// single layer
mediaTypeCached = true;
mediaType = 0; mediaType = 0;
return mediaType;
} }
else if (dld.ld.TrackPath == 0) // PTP
{
mediaType = 1;
}
else // OTP
{
mediaType = 2;
}
mediaTypeCached = true;
return mediaType;
} }
//if not a cd, and fails, assume single layer //if not a cd, and fails, assume single layer