2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-08-22 00:49:48 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Human68k.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Component : Partitioning scheme plugins.
|
2016-08-22 00:49:48 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
// Manages Human68k (Sharp X68000) partitions.
|
2016-08-22 00:49:48 +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
|
2016-08-22 00:49:48 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
|
|
|
|
using DiscImageChef.Console;
|
2017-12-20 17:15:26 +00:00
|
|
|
using DiscImageChef.DiscImages;
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
namespace DiscImageChef.Partitions
|
2016-08-22 00:49:48 +01:00
|
|
|
{
|
2017-12-20 17:15:26 +00:00
|
|
|
public class Human68K : PartitionPlugin
|
2016-08-22 00:49:48 +01:00
|
|
|
{
|
2017-12-22 16:53:11 +00:00
|
|
|
const uint X68K_MAGIC = 0x5836384B;
|
2016-08-22 00:49:48 +01:00
|
|
|
|
|
|
|
|
public Human68K()
|
|
|
|
|
{
|
|
|
|
|
Name = "Human 68k partitions";
|
2017-12-20 17:15:26 +00:00
|
|
|
PluginUuid = new Guid("246A6D93-4F1A-1F8A-344D-50187A5513A9");
|
2016-08-22 00:49:48 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-24 23:35:33 +01:00
|
|
|
public override bool GetInformation(ImagePlugin imagePlugin, out List<Partition> partitions, ulong sectorOffset)
|
2016-08-22 00:49:48 +01:00
|
|
|
{
|
|
|
|
|
partitions = new List<Partition>();
|
|
|
|
|
|
|
|
|
|
byte[] sector;
|
2017-12-21 16:07:20 +00:00
|
|
|
ulong sectsPerUnit;
|
2016-08-22 00:49:48 +01:00
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "sectorSize = {0}", imagePlugin.GetSectorSize());
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
if(sectorOffset + 4 >= imagePlugin.GetSectors()) return false;
|
2017-07-24 23:35:33 +01:00
|
|
|
|
2016-08-22 00:49:48 +01:00
|
|
|
switch(imagePlugin.GetSectorSize())
|
|
|
|
|
{
|
|
|
|
|
case 256:
|
2017-07-24 23:35:33 +01:00
|
|
|
sector = imagePlugin.ReadSector(4 + sectorOffset);
|
2016-08-22 00:49:48 +01:00
|
|
|
sectsPerUnit = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 512:
|
2017-07-24 23:35:33 +01:00
|
|
|
sector = imagePlugin.ReadSector(4 + sectorOffset);
|
2016-08-22 00:49:48 +01:00
|
|
|
sectsPerUnit = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 1024:
|
2017-07-24 23:35:33 +01:00
|
|
|
sector = imagePlugin.ReadSector(2 + sectorOffset);
|
2016-08-22 00:49:48 +01:00
|
|
|
sectsPerUnit = 1;
|
|
|
|
|
break;
|
2017-12-19 20:33:03 +00:00
|
|
|
default: return false;
|
2016-08-22 00:49:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
X68kTable table = BigEndianMarshal.ByteArrayToStructureBigEndian<X68kTable>(sector);
|
2017-07-24 04:51:08 +01:00
|
|
|
|
2017-07-24 23:35:33 +01:00
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "table.magic = {0:X4}", table.magic);
|
|
|
|
|
|
2017-12-22 16:53:11 +00:00
|
|
|
if(table.magic != X68K_MAGIC) return false;
|
2017-07-24 04:51:08 +01:00
|
|
|
|
2016-08-22 00:49:48 +01:00
|
|
|
for(int i = 0; i < table.entries.Length; i++)
|
|
|
|
|
table.entries[i] = BigEndianMarshal.SwapStructureMembersEndian(table.entries[i]);
|
|
|
|
|
|
|
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "table.size = {0:X4}", table.size);
|
|
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "table.size2 = {0:X4}", table.size2);
|
|
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "table.unknown = {0:X4}", table.unknown);
|
|
|
|
|
|
|
|
|
|
ulong counter = 0;
|
|
|
|
|
|
|
|
|
|
foreach(X68kEntry entry in table.entries)
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "entry.name = {0}",
|
|
|
|
|
StringHandlers.CToString(entry.name, Encoding.GetEncoding(932)));
|
2016-08-22 00:49:48 +01:00
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "entry.stateStart = {0}", entry.stateStart);
|
|
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "entry.length = {0}", entry.length);
|
2017-12-19 20:33:03 +00:00
|
|
|
DicConsole.DebugWriteLine("Human68k plugin", "sectsPerUnit = {0} {1}", sectsPerUnit,
|
|
|
|
|
imagePlugin.GetSectorSize());
|
2016-08-22 00:49:48 +01:00
|
|
|
|
2017-07-23 22:54:36 +01:00
|
|
|
Partition part = new Partition
|
|
|
|
|
{
|
|
|
|
|
Start = (entry.stateStart & 0xFFFFFF) * sectsPerUnit,
|
|
|
|
|
Length = entry.length * sectsPerUnit,
|
|
|
|
|
Type = StringHandlers.CToString(entry.name, Encoding.GetEncoding(932)),
|
|
|
|
|
Sequence = counter,
|
|
|
|
|
Scheme = Name
|
|
|
|
|
};
|
2017-07-19 16:37:11 +01:00
|
|
|
part.Offset = part.Start * (ulong)sector.Length;
|
|
|
|
|
part.Size = part.Length * (ulong)sector.Length;
|
2017-12-21 06:06:19 +00:00
|
|
|
if(entry.length <= 0) continue;
|
|
|
|
|
|
|
|
|
|
partitions.Add(part);
|
|
|
|
|
counter++;
|
2016-08-22 00:49:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct X68kTable
|
|
|
|
|
{
|
|
|
|
|
public uint magic;
|
|
|
|
|
public uint size;
|
|
|
|
|
public uint size2;
|
|
|
|
|
public uint unknown;
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public X68kEntry[] entries;
|
2016-08-22 00:49:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
|
|
|
struct X68kEntry
|
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] name;
|
2016-08-22 00:49:48 +01:00
|
|
|
public uint stateStart;
|
|
|
|
|
public uint length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|