2017-09-26 23:54:14 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : RayDIM.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2017-09-26 23:54:14 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Manages Ray Arachelian's disk images.
|
2017-09-26 23:54:14 +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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-09-26 23:54:14 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-22 06:55:04 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-09-26 23:54:14 +01:00
|
|
|
|
using System.IO;
|
2017-12-31 23:34:02 +00:00
|
|
|
|
using System.Linq;
|
2017-09-26 23:54:14 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2017-12-31 23:34:02 +00:00
|
|
|
|
using System.Text;
|
2017-09-26 23:54:14 +01:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
|
using DiscImageChef.Console;
|
|
|
|
|
|
using DiscImageChef.Filters;
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
2017-09-26 23:54:14 +01:00
|
|
|
|
{
|
2017-12-31 23:34:02 +00:00
|
|
|
|
public class RayDim : IWritableImage
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-24 00:12:31 +00:00
|
|
|
|
const string REGEX_SIGNATURE =
|
2017-12-28 04:57:26 +00:00
|
|
|
|
@"Disk IMage VER (?<major>\d).(?<minor>\d) Copyright \(C\) (?<year>\d{4}) Ray Arachelian, All Rights Reserved\.";
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
MemoryStream disk;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
ImageInfo imageInfo;
|
2017-12-31 23:38:45 +00:00
|
|
|
|
FileStream writingStream;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public RayDim()
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo = new ImageInfo
|
2017-12-22 06:55:04 +00:00
|
|
|
|
{
|
2017-12-28 04:57:26 +00:00
|
|
|
|
ReadableSectorTags = new List<SectorTagType>(),
|
|
|
|
|
|
ReadableMediaTags = new List<MediaTagType>(),
|
|
|
|
|
|
HasPartitions = false,
|
|
|
|
|
|
HasSessions = false,
|
|
|
|
|
|
Application = "Ray Arachelian's Disk IMage",
|
|
|
|
|
|
Creator = null,
|
|
|
|
|
|
Comments = null,
|
|
|
|
|
|
MediaManufacturer = null,
|
|
|
|
|
|
MediaModel = null,
|
|
|
|
|
|
MediaSerialNumber = null,
|
|
|
|
|
|
MediaBarcode = null,
|
|
|
|
|
|
MediaPartNumber = null,
|
|
|
|
|
|
MediaSequence = 0,
|
|
|
|
|
|
LastMediaSequence = 0,
|
|
|
|
|
|
DriveManufacturer = null,
|
|
|
|
|
|
DriveModel = null,
|
|
|
|
|
|
DriveSerialNumber = null,
|
2017-12-22 06:55:04 +00:00
|
|
|
|
DriveFirmwareRevision = null
|
|
|
|
|
|
};
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
public string Name => "Ray Arachelian's Disk IMage";
|
|
|
|
|
|
public Guid Id => new Guid("F541F4E7-C1E3-4A2D-B07F-D863E87AB961");
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public ImageInfo Info => imageInfo;
|
2017-12-26 02:51:10 +00:00
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public string Format => "Ray Arachelian's Disk IMage";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Partition> Partitions =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> Tracks =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Session> Sessions =>
|
2017-12-26 02:51:10 +00:00
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Identify(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < Marshal.SizeOf(typeof(RayHdr))) return false;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[Marshal.SizeOf(typeof(RayHdr))];
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
stream.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
|
|
|
|
|
IntPtr ftrPtr = Marshal.AllocHGlobal(buffer.Length);
|
|
|
|
|
|
Marshal.Copy(buffer, 0, ftrPtr, buffer.Length);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
RayHdr header = (RayHdr)Marshal.PtrToStructure(ftrPtr, typeof(RayHdr));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Marshal.FreeHGlobal(ftrPtr);
|
|
|
|
|
|
|
|
|
|
|
|
string signature = StringHandlers.CToString(header.signature);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.signature = {0}", signature);
|
2017-12-28 04:57:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.diskType = {0}", header.diskType);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.heads = {0}", header.heads);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.cylinders = {0}", header.cylinders);
|
|
|
|
|
|
DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.sectorsPerTrack = {0}",
|
|
|
|
|
|
header.sectorsPerTrack);
|
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Regex sx = new Regex(REGEX_SIGNATURE);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Match sm = sx.Match(signature);
|
|
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Ray Arachelian's Disk IMage plugin", "header.signature matches? = {0}",
|
|
|
|
|
|
sm.Success);
|
|
|
|
|
|
|
|
|
|
|
|
return sm.Success;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
|
|
|
|
|
|
if(stream.Length < Marshal.SizeOf(typeof(RayHdr))) return false;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] buffer = new byte[Marshal.SizeOf(typeof(RayHdr))];
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
stream.Read(buffer, 0, buffer.Length);
|
|
|
|
|
|
|
|
|
|
|
|
IntPtr ftrPtr = Marshal.AllocHGlobal(buffer.Length);
|
|
|
|
|
|
Marshal.Copy(buffer, 0, ftrPtr, buffer.Length);
|
2017-12-22 06:55:04 +00:00
|
|
|
|
RayHdr header = (RayHdr)Marshal.PtrToStructure(ftrPtr, typeof(RayHdr));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Marshal.FreeHGlobal(ftrPtr);
|
|
|
|
|
|
|
|
|
|
|
|
string signature = StringHandlers.CToString(header.signature);
|
|
|
|
|
|
|
2017-12-24 00:12:31 +00:00
|
|
|
|
Regex sx = new Regex(REGEX_SIGNATURE);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
Match sm = sx.Match(signature);
|
|
|
|
|
|
|
|
|
|
|
|
if(!sm.Success) return false;
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.ApplicationVersion = $"{sm.Groups["major"].Value}.{sm.Groups["minor"].Value}";
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.Cylinders = (uint)(header.cylinders + 1);
|
|
|
|
|
|
imageInfo.Heads = (uint)(header.heads + 1);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.SectorsPerTrack = header.sectorsPerTrack;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.Sectors = imageInfo.Cylinders * imageInfo.Heads * imageInfo.SectorsPerTrack;
|
|
|
|
|
|
imageInfo.SectorSize = 512;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
byte[] sectors = new byte[imageInfo.SectorsPerTrack * imageInfo.SectorSize];
|
2017-12-28 04:57:26 +00:00
|
|
|
|
disk = new MemoryStream();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
for(int i = 0; i < imageInfo.SectorsPerTrack * imageInfo.SectorSize; i++)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
stream.Read(sectors, 0, sectors.Length);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
stream.Seek(imageInfo.SectorsPerTrack, SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
disk.Write(sectors, 0, sectors.Length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
imageInfo.MediaType =
|
|
|
|
|
|
Geometry.GetMediaType(((ushort)imageInfo.Cylinders, (byte)imageInfo.Heads,
|
|
|
|
|
|
(ushort)imageInfo.SectorsPerTrack, 512, MediaEncoding.MFM, false));
|
|
|
|
|
|
|
|
|
|
|
|
switch(imageInfo.MediaType)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-28 04:57:26 +00:00
|
|
|
|
case MediaType.NEC_525_HD when header.diskType == RayDiskTypes.Mf2hd ||
|
|
|
|
|
|
header.diskType == RayDiskTypes.Mf2ed:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.NEC_35_HD_8;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
case MediaType.DOS_525_HD when header.diskType == RayDiskTypes.Mf2hd ||
|
|
|
|
|
|
header.diskType == RayDiskTypes.Mf2ed:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.NEC_35_HD_15;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
2017-12-28 04:57:26 +00:00
|
|
|
|
case MediaType.RX50 when header.diskType == RayDiskTypes.Md2dd || header.diskType == RayDiskTypes.Md2hd:
|
|
|
|
|
|
imageInfo.MediaType = MediaType.ATARI_35_SS_DD;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, out List<ulong> failingLbas,
|
2017-12-28 04:57:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifySectors(ulong sectorAddress, uint length, uint track, out List<ulong> failingLbas,
|
2017-12-28 04:57:26 +00:00
|
|
|
|
out List<ulong> unknownLbas)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
failingLbas = new List<ulong>();
|
|
|
|
|
|
unknownLbas = new List<ulong>();
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(ulong i = sectorAddress; i < sectorAddress + length; i++) unknownLbas.Add(i);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool? VerifyMediaImage()
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
return ReadSectors(sectorAddress, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress > imageInfo.Sectors - 1)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
byte[] buffer = new byte[length * imageInfo.SectorSize];
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-28 04:57:26 +00:00
|
|
|
|
disk.Seek((long)(sectorAddress * imageInfo.SectorSize), SeekOrigin.Begin);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
disk.Read(buffer, 0, (int)(length * imageInfo.SectorSize));
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(Session session)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public List<Track> GetSessionTracks(ushort session)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, uint track, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, uint track, SectorTagType tag)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length, uint track)
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
throw new FeatureUnsupportedImageException("Feature not supported by image format");
|
|
|
|
|
|
}
|
2017-12-24 00:12:31 +00:00
|
|
|
|
|
2017-12-31 23:34:02 +00:00
|
|
|
|
public IEnumerable<MediaTagType> SupportedMediaTags => new MediaTagType[] { };
|
|
|
|
|
|
public IEnumerable<SectorTagType> SupportedSectorTags => new SectorTagType[] { };
|
|
|
|
|
|
// TODO: Test with real hardware to see real supported media
|
|
|
|
|
|
public IEnumerable<MediaType> SupportedMediaTypes =>
|
|
|
|
|
|
new[]
|
|
|
|
|
|
{
|
2017-12-31 23:38:45 +00:00
|
|
|
|
MediaType.Apricot_35, MediaType.ATARI_35_DS_DD, MediaType.ATARI_35_DS_DD_11, MediaType.ATARI_35_SS_DD,
|
|
|
|
|
|
MediaType.ATARI_35_SS_DD_11, MediaType.DMF, MediaType.DMF_82, MediaType.DOS_35_DS_DD_8,
|
|
|
|
|
|
MediaType.DOS_35_DS_DD_9, MediaType.DOS_35_ED, MediaType.DOS_35_HD, MediaType.DOS_35_SS_DD_8,
|
|
|
|
|
|
MediaType.DOS_35_SS_DD_9, MediaType.DOS_525_DS_DD_8, MediaType.DOS_525_DS_DD_9, MediaType.DOS_525_HD,
|
|
|
|
|
|
MediaType.DOS_525_SS_DD_8, MediaType.DOS_525_SS_DD_9, MediaType.FDFORMAT_35_DD,
|
|
|
|
|
|
MediaType.FDFORMAT_35_HD, MediaType.FDFORMAT_525_DD, MediaType.FDFORMAT_525_HD, MediaType.RX50,
|
|
|
|
|
|
MediaType.XDF_35, MediaType.XDF_525
|
2017-12-31 23:34:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
public IEnumerable<(string name, Type type, string description)> SupportedOptions =>
|
|
|
|
|
|
new(string name, Type type, string description)[] { };
|
|
|
|
|
|
public IEnumerable<string> KnownExtensions => new[] {".dim"};
|
2017-12-31 23:38:45 +00:00
|
|
|
|
public bool IsWriting { get; private set; }
|
|
|
|
|
|
public string ErrorMessage { get; private set; }
|
2017-12-31 23:34:02 +00:00
|
|
|
|
|
2017-12-31 23:38:45 +00:00
|
|
|
|
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
|
|
|
|
|
uint sectorSize)
|
2017-12-31 23:34:02 +00:00
|
|
|
|
{
|
|
|
|
|
|
if(sectorSize == 512)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Unsupported sector size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-31 23:38:45 +00:00
|
|
|
|
if(sectors > 255 * 255 * 255)
|
2017-12-31 23:34:02 +00:00
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = $"Too many sectors";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!SupportedMediaTypes.Contains(mediaType))
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = $"Unsupport media format {mediaType}";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
(ushort cylinders, byte heads, ushort sectorsPerTrack, uint bytesPerSector, MediaEncoding encoding, bool
|
|
|
|
|
|
variableSectorsPerTrack, MediaType type) geometry = Geometry.GetGeometry(mediaType);
|
2017-12-31 23:38:45 +00:00
|
|
|
|
imageInfo = new ImageInfo
|
2017-12-31 23:34:02 +00:00
|
|
|
|
{
|
2017-12-31 23:38:45 +00:00
|
|
|
|
MediaType = mediaType,
|
|
|
|
|
|
SectorSize = sectorSize,
|
|
|
|
|
|
Sectors = sectors,
|
|
|
|
|
|
Cylinders = geometry.cylinders,
|
|
|
|
|
|
Heads = geometry.heads,
|
2017-12-31 23:34:02 +00:00
|
|
|
|
SectorsPerTrack = geometry.sectorsPerTrack
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
try { writingStream = new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); }
|
|
|
|
|
|
catch(IOException e)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = $"Could not create new image file, exception {e.Message}";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IsWriting = true;
|
|
|
|
|
|
ErrorMessage = null;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteMediaTag(byte[] data, MediaTagType tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Writing media tags is not supported.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSector(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write on a non-writable image";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(data.Length != 512)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Incorrect data size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress >= imageInfo.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write past image size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-31 23:38:45 +00:00
|
|
|
|
writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize),
|
|
|
|
|
|
SeekOrigin.Begin);
|
2017-12-31 23:34:02 +00:00
|
|
|
|
writingStream.Write(data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write on a non-writable image";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(data.Length % 512 != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Incorrect data size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(sectorAddress + length > imageInfo.Sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Tried to write past image size";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-31 23:38:45 +00:00
|
|
|
|
writingStream.Seek((long)((ulong)Marshal.SizeOf(typeof(RayHdr)) + sectorAddress * imageInfo.SectorSize),
|
|
|
|
|
|
SeekOrigin.Begin);
|
2017-12-31 23:34:02 +00:00
|
|
|
|
writingStream.Write(data, 0, data.Length);
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Writing sectors with tags is not supported.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Writing sectors with tags is not supported.";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool SetTracks(List<Track> tracks)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Unsupported feature";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-01 20:56:33 +00:00
|
|
|
|
public bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Geometry is set by media type
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-31 23:34:02 +00:00
|
|
|
|
public bool Close()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
|
|
|
|
|
ErrorMessage = "Image is not opened for writing";
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string headerSignature =
|
|
|
|
|
|
$"Disk IMage VER 1.0 Copyright (C) ({DateTime.Now.Year:D4}) Ray Arachelian, All Rights Reserved. DIC ";
|
|
|
|
|
|
RayHdr header = new RayHdr
|
|
|
|
|
|
{
|
|
|
|
|
|
signature = Encoding.ASCII.GetBytes(headerSignature),
|
|
|
|
|
|
cylinders = (byte)imageInfo.Cylinders,
|
|
|
|
|
|
diskType = RayDiskTypes.Mf2ed,
|
|
|
|
|
|
heads = (byte)imageInfo.Heads,
|
|
|
|
|
|
sectorsPerTrack = (byte)imageInfo.SectorsPerTrack
|
|
|
|
|
|
};
|
|
|
|
|
|
header.signature[0x4A] = 0x00;
|
|
|
|
|
|
|
|
|
|
|
|
byte[] hdr = new byte[Marshal.SizeOf(header)];
|
|
|
|
|
|
IntPtr hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header));
|
|
|
|
|
|
Marshal.StructureToPtr(header, hdrPtr, true);
|
|
|
|
|
|
Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
|
|
|
|
|
Marshal.FreeHGlobal(hdrPtr);
|
|
|
|
|
|
|
|
|
|
|
|
writingStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
writingStream.Write(hdr, 0, hdr.Length);
|
|
|
|
|
|
|
|
|
|
|
|
writingStream.Flush();
|
|
|
|
|
|
writingStream.Close();
|
|
|
|
|
|
IsWriting = false;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool SetMetadata(ImageInfo metadata)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2017-12-31 23:38:45 +00:00
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
|
struct RayHdr
|
|
|
|
|
|
{
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 80)]
|
|
|
|
|
|
public byte[] signature;
|
|
|
|
|
|
public RayDiskTypes diskType;
|
|
|
|
|
|
public byte cylinders;
|
|
|
|
|
|
public byte sectorsPerTrack;
|
|
|
|
|
|
public byte heads;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
|
enum RayDiskTypes : byte
|
|
|
|
|
|
{
|
|
|
|
|
|
Md2dd = 1,
|
|
|
|
|
|
Md2hd = 2,
|
|
|
|
|
|
Mf2dd = 3,
|
|
|
|
|
|
Mf2hd = 4,
|
|
|
|
|
|
Mf2ed = 5
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|