diff --git a/CD/Subchannel.cs b/CD/Subchannel.cs index cd94fdd5b..49b2ef1c5 100644 --- a/CD/Subchannel.cs +++ b/CD/Subchannel.cs @@ -1,3 +1,4 @@ +using System; using Aaru.Checksums; namespace Aaru.Decoders.CD @@ -482,5 +483,84 @@ namespace Aaru.Decoders.CD default: return 0x00; } } + + 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]; + + // P + if(isPregap) + { + sub[0] = 0xFF; + sub[1] = 0xFF; + sub[2] = 0xFF; + sub[3] = 0xFF; + sub[4] = 0xFF; + sub[5] = 0xFF; + sub[6] = 0xFF; + sub[7] = 0xFF; + sub[8] = 0xFF; + sub[9] = 0xFF; + sub[10] = 0xFF; + sub[11] = 0xFF; + } + + // Q + byte[] q = new byte[12]; + + q[0] = (byte)((flags << 4) + 1); + q[1] = (byte)trackSequence; + q[2] = index; + + int relative; + + if(isPregap) + relative = (pregap + trackStart) - sector; + else + relative = sector - trackStart; + + sector += 150; + + int min = relative / 60 / 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); + + q[3] = (byte)min; + q[4] = (byte)sec; + q[5] = (byte)frame; + + q[7] = (byte)amin; + 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[9] = (byte)(((q[9] / 10) << 4) + (q[9] % 10)); + + CRC16CCITTContext.Data(q, 10, out byte[] qCrc); + q[10] = qCrc[0]; + q[11] = qCrc[1]; + + Array.Copy(q, 0, sub, 12, 12); + + return Interleave(sub); + } } } \ No newline at end of file diff --git a/SCSI/Sense.cs b/SCSI/Sense.cs index 98e3ac41f..dd7aa16bf 100644 --- a/SCSI/Sense.cs +++ b/SCSI/Sense.cs @@ -213,11 +213,10 @@ namespace Aaru.Decoders.SCSI var decoded = new FixedSense { - InformationValid = (sense[0] & 0x80) == 0x80, SegmentNumber = sense[1], - Filemark = (sense[2] & 0x80) == 0x80, EOM = (sense[2] & 0x40) == 0x40, - ILI = (sense[2] & 0x20) == 0x20, - SenseKey = (SenseKeys)(sense[2] & 0x0F), - Information = (uint)((sense[3] << 24) + (sense[4] << 16) + (sense[5] << 8) + sense[6]), + InformationValid = (sense[0] & 0x80) == 0x80, SegmentNumber = sense[1], + Filemark = (sense[2] & 0x80) == 0x80, EOM = (sense[2] & 0x40) == 0x40, ILI = (sense[2] & 0x20) == 0x20, + SenseKey = (SenseKeys)(sense[2] & 0x0F), + Information = (uint)((sense[3] << 24) + (sense[4] << 16) + (sense[5] << 8) + sense[6]), AdditionalLength = sense[7] }; @@ -258,6 +257,11 @@ namespace Aaru.Decoders.SCSI if(sense.Length < 8) return null; + // Fixed sense + if((sense[0] & 0x7F) == 0x70 || + (sense[0] & 0x7F) == 0x71) + return null; + var decoded = new DescriptorSense { SenseKey = (SenseKeys)(sense[1] & 0x0F), ASC = sense[2], ASCQ = sense[3], @@ -512,12 +516,11 @@ namespace Aaru.Decoders.SCSI public static AtaErrorRegistersLba48 DecodeDescriptor09(byte[] descriptor) => new AtaErrorRegistersLba48 { - Error = descriptor[3], SectorCount = (ushort)((descriptor[4] << 8) + descriptor[5]), - LbaLow = (ushort)((descriptor[6] << 8) + descriptor[7]), - LbaMid = (ushort)((descriptor[8] << 8) + descriptor[9]), - LbaHigh = (ushort)((descriptor[10] << 8) + descriptor[11]), - DeviceHead = descriptor[12], - Status = descriptor[13] + Error = descriptor[3], SectorCount = (ushort)((descriptor[4] << 8) + descriptor[5]), + LbaLow = (ushort)((descriptor[6] << 8) + descriptor[7]), + LbaMid = (ushort)((descriptor[8] << 8) + descriptor[9]), + LbaHigh = (ushort)((descriptor[10] << 8) + descriptor[11]), DeviceHead = descriptor[12], + Status = descriptor[13] }; public static void DecodeDescriptor0B(byte[] descriptor) => throw new NotImplementedException("Check SBC-3");