Files
Aaru/Aaru.Images/TeleDisk/Identify.cs

109 lines
4.6 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Identify.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Identifies Sydex TeleDisk disk images.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2024-05-01 04:17:32 +01:00
// Copyright © 2011-2024 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
2020-02-27 00:33:26 +00:00
using Aaru.CommonTypes.Interfaces;
using Aaru.Console;
using Aaru.Helpers;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class TeleDisk
{
2023-10-03 23:34:59 +01:00
#region IMediaImage Members
2022-03-06 13:29:38 +00:00
/// <inheritdoc />
public bool Identify(IFilter imageFilter)
{
2022-03-06 13:29:38 +00:00
_header = new Header();
2023-10-03 23:34:59 +01:00
var headerBytes = new byte[12];
2022-03-06 13:29:38 +00:00
Stream stream = imageFilter.GetDataForkStream();
stream.Seek(0, SeekOrigin.Begin);
stream.EnsureRead(headerBytes, 0, 12);
2022-03-06 13:29:38 +00:00
_header.Signature = BitConverter.ToUInt16(headerBytes, 0);
2024-05-01 04:05:22 +01:00
if(_header.Signature != TD_MAGIC && _header.Signature != TD_ADV_COMP_MAGIC) return false;
2022-03-06 13:29:38 +00:00
_header.Sequence = headerBytes[2];
_header.DiskSet = headerBytes[3];
_header.Version = headerBytes[4];
_header.DataRate = headerBytes[5];
_header.DriveType = headerBytes[6];
_header.Stepping = headerBytes[7];
_header.DosAllocation = headerBytes[8];
_header.Sides = headerBytes[9];
_header.Crc = BitConverter.ToUInt16(headerBytes, 10);
2023-10-03 23:34:59 +01:00
var headerBytesForCrc = new byte[10];
2022-03-06 13:29:38 +00:00
Array.Copy(headerBytes, headerBytesForCrc, 10);
ushort calculatedHeaderCrc = TeleDiskCrc(0x0000, headerBytesForCrc);
2023-10-03 23:34:59 +01:00
AaruConsole.DebugWriteLine(MODULE_NAME, "header.signature = 0x{0:X4}", _header.Signature);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.sequence = 0x{0:X2}", _header.Sequence);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.diskSet = 0x{0:X2}", _header.DiskSet);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.version = 0x{0:X2}", _header.Version);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.dataRate = 0x{0:X2}", _header.DataRate);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.driveType = 0x{0:X2}", _header.DriveType);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.stepping = 0x{0:X2}", _header.Stepping);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.dosAllocation = 0x{0:X2}", _header.DosAllocation);
2023-10-03 23:34:59 +01:00
AaruConsole.DebugWriteLine(MODULE_NAME, "header.sides = 0x{0:X2}", _header.Sides);
AaruConsole.DebugWriteLine(MODULE_NAME, "header.crc = 0x{0:X4}", _header.Crc);
AaruConsole.DebugWriteLine(MODULE_NAME, Localization.calculated_header_crc_equals_0_X4, calculatedHeaderCrc);
2022-03-06 13:29:38 +00:00
// We need more checks as the magic is too simply.
// This may deny legal images
2022-03-06 13:29:38 +00:00
// That would be much of a coincidence
2024-05-01 04:05:22 +01:00
if(_header.Crc == calculatedHeaderCrc) return true;
2024-05-01 04:05:22 +01:00
if(_header.Sequence != 0x00) return false;
2022-03-06 13:29:38 +00:00
if(_header.DataRate != DATA_RATE_250_KBPS &&
_header.DataRate != DATA_RATE_300_KBPS &&
_header.DataRate != DATA_RATE_500_KBPS)
return false;
2024-05-01 04:05:22 +01:00
return _header.DriveType is DRIVE_TYPE_35_DD
or DRIVE_TYPE_35_ED
or DRIVE_TYPE_35_HD
or DRIVE_TYPE_525_DD
or DRIVE_TYPE_525_HD
or DRIVE_TYPE_525_HD_DD_DISK
or DRIVE_TYPE_8_INCH;
}
2023-10-03 23:34:59 +01:00
#endregion
}