Skip to content

Commit

Permalink
Merge pull request #669 from aaru-dps/fakeshemp/add-gdrom-pregap
Browse files Browse the repository at this point in the history
Add pregap to second session in redump gdrom
  • Loading branch information
claunia authored Sep 25, 2021
2 parents 4a9986e + 8ab3623 commit 3372d62
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
13 changes: 8 additions & 5 deletions Aaru.Images/CDRWin/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ public List<Track> Tracks
foreach((ushort index, int position) in cdrTrack.Indexes)
aaruTrack.Indexes[index] = position;

if(_discImage.IsRedumpGigadisc &&
cdrTrack.Session == 2 &&
previousStartSector < gdRomSession2Offset)
aaruTrack.TrackStartSector = gdRomSession2Offset;

previousTrackFile = cdrTrack.TrackFile.DataFilter.GetFilename();

aaruTrack.TrackEndSector = aaruTrack.TrackStartSector + cdrTrack.Sectors - 1;

if(_discImage.IsRedumpGigadisc &&
cdrTrack.Session == 2 &&
previousStartSector < gdRomSession2Offset)
{
aaruTrack.TrackStartSector = (ulong)cdrTrack.Indexes[0];
aaruTrack.TrackEndSector = gdRomSession2Offset + cdrTrack.Sectors - (uint)cdrTrack.Pregap - 1;
}

if(cdrTrack.TrackType == CDRWIN_TRACK_TYPE_CDG)
{
aaruTrack.TrackSubchannelFilter = cdrTrack.TrackFile.DataFilter;
Expand Down
57 changes: 53 additions & 4 deletions Aaru.Images/CDRWin/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,9 +1253,11 @@ public bool Open(IFilter imageFilter)
track.Session == 2 &&
firstTrackInSession)
{
track.Indexes.Add(0, (int)(0 - (ulong)track.Pregap));
currentSector = (int)gdRomSession2Offset;
firstTrackInSession = false;
currentSector = (int)gdRomSession2Offset - track.Pregap;
track.Indexes.Add(0, 0);
track.Indexes[1] = track.Pregap;
track.Sectors += (ulong)track.Pregap;
firstTrackInSession = false;
}

currentFileStartSector = currentSector;
Expand Down Expand Up @@ -1346,7 +1348,8 @@ public bool Open(IFilter imageFilter)

if(_discImage.IsRedumpGigadisc &&
_discImage.Tracks[i].Sequence == 3)
_offsetMap.Add(_discImage.Tracks[i].Sequence, gdRomSession2Offset);
_offsetMap.Add(_discImage.Tracks[i].Sequence,
gdRomSession2Offset - (ulong)_discImage.Tracks[i].Pregap);
else if(_discImage.Tracks[i].Indexes.TryGetValue(0, out int idx0))
_offsetMap.Add(_discImage.Tracks[i].Sequence, (ulong)idx0);
else if(_discImage.Tracks[i].Sequence > 1)
Expand Down Expand Up @@ -1746,6 +1749,29 @@ public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
sectorAddress -= _lostPregap;
}

if(_discImage.IsRedumpGigadisc &&
aaruTrack.Session == 2 &&
aaruTrack.Indexes[0] >= 45000 - aaruTrack.Pregap &&
aaruTrack.Indexes[1] <= 45000)
{
if(sectorAddress < (ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]))
{
if(sectorAddress + length + (ulong)aaruTrack.Indexes[0] <= (ulong)aaruTrack.Indexes[1])
return buffer;

ulong pregapPos = (ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]) - sectorAddress;

byte[] presentData = ReadSectors((ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]),
(uint)(length - pregapPos), track);

Array.Copy(presentData, 0, buffer, (long)(pregapPos * sectorSize), presentData.Length);

return buffer;
}

sectorAddress -= (ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]);
}

_imageStream = aaruTrack.TrackFile.DataFilter.GetDataForkStream();
var br = new BinaryReader(_imageStream);

Expand Down Expand Up @@ -2152,6 +2178,29 @@ public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
sectorAddress -= _lostPregap;
}

if(_discImage.IsRedumpGigadisc &&
aaruTrack.Session == 2 &&
aaruTrack.Indexes[0] >= 45000 - aaruTrack.Pregap &&
aaruTrack.Indexes[1] <= 45000)
{
if(sectorAddress < (ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]))
{
if(sectorAddress + length + (ulong)aaruTrack.Indexes[0] <= (ulong)aaruTrack.Indexes[1])
return buffer;

ulong pregapPos = (ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]) - sectorAddress;

byte[] presentData = ReadSectorsLong((ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]),
(uint)(length - pregapPos), track);

Array.Copy(presentData, 0, buffer, (long)(pregapPos * sectorSize), presentData.Length);

return buffer;
}

sectorAddress -= (ulong)(aaruTrack.Indexes[1] - aaruTrack.Indexes[0]);
}

_imageStream = aaruTrack.TrackFile.DataFilter.GetDataForkStream();
var br = new BinaryReader(_imageStream);

Expand Down

0 comments on commit 3372d62

Please sign in to comment.