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

@@ -37,14 +37,14 @@ namespace DiscImageChef.Devices
{
public partial class Device
{
public bool ReadBuffer(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint timeout,
public bool ReadBuffer(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
out double duration)
{
buffer = new byte[512];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
registers.command = (byte)AtaCommands.ReadBuffer;
registers.Command = (byte)AtaCommands.ReadBuffer;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
@@ -56,14 +56,14 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadBufferDma(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint timeout,
public bool ReadBufferDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
out double duration)
{
buffer = new byte[512];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
registers.command = (byte)AtaCommands.ReadBufferDma;
registers.Command = (byte)AtaCommands.ReadBufferDma;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.NoTransfer,
ref buffer, timeout, false, out duration, out sense);
@@ -74,28 +74,28 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, byte count,
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
{
return ReadDma(out buffer, out statusRegisters, true, lba, count, timeout, out duration);
}
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, bool retry, uint lba,
public bool ReadDma(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
byte count, uint timeout, out double duration)
{
if(count == 0) buffer = new byte[512 * 256];
else buffer = new byte[512 * count];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
if(retry) registers.command = (byte)AtaCommands.ReadDmaRetry;
else registers.command = (byte)AtaCommands.ReadDma;
registers.sectorCount = count;
registers.deviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.lbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.lbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.lbaLow = (byte)((lba & 0xFF) / 0x1);
registers.deviceHead += 0x40;
if(retry) registers.Command = (byte)AtaCommands.ReadDmaRetry;
else registers.Command = (byte)AtaCommands.ReadDma;
registers.SectorCount = count;
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.Dma, AtaTransferRegister.SectorCount,
ref buffer, timeout, true, out duration, out sense);
@@ -106,21 +106,21 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, byte count,
public bool ReadMultiple(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
{
if(count == 0) buffer = new byte[512 * 256];
else buffer = new byte[512 * count];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
registers.command = (byte)AtaCommands.ReadMultiple;
registers.sectorCount = count;
registers.deviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.lbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.lbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.lbaLow = (byte)((lba & 0xFF) / 0x1);
registers.deviceHead += 0x40;
registers.Command = (byte)AtaCommands.ReadMultiple;
registers.SectorCount = count;
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
@@ -132,29 +132,29 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadNativeMaxAddress(out uint lba, out AtaErrorRegistersLBA28 statusRegisters, uint timeout,
public bool ReadNativeMaxAddress(out uint lba, out AtaErrorRegistersLba28 statusRegisters, uint timeout,
out double duration)
{
lba = 0;
byte[] buffer = new byte[0];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
registers.command = (byte)AtaCommands.ReadNativeMaxAddress;
registers.deviceHead += 0x40;
registers.Command = (byte)AtaCommands.ReadNativeMaxAddress;
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,
out sense);
Error = LastError != 0;
if((statusRegisters.status & 0x23) == 0)
if((statusRegisters.Status & 0x23) == 0)
{
lba += (uint)(statusRegisters.deviceHead & 0xF);
lba += (uint)(statusRegisters.DeviceHead & 0xF);
lba *= 0x1000000;
lba += (uint)(statusRegisters.lbaHigh << 16);
lba += (uint)(statusRegisters.lbaMid << 8);
lba += statusRegisters.lbaLow;
lba += (uint)(statusRegisters.LbaHigh << 16);
lba += (uint)(statusRegisters.LbaMid << 8);
lba += statusRegisters.LbaLow;
}
DicConsole.DebugWriteLine("ATA Device", "READ NATIVE MAX ADDRESS took {0} ms.", duration);
@@ -162,28 +162,28 @@ namespace DiscImageChef.Devices
return sense;
}
public bool Read(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, byte count,
public bool Read(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, byte count,
uint timeout, out double duration)
{
return Read(out buffer, out statusRegisters, true, lba, count, timeout, out duration);
}
public bool Read(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, bool retry, uint lba,
public bool Read(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
byte count, uint timeout, out double duration)
{
if(count == 0) buffer = new byte[512 * 256];
else buffer = new byte[512 * count];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
if(retry) registers.command = (byte)AtaCommands.ReadRetry;
else registers.command = (byte)AtaCommands.Read;
registers.sectorCount = count;
registers.deviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.lbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.lbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.lbaLow = (byte)((lba & 0xFF) / 0x1);
registers.deviceHead += 0x40;
if(retry) registers.Command = (byte)AtaCommands.ReadRetry;
else registers.Command = (byte)AtaCommands.Read;
registers.SectorCount = count;
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
@@ -195,27 +195,27 @@ namespace DiscImageChef.Devices
return sense;
}
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, uint lba, uint blockSize,
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, uint lba, uint blockSize,
uint timeout, out double duration)
{
return ReadLong(out buffer, out statusRegisters, true, lba, blockSize, timeout, out duration);
}
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLBA28 statusRegisters, bool retry, uint lba,
public bool ReadLong(out byte[] buffer, out AtaErrorRegistersLba28 statusRegisters, bool retry, uint lba,
uint blockSize, uint timeout, out double duration)
{
buffer = new byte[blockSize];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
if(retry) registers.command = (byte)AtaCommands.ReadLongRetry;
else registers.command = (byte)AtaCommands.ReadLong;
registers.sectorCount = 1;
registers.deviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.lbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.lbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.lbaLow = (byte)((lba & 0xFF) / 0x1);
registers.deviceHead += 0x40;
if(retry) registers.Command = (byte)AtaCommands.ReadLongRetry;
else registers.Command = (byte)AtaCommands.ReadLong;
registers.SectorCount = 1;
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.PioIn,
AtaTransferRegister.SectorCount, ref buffer, timeout, true, out duration,
@@ -227,18 +227,18 @@ namespace DiscImageChef.Devices
return sense;
}
public bool Seek(out AtaErrorRegistersLBA28 statusRegisters, uint lba, uint timeout, out double duration)
public bool Seek(out AtaErrorRegistersLba28 statusRegisters, uint lba, uint timeout, out double duration)
{
byte[] buffer = new byte[0];
AtaRegistersLBA28 registers = new AtaRegistersLBA28();
AtaRegistersLba28 registers = new AtaRegistersLba28();
bool sense;
registers.command = (byte)AtaCommands.Seek;
registers.deviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.lbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.lbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.lbaLow = (byte)((lba & 0xFF) / 0x1);
registers.deviceHead += 0x40;
registers.Command = (byte)AtaCommands.Seek;
registers.DeviceHead = (byte)((lba & 0xF000000) / 0x1000000);
registers.LbaHigh = (byte)((lba & 0xFF0000) / 0x10000);
registers.LbaMid = (byte)((lba & 0xFF00) / 0x100);
registers.LbaLow = (byte)((lba & 0xFF) / 0x1);
registers.DeviceHead += 0x40;
LastError = SendAtaCommand(registers, out statusRegisters, AtaProtocol.NonData,
AtaTransferRegister.NoTransfer, ref buffer, timeout, false, out duration,