[CBM] Use new source generator based big endian marshaller

This commit is contained in:
2025-10-21 02:47:45 +01:00
parent 9c764a4076
commit aa75699bf2
2 changed files with 54 additions and 51 deletions

View File

@@ -27,6 +27,7 @@
// ****************************************************************************/
using System.Runtime.InteropServices;
using Aaru.CommonTypes.Attributes;
using Aaru.CommonTypes.Interfaces;
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
@@ -39,46 +40,47 @@ public sealed partial class CBM
#region Nested type: BAM
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct BAM
[SwapEndian]
partial struct BAM
{
/// <summary>Track where directory starts</summary>
public readonly byte directoryTrack;
public byte directoryTrack;
/// <summary>Sector where directory starts</summary>
public readonly byte directorySector;
public byte directorySector;
/// <summary>Disk DOS version, 0x41</summary>
public readonly byte dosVersion;
public byte dosVersion;
/// <summary>Set to 0x80 if 1571, 0x00 if not</summary>
public readonly byte doubleSided;
public byte doubleSided;
/// <summary>Block allocation map</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 140)]
public readonly byte[] bam;
public byte[] bam;
/// <summary>Disk name</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] name;
public byte[] name;
/// <summary>Filled with 0xA0</summary>
public readonly ushort fill1;
public ushort fill1;
/// <summary>Disk ID</summary>
public readonly ushort diskId;
public ushort diskId;
/// <summary>Filled with 0xA0</summary>
public readonly byte fill2;
public byte fill2;
/// <summary>DOS type</summary>
public readonly ushort dosType;
public ushort dosType;
/// <summary>Filled with 0xA0</summary>
public readonly uint fill3;
public uint fill3;
/// <summary>Unused</summary>
public readonly byte unused1;
public byte unused1;
/// <summary>Block allocation map for Dolphin DOS extended tracks</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public readonly byte[] dolphinBam;
public byte[] dolphinBam;
/// <summary>Block allocation map for Speed DOS extended tracks</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public readonly byte[] speedBam;
public byte[] speedBam;
/// <summary>Unused</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
public readonly byte[] unused2;
public byte[] unused2;
/// <summary>Free sector count for second side in 1571</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
public readonly byte[] freeCount;
public byte[] freeCount;
}
#endregion
@@ -138,22 +140,23 @@ public sealed partial class CBM
#region Nested type: DirectoryEntry
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct DirectoryEntry
[SwapEndian]
partial struct DirectoryEntry
{
public readonly byte nextDirBlockTrack;
public readonly byte nextDirBlockSector;
public readonly byte fileType;
public readonly byte firstFileBlockTrack;
public readonly byte firstFileBlockSector;
public byte nextDirBlockTrack;
public byte nextDirBlockSector;
public byte fileType;
public byte firstFileBlockTrack;
public byte firstFileBlockSector;
/// <summary>Filename</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] name;
public readonly byte firstSideBlockTrack;
public readonly byte firstSideBlockSector;
public readonly uint unused;
public readonly byte replacementTrack;
public readonly byte replacementSector;
public readonly short blocks;
public byte[] name;
public byte firstSideBlockTrack;
public byte firstSideBlockSector;
public uint unused;
public byte replacementTrack;
public byte replacementSector;
public short blocks;
}
#endregion
@@ -161,31 +164,32 @@ public sealed partial class CBM
#region Nested type: Header
[StructLayout(LayoutKind.Sequential, Pack = 1)]
readonly struct Header
[SwapEndian]
partial struct Header
{
/// <summary>Track where directory starts</summary>
public readonly byte directoryTrack;
public byte directoryTrack;
/// <summary>Sector where directory starts</summary>
public readonly byte directorySector;
public byte directorySector;
/// <summary>Disk DOS version, 0x44</summary>
public readonly byte diskDosVersion;
public byte diskDosVersion;
/// <summary>Unusued</summary>
public readonly byte unused1;
public byte unused1;
/// <summary>Disk name</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public readonly byte[] name;
public byte[] name;
/// <summary>Filled with 0xA0</summary>
public readonly ushort fill1;
public ushort fill1;
/// <summary>Disk ID</summary>
public readonly ushort diskId;
public ushort diskId;
/// <summary>Filled with 0xA0</summary>
public readonly byte fill2;
public byte fill2;
/// <summary>DOS version ('3')</summary>
public readonly byte dosVersion;
public byte dosVersion;
/// <summary>Disk version ('D')</summary>
public readonly byte diskVersion;
public byte diskVersion;
/// <summary>Filled with 0xA0</summary>
public readonly short fill3;
public short fill3;
}
#endregion

View File

@@ -88,7 +88,7 @@ public sealed partial class CBM
if(errno != ErrorNumber.NoError) return errno;
Header cbmHdr = Marshal.ByteArrayToStructureBigEndian<Header>(_diskHeader);
Header cbmHdr = Marshal.ByteArrayToStructureBigEndianGenerated<Header>(_diskHeader);
if(cbmHdr.diskDosVersion != 0x44 || cbmHdr is not { dosVersion: 0x33, diskVersion: 0x44 })
return ErrorNumber.InvalidArgument;
@@ -126,7 +126,7 @@ public sealed partial class CBM
if(errno != ErrorNumber.NoError) return errno;
BAM cbmBam = Marshal.ByteArrayToStructureBigEndian<BAM>(_bam);
BAM cbmBam = Marshal.ByteArrayToStructureBigEndianGenerated<BAM>(_bam);
if(cbmBam is not ({ dosVersion: 0x41, doubleSided : 0x00 or 0x80 }
and { unused1 : 0x00, directoryTrack: 0x12 }))
@@ -143,7 +143,7 @@ public sealed partial class CBM
ulong nextLba = rootLba;
var rootMs = new MemoryStream();
bool relativeFileWarningShown = false;
var relativeFileWarningShown = false;
do
{
@@ -180,7 +180,7 @@ public sealed partial class CBM
// As this filesystem comes in (by nowadays standards) very small sizes, we can cache all files
_cache = new Dictionary<string, CachedFile>();
int offset = 0;
var offset = 0;
ulong fileId = 0;
if(_debug)
@@ -228,7 +228,7 @@ public sealed partial class CBM
while(offset < _root.Length)
{
DirectoryEntry dirEntry = Marshal.ByteArrayToStructureBigEndian<DirectoryEntry>(_root, offset, 32);
DirectoryEntry dirEntry = Marshal.ByteArrayToStructureBigEndianGenerated<DirectoryEntry>(_root, offset, 32);
if(dirEntry.fileType == 0)
{
@@ -240,10 +240,9 @@ public sealed partial class CBM
_statfs.Files++;
_statfs.FreeFiles--;
for(int i = 0; i < dirEntry.name.Length; i++)
{
if(dirEntry.name[i] == 0xA0) dirEntry.name[i] = 0;
}
for(var i = 0; i < dirEntry.name.Length; i++)
if(dirEntry.name[i] == 0xA0)
dirEntry.name[i] = 0;
string name = StringHandlers.CToString(dirEntry.name, encoding);