diff --git a/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj b/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj index 08375a06..cf14595a 100644 --- a/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj +++ b/DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj @@ -59,6 +59,8 @@ + + diff --git a/DiscImageChef.DiscImages/Enums.cs b/DiscImageChef.DiscImages/Enums.cs index 5a8826b5..d8922600 100644 --- a/DiscImageChef.DiscImages/Enums.cs +++ b/DiscImageChef.DiscImages/Enums.cs @@ -266,7 +266,7 @@ namespace DiscImageChef.DiscImages /// XGD unlocked DMI Xbox_DMI, /// XDG unlocked PFI - Xbox_PFI, + Xbox_PFI } /// @@ -305,4 +305,52 @@ namespace DiscImageChef.DiscImages /// Track has pre-emphasis. PreEmphasis = 0x01 } + + /// Status of a requested floppy sector + [Flags] + public enum FloppySectorStatus : byte + { + /// Both address mark and data checksums are correct. + Correct = 0x01, + /// Data checksum is incorrect. + DataError = 0x02, + /// Addres mark checksum is incorrect. + AddressMarkError = 0x04, + /// There is another sector in the same track/head with same sector id. + Duplicated = 0x08, + /// Sector data section is not magnetized. + Demagnetized = 0x10, + /// Sector data section has a physically visible hole. + Hole = 0x20, + /// There is no address mark containing the requested sector id in the track/head. + NotFound = 0x40 + } + + public enum FloppyTypes : byte + { + /// 8" floppy + Floppy, + /// 5.25" floppy + MiniFloppy, + /// 3.5" floppy + MicroFloppy, + /// 3" floppy + CompactFloppy, + /// 5.25" twiggy + FileWare, + /// 2.5" quickdisk + QuickDisk + } + + public enum FloppyDensities : byte + { + /// Standard coercitivity (about 300Oe as found in 8" and 5.25"-double-density disks). + Standard, + /// Double density coercitivity (about 600Oe as found in 5.25" HD and 3.5" DD disks). + Double, + /// High density coercitivity (about 700Oe as found in 3.5" HD disks). + High, + /// Extended density coercitivity (about 750Oe as found in 3.5" ED disks). + Extended + } } \ No newline at end of file diff --git a/DiscImageChef.DiscImages/IFloppyImage.cs b/DiscImageChef.DiscImages/IFloppyImage.cs new file mode 100644 index 00000000..97fd9745 --- /dev/null +++ b/DiscImageChef.DiscImages/IFloppyImage.cs @@ -0,0 +1,126 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : IFloppyImage.cs +// Author(s) : Natalia Portillo +// +// 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +namespace DiscImageChef.DiscImages +{ + /// + /// 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 . + /// All data returned by these methods is already decoded from its corresponding bitstream. + /// + public interface IFloppyImage : IMediaImage + { + /// + /// Floppy info, contains information about physical characteristics of floppy, like size, bitrate, track density, + /// etc... + /// + FloppyInfo FloppyInfo { get; } + + /// + /// Reads a sector's user data. + /// + /// + /// If is one of the duplicates is returned + /// randomly. + /// If is or + /// random data is returned. + /// If is null is returned. + /// Otherwise, whatever is in the sector is returned. + /// + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// Logical sector ID. + /// Status of request. + byte[] ReadSector(ushort track, byte head, ushort sector, out FloppySectorStatus status); + + /// + /// Reads a sector's tag. + /// + /// + /// If is one of the duplicates is returned + /// randomly. + /// If is or + /// random data is returned. + /// If is null is returned. + /// Otherwise, whatever tag is in the sector is returned. + /// + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// Logical sector ID. + /// Status of request. + byte[] ReadSectorTag(ushort track, byte head, ushort sector, out FloppySectorStatus status, SectorTagType tag); + + /// + /// Reads a whole track. It includes all gaps, address marks, sectors data, etc. + /// + /// The track data. + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + byte[] ReadTrack(ushort track, byte head); + + /// + /// Reads a sector's data including all tags, address mark, and so, in a format dependent of represented media. + /// + /// + /// If is one of the duplicates is returned + /// randomly. + /// If is or + /// random data is returned. + /// If is null is returned. + /// Otherwise, whatever is in the sector is returned. + /// + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// Logical sector ID. + /// Status of request. + byte[] ReadSectorLong(ushort track, byte head, ushort sector, out FloppySectorStatus status); + + /// + /// Verifies a track. + /// + /// True if correct, false if incorrect, null if uncheckable. + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + bool? VerifyTrack(ushort track, byte head); + + /// + /// Verifies a sector, relative to track. + /// + /// True if correct, false if incorrect, null if uncheckable. + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// Logical sector ID. + /// Status of request. + bool? VerifySector(ushort track, byte head, ushort sector); + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/IWritableFloppyImage.cs b/DiscImageChef.DiscImages/IWritableFloppyImage.cs new file mode 100644 index 00000000..1eb36786 --- /dev/null +++ b/DiscImageChef.DiscImages/IWritableFloppyImage.cs @@ -0,0 +1,95 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : IFloppyImage.cs +// Author(s) : Natalia Portillo +// +// 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +namespace DiscImageChef.DiscImages +{ + /// + /// 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 . + /// All data expected by these methods is already decoded from its corresponding bitstream. + /// + public interface IWritableFloppyImage : IFloppyImage, IWritableImage + { + /// + /// 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. + /// + /// + /// Floppy info, contains information about physical characteristics of floppy, like size, bitrate, + /// track density, etc... + /// + /// true if operating completed successfully, false otherwise + bool SetFloppyCharacteristics(FloppyInfo info); + + /// + /// Writes a sector's user data. + /// + /// + /// If is one of the duplicates. + /// If is , , + /// it will be ignored. + /// Otherwise, whatever data should be in the sector. + /// + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// Logical sector ID. + /// Status of sector. + /// true if operating completed successfully, false otherwise + bool WriteSector(byte[] data, ushort track, byte head, ushort sector, FloppySectorStatus status); + + /// + /// Writes a whole track, including all gaps, address marks, sectors data, etc. + /// + /// The track data. + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// true if operating completed successfully, false otherwise + bool WriteTrack(byte[] data, ushort track, byte head); + + /// + /// Writes a sector's data including all tags, address mark, and so, in a format dependent of represented media. + /// + /// + /// If is one of the duplicates. + /// If is , , + /// it will be ignored. + /// Otherwise, whatever data should be in the sector. + /// + /// Physical track (position of the heads over the floppy media, 0-based). + /// Physical head (0-based). + /// Logical sector ID. + /// Status of request. + /// true if operating completed successfully, false otherwise + bool WriteSectorLong(byte[] data, ushort track, byte head, ushort sector, out FloppySectorStatus status); + } +} \ No newline at end of file diff --git a/DiscImageChef.DiscImages/Structs.cs b/DiscImageChef.DiscImages/Structs.cs index 9e7301cb..3234852f 100644 --- a/DiscImageChef.DiscImages/Structs.cs +++ b/DiscImageChef.DiscImages/Structs.cs @@ -166,4 +166,23 @@ namespace DiscImageChef.DiscImages /// Type of subchannel stored for this track public TrackSubchannelType TrackSubchannelType; } + + /// + /// Floppy physical characteristics structure. + /// + public struct FloppyInfo + { + /// Physical floppy type. + public FloppyTypes Type; + /// Bitrate in bits per second used to write the floppy, 0 if unknown or track-variable. + public uint Bitrate; + /// Physical magnetic density (coercitivity) of floppy medium. + public FloppyDensities Coercitivity; + /// How many physical tracks are actually written in the floppy image. + public ushort Tracks; + /// How many physical heads are actually written in the floppy image. + public byte Heads; + /// How many tracks per inch are actually written in the floppy image. + public ushort TrackDensity; + } } \ No newline at end of file