[Aaru.Core] Reformat and cleanup.

This commit is contained in:
2023-10-03 22:57:50 +01:00
parent 57853b0d2a
commit af659f3fcb
85 changed files with 3303 additions and 1961 deletions

View File

@@ -99,15 +99,15 @@ public static class CompactDisc
int prePos = int.MinValue;
// Check subchannel
for(int subPos = 0; subPos < deSub.Length; subPos += 96)
for(var subPos = 0; subPos < deSub.Length; subPos += 96)
{
// Expected LBA
long lba = (long)sectorAddress + (subPos / 96);
long lba = (long)sectorAddress + subPos / 96;
// We fixed the subchannel
bool @fixed = false;
var @fixed = false;
byte[] q = new byte[12];
var q = new byte[12];
Array.Copy(deSub, subPos + 12, q, 0, 12);
// Check Q CRC
@@ -115,8 +115,8 @@ public static class CompactDisc
bool crcOk = crc[0] == q[10] && crc[1] == q[11];
// Start considering P to be OK
bool pOk = true;
int pWeight = 0;
var pOk = true;
var pWeight = 0;
// Check P and weight
for(int p = subPos; p < subPos + 12; p++)
@@ -125,9 +125,11 @@ public static class CompactDisc
deSub[p] != 255)
pOk = false;
for(int w = 0; w < 8; w++)
if(((deSub[p] >> w) & 1) > 0)
for(var w = 0; w < 8; w++)
{
if((deSub[p] >> w & 1) > 0)
pWeight++;
}
}
// This seems to be a somewhat common pattern
@@ -150,13 +152,13 @@ public static class CompactDisc
deSub.Skip(subPos + 84).Take(12).All(w => w == 0xFF);
bool rwOk = rOk && sOk && tOk && uOk && vOk && wOk;
bool rwPacket = false;
bool cdtextPacket = false;
var rwPacket = false;
var cdtextPacket = false;
// Check RW contents
if(!rwOk)
{
byte[] sectorSub = new byte[96];
var sectorSub = new byte[96];
Array.Copy(sub, subPos, sectorSub, 0, 96);
DetectRwPackets(sectorSub, out _, out rwPacket, out cdtextPacket);
@@ -173,11 +175,15 @@ public static class CompactDisc
if(!pOk && fixSubchannel)
{
if(pWeight >= 48)
{
for(int p = subPos; p < subPos + 12; p++)
deSub[p] = 255;
}
else
{
for(int p = subPos; p < subPos + 12; p++)
deSub[p] = 0;
}
pOk = true;
@fixed = true;
@@ -257,22 +263,22 @@ public static class CompactDisc
!rwOk)
continue;
byte aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
var aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if((q[0] & 0x3) == 1)
{
byte amin = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
byte asec = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
aPos = (amin * 60 * 75) + (asec * 75) + aframe - 150;
var amin = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
var asec = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
aPos = amin * 60 * 75 + asec * 75 + aframe - 150;
}
else
{
ulong expectedSectorAddress = sectorAddress + (ulong)(subPos / 96) + 150;
byte smin = (byte)(expectedSectorAddress / 60 / 75);
var smin = (byte)(expectedSectorAddress / 60 / 75);
expectedSectorAddress -= (ulong)(smin * 60 * 75);
byte ssec = (byte)(expectedSectorAddress / 75);
var ssec = (byte)(expectedSectorAddress / 75);
aPos = (smin * 60 * 75) + (ssec * 75) + aframe - 150;
aPos = smin * 60 * 75 + ssec * 75 + aframe - 150;
// Next second
if(aPos < prePos)
@@ -285,7 +291,7 @@ public static class CompactDisc
prePos = aPos;
byte[] posSub = new byte[96];
var posSub = new byte[96];
Array.Copy(deSub, subPos, posSub, 0, 96);
posSub = Subchannel.Interleave(posSub);
outputPlugin.WriteSectorTag(posSub, (ulong)aPos, SectorTagType.CdSectorSubchannel);
@@ -316,13 +322,13 @@ public static class CompactDisc
Dictionary<byte, int> smallestPregapLbaPerTrack, bool dumping,
out List<ulong> newPregapSectors, ulong sectorAddress)
{
bool status = false;
var status = false;
newPregapSectors = new List<ulong>();
// Check subchannel
for(int subPos = 0; subPos < deSub.Length; subPos += 96)
for(var subPos = 0; subPos < deSub.Length; subPos += 96)
{
byte[] q = new byte[12];
var q = new byte[12];
Array.Copy(deSub, subPos + 12, q, 0, 12);
CRC16CCITTContext.Data(q, 10, out byte[] crc);
@@ -354,7 +360,7 @@ public static class CompactDisc
else if(isrcs[currentTrackNumber] != isrc)
{
Track currentTrack =
tracks.FirstOrDefault(t => sectorAddress + ((ulong)subPos / 96) >= t.StartSector);
tracks.FirstOrDefault(t => sectorAddress + (ulong)subPos / 96 >= t.StartSector);
if(currentTrack?.Sequence == currentTrackNumber)
{
@@ -384,12 +390,12 @@ public static class CompactDisc
if(mcn is null)
{
dumpLog?.WriteLine(string.Format(Localization.Core.Found_new_MCN_0, newMcn));
dumpLog?.WriteLine(string.Format(Localization.Core.Found_new_MCN_0, newMcn));
updateStatus?.Invoke(string.Format(Localization.Core.Found_new_MCN_0, newMcn));
}
else if(mcn != newMcn)
{
dumpLog?.WriteLine(string.Format(Localization.Core.MCN_changed_from_0_to_1, mcn, newMcn));
dumpLog?.WriteLine(string.Format(Localization.Core.MCN_changed_from_0_to_1, mcn, newMcn));
updateStatus?.Invoke(string.Format(Localization.Core.MCN_changed_from_0_to_1, mcn, newMcn));
}
@@ -399,12 +405,13 @@ public static class CompactDisc
}
// Positioning
case 1 when !crcOk: continue;
case 1 when !crcOk:
continue;
case 1:
{
byte trackNo = (byte)((q[1] / 16 * 10) + (q[1] & 0x0F));
var trackNo = (byte)(q[1] / 16 * 10 + (q[1] & 0x0F));
for(int i = 0; i < tracks.Length; i++)
for(var i = 0; i < tracks.Length; i++)
{
if(tracks[i].Sequence != trackNo)
continue;
@@ -413,10 +420,10 @@ public static class CompactDisc
if(q[2] == 0 &&
trackNo > 1)
{
byte pmin = (byte)((q[3] / 16 * 10) + (q[3] & 0x0F));
byte psec = (byte)((q[4] / 16 * 10) + (q[4] & 0x0F));
byte pframe = (byte)((q[5] / 16 * 10) + (q[5] & 0x0F));
int qPos = (pmin * 60 * 75) + (psec * 75) + pframe;
var pmin = (byte)(q[3] / 16 * 10 + (q[3] & 0x0F));
var psec = (byte)(q[4] / 16 * 10 + (q[4] & 0x0F));
var pframe = (byte)(q[5] / 16 * 10 + (q[5] & 0x0F));
int qPos = pmin * 60 * 75 + psec * 75 + pframe;
// When we are dumping we calculate the pregap in reverse from index 1 back.
// When we are not, we go from index 0.
@@ -448,7 +455,7 @@ public static class CompactDisc
Invoke(string.Format(Localization.Core.Pregap_for_track_0_set_to_1_sectors, trackNo,
tracks[i].Pregap));
for(int p = 0; p < dif; p++)
for(var p = 0; p < dif; p++)
newPregapSectors.Add(tracks[i].StartSector + (ulong)p);
status = true;
@@ -472,7 +479,7 @@ public static class CompactDisc
updateStatus?.Invoke(string.Format(Localization.Core.Pregap_for_track_0_set_to_1_sectors,
trackNo, tracks[i].Pregap));
for(int p = 0; p < (int)(tracks[i].Pregap - oldPregap); p++)
for(var p = 0; p < (int)(tracks[i].Pregap - oldPregap); p++)
newPregapSectors.Add(tracks[i].StartSector + (ulong)p);
status = true;
@@ -483,10 +490,10 @@ public static class CompactDisc
if(q[2] == 0)
continue;
byte amin = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
byte asec = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
byte aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
int aPos = (amin * 60 * 75) + (asec * 75) + aframe - 150;
var amin = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
var asec = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
var aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
int aPos = amin * 60 * 75 + asec * 75 + aframe - 150;
// Do not set INDEX 1 to a value higher than what the TOC already said.
if(q[2] == 1 &&
@@ -527,105 +534,105 @@ public static class CompactDisc
rwPacket = false;
cdtextPacket = false;
byte[] cdTextPack1 = new byte[18];
byte[] cdTextPack2 = new byte[18];
byte[] cdTextPack3 = new byte[18];
byte[] cdTextPack4 = new byte[18];
byte[] cdSubRwPack1 = new byte[24];
byte[] cdSubRwPack2 = new byte[24];
byte[] cdSubRwPack3 = new byte[24];
byte[] cdSubRwPack4 = new byte[24];
var cdTextPack1 = new byte[18];
var cdTextPack2 = new byte[18];
var cdTextPack3 = new byte[18];
var cdTextPack4 = new byte[18];
var cdSubRwPack1 = new byte[24];
var cdSubRwPack2 = new byte[24];
var cdSubRwPack3 = new byte[24];
var cdSubRwPack4 = new byte[24];
int i = 0;
var i = 0;
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack1[j] = (byte)(cdTextPack1[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack1[j] = (byte)(cdTextPack1[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack1[j] = (byte)(cdTextPack1[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F));
cdTextPack1[j] = (byte)(cdTextPack1[j] | subchannel[i++] & 0x3F);
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack2[j] = (byte)(cdTextPack2[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack2[j] = (byte)(cdTextPack2[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack2[j] = (byte)(cdTextPack2[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F));
cdTextPack2[j] = (byte)(cdTextPack2[j] | subchannel[i++] & 0x3F);
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack3[j] = (byte)(cdTextPack3[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack3[j] = (byte)(cdTextPack3[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack3[j] = (byte)(cdTextPack3[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F));
cdTextPack3[j] = (byte)(cdTextPack3[j] | subchannel[i++] & 0x3F);
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack4[j] = (byte)(cdTextPack4[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack4[j] = (byte)(cdTextPack4[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack4[j] = (byte)(cdTextPack4[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x3F));
cdTextPack4[j] = (byte)(cdTextPack4[j] | subchannel[i++] & 0x3F);
}
i = 0;
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack1[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack2[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack3[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack4[j] = (byte)(subchannel[i++] & 0x3F);
switch(cdSubRwPack1[0])
@@ -726,95 +733,95 @@ public static class CompactDisc
/// <returns><c>true</c> if subchannel contains a TEXT packet, <c>false</c> otherwise</returns>
static bool CheckCdTextPackets(byte[] subchannel)
{
byte[] cdTextPack1 = new byte[18];
byte[] cdTextPack2 = new byte[18];
byte[] cdTextPack3 = new byte[18];
byte[] cdTextPack4 = new byte[18];
var cdTextPack1 = new byte[18];
var cdTextPack2 = new byte[18];
var cdTextPack3 = new byte[18];
var cdTextPack4 = new byte[18];
int i = 0;
var i = 0;
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack1[j] = (byte)(cdTextPack1[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack1[j] = (byte)(cdTextPack1[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack1[j] = (byte)(cdTextPack1[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack1[j] = (byte)(cdTextPack1[j] | (subchannel[i++] & 0x3F));
cdTextPack1[j] = (byte)(cdTextPack1[j] | subchannel[i++] & 0x3F);
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack2[j] = (byte)(cdTextPack2[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack2[j] = (byte)(cdTextPack2[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack2[j] = (byte)(cdTextPack2[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack2[j] = (byte)(cdTextPack2[j] | (subchannel[i++] & 0x3F));
cdTextPack2[j] = (byte)(cdTextPack2[j] | subchannel[i++] & 0x3F);
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack3[j] = (byte)(cdTextPack3[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack3[j] = (byte)(cdTextPack3[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack3[j] = (byte)(cdTextPack3[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack3[j] = (byte)(cdTextPack3[j] | (subchannel[i++] & 0x3F));
cdTextPack3[j] = (byte)(cdTextPack3[j] | subchannel[i++] & 0x3F);
}
for(int j = 0; j < 18; j++)
for(var j = 0; j < 18; j++)
{
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x3F) << 2));
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x3F) << 2);
cdTextPack4[j] = (byte)(cdTextPack4[j++] | ((subchannel[i] & 0xC0) >> 4));
cdTextPack4[j] = (byte)(cdTextPack4[j++] | (subchannel[i] & 0xC0) >> 4);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x0F) << 4));
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x0F) << 4);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j++] | ((subchannel[i] & 0x3C) >> 2));
cdTextPack4[j] = (byte)(cdTextPack4[j++] | (subchannel[i] & 0x3C) >> 2);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j] | ((subchannel[i++] & 0x03) << 6));
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x03) << 6);
if(j < 18)
cdTextPack4[j] = (byte)(cdTextPack4[j] | (subchannel[i++] & 0x3F));
cdTextPack4[j] = (byte)(cdTextPack4[j] | subchannel[i++] & 0x3F);
}
bool status = true;
var status = true;
if((cdTextPack1[0] & 0x80) == 0x80)
{
ushort cdTextPack1Crc = BigEndianBitConverter.ToUInt16(cdTextPack1, 16);
byte[] cdTextPack1ForCrc = new byte[16];
var cdTextPack1Crc = BigEndianBitConverter.ToUInt16(cdTextPack1, 16);
var cdTextPack1ForCrc = new byte[16];
Array.Copy(cdTextPack1, 0, cdTextPack1ForCrc, 0, 16);
ushort calculatedCdtp1Crc = CRC16CCITTContext.Calculate(cdTextPack1ForCrc);
@@ -825,8 +832,8 @@ public static class CompactDisc
if((cdTextPack2[0] & 0x80) == 0x80)
{
ushort cdTextPack2Crc = BigEndianBitConverter.ToUInt16(cdTextPack2, 16);
byte[] cdTextPack2ForCrc = new byte[16];
var cdTextPack2Crc = BigEndianBitConverter.ToUInt16(cdTextPack2, 16);
var cdTextPack2ForCrc = new byte[16];
Array.Copy(cdTextPack2, 0, cdTextPack2ForCrc, 0, 16);
ushort calculatedCdtp2Crc = CRC16CCITTContext.Calculate(cdTextPack2ForCrc);
@@ -837,8 +844,8 @@ public static class CompactDisc
if((cdTextPack3[0] & 0x80) == 0x80)
{
ushort cdTextPack3Crc = BigEndianBitConverter.ToUInt16(cdTextPack3, 16);
byte[] cdTextPack3ForCrc = new byte[16];
var cdTextPack3Crc = BigEndianBitConverter.ToUInt16(cdTextPack3, 16);
var cdTextPack3ForCrc = new byte[16];
Array.Copy(cdTextPack3, 0, cdTextPack3ForCrc, 0, 16);
ushort calculatedCdtp3Crc = CRC16CCITTContext.Calculate(cdTextPack3ForCrc);
@@ -850,8 +857,8 @@ public static class CompactDisc
if((cdTextPack4[0] & 0x80) != 0x80)
return status;
ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
byte[] cdTextPack4ForCrc = new byte[16];
var cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
var cdTextPack4ForCrc = new byte[16];
Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16);
ushort calculatedCdtp4Crc = CRC16CCITTContext.Calculate(cdTextPack4ForCrc);
@@ -880,10 +887,10 @@ public static class CompactDisc
/// <param name="fixedMcn">Set to <c>true</c> if we fixed the MCN, <c>false</c> otherwise</param>
/// <param name="fixedIsrc">Set to <c>true</c> if we fixed the ISRC, <c>false</c> otherwise</param>
/// <returns><c>true</c> if it was fixed correctly, <c>false</c> otherwise</returns>
static bool FixQSubchannel(byte[] deSub, byte[] q, int subPos, string mcn, string isrc, bool fixCrc,
out bool fixedAdr, out bool controlFix, out bool fixedZero, out bool fixedTno,
static bool FixQSubchannel(byte[] deSub, byte[] q, int subPos, string mcn, string isrc, bool fixCrc,
out bool fixedAdr, out bool controlFix, out bool fixedZero, out bool fixedTno,
out bool fixedIndex, out bool fixedRelPos, out bool fixedAbsPos, out bool fixedCrc,
out bool fixedMcn, out bool fixedIsrc)
out bool fixedMcn, out bool fixedIsrc)
{
byte aframe;
byte rframe;
@@ -897,9 +904,9 @@ public static class CompactDisc
fixedMcn = false;
fixedIsrc = false;
byte[] preQ = new byte[12];
byte[] nextQ = new byte[12];
Array.Copy(deSub, subPos + 12 - 96, preQ, 0, 12);
var preQ = new byte[12];
var nextQ = new byte[12];
Array.Copy(deSub, subPos + 12 - 96, preQ, 0, 12);
Array.Copy(deSub, subPos + 12 + 96, nextQ, 0, 12);
CRC16CCITTContext.Data(preQ, 10, out byte[] preCrc);
@@ -1030,6 +1037,7 @@ public static class CompactDisc
}
if(preCrcOk && nextCrcOk)
{
if(preQ[1] == nextQ[1] &&
preQ[1] != q[1])
{
@@ -1042,8 +1050,10 @@ public static class CompactDisc
if(status)
return true;
}
}
if(preCrcOk && nextCrcOk)
{
if(preQ[2] == nextQ[2] &&
preQ[2] != q[2])
{
@@ -1056,16 +1066,17 @@ public static class CompactDisc
if(status)
return true;
}
}
byte amin = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
byte asec = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
int aPos = (amin * 60 * 75) + (asec * 75) + aframe - 150;
var amin = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
var asec = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
int aPos = amin * 60 * 75 + asec * 75 + aframe - 150;
byte pmin = (byte)((q[3] / 16 * 10) + (q[3] & 0x0F));
byte psec = (byte)((q[4] / 16 * 10) + (q[4] & 0x0F));
byte pframe = (byte)((q[5] / 16 * 10) + (q[5] & 0x0F));
int pPos = (pmin * 60 * 75) + (psec * 75) + pframe;
var pmin = (byte)(q[3] / 16 * 10 + (q[3] & 0x0F));
var psec = (byte)(q[4] / 16 * 10 + (q[4] & 0x0F));
var pframe = (byte)(q[5] / 16 * 10 + (q[5] & 0x0F));
int pPos = pmin * 60 * 75 + psec * 75 + pframe;
// TODO: pregap
// Not pregap
@@ -1082,10 +1093,10 @@ public static class CompactDisc
// Previous was not pregap either
if(preQ[2] > 0 && preCrcOk)
{
rmin = (byte)((preQ[3] / 16 * 10) + (preQ[3] & 0x0F));
rsec = (byte)((preQ[4] / 16 * 10) + (preQ[4] & 0x0F));
rframe = (byte)((preQ[5] / 16 * 10) + (preQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(preQ[3] / 16 * 10 + (preQ[3] & 0x0F));
rsec = (byte)(preQ[4] / 16 * 10 + (preQ[4] & 0x0F));
rframe = (byte)(preQ[5] / 16 * 10 + (preQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = pPos - rPos;
@@ -1139,10 +1150,10 @@ public static class CompactDisc
nextCrcOk &&
!fixedRelPos)
{
rmin = (byte)((nextQ[3] / 16 * 10) + (nextQ[3] & 0x0F));
rsec = (byte)((nextQ[4] / 16 * 10) + (nextQ[4] & 0x0F));
rframe = (byte)((nextQ[5] / 16 * 10) + (nextQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(nextQ[3] / 16 * 10 + (nextQ[3] & 0x0F));
rsec = (byte)(nextQ[4] / 16 * 10 + (nextQ[4] & 0x0F));
rframe = (byte)(nextQ[5] / 16 * 10 + (nextQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = rPos - pPos;
@@ -1199,10 +1210,10 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rmin = (byte)((preQ[7] / 16 * 10) + (preQ[7] & 0x0F));
rsec = (byte)((preQ[8] / 16 * 10) + (preQ[8] & 0x0F));
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(preQ[7] / 16 * 10 + (preQ[7] & 0x0F));
rsec = (byte)(preQ[8] / 16 * 10 + (preQ[8] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = aPos - rPos;
@@ -1256,10 +1267,10 @@ public static class CompactDisc
nextCrcOk &&
!fixedAbsPos)
{
rmin = (byte)((nextQ[7] / 16 * 10) + (nextQ[7] & 0x0F));
rsec = (byte)((nextQ[8] / 16 * 10) + (nextQ[8] & 0x0F));
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(nextQ[7] / 16 * 10 + (nextQ[7] & 0x0F));
rsec = (byte)(nextQ[8] / 16 * 10 + (nextQ[8] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = rPos - pPos;
@@ -1322,19 +1333,19 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rmin = (byte)((preQ[7] / 16 * 10) + (preQ[7] & 0x0F));
rsec = (byte)((preQ[8] / 16 * 10) + (preQ[8] & 0x0F));
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(preQ[7] / 16 * 10 + (preQ[7] & 0x0F));
rsec = (byte)(preQ[8] / 16 * 10 + (preQ[8] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = aPos - rPos;
bool absOk = dPos == 1;
rmin = (byte)((preQ[3] / 16 * 10) + (preQ[3] & 0x0F));
rsec = (byte)((preQ[4] / 16 * 10) + (preQ[4] & 0x0F));
rframe = (byte)((preQ[5] / 16 * 10) + (preQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(preQ[3] / 16 * 10 + (preQ[3] & 0x0F));
rsec = (byte)(preQ[4] / 16 * 10 + (preQ[4] & 0x0F));
rframe = (byte)(preQ[5] / 16 * 10 + (preQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = pPos - rPos;
@@ -1360,19 +1371,19 @@ public static class CompactDisc
// Next Q's CRC is correct
if(nextCrcOk)
{
rmin = (byte)((nextQ[7] / 16 * 10) + (nextQ[7] & 0x0F));
rsec = (byte)((nextQ[8] / 16 * 10) + (nextQ[8] & 0x0F));
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe - 150;
rmin = (byte)(nextQ[7] / 16 * 10 + (nextQ[7] & 0x0F));
rsec = (byte)(nextQ[8] / 16 * 10 + (nextQ[8] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe - 150;
dPos = rPos - aPos;
bool absOk = dPos == 1;
rmin = (byte)((nextQ[3] / 16 * 10) + (nextQ[3] & 0x0F));
rsec = (byte)((nextQ[4] / 16 * 10) + (nextQ[4] & 0x0F));
rframe = (byte)((nextQ[5] / 16 * 10) + (nextQ[5] & 0x0F));
rPos = (rmin * 60 * 75) + (rsec * 75) + rframe;
rmin = (byte)(nextQ[3] / 16 * 10 + (nextQ[3] & 0x0F));
rsec = (byte)(nextQ[4] / 16 * 10 + (nextQ[4] & 0x0F));
rframe = (byte)(nextQ[5] / 16 * 10 + (nextQ[5] & 0x0F));
rPos = rmin * 60 * 75 + rsec * 75 + rframe;
dPos = rPos - pPos;
@@ -1405,8 +1416,8 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1433,8 +1444,8 @@ public static class CompactDisc
// Next Q's CRC is correct
else if(nextCrcOk)
{
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1460,13 +1471,13 @@ public static class CompactDisc
// We know the MCN
if(mcn != null)
{
q[1] = (byte)((((mcn[0] - 0x30) & 0x0F) * 16) + ((mcn[1] - 0x30) & 0x0F));
q[2] = (byte)((((mcn[2] - 0x30) & 0x0F) * 16) + ((mcn[3] - 0x30) & 0x0F));
q[3] = (byte)((((mcn[4] - 0x30) & 0x0F) * 16) + ((mcn[5] - 0x30) & 0x0F));
q[4] = (byte)((((mcn[6] - 0x30) & 0x0F) * 16) + ((mcn[7] - 0x30) & 0x0F));
q[5] = (byte)((((mcn[8] - 0x30) & 0x0F) * 16) + ((mcn[9] - 0x30) & 0x0F));
q[6] = (byte)((((mcn[10] - 0x30) & 0x0F) * 16) + ((mcn[11] - 0x30) & 0x0F));
q[7] = (byte)(((mcn[12] - 0x30) & 0x0F) * 8);
q[1] = (byte)((mcn[0] - 0x30 & 0x0F) * 16 + (mcn[1] - 0x30 & 0x0F));
q[2] = (byte)((mcn[2] - 0x30 & 0x0F) * 16 + (mcn[3] - 0x30 & 0x0F));
q[3] = (byte)((mcn[4] - 0x30 & 0x0F) * 16 + (mcn[5] - 0x30 & 0x0F));
q[4] = (byte)((mcn[6] - 0x30 & 0x0F) * 16 + (mcn[7] - 0x30 & 0x0F));
q[5] = (byte)((mcn[8] - 0x30 & 0x0F) * 16 + (mcn[9] - 0x30 & 0x0F));
q[6] = (byte)((mcn[10] - 0x30 & 0x0F) * 16 + (mcn[11] - 0x30 & 0x0F));
q[7] = (byte)((mcn[12] - 0x30 & 0x0F) * 8);
q[8] = 0;
fixedMcn = true;
@@ -1498,8 +1509,8 @@ public static class CompactDisc
// Previous Q's CRC is correct
if(preCrcOk)
{
rframe = (byte)((preQ[9] / 16 * 10) + (preQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(preQ[9] / 16 * 10 + (preQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1526,8 +1537,8 @@ public static class CompactDisc
// Next Q's CRC is correct
else if(nextCrcOk)
{
rframe = (byte)((nextQ[9] / 16 * 10) + (nextQ[9] & 0x0F));
aframe = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
rframe = (byte)(nextQ[9] / 16 * 10 + (nextQ[9] & 0x0F));
aframe = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
if(aframe - rframe != 1)
{
@@ -1563,10 +1574,10 @@ public static class CompactDisc
q[2] = (byte)(((i2 & 0xF) << 4) + (i3 >> 2));
q[3] = (byte)(((i3 & 0x3) << 6) + i4);
q[4] = (byte)(i5 << 2);
q[5] = (byte)((((isrc[5] - 0x30) & 0x0F) * 16) + ((isrc[6] - 0x30) & 0x0F));
q[6] = (byte)((((isrc[7] - 0x30) & 0x0F) * 16) + ((isrc[8] - 0x30) & 0x0F));
q[7] = (byte)((((isrc[9] - 0x30) & 0x0F) * 16) + ((isrc[10] - 0x30) & 0x0F));
q[8] = (byte)(((isrc[11] - 0x30) & 0x0F) * 16);
q[5] = (byte)((isrc[5] - 0x30 & 0x0F) * 16 + (isrc[6] - 0x30 & 0x0F));
q[6] = (byte)((isrc[7] - 0x30 & 0x0F) * 16 + (isrc[8] - 0x30 & 0x0F));
q[7] = (byte)((isrc[9] - 0x30 & 0x0F) * 16 + (isrc[10] - 0x30 & 0x0F));
q[8] = (byte)((isrc[11] - 0x30 & 0x0F) * 16);
fixedIsrc = true;
@@ -1606,11 +1617,11 @@ public static class CompactDisc
/// <param name="updateProgress">Progress update callback</param>
/// <param name="endProgress">Progress finalization callback</param>
/// <param name="outputPlugin">Output image</param>
public static void GenerateSubchannels(HashSet<int> subchannelExtents, Track[] tracks,
Dictionary<byte, byte> trackFlags, ulong blocks, SubchannelLog subLog,
DumpLog dumpLog, InitProgressHandler initProgress,
UpdateProgressHandler updateProgress, EndProgressHandler endProgress,
IWritableImage outputPlugin)
public static void GenerateSubchannels(HashSet<int> subchannelExtents, Track[] tracks,
Dictionary<byte, byte> trackFlags, ulong blocks, SubchannelLog subLog,
DumpLog dumpLog, InitProgressHandler initProgress,
UpdateProgressHandler updateProgress, EndProgressHandler endProgress,
IWritableImage outputPlugin)
{
initProgress?.Invoke();

View File

@@ -80,16 +80,10 @@ public static class MMC
0x50, 0x6C, 0x61, 0x79, 0x53, 0x74, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x35, 0x00, 0x00, 0x00, 0x00
};
static readonly byte[] _operaId =
{
0x01, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x01
};
static readonly byte[] _operaId = { 0x01, 0x5A, 0x5A, 0x5A, 0x5A, 0x5A, 0x01 };
// Only present on bootable CDs, but those make more than 99% of all available
static readonly byte[] _fmTownsBootId =
{
0x49, 0x50, 0x4C, 0x34, 0xEB, 0x55, 0x06
};
static readonly byte[] _fmTownsBootId = { 0x49, 0x50, 0x4C, 0x34, 0xEB, 0x55, 0x06 };
/// <summary>Present on first two seconds of second track, says "COPYRIGHT BANDAI"</summary>
static readonly byte[] _playdiaCopyright = "COPYRIGHT BANDAI"u8.ToArray();
@@ -131,12 +125,9 @@ public static class MMC
if(sector?.Length != 2352)
return false;
byte[] syncMark =
{
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00
};
byte[] syncMark = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
byte[] testMark = new byte[12];
var testMark = new byte[12];
Array.Copy(sector, 0, testMark, 0, 12);
return syncMark.SequenceEqual(testMark) && (sector[0xF] == 0 || sector[0xF] == 1 || sector[0xF] == 2);
@@ -149,19 +140,16 @@ public static class MMC
if(sector?.Length != 2352)
return false;
byte[] syncMark =
{
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00
};
byte[] syncMark = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
byte[] testMark = new byte[12];
var testMark = new byte[12];
for(int i = 0; i <= 2336; i++)
for(var i = 0; i <= 2336; i++)
{
Array.Copy(sector, i, testMark, 0, 12);
if(!syncMark.SequenceEqual(testMark) ||
(sector[i + 0xF] != 0x60 && sector[i + 0xF] != 0x61 && sector[i + 0xF] != 0x62))
sector[i + 0xF] != 0x60 && sector[i + 0xF] != 0x61 && sector[i + 0xF] != 0x62)
continue;
// De-scramble M and S
@@ -170,17 +158,17 @@ public static class MMC
int frame = sector[i + 14];
// Convert to binary
minute = (minute / 16 * 10) + (minute & 0x0F);
second = (second / 16 * 10) + (second & 0x0F);
frame = (frame / 16 * 10) + (frame & 0x0F);
minute = minute / 16 * 10 + (minute & 0x0F);
second = second / 16 * 10 + (second & 0x0F);
frame = frame / 16 * 10 + (frame & 0x0F);
// Calculate the first found LBA
int lba = (minute * 60 * 75) + (second * 75) + frame - 150;
int lba = minute * 60 * 75 + second * 75 + frame - 150;
// Calculate the difference between the found LBA and the requested one
int diff = wantedLba - lba;
offset = i + (2352 * diff);
offset = i + 2352 * diff;
return true;
}
@@ -190,9 +178,9 @@ public static class MMC
static byte[] DescrambleAndFixOffset(byte[] sector, int offsetBytes, int sectorsForOffset)
{
byte[] descrambled = new byte[2352];
var descrambled = new byte[2352];
int offsetFix = offsetBytes < 0 ? (2352 * sectorsForOffset) + offsetBytes : offsetBytes;
int offsetFix = offsetBytes < 0 ? 2352 * sectorsForOffset + offsetBytes : offsetBytes;
Array.Copy(sector, offsetFix, descrambled, 0, 2352);
@@ -208,18 +196,15 @@ public static class MMC
if(sector16?.Length != 2352)
return false;
byte[] cdiMark =
{
0x01, 0x43, 0x44, 0x2D
};
byte[] cdiMark = { 0x01, 0x43, 0x44, 0x2D };
bool isData = IsData(sector0);
if(!isData ||
(sector0[0xF] != 2 && sector0[0xF] != 1))
sector0[0xF] != 2 && sector0[0xF] != 1)
return false;
byte[] testMark = new byte[4];
var testMark = new byte[4];
Array.Copy(sector16, 24, testMark, 0, 4);
return cdiMark.SequenceEqual(testMark);
@@ -231,13 +216,13 @@ public static class MMC
videoFrame.Length < _videoNowColorFrameMarker.Length)
return false;
byte[] buffer = new byte[_videoNowColorFrameMarker.Length];
var buffer = new byte[_videoNowColorFrameMarker.Length];
for(int framePosition = 0; framePosition + buffer.Length < videoFrame.Length; framePosition++)
for(var framePosition = 0; framePosition + buffer.Length < videoFrame.Length; framePosition++)
{
Array.Copy(videoFrame, framePosition, buffer, 0, buffer.Length);
for(int ab = 9; ab < buffer.Length; ab += 10)
for(var ab = 9; ab < buffer.Length; ab += 10)
buffer[ab] = 0;
if(!_videoNowColorFrameMarker.SequenceEqual(buffer))
@@ -251,13 +236,13 @@ public static class MMC
internal static int GetVideoNowColorOffset(byte[] data)
{
byte[] buffer = new byte[_videoNowColorFrameMarker.Length];
var buffer = new byte[_videoNowColorFrameMarker.Length];
for(int framePosition = 0; framePosition + buffer.Length < data.Length; framePosition++)
for(var framePosition = 0; framePosition + buffer.Length < data.Length; framePosition++)
{
Array.Copy(data, framePosition, buffer, 0, buffer.Length);
for(int ab = 9; ab < buffer.Length; ab += 10)
for(var ab = 9; ab < buffer.Length; ab += 10)
buffer[ab] = 0;
if(!_videoNowColorFrameMarker.SequenceEqual(buffer))
@@ -270,8 +255,8 @@ public static class MMC
}
internal static void DetectDiscType(ref MediaType mediaType, int sessions, FullTOC.CDFullTOC? decodedToc,
Device dev, out bool hiddenTrack, out bool hiddenData,
int firstTrackLastSession, ulong blocks)
Device dev, out bool hiddenTrack, out bool hiddenData,
int firstTrackLastSession, ulong blocks)
{
uint startOfFirstDataTrack = uint.MaxValue;
DI.DiscInformation? blurayDi = null;
@@ -420,8 +405,10 @@ public static class MMC
}
if(decodedToc?.TrackDescriptors.Any(t => t.SessionNumber == 2) == true)
{
secondSessionFirstTrack = decodedToc.Value.TrackDescriptors.Where(t => t.SessionNumber == 2).
Min(t => t.POINT);
}
if(mediaType is MediaType.CD or MediaType.CDROMXA or MediaType.CDI)
{
@@ -440,10 +427,10 @@ public static class MMC
if(mediaType is MediaType.CD or MediaType.CDROMXA)
{
bool hasDataTrack = false;
bool hasAudioTrack = false;
bool allFirstSessionTracksAreAudio = true;
bool hasVideoTrack = false;
var hasDataTrack = false;
var hasAudioTrack = false;
var allFirstSessionTracksAreAudio = true;
var hasVideoTrack = false;
if(decodedToc.HasValue)
{
@@ -451,6 +438,7 @@ public static class MMC
decodedToc.Value.TrackDescriptors.FirstOrDefault(t => t is { POINT: 0xA0, ADR: 1 });
if(a0Track.POINT == 0xA0)
{
switch(a0Track.PSEC)
{
case 0x10:
@@ -466,6 +454,7 @@ public static class MMC
break;
}
}
foreach(FullTOC.TrackDataDescriptor track in
decodedToc.Value.TrackDescriptors.Where(t => t.POINT is > 0 and <= 0x99))
@@ -478,8 +467,8 @@ public static class MMC
if((TocControl)(track.CONTROL & 0x0D) == TocControl.DataTrack ||
(TocControl)(track.CONTROL & 0x0D) == TocControl.DataTrackIncremental)
{
uint startAddress = (uint)((track.PHOUR * 3600 * 75) + (track.PMIN * 60 * 75) +
(track.PSEC * 75) + track.PFRAME - 150);
var startAddress = (uint)(track.PHOUR * 3600 * 75 + track.PMIN * 60 * 75 +
track.PSEC * 75 + track.PFRAME - 150);
if(startAddress < startOfFirstDataTrack)
startOfFirstDataTrack = startAddress;
@@ -536,15 +525,16 @@ public static class MMC
}
if(mediaType is MediaType.CD or MediaType.CDROM && hasDataTrack)
{
foreach(uint startAddress in decodedToc.Value.TrackDescriptors.
Where(t => t.POINT is > 0 and <= 0x99 &&
((TocControl)(t.CONTROL & 0x0D) ==
TocControl.DataTrack ||
(TocControl)(t.CONTROL & 0x0D) ==
TocControl.DataTrackIncremental)).
Select(track => (uint)((track.PHOUR * 3600 * 75) +
(track.PMIN * 60 * 75) +
(track.PSEC * 75) + track.PFRAME - 150) +
Select(track => (uint)(track.PHOUR * 3600 * 75 +
track.PMIN * 60 * 75 +
track.PSEC * 75 + track.PFRAME - 150) +
16))
{
sense = dev.ReadCd(out cmdBuf, out _, startAddress, 2352, 1, MmcSectorTypes.AllTypes, false, false,
@@ -576,6 +566,7 @@ public static class MMC
break;
}
}
}
if(secondSessionFirstTrack != 0 &&
@@ -584,10 +575,10 @@ public static class MMC
FullTOC.TrackDataDescriptor secondSessionFirstTrackTrack =
decodedToc.Value.TrackDescriptors.First(t => t.POINT == secondSessionFirstTrack);
uint firstSectorSecondSessionFirstTrack = (uint)((secondSessionFirstTrackTrack.PHOUR * 3600 * 75) +
(secondSessionFirstTrackTrack.PMIN * 60 * 75) +
(secondSessionFirstTrackTrack.PSEC * 75) +
secondSessionFirstTrackTrack.PFRAME - 150);
var firstSectorSecondSessionFirstTrack = (uint)(secondSessionFirstTrackTrack.PHOUR * 3600 * 75 +
secondSessionFirstTrackTrack.PMIN * 60 * 75 +
secondSessionFirstTrackTrack.PSEC * 75 +
secondSessionFirstTrackTrack.PFRAME - 150);
sense = dev.ReadCd(out cmdBuf, out _, firstSectorSecondSessionFirstTrack, 2352, 1, MmcSectorTypes.AllTypes,
false, false, true, MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None,
@@ -628,7 +619,7 @@ public static class MMC
videoNowColorFrame = new byte[9 * 2352];
for(int i = 0; i < 9; i++)
for(var i = 0; i < 9; i++)
{
sense = dev.ReadCd(out cmdBuf, out _, (uint)i, 2352, 1, MmcSectorTypes.AllTypes, false, false, true,
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None,
@@ -657,8 +648,8 @@ public static class MMC
if(firstTrack?.POINT is >= 1 and < 0xA0)
{
uint firstTrackSector = (uint)((firstTrack.Value.PHOUR * 3600 * 75) + (firstTrack.Value.PMIN * 60 * 75) +
(firstTrack.Value.PSEC * 75) + firstTrack.Value.PFRAME - 150);
var firstTrackSector = (uint)(firstTrack.Value.PHOUR * 3600 * 75 + firstTrack.Value.PMIN * 60 * 75 +
firstTrack.Value.PSEC * 75 + firstTrack.Value.PFRAME - 150);
// Check for hidden data before start of track 1
if(firstTrackSector > 0)
@@ -705,8 +696,8 @@ public static class MMC
if(combinedOffset % 2352 != 0)
sectorsForOffset++;
int lba0 = 0;
int lba16 = 16;
var lba0 = 0;
var lba16 = 16;
if(combinedOffset < 0)
{
@@ -988,7 +979,8 @@ public static class MMC
}
// TODO: Check for CD-i Ready
case MediaType.CDI: break;
case MediaType.CDI:
break;
case MediaType.DVDROM:
case MediaType.HDDVDROM:
case MediaType.BDROM:
@@ -1111,24 +1103,31 @@ public static class MMC
PFI.PhysicalFormatInformation? pfi = PFI.Decode(cmdBuf, mediaType);
if(pfi != null)
{
mediaType = pfi.Value.DiskCategory switch
{
DiskCategory.DVDPR => MediaType.DVDPR,
DiskCategory.DVDPRDL => MediaType.DVDPRDL,
DiskCategory.DVDPRW => MediaType.DVDPRW,
DiskCategory.DVDPRWDL => MediaType.DVDPRWDL,
DiskCategory.DVDR => pfi.Value.PartVersion >= 6 ? MediaType.DVDRDL : MediaType.DVDR,
DiskCategory.DVDRAM => MediaType.DVDRAM,
DiskCategory.DVDRW => pfi.Value.PartVersion >= 15 ? MediaType.DVDRWDL : MediaType.DVDRW,
DiskCategory.HDDVDR => MediaType.HDDVDR,
DiskCategory.HDDVDRAM => MediaType.HDDVDRAM,
DiskCategory.HDDVDROM => MediaType.HDDVDROM,
DiskCategory.HDDVDRW => MediaType.HDDVDRW,
DiskCategory.Nintendo => pfi.Value.DiscSize == DVDSize.Eighty ? MediaType.GOD
: MediaType.WOD,
DiskCategory.UMD => MediaType.UMD,
_ => mediaType
};
{
DiskCategory.DVDPR => MediaType.DVDPR,
DiskCategory.DVDPRDL => MediaType.DVDPRDL,
DiskCategory.DVDPRW => MediaType.DVDPRW,
DiskCategory.DVDPRWDL => MediaType.DVDPRWDL,
DiskCategory.DVDR => pfi.Value.PartVersion >= 6
? MediaType.DVDRDL
: MediaType.DVDR,
DiskCategory.DVDRAM => MediaType.DVDRAM,
DiskCategory.DVDRW => pfi.Value.PartVersion >= 15
? MediaType.DVDRWDL
: MediaType.DVDRW,
DiskCategory.HDDVDR => MediaType.HDDVDR,
DiskCategory.HDDVDRAM => MediaType.HDDVDRAM,
DiskCategory.HDDVDROM => MediaType.HDDVDROM,
DiskCategory.HDDVDRW => MediaType.HDDVDRW,
DiskCategory.Nintendo => pfi.Value.DiscSize == DVDSize.Eighty
? MediaType.GOD
: MediaType.WOD,
DiskCategory.UMD => MediaType.UMD,
_ => mediaType
};
}
}
sense = dev.ReadDiscStructure(out cmdBuf, out _, MmcDiscStructureMediaType.Dvd, 0, 0,
@@ -1224,8 +1223,8 @@ public static class MMC
isoSector[5] != 0x31)
return;
uint rootStart = BitConverter.ToUInt32(isoSector, 158);
uint rootLength = BitConverter.ToUInt32(isoSector, 166);
var rootStart = BitConverter.ToUInt32(isoSector, 158);
var rootLength = BitConverter.ToUInt32(isoSector, 166);
if(rootStart == 0 ||
rootLength == 0)
@@ -1258,7 +1257,7 @@ public static class MMC
if(isoSector.Length < 2048)
return;
int rootPos = 0;
var rootPos = 0;
uint pcdStart = 0;
uint pcdLength = 0;
@@ -1266,8 +1265,8 @@ public static class MMC
rootPos < isoSector.Length &&
rootPos + isoSector[rootPos] <= isoSector.Length)
{
int nameLen = isoSector[rootPos + 32];
byte[] tmpName = new byte[nameLen];
int nameLen = isoSector[rootPos + 32];
var tmpName = new byte[nameLen];
Array.Copy(isoSector, rootPos + 33, tmpName, 0, nameLen);
string name = StringHandlers.CToString(tmpName).ToUpperInvariant();
@@ -1311,7 +1310,7 @@ public static class MMC
if(isoSector.Length < 2048)
return;
for(int pi = 0; pi < pcdLength; pi++)
for(var pi = 0; pi < pcdLength; pi++)
{
int pcdPos = pi * 2048;
uint infoPos = 0;
@@ -1320,8 +1319,8 @@ public static class MMC
pcdPos < isoSector.Length &&
pcdPos + isoSector[pcdPos] <= isoSector.Length)
{
int nameLen = isoSector[pcdPos + 32];
byte[] tmpName = new byte[nameLen];
int nameLen = isoSector[pcdPos + 32];
var tmpName = new byte[nameLen];
Array.Copy(isoSector, pcdPos + 33, tmpName, 0, nameLen);
string name = StringHandlers.CToString(tmpName).ToUpperInvariant();
@@ -1346,7 +1345,7 @@ public static class MMC
if(sense)
break;
byte[] systemId = new byte[8];
var systemId = new byte[8];
Array.Copy(isoSector, 0, systemId, 0, 8);
string id = StringHandlers.CToString(systemId).TrimEnd();
@@ -1390,7 +1389,8 @@ public static class MMC
case MediaType.BDR:
case MediaType.BDRE:
case MediaType.BDRXL:
case MediaType.BDREXL: return;
case MediaType.BDREXL:
return;
}
if(sector0 == null)
@@ -1438,7 +1438,7 @@ public static class MMC
// The decryption key is applied as XOR. As first byte is originally always NULL, it gives us the key :)
byte decryptByte = ps2BootSectors[0];
for(int i = 0; i < 0x6000; i++)
for(var i = 0; i < 0x6000; i++)
ps2BootSectors[i] ^= decryptByte;
string ps2BootSectorsHash = Sha256Context.Data(ps2BootSectors, out _);
@@ -1460,7 +1460,7 @@ public static class MMC
if(sector0 != null)
{
byte[] syncBytes = new byte[7];
var syncBytes = new byte[7];
Array.Copy(sector0, 0, syncBytes, 0, 7);
if(_operaId.SequenceEqual(syncBytes))
@@ -1485,11 +1485,11 @@ public static class MMC
if(playdia1 != null &&
playdia2 != null)
{
byte[] pd1 = new byte[_playdiaCopyright.Length];
byte[] pd2 = new byte[_playdiaCopyright.Length];
var pd1 = new byte[_playdiaCopyright.Length];
var pd2 = new byte[_playdiaCopyright.Length];
Array.Copy(playdia1, 38, pd1, 0, pd1.Length);
Array.Copy(playdia2, 0, pd2, 0, pd1.Length);
Array.Copy(playdia2, 0, pd2, 0, pd1.Length);
if(_playdiaCopyright.SequenceEqual(pd1) &&
_playdiaCopyright.SequenceEqual(pd2))
@@ -1504,7 +1504,7 @@ public static class MMC
if(secondDataSectorNotZero != null)
{
byte[] pce = new byte[_pcEngineSignature.Length];
var pce = new byte[_pcEngineSignature.Length];
Array.Copy(secondDataSectorNotZero, 32, pce, 0, pce.Length);
if(_pcEngineSignature.SequenceEqual(pce))
@@ -1519,7 +1519,7 @@ public static class MMC
if(firstDataSectorNotZero != null)
{
byte[] pcfx = new byte[_pcFxSignature.Length];
var pcfx = new byte[_pcFxSignature.Length];
Array.Copy(firstDataSectorNotZero, 0, pcfx, 0, pcfx.Length);
if(_pcFxSignature.SequenceEqual(pcfx))
@@ -1534,9 +1534,9 @@ public static class MMC
if(firstTrackSecondSessionAudio != null)
{
byte[] jaguar = new byte[_atariSignature.Length];
var jaguar = new byte[_atariSignature.Length];
for(int i = 0; i + jaguar.Length <= firstTrackSecondSessionAudio.Length; i += 2)
for(var i = 0; i + jaguar.Length <= firstTrackSecondSessionAudio.Length; i += 2)
{
Array.Copy(firstTrackSecondSessionAudio, i, jaguar, 0, jaguar.Length);
@@ -1553,7 +1553,7 @@ public static class MMC
if(firstTrackSecondSession?.Length >= 2336)
{
byte[] milcd = new byte[2048];
var milcd = new byte[2048];
Array.Copy(firstTrackSecondSession, 24, milcd, 0, 2048);
if(Dreamcast.DecodeIPBin(milcd).HasValue)
@@ -1587,13 +1587,13 @@ public static class MMC
if(!sense)
{
bool cdg = false;
bool cdeg = false;
bool cdmidi = false;
var cdg = false;
var cdeg = false;
var cdmidi = false;
for(int i = 0; i < 8; i++)
for(var i = 0; i < 8; i++)
{
byte[] tmpSub = new byte[96];
var tmpSub = new byte[96];
Array.Copy(subBuf, i * 96, tmpSub, 0, 96);
DetectRwPackets(tmpSub, out bool cdgPacket, out bool cdegPacket, out bool cdmidiPacket);
@@ -1638,7 +1638,7 @@ public static class MMC
}
// If it has a PS2 boot area it can still be PS1, so check for SYSTEM.CNF below
hasPs2CdBoot:
hasPs2CdBoot:
// Check if ISO9660
sense = dev.Read12(out byte[] isoSector, out _, 0, false, false, false, false, 16, 2048, 0, 1, false,
@@ -1690,8 +1690,8 @@ public static class MMC
isoSector[5] != 0x31)
return;
uint rootStart = BitConverter.ToUInt32(isoSector, 158);
uint rootLength = BitConverter.ToUInt32(isoSector, 166);
var rootStart = BitConverter.ToUInt32(isoSector, 158);
var rootLength = BitConverter.ToUInt32(isoSector, 166);
if(rootStart == 0 ||
rootLength == 0)
@@ -1734,7 +1734,7 @@ public static class MMC
uint ps1Start = 0;
uint ps1Length = 0;
for(int ri = 0; ri < rootLength; ri++)
for(var ri = 0; ri < rootLength; ri++)
{
int rootPos = ri * 2048;
@@ -1742,8 +1742,8 @@ public static class MMC
isoSector[rootPos] > 0 &&
rootPos + isoSector[rootPos] <= isoSector.Length)
{
int nameLen = isoSector[rootPos + 32];
byte[] tmpName = new byte[nameLen];
int nameLen = isoSector[rootPos + 32];
var tmpName = new byte[nameLen];
Array.Copy(isoSector, rootPos + 33, tmpName, 0, nameLen);
string name = StringHandlers.CToString(tmpName).ToUpperInvariant();
@@ -1843,8 +1843,8 @@ public static class MMC
{
using var sr = new StringReader(iplTxt);
bool correctNeoGeoCd = true;
int lineNumber = 0;
var correctNeoGeoCd = true;
var lineNumber = 0;
while(sr.Peek() > 0)
{
@@ -1977,7 +1977,7 @@ public static class MMC
uint infoPos = 0;
for(int vi = 0; vi < vcdLength; vi++)
for(var vi = 0; vi < vcdLength; vi++)
{
int vcdPos = vi * 2048;
@@ -1985,8 +1985,8 @@ public static class MMC
isoSector[vcdPos] > 0 &&
vcdPos + isoSector[vcdPos] <= isoSector.Length)
{
int nameLen = isoSector[vcdPos + 32];
byte[] tmpName = new byte[nameLen];
int nameLen = isoSector[vcdPos + 32];
var tmpName = new byte[nameLen];
Array.Copy(isoSector, vcdPos + 33, tmpName, 0, nameLen);
string name = StringHandlers.CToString(tmpName).ToUpperInvariant();
@@ -2012,7 +2012,7 @@ public static class MMC
if(sense)
break;
byte[] systemId = new byte[8];
var systemId = new byte[8];
Array.Copy(isoSector, 0, systemId, 0, 8);
string id = StringHandlers.CToString(systemId).TrimEnd();
@@ -2073,7 +2073,7 @@ public static class MMC
uint infoPos = 0;
for(int pi = 0; pi < pcdLength; pi++)
for(var pi = 0; pi < pcdLength; pi++)
{
int pcdPos = pi * 2048;
@@ -2081,8 +2081,8 @@ public static class MMC
isoSector[pcdPos] > 0 &&
pcdPos + isoSector[pcdPos] <= isoSector.Length)
{
int nameLen = isoSector[pcdPos + 32];
byte[] tmpName = new byte[nameLen];
int nameLen = isoSector[pcdPos + 32];
var tmpName = new byte[nameLen];
Array.Copy(isoSector, pcdPos + 33, tmpName, 0, nameLen);
string name = StringHandlers.CToString(tmpName).ToUpperInvariant();
@@ -2108,7 +2108,7 @@ public static class MMC
if(sense)
break;
byte[] systemId = new byte[8];
var systemId = new byte[8];
Array.Copy(isoSector, 0, systemId, 0, 8);
string id = StringHandlers.CToString(systemId).TrimEnd();
@@ -2230,7 +2230,8 @@ public static class MMC
}
// TODO: Check for CD-i Ready
case MediaType.CDI: break;
case MediaType.CDI:
break;
case MediaType.DVDROM:
case MediaType.HDDVDROM:
case MediaType.BDROM:
@@ -2242,7 +2243,7 @@ public static class MMC
// The decryption key is applied as XOR. As first byte is originally always NULL, it gives us the key :)
byte decryptByte = ps2BootSectors[0];
for(int i = 0; i < 0x6000; i++)
for(var i = 0; i < 0x6000; i++)
ps2BootSectors[i] ^= decryptByte;
string ps2BootSectorsHash = Sha256Context.Data(ps2BootSectors, out _);
@@ -2262,10 +2263,11 @@ public static class MMC
if(sector1 != null)
{
byte[] tmp = new byte[_ps3Id.Length];
var tmp = new byte[_ps3Id.Length];
Array.Copy(sector1, 0, tmp, 0, tmp.Length);
if(tmp.SequenceEqual(_ps3Id))
{
switch(mediaType)
{
case MediaType.BDROM:
@@ -2283,6 +2285,7 @@ public static class MMC
break;
}
}
tmp = new byte[_ps4Id.Length];
Array.Copy(sector1, 512, tmp, 0, tmp.Length);
@@ -2316,7 +2319,7 @@ public static class MMC
case "BDU":
if(sector1 != null)
{
byte[] tmp = new byte[_ps5Id.Length];
var tmp = new byte[_ps5Id.Length];
Array.Copy(sector1, 1024, tmp, 0, tmp.Length);
if(tmp.SequenceEqual(_ps5Id))
@@ -2349,23 +2352,23 @@ public static class MMC
cdegPacket = false;
cdmidiPacket = false;
byte[] cdSubRwPack1 = new byte[24];
byte[] cdSubRwPack2 = new byte[24];
byte[] cdSubRwPack3 = new byte[24];
byte[] cdSubRwPack4 = new byte[24];
var cdSubRwPack1 = new byte[24];
var cdSubRwPack2 = new byte[24];
var cdSubRwPack3 = new byte[24];
var cdSubRwPack4 = new byte[24];
int i = 0;
var i = 0;
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack1[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack2[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack3[j] = (byte)(subchannel[i++] & 0x3F);
for(int j = 0; j < 24; j++)
for(var j = 0; j < 24; j++)
cdSubRwPack4[j] = (byte)(subchannel[i++] & 0x3F);
switch(cdSubRwPack1[0])

View File

@@ -62,9 +62,9 @@ public static class CompactDisc
/// <param name="supportsPlextorReadCdDa">Set to <c>true</c> if drive supports PLEXTOR READ CD-DA vendor command</param>
/// <returns><c>true</c> if offset could be found, <c>false</c> otherwise</returns>
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
public static void GetOffset(CdOffset cdOffset, Device dbDev, bool debug, Aaru.Devices.Device dev,
public static void GetOffset(CdOffset cdOffset, Device dbDev, bool debug, Aaru.Devices.Device dev,
MediaType dskType, DumpLog dumpLog, Track[] tracks, UpdateStatusHandler updateStatus,
out int? driveOffset, out int? combinedOffset, out bool supportsPlextorReadCdDa)
out int? driveOffset, out int? combinedOffset, out bool supportsPlextorReadCdDa)
{
byte[] cmdBuf;
bool sense;
@@ -77,7 +77,7 @@ public static class CompactDisc
int diff;
Track dataTrack = default;
Track audioTrack = default;
bool offsetFound = false;
var offsetFound = false;
const uint sectorSize = 2352;
driveOffset = cdOffset?.Offset * 4;
combinedOffset = null;
@@ -92,15 +92,12 @@ public static class CompactDisc
if(dataTrack != null)
{
// Build sync
sectorSync = new byte[]
{
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00
};
sectorSync = new byte[] { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
tmpBuf = new byte[sectorSync.Length];
// Ensure to be out of the pregap, or multi-session discs give funny values
uint wantedLba = (uint)(dataTrack.StartSector + 151);
var wantedLba = (uint)(dataTrack.StartSector + 151);
// Plextor READ CDDA
if(dbDev?.ATAPI?.RemovableMedias?.Any(d => d.SupportsPlextorReadCDDA == true) == true ||
@@ -115,7 +112,7 @@ public static class CompactDisc
{
supportsPlextorReadCdDa = true;
for(int i = 0; i < cmdBuf.Length - sectorSync.Length; i++)
for(var i = 0; i < cmdBuf.Length - sectorSync.Length; i++)
{
Array.Copy(cmdBuf, i, tmpBuf, 0, sectorSync.Length);
@@ -128,17 +125,17 @@ public static class CompactDisc
frame = cmdBuf[i + 14];
// Convert to binary
minute = (minute / 16 * 10) + (minute & 0x0F);
second = (second / 16 * 10) + (second & 0x0F);
frame = (frame / 16 * 10) + (frame & 0x0F);
minute = minute / 16 * 10 + (minute & 0x0F);
second = second / 16 * 10 + (second & 0x0F);
frame = frame / 16 * 10 + (frame & 0x0F);
// Calculate the first found LBA
lba = (minute * 60 * 75) + (second * 75) + frame - 150;
lba = minute * 60 * 75 + second * 75 + frame - 150;
// Calculate the difference between the found LBA and the requested one
diff = (int)wantedLba - lba;
combinedOffset = i + (2352 * diff);
combinedOffset = i + 2352 * diff;
offsetFound = true;
break;
@@ -160,9 +157,9 @@ public static class CompactDisc
!dev.Error)
{
// Clear cache
for(int i = 0; i < 63; i++)
for(var i = 0; i < 63; i++)
{
sense = dev.ReadCd(out _, out _, (uint)(wantedLba + 3 + (16 * i)), sectorSize, 16,
sense = dev.ReadCd(out _, out _, (uint)(wantedLba + 3 + 16 * i), sectorSize, 16,
MmcSectorTypes.AllTypes, false, false, false, MmcHeaderCodes.None,
true, false, MmcErrorField.None, MmcSubchannel.None, dev.Timeout,
out _);
@@ -175,7 +172,7 @@ public static class CompactDisc
false, MmcHeaderCodes.None, true, false, MmcErrorField.None, MmcSubchannel.None,
dev.Timeout, out _);
for(int i = 0; i < cmdBuf.Length - sectorSync.Length; i++)
for(var i = 0; i < cmdBuf.Length - sectorSync.Length; i++)
{
Array.Copy(cmdBuf, i, tmpBuf, 0, sectorSync.Length);
@@ -188,17 +185,17 @@ public static class CompactDisc
frame = cmdBuf[i + 14];
// Convert to binary
minute = (minute / 16 * 10) + (minute & 0x0F);
second = (second / 16 * 10) + (second & 0x0F);
frame = (frame / 16 * 10) + (frame & 0x0F);
minute = minute / 16 * 10 + (minute & 0x0F);
second = second / 16 * 10 + (second & 0x0F);
frame = frame / 16 * 10 + (frame & 0x0F);
// Calculate the first found LBA
lba = (minute * 60 * 75) + (second * 75) + frame - 150;
lba = minute * 60 * 75 + second * 75 + frame - 150;
// Calculate the difference between the found LBA and the requested one
diff = (int)wantedLba - lba;
combinedOffset = i + (2352 * diff);
combinedOffset = i + 2352 * diff;
offsetFound = true;
break;
@@ -213,7 +210,7 @@ public static class CompactDisc
// Try to get another the offset some other way, we need an audio track just after a data track, same session
for(int i = 1; i < tracks.Length; i++)
for(var i = 1; i < tracks.Length; i++)
{
if(tracks[i - 1].Type == TrackType.Audio ||
tracks[i].Type != TrackType.Audio)
@@ -240,16 +237,16 @@ public static class CompactDisc
dataTrack.EndSector += 150;
// Calculate MSF
minute = (int)dataTrack.EndSector / 4500;
second = ((int)dataTrack.EndSector - (minute * 4500)) / 75;
frame = (int)dataTrack.EndSector - (minute * 4500) - (second * 75);
minute = (int)dataTrack.EndSector / 4500;
second = ((int)dataTrack.EndSector - minute * 4500) / 75;
frame = (int)dataTrack.EndSector - minute * 4500 - second * 75;
dataTrack.EndSector -= 150;
// Convert to BCD
minute = ((minute / 10) << 4) + (minute % 10);
second = ((second / 10) << 4) + (second % 10);
frame = ((frame / 10) << 4) + (frame % 10);
minute = (minute / 10 << 4) + minute % 10;
second = (second / 10 << 4) + second % 10;
frame = (frame / 10 << 4) + frame % 10;
// Scramble M and S
minute ^= 0x01;
@@ -264,7 +261,7 @@ public static class CompactDisc
tmpBuf = new byte[sectorSync.Length];
for(int i = 0; i < cmdBuf.Length - sectorSync.Length; i++)
for(var i = 0; i < cmdBuf.Length - sectorSync.Length; i++)
{
Array.Copy(cmdBuf, i, tmpBuf, 0, sectorSync.Length);
@@ -287,16 +284,16 @@ public static class CompactDisc
if(sense || dev.Error)
return;
for(int i = 0; i < dataBuf.Length; i++)
for(var i = 0; i < dataBuf.Length; i++)
dataBuf[i] ^= Sector.ScrambleTable[i];
for(int i = 0; i < 2352; i++)
for(var i = 0; i < 2352; i++)
{
byte[] dataSide = new byte[2352 - i];
byte[] audioSide = new byte[2352 - i];
var dataSide = new byte[2352 - i];
var audioSide = new byte[2352 - i];
Array.Copy(dataBuf, i, dataSide, 0, dataSide.Length);
Array.Copy(cmdBuf, 0, audioSide, 0, audioSide.Length);
Array.Copy(dataBuf, i, dataSide, 0, dataSide.Length);
Array.Copy(cmdBuf, 0, audioSide, 0, audioSide.Length);
if(!dataSide.SequenceEqual(audioSide))
continue;
@@ -308,7 +305,7 @@ public static class CompactDisc
}
else
{
byte[] videoNowColorFrame = new byte[9 * sectorSize];
var videoNowColorFrame = new byte[9 * sectorSize];
sense = dev.ReadCd(out cmdBuf, out _, 0, sectorSize, 9, MmcSectorTypes.AllTypes, false, false, true,
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.None,

File diff suppressed because it is too large Load Diff