General code cleanup and style refactor.

This commit is contained in:
2022-11-15 15:58:41 +00:00
parent aa5278fa0d
commit bc415e205f
120 changed files with 2455 additions and 2554 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

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
@@ -117,17 +117,17 @@ public static class CDTextOnLeadIn
return null;
}
for(var i = 0; i < (decoded.DataLength - 2) / 18; i++)
for(int 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;

View File

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

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -41,6 +39,8 @@ 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
@@ -90,22 +90,22 @@ public static class FullTOC
return null;
}
for(var i = 0; i < (decoded.DataLength - 2) / 11; i++)
for(int 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;
@@ -120,14 +120,14 @@ public static class FullTOC
var sb = new StringBuilder();
var lastSession = 0;
int 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");
@@ -340,7 +340,7 @@ public static class FullTOC
descriptor.POINT).AppendLine();
else
{
var type = "Audio";
string type = "Audio";
if((TocControl)(descriptor.CONTROL & 0x0D) == TocControl.DataTrack ||
(TocControl)(descriptor.CONTROL & 0x0D) == TocControl.DataTrackIncremental)
@@ -558,7 +558,7 @@ public static class FullTOC
case 6:
{
var id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
uint id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
sb.AppendFormat("Disc ID: {0:X6}", id & 0x00FFFFFF).AppendLine();
break;

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,21 +80,21 @@ public static class PMA
return null;
}
for(var i = 0; i < (decoded.DataLength - 2) / 11; i++)
for(int 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;
@@ -180,7 +180,7 @@ public static class PMA
break;
case 2:
var id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
uint id = (uint)((descriptor.Min << 16) + (descriptor.Sec << 8) + descriptor.Frame);
sb.AppendFormat("Disc ID: {0:X6}", id & 0x00FFFFFF).AppendLine();
break;

View File

@@ -30,8 +30,6 @@
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Decoders.CD;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -39,6 +37,8 @@ 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;
var sync = new byte[12];
byte[] sync = new byte[12];
Array.Copy(sector, 0, sync, 0, 12);
if(!SyncMark.SequenceEqual(sync))
return sector;
var scrambled = new byte[sector.Length];
byte[] scrambled = new byte[sector.Length];
for(var i = 0; i < 2352; i++)
for(int i = 0; i < 2352; i++)
scrambled[i] = (byte)(sector[i] ^ ScrambleTable[i]);
if(sector.Length <= 2352)
return scrambled;
for(var i = 2352; i < sector.Length; i++)
for(int 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:
var sector = new byte[2048];
byte[] 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;
var pos = 0;
int 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;
var sector = new byte[len];
byte[] 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];
var lba = 0;
var moreThan90 = false;
int lba = 0;
bool 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,13 +381,13 @@ public static class Sector
CdChecksums.CheckCdSector(buffer, out bool? correctEccP, out bool? correctEccQ, out bool? correctEdc);
var empty = true;
bool empty = true;
switch(buffer[15] & 0x03)
{
case 0:
for(var i = 16; i < 2352; i++)
for(int i = 16; i < 2352; i++)
if(buffer[i] != 0x00)
{
empty = false;
@@ -403,7 +403,7 @@ 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(var i = 2068; i < 2076; i++)
for(int i = 2068; i < 2076; i++)
if(buffer[i] != 0x00)
{
empty = false;

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;
var j = (uint)((i << 1) ^ ((i & 0x80) == 0x80 ? 0x11D : 0));
uint 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;
}
var zeroaddress = new byte[4];
byte[] zeroaddress = new byte[4];
switch(type)
{
@@ -210,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
@@ -76,16 +76,16 @@ public static class Session
return null;
}
for(var i = 0; i < (decoded.DataLength - 2) / 8; i++)
for(int 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;

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,25 +71,25 @@ 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)
{
var pos = 0;
var subBuf = new byte[subchannel.Length * 6];
int pos = 0;
byte[] subBuf = new byte[subchannel.Length * 6];
for(var i = 0; i < subchannel.Length; i += 16)
for(int i = 0; i < subchannel.Length; i += 16)
{
// P
if((subchannel[i + 15] & 0x80) <= 0)
@@ -133,13 +133,13 @@ public static class Subchannel
public static byte[] Interleave(byte[] subchannel)
{
var subBuf = new byte[subchannel.Length];
byte[] subBuf = new byte[subchannel.Length];
var outPos = 0;
int outPos = 0;
for(var inPos = 0; inPos < subchannel.Length; inPos += 96)
for(int inPos = 0; inPos < subchannel.Length; inPos += 96)
{
for(var i = 0; i < 12; i++)
for(int i = 0; i < 12; i++)
{
// P
subBuf[outPos + 0] += (byte)(subchannel[inPos + i + 0] & 0x80);
@@ -229,12 +229,12 @@ public static class Subchannel
public static byte[] Deinterleave(byte[] subchannel)
{
var subBuf = new byte[subchannel.Length];
var inPos = 0;
byte[] subBuf = new byte[subchannel.Length];
int inPos = 0;
for(var outPos = 0; outPos < subchannel.Length; outPos += 96)
for(int outPos = 0; outPos < subchannel.Length; outPos += 96)
{
for(var i = 0; i < 12; i++)
for(int i = 0; i < 12; i++)
{
// P
subBuf[outPos + i + 0] += (byte)((subchannel[inPos + 0] & 0x80) >> 0);
@@ -336,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);
@@ -379,12 +379,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"
@@ -546,90 +546,87 @@ 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}";
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}";
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) => c switch
{
'0' => 0x00,
'1' => 0x01,
'2' => 0x02,
'3' => 0x03,
'4' => 0x04,
'5' => 0x05,
'6' => 0x06,
'7' => 0x07,
'8' => 0x08,
'9' => 0x09,
'A' => 0x11,
'B' => 0x12,
'C' => 0x13,
'D' => 0x14,
'E' => 0x15,
'F' => 0x16,
'G' => 0x17,
'H' => 0x18,
'I' => 0x19,
'J' => 0x1A,
'K' => 0x1B,
'L' => 0x1C,
'M' => 0x1D,
'N' => 0x1E,
'O' => 0x1F,
'P' => 0x20,
'Q' => 0x21,
'R' => 0x22,
'S' => 0x23,
'T' => 0x24,
'U' => 0x25,
'V' => 0x26,
'W' => 0x27,
'X' => 0x28,
'Y' => 0x29,
'Z' => 0x2A,
_ => 0x00
};
{
'0' => 0x00,
'1' => 0x01,
'2' => 0x02,
'3' => 0x03,
'4' => 0x04,
'5' => 0x05,
'6' => 0x06,
'7' => 0x07,
'8' => 0x08,
'9' => 0x09,
'A' => 0x11,
'B' => 0x12,
'C' => 0x13,
'D' => 0x14,
'E' => 0x15,
'F' => 0x16,
'G' => 0x17,
'H' => 0x18,
'I' => 0x19,
'J' => 0x1A,
'K' => 0x1B,
'L' => 0x1C,
'M' => 0x1D,
'N' => 0x1E,
'O' => 0x1F,
'P' => 0x20,
'Q' => 0x21,
'R' => 0x22,
'S' => 0x23,
'T' => 0x24,
'U' => 0x25,
'V' => 0x26,
'W' => 0x27,
'X' => 0x28,
'Y' => 0x29,
'Z' => 0x2A,
_ => 0x00
};
public static byte[] Generate(int sector, uint trackSequence, int pregap, int trackStart, byte flags, byte index)
{
@@ -638,7 +635,7 @@ public static class Subchannel
if(index == 0)
index = (byte)(isPregap ? 0 : 1);
var sub = new byte[96];
byte[] sub = new byte[96];
// P
if(isPregap)
@@ -658,7 +655,7 @@ public static class Subchannel
}
// Q
var q = new byte[12];
byte[] q = new byte[12];
q[0] = (byte)((flags << 4) + 1);
q[1] = (byte)trackSequence;
@@ -674,12 +671,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;
@@ -689,16 +686,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
@@ -79,16 +79,16 @@ public static class TOC
return null;
}
for(var i = 0; i < (decoded.DataLength - 2) / 8; i++)
for(int 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;