2017-12-03 01:49:33 +00:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Filename : Read.cs
|
2017-12-03 01:49:33 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Disk image plugins.
|
2017-12-03 01:49:33 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// Reads SuperCardPro flux images.
|
2017-12-03 01:49:33 +00: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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2018-12-29 17:34:38 +00:00
|
|
|
|
// Copyright © 2011-2019 Natalia Portillo
|
2017-12-03 01:49:33 +00:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2018-06-25 19:08:16 +01:00
|
|
|
|
using DiscImageChef.CommonTypes.Enums;
|
|
|
|
|
|
using DiscImageChef.CommonTypes.Interfaces;
|
2017-12-03 01:49:33 +00:00
|
|
|
|
using DiscImageChef.Console;
|
2019-03-01 07:35:22 +00:00
|
|
|
|
using DiscImageChef.Helpers;
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
namespace DiscImageChef.DiscImages
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public partial class SuperCardPro
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2017-12-28 19:56:36 +00:00
|
|
|
|
public bool Open(IFilter imageFilter)
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
Header = new ScpHeader();
|
2017-12-06 01:31:37 +00:00
|
|
|
|
scpStream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
scpStream.Seek(0, SeekOrigin.Begin);
|
2019-03-01 07:35:22 +00:00
|
|
|
|
if(scpStream.Length < Marshal.SizeOf<ScpHeader>()) return false;
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
byte[] hdr = new byte[Marshal.SizeOf<ScpHeader>()];
|
|
|
|
|
|
scpStream.Read(hdr, 0, Marshal.SizeOf<ScpHeader>());
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
Header = Marshal.ByteArrayToStructureLittleEndian<ScpHeader>(hdr);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.signature = \"{0}\"",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
StringHandlers.CToString(Header.signature));
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.version = {0}.{1}", (Header.version & 0xF0) >> 4,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Header.version & 0xF);
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.type = {0}", Header.type);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.revolutions = {0}", Header.revolutions);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.start = {0}", Header.start);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.end = {0}", Header.end);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.flags = {0}", Header.flags);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.bitCellEncoding = {0}", Header.bitCellEncoding);
|
2018-01-28 20:29:46 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.heads = {0}", Header.heads);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.reserved = {0}", Header.reserved);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "header.checksum = 0x{0:X8}", Header.checksum);
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
|
|
|
|
|
if(!scpSignature.SequenceEqual(Header.signature)) return false;
|
|
|
|
|
|
|
2017-12-26 02:51:10 +00:00
|
|
|
|
ScpTracks = new Dictionary<byte, TrackHeader>();
|
2017-12-20 17:15:26 +00:00
|
|
|
|
|
|
|
|
|
|
for(byte t = Header.start; t <= Header.end; t++)
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(t >= Header.offsets.Length) break;
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
scpStream.Position = Header.offsets[t];
|
|
|
|
|
|
TrackHeader trk =
|
2017-12-22 06:55:04 +00:00
|
|
|
|
new TrackHeader {Signature = new byte[3], Entries = new TrackEntry[Header.revolutions]};
|
2017-12-20 17:15:26 +00:00
|
|
|
|
scpStream.Read(trk.Signature, 0, trk.Signature.Length);
|
|
|
|
|
|
trk.TrackNumber = (byte)scpStream.ReadByte();
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(!trk.Signature.SequenceEqual(trkSignature))
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
"Track header at {0} contains incorrect signature.", Header.offsets[t]);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(trk.TrackNumber != t)
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "Track number at {0} should be {1} but is {2}.",
|
2017-12-20 17:15:26 +00:00
|
|
|
|
Header.offsets[t], t, trk.TrackNumber);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "Found track {0} at {1}.", t, Header.offsets[t]);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
for(byte r = 0; r < Header.revolutions; r++)
|
2017-12-03 01:49:33 +00:00
|
|
|
|
{
|
2019-03-01 07:35:22 +00:00
|
|
|
|
byte[] rev = new byte[Marshal.SizeOf<TrackEntry>()];
|
|
|
|
|
|
scpStream.Read(rev, 0, Marshal.SizeOf<TrackEntry>());
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
trk.Entries[r] = Marshal.ByteArrayToStructureLittleEndian<TrackEntry>(rev);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
// De-relative offsets
|
2017-12-20 17:15:26 +00:00
|
|
|
|
trk.Entries[r].dataOffset += Header.offsets[t];
|
2017-12-03 01:49:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 02:51:10 +00:00
|
|
|
|
ScpTracks.Add(t, trk);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(Header.flags.HasFlag(ScpFlags.HasFooter))
|
2017-12-05 20:38:47 +00:00
|
|
|
|
{
|
2017-12-06 01:31:37 +00:00
|
|
|
|
long position = scpStream.Position;
|
|
|
|
|
|
scpStream.Seek(-4, SeekOrigin.End);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-06 01:31:37 +00:00
|
|
|
|
while(scpStream.Position >= position)
|
2017-12-05 20:38:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
byte[] footerSig = new byte[4];
|
2017-12-06 01:31:37 +00:00
|
|
|
|
scpStream.Read(footerSig, 0, 4);
|
2017-12-05 20:38:47 +00:00
|
|
|
|
uint footerMagic = BitConverter.ToUInt32(footerSig, 0);
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
if(footerMagic == FOOTER_SIGNATURE)
|
2017-12-05 20:38:47 +00:00
|
|
|
|
{
|
2019-03-01 07:35:22 +00:00
|
|
|
|
scpStream.Seek(-Marshal.SizeOf<ScpFooter>(), SeekOrigin.Current);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-06 01:31:37 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "Found footer at {0}", scpStream.Position);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
byte[] ftr = new byte[Marshal.SizeOf<ScpFooter>()];
|
|
|
|
|
|
scpStream.Read(ftr, 0, Marshal.SizeOf<ScpFooter>());
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2019-03-01 07:35:22 +00:00
|
|
|
|
ScpFooter footer = Marshal.ByteArrayToStructureLittleEndian<ScpFooter>(ftr);
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.manufacturerOffset = 0x{0:X8}",
|
|
|
|
|
|
footer.manufacturerOffset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.modelOffset = 0x{0:X8}",
|
|
|
|
|
|
footer.modelOffset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.serialOffset = 0x{0:X8}",
|
|
|
|
|
|
footer.serialOffset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.creatorOffset = 0x{0:X8}",
|
|
|
|
|
|
footer.creatorOffset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.applicationOffset = 0x{0:X8}",
|
|
|
|
|
|
footer.applicationOffset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.commentsOffset = 0x{0:X8}",
|
|
|
|
|
|
footer.commentsOffset);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.creationTime = {0}",
|
|
|
|
|
|
footer.creationTime);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.modificationTime = {0}",
|
|
|
|
|
|
footer.modificationTime);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.applicationVersion = {0}.{1}",
|
|
|
|
|
|
(footer.applicationVersion & 0xF0) >> 4,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
footer.applicationVersion & 0xF);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.hardwareVersion = {0}.{1}",
|
|
|
|
|
|
(footer.hardwareVersion & 0xF0) >> 4, footer.hardwareVersion & 0xF);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.firmwareVersion = {0}.{1}",
|
|
|
|
|
|
(footer.firmwareVersion & 0xF0) >> 4, footer.firmwareVersion & 0xF);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.imageVersion = {0}.{1}",
|
|
|
|
|
|
(footer.imageVersion & 0xF0) >> 4, footer.imageVersion & 0xF);
|
|
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "footer.signature = \"{0}\"",
|
|
|
|
|
|
StringHandlers.CToString(BitConverter.GetBytes(footer.signature)));
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.DriveManufacturer = ReadPStringUtf8(scpStream, footer.manufacturerOffset);
|
2018-01-28 20:29:46 +00:00
|
|
|
|
imageInfo.DriveModel = ReadPStringUtf8(scpStream, footer.modelOffset);
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.DriveSerialNumber = ReadPStringUtf8(scpStream, footer.serialOffset);
|
2018-01-28 20:29:46 +00:00
|
|
|
|
imageInfo.Creator = ReadPStringUtf8(scpStream, footer.creatorOffset);
|
|
|
|
|
|
imageInfo.Application = ReadPStringUtf8(scpStream, footer.applicationOffset);
|
|
|
|
|
|
imageInfo.Comments = ReadPStringUtf8(scpStream, footer.commentsOffset);
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.driveManufacturer = \"{0}\"",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.DriveManufacturer);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.driveModel = \"{0}\"",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.DriveModel);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.driveSerialNumber = \"{0}\"",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.DriveSerialNumber);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.imageCreator = \"{0}\"",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Creator);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.imageApplication = \"{0}\"",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Application);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.imageComments = \"{0}\"",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.Comments);
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.CreationTime = footer.creationTime != 0
|
|
|
|
|
|
? DateHandlers.UnixToDateTime(footer.creationTime)
|
|
|
|
|
|
: imageFilter.GetCreationTime();
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime = footer.modificationTime != 0
|
|
|
|
|
|
? DateHandlers.UnixToDateTime(footer.modificationTime)
|
|
|
|
|
|
: imageFilter.GetLastWriteTime();
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.imageCreationTime = {0}",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.CreationTime);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
DicConsole.DebugWriteLine("SuperCardPro plugin", "ImageInfo.imageLastModificationTime = {0}",
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime);
|
2017-12-05 20:38:47 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.ApplicationVersion =
|
2017-12-21 17:58:51 +00:00
|
|
|
|
$"{(footer.applicationVersion & 0xF0) >> 4}.{footer.applicationVersion & 0xF}";
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.DriveFirmwareRevision =
|
2018-06-22 08:08:38 +01:00
|
|
|
|
$"{(footer.firmwareVersion & 0xF0) >> 4}.{footer.firmwareVersion & 0xF}";
|
|
|
|
|
|
imageInfo.Version = $"{(footer.imageVersion & 0xF0) >> 4}.{footer.imageVersion & 0xF}";
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-05 20:38:47 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-06 01:31:37 +00:00
|
|
|
|
scpStream.Seek(-8, SeekOrigin.Current);
|
2017-12-05 20:38:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-01-28 20:29:46 +00:00
|
|
|
|
imageInfo.Application = "SuperCardPro";
|
|
|
|
|
|
imageInfo.ApplicationVersion = $"{(Header.version & 0xF0) >> 4}.{Header.version & 0xF}";
|
|
|
|
|
|
imageInfo.CreationTime = imageFilter.GetCreationTime();
|
2017-12-26 06:05:12 +00:00
|
|
|
|
imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
|
2018-01-28 20:29:46 +00:00
|
|
|
|
imageInfo.Version = "1.5";
|
2017-12-05 20:38:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadDiskTag(MediaTagType tag) =>
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1);
|
2017-12-03 01:49:33 +00:00
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) =>
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length) =>
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorsTag(ulong sectorAddress, uint length, SectorTagType tag) =>
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorLong(ulong sectorAddress) =>
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSectorsLong(ulong sectorAddress, uint length) =>
|
2017-12-03 01:49:33 +00:00
|
|
|
|
throw new NotImplementedException("Flux decoding is not yet implemented.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|