General cleanup and refactor.

This commit is contained in:
2022-03-07 07:36:42 +00:00
parent 0deebadaa0
commit bd76adc35e
119 changed files with 1647 additions and 2151 deletions

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Decoders.CD;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
@@ -215,8 +215,7 @@ public static class ATIP
break;
default:
sb.AppendFormat("Reference speed set is unknown: {0}", response.ReferenceSpeed).
AppendLine();
sb.AppendFormat("Reference speed set is unknown: {0}", response.ReferenceSpeed).AppendLine();
break;
}
@@ -271,9 +270,8 @@ public static class ATIP
sb.AppendFormat("ATIP Start time of Lead-in: {0}:{1:D2}:{2:D2}", response.LeadInStartMin,
response.LeadInStartSec, response.LeadInStartFrame).AppendLine();
sb.AppendFormat("ATIP Last possible start time of Lead-out: {0}:{1:D2}:{2:D2}",
response.LeadOutStartMin, response.LeadOutStartSec, response.LeadOutStartFrame).
AppendLine();
sb.AppendFormat("ATIP Last possible start time of Lead-out: {0}:{1:D2}:{2:D2}", response.LeadOutStartMin,
response.LeadOutStartSec, response.LeadOutStartFrame).AppendLine();
if(response.A1Valid)
sb.AppendFormat("A1 value: 0x{0:X6}",

View File

@@ -30,14 +30,14 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Decoders.CD;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
@@ -118,17 +118,17 @@ public static class CDTextOnLeadIn
return null;
}
for(int i = 0; i < (decoded.DataLength - 2) / 18; i++)
for(var i = 0; i < (decoded.DataLength - 2) / 18; i++)
{
decoded.DataPacks[i].HeaderID1 = CDTextResponse[0 + (i * 18) + 4];
decoded.DataPacks[i].HeaderID2 = CDTextResponse[1 + (i * 18) + 4];
decoded.DataPacks[i].HeaderID3 = CDTextResponse[2 + (i * 18) + 4];
decoded.DataPacks[i].DBCC = Convert.ToBoolean(CDTextResponse[3 + (i * 18) + 4] & 0x80);
decoded.DataPacks[i].BlockNumber = (byte)((CDTextResponse[3 + (i * 18) + 4] & 0x70) >> 4);
decoded.DataPacks[i].CharacterPosition = (byte)(CDTextResponse[3 + (i * 18) + 4] & 0x0F);
decoded.DataPacks[i].HeaderID1 = CDTextResponse[0 + i * 18 + 4];
decoded.DataPacks[i].HeaderID2 = CDTextResponse[1 + i * 18 + 4];
decoded.DataPacks[i].HeaderID3 = CDTextResponse[2 + i * 18 + 4];
decoded.DataPacks[i].DBCC = Convert.ToBoolean(CDTextResponse[3 + i * 18 + 4] & 0x80);
decoded.DataPacks[i].BlockNumber = (byte)((CDTextResponse[3 + i * 18 + 4] & 0x70) >> 4);
decoded.DataPacks[i].CharacterPosition = (byte)(CDTextResponse[3 + i * 18 + 4] & 0x0F);
decoded.DataPacks[i].TextDataField = new byte[12];
Array.Copy(CDTextResponse, 4 + (i * 18) + 4, decoded.DataPacks[i].TextDataField, 0, 12);
decoded.DataPacks[i].CRC = BigEndianBitConverter.ToUInt16(CDTextResponse, 16 + (i * 18) + 4);
Array.Copy(CDTextResponse, 4 + i * 18 + 4, decoded.DataPacks[i].TextDataField, 0, 12);
decoded.DataPacks[i].CRC = BigEndianBitConverter.ToUInt16(CDTextResponse, 16 + i * 18 + 4);
}
return decoded;
@@ -155,8 +155,7 @@ public static class CDTextOnLeadIn
{
// Ignore NOPs
if((descriptor.HeaderID1 & 0x80) != 0)
sb.AppendFormat("Incorrect CD-Text pack type {0}, not decoding", descriptor.HeaderID1).
AppendLine();
sb.AppendFormat("Incorrect CD-Text pack type {0}, not decoding", descriptor.HeaderID1).AppendLine();
}
else
{
@@ -322,8 +321,7 @@ public static class CDTextOnLeadIn
default:
{
sb.AppendFormat("Binary contents: {0}",
PrintHex.ByteArrayToHexArrayString(descriptor.TextDataField, 28)).
AppendLine();
PrintHex.ByteArrayToHexArrayString(descriptor.TextDataField, 28)).AppendLine();
break;
}

View File

@@ -30,10 +30,10 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
using System.Diagnostics.CodeAnalysis;
namespace Aaru.Decoders.CD;
using System.Diagnostics.CodeAnalysis;
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
public enum TocAdr : byte
{

View File

@@ -30,6 +30,8 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -39,8 +41,6 @@ using Aaru.CommonTypes.Structs;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Decoders.CD;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
@@ -91,22 +91,22 @@ public static class FullTOC
return null;
}
for(int i = 0; i < (decoded.DataLength - 2) / 11; i++)
for(var i = 0; i < (decoded.DataLength - 2) / 11; i++)
{
decoded.TrackDescriptors[i].SessionNumber = CDFullTOCResponse[0 + (i * 11) + 4];
decoded.TrackDescriptors[i].ADR = (byte)((CDFullTOCResponse[1 + (i * 11) + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].CONTROL = (byte)(CDFullTOCResponse[1 + (i * 11) + 4] & 0x0F);
decoded.TrackDescriptors[i].TNO = CDFullTOCResponse[2 + (i * 11) + 4];
decoded.TrackDescriptors[i].POINT = CDFullTOCResponse[3 + (i * 11) + 4];
decoded.TrackDescriptors[i].Min = CDFullTOCResponse[4 + (i * 11) + 4];
decoded.TrackDescriptors[i].Sec = CDFullTOCResponse[5 + (i * 11) + 4];
decoded.TrackDescriptors[i].Frame = CDFullTOCResponse[6 + (i * 11) + 4];
decoded.TrackDescriptors[i].Zero = CDFullTOCResponse[7 + (i * 11) + 4];
decoded.TrackDescriptors[i].HOUR = (byte)((CDFullTOCResponse[7 + (i * 11) + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].PHOUR = (byte)(CDFullTOCResponse[7 + (i * 11) + 4] & 0x0F);
decoded.TrackDescriptors[i].PMIN = CDFullTOCResponse[8 + (i * 11) + 4];
decoded.TrackDescriptors[i].PSEC = CDFullTOCResponse[9 + (i * 11) + 4];
decoded.TrackDescriptors[i].PFRAME = CDFullTOCResponse[10 + (i * 11) + 4];
decoded.TrackDescriptors[i].SessionNumber = CDFullTOCResponse[0 + i * 11 + 4];
decoded.TrackDescriptors[i].ADR = (byte)((CDFullTOCResponse[1 + i * 11 + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].CONTROL = (byte)(CDFullTOCResponse[1 + i * 11 + 4] & 0x0F);
decoded.TrackDescriptors[i].TNO = CDFullTOCResponse[2 + i * 11 + 4];
decoded.TrackDescriptors[i].POINT = CDFullTOCResponse[3 + i * 11 + 4];
decoded.TrackDescriptors[i].Min = CDFullTOCResponse[4 + i * 11 + 4];
decoded.TrackDescriptors[i].Sec = CDFullTOCResponse[5 + i * 11 + 4];
decoded.TrackDescriptors[i].Frame = CDFullTOCResponse[6 + i * 11 + 4];
decoded.TrackDescriptors[i].Zero = CDFullTOCResponse[7 + i * 11 + 4];
decoded.TrackDescriptors[i].HOUR = (byte)((CDFullTOCResponse[7 + i * 11 + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].PHOUR = (byte)(CDFullTOCResponse[7 + i * 11 + 4] & 0x0F);
decoded.TrackDescriptors[i].PMIN = CDFullTOCResponse[8 + i * 11 + 4];
decoded.TrackDescriptors[i].PSEC = CDFullTOCResponse[9 + i * 11 + 4];
decoded.TrackDescriptors[i].PFRAME = CDFullTOCResponse[10 + i * 11 + 4];
}
return decoded;
@@ -121,14 +121,14 @@ public static class FullTOC
var sb = new StringBuilder();
int lastSession = 0;
var lastSession = 0;
sb.AppendFormat("First complete session number: {0}", response.FirstCompleteSession).AppendLine();
sb.AppendFormat("Last complete session number: {0}", response.LastCompleteSession).AppendLine();
foreach(TrackDataDescriptor descriptor in response.TrackDescriptors)
if((descriptor.CONTROL & 0x08) == 0x08 ||
(descriptor.ADR != 1 && descriptor.ADR != 5 && descriptor.ADR != 4 && descriptor.ADR != 6) ||
if((descriptor.CONTROL & 0x08) == 0x08 ||
descriptor.ADR != 1 && descriptor.ADR != 5 && descriptor.ADR != 4 && descriptor.ADR != 6 ||
descriptor.TNO != 0)
{
sb.AppendLine("Unknown TOC entry format, printing values as-is");
@@ -292,9 +292,8 @@ public static class FullTOC
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME,
descriptor.PHOUR).AppendLine();
else
sb.AppendFormat("Lead-out start position: {0:D2}:{1:D2}:{2:D2}",
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
AppendLine();
sb.AppendFormat("Lead-out start position: {0:D2}:{1:D2}:{2:D2}", descriptor.PMIN,
descriptor.PSEC, descriptor.PFRAME).AppendLine();
//sb.AppendFormat("Absolute time: {3:D2}:{0:D2}:{1:D2}:{2:D2}", descriptor.Min, descriptor.Sec, descriptor.Frame, descriptor.HOUR).AppendLine();
@@ -343,11 +342,10 @@ public static class FullTOC
descriptor.POINT).AppendLine();
else
{
string type = "Audio";
var type = "Audio";
if((TocControl)(descriptor.CONTROL & 0x0D) == TocControl.DataTrack ||
(TocControl)(descriptor.CONTROL & 0x0D) ==
TocControl.DataTrackIncremental)
(TocControl)(descriptor.CONTROL & 0x0D) == TocControl.DataTrackIncremental)
type = "Data";
if(descriptor.PHOUR > 0)
@@ -422,8 +420,8 @@ public static class FullTOC
{
sb.
AppendFormat("Start of next possible program in the recordable area of the disc: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
descriptor.Min, descriptor.Sec, descriptor.Frame,
descriptor.HOUR).AppendLine();
descriptor.Min, descriptor.Sec, descriptor.Frame, descriptor.HOUR).
AppendLine();
sb.
AppendFormat("Maximum start of outermost Lead-out in the recordable area of the disc: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
@@ -438,8 +436,7 @@ public static class FullTOC
sb.
AppendFormat("Maximum start of outermost Lead-out in the recordable area of the disc: {0:D2}:{1:D2}:{2:D2}",
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
AppendLine();
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).AppendLine();
}
break;
@@ -447,8 +444,7 @@ public static class FullTOC
case 0xB1:
{
sb.AppendFormat("Number of skip interval pointers: {0}", descriptor.PMIN).
AppendLine();
sb.AppendFormat("Number of skip interval pointers: {0}", descriptor.PMIN).AppendLine();
sb.AppendFormat("Number of skip track pointers: {0}", descriptor.PSEC).AppendLine();
@@ -482,8 +478,7 @@ public static class FullTOC
else
sb.
AppendFormat("Start time of the first Lead-in area in the disc: {0:D2}:{1:D2}:{2:D2}",
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
AppendLine();
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).AppendLine();
break;
}
@@ -513,19 +508,16 @@ public static class FullTOC
sb.
AppendFormat("Stop position of inner part lead-out area: {3:D2}:{0:D2}:{1:D2}:{2:D2}",
descriptor.Min, descriptor.Sec, descriptor.Frame,
descriptor.HOUR).AppendLine();
descriptor.Min, descriptor.Sec, descriptor.Frame, descriptor.HOUR).
AppendLine();
}
else
{
sb.
AppendFormat("Start position of outer part lead-in area: {0:D2}:{1:D2}:{2:D2}",
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
AppendLine();
sb.AppendFormat("Start position of outer part lead-in area: {0:D2}:{1:D2}:{2:D2}",
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).AppendLine();
sb.
AppendFormat("Stop position of inner part lead-out area: {0:D2}:{1:D2}:{2:D2}",
descriptor.Min, descriptor.Sec, descriptor.Frame).AppendLine();
sb.AppendFormat("Stop position of inner part lead-out area: {0:D2}:{1:D2}:{2:D2}",
descriptor.Min, descriptor.Sec, descriptor.Frame).AppendLine();
}
break;
@@ -538,8 +530,7 @@ public static class FullTOC
{
sb.
AppendFormat("Start time for interval that should be skipped: {0:D2}:{1:D2}:{2:D2}",
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).
AppendLine();
descriptor.PMIN, descriptor.PSEC, descriptor.PFRAME).AppendLine();
sb.
AppendFormat("Ending time for interval that should be skipped: {0:D2}:{1:D2}:{2:D2}",
@@ -570,7 +561,7 @@ public static class FullTOC
case 6:
{
uint id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
var id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
sb.AppendFormat("Disc ID: {0:X6}", id & 0x00FFFFFF).AppendLine();
break;
@@ -632,8 +623,7 @@ public static class FullTOC
public byte PFRAME;
}
public static CDFullTOC Create(List<Track> tracks, Dictionary<byte, byte> trackFlags,
bool createC0Entry = false)
public static CDFullTOC Create(List<Track> tracks, Dictionary<byte, byte> trackFlags, bool createC0Entry = false)
{
var toc = new CDFullTOC();
Dictionary<byte, byte> sessionEndingTrack = new();

View File

@@ -30,13 +30,13 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Decoders.CD;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
@@ -81,21 +81,21 @@ public static class PMA
return null;
}
for(int i = 0; i < (decoded.DataLength - 2) / 11; i++)
for(var i = 0; i < (decoded.DataLength - 2) / 11; i++)
{
decoded.PMADescriptors[i].Reserved = CDPMAResponse[0 + (i * 11) + 4];
decoded.PMADescriptors[i].ADR = (byte)((CDPMAResponse[1 + (i * 11) + 4] & 0xF0) >> 4);
decoded.PMADescriptors[i].CONTROL = (byte)(CDPMAResponse[1 + (i * 11) + 4] & 0x0F);
decoded.PMADescriptors[i].TNO = CDPMAResponse[2 + (i * 11) + 4];
decoded.PMADescriptors[i].POINT = CDPMAResponse[3 + (i * 11) + 4];
decoded.PMADescriptors[i].Min = CDPMAResponse[4 + (i * 11) + 4];
decoded.PMADescriptors[i].Sec = CDPMAResponse[5 + (i * 11) + 4];
decoded.PMADescriptors[i].Frame = CDPMAResponse[6 + (i * 11) + 4];
decoded.PMADescriptors[i].HOUR = (byte)((CDPMAResponse[7 + (i * 11) + 4] & 0xF0) >> 4);
decoded.PMADescriptors[i].PHOUR = (byte)(CDPMAResponse[7 + (i * 11) + 4] & 0x0F);
decoded.PMADescriptors[i].PMIN = CDPMAResponse[8 + (i * 11) + 4];
decoded.PMADescriptors[i].PSEC = CDPMAResponse[9 + (i * 11) + 4];
decoded.PMADescriptors[i].PFRAME = CDPMAResponse[10 + (i * 11) + 4];
decoded.PMADescriptors[i].Reserved = CDPMAResponse[0 + i * 11 + 4];
decoded.PMADescriptors[i].ADR = (byte)((CDPMAResponse[1 + i * 11 + 4] & 0xF0) >> 4);
decoded.PMADescriptors[i].CONTROL = (byte)(CDPMAResponse[1 + i * 11 + 4] & 0x0F);
decoded.PMADescriptors[i].TNO = CDPMAResponse[2 + i * 11 + 4];
decoded.PMADescriptors[i].POINT = CDPMAResponse[3 + i * 11 + 4];
decoded.PMADescriptors[i].Min = CDPMAResponse[4 + i * 11 + 4];
decoded.PMADescriptors[i].Sec = CDPMAResponse[5 + i * 11 + 4];
decoded.PMADescriptors[i].Frame = CDPMAResponse[6 + i * 11 + 4];
decoded.PMADescriptors[i].HOUR = (byte)((CDPMAResponse[7 + i * 11 + 4] & 0xF0) >> 4);
decoded.PMADescriptors[i].PHOUR = (byte)(CDPMAResponse[7 + i * 11 + 4] & 0x0F);
decoded.PMADescriptors[i].PMIN = CDPMAResponse[8 + i * 11 + 4];
decoded.PMADescriptors[i].PSEC = CDPMAResponse[9 + i * 11 + 4];
decoded.PMADescriptors[i].PFRAME = CDPMAResponse[10 + i * 11 + 4];
}
return decoded;
@@ -181,7 +181,7 @@ public static class PMA
break;
case 2:
uint id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
var id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
sb.AppendFormat("Disc ID: {0:X6}", id & 0x00FFFFFF).AppendLine();
break;
@@ -244,8 +244,8 @@ public static class PMA
descriptor.PFRAME);
if(descriptor.PHOUR > 0)
sb.AppendFormat("{3}:{0:D2}:{1:D2}:{2:D2} ", descriptor.Min, descriptor.Sec,
descriptor.Frame, descriptor.HOUR);
sb.AppendFormat("{3}:{0:D2}:{1:D2}:{2:D2} ", descriptor.Min, descriptor.Sec, descriptor.Frame,
descriptor.HOUR);
else
sb.AppendFormat("{0:D2}:{1:D2}:{2:D2} ", descriptor.Min, descriptor.Sec, descriptor.Frame);
@@ -263,8 +263,8 @@ public static class PMA
descriptor.PFRAME);
if(descriptor.PHOUR > 0)
sb.AppendFormat("{3}:{0:D2}:{1:D2}:{2:D2} ", descriptor.Min, descriptor.Sec,
descriptor.Frame, descriptor.HOUR);
sb.AppendFormat("{3}:{0:D2}:{1:D2}:{2:D2} ", descriptor.Min, descriptor.Sec, descriptor.Frame,
descriptor.HOUR);
else
sb.AppendFormat("{0:D2}:{1:D2}:{2:D2} ", descriptor.Min, descriptor.Sec, descriptor.Frame);

View File

@@ -30,6 +30,8 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -37,8 +39,6 @@ using System.Runtime.CompilerServices;
using System.Text;
using Aaru.Checksums;
namespace Aaru.Decoders.CD;
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static class Sector
@@ -189,21 +189,21 @@ public static class Sector
sector.Length < 2352)
return sector;
byte[] sync = new byte[12];
var sync = new byte[12];
Array.Copy(sector, 0, sync, 0, 12);
if(!SyncMark.SequenceEqual(sync))
return sector;
byte[] scrambled = new byte[sector.Length];
var scrambled = new byte[sector.Length];
for(int i = 0; i < 2352; i++)
for(var i = 0; i < 2352; i++)
scrambled[i] = (byte)(sector[i] ^ ScrambleTable[i]);
if(sector.Length <= 2352)
return scrambled;
for(int i = 2352; i < sector.Length; i++)
for(var i = 2352; i < sector.Length; i++)
scrambled[i] = sector[i];
return scrambled;
@@ -222,7 +222,7 @@ public static class Sector
{
case 0: return new byte[2048];
case 1:
byte[] sector = new byte[2048];
var sector = new byte[2048];
Array.Copy(data, 16, sector, 0, 2048);
return sector;
@@ -241,7 +241,7 @@ public static class Sector
data.Length != 2336)
return data;
int pos = 0;
var pos = 0;
if(data.Length == 2352)
{
@@ -270,7 +270,7 @@ public static class Sector
int len = (data[pos + 2] & 0x20) == 0x20 ? 2324 : 2048;
pos += 8;
byte[] sector = new byte[len];
var sector = new byte[len];
Array.Copy(data, pos, sector, 0, len);
return sector;
@@ -303,8 +303,8 @@ public static class Sector
byte min = buffer[12];
byte sec = buffer[13];
byte frame = buffer[14];
int lba = 0;
bool moreThan90 = false;
var lba = 0;
var moreThan90 = false;
if(min > 0x90)
{
@@ -313,9 +313,9 @@ public static class Sector
moreThan90 = true;
}
lba += (((min >> 4) * 10) + (min & 0x0F)) * 75 * 60;
lba += (((sec >> 4) * 10) + (sec & 0x0F)) * 75;
lba += ((frame >> 4) * 10) + (frame & 0x0F);
lba += ((min >> 4) * 10 + (min & 0x0F)) * 75 * 60;
lba += ((sec >> 4) * 10 + (sec & 0x0F)) * 75;
lba += (frame >> 4) * 10 + (frame & 0x0F);
lba -= 150;
if(moreThan90)
@@ -381,21 +381,19 @@ public static class Sector
CdChecksums.CheckCdSector(buffer, out bool? correctEccP, out bool? correctEccQ, out bool? correctEdc);
bool empty = true;
var empty = true;
switch(buffer[15] & 0x03)
{
case 0:
for(int i = 16; i < 2352; i++)
{
for(var i = 16; i < 2352; i++)
if(buffer[i] != 0x00)
{
empty = false;
break;
}
}
sb.AppendLine(empty ? "Correct sector contents." : "Incorrect sector contents.");
@@ -405,15 +403,13 @@ public static class Sector
sb.AppendLine(correctEccP == true ? "Correct ECC P." : "Incorrect ECC P.");
sb.AppendLine(correctEccQ == true ? "Correct ECC Q." : "Incorrect ECC Q.");
for(int i = 2068; i < 2076; i++)
{
for(var i = 2068; i < 2076; i++)
if(buffer[i] != 0x00)
{
empty = false;
break;
}
}
sb.AppendLine(empty ? "Correct zero fill." : "Incorrect zero fill.");

View File

@@ -26,11 +26,11 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System;
using Aaru.CommonTypes.Enums;
namespace Aaru.Decoders.CD;
public class SectorBuilder
{
readonly byte[] _eccBTable;
@@ -46,7 +46,7 @@ public class SectorBuilder
for(uint i = 0; i < 256; i++)
{
uint edc = i;
uint j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
var j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
_eccFTable[i] = (byte)j;
_eccBTable[i ^ j] = (byte)i;
@@ -81,9 +81,9 @@ public class SectorBuilder
(byte minute, byte second, byte frame) msf = LbaToMsf(lba);
sector[0x00C] = (byte)(((msf.minute / 10) << 4) + (msf.minute % 10));
sector[0x00D] = (byte)(((msf.second / 10) << 4) + (msf.second % 10));
sector[0x00E] = (byte)(((msf.frame / 10) << 4) + (msf.frame % 10));
sector[0x00C] = (byte)(((msf.minute / 10) << 4) + msf.minute % 10);
sector[0x00D] = (byte)(((msf.second / 10) << 4) + msf.second % 10);
sector[0x00E] = (byte)(((msf.frame / 10) << 4) + msf.frame % 10);
switch(type)
{
@@ -162,7 +162,7 @@ public class SectorBuilder
default: return;
}
byte[] zeroaddress = new byte[4];
var zeroaddress = new byte[4];
switch(type)
{
@@ -196,8 +196,7 @@ public class SectorBuilder
//
}
void EccWriteSector(byte[] address, byte[] data, ref byte[] ecc, int addressOffset, int dataOffset,
int eccOffset)
void EccWriteSector(byte[] address, byte[] data, ref byte[] ecc, int addressOffset, int dataOffset, int eccOffset)
{
WriteEcc(address, data, 86, 24, 2, 86, ref ecc, addressOffset, dataOffset, eccOffset); // P
WriteEcc(address, data, 52, 43, 86, 88, ref ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q
@@ -211,7 +210,7 @@ public class SectorBuilder
for(major = 0; major < majorCount; major++)
{
uint idx = ((major >> 1) * majorMult) + (major & 1);
uint idx = (major >> 1) * majorMult + (major & 1);
byte eccA = 0;
byte eccB = 0;
uint minor;

View File

@@ -30,13 +30,13 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Decoders.CD;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
@@ -77,16 +77,16 @@ public static class Session
return null;
}
for(int i = 0; i < (decoded.DataLength - 2) / 8; i++)
for(var i = 0; i < (decoded.DataLength - 2) / 8; i++)
{
decoded.TrackDescriptors[i].Reserved1 = CDSessionInfoResponse[0 + (i * 8) + 4];
decoded.TrackDescriptors[i].ADR = (byte)((CDSessionInfoResponse[1 + (i * 8) + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].CONTROL = (byte)(CDSessionInfoResponse[1 + (i * 8) + 4] & 0x0F);
decoded.TrackDescriptors[i].TrackNumber = CDSessionInfoResponse[2 + (i * 8) + 4];
decoded.TrackDescriptors[i].Reserved2 = CDSessionInfoResponse[3 + (i * 8) + 4];
decoded.TrackDescriptors[i].Reserved1 = CDSessionInfoResponse[0 + i * 8 + 4];
decoded.TrackDescriptors[i].ADR = (byte)((CDSessionInfoResponse[1 + i * 8 + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].CONTROL = (byte)(CDSessionInfoResponse[1 + i * 8 + 4] & 0x0F);
decoded.TrackDescriptors[i].TrackNumber = CDSessionInfoResponse[2 + i * 8 + 4];
decoded.TrackDescriptors[i].Reserved2 = CDSessionInfoResponse[3 + i * 8 + 4];
decoded.TrackDescriptors[i].TrackStartAddress =
BigEndianBitConverter.ToUInt32(CDSessionInfoResponse, 4 + (i * 8) + 4);
BigEndianBitConverter.ToUInt32(CDSessionInfoResponse, 4 + i * 8 + 4);
}
return decoded;
@@ -106,8 +106,7 @@ public static class Session
foreach(TrackDataDescriptor descriptor in response.TrackDescriptors)
{
sb.AppendFormat("First track number in last complete session: {0}", descriptor.TrackNumber).
AppendLine();
sb.AppendFormat("First track number in last complete session: {0}", descriptor.TrackNumber).AppendLine();
sb.AppendFormat("Track starts at LBA {0}, or MSF {1:X2}:{2:X2}:{3:X2}", descriptor.TrackStartAddress,
(descriptor.TrackStartAddress & 0x0000FF00) >> 8,

View File

@@ -26,11 +26,11 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System;
using Aaru.Checksums;
namespace Aaru.Decoders.CD;
public static class Subchannel
{
static readonly string[] _isrcTable =
@@ -53,17 +53,17 @@ public static class Subchannel
if((q[0] & 0xF) == 1 ||
(q[0] & 0xF) == 5)
{
q[1] = (byte)(((q[1] / 10) << 4) + (q[1] % 10));
q[2] = (byte)(((q[2] / 10) << 4) + (q[2] % 10));
q[3] = (byte)(((q[3] / 10) << 4) + (q[3] % 10));
q[4] = (byte)(((q[4] / 10) << 4) + (q[4] % 10));
q[5] = (byte)(((q[5] / 10) << 4) + (q[5] % 10));
q[6] = (byte)(((q[6] / 10) << 4) + (q[6] % 10));
q[7] = (byte)(((q[7] / 10) << 4) + (q[7] % 10));
q[8] = (byte)(((q[8] / 10) << 4) + (q[8] % 10));
q[1] = (byte)(((q[1] / 10) << 4) + q[1] % 10);
q[2] = (byte)(((q[2] / 10) << 4) + q[2] % 10);
q[3] = (byte)(((q[3] / 10) << 4) + q[3] % 10);
q[4] = (byte)(((q[4] / 10) << 4) + q[4] % 10);
q[5] = (byte)(((q[5] / 10) << 4) + q[5] % 10);
q[6] = (byte)(((q[6] / 10) << 4) + q[6] % 10);
q[7] = (byte)(((q[7] / 10) << 4) + q[7] % 10);
q[8] = (byte)(((q[8] / 10) << 4) + q[8] % 10);
}
q[9] = (byte)(((q[9] / 10) << 4) + (q[9] % 10));
q[9] = (byte)(((q[9] / 10) << 4) + q[9] % 10);
}
public static void BcdToBinaryQ(byte[] q)
@@ -71,31 +71,29 @@ public static class Subchannel
if((q[0] & 0xF) == 1 ||
(q[0] & 0xF) == 5)
{
q[1] = (byte)((q[1] / 16 * 10) + (q[1] & 0x0F));
q[2] = (byte)((q[2] / 16 * 10) + (q[2] & 0x0F));
q[3] = (byte)((q[3] / 16 * 10) + (q[3] & 0x0F));
q[4] = (byte)((q[4] / 16 * 10) + (q[4] & 0x0F));
q[5] = (byte)((q[5] / 16 * 10) + (q[5] & 0x0F));
q[6] = (byte)((q[6] / 16 * 10) + (q[6] & 0x0F));
q[7] = (byte)((q[7] / 16 * 10) + (q[7] & 0x0F));
q[8] = (byte)((q[8] / 16 * 10) + (q[8] & 0x0F));
q[1] = (byte)(q[1] / 16 * 10 + (q[1] & 0x0F));
q[2] = (byte)(q[2] / 16 * 10 + (q[2] & 0x0F));
q[3] = (byte)(q[3] / 16 * 10 + (q[3] & 0x0F));
q[4] = (byte)(q[4] / 16 * 10 + (q[4] & 0x0F));
q[5] = (byte)(q[5] / 16 * 10 + (q[5] & 0x0F));
q[6] = (byte)(q[6] / 16 * 10 + (q[6] & 0x0F));
q[7] = (byte)(q[7] / 16 * 10 + (q[7] & 0x0F));
q[8] = (byte)(q[8] / 16 * 10 + (q[8] & 0x0F));
}
q[9] = (byte)((q[9] / 16 * 10) + (q[9] & 0x0F));
q[9] = (byte)(q[9] / 16 * 10 + (q[9] & 0x0F));
}
public static byte[] ConvertQToRaw(byte[] subchannel)
{
int pos = 0;
byte[] subBuf = new byte[subchannel.Length * 6];
var pos = 0;
var subBuf = new byte[subchannel.Length * 6];
for(int i = 0; i < subchannel.Length; i += 16)
for(var i = 0; i < subchannel.Length; i += 16)
{
// P
if((subchannel[i + 15] & 0x80) <= 0)
{
pos += 12;
}
else
{
subBuf[pos++] = 0xFF;
@@ -135,13 +133,13 @@ public static class Subchannel
public static byte[] Interleave(byte[] subchannel)
{
byte[] subBuf = new byte[subchannel.Length];
var subBuf = new byte[subchannel.Length];
int outPos = 0;
var outPos = 0;
for(int inPos = 0; inPos < subchannel.Length; inPos += 96)
for(var inPos = 0; inPos < subchannel.Length; inPos += 96)
{
for(int i = 0; i < 12; i++)
for(var i = 0; i < 12; i++)
{
// P
subBuf[outPos + 0] += (byte)(subchannel[inPos + i + 0] & 0x80);
@@ -231,12 +229,12 @@ public static class Subchannel
public static byte[] Deinterleave(byte[] subchannel)
{
byte[] subBuf = new byte[subchannel.Length];
int inPos = 0;
var subBuf = new byte[subchannel.Length];
var inPos = 0;
for(int outPos = 0; outPos < subchannel.Length; outPos += 96)
for(var outPos = 0; outPos < subchannel.Length; outPos += 96)
{
for(int i = 0; i < 12; i++)
for(var i = 0; i < 12; i++)
{
// P
subBuf[outPos + i + 0] += (byte)((subchannel[inPos + 0] & 0x80) >> 0);
@@ -338,26 +336,26 @@ public static class Subchannel
int adr = subBuf[0] & 0x0F;
string controlInfo = ((control & 0xC) / 4) switch
{
0 => $"stereo audio {((control & 0x01) == 1 ? "with" : "without")} pre-emphasis",
1 => $"{((control & 0x01) == 1 ? "incremental" : "uninterrupted")} data",
2 => $"quadraphonic audio {((control & 0x01) == 1 ? "with" : "without")} pre-emphasis",
_ => $"reserved control value {control & 0x01}"
};
{
0 => $"stereo audio {((control & 0x01) == 1 ? "with" : "without")} pre-emphasis",
1 => $"{((control & 0x01) == 1 ? "incremental" : "uninterrupted")} data",
2 => $"quadraphonic audio {((control & 0x01) == 1 ? "with" : "without")} pre-emphasis",
_ => $"reserved control value {control & 0x01}"
};
string copy = (control & 0x02) > 0 ? "copy permitted" : "copy prohibited";
if(bcd)
BcdToBinaryQ(subBuf);
int qPos = (subBuf[3] * 60 * 75) + (subBuf[4] * 75) + subBuf[5] - 150;
int qPos = subBuf[3] * 60 * 75 + subBuf[4] * 75 + subBuf[5] - 150;
byte pmin = subBuf[7];
byte psec = subBuf[8];
int qStart = (subBuf[7] * 60 * 75) + (subBuf[8] * 75) + subBuf[9] - 150;
int nextPos = (subBuf[3] * 60 * 75) + (subBuf[4] * 75) + subBuf[5] - 150;
int qStart = subBuf[7] * 60 * 75 + subBuf[8] * 75 + subBuf[9] - 150;
int nextPos = subBuf[3] * 60 * 75 + subBuf[4] * 75 + subBuf[5] - 150;
byte zero = subBuf[6];
int maxOut = (subBuf[7] * 60 * 75) + (subBuf[8] * 75) + subBuf[9] - 150;
int maxOut = subBuf[7] * 60 * 75 + subBuf[8] * 75 + subBuf[9] - 150;
bool final = subBuf[3] == 0xFF && subBuf[4] == 0xFF && subBuf[5] == 0xFF;
BinaryToBcdQ(subBuf);
@@ -374,12 +372,12 @@ public static class Subchannel
case 1 when subBuf[2] == 0xA0:
{
string format = subBuf[8] switch
{
0x00 => "CD-DA / CD-ROM",
0x10 => "CD-i",
0x20 => "CD-ROM XA",
_ => $"unknown {subBuf[0]:X2}"
};
{
0x00 => "CD-DA / CD-ROM",
0x10 => "CD-i",
0x20 => "CD-ROM XA",
_ => $"unknown {subBuf[0]:X2}"
};
return
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} position: {subBuf[3]:X2}:{subBuf[4]:X2}:{subBuf[5]:X2} (LBA {qPos}), track {subBuf[2]:X} is first program area track in {format} format, Q CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}";
@@ -401,23 +399,17 @@ public static class Subchannel
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q: {subBuf[0]:X2} {subBuf[1]:X2} {subBuf[2]:X2} {subBuf[3]:X2} {subBuf[4]:X2} {subBuf[5]:X2} {subBuf[6]:X2} {subBuf[7]:X2} {subBuf[8]:X2} {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}";
if(subBuf[2] <= 0x40)
{
return
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} skip interval start time {subBuf[7]:X2}{subBuf[8]:X2}{subBuf[9]:X2}, skip interval stop time {subBuf[3]:X2}{subBuf[4]:X2}{subBuf[5]:X2}, CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}";
}
if(subBuf[2] == 0xB0)
{
return final
? $"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} next program area can start at {subBuf[3]:X2}:{subBuf[4]:X2}:{subBuf[5]:X2} (LBA {nextPos}), last-session, {zero} mode 5 pointers, CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}"
: $"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} next program area can start at {subBuf[3]:X2}:{subBuf[4]:X2}:{subBuf[5]:X2} (LBA {nextPos}), maximum Lead-out at {subBuf[7]:X2}:{subBuf[8]:X2}:{subBuf[9]:X2} (LBA {maxOut}), {zero} mode 5 pointers, CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}";
}
if(subBuf[2] == 0xB1)
{
return
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr}, {pmin} skip interval pointers, {psec} skip track assignments, CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}";
}
if(subBuf[2] != 0xB2 &&
subBuf[2] != 0xB3 &&
@@ -450,23 +442,22 @@ public static class Subchannel
area = subBuf[1] == 0xAA ? "Lead-out" : "Program";
return adr switch
{
1 =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} position: track {subBuf[1]:X} index {subBuf[2]:X} relative position {subBuf[3]:X2}:{subBuf[4]:X2}:{subBuf[5]:X2} (LBA {qPos + 150}), absolute position {subBuf[7]:X2}:{subBuf[8]:X2}:{subBuf[9]:X2} (LBA {qStart}), Q CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}",
2 =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} MCN: {DecodeMcn(subBuf)} frame {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}",
3 =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} ISRC: {DecodeIsrc(subBuf)} frame {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}",
_ =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q: {subBuf[0]:X2} {subBuf[1]:X2} {subBuf[2]:X2} {subBuf[3]:X2} {subBuf[4]:X2} {subBuf[5]:X2} {subBuf[6]:X2} {subBuf[7]:X2} {subBuf[8]:X2} {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}"
};
{
1 =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} position: track {subBuf[1]:X} index {subBuf[2]:X} relative position {subBuf[3]:X2}:{subBuf[4]:X2}:{subBuf[5]:X2} (LBA {qPos + 150}), absolute position {subBuf[7]:X2}:{subBuf[8]:X2}:{subBuf[9]:X2} (LBA {qStart}), Q CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}",
2 =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} MCN: {DecodeMcn(subBuf)} frame {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}",
3 =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q mode {adr} ISRC: {DecodeIsrc(subBuf)} frame {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}",
_ =>
$"{minute:D2}:{second:D2}:{frame:D2} - LBA {lba,6}: {area} area, {(corruptedPause ? "corrupted pause" : pause ? "pause" : "not pause")}, {controlInfo}, {copy}, Q: {subBuf[0]:X2} {subBuf[1]:X2} {subBuf[2]:X2} {subBuf[3]:X2} {subBuf[4]:X2} {subBuf[5]:X2} {subBuf[6]:X2} {subBuf[7]:X2} {subBuf[8]:X2} {subBuf[9]:X2} CRC 0x{subBuf[10]:X2}{subBuf[11]:X2} ({(crcOk ? "OK" : "BAD")}), R-W {(rwEmpty ? "empty" : "not empty")}"
};
}
public static string DecodeIsrc(byte[] q) =>
$"{_isrcTable[q[1] / 4]}{_isrcTable[((q[1] & 3) * 16) + (q[2] / 16)]}{_isrcTable[((q[2] & 0xF) * 4) + (q[3] / 64)]}{_isrcTable[q[3] & 0x3F]}{_isrcTable[q[4] / 4]}{q[5]:X2}{q[6]:X2}{q[7]:X2}{q[8] / 16:X1}";
$"{_isrcTable[q[1] / 4]}{_isrcTable[(q[1] & 3) * 16 + q[2] / 16]}{_isrcTable[(q[2] & 0xF) * 4 + q[3] / 64]}{_isrcTable[q[3] & 0x3F]}{_isrcTable[q[4] / 4]}{q[5]:X2}{q[6]:X2}{q[7]:X2}{q[8] / 16:X1}";
public static string DecodeMcn(byte[] q) =>
$"{q[1]:X2}{q[2]:X2}{q[3]:X2}{q[4]:X2}{q[5]:X2}{q[6]:X2}{q[7] >> 4:X}";
public static string DecodeMcn(byte[] q) => $"{q[1]:X2}{q[2]:X2}{q[3]:X2}{q[4]:X2}{q[5]:X2}{q[6]:X2}{q[7] >> 4:X}";
public static byte GetIsrcCode(char c)
{
@@ -512,15 +503,14 @@ public static class Subchannel
}
}
public static byte[] Generate(int sector, uint trackSequence, int pregap, int trackStart, byte flags,
byte index)
public static byte[] Generate(int sector, uint trackSequence, int pregap, int trackStart, byte flags, byte index)
{
bool isPregap = sector < 0 || sector <= trackStart + pregap;
if(index == 0)
index = (byte)(isPregap ? 0 : 1);
byte[] sub = new byte[96];
var sub = new byte[96];
// P
if(isPregap)
@@ -540,7 +530,7 @@ public static class Subchannel
}
// Q
byte[] q = new byte[12];
var q = new byte[12];
q[0] = (byte)((flags << 4) + 1);
q[1] = (byte)trackSequence;
@@ -556,12 +546,12 @@ public static class Subchannel
sector += 150;
int min = relative / 60 / 75;
int sec = (relative / 75) - (min * 60);
int frame = relative - (min * 60 * 75) - (sec * 75);
int sec = relative / 75 - min * 60;
int frame = relative - min * 60 * 75 - sec * 75;
int amin = sector / 60 / 75;
int asec = (sector / 75) - (amin * 60);
int aframe = sector - (amin * 60 * 75) - (asec * 75);
int asec = sector / 75 - amin * 60;
int aframe = sector - amin * 60 * 75 - asec * 75;
q[3] = (byte)min;
q[4] = (byte)sec;
@@ -571,16 +561,16 @@ public static class Subchannel
q[8] = (byte)asec;
q[9] = (byte)aframe;
q[1] = (byte)(((q[1] / 10) << 4) + (q[1] % 10));
q[2] = (byte)(((q[2] / 10) << 4) + (q[2] % 10));
q[3] = (byte)(((q[3] / 10) << 4) + (q[3] % 10));
q[4] = (byte)(((q[4] / 10) << 4) + (q[4] % 10));
q[5] = (byte)(((q[5] / 10) << 4) + (q[5] % 10));
q[6] = (byte)(((q[6] / 10) << 4) + (q[6] % 10));
q[7] = (byte)(((q[7] / 10) << 4) + (q[7] % 10));
q[8] = (byte)(((q[8] / 10) << 4) + (q[8] % 10));
q[1] = (byte)(((q[1] / 10) << 4) + q[1] % 10);
q[2] = (byte)(((q[2] / 10) << 4) + q[2] % 10);
q[3] = (byte)(((q[3] / 10) << 4) + q[3] % 10);
q[4] = (byte)(((q[4] / 10) << 4) + q[4] % 10);
q[5] = (byte)(((q[5] / 10) << 4) + q[5] % 10);
q[6] = (byte)(((q[6] / 10) << 4) + q[6] % 10);
q[7] = (byte)(((q[7] / 10) << 4) + q[7] % 10);
q[8] = (byte)(((q[8] / 10) << 4) + q[8] % 10);
q[9] = (byte)(((q[9] / 10) << 4) + (q[9] % 10));
q[9] = (byte)(((q[9] / 10) << 4) + q[9] % 10);
CRC16CCITTContext.Data(q, 10, out byte[] qCrc);
q[10] = qCrc[0];

View File

@@ -30,13 +30,13 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Decoders.CD;
// Information from the following standards:
// ANSI X3.304-1997
// T10/1048-D revision 9.0
@@ -80,16 +80,16 @@ public static class TOC
return null;
}
for(int i = 0; i < (decoded.DataLength - 2) / 8; i++)
for(var i = 0; i < (decoded.DataLength - 2) / 8; i++)
{
decoded.TrackDescriptors[i].Reserved1 = CDTOCResponse[0 + (i * 8) + 4];
decoded.TrackDescriptors[i].ADR = (byte)((CDTOCResponse[1 + (i * 8) + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].CONTROL = (byte)(CDTOCResponse[1 + (i * 8) + 4] & 0x0F);
decoded.TrackDescriptors[i].TrackNumber = CDTOCResponse[2 + (i * 8) + 4];
decoded.TrackDescriptors[i].Reserved2 = CDTOCResponse[3 + (i * 8) + 4];
decoded.TrackDescriptors[i].Reserved1 = CDTOCResponse[0 + i * 8 + 4];
decoded.TrackDescriptors[i].ADR = (byte)((CDTOCResponse[1 + i * 8 + 4] & 0xF0) >> 4);
decoded.TrackDescriptors[i].CONTROL = (byte)(CDTOCResponse[1 + i * 8 + 4] & 0x0F);
decoded.TrackDescriptors[i].TrackNumber = CDTOCResponse[2 + i * 8 + 4];
decoded.TrackDescriptors[i].Reserved2 = CDTOCResponse[3 + i * 8 + 4];
decoded.TrackDescriptors[i].TrackStartAddress =
BigEndianBitConverter.ToUInt32(CDTOCResponse, 4 + (i * 8) + 4);
BigEndianBitConverter.ToUInt32(CDTOCResponse, 4 + i * 8 + 4);
}
return decoded;