Files
Aaru/SCSI/Modes/05.cs

313 lines
14 KiB
C#
Raw Normal View History

2017-12-21 02:03:21 +00:00
// /***************************************************************************
2020-02-27 12:31:23 +00:00
// Aaru Data Preservation Suite
2017-12-21 02:03:21 +00:00
// ----------------------------------------------------------------------------
//
// Filename : 05.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Device structures decoders.
//
// --[ Description ] ----------------------------------------------------------
//
// Decodes SCSI MODE PAGE 05h: Flexible disk page.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2020-12-31 23:08:22 +00:00
// Copyright © 2011-2021 Natalia Portillo
2017-12-21 02:03:21 +00:00
// ****************************************************************************/
using System.Diagnostics.CodeAnalysis;
2017-12-21 02:03:21 +00:00
using System.Text;
2020-02-27 00:33:24 +00:00
namespace Aaru.Decoders.SCSI
2017-12-21 02:03:21 +00:00
{
2019-11-25 00:54:38 +00:00
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
2017-12-21 02:03:21 +00:00
public static partial class Modes
{
#region Mode Page 0x05: Flexible disk page
2019-11-25 00:54:38 +00:00
/// <summary>Disconnect-reconnect page Page code 0x05 32 bytes in SCSI-2, SBC-1</summary>
2017-12-21 02:03:21 +00:00
public struct ModePage_05
{
2019-11-25 00:54:38 +00:00
/// <summary>Parameters can be saved</summary>
2017-12-21 02:03:21 +00:00
public bool PS;
2019-11-25 00:54:38 +00:00
/// <summary>Data rate of peripheral device on kbit/s</summary>
2017-12-21 02:03:21 +00:00
public ushort TransferRate;
2019-11-25 00:54:38 +00:00
/// <summary>Heads for reading and/or writing</summary>
2017-12-21 02:03:21 +00:00
public byte Heads;
2019-11-25 00:54:38 +00:00
/// <summary>Sectors per revolution per head</summary>
2017-12-21 02:03:21 +00:00
public byte SectorsPerTrack;
2019-11-25 00:54:38 +00:00
/// <summary>Bytes of data per sector</summary>
2017-12-21 02:03:21 +00:00
public ushort BytesPerSector;
2019-11-25 00:54:38 +00:00
/// <summary>Cylinders used for data storage</summary>
2017-12-21 02:03:21 +00:00
public ushort Cylinders;
2019-11-25 00:54:38 +00:00
/// <summary>Cylinder where write precompensation starts</summary>
2017-12-21 02:03:21 +00:00
public ushort WritePrecompCylinder;
2019-11-25 00:54:38 +00:00
/// <summary>Cylinder where write current reduction starts</summary>
2017-12-21 02:03:21 +00:00
public ushort WriteReduceCylinder;
2019-11-25 00:54:38 +00:00
/// <summary>Step rate in 100 μs units</summary>
2017-12-21 02:03:21 +00:00
public ushort DriveStepRate;
2019-11-25 00:54:38 +00:00
/// <summary>Width of step pulse in μs</summary>
2017-12-21 02:03:21 +00:00
public byte DriveStepPulse;
2019-11-25 00:54:38 +00:00
/// <summary>Head settle time in 100 μs units</summary>
2017-12-21 02:03:21 +00:00
public ushort HeadSettleDelay;
/// <summary>
2019-11-25 00:54:38 +00:00
/// If <see cref="TRDY" /> is <c>true</c>, specified in 1/10s of a second the time waiting for read status before
/// aborting medium access. Otherwise, indicates time to way before medimum access after motor on signal is asserted.
2017-12-21 02:03:21 +00:00
/// </summary>
public byte MotorOnDelay;
/// <summary>
2019-11-25 00:54:38 +00:00
/// Time in 1/10s of a second to wait before releasing the motor on signal after an idle condition. 0xFF means to
/// never release the signal
2017-12-21 02:03:21 +00:00
/// </summary>
public byte MotorOffDelay;
2019-11-25 00:54:38 +00:00
/// <summary>Specifies if a signal indicates that the medium is ready to be accessed</summary>
2017-12-21 02:03:21 +00:00
public bool TRDY;
2019-11-25 00:54:38 +00:00
/// <summary>If <c>true</c> sectors start with one. Otherwise, they start with zero.</summary>
2017-12-21 02:03:21 +00:00
public bool SSN;
2019-11-25 00:54:38 +00:00
/// <summary>If <c>true</c> specifies that motor on shall remain released.</summary>
2017-12-21 02:03:21 +00:00
public bool MO;
2019-11-25 00:54:38 +00:00
/// <summary>Number of additional step pulses per cylinder.</summary>
2017-12-21 02:03:21 +00:00
public byte SPC;
2019-11-25 00:54:38 +00:00
/// <summary>Write compensation value</summary>
2017-12-21 02:03:21 +00:00
public byte WriteCompensation;
2019-11-25 00:54:38 +00:00
/// <summary>Head loading time in ms.</summary>
2017-12-21 02:03:21 +00:00
public byte HeadLoadDelay;
2019-11-25 00:54:38 +00:00
/// <summary>Head unloading time in ms.</summary>
2017-12-21 02:03:21 +00:00
public byte HeadUnloadDelay;
2019-11-25 00:54:38 +00:00
/// <summary>Description of shugart's bus pin 34 usage</summary>
2017-12-21 02:03:21 +00:00
public byte Pin34;
2019-11-25 00:54:38 +00:00
/// <summary>Description of shugart's bus pin 2 usage</summary>
2017-12-21 02:03:21 +00:00
public byte Pin2;
2019-11-25 00:54:38 +00:00
/// <summary>Description of shugart's bus pin 4 usage</summary>
2017-12-21 02:03:21 +00:00
public byte Pin4;
2019-11-25 00:54:38 +00:00
/// <summary>Description of shugart's bus pin 1 usage</summary>
2017-12-21 02:03:21 +00:00
public byte Pin1;
2019-11-25 00:54:38 +00:00
/// <summary>Medium speed in rpm</summary>
2017-12-21 02:03:21 +00:00
public ushort MediumRotationRate;
}
public static ModePage_05? DecodeModePage_05(byte[] pageResponse)
{
2019-11-25 00:54:38 +00:00
if((pageResponse?[0] & 0x40) == 0x40)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if((pageResponse?[0] & 0x3F) != 0x05)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if(pageResponse[1] + 2 != pageResponse.Length)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if(pageResponse.Length < 32)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
var decoded = new ModePage_05();
2017-12-21 02:03:21 +00:00
2018-06-22 08:08:38 +01:00
decoded.PS |= (pageResponse[0] & 0x80) == 0x80;
decoded.TransferRate = (ushort)((pageResponse[2] << 8) + pageResponse[3]);
decoded.Heads = pageResponse[4];
decoded.SectorsPerTrack = pageResponse[5];
decoded.BytesPerSector = (ushort)((pageResponse[6] << 8) + pageResponse[7]);
decoded.Cylinders = (ushort)((pageResponse[8] << 8) + pageResponse[9]);
decoded.WritePrecompCylinder = (ushort)((pageResponse[10] << 8) + pageResponse[11]);
decoded.WriteReduceCylinder = (ushort)((pageResponse[12] << 8) + pageResponse[13]);
decoded.DriveStepRate = (ushort)((pageResponse[14] << 8) + pageResponse[15]);
decoded.DriveStepPulse = pageResponse[16];
decoded.HeadSettleDelay = (ushort)((pageResponse[17] << 8) + pageResponse[18]);
decoded.MotorOnDelay = pageResponse[19];
decoded.MotorOffDelay = pageResponse[20];
decoded.TRDY |= (pageResponse[21] & 0x80) == 0x80;
decoded.SSN |= (pageResponse[21] & 0x40) == 0x40;
decoded.MO |= (pageResponse[21] & 0x20) == 0x20;
decoded.SPC = (byte)(pageResponse[22] & 0x0F);
decoded.WriteCompensation = pageResponse[23];
decoded.HeadLoadDelay = pageResponse[24];
decoded.HeadUnloadDelay = pageResponse[25];
decoded.Pin34 = (byte)((pageResponse[26] & 0xF0) >> 4);
decoded.Pin2 = (byte)(pageResponse[26] & 0x0F);
decoded.Pin4 = (byte)((pageResponse[27] & 0xF0) >> 4);
decoded.Pin1 = (byte)(pageResponse[27] & 0x0F);
decoded.MediumRotationRate = (ushort)((pageResponse[28] << 8) + pageResponse[29]);
2017-12-21 02:03:21 +00:00
return decoded;
}
2018-12-31 13:17:27 +00:00
public static string PrettifyModePage_05(byte[] pageResponse) =>
PrettifyModePage_05(DecodeModePage_05(pageResponse));
2017-12-21 02:03:21 +00:00
public static string PrettifyModePage_05(ModePage_05? modePage)
{
2019-11-25 00:54:38 +00:00
if(!modePage.HasValue)
return null;
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
ModePage_05 page = modePage.Value;
var sb = new StringBuilder();
2017-12-21 02:03:21 +00:00
sb.AppendLine("SCSI Flexible disk page:");
2019-11-25 00:54:38 +00:00
if(page.PS)
sb.AppendLine("\tParameters can be saved");
2017-12-21 02:03:21 +00:00
sb.AppendFormat("\tTransfer rate: {0} kbit/s", page.TransferRate).AppendLine();
sb.AppendFormat("\t{0} heads", page.Heads).AppendLine();
sb.AppendFormat("\t{0} cylinders", page.Cylinders).AppendLine();
sb.AppendFormat("\t{0} sectors per track", page.SectorsPerTrack).AppendLine();
sb.AppendFormat("\t{0} bytes per sector", page.BytesPerSector).AppendLine();
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
if(page.WritePrecompCylinder < page.Cylinders)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("\tWrite pre-compensation starts at cylinder {0}", page.WritePrecompCylinder).
AppendLine();
2017-12-21 02:03:21 +00:00
if(page.WriteReduceCylinder < page.Cylinders)
2019-11-25 00:54:38 +00:00
sb.AppendFormat("\tWrite current reduction starts at cylinder {0}", page.WriteReduceCylinder).
AppendLine();
2017-12-21 02:03:21 +00:00
if(page.DriveStepRate > 0)
sb.AppendFormat("\tDrive steps in {0} μs", (uint)page.DriveStepRate * 100).AppendLine();
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
if(page.DriveStepPulse > 0)
sb.AppendFormat("\tEach step pulse is {0} ms", page.DriveStepPulse).AppendLine();
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
if(page.HeadSettleDelay > 0)
sb.AppendFormat("\tHeads settles in {0} μs", (uint)page.HeadSettleDelay * 100).AppendLine();
if(!page.TRDY)
2019-11-25 00:54:38 +00:00
sb.
AppendFormat("\tTarget shall wait {0} seconds before attempting to access the medium after motor on is asserted",
2018-06-22 08:08:38 +01:00
(double)page.MotorOnDelay * 10).AppendLine();
2017-12-21 02:03:21 +00:00
else
2019-11-25 00:54:38 +00:00
sb.
AppendFormat("\tTarget shall wait {0} seconds after drive is ready before aborting medium access attemps",
2018-06-22 08:08:38 +01:00
(double)page.MotorOnDelay * 10).AppendLine();
2017-12-21 02:03:21 +00:00
if(page.MotorOffDelay != 0xFF)
2019-11-25 00:54:38 +00:00
sb.
AppendFormat("\tTarget shall wait {0} seconds before releasing the motor on signal after becoming idle",
2018-06-22 08:08:38 +01:00
(double)page.MotorOffDelay * 10).AppendLine();
2019-11-25 00:54:38 +00:00
else
sb.AppendLine("\tTarget shall never release the motor on signal");
if(page.TRDY)
sb.AppendLine("\tThere is a drive ready signal");
2017-12-21 02:03:21 +00:00
2019-11-25 00:54:38 +00:00
if(page.SSN)
sb.AppendLine("\tSectors start at 1");
if(page.MO)
sb.AppendLine("\tThe motor on signal shall remain released");
2017-12-21 02:03:21 +00:00
sb.AppendFormat("\tDrive needs to do {0} step pulses per cylinder", page.SPC + 1).AppendLine();
if(page.WriteCompensation > 0)
sb.AppendFormat("\tWrite pre-compensation is {0}", page.WriteCompensation).AppendLine();
2019-11-25 00:54:38 +00:00
if(page.HeadLoadDelay > 0)
sb.AppendFormat("\tHead takes {0} ms to load", page.HeadLoadDelay).AppendLine();
2017-12-21 02:03:21 +00:00
if(page.HeadUnloadDelay > 0)
sb.AppendFormat("\tHead takes {0} ms to unload", page.HeadUnloadDelay).AppendLine();
if(page.MediumRotationRate > 0)
sb.AppendFormat("\tMedium rotates at {0} rpm", page.MediumRotationRate).AppendLine();
switch(page.Pin34 & 0x07)
{
case 0:
sb.AppendLine("\tPin 34 is unconnected");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 1:
sb.Append("\tPin 34 indicates drive is ready when active ");
sb.Append((page.Pin34 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 2:
sb.Append("\tPin 34 indicates disk has changed when active ");
sb.Append((page.Pin34 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
default:
sb.AppendFormat("\tPin 34 indicates unknown function {0} when active ", page.Pin34 & 0x07);
sb.Append((page.Pin34 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
}
switch(page.Pin4 & 0x07)
{
case 0:
sb.AppendLine("\tPin 4 is unconnected");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 1:
sb.Append("\tPin 4 indicates drive is in use when active ");
sb.Append((page.Pin4 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 2:
sb.Append("\tPin 4 indicates eject when active ");
sb.Append((page.Pin4 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 3:
sb.Append("\tPin 4 indicates head load when active ");
sb.Append((page.Pin4 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
default:
sb.AppendFormat("\tPin 4 indicates unknown function {0} when active ", page.Pin4 & 0x07);
sb.Append((page.Pin4 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
}
switch(page.Pin2 & 0x07)
{
case 0:
sb.AppendLine("\tPin 2 is unconnected");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
default:
sb.AppendFormat("\tPin 2 indicates unknown function {0} when active ", page.Pin2 & 0x07);
sb.Append((page.Pin2 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
}
switch(page.Pin1 & 0x07)
{
case 0:
sb.AppendLine("\tPin 1 is unconnected");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
case 1:
sb.Append("\tPin 1 indicates disk change reset when active ");
sb.Append((page.Pin1 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
default:
sb.AppendFormat("\tPin 1 indicates unknown function {0} when active ", page.Pin1 & 0x07);
sb.Append((page.Pin1 & 0x08) == 0x08 ? "high" : "low");
2019-11-25 00:54:38 +00:00
2017-12-21 02:03:21 +00:00
break;
}
return sb.ToString();
}
#endregion Mode Page 0x05: Flexible disk page
}
}