Files
Aaru.Server/DiscImageChef.DiscImages/AppleDOS.cs

260 lines
9.9 KiB
C#
Raw Normal View History

// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : AppleDOS.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Manages interleaved Apple ][ disk images.
//
// --[ 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
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using DiscImageChef.CommonTypes;
using DiscImageChef.Filters;
namespace DiscImageChef.DiscImages
{
2017-12-19 20:33:03 +00:00
// Checked using several images and strings inside Apple's DiskImages.framework
public class AppleDos : ImagePlugin
2017-12-19 20:33:03 +00:00
{
readonly int[] dosOffsets = {0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15};
readonly int[] prodosOffsets = {0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15};
2017-12-19 20:33:03 +00:00
public AppleDos()
2017-12-19 20:33:03 +00:00
{
Name = "Apple ][ Interleaved Disk Image";
PluginUuid = new Guid("A5828AC0-62C9-4304-81D4-EFD4AAE47360");
2017-12-19 20:33:03 +00:00
ImageInfo = new ImageInfo
{
ReadableSectorTags = new List<SectorTagType>(),
ReadableMediaTags = new List<MediaTagType>(),
HasPartitions = false,
HasSessions = false,
Version = null,
Application = null,
ApplicationVersion = null,
Creator = null,
Comments = null,
MediaManufacturer = null,
MediaModel = null,
MediaSerialNumber = null,
MediaBarcode = null,
MediaPartNumber = null,
MediaSequence = 0,
LastMediaSequence = 0,
DriveManufacturer = null,
DriveModel = null,
DriveSerialNumber = null,
DriveFirmwareRevision = null
2017-12-19 20:33:03 +00:00
};
}
public override string ImageFormat => extension == ".po"
? "Apple ][ Interleaved Disk Image (ProDOS order)"
: "Apple ][ Interleaved Disk Image (DOS order)";
public override List<Track> Tracks =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public override List<Session> Sessions =>
throw new FeatureUnsupportedImageException("Feature not supported by image format");
2017-12-19 20:33:03 +00:00
public override bool IdentifyImage(Filter imageFilter)
{
extension = Path.GetExtension(imageFilter.GetFilename())?.ToLower();
2017-12-19 20:33:03 +00:00
return imageFilter.GetDataForkLength() == 143360 && (extension == ".po" || extension == ".do");
2017-12-19 20:33:03 +00:00
}
public override bool OpenImage(Filter imageFilter)
{
Stream stream = imageFilter.GetDataForkStream();
stream.Seek(0, SeekOrigin.Begin);
byte[] tmp = new byte[imageFilter.GetDataForkLength()];
stream.Read(tmp, 0, tmp.Length);
deinterleaved = new byte[tmp.Length];
extension = Path.GetExtension(imageFilter.GetFilename())?.ToLower();
2017-12-19 20:33:03 +00:00
int[] offsets = extension == ".do" ? dosOffsets : prodosOffsets;
2017-12-19 20:33:03 +00:00
for(int t = 0; t < 35; t++)
{
for(int s = 0; s < 16; s++)
Array.Copy(tmp, t * 16 * 256 + s * 256, deinterleaved, t * 16 * 256 + offsets[s] * 256, 256);
2017-12-19 20:33:03 +00:00
}
ImageInfo.SectorSize = 256;
ImageInfo.ImageSize = (ulong)imageFilter.GetDataForkLength();
ImageInfo.CreationTime = imageFilter.GetCreationTime();
ImageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
ImageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
ImageInfo.Sectors = 560;
ImageInfo.MediaType = MediaType.Apple33SS;
ImageInfo.XmlMediaType = XmlMediaType.BlockMedia;
ImageInfo.Cylinders = 35;
ImageInfo.Heads = 2;
ImageInfo.SectorsPerTrack = 16;
2017-12-19 20:33:03 +00:00
return true;
}
public override byte[] ReadSector(ulong sectorAddress)
{
return ReadSectors(sectorAddress, 1);
}
public override byte[] ReadSectors(ulong sectorAddress, uint length)
{
if(sectorAddress > ImageInfo.Sectors - 1)
2017-12-19 20:33:03 +00:00
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
if(sectorAddress + length > ImageInfo.Sectors)
2017-12-19 20:33:03 +00:00
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
byte[] buffer = new byte[length * ImageInfo.SectorSize];
2017-12-19 20:33:03 +00:00
Array.Copy(deinterleaved, (int)(sectorAddress * ImageInfo.SectorSize), buffer, 0, buffer.Length);
2017-12-19 20:33:03 +00:00
return buffer;
}
public override bool? VerifySector(ulong sectorAddress)
{
return null;
}
public override bool? VerifySector(ulong sectorAddress, uint track)
{
return null;
}
public override bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
2017-12-19 20:33:03 +00:00
{
failingLbas = new List<ulong>();
unknownLbas = new List<ulong>();
2017-12-19 20:33:03 +00:00
for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i);
2017-12-19 20:33:03 +00:00
return null;
}
public override bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
out List<ulong> unknownLbas)
2017-12-19 20:33:03 +00:00
{
failingLbas = new List<ulong>();
unknownLbas = new List<ulong>();
2017-12-19 20:33:03 +00:00
for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i);
2017-12-19 20:33:03 +00:00
return null;
}
public override bool? VerifyMediaImage()
{
return null;
}
public override List<Track> GetSessionTracks(Session session)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override List<Track> GetSessionTracks(ushort session)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSector(ulong sectorAddress, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorLong(ulong sectorAddress, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
#region Internal variables
byte[] deinterleaved;
string extension;
#endregion
2017-12-19 20:33:03 +00:00
#region Unsupported features
public override byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorLong(ulong sectorAddress)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsLong(ulong sectorAddress, uint length)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadDiskTag(MediaTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override List<Partition> Partitions =>
2017-12-19 20:33:03 +00:00
throw new FeatureUnsupportedImageException("Feature not supported by image format");
public override byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
public override byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
{
throw new FeatureUnsupportedImageException("Feature not supported by image format");
}
#endregion
2017-12-19 20:33:03 +00:00
}
}