mirror of
https://github.com/SabreTools/SabreTools.Models.git
synced 2026-07-24 09:42:16 +00:00
Add first set of CHD models
This commit is contained in:
28
CHD/CompressedMapEntryV5.cs
Normal file
28
CHD/CompressedMapEntryV5.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class CompressedMapEntryV5
|
||||
{
|
||||
/// <summary>
|
||||
/// Compression type
|
||||
/// </summary>
|
||||
public byte Compression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compressed length
|
||||
/// </summary>
|
||||
/// <remarks>Actually UInt24</remarks>
|
||||
public uint CompLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset
|
||||
/// </summary>
|
||||
/// <remarks>Actually UInt48</remarks>
|
||||
public ulong Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CRC-16 of the data
|
||||
/// </summary>
|
||||
public ushort CRC { get; set; }
|
||||
}
|
||||
}
|
||||
42
CHD/CompressedMapHeaderV5.cs
Normal file
42
CHD/CompressedMapHeaderV5.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class CompressedMapHeaderV5
|
||||
{
|
||||
/// <summary>
|
||||
/// Length of compressed map
|
||||
/// </summary>
|
||||
public uint Length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset of first block
|
||||
/// </summary>
|
||||
/// <remarks>Actually UInt48</remarks>
|
||||
public ulong DataStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CRC-16 of the map
|
||||
/// </summary>
|
||||
public ushort CRC { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Bits used to encode complength
|
||||
/// </summary>
|
||||
public byte LengthBits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Bits used to encode self-refs
|
||||
/// </summary>
|
||||
public byte HunkBits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Bits used to encode parent unit refs
|
||||
/// </summary>
|
||||
public byte ParentUnitBits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Future use
|
||||
/// </summary>
|
||||
public byte Reserved { get; set; }
|
||||
}
|
||||
}
|
||||
42
CHD/Enums.cs
Normal file
42
CHD/Enums.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public enum CompressionType : uint
|
||||
{
|
||||
#region V1
|
||||
|
||||
CHDCOMPRESSION_NONE = 0,
|
||||
CHDCOMPRESSION_ZLIB = 1,
|
||||
|
||||
#endregion
|
||||
|
||||
#region V3
|
||||
|
||||
CHDCOMPRESSION_ZLIB_PLUS = 2,
|
||||
|
||||
#endregion
|
||||
|
||||
#region V4
|
||||
|
||||
CHDCOMPRESSION_AV = 3,
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
[Flags]
|
||||
public enum Flags : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Set if this drive has a parent
|
||||
/// </summary>
|
||||
DriveHasParent = 0x00000001,
|
||||
|
||||
/// <summary>
|
||||
/// Set if this drive allows writes
|
||||
/// </summary>
|
||||
DriveAllowsWrites = 0x00000002,
|
||||
}
|
||||
}
|
||||
25
CHD/Header.cs
Normal file
25
CHD/Header.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public abstract class Header
|
||||
{
|
||||
/// <summary>
|
||||
/// 'MComprHD'
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public string Tag { get; set; }
|
||||
#else
|
||||
public string? Tag { get; set; }
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Length of header (including tag and length fields)
|
||||
/// </summary>
|
||||
public uint Length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Drive format version
|
||||
/// </summary>
|
||||
public uint Version { get; set; }
|
||||
}
|
||||
}
|
||||
59
CHD/HeaderV1.cs
Normal file
59
CHD/HeaderV1.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class HeaderV1 : Header
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags
|
||||
/// </summary>
|
||||
public Flags Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compression type
|
||||
/// </summary>
|
||||
public CompressionType Compression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 512-byte sectors per hunk
|
||||
/// </summary>
|
||||
public uint HunkSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total # of hunks represented
|
||||
/// </summary>
|
||||
public uint TotalHunks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of cylinders on hard disk
|
||||
/// </summary>
|
||||
public uint Cylinders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of heads on hard disk
|
||||
/// </summary>
|
||||
public uint Heads { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of sectors on hard disk
|
||||
/// </summary>
|
||||
public uint Sectors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MD5 checksum of raw data
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] MD5 { get; set; } = new byte[16];
|
||||
#else
|
||||
public byte[]? MD5 { get; set; } = new byte[16];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// MD5 checksum of parent file
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] ParentMD5 { get; set; } = new byte[16];
|
||||
#else
|
||||
public byte[]? ParentMD5 { get; set; } = new byte[16];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
64
CHD/HeaderV2.cs
Normal file
64
CHD/HeaderV2.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class HeaderV2 : Header
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags
|
||||
/// </summary>
|
||||
public Flags Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compression type
|
||||
/// </summary>
|
||||
public CompressionType Compression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Seclen-byte sectors per hunk
|
||||
/// </summary>
|
||||
public uint HunkSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total # of hunks represented
|
||||
/// </summary>
|
||||
public uint TotalHunks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of cylinders on hard disk
|
||||
/// </summary>
|
||||
public uint Cylinders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of heads on hard disk
|
||||
/// </summary>
|
||||
public uint Heads { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of sectors on hard disk
|
||||
/// </summary>
|
||||
public uint Sectors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MD5 checksum of raw data
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] MD5 { get; set; } = new byte[16];
|
||||
#else
|
||||
public byte[]? MD5 { get; set; } = new byte[16];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// MD5 checksum of parent file
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] ParentMD5 { get; set; } = new byte[16];
|
||||
#else
|
||||
public byte[]? ParentMD5 { get; set; } = new byte[16];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes per sector
|
||||
/// </summary>
|
||||
public uint BytesPerSector { get; set; }
|
||||
}
|
||||
}
|
||||
72
CHD/HeaderV3.cs
Normal file
72
CHD/HeaderV3.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class HeaderV3 : Header
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags
|
||||
/// </summary>
|
||||
public Flags Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compression type
|
||||
/// </summary>
|
||||
public CompressionType Compression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total # of hunks represented
|
||||
/// </summary>
|
||||
public uint TotalHunks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Logical size of the data (in bytes)
|
||||
/// </summary>
|
||||
public ulong LogicalBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset to the first blob of metadata
|
||||
/// </summary>
|
||||
public ulong MetaOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MD5 checksum of raw data
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] MD5 { get; set; } = new byte[16];
|
||||
#else
|
||||
public byte[]? MD5 { get; set; } = new byte[16];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// MD5 checksum of parent file
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] ParentMD5 { get; set; } = new byte[16];
|
||||
#else
|
||||
public byte[]? ParentMD5 { get; set; } = new byte[16];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes per hunk
|
||||
/// </summary>
|
||||
public uint HunkBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SHA1 checksum of raw data
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] SHA1 { get; set; } = new byte[20];
|
||||
#else
|
||||
public byte[]? SHA1 { get; set; } = new byte[20];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// SHA1 checksum of parent file
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] ParentSHA1 { get; set; } = new byte[20];
|
||||
#else
|
||||
public byte[]? ParentSHA1 { get; set; } = new byte[20];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
63
CHD/HeaderV4.cs
Normal file
63
CHD/HeaderV4.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class HeaderV4 : Header
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags
|
||||
/// </summary>
|
||||
public Flags Flags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compression type
|
||||
/// </summary>
|
||||
public CompressionType Compression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total # of hunks represented
|
||||
/// </summary>
|
||||
public uint TotalHunks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Logical size of the data (in bytes)
|
||||
/// </summary>
|
||||
public ulong LogicalBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset to the first blob of metadata
|
||||
/// </summary>
|
||||
public ulong MetaOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes per hunk
|
||||
/// </summary>
|
||||
public uint HunkBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Combined raw+meta SHA1
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] SHA1 { get; set; } = new byte[20];
|
||||
#else
|
||||
public byte[]? SHA1 { get; set; } = new byte[20];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Combined raw+meta SHA1 of parent
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] ParentSHA1 { get; set; } = new byte[20];
|
||||
#else
|
||||
public byte[]? ParentSHA1 { get; set; } = new byte[20];
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Raw data SHA1
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] RawSHA1 { get; set; } = new byte[20];
|
||||
#else
|
||||
public byte[]? RawSHA1 { get; set; } = new byte[20];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
63
CHD/HeaderV5.cs
Normal file
63
CHD/HeaderV5.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class HeaderV5 : Header
|
||||
{
|
||||
/// <summary>
|
||||
/// Which custom compressors are used?
|
||||
/// </summary>
|
||||
public uint[] Compressors { get; set; } = new uint[4];
|
||||
|
||||
/// <summary>
|
||||
/// Logical size of the data (in bytes)
|
||||
/// </summary>
|
||||
public ulong LogicalBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset to the map
|
||||
/// </summary>
|
||||
public ulong MapOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset to the first blob of metadata
|
||||
/// </summary>
|
||||
public ulong MetaOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes per hunk (512k maximum)
|
||||
/// </summary>
|
||||
public uint HunkBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes per unit within each hunk
|
||||
/// </summary>
|
||||
public uint UnitBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Raw data SHA1
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] RawSHA1 { get; set; }
|
||||
#else
|
||||
public byte[]? RawSHA1 { get; set; }
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Combined raw+meta SHA1
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] SHA1 { get; set; }
|
||||
#else
|
||||
public byte[]? SHA1 { get; set; }
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Combined raw+meta SHA1 of parent
|
||||
/// </summary>
|
||||
#if NET48
|
||||
public byte[] ParentSHA1 { get; set; }
|
||||
#else
|
||||
public byte[]? ParentSHA1 { get; set; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
16
CHD/MapV1.cs
Normal file
16
CHD/MapV1.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class MapV1
|
||||
{
|
||||
/// <summary>
|
||||
/// Starting offset within the file
|
||||
/// </summary>
|
||||
public ulong StartingOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Length of data; If == hunksize, data is uncompressed
|
||||
/// </summary>
|
||||
public ulong Length { get; set; }
|
||||
}
|
||||
}
|
||||
31
CHD/MapV3.cs
Normal file
31
CHD/MapV3.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class MapV3
|
||||
{
|
||||
/// <summary>
|
||||
/// Starting offset within the file
|
||||
/// </summary>
|
||||
public ulong StartingOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 32-bit CRC of the uncompressed data
|
||||
/// </summary>
|
||||
public uint CRC32 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Lower 16 bits of length
|
||||
/// </summary>
|
||||
public ushort LengthLo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Upper 8 bits of length
|
||||
/// </summary>
|
||||
public byte LengthHi { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Flags, indicating compression info
|
||||
/// </summary>
|
||||
public byte Flags { get; set; }
|
||||
}
|
||||
}
|
||||
11
CHD/UncompressedMapV5.cs
Normal file
11
CHD/UncompressedMapV5.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace SabreTools.Models.CHD
|
||||
{
|
||||
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
|
||||
public class UncompressedMapV5
|
||||
{
|
||||
/// <summary>
|
||||
/// Starting offset / hunk size
|
||||
/// </summary>
|
||||
public uint StartingOffset { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user