2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-08-26 01:43:15 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Definitions.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2016-08-26 01:45:58 +01:00
|
|
|
// Component : CP/M filesystem plugin.
|
2016-08-26 01:43:15 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2017-12-21 07:36:47 +00:00
|
|
|
// Handles definitions of known CP/M disks.
|
2016-08-26 01:43:15 +01:00
|
|
|
//
|
|
|
|
|
// --[ 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:23 +00:00
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2016-08-26 01:43:15 +01:00
|
|
|
// ****************************************************************************/
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2016-08-26 01:43:15 +01:00
|
|
|
using System;
|
2016-08-26 01:45:58 +01:00
|
|
|
using System.Collections.Generic;
|
2021-08-17 16:27:42 +01:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2021-09-21 04:55:28 +01:00
|
|
|
using System.IO;
|
2016-08-26 01:45:58 +01:00
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
2020-07-20 15:43:52 +01:00
|
|
|
namespace Aaru.Filesystems
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
public sealed partial class CPM
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Loads all the known CP/M disk definitions from an XML stored as an embedded resource.</summary>
|
2016-08-26 01:45:58 +01:00
|
|
|
/// <returns>The definitions.</returns>
|
2017-12-20 02:08:37 +00:00
|
|
|
bool LoadDefinitions()
|
2016-08-26 01:43:15 +01:00
|
|
|
{
|
2016-08-26 01:45:58 +01:00
|
|
|
try
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
var defsReader =
|
|
|
|
|
XmlReader.Create(Assembly.GetExecutingAssembly().
|
|
|
|
|
GetManifestResourceStream("Aaru.Filesystems.CPM.cpmdefs.xml") ??
|
2021-09-21 04:55:28 +01:00
|
|
|
new MemoryStream());
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
|
|
|
var defsSerializer = new XmlSerializer(typeof(CpmDefinitions));
|
2020-07-20 21:11:32 +01:00
|
|
|
_definitions = (CpmDefinitions)defsSerializer.Deserialize(defsReader);
|
2016-08-26 01:45:58 +01:00
|
|
|
|
|
|
|
|
// Patch definitions
|
2020-07-20 21:11:32 +01:00
|
|
|
foreach(CpmDefinition def in _definitions.definitions)
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
|
|
|
|
if(def.side1 == null)
|
|
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
def.side1 = new Side
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
sideId = 0,
|
|
|
|
|
sectorIds = new int[def.sectorsPerTrack]
|
2020-02-29 18:03:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < def.sectorsPerTrack; i++)
|
|
|
|
|
def.side1.sectorIds[i] = i + 1;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
if(def.sides != 2 ||
|
|
|
|
|
def.side2 != null)
|
|
|
|
|
continue;
|
2017-12-21 06:06:19 +00:00
|
|
|
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
def.side2 = new Side
|
|
|
|
|
{
|
2020-07-20 04:34:16 +01:00
|
|
|
sideId = 1,
|
|
|
|
|
sectorIds = new int[def.sectorsPerTrack]
|
2020-02-29 18:03:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < def.sectorsPerTrack; i++)
|
|
|
|
|
def.side2.sectorIds[i] = i + 1;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-08-26 01:43:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-08-26 01:45:58 +01:00
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>CP/M disk definitions</summary>
|
2021-08-17 16:27:42 +01:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
2020-07-22 13:20:25 +01:00
|
|
|
public sealed class CpmDefinitions
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Timestamp of creation of the CP/M disk definitions list</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public DateTime creation;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>List of all CP/M disk definitions</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public List<CpmDefinition> definitions;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>CP/M disk definition</summary>
|
2021-08-17 16:27:42 +01:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
2020-07-22 13:20:25 +01:00
|
|
|
public sealed class CpmDefinition
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Maps the first 16 allocation blocks for reservation, high byte</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int al0;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Maps the first 16 allocation blocks for reservation, low byte</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int al1;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Controller bitrate</summary>
|
2016-08-26 01:45:58 +01:00
|
|
|
public string bitrate;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Block mask for <see cref="bsh" /></summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int blm;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Left shifts needed to translate allocation block number to lba</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int bsh;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Physical bytes per sector</summary>
|
2016-08-26 01:45:58 +01:00
|
|
|
public int bytesPerSector;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Comment and description</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public string comment;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>If true, all bytes written on disk are negated</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public bool complement;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Total cylinders</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int cylinders;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Total number of available directory entries</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int drm;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Total number of 128 byte records on disk</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int dsm;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Encoding, "FM", "MFM", "GCR"</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public string encoding;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Absolutely unknown?</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public bool evenOdd;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Extent mask</summary>
|
2016-08-26 01:45:58 +01:00
|
|
|
public int exm;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Disk definition label</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public string label;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Tracks at the beginning of disk reserved for BIOS/BDOS</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int ofs;
|
2016-08-26 01:45:58 +01:00
|
|
|
/// <summary>
|
2020-02-29 18:03:35 +00:00
|
|
|
/// Cylinder/side ordering. SIDES = change side after each track, CYLINDERS = change side after whole side, EAGLE
|
|
|
|
|
/// and COLUMBIA unknown
|
2016-08-26 01:45:58 +01:00
|
|
|
/// </summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public string order;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Physical sectors per side</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int sectorsPerTrack;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Description of controller's side 0 (usually, upper side)</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public Side side1;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Description of controller's side 1 (usually, lower side)</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public Side side2;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Total sides</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int sides;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Physical sector interleaving</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int skew;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Sectors at the beginning of disk reserved for BIOS/BDOS</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int sofs;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Side descriptions</summary>
|
2021-08-17 16:27:42 +01:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
2020-07-22 13:20:25 +01:00
|
|
|
public sealed class Side
|
2016-08-26 01:45:58 +01:00
|
|
|
{
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Software interleaving mask, [1,3,0,2] means CP/M LBA 0 is physical sector 1, LBA 1 = 3, so on</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int[] sectorIds;
|
2020-02-29 18:03:35 +00:00
|
|
|
/// <summary>Side ID as found in each sector address mark</summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
public int sideId;
|
2016-08-26 01:45:58 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|