Add interface for floppy images (track/head/sector based).

This commit is contained in:
2018-03-26 23:59:26 +01:00
parent b4d7966ada
commit b417982510
5 changed files with 291 additions and 1 deletions

View File

@@ -59,6 +59,8 @@
<Compile Include="Enums.cs" /> <Compile Include="Enums.cs" />
<Compile Include="Exceptions.cs" /> <Compile Include="Exceptions.cs" />
<Compile Include="HDCopy.cs" /> <Compile Include="HDCopy.cs" />
<Compile Include="IFloppyImage.cs" />
<Compile Include="IWritableFloppyImage.cs" />
<Compile Include="IWritableImage.cs" /> <Compile Include="IWritableImage.cs" />
<Compile Include="KryoFlux.cs" /> <Compile Include="KryoFlux.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@@ -266,7 +266,7 @@ namespace DiscImageChef.DiscImages
/// <summary>XGD unlocked DMI</summary> /// <summary>XGD unlocked DMI</summary>
Xbox_DMI, Xbox_DMI,
/// <summary>XDG unlocked PFI</summary> /// <summary>XDG unlocked PFI</summary>
Xbox_PFI, Xbox_PFI
} }
/// <summary> /// <summary>
@@ -305,4 +305,52 @@ namespace DiscImageChef.DiscImages
/// <summary>Track has pre-emphasis.</summary> /// <summary>Track has pre-emphasis.</summary>
PreEmphasis = 0x01 PreEmphasis = 0x01
} }
/// <summary>Status of a requested floppy sector</summary>
[Flags]
public enum FloppySectorStatus : byte
{
/// <summary>Both address mark and data checksums are correct.</summary>
Correct = 0x01,
/// <summary>Data checksum is incorrect.</summary>
DataError = 0x02,
/// <summary>Addres mark checksum is incorrect.</summary>
AddressMarkError = 0x04,
/// <summary>There is another sector in the same track/head with same sector id.</summary>
Duplicated = 0x08,
/// <summary>Sector data section is not magnetized.</summary>
Demagnetized = 0x10,
/// <summary>Sector data section has a physically visible hole.</summary>
Hole = 0x20,
/// <summary>There is no address mark containing the requested sector id in the track/head.</summary>
NotFound = 0x40
}
public enum FloppyTypes : byte
{
/// <summary>8" floppy</summary>
Floppy,
/// <summary>5.25" floppy</summary>
MiniFloppy,
/// <summary>3.5" floppy</summary>
MicroFloppy,
/// <summary>3" floppy</summary>
CompactFloppy,
/// <summary>5.25" twiggy</summary>
FileWare,
/// <summary>2.5" quickdisk</summary>
QuickDisk
}
public enum FloppyDensities : byte
{
/// <summary>Standard coercitivity (about 300Oe as found in 8" and 5.25"-double-density disks).</summary>
Standard,
/// <summary>Double density coercitivity (about 600Oe as found in 5.25" HD and 3.5" DD disks).</summary>
Double,
/// <summary>High density coercitivity (about 700Oe as found in 3.5" HD disks).</summary>
High,
/// <summary>Extended density coercitivity (about 750Oe as found in 3.5" ED disks).</summary>
Extended
}
} }

View File

@@ -0,0 +1,126 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : IFloppyImage.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disc image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Defines interface to be implemented by floppy image plugins.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
namespace DiscImageChef.DiscImages
{
/// <summary>
/// Abstract class to implement disk image reading plugins that can contain floppy images.
/// This interface is needed because floppy formatting characteristics are not necesarily compatible with the whole.
/// LBA-oriented interface is defined by <see cref="IMediaImage" />.
/// All data returned by these methods is already decoded from its corresponding bitstream.
/// </summary>
public interface IFloppyImage : IMediaImage
{
/// <summary>
/// Floppy info, contains information about physical characteristics of floppy, like size, bitrate, track density,
/// etc...
/// </summary>
FloppyInfo FloppyInfo { get; }
/// <summary>
/// Reads a sector's user data.
/// </summary>
/// <returns>
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Duplicated" /> one of the duplicates is returned
/// randomly.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Demagnetized" /> or
/// <see cref="FloppySectorStatus.Hole" /> random data is returned.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.NotFound" /> <c>null</c> is returned.
/// Otherwise, whatever is in the sector is returned.
/// </returns>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <param name="sector">Logical sector ID.</param>
/// <param name="status">Status of request.</param>
byte[] ReadSector(ushort track, byte head, ushort sector, out FloppySectorStatus status);
/// <summary>
/// Reads a sector's tag.
/// </summary>
/// <returns>
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Duplicated" /> one of the duplicates is returned
/// randomly.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Demagnetized" /> or
/// <see cref="FloppySectorStatus.Hole" /> random data is returned.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.NotFound" /> <c>null</c> is returned.
/// Otherwise, whatever tag is in the sector is returned.
/// </returns>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <param name="sector">Logical sector ID.</param>
/// <param name="status">Status of request.</param>
byte[] ReadSectorTag(ushort track, byte head, ushort sector, out FloppySectorStatus status, SectorTagType tag);
/// <summary>
/// Reads a whole track. It includes all gaps, address marks, sectors data, etc.
/// </summary>
/// <returns>The track data.</returns>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
byte[] ReadTrack(ushort track, byte head);
/// <summary>
/// Reads a sector's data including all tags, address mark, and so, in a format dependent of represented media.
/// </summary>
/// <returns>
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Duplicated" /> one of the duplicates is returned
/// randomly.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Demagnetized" /> or
/// <see cref="FloppySectorStatus.Hole" /> random data is returned.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.NotFound" /> <c>null</c> is returned.
/// Otherwise, whatever is in the sector is returned.
/// </returns>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <param name="sector">Logical sector ID.</param>
/// <param name="status">Status of request.</param>
byte[] ReadSectorLong(ushort track, byte head, ushort sector, out FloppySectorStatus status);
/// <summary>
/// Verifies a track.
/// </summary>
/// <returns>True if correct, false if incorrect, null if uncheckable.</returns>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
bool? VerifyTrack(ushort track, byte head);
/// <summary>
/// Verifies a sector, relative to track.
/// </summary>
/// <returns>True if correct, false if incorrect, null if uncheckable.</returns>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <param name="sector">Logical sector ID.</param>
/// <param name="status">Status of request.</param>
bool? VerifySector(ushort track, byte head, ushort sector);
}
}

View File

@@ -0,0 +1,95 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : IFloppyImage.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disc image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Defines interface to be implemented by floppy image plugins.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
namespace DiscImageChef.DiscImages
{
/// <summary>
/// Abstract class to implement disk image reading plugins that can contain floppy images.
/// This interface is needed because floppy formatting characteristics are not necesarily compatible with the whole
/// LBA-oriented interface defined by <see cref="IMediaImage" />.
/// All data expected by these methods is already decoded from its corresponding bitstream.
/// </summary>
public interface IWritableFloppyImage : IFloppyImage, IWritableImage
{
/// <summary>
/// Indicates the image plugin the floppy physical characteristics and must be called before following methods are
/// called. Once this is called, LBA-based methods should not be used.
/// </summary>
/// <param name="info">
/// Floppy info, contains information about physical characteristics of floppy, like size, bitrate,
/// track density, etc...
/// </param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool SetFloppyCharacteristics(FloppyInfo info);
/// <summary>
/// Writes a sector's user data.
/// </summary>
/// <param name="data">
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Duplicated" /> one of the duplicates.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Demagnetized" />, <see cref="FloppySectorStatus.Hole" />,
/// <see cref="FloppySectorStatus.NotFound" /> it will be ignored.
/// Otherwise, whatever data should be in the sector.
/// </param>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <param name="sector">Logical sector ID.</param>
/// <param name="status">Status of sector.</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool WriteSector(byte[] data, ushort track, byte head, ushort sector, FloppySectorStatus status);
/// <summary>
/// Writes a whole track, including all gaps, address marks, sectors data, etc.
/// </summary>
/// <param name="data">The track data.</param>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool WriteTrack(byte[] data, ushort track, byte head);
/// <summary>
/// Writes a sector's data including all tags, address mark, and so, in a format dependent of represented media.
/// </summary>
/// <param name="data">
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Duplicated" /> one of the duplicates.
/// If <see cref="status" /> is <see cref="FloppySectorStatus.Demagnetized" />, <see cref="FloppySectorStatus.Hole" />,
/// <see cref="FloppySectorStatus.NotFound" /> it will be ignored.
/// Otherwise, whatever data should be in the sector.
/// </param>
/// <param name="track">Physical track (position of the heads over the floppy media, 0-based).</param>
/// <param name="head">Physical head (0-based).</param>
/// <param name="sector">Logical sector ID.</param>
/// <param name="status">Status of request.</param>
/// <returns><c>true</c> if operating completed successfully, <c>false</c> otherwise</returns>
bool WriteSectorLong(byte[] data, ushort track, byte head, ushort sector, out FloppySectorStatus status);
}
}

View File

@@ -166,4 +166,23 @@ namespace DiscImageChef.DiscImages
/// <summary>Type of subchannel stored for this track</summary> /// <summary>Type of subchannel stored for this track</summary>
public TrackSubchannelType TrackSubchannelType; public TrackSubchannelType TrackSubchannelType;
} }
/// <summary>
/// Floppy physical characteristics structure.
/// </summary>
public struct FloppyInfo
{
/// <summary>Physical floppy type.</summary>
public FloppyTypes Type;
/// <summary>Bitrate in bits per second used to write the floppy, 0 if unknown or track-variable.</summary>
public uint Bitrate;
/// <summary>Physical magnetic density (coercitivity) of floppy medium.</summary>
public FloppyDensities Coercitivity;
/// <summary>How many physical tracks are actually written in the floppy image.</summary>
public ushort Tracks;
/// <summary>How many physical heads are actually written in the floppy image.</summary>
public byte Heads;
/// <summary>How many tracks per inch are actually written in the floppy image.</summary>
public ushort TrackDensity;
}
} }