diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9085d1f --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Snes8BppPlanar")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Snes8BppPlanar")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("8d10bcbc-15a3-4324-a68e-e45241c6e11a")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Snes8BppPlanar.cs b/Snes8BppPlanar.cs new file mode 100644 index 0000000..bebafd6 --- /dev/null +++ b/Snes8BppPlanar.cs @@ -0,0 +1,96 @@ +using System; +using System.Drawing; +using CharactorLib.Common; +using CharactorLib.Format; + +namespace Snes8BppPlanar +{ + public class Snes8BppPlanarFormat : FormatBase + { + public Snes8BppPlanarFormat() + { + base.FormatText = "[8][8]"; + base.Name = "8BPP SNES Planar"; + base.Extension = "smc,sfc,fig"; + + base.ColorBit = 8; + base.ColorNum = 256; + base.Width = 128; + base.Height = 128; + base.CharWidth = 8; + base.CharHeight = 8; + + base.Readonly = false; + base.IsSupportMirror = true; + base.IsSupportRotate = true; + base.IsCompressed = false; + base.EnableAdf = true; + + base.Author = "ikari_01"; + base.Url = "https://sd2snes.de"; + } + + /* offsets into SNES bitplanes per tile */ + byte[] PlaneOffset = { 0x00, 0x01, 0x10, 0x11, 0x20, 0x21, 0x30, 0x31 }; + + /* bytemap: contains image data in YYCHR internal format */ + /* data: contains image data in source format (ROM) */ + + /* convert from source format (ROM) to YYCHR graphics, one tile at a time */ + public override void ConvertMemToChr(Byte[] data, int addr, Bytemap bytemap, int px, int py) + { + for (int x = 0; x < CharWidth; x++) + { + for (int y = 0; y < CharHeight; y++) + { + byte pixel = 0x00; + + /* gather bits from bitplanes and combine into pixel */ + for (int b = 0; b < ColorBit; b++) + { + byte tmp = data[addr + PlaneOffset[b] + 2 * y]; + tmp &= (byte)(1 << (CharWidth - 1 - x)); + tmp >>= CharWidth - 1 - x; + tmp <<= b; + pixel |= tmp; + } + + /* get pixel address for requested coordinates in YYCHR bitmap */ + Point p = base.GetAdvancePixelPoint(px + x, py + y); + int bytemapAddr = bytemap.GetPointAddress(p.X, p.Y); + + /* write pixel to YYCHR bitmap */ + bytemap.Data[bytemapAddr] = pixel; + } + } + } + + /* convert from YYCHR graphics to source format (ROM), one tile at a time */ + public override void ConvertChrToMem(Byte[] data, int addr, Bytemap bytemap, int px, int py) + { + for (int x = 0; x < CharWidth; x++) + { + /* mask to substitute pixel in ROM data */ + byte mask = (byte)~(1 << (CharWidth - 1 - x)); + for (int y = 0; y < CharHeight; y++) + { + /* read pixel from YYCHR bitmap */ + Point p = base.GetAdvancePixelPoint(px + x, py + y); + int bytemapAddr = bytemap.GetPointAddress(p.X, p.Y); + byte pixel = bytemap.Data[bytemapAddr]; + for (int b = 0; b < ColorBit; b++) + { + /* scatter bits from pixel across ROM bitplanes */ + int tileAddr = addr + PlaneOffset[b] + 2 * y; + byte orig = (byte)(data[tileAddr] & mask); + byte bit = (byte)(pixel & (1 << b)); + bit >>= b; + bit <<= (7 - x); + orig |= bit; + data[tileAddr] = orig; + } + } + } + } + } +} diff --git a/Snes8BppPlanar.csproj b/Snes8BppPlanar.csproj new file mode 100644 index 0000000..ffc2317 --- /dev/null +++ b/Snes8BppPlanar.csproj @@ -0,0 +1,47 @@ + + + + + Debug + AnyCPU + {8D10BCBC-15A3-4324-A68E-E45241C6E11A} + Library + Properties + Snes8BppPlanar + Snes8BppPlanar + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + .\CharactorLib.dll + + + + + + + + + + + \ No newline at end of file diff --git a/Snes8BppPlanar.sln b/Snes8BppPlanar.sln new file mode 100644 index 0000000..fe99827 --- /dev/null +++ b/Snes8BppPlanar.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snes8BppPlanar", "Snes8BppPlanar.csproj", "{8D10BCBC-15A3-4324-A68E-E45241C6E11A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D10BCBC-15A3-4324-A68E-E45241C6E11A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D10BCBC-15A3-4324-A68E-E45241C6E11A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D10BCBC-15A3-4324-A68E-E45241C6E11A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D10BCBC-15A3-4324-A68E-E45241C6E11A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A5D04AF4-BB3B-4125-A3DA-9BAD5B7B36C4} + EndGlobalSection +EndGlobal