Files
Aaru/Aaru.Filesystems/CPM/Definitions.cs

168 lines
6.5 KiB
C#
Raw Normal View History

2017-05-19 20:28:49 +01:00
// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Definitions.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : CP/M filesystem plugin.
//
// --[ Description ] ----------------------------------------------------------
//
// Handles definitions of known CP/M disks.
//
// --[ 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-01-03 17:51:30 +00:00
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using System.Xml.Serialization;
2020-07-20 15:43:52 +01:00
namespace Aaru.Filesystems
{
2020-02-29 18:03:35 +00:00
internal partial class CPM
{
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>
/// <returns>The definitions.</returns>
bool LoadDefinitions()
{
try
{
2020-02-29 18:03:35 +00:00
var defsReader =
XmlReader.Create(Assembly.GetExecutingAssembly().
GetManifestResourceStream("Aaru.Filesystems.CPM.cpmdefs.xml") ??
throw new InvalidOperationException());
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);
// Patch definitions
2020-07-20 21:11:32 +01:00
foreach(CpmDefinition def in _definitions.definitions)
{
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;
}
2020-02-29 18:03:35 +00:00
if(def.sides != 2 ||
def.side2 != null)
continue;
{
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;
}
}
return true;
}
2020-02-29 18:03:35 +00:00
catch
{
return false;
}
}
}
2020-02-29 18:03:35 +00:00
/// <summary>CP/M disk definitions</summary>
public class CpmDefinitions
{
2020-02-29 18:03:35 +00:00
/// <summary>Timestamp of creation of the CP/M disk definitions list</summary>
public DateTime creation;
2020-02-29 18:03:35 +00:00
/// <summary>List of all CP/M disk definitions</summary>
public List<CpmDefinition> definitions;
}
2020-02-29 18:03:35 +00:00
/// <summary>CP/M disk definition</summary>
public class CpmDefinition
{
2020-02-29 18:03:35 +00:00
/// <summary>Maps the first 16 allocation blocks for reservation, high byte</summary>
public int al0;
2020-02-29 18:03:35 +00:00
/// <summary>Maps the first 16 allocation blocks for reservation, low byte</summary>
public int al1;
2020-02-29 18:03:35 +00:00
/// <summary>Controller bitrate</summary>
public string bitrate;
2020-02-29 18:03:35 +00:00
/// <summary>Block mask for <see cref="bsh" /></summary>
public int blm;
2020-02-29 18:03:35 +00:00
/// <summary>Left shifts needed to translate allocation block number to lba</summary>
public int bsh;
2020-02-29 18:03:35 +00:00
/// <summary>Physical bytes per sector</summary>
public int bytesPerSector;
2020-02-29 18:03:35 +00:00
/// <summary>Comment and description</summary>
public string comment;
2020-02-29 18:03:35 +00:00
/// <summary>If true, all bytes written on disk are negated</summary>
public bool complement;
2020-02-29 18:03:35 +00:00
/// <summary>Total cylinders</summary>
public int cylinders;
2020-02-29 18:03:35 +00:00
/// <summary>Total number of available directory entries</summary>
public int drm;
2020-02-29 18:03:35 +00:00
/// <summary>Total number of 128 byte records on disk</summary>
public int dsm;
2020-02-29 18:03:35 +00:00
/// <summary>Encoding, "FM", "MFM", "GCR"</summary>
public string encoding;
2020-02-29 18:03:35 +00:00
/// <summary>Absolutely unknown?</summary>
public bool evenOdd;
2020-02-29 18:03:35 +00:00
/// <summary>Extent mask</summary>
public int exm;
2020-02-29 18:03:35 +00:00
/// <summary>Disk definition label</summary>
public string label;
2020-02-29 18:03:35 +00:00
/// <summary>Tracks at the beginning of disk reserved for BIOS/BDOS</summary>
public int ofs;
/// <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
/// </summary>
public string order;
2020-02-29 18:03:35 +00:00
/// <summary>Physical sectors per side</summary>
public int sectorsPerTrack;
2020-02-29 18:03:35 +00:00
/// <summary>Description of controller's side 0 (usually, upper side)</summary>
public Side side1;
2020-02-29 18:03:35 +00:00
/// <summary>Description of controller's side 1 (usually, lower side)</summary>
public Side side2;
2020-02-29 18:03:35 +00:00
/// <summary>Total sides</summary>
public int sides;
2020-02-29 18:03:35 +00:00
/// <summary>Physical sector interleaving</summary>
public int skew;
2020-02-29 18:03:35 +00:00
/// <summary>Sectors at the beginning of disk reserved for BIOS/BDOS</summary>
public int sofs;
}
2020-02-29 18:03:35 +00:00
/// <summary>Side descriptions</summary>
public class Side
{
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>
public int[] sectorIds;
2020-02-29 18:03:35 +00:00
/// <summary>Side ID as found in each sector address mark</summary>
public int sideId;
}
2017-12-19 20:33:03 +00:00
}