REFACTOR: All refactor in DiscImageChef.Decoders.

This commit is contained in:
2017-12-22 02:04:18 +00:00
parent 7f829422a8
commit 49144eeb01
148 changed files with 2606 additions and 1939 deletions

View File

@@ -31,10 +31,15 @@
// ****************************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace DiscImageChef.Decoders.MMC
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
[SuppressMessage("ReSharper", "NotAccessedField.Global")]
public class CSD
{
public byte Structure;
@@ -72,18 +77,18 @@ namespace DiscImageChef.Decoders.MMC
public byte CRC;
}
public partial class Decoders
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static partial class Decoders
{
public static CSD DecodeCSD(uint[] response)
{
if(response == null) return null;
if(response.Length != 4) return null;
if(response?.Length != 4) return null;
byte[] data = new byte[16];
byte[] tmp;
tmp = BitConverter.GetBytes(response[0]);
byte[] tmp = BitConverter.GetBytes(response[0]);
Array.Copy(tmp, 0, data, 0, 4);
tmp = BitConverter.GetBytes(response[1]);
Array.Copy(tmp, 0, data, 4, 4);
@@ -97,47 +102,44 @@ namespace DiscImageChef.Decoders.MMC
public static CSD DecodeCSD(byte[] response)
{
if(response == null) return null;
if(response?.Length != 16) return null;
if(response.Length != 16) return null;
CSD csd = new CSD();
csd.Structure = (byte)((response[0] & 0xC0) >> 6);
csd.Version = (byte)((response[0] & 0x3C) >> 2);
csd.TAAC = response[1];
csd.NSAC = response[2];
csd.Speed = response[3];
csd.Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4));
csd.ReadBlockLength = (byte)(response[5] & 0x0F);
csd.ReadsPartialBlocks = (response[6] & 0x80) == 0x80;
csd.WriteMisalignment = (response[6] & 0x40) == 0x40;
csd.ReadMisalignment = (response[6] & 0x20) == 0x20;
csd.DSRImplemented = (response[6] & 0x10) == 0x10;
csd.Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6));
csd.ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3);
csd.ReadCurrentAtVddMax = (byte)(response[8] & 0x07);
csd.WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5);
csd.WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2);
csd.SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7));
csd.EraseGroupSize = (byte)((response[10] & 0x7C) >> 2);
csd.EraseGroupSizeMultiplier = (byte)(((response[10] & 0x03) << 3) + ((response[11] & 0xE0) >> 5));
csd.WriteProtectGroupSize = (byte)(response[11] & 0x1F);
csd.WriteProtectGroupEnable = (response[12] & 0x80) == 0x80;
csd.DefaultECC = (byte)((response[12] & 0x60) >> 5);
csd.WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2);
csd.WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6));
csd.WritesPartialBlocks = (response[13] & 0x20) == 0x20;
csd.ContentProtection = (response[13] & 0x01) == 0x01;
csd.FileFormatGroup = (response[14] & 0x80) == 0x80;
csd.Copy = (response[14] & 0x40) == 0x40;
csd.PermanentWriteProtect = (response[14] & 0x20) == 0x20;
csd.TemporaryWriteProtect = (response[14] & 0x10) == 0x10;
csd.FileFormat = (byte)((response[14] & 0x0C) >> 2);
csd.ECC = (byte)(response[14] & 0x03);
csd.CRC = (byte)((response[15] & 0xFE) >> 1);
return csd;
return new CSD
{
Structure = (byte)((response[0] & 0xC0) >> 6),
Version = (byte)((response[0] & 0x3C) >> 2),
TAAC = response[1],
NSAC = response[2],
Speed = response[3],
Classes = (ushort)((response[4] << 4) + ((response[5] & 0xF0) >> 4)),
ReadBlockLength = (byte)(response[5] & 0x0F),
ReadsPartialBlocks = (response[6] & 0x80) == 0x80,
WriteMisalignment = (response[6] & 0x40) == 0x40,
ReadMisalignment = (response[6] & 0x20) == 0x20,
DSRImplemented = (response[6] & 0x10) == 0x10,
Size = (ushort)(((response[6] & 0x03) << 10) + (response[7] << 2) + ((response[8] & 0xC0) >> 6)),
ReadCurrentAtVddMin = (byte)((response[8] & 0x38) >> 3),
ReadCurrentAtVddMax = (byte)(response[8] & 0x07),
WriteCurrentAtVddMin = (byte)((response[9] & 0xE0) >> 5),
WriteCurrentAtVddMax = (byte)((response[9] & 0x1C) >> 2),
SizeMultiplier = (byte)(((response[9] & 0x03) << 1) + ((response[10] & 0x80) >> 7)),
EraseGroupSize = (byte)((response[10] & 0x7C) >> 2),
EraseGroupSizeMultiplier = (byte)(((response[10] & 0x03) << 3) + ((response[11] & 0xE0) >> 5)),
WriteProtectGroupSize = (byte)(response[11] & 0x1F),
WriteProtectGroupEnable = (response[12] & 0x80) == 0x80,
DefaultECC = (byte)((response[12] & 0x60) >> 5),
WriteSpeedFactor = (byte)((response[12] & 0x1C) >> 2),
WriteBlockLength = (byte)(((response[12] & 0x03) << 2) + ((response[13] & 0xC0) >> 6)),
WritesPartialBlocks = (response[13] & 0x20) == 0x20,
ContentProtection = (response[13] & 0x01) == 0x01,
FileFormatGroup = (response[14] & 0x80) == 0x80,
Copy = (response[14] & 0x40) == 0x40,
PermanentWriteProtect = (response[14] & 0x20) == 0x20,
TemporaryWriteProtect = (response[14] & 0x10) == 0x10,
FileFormat = (byte)((response[14] & 0x0C) >> 2),
ECC = (byte)(response[14] & 0x03),
CRC = (byte)((response[15] & 0xFE) >> 1)
};
}
public static string PrettifyCSD(CSD csd)