2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Read.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Disk image plugins.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Reads 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-12-31 23:08:23 +00:00
|
|
|
|
// Copyright © 2011-2021 Natalia Portillo
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
|
namespace Aaru.DiscImages
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2020-07-22 13:20:25 +01:00
|
|
|
|
public sealed partial class AppleDos
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-09-16 19:10:39 +01:00
|
|
|
|
public ErrorNumber Open(IFilter imageFilter)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
Stream stream = imageFilter.GetDataForkStream();
|
|
|
|
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
2021-09-15 11:25:26 +01:00
|
|
|
|
byte[] tmp = new byte[imageFilter.DataForkLength];
|
2018-07-23 23:25:43 +01:00
|
|
|
|
stream.Read(tmp, 0, tmp.Length);
|
|
|
|
|
|
|
2021-09-15 11:25:26 +01:00
|
|
|
|
_extension = Path.GetExtension(imageFilter.Filename)?.ToLower();
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2021-06-08 03:10:42 +01:00
|
|
|
|
if((_extension == ".d13" || _extension == ".do") &&
|
|
|
|
|
|
tmp.Length == 116480)
|
|
|
|
|
|
{
|
|
|
|
|
|
_dos32 = true;
|
|
|
|
|
|
_deinterleaved = tmp;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2021-06-08 03:10:42 +01:00
|
|
|
|
bool isDos = tmp[0x11001] == 17 && tmp[0x11002] < 16 && tmp[0x11027] <= 122 && tmp[0x11034] == 35 &&
|
|
|
|
|
|
tmp[0x11035] == 16 && tmp[0x11036] == 0 && tmp[0x11037] == 1;
|
|
|
|
|
|
|
|
|
|
|
|
_deinterleaved = new byte[tmp.Length];
|
|
|
|
|
|
|
|
|
|
|
|
int[] offsets = _extension == ".do"
|
|
|
|
|
|
? isDos
|
|
|
|
|
|
? _deinterleave
|
|
|
|
|
|
: _interleave
|
|
|
|
|
|
: isDos
|
|
|
|
|
|
? _interleave
|
|
|
|
|
|
: _deinterleave;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.SectorSize = 256;
|
2021-09-15 11:25:26 +01:00
|
|
|
|
_imageInfo.ImageSize = (ulong)imageFilter.DataForkLength;
|
|
|
|
|
|
_imageInfo.CreationTime = imageFilter.CreationTime;
|
|
|
|
|
|
_imageInfo.LastModificationTime = imageFilter.LastWriteTime;
|
|
|
|
|
|
_imageInfo.MediaTitle = Path.GetFileNameWithoutExtension(imageFilter.Filename);
|
2021-06-08 03:10:42 +01:00
|
|
|
|
_imageInfo.Sectors = _dos32 ? 455u : 560u;
|
|
|
|
|
|
_imageInfo.MediaType = _dos32 ? MediaType.Apple32SS : MediaType.Apple33SS;
|
2020-07-20 21:11:32 +01:00
|
|
|
|
_imageInfo.XmlMediaType = XmlMediaType.BlockMedia;
|
|
|
|
|
|
_imageInfo.Cylinders = 35;
|
2021-06-08 03:10:42 +01:00
|
|
|
|
_imageInfo.Heads = 1;
|
|
|
|
|
|
_imageInfo.SectorsPerTrack = _dos32 ? 13u : 16u;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2021-09-16 19:10:39 +01:00
|
|
|
|
return ErrorNumber.NoError;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-12-31 13:17:27 +00:00
|
|
|
|
public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2021-08-17 13:56:05 +01:00
|
|
|
|
/// <inheritdoc />
|
2018-07-23 23:25:43 +01:00
|
|
|
|
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress > _imageInfo.Sectors - 1)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
if(sectorAddress + length > _imageInfo.Sectors)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(length), "Requested more sectors than available");
|
|
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
byte[] buffer = new byte[length * _imageInfo.SectorSize];
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2020-07-20 21:11:32 +01:00
|
|
|
|
Array.Copy(_deinterleaved, (int)(sectorAddress * _imageInfo.SectorSize), buffer, 0, buffer.Length);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|