preliminary implementation of Amiga plugin and dataformat for reading Amiga disk image files

This commit is contained in:
Michael Becker 2020-05-16 07:20:08 -04:00
parent cf16383a33
commit a7fa91a07c
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
9 changed files with 504 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="Amiga Disk Format (ADF) disk image">
<FileNameFilters>
<FileNameFilter>*.adf</FileNameFilter>
</FileNameFilters>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.ObjectModels.FileSystem.FileSystemObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.Plugins.Amiga.DataFormats.FileSystem.ADF.ADFDiskImageDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -733,6 +733,7 @@
<Content Include="Extensions\AudioWorkstation\Extensions\Vocaloid\Associations\SynthesizedAudio\VSQX.uexml" />
<Content Include="Extensions\AudioWorkstation\Extensions\Vocaloid\Associations\SynthesizedAudio\VPR.uexml" />
<Content Include="Editors\Binary\Commands.uexml" />
<Content Include="Extensions\Amiga\Associations\FileSystem\ADFDiskImage.uexml" />
<Content Include="Editors\Designer\DesignerEditor.glade" />
</ItemGroup>
<ItemGroup>
@ -795,6 +796,9 @@
<Folder Include="Extensions\AudioWorkstation\Extensions\Vocaloid\Associations\Voicebank\" />
<Folder Include="Extensions\AudioWorkstation\Extensions\Vocaloid\Associations\SynthesizedAudio\" />
<Folder Include="Extensions\AudioWorkstation\Extensions\Vocaloid\Associations\VoicebankIndex\" />
<Folder Include="Extensions\Amiga\" />
<Folder Include="Extensions\Amiga\Associations\" />
<Folder Include="Extensions\Amiga\Associations\FileSystem\" />
</ItemGroup>
<ItemGroup>
<Content Include="Extensions\SoftwareDeveloper\Templates\Project\Software Development\Arduino\Images\Blink.xcf" />

View File

@ -0,0 +1,30 @@
//
// ADFDiskImageBlockSecondaryType.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.Amiga.DataFormats.FileSystem.ADF
{
public enum ADFDiskImageBlockSecondaryType
{
Root = 1,
Directory = 2,
File = -3
}
}

View File

@ -0,0 +1,237 @@
//
// ADFDiskImageDataFormat.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using UniversalEditor.Accessors;
using UniversalEditor.IO;
using UniversalEditor.ObjectModels.FileSystem;
using UniversalEditor.Plugins.Amiga.DataFormats.FileSystem.ADF.Internal;
using UniversalEditor.UserInterface;
namespace UniversalEditor.Plugins.Amiga.DataFormats.FileSystem.ADF
{
public class ADFDiskImageDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = base.MakeReferenceInternal();
_dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
public int BytesPerSector { get; set; } = 512;
[CustomOptionText("Volume _name")]
public string VolumeName { get; set; } = String.Empty;
protected override void LoadInternal(ref ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) throw new ObjectModelNotSupportedException();
Reader reader = Accessor.Reader;
reader.Endianness = Endianness.BigEndian;
// boot block
string diskType = reader.ReadFixedLengthString(3);
if (diskType == "DOS")
{
}
else if (diskType == "PFS")
{
throw new NotImplementedException("Professional File System not implemented ... yet!");
}
else
{
throw new InvalidDataFormatException();
}
ADFDiskImageFlags flags = (ADFDiskImageFlags)reader.ReadByte();
uint checksum = reader.ReadUInt32();
uint rootblock = reader.ReadUInt32(); // value is 880 for DD and HD
byte[] bootblock = reader.ReadBytes(1012); // The size for a floppy disk is 1012; for a harddisk it is (DosEnvVec->Bootblocks * BSIZE) - 12
uint checksumVerify = CalculateChecksum(diskType, flags, rootblock, bootblock);
if (checksumVerify != checksum)
{
HostApplication.Messages.Add(HostApplicationMessageSeverity.Warning, "boot block checksum mismatch", Accessor.GetFileName());
}
reader.Seek(CalculateSectorOffset(rootblock), SeekOrigin.Begin);
uint[] hashTableEntries = null;
#region Rootblock
{
Internal.ADFBlock block = ReadBlock(reader);
VolumeName = block.filename;
hashTableEntries = block.hashTableEntries;
/*
ulong 1 next_hash unused (value = 0)
ulong 1 parent_dir unused (value = 0)
BSIZE- 8/-0x08 ulong 1 extension FFS: first directory cache block,
0 otherwise
BSIZE- 4/-0x04 ulong 1 sec_type block secondary type = ST_ROOT
(value 1)
*/
LoadDirectory(reader, block, fsom);
}
#endregion
}
private void LoadDirectory(Reader reader, ADFBlock block, IFileSystemContainer fsom)
{
for (int i = 0; i < block.hashTableEntries.Length; i++)
{
if (block.hashTableEntries[i] == 0) continue;
reader.Seek(CalculateSectorOffset(block.hashTableEntries[i]), SeekOrigin.Begin);
Internal.ADFBlock block2 = ReadBlock(reader);
if (block2.sec_type == ADFDiskImageBlockSecondaryType.File)
{
File f = fsom.AddFile(block2.filename);
f.Properties["block"] = block2;
f.Properties["reader"] = reader;
f.DataRequest += F_DataRequest;
}
else if (block2.sec_type == ADFDiskImageBlockSecondaryType.Directory)
{
Folder folder = fsom.Folders.Add(block2.filename);
LoadDirectory(reader, block2, folder);
}
}
}
private void F_DataRequest(object sender, DataRequestEventArgs e)
{
File f = (File)sender;
Internal.ADFBlock block = f.GetProperty<Internal.ADFBlock>("block");
Reader reader = f.GetProperty<Reader>("reader");
byte[] data = new byte[0];
int len = 0;
for (int i = 0; i < block.hashTableEntries.Length; i++)
{
if (block.hashTableEntries[i] == 0) continue;
reader.Seek(CalculateSectorOffset(block.hashTableEntries[i]), SeekOrigin.Begin);
byte[] blockData = reader.ReadBytes(BytesPerSector);
Array.Resize<byte>(ref data, data.Length + blockData.Length);
Array.Copy(blockData, 0, data, len, BytesPerSector);
len += BytesPerSector;
}
e.Data = data;
}
private Internal.ADFBlock ReadBlock(Reader reader)
{
Internal.ADFBlock block = new Internal.ADFBlock();
block.blockPrimaryType = reader.ReadUInt32(); // 2 = T_HEADER
block.headerKey = reader.ReadUInt32();
block.highSeq = reader.ReadUInt32(); // file: number of data block ptr stored here
block.hashTableSize = reader.ReadUInt32();
block.firstData = reader.ReadUInt32(); // unused (value 0)
block.blockChecksum = reader.ReadUInt32();
int hashTableEntryCount = (BytesPerSector / 4) - 56;
block.hashTableEntries = reader.ReadUInt32Array(hashTableEntryCount); // 72 for floppy disk, (BSIZE/4) - 56 for hard disks
block.bm_flag = reader.ReadUInt32(); // -1 means VALID
block.bm_pages = reader.ReadUInt32Array(25); // bitmap blocks pointers (first one at bm_pages[0])
block.bm_ext = reader.ReadUInt32(); // first bitmap extension block (hard disks only)
// last root alteration date
block.r_days = reader.ReadUInt32(); // days since 1 jan 78
block.r_mins = reader.ReadUInt32(); // minutes past midnight
block.r_ticks = reader.ReadUInt32(); // ticks (1/50 sec) past last minute
byte name_len = reader.ReadByte(); // volume name length
block.filename = reader.ReadFixedLengthString(30).TrimNull(); // volume name
block.unused1 = reader.ReadByte(); // set to 0
block.unused2 = reader.ReadUInt32(); // set to 0
block.unused3 = reader.ReadUInt32(); // set to 0
// last disk alteration date
block.v_days = reader.ReadUInt32(); // days since 1 jan 78
block.v_mins = reader.ReadUInt32();
block.v_ticks = reader.ReadUInt32();
// filesystem creation date
block.c_days = reader.ReadUInt32();
block.c_mins = reader.ReadUInt32();
block.c_ticks = reader.ReadUInt32();
block.next_hash = reader.ReadUInt32();
block.parent_dir = reader.ReadUInt32();
block.extension = reader.ReadUInt32();
block.sec_type = (ADFDiskImageBlockSecondaryType)reader.ReadUInt32();
return block;
}
private long CalculateSectorOffset(long sector)
{
return BytesPerSector * sector;
}
private uint CalculateChecksum(string diskType, ADFDiskImageFlags flags, uint rootblock, byte[] data)
{
MemoryAccessor ma = new MemoryAccessor();
ma.Writer.Endianness = Endianness.BigEndian;
ma.Writer.WriteFixedLengthString(diskType, 3);
ma.Writer.WriteByte((byte)flags);
ma.Writer.WriteUInt32(0);
ma.Writer.WriteUInt32(rootblock);
ma.Writer.WriteBytes(data);
ma.Flush();
ma.Close();
return CalculateChecksum(ma.ToArray());
}
private uint CalculateChecksum(byte[] data)
{
return CalculateChecksum(new MemoryAccessor(data));
}
private uint CalculateChecksum(MemoryAccessor ma)
{
uint newsum = 0;
ma.Reader.Endianness = Endianness.BigEndian;
for (int i = 0; i < ma.Length / 4; i++)
{
uint d = ma.Reader.ReadUInt32();
if ((UInt32.MaxValue - newsum) < d) /* overflow */
newsum++;
newsum += d;
}
newsum = ~newsum; /* not */
return newsum;
}
protected override void SaveInternal(ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
if (fsom == null) throw new ObjectModelNotSupportedException();
}
}
}

View File

@ -0,0 +1,45 @@
//
// ADFDiskImageFlags.cs - indicates attributes for an ADF disk image file
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.Amiga.DataFormats.FileSystem.ADF
{
/// <summary>
/// Indicates attributes for an ADF disk image file.
/// </summary>
[Flags()]
public enum ADFDiskImageFlags
{
/// <summary>
/// Indicates the disk image uses the Fast File System (AmigaDOS 2.04), as opposed to the Original File System (AmigaDOS 1.2).
/// </summary>
FFS = 0x01,
/// <summary>
/// Indicates the disk image supports international characters mode only.
/// </summary>
InternationalOnly = 0x02,
/// <summary>
/// Indicates the disk image supports directory cache mode and international characters. This mode speeds up directory listing, but uses more disk space.
/// </summary>
DirectoryCacheModeAndInternational = 0x04
}
}

View File

@ -0,0 +1,54 @@
//
// ADFBlock.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.Plugins.Amiga.DataFormats.FileSystem.ADF.Internal
{
public class ADFBlock
{
internal uint blockPrimaryType;
internal uint headerKey;
internal uint highSeq;
internal uint hashTableSize;
internal uint firstData;
internal uint blockChecksum;
internal uint[] hashTableEntries;
internal uint bm_flag;
internal uint[] bm_pages;
internal uint bm_ext;
internal uint r_days;
internal uint r_mins;
internal uint r_ticks;
internal string filename;
internal byte unused1;
internal uint unused2;
internal uint unused3;
internal uint v_days;
internal uint v_mins;
internal uint v_ticks;
internal uint c_days;
internal uint c_mins;
internal uint c_ticks;
internal uint next_hash;
internal uint parent_dir;
internal uint extension;
internal ADFDiskImageBlockSecondaryType sec_type;
}
}

View File

@ -0,0 +1,46 @@
//
// AssemblyInfo.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("UniversalEditor.Plugins.Amiga")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Mike Becker's Software")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Mike Becker's Software")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>UniversalEditor.Plugins.Amiga</RootNamespace>
<AssemblyName>UniversalEditor.Plugins.Amiga</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<ReleaseVersion>4.0.2019.12</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="DataFormats\FileSystem\ADF\ADFDiskImageDataFormat.cs" />
<Compile Include="DataFormats\FileSystem\ADF\ADFDiskImageFlags.cs" />
<Compile Include="DataFormats\FileSystem\ADF\ADFDiskImageBlockSecondaryType.cs" />
<Compile Include="DataFormats\FileSystem\ADF\Internal\ADFBlock.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="DataFormats\" />
<Folder Include="DataFormats\FileSystem\" />
<Folder Include="DataFormats\FileSystem\ADF\" />
<Folder Include="DataFormats\FileSystem\ADF\Internal\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2D4737E6-6D95-408A-90DB-8DFF38147E85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
<Project>{30467E5C-05BC-4856-AADC-13906EF4CADD}</Project>
<Name>UniversalEditor.Essential</Name>
</ProjectReference>
<ProjectReference Include="..\..\Libraries\UniversalEditor.UserInterface\UniversalEditor.UserInterface.csproj">
<Project>{8622EBC4-8E20-476E-B284-33D472081F5C}</Project>
<Name>UniversalEditor.UserInterface</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -167,6 +167,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Ado
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Vocaloid", "Plugins\UniversalEditor.Plugins.Vocaloid\UniversalEditor.Plugins.Vocaloid.csproj", "{C8953DB2-AE48-4F04-87EC-549E6A3E30D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Amiga", "Plugins\UniversalEditor.Plugins.Amiga\UniversalEditor.Plugins.Amiga.csproj", "{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Designer.UserInterface", "Plugins.UserInterface\UniversalEditor.Plugins.Designer.UserInterface\UniversalEditor.Plugins.Designer.UserInterface.csproj", "{08168BEA-E652-4493-8D89-5AB72B225841}"
EndProject
Global
@ -485,6 +487,10 @@ Global
{C8953DB2-AE48-4F04-87EC-549E6A3E30D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C8953DB2-AE48-4F04-87EC-549E6A3E30D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C8953DB2-AE48-4F04-87EC-549E6A3E30D8}.Release|Any CPU.Build.0 = Release|Any CPU
{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B}.Release|Any CPU.Build.0 = Release|Any CPU
{08168BEA-E652-4493-8D89-5AB72B225841}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08168BEA-E652-4493-8D89-5AB72B225841}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08168BEA-E652-4493-8D89-5AB72B225841}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -567,6 +573,7 @@ Global
{553DFD37-805C-4553-980A-D5696D88241A} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{FD46EA8D-7711-4BAF-A486-719D754504F8} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{C8953DB2-AE48-4F04-87EC-549E6A3E30D8} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{BCEB66A6-24E3-4877-B8D4-83FCF8EC748B} = {2ED32D16-6C06-4450-909A-40D32DA67FB4}
{08168BEA-E652-4493-8D89-5AB72B225841} = {7B535D74-5496-4802-B809-89ED88274A91}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution