2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-19 02:04:38 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : System34.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:04:38 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:04:38 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes IBM System 34 floppy structures.
|
2015-10-19 02:04:38 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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
|
2015-10-19 02:04:38 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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.
|
2015-10-19 02:04:38 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// 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/>.
|
2015-10-19 02:04:38 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2015-10-19 02:04:38 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-10-19 02:13:54 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2015-10-19 02:04:38 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Decoders.Floppy
|
|
|
|
|
{
|
|
|
|
|
// Information from:
|
|
|
|
|
// National Semiconductor PC87332VLJ datasheet
|
|
|
|
|
// SMsC FDC37C78 datasheet
|
|
|
|
|
// Intel 82078 datasheet
|
|
|
|
|
// Intel 82077AA datasheet
|
|
|
|
|
// Toshiba TC8566AF datasheet
|
|
|
|
|
// Fujitsu MB8876A datasheet
|
|
|
|
|
// ECMA-147
|
|
|
|
|
// ECMA-100
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Methods and structures for IBM System 34 floppy decoding
|
|
|
|
|
/// </summary>
|
2017-12-22 02:04:18 +00:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
|
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
2015-10-19 02:04:38 +01:00
|
|
|
public static class System34
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Track format for IBM System 34 floppy
|
|
|
|
|
/// Used by IBM PC, Apple Macintosh (high-density only), and a lot others
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public struct Track
|
2015-10-19 02:04:38 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Start of track
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public TrackPreamble trackStart;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Track sectors
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public Sector[] sectors;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Undefined size
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] gap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Start of IBM PC MFM floppy track
|
|
|
|
|
/// Used by IBM PC, Apple Macintosh (high-density only), and a lot others
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public struct TrackPreamble
|
2015-10-19 02:04:38 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gap from index pulse, 80 bytes set to 0x4E
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)] public byte[] gap;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// 12 bytes set to 0x00
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] public byte[] zero;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// 3 bytes set to 0xC2
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] ctwo;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
2017-12-21 07:36:47 +00:00
|
|
|
/// Set to <see cref="IBMIdType.IndexMark"/>
|
2015-10-19 02:04:38 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public IBMIdType type;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gap until first sector, 50 bytes to 0x4E
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)] public byte[] gap1;
|
2015-10-19 02:04:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raw demodulated format for IBM System 34 floppies
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public struct Sector
|
2015-10-19 02:04:38 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sector address mark
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public AddressMark addressMark;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// 22 bytes set to 0x4E, set to 0x22 on Commodore 1581
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 22)] public byte[] innerGap;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sector data block
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public DataBlock dataBlock;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Variable bytes set to 0x4E, ECMA defines 54
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] outerGap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sector address mark for IBM System 34 floppies, contains sync word
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public struct AddressMark
|
2015-10-19 02:04:38 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 12 bytes set to 0
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] public byte[] zero;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// 3 bytes set to 0xA1
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] aone;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Set to <see cref="IBMIdType.AddressMark"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IBMIdType type;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Track number
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte track;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Side number
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte side;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sector number
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte sector;
|
|
|
|
|
/// <summary>
|
2017-12-21 07:36:47 +00:00
|
|
|
/// <see cref="IBMSectorSizeCode"/>
|
2015-10-19 02:04:38 +01:00
|
|
|
/// </summary>
|
|
|
|
|
public IBMSectorSizeCode sectorSize;
|
|
|
|
|
/// <summary>
|
2017-12-21 07:36:47 +00:00
|
|
|
/// CRC16 from <see cref="aone"/> to end of <see cref="sectorSize"/>
|
2015-10-19 02:04:38 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort crc;
|
2015-10-19 02:04:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sector data block for IBM System 34 floppies
|
|
|
|
|
/// </summary>
|
2015-10-19 02:13:54 +01:00
|
|
|
public struct DataBlock
|
2015-10-19 02:04:38 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 12 bytes set to 0
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] public byte[] zero;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// 3 bytes set to 0xA1
|
|
|
|
|
/// </summary>
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] aone;
|
2015-10-19 02:04:38 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Set to <see cref="IBMIdType.DataMark"/> or to <see cref="IBMIdType.DeletedDataMark"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IBMIdType type;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// User data
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte[] data;
|
|
|
|
|
/// <summary>
|
2017-12-21 07:36:47 +00:00
|
|
|
/// CRC16 from <see cref="aone"/> to end of <see cref="data"/>
|
2015-10-19 02:04:38 +01:00
|
|
|
/// </summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
public ushort crc;
|
2015-10-19 02:04:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|