diff --git a/CommandLine/CommandLine.csproj b/CommandLine/CommandLine.csproj index ff3b2ab..7e2b3fa 100644 --- a/CommandLine/CommandLine.csproj +++ b/CommandLine/CommandLine.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 pw Debug;Release enable @@ -20,7 +20,6 @@ - \ No newline at end of file diff --git a/CommandLine/Commands/Convert/ConvertFromC64Command.cs b/CommandLine/Commands/Convert/ConvertFromC64Command.cs index ebda89a..c1e0db3 100644 --- a/CommandLine/Commands/Convert/ConvertFromC64Command.cs +++ b/CommandLine/Commands/Convert/ConvertFromC64Command.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using System.IO; using CommandLine.Commands.Settings; using PixelWorld; @@ -12,7 +12,7 @@ namespace CommandLine.Commands.Convert; [Description("Create ZX font from Commodore 64 font")] public class ConvertFromC64Command : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] RequiredSettings settings) + public override Int32 Execute(CommandContext context, RequiredSettings settings) { foreach (var fileName in Utils.MatchGlobWithFiles(settings.Glob)) ConvertFromC64(settings, fileName); @@ -20,7 +20,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Required return 0; } - private static void ConvertFromC64(RequiredSettings settings, string fileName) + private static void ConvertFromC64(RequiredSettings settings, String fileName) { Out.Write($"Generating ch8 file from {fileName}"); diff --git a/CommandLine/Commands/Convert/ConvertFromPngCommand.cs b/CommandLine/Commands/Convert/ConvertFromPngCommand.cs index 609b3b4..38b9f4c 100644 --- a/CommandLine/Commands/Convert/ConvertFromPngCommand.cs +++ b/CommandLine/Commands/Convert/ConvertFromPngCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using System.IO; using CommandLine.Commands.Settings; using PixelWorld; @@ -13,7 +13,7 @@ namespace CommandLine.Commands.Convert; [Description("Create ZX font from PNG preview")] public class ConvertFromPngCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] RequiredSettings settings) + public override Int32 Execute(CommandContext context, RequiredSettings settings) { foreach (var fileName in Utils.MatchGlobWithFiles(settings.Glob)) ConvertFromImage(settings, fileName); @@ -21,7 +21,7 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Required return 0; } - private static void ConvertFromImage(RequiredSettings settings, string fileName) + private static void ConvertFromImage(RequiredSettings settings, String fileName) { var name = Path.GetFileNameWithoutExtension(fileName); Out.Write($"Generating ch8 file from {fileName}"); diff --git a/CommandLine/Commands/Convert/ConvertToAtari8BitCommand.cs b/CommandLine/Commands/Convert/ConvertToAtari8BitCommand.cs index a1519b7..dc57327 100644 --- a/CommandLine/Commands/Convert/ConvertToAtari8BitCommand.cs +++ b/CommandLine/Commands/Convert/ConvertToAtari8BitCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create Atari 8-bit font from ZX font")] public class ConvertToAtari8BitCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ConvertSettings settings) + public override Int32 Execute(CommandContext context, ConvertSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertTo.Atari8(files, Spectrum.UK, settings.OutputFolder, settings.TemplatePath); diff --git a/CommandLine/Commands/Convert/ConvertToC64Command.cs b/CommandLine/Commands/Convert/ConvertToC64Command.cs index 05391c2..d932e6f 100644 --- a/CommandLine/Commands/Convert/ConvertToC64Command.cs +++ b/CommandLine/Commands/Convert/ConvertToC64Command.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create Commodore 64 fonts from ZX font")] public class ConvertToC64Command : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ConvertSettings settings) + public override Int32 Execute(CommandContext context, ConvertSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertTo.Commodore64(files, Spectrum.UK, settings.OutputFolder, settings.TemplatePath); diff --git a/CommandLine/Commands/Convert/ConvertToCoVGACommand.cs b/CommandLine/Commands/Convert/ConvertToCoVGACommand.cs new file mode 100644 index 0000000..4abf4d4 --- /dev/null +++ b/CommandLine/Commands/Convert/ConvertToCoVGACommand.cs @@ -0,0 +1,20 @@ +using System; +using System.ComponentModel; +using CommandLine.Commands.Settings; +using PixelWorld; +using PixelWorld.Machines; +using PixelWorld.Tools; +using Spectre.Console.Cli; + +namespace CommandLine.Commands.Convert; + +[Description("Create CoCoVGA fonts from ZX font")] +public class ConvertToCoVgaCommand : Command +{ + public override Int32 Execute(CommandContext context, ConvertSettings settings) + { + var files = Utils.MatchGlobWithFiles(settings.Glob); + ConvertTo.CoCoVGA(files, Spectrum.UK, settings.OutputFolder, settings.TemplatePath); + return 0; + } +} \ No newline at end of file diff --git a/CommandLine/Commands/Convert/ConvertToCpcCommand.cs b/CommandLine/Commands/Convert/ConvertToCpcCommand.cs index bc92d82..54166ce 100644 --- a/CommandLine/Commands/Convert/ConvertToCpcCommand.cs +++ b/CommandLine/Commands/Convert/ConvertToCpcCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create Amstrad CPC BASIC font from ZX font")] public class ConvertToCpcCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] BasicOutputSettings settings) + public override Int32 Execute(CommandContext context, BasicOutputSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertTo.AmstradCpc(files, Spectrum.UK, settings.OutputFolder, settings.Credit, settings.Line); diff --git a/CommandLine/Commands/Convert/ConvertToFzxCommand.cs b/CommandLine/Commands/Convert/ConvertToFzxCommand.cs index 693e363..84b617a 100644 --- a/CommandLine/Commands/Convert/ConvertToFzxCommand.cs +++ b/CommandLine/Commands/Convert/ConvertToFzxCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create FZX font from ZX font")] public class ConvertToFzxCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ProportionalSettings settings) + public override Int32 Execute(CommandContext context, ProportionalSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertTo.Fzx(files, Spectrum.UK, settings.Proportional, settings.OutputFolder); diff --git a/CommandLine/Commands/Convert/ConvertToGbStudioCommand.cs b/CommandLine/Commands/Convert/ConvertToGbStudioCommand.cs index 2542562..e68a5ac 100644 --- a/CommandLine/Commands/Convert/ConvertToGbStudioCommand.cs +++ b/CommandLine/Commands/Convert/ConvertToGbStudioCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create GB Studio PNG font from ZX font")] public class ConvertToGbStudioCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] GbStudioSettings settings) + public override Int32 Execute(CommandContext context, GbStudioSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertToGameBoy.GbStudio(files, Spectrum.UK, settings.OutputFolder, settings.Dark, settings.Proportional); diff --git a/CommandLine/Commands/Convert/ConvertToMsxCommand.cs b/CommandLine/Commands/Convert/ConvertToMsxCommand.cs index d1f5b80..4ffff15 100644 --- a/CommandLine/Commands/Convert/ConvertToMsxCommand.cs +++ b/CommandLine/Commands/Convert/ConvertToMsxCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create MSX font from ZX font")] public class ConvertToMsxCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ConvertSettings settings) + public override Int32 Execute(CommandContext context, ConvertSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertTo.Msx(files, Spectrum.UK, settings.OutputFolder, settings.TemplatePath); diff --git a/CommandLine/Commands/Convert/ConvertToUFOCommand.cs b/CommandLine/Commands/Convert/ConvertToUFOCommand.cs index 666468e..7c47112 100644 --- a/CommandLine/Commands/Convert/ConvertToUFOCommand.cs +++ b/CommandLine/Commands/Convert/ConvertToUFOCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Machines; @@ -11,7 +11,7 @@ namespace CommandLine.Commands.Convert; [Description("Create UFO font from ZX font")] public class ConvertToUfoCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ConvertSettings settings) + public override Int32 Execute(CommandContext context, ConvertSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); ConvertTo.Ufo(files, Spectrum.UK, settings.OutputFolder); diff --git a/CommandLine/Commands/DumpCommand.cs b/CommandLine/Commands/DumpCommand.cs index 31abf01..dd34a4e 100644 --- a/CommandLine/Commands/DumpCommand.cs +++ b/CommandLine/Commands/DumpCommand.cs @@ -1,8 +1,8 @@ -using PixelWorld; +using System; +using PixelWorld; using PixelWorld.Tools; using Spectre.Console.Cli; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; using CommandLine.Commands.Settings; namespace CommandLine.Commands; @@ -10,7 +10,7 @@ namespace CommandLine.Commands; [Description("Dump memory from emulator snapshot")] public class DumpCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] RequiredSettings settings) + public override Int32 Execute(CommandContext context, RequiredSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); Dumper.Dump(files, settings.OutputFolder); diff --git a/CommandLine/Commands/ExtractScreenTilesCommand.cs b/CommandLine/Commands/ExtractScreenTilesCommand.cs index 1cf72a6..c0e7828 100644 --- a/CommandLine/Commands/ExtractScreenTilesCommand.cs +++ b/CommandLine/Commands/ExtractScreenTilesCommand.cs @@ -1,8 +1,8 @@ -using PixelWorld; +using System; +using PixelWorld; using PixelWorld.Tools; using Spectre.Console.Cli; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; using CommandLine.Commands.Settings; namespace CommandLine.Commands; @@ -10,7 +10,7 @@ namespace CommandLine.Commands; [Description("Dump memory from emulator snapshot")] public class ExtractScreenTilesCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ExtractTilesSettings settings) + public override Int32 Execute(CommandContext context, ExtractTilesSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); TileExtractor.Extract(files, settings.OutputFolder, settings.MinTiles, settings.MaxTiles); diff --git a/CommandLine/Commands/FindMatchingGlyphsCommand.cs b/CommandLine/Commands/FindMatchingGlyphsCommand.cs index d427097..04dfd61 100644 --- a/CommandLine/Commands/FindMatchingGlyphsCommand.cs +++ b/CommandLine/Commands/FindMatchingGlyphsCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Tools; @@ -10,7 +10,7 @@ namespace CommandLine.Commands; [Description("Identify fonts that use glyphs from a source font")] public class FindMatchingGlyphsCommand :Command { - public override int Execute([NotNull] CommandContext context, [NotNull] FindMatchingGlyphsSettings settings) + public override Int32 Execute(CommandContext context, FindMatchingGlyphsSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); Matcher.Match(files, settings.SourceFontFile, settings.MatchGlyphs); diff --git a/CommandLine/Commands/Generate/Generate6502AssemblyCommand.cs b/CommandLine/Commands/Generate/Generate6502AssemblyCommand.cs index 7317ad2..bac8db7 100644 --- a/CommandLine/Commands/Generate/Generate6502AssemblyCommand.cs +++ b/CommandLine/Commands/Generate/Generate6502AssemblyCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Formatters; @@ -10,12 +10,15 @@ namespace CommandLine.Commands.Generate; [Description("Generate MOS 6502 assembly")] public class Generate6502AssemblyCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] AssemblySettings settings) + public override Int32 Execute(CommandContext context, AssemblySettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); switch (settings.Base) { - case NumberBase.Decimal: + case NumberBase.Binary: + AssemblyFontFormatter.CreateDefines("6502", ".byte ", "%{0:b8}", files, settings.OutputFolder, settings.Credit); + break; + case NumberBase.Hex: AssemblyFontFormatter.CreateDefines("6502", ".byte ", "${0:x2}", files, settings.OutputFolder, settings.Credit); break; default: diff --git a/CommandLine/Commands/Generate/Generate68000AssemblyCommand.cs b/CommandLine/Commands/Generate/Generate68000AssemblyCommand.cs index d3c9002..260ed7c 100644 --- a/CommandLine/Commands/Generate/Generate68000AssemblyCommand.cs +++ b/CommandLine/Commands/Generate/Generate68000AssemblyCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Formatters; @@ -10,18 +10,19 @@ namespace CommandLine.Commands.Generate; [Description("Generate Motorola 68000 assembly")] public class Generate68000AssemblyCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] AssemblySettings settings) + public override Int32 Execute(CommandContext context, AssemblySettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); switch (settings.Base) { - case NumberBase.Decimal: - AssemblyFontFormatter.CreateDefines("68000", "DC.B ", "${0:x2}", files, settings.OutputFolder, - settings.Credit); + case NumberBase.Binary: + AssemblyFontFormatter.CreateDefines("68000", "DC.B ", "${0:x2}", files, settings.OutputFolder, settings.Credit); + break; + case NumberBase.Hex: + AssemblyFontFormatter.CreateDefines("68000", "DC.B ", "${0:x2}", files, settings.OutputFolder, settings.Credit); break; default: - AssemblyFontFormatter.CreateDefines("68000", "DC.B ", "{0}", files, settings.OutputFolder, - settings.Credit); + AssemblyFontFormatter.CreateDefines("68000", "DC.B ", "{0}", files, settings.OutputFolder, settings.Credit); break; } diff --git a/CommandLine/Commands/Generate/Generate8086AssemblyCommand.cs b/CommandLine/Commands/Generate/Generate8086AssemblyCommand.cs index 149dae6..a7d7042 100644 --- a/CommandLine/Commands/Generate/Generate8086AssemblyCommand.cs +++ b/CommandLine/Commands/Generate/Generate8086AssemblyCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Formatters; @@ -10,14 +10,16 @@ namespace CommandLine.Commands.Generate; [Description("Generate Intel 8086 assembly")] public class Generate8086AssemblyCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] AssemblySettings settings) + public override Int32 Execute(CommandContext context, AssemblySettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); switch (settings.Base) { - case NumberBase.Decimal: - AssemblyFontFormatter.CreateDefines("x86", "db\t", "0x{0:x2}", files, settings.OutputFolder, - settings.Credit); + case NumberBase.Binary: + AssemblyFontFormatter.CreateDefines("x86", "db\t", "0b{0:b8}", files, settings.OutputFolder, settings.Credit); + break; + case NumberBase.Hex: + AssemblyFontFormatter.CreateDefines("x86", "db\t", "0x{0:x2}", files, settings.OutputFolder, settings.Credit); break; default: AssemblyFontFormatter.CreateDefines("x86", "db\t", "{0}", files, settings.OutputFolder, diff --git a/CommandLine/Commands/Generate/GenerateCHeaderCommand.cs b/CommandLine/Commands/Generate/GenerateCHeaderCommand.cs index c57e687..72b6f6a 100644 --- a/CommandLine/Commands/Generate/GenerateCHeaderCommand.cs +++ b/CommandLine/Commands/Generate/GenerateCHeaderCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Formatters; @@ -10,7 +10,7 @@ namespace CommandLine.Commands.Generate; [Description("Generate C header")] public class GenerateCHeaderCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] COutputSettings settings) + public override Int32 Execute(CommandContext context, COutputSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); CHeaderFontFormatter.CreateFontHeaderConst(settings.ByteType, files, settings.OutputFolder, settings.Credit); diff --git a/CommandLine/Commands/Generate/GenerateRustHeaderCommand.cs b/CommandLine/Commands/Generate/GenerateRustHeaderCommand.cs index 47e135b..1f71e8d 100644 --- a/CommandLine/Commands/Generate/GenerateRustHeaderCommand.cs +++ b/CommandLine/Commands/Generate/GenerateRustHeaderCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Formatters; @@ -10,7 +10,7 @@ namespace CommandLine.Commands.Generate; [Description("Generate Rust header")] public class GenerateRustHeaderCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] TextOutputSettings settings) + public override Int32 Execute(CommandContext context, TextOutputSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); RustHeaderFontFormatter.CreateFontHeaderConst(files, settings.OutputFolder, settings.Credit); diff --git a/CommandLine/Commands/Generate/GenerateZ80AssemblyCommand.cs b/CommandLine/Commands/Generate/GenerateZ80AssemblyCommand.cs index 3acaacc..1a7a6b7 100644 --- a/CommandLine/Commands/Generate/GenerateZ80AssemblyCommand.cs +++ b/CommandLine/Commands/Generate/GenerateZ80AssemblyCommand.cs @@ -1,5 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; +using System; +using System.ComponentModel; using CommandLine.Commands.Settings; using PixelWorld; using PixelWorld.Formatters; @@ -10,21 +10,20 @@ namespace CommandLine.Commands.Generate; [Description("Generate Zilog Z80 assembly")] public class GenerateZ80AssemblyCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] AssemblySettings settings) + public override Int32 Execute(CommandContext context, AssemblySettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); switch (settings.Base) { case NumberBase.Binary: - AssemblyFontFormatter.GenZ80AsmBinary(files, settings.OutputFolder, settings.Credit); + AssemblyFontFormatter.CreateDefines("z80", "defb ", "%{0:b8}", files, settings.OutputFolder, settings.Credit); break; + case NumberBase.Decimal: - AssemblyFontFormatter.CreateDefines("z80", "defb ", "{0}", files, settings.OutputFolder, - settings.Credit); + AssemblyFontFormatter.CreateDefines("z80", "defb ", "{0}", files, settings.OutputFolder, settings.Credit); break; default: - AssemblyFontFormatter.CreateDefines("z80", "defb ", "&{0:x2}", files, settings.OutputFolder, - settings.Credit); + AssemblyFontFormatter.CreateDefines("z80", "defb ", "&{0:x2}", files, settings.OutputFolder, settings.Credit); break; } diff --git a/CommandLine/Commands/HuntCommand.cs b/CommandLine/Commands/HuntCommand.cs index e243947..259f236 100644 --- a/CommandLine/Commands/HuntCommand.cs +++ b/CommandLine/Commands/HuntCommand.cs @@ -1,8 +1,8 @@ -using PixelWorld; +using System; +using PixelWorld; using PixelWorld.Tools; using Spectre.Console.Cli; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; using CommandLine.Commands.Settings; namespace CommandLine.Commands; @@ -10,7 +10,7 @@ namespace CommandLine.Commands; [Description("Hunt memory dumps for possible ZX fonts")] public class HuntCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] RequiredSettings settings) + public override Int32 Execute(CommandContext context, RequiredSettings settings) { var files = Utils.MatchGlobWithFiles(settings.Glob); FontHunter.Hunt(files, settings.OutputFolder); diff --git a/CommandLine/Commands/PreviewCommand.cs b/CommandLine/Commands/PreviewCommand.cs index 32793aa..8ea3e27 100644 --- a/CommandLine/Commands/PreviewCommand.cs +++ b/CommandLine/Commands/PreviewCommand.cs @@ -1,7 +1,7 @@ -using PixelWorld; +using System; +using PixelWorld; using Spectre.Console.Cli; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; using System.IO; using CommandLine.Commands.Settings; using PixelWorld.Formatters; @@ -12,7 +12,7 @@ namespace CommandLine.Commands; [Description("Create preview images from ZX font")] public class PreviewCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] PreviewSettings settings) + public override Int32 Execute(CommandContext context, PreviewSettings settings) { foreach (var fileName in Utils.MatchGlobWithFiles(settings.Glob)) { diff --git a/CommandLine/Commands/ScreenshotCommand.cs b/CommandLine/Commands/ScreenshotCommand.cs index 6d31552..b85132a 100644 --- a/CommandLine/Commands/ScreenshotCommand.cs +++ b/CommandLine/Commands/ScreenshotCommand.cs @@ -6,7 +6,6 @@ using Spectre.Console.Cli; using System; using System.ComponentModel; -using System.Diagnostics.CodeAnalysis; using System.IO; using SixLabors.ImageSharp.PixelFormats; @@ -15,7 +14,7 @@ namespace CommandLine.Commands; [Description("Create screenshots from memory dump or emulator snapshot")] public class ScreenshotCommand : Command { - public override int Execute([NotNull] CommandContext context, [NotNull] ScreenshotSettings settings) + public override Int32 Execute(CommandContext context, ScreenshotSettings settings) { var fileNames = Utils.MatchGlobWithFiles(settings.Glob); foreach (var fileName in fileNames) @@ -28,9 +27,9 @@ public override int Execute([NotNull] CommandContext context, [NotNull] Screensh return 0; } - private const int FlashDelay = 64; + private const Int32 FlashDelay = 64; - private static bool WriteScreenToDisk(string fileName, ArraySegment memory, ScreenshotSettings settings) + private static Boolean WriteScreenToDisk(String fileName, ArraySegment memory, ScreenshotSettings settings) { var address = settings.Address ?? (memory.Count == 49152 ? 0 : 16384); if (settings.Png || settings.Webp) @@ -50,7 +49,7 @@ private static bool WriteScreenToDisk(string fileName, ArraySegment memory return true; } - private static void WriteScr(string sourceName, ArraySegment memory, ScreenshotSettings settings, int address) + private static void WriteScr(String sourceName, ArraySegment memory, ScreenshotSettings settings, Int32 address) { var targetName = Utils.MakeFileName(sourceName, "scr", settings.OutputFolder); Out.Write($" Screenshotting {sourceName} @ {address} to {targetName}"); @@ -58,7 +57,7 @@ private static void WriteScr(string sourceName, ArraySegment memory, Scree File.WriteAllBytes(targetName, screenBuffer); } - private static void WriteGif(string sourceName, ArraySegment memory, ScreenshotSettings settings, int address) + private static void WriteGif(String sourceName, ArraySegment memory, ScreenshotSettings settings, Int32 address) { var targetName = Utils.MakeFileName(sourceName, "gif", settings.OutputFolder); Out.Write($" Screenshotting {sourceName} @ {address} to {targetName}"); @@ -71,14 +70,14 @@ private static void WriteGif(string sourceName, ArraySegment memory, Scree animated.SaveAsGif(targetName); } - private static void WritePng(string sourceName, Image image, ScreenshotSettings settings, int address) + private static void WritePng(String sourceName, Image image, ScreenshotSettings settings, Int32 address) { var targetName = Utils.MakeFileName(sourceName, "png", settings.OutputFolder); Out.Write($" Screenshotting {sourceName} @ {address} to {targetName}"); image.SaveAsPng(targetName); } - private static void WriteWebp(string sourceName, Image image, ScreenshotSettings settings, int address) + private static void WriteWebp(String sourceName, Image image, ScreenshotSettings settings, Int32 address) { var targetName = Utils.MakeFileName(sourceName, "webp", settings.OutputFolder); Out.Write($" Screenshotting {sourceName} @ {address} to {targetName}"); diff --git a/CommandLine/Commands/Settings/BasicOutputSettings.cs b/CommandLine/Commands/Settings/BasicOutputSettings.cs index 1d1adcb..9606b95 100644 --- a/CommandLine/Commands/Settings/BasicOutputSettings.cs +++ b/CommandLine/Commands/Settings/BasicOutputSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -8,5 +9,5 @@ public class BasicOutputSettings : TextOutputSettings [CommandOption("--line ")] [Description("What line number to start on. Defaults to 9000.")] [DefaultValue(9000)] - public int Line { get; set; } = 9000; + public Int32 Line { get; set; } = 9000; } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/COutputSettings.cs b/CommandLine/Commands/Settings/COutputSettings.cs index 0c62072..c32666f 100644 --- a/CommandLine/Commands/Settings/COutputSettings.cs +++ b/CommandLine/Commands/Settings/COutputSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -8,5 +9,5 @@ public class COutputSettings : TextOutputSettings [CommandOption("--byteType")] [Description("What type to use for the byte")] [DefaultValue("uint8_t")] - public string ByteType { get; set; } = ""; + public String ByteType { get; set; } = ""; } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/ConvertSettings.cs b/CommandLine/Commands/Settings/ConvertSettings.cs index a7398ee..fae5b36 100644 --- a/CommandLine/Commands/Settings/ConvertSettings.cs +++ b/CommandLine/Commands/Settings/ConvertSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -8,5 +9,5 @@ public class ConvertSettings : RequiredSettings [CommandOption("--templatePath ")] [Description("What path to use for binary templates containing missing glyphs.")] [DefaultValue(".")] - public string TemplatePath { get; set; } = "."; + public String TemplatePath { get; set; } = "."; } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/ExtractTilesSettings.cs b/CommandLine/Commands/Settings/ExtractTilesSettings.cs index 1ea967c..0cab9c3 100644 --- a/CommandLine/Commands/Settings/ExtractTilesSettings.cs +++ b/CommandLine/Commands/Settings/ExtractTilesSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -8,10 +9,10 @@ public class ExtractTilesSettings : RequiredSettings [CommandOption("--min ")] [Description("Minimum number of unique tiles for extraction")] [DefaultValue("1")] - public int MinTiles { get; set; } = 1; + public Int32 MinTiles { get; set; } = 1; [CommandOption("--max ")] [Description("Maximum number of unique tiles for extraction")] [DefaultValue("768")] - public int MaxTiles { get; set; } = 768; + public Int32 MaxTiles { get; set; } = 768; } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/FindMatchingGlyphsSettings.cs b/CommandLine/Commands/Settings/FindMatchingGlyphsSettings.cs index bb249b7..2dfd7e0 100644 --- a/CommandLine/Commands/Settings/FindMatchingGlyphsSettings.cs +++ b/CommandLine/Commands/Settings/FindMatchingGlyphsSettings.cs @@ -1,15 +1,16 @@ -using Spectre.Console.Cli; +using System; +using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; public class FindMatchingGlyphsSettings : CommandSettings { [CommandArgument(0, "[SourceFontFile]")] - public string SourceFontFile { get; set; } = ""; + public String SourceFontFile { get; set; } = ""; [CommandArgument(1, "[FileGlob]")] - public string Glob { get; set; } = ""; + public String Glob { get; set; } = ""; [CommandArgument(2, "[MatchGlyphs]")] - public string MatchGlyphs { get; set; } = ""; + public String MatchGlyphs { get; set; } = ""; } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/GbStudioSettings.cs b/CommandLine/Commands/Settings/GbStudioSettings.cs index ce2ac54..866facd 100644 --- a/CommandLine/Commands/Settings/GbStudioSettings.cs +++ b/CommandLine/Commands/Settings/GbStudioSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -7,9 +8,9 @@ public class GbStudioSettings : RequiredSettings { [CommandOption("--dark")] [Description("Generate a dark variant")] - public bool Dark { get; set; } + public Boolean Dark { get; set; } [CommandOption("--proportional")] [Description("Generate a proportional variant by left aligning and detecting width")] - public bool Proportional { get; set; } + public Boolean Proportional { get; set; } } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/PreviewSettings.cs b/CommandLine/Commands/Settings/PreviewSettings.cs index f46b646..41a231b 100644 --- a/CommandLine/Commands/Settings/PreviewSettings.cs +++ b/CommandLine/Commands/Settings/PreviewSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -7,14 +8,14 @@ public class PreviewSettings : RequiredSettings { [CommandOption("--png")] [Description("Write a .png version of the screenshot.")] - public bool Png { get; set; } + public Boolean Png { get; set; } [CommandOption("--webp")] [Description("Write a .webp version of the screenshot.")] - public bool Webp { get; set; } + public Boolean Webp { get; set; } [CommandOption("--transparent")] [DefaultValue(true)] [Description("Write images with transparent backgrounds.")] - public bool Transparent { get; set; } + public Boolean Transparent { get; set; } } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/ProportionalSettings.cs b/CommandLine/Commands/Settings/ProportionalSettings.cs index bde8829..d2c6b6e 100644 --- a/CommandLine/Commands/Settings/ProportionalSettings.cs +++ b/CommandLine/Commands/Settings/ProportionalSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -7,5 +8,5 @@ public class ProportionalSettings : RequiredSettings { [CommandOption("--proportional")] [Description("Make the font proportional by left aligning and detecting width")] - public bool Proportional { get; set; } + public Boolean Proportional { get; set; } } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/RequiredSettings.cs b/CommandLine/Commands/Settings/RequiredSettings.cs index 68d2697..faad613 100644 --- a/CommandLine/Commands/Settings/RequiredSettings.cs +++ b/CommandLine/Commands/Settings/RequiredSettings.cs @@ -1,12 +1,13 @@ -using Spectre.Console.Cli; +using System; +using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; public class RequiredSettings : CommandSettings { [CommandArgument(0, "[FileGlob]")] - public string Glob { get; set; } = ""; + public String Glob { get; set; } = ""; [CommandArgument(1, "[OutputFolder]")] - public string OutputFolder { get; set; } = "."; + public String OutputFolder { get; set; } = "."; } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/ScreenshotSettings.cs b/CommandLine/Commands/Settings/ScreenshotSettings.cs index 64ef5e0..b10ca41 100644 --- a/CommandLine/Commands/Settings/ScreenshotSettings.cs +++ b/CommandLine/Commands/Settings/ScreenshotSettings.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -7,25 +8,25 @@ public class ScreenshotSettings : RequiredSettings { [CommandOption("--address ")] [Description("What memory address to use - otherwise auto detected.")] - public int? Address { get; set; } + public Int32? Address { get; set; } [CommandOption("--png")] [Description("Write a .png version of the screenshot.")] - public bool Png { get; set; } + public Boolean Png { get; set; } [CommandOption("--webp")] [Description("Write a .webp version of the screenshot.")] - public bool Webp { get; set; } + public Boolean Webp { get; set; } [CommandOption("--scr")] [Description("Write a .scr version of the screenshot (default).")] - public bool Scr { get; set; } + public Boolean Scr { get; set; } [CommandOption("--gif")] [Description("Write an animated .gif of the screenshot.")] - public bool Gif { get; set; } + public Boolean Gif { get; set; } [CommandOption("--flashed")] [Description("Write png with the alternate flashed attribute state.")] - public bool Flashed { get; set; } + public Boolean Flashed { get; set; } } \ No newline at end of file diff --git a/CommandLine/Commands/Settings/TextOutputSetting.cs b/CommandLine/Commands/Settings/TextOutputSetting.cs index 89488e7..dc3fbd5 100644 --- a/CommandLine/Commands/Settings/TextOutputSetting.cs +++ b/CommandLine/Commands/Settings/TextOutputSetting.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using Spectre.Console.Cli; namespace CommandLine.Commands.Settings; @@ -7,5 +8,5 @@ public class TextOutputSettings : RequiredSettings { [CommandOption("--credit")] [Description("Credit for the font on generated human-readable versions")] - public string Credit { get; set; } = ""; + public String Credit { get; set; } = ""; } \ No newline at end of file diff --git a/CommandLine/NumberBase.cs b/CommandLine/NumberBase.cs index 239f2ac..2ac825a 100644 --- a/CommandLine/NumberBase.cs +++ b/CommandLine/NumberBase.cs @@ -14,7 +14,7 @@ public enum NumberBase public sealed class NumberBaseConverter : TypeConverter { - private static readonly Dictionary lookup = + private static readonly Dictionary lookup = new(StringComparer.OrdinalIgnoreCase) { {"hex", NumberBase.Hex}, @@ -25,11 +25,11 @@ public sealed class NumberBaseConverter : TypeConverter {"2", NumberBase.Binary} }; - public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value) + public override Object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, Object value) { - if (value is not string stringValue) throw new NotSupportedException("Can't convert value to number base."); - if (!lookup.TryGetValue(stringValue, out var numberBase)) - throw new InvalidOperationException($"The value '{value}' is not a number base."); - return numberBase; + if (value is not String stringValue) throw new NotSupportedException("Can't convert value to number base."); + return lookup.TryGetValue(stringValue, out var numberBase) + ? numberBase + : throw new InvalidOperationException($"The value '{value}' is not a number base."); } } \ No newline at end of file diff --git a/CommandLine/Program.cs b/CommandLine/Program.cs index 03f5291..970b62c 100644 --- a/CommandLine/Program.cs +++ b/CommandLine/Program.cs @@ -9,7 +9,7 @@ namespace CommandLine; internal static class Program { - private static void Main(string[] args) + private static void Main(String[] args) { Out.Attach(Console.WriteLine); @@ -29,26 +29,27 @@ private static void AddCommands(IConfigurator config) config.AddCommand("dump"); config.AddCommand("hunt"); config.AddCommand("extracttiles"); + config.AddCommand("findmatches"); config.AddCommand("screenshot"); config.AddCommand("preview"); config.AddCommand("pngtozx"); config.AddCommand("c64tozx"); - config.AddCommand("findmatches"); - config.AddCommand("z80asm"); + config.AddCommand("zxtoa8"); + config.AddCommand("zxtoc64"); + config.AddCommand("zxtoccv"); + config.AddCommand("zxtocpc"); + config.AddCommand("zxtofzx"); + config.AddCommand("zxtogbs"); + config.AddCommand("zxtomsx"); + config.AddCommand("zxtoufo"); + config.AddCommand("6502asm"); config.AddCommand("68000asm"); - config.AddCommand("x86asm"); config.AddCommand("chead"); config.AddCommand("rusthead"); - - config.AddCommand("zxtofzx"); - config.AddCommand("zxtoc64"); - config.AddCommand("zxtomsx"); - config.AddCommand("zxtocpc"); - config.AddCommand("zxtoa8"); - config.AddCommand("zxtoufo"); - config.AddCommand("zxtogbs"); + config.AddCommand("x86asm"); + config.AddCommand("z80asm"); } } \ No newline at end of file diff --git a/Common/BinarySource/Decoders/SNAFile.cs b/Common/BinarySource/Decoders/SNAFile.cs index aecd7f2..8b6198d 100644 --- a/Common/BinarySource/Decoders/SNAFile.cs +++ b/Common/BinarySource/Decoders/SNAFile.cs @@ -11,20 +11,20 @@ namespace PixelWorld.BinarySource.Decoders [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SNA_HEADER { - public byte I; //I Register - public ushort HL_, DE_, BC_, AF_; //Alternate registers - public ushort HL, DE, BC, IY, IX; //16 bit main registers - public byte IFF2; //Interrupt enabled? (bit 2 on/off) - public byte R; //R Register - public ushort AF, SP; //AF and SP register - public byte IM; //Interupt Mode - public byte BORDER; //Border colour + public Byte I; //I Register + public UInt16 HL_, DE_, BC_, AF_; //Alternate registers + public UInt16 HL, DE, BC, IY, IX; //16 bit main registers + public Byte IFF2; //Interrupt enabled? (bit 2 on/off) + public Byte R; //R Register + public UInt16 AF, SP; //AF and SP register + public Byte IM; //Interupt Mode + public Byte BORDER; //Border colour } [StructLayout(LayoutKind.Sequential, Pack = 1)] public class SNA_SNAPSHOT { - public byte TYPE; //0 = 48k, 1 = 128; + public Byte TYPE; //0 = 48k, 1 = 128; public SNA_HEADER HEADER; //The above header } @@ -32,16 +32,16 @@ public class SNA_SNAPSHOT public class SNA_48K : SNA_SNAPSHOT { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 49152)] - public byte[] RAM; //Contents of the RAM + public Byte[] RAM; //Contents of the RAM } [StructLayout(LayoutKind.Sequential, Pack = 1)] public class SNA_128K : SNA_SNAPSHOT { - public ushort PC; //PC Register - public byte PORT_7FFD; //Current state of port 7ffd - public byte TR_DOS; //Is TR DOS ROM paged in? - public byte[][] RAM_BANK = new byte[16][]; //Contents of the 8192*16 ram banks + public UInt16 PC; //PC Register + public Byte PORT_7FFD; //Current state of port 7ffd + public Byte TR_DOS; //Is TR DOS ROM paged in? + public Byte[][] RAM_BANK = new Byte[16][]; //Contents of the 8192*16 ram banks } public class SNAFile @@ -53,9 +53,9 @@ public static SNA_SNAPSHOT LoadSNA(Stream fs) using (BinaryReader r = new(fs)) { - var bytesToRead = (int)fs.Length; + var bytesToRead = (Int32)fs.Length; - var buffer = new byte[bytesToRead]; + var buffer = new Byte[bytesToRead]; var bytesRead = r.Read(buffer, 0, bytesToRead); if (bytesRead == 0) @@ -79,28 +79,28 @@ public static SNA_SNAPSHOT LoadSNA(Stream fs) return null; snapshot.HEADER.I = buffer[0]; - snapshot.HEADER.HL_ = (ushort)(buffer[1] | (buffer[2] << 8)); - snapshot.HEADER.DE_ = (ushort)(buffer[3] | (buffer[4] << 8)); - snapshot.HEADER.BC_ = (ushort)(buffer[5] | (buffer[6] << 8)); - snapshot.HEADER.AF_ = (ushort)(buffer[7] | (buffer[8] << 8)); + snapshot.HEADER.HL_ = (UInt16)(buffer[1] | (buffer[2] << 8)); + snapshot.HEADER.DE_ = (UInt16)(buffer[3] | (buffer[4] << 8)); + snapshot.HEADER.BC_ = (UInt16)(buffer[5] | (buffer[6] << 8)); + snapshot.HEADER.AF_ = (UInt16)(buffer[7] | (buffer[8] << 8)); - snapshot.HEADER.HL = (ushort)(buffer[9] | (buffer[10] << 8)); - snapshot.HEADER.DE = (ushort)(buffer[11] | (buffer[12] << 8)); - snapshot.HEADER.BC = (ushort)(buffer[13] | (buffer[14] << 8)); - snapshot.HEADER.IY = (ushort)(buffer[15] | (buffer[16] << 8)); - snapshot.HEADER.IX = (ushort)(buffer[17] | (buffer[18] << 8)); + snapshot.HEADER.HL = (UInt16)(buffer[9] | (buffer[10] << 8)); + snapshot.HEADER.DE = (UInt16)(buffer[11] | (buffer[12] << 8)); + snapshot.HEADER.BC = (UInt16)(buffer[13] | (buffer[14] << 8)); + snapshot.HEADER.IY = (UInt16)(buffer[15] | (buffer[16] << 8)); + snapshot.HEADER.IX = (UInt16)(buffer[17] | (buffer[18] << 8)); snapshot.HEADER.IFF2 = buffer[19]; snapshot.HEADER.R = buffer[20]; - snapshot.HEADER.AF = (ushort)(buffer[21] | (buffer[22] << 8)); - snapshot.HEADER.SP = (ushort)(buffer[23] | (buffer[24] << 8)); + snapshot.HEADER.AF = (UInt16)(buffer[21] | (buffer[22] << 8)); + snapshot.HEADER.SP = (UInt16)(buffer[23] | (buffer[24] << 8)); snapshot.HEADER.IM = buffer[25]; - snapshot.HEADER.BORDER = (byte)(buffer[26] & 0x07); + snapshot.HEADER.BORDER = (Byte)(buffer[26] & 0x07); //48k snapshot if (snapshot.TYPE == 0) { - ((SNA_48K)snapshot).RAM = new byte[49152]; + ((SNA_48K)snapshot).RAM = new Byte[49152]; Array.Copy(buffer, 27, ((SNA_48K)snapshot).RAM, 0, 49152); } else @@ -108,7 +108,7 @@ public static SNA_SNAPSHOT LoadSNA(Stream fs) //128k snapshot for (var f = 0; f < 16; f++) { - ((SNA_128K)snapshot).RAM_BANK[f] = new byte[8192]; + ((SNA_128K)snapshot).RAM_BANK[f] = new Byte[8192]; } //Copy ram bank 5 @@ -127,7 +127,7 @@ public static SNA_SNAPSHOT LoadSNA(Stream fs) Array.Copy(buffer, 27 + 16384 + 16384, ((SNA_128K)snapshot).RAM_BANK[BankInPage4 * 2], 0, 8192); Array.Copy(buffer, 27 + 16384 + 16384 + 8192, ((SNA_128K)snapshot).RAM_BANK[BankInPage4 * 2 + 1], 0, 8192); - ((SNA_128K)snapshot).PC = (ushort)(buffer[49179] | (buffer[49180] << 8)); + ((SNA_128K)snapshot).PC = (UInt16)(buffer[49179] | (buffer[49180] << 8)); ((SNA_128K)snapshot).TR_DOS = buffer[49182]; diff --git a/Common/BinarySource/Decoders/Z80File.cs b/Common/BinarySource/Decoders/Z80File.cs index b98f986..acbc334 100644 --- a/Common/BinarySource/Decoders/Z80File.cs +++ b/Common/BinarySource/Decoders/Z80File.cs @@ -9,32 +9,32 @@ namespace PixelWorld.BinarySource.Decoders #nullable disable // Leave 3rd party code as-is. public class Z80_SNAPSHOT { - public int TYPE; //0 = 48k, 1 = 128k, 2 = +3, 3 = Pentagon 128k - public byte I; //I Register - public int HL_, DE_, BC_, AF_; //Alternate registers - public int HL, DE, BC, IX, IY; //16 bit main registers - public byte R; //R Register - public int AF, SP; //AF and SP register - public byte IM; //Interupt Mode - public byte BORDER; //Border colour - public int PC; //PC Register - public byte PORT_7FFD; //Current state of port 7ffd - public byte PORT_FFFD; //Current state of soundchip AY - public byte PORT_1FFD; //Last out to port 1ffd (for +3) - public byte[] AY_REGS; //Contents of AY registers - public bool IFF1; //Are interrupts enabled? - public bool IFF2; - public bool ISSUE2; //Issue 2 Keyboard? - public bool AY_FOR_48K; - public int TSTATES; - public int Byte34; // Extended to detect machine type - public int FileVersion; - public byte[][] RAM_BANK = new byte[16][]; //Contents of the 8192*16 ram banks + public Int32 TYPE; //0 = 48k, 1 = 128k, 2 = +3, 3 = Pentagon 128k + public Byte I; //I Register + public Int32 HL_, DE_, BC_, AF_; //Alternate registers + public Int32 HL, DE, BC, IX, IY; //16 bit main registers + public Byte R; //R Register + public Int32 AF, SP; //AF and SP register + public Byte IM; //Interupt Mode + public Byte BORDER; //Border colour + public Int32 PC; //PC Register + public Byte PORT_7FFD; //Current state of port 7ffd + public Byte PORT_FFFD; //Current state of soundchip AY + public Byte PORT_1FFD; //Last out to port 1ffd (for +3) + public Byte[] AY_REGS; //Contents of AY registers + public Boolean IFF1; //Are interrupts enabled? + public Boolean IFF2; + public Boolean ISSUE2; //Issue 2 Keyboard? + public Boolean AY_FOR_48K; + public Int32 TSTATES; + public Int32 Byte34; // Extended to detect machine type + public Int32 FileVersion; + public Byte[][] RAM_BANK = new Byte[16][]; //Contents of the 8192*16 ram banks } public class Z80File { - private static void GetPage(byte[] buffer, int counter, byte[] bank, int dataLength) + private static void GetPage(Byte[] buffer, Int32 counter, Byte[] bank, Int32 dataLength) { if (dataLength == 0xffff) { @@ -50,11 +50,11 @@ private static void GetPage(byte[] buffer, int counter, byte[] bank, int dataLen if (bite == 0xED && counter - dataBlockOffset < dataLength) { - int bite2 = buffer[counter]; + Int32 bite2 = buffer[counter]; if (bite2 == 0xED) { counter++; - int dataSize = buffer[counter++]; + Int32 dataSize = buffer[counter++]; var data = buffer[counter++]; //compressed data @@ -96,8 +96,8 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) if (byte12 == 255) byte12 = 1; - snapshot.R |= (byte)((byte12 & 0x01) << 7); - snapshot.BORDER = (byte)((byte12 >> 1) & 0x07); + snapshot.R |= (Byte)((byte12 & 0x01) << 7); + snapshot.BORDER = (Byte)((byte12 >> 1) & 0x07); snapshot.DE = buffer[13] | (buffer[14] << 8); snapshot.BC_ = buffer[15] | (buffer[16] << 8); @@ -113,18 +113,18 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) var byte29 = buffer[29]; - snapshot.IM = (byte)(byte29 & 0x3); + snapshot.IM = (Byte)(byte29 & 0x3); snapshot.ISSUE2 = (byte29 & 0x08) != 0; for (var f = 0; f < 16; f++) { - snapshot.RAM_BANK[f] = new byte[8192]; + snapshot.RAM_BANK[f] = new Byte[8192]; } //Version 2 or 3 if (snapshot.PC == 0) { - int headerLength = buffer[30]; + Int32 headerLength = buffer[30]; snapshot.FileVersion = headerLength == 23 ? 2 : 3; snapshot.PC = buffer[32] | (buffer[33] << 8); snapshot.Byte34 = buffer[34]; @@ -174,7 +174,7 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) snapshot.PORT_7FFD = buffer[35]; snapshot.AY_FOR_48K = (buffer[37] & 0x4) != 0; snapshot.PORT_FFFD = buffer[38]; - snapshot.AY_REGS = new byte[16]; + snapshot.AY_REGS = new Byte[16]; for (var f = 0; f < 16; f++) snapshot.AY_REGS[f] = buffer[39 + f]; } @@ -187,7 +187,7 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) snapshot.PORT_1FFD = buffer[86]; } - var _bank = new byte[16384]; + var _bank = new Byte[16384]; //Load rest of the data while (counter < buffer.Length - 1) @@ -196,7 +196,7 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) var dataLength = buffer[counter] | (buffer[counter + 1] << 8); counter += 2; if (counter >= buffer.Length) break; // Some 128K .z80 files have a trailing zero or two - int page = buffer[counter++]; + Int32 page = buffer[counter++]; //copies page data to temporary RAM array GetPage(buffer, counter, _bank, dataLength); @@ -278,7 +278,7 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) snapshot.FileVersion = 1; snapshot.TYPE = 0; //int screenAddr = GetPageAddress(10); - var RAM_48K = new byte[49152]; + var RAM_48K = new Byte[49152]; var isCompressed = (byte12 & 0x20) != 0; if (!isCompressed) @@ -320,7 +320,7 @@ public static Z80_SNAPSHOT LoadZ80(Stream fs) if (bite2 == 0xED) { byteCounter++; - int dataLength = buffer[byteCounter++]; + Int32 dataLength = buffer[byteCounter++]; var data = buffer[byteCounter++]; //compressed data diff --git a/Common/BinarySource/IBinarySource.cs b/Common/BinarySource/IBinarySource.cs index e621d42..8c24810 100644 --- a/Common/BinarySource/IBinarySource.cs +++ b/Common/BinarySource/IBinarySource.cs @@ -5,5 +5,5 @@ namespace PixelWorld.BinarySource; public interface IBinarySource { - ArraySegment GetMemory(Stream source); + ArraySegment GetMemory(Stream source); } \ No newline at end of file diff --git a/Common/BinarySource/RawBinarySource.cs b/Common/BinarySource/RawBinarySource.cs index 60372ff..0f60b52 100644 --- a/Common/BinarySource/RawBinarySource.cs +++ b/Common/BinarySource/RawBinarySource.cs @@ -5,8 +5,8 @@ namespace PixelWorld.BinarySource; public class RawBinarySource : IBinarySource { - public ArraySegment GetMemory(Stream input) + public ArraySegment GetMemory(Stream input) { - return new ArraySegment(input.ReadAllBytes()); + return new ArraySegment(input.ReadAllBytes()); } } \ No newline at end of file diff --git a/Common/BinarySource/SnaBinarySource.cs b/Common/BinarySource/SnaBinarySource.cs index dfa0a83..c438d3f 100644 --- a/Common/BinarySource/SnaBinarySource.cs +++ b/Common/BinarySource/SnaBinarySource.cs @@ -10,8 +10,8 @@ public class SnaBinarySource : IBinarySource public ArraySegment GetMemory(Stream source) { - var signatureBuffer = new byte[8]; - source.Read(signatureBuffer, 0, signatureBuffer.Length); + var signatureBuffer = new Byte[8]; + source.ReadExactly(signatureBuffer); if (Encoding.ASCII.GetString(signatureBuffer, 0, signatureBuffer.Length) == "MV - SNA") { diff --git a/Common/BinarySource/SpectrumBinarySource.cs b/Common/BinarySource/SpectrumBinarySource.cs index 81d4d86..7366706 100644 --- a/Common/BinarySource/SpectrumBinarySource.cs +++ b/Common/BinarySource/SpectrumBinarySource.cs @@ -4,9 +4,9 @@ namespace PixelWorld.BinarySource; public abstract class SpectrumBinarySource { - private static readonly int[] mappablePages = [0, 2, 6, 8, 12, 14]; + private static readonly Int32[] mappablePages = [0, 2, 6, 8, 12, 14]; - protected static ArraySegment Setup128KMemory(byte[][] ramBanks, byte port7ffd) + protected static ArraySegment Setup128KMemory(Byte[][] ramBanks, Byte port7ffd) { Out.Write(" Loading as ZX Spectrum 128K"); @@ -18,7 +18,7 @@ protected static ArraySegment Setup128KMemory(byte[][] ramBanks, byte port extraSpace = 32; } - var memory = new byte[(extraSpace + 128) * 1024]; // Leave first 16KB ROM blank + var memory = new Byte[(extraSpace + 128) * 1024]; // Leave first 16KB ROM blank CopyBank(ramBanks, 10, memory, 0x4000); CopyBank(ramBanks, 04, memory, 0x8000); @@ -34,16 +34,16 @@ protected static ArraySegment Setup128KMemory(byte[][] ramBanks, byte port } } - return new ArraySegment(memory); + return new ArraySegment(memory); } - protected static void CopyBank(byte[][] ramBanks, int bank, byte[] ram, int address) + protected static void CopyBank(Byte[][] ramBanks, Int32 bank, Byte[] ram, Int32 address) { Array.Copy(ramBanks[bank], 0, ram, address, 8192); Array.Copy(ramBanks[bank + 1], 0, ram, address + 8192, 8192); } - protected static int GetC800RamBank(int out7ffd) + protected static Int32 GetC800RamBank(Int32 out7ffd) { return (out7ffd & 0x07) * 2; } diff --git a/Common/BinarySource/Z80BinarySource.cs b/Common/BinarySource/Z80BinarySource.cs index 0a77226..e21cb92 100644 --- a/Common/BinarySource/Z80BinarySource.cs +++ b/Common/BinarySource/Z80BinarySource.cs @@ -37,11 +37,11 @@ public ArraySegment GetMemory(Stream source) catch (Exception e) { Out.Write($" Unable to process {e.Message}"); - return new ArraySegment(); + return new ArraySegment(); } } - private static ArraySegment SetupPlus3Memory(Z80_SNAPSHOT snapshot) + private static ArraySegment SetupPlus3Memory(Z80_SNAPSHOT snapshot) { Out.Write(" Loading as ZX Spectrum 128K +3"); @@ -51,14 +51,14 @@ private static ArraySegment SetupPlus3Memory(Z80_SNAPSHOT snapshot) throw new NotSupportedException("Need to implement +3 ROM bank paging"); } - private static ArraySegment Setup48KMemory(Z80_SNAPSHOT snapshot) + private static ArraySegment Setup48KMemory(Z80_SNAPSHOT snapshot) { Out.Write(" Loading as ZX Spectrum 48K"); - var memory = new byte[(16 + 48) * 1024]; // Leave first 16KB ROM blank + var memory = new Byte[(16 + 48) * 1024]; // Leave first 16KB ROM blank CopyBank(snapshot.RAM_BANK, 10, memory, 0x4000); CopyBank(snapshot.RAM_BANK, 04, memory, 0x8000); CopyBank(snapshot.RAM_BANK, 00, memory, 0xC000); - return new ArraySegment(memory); + return new ArraySegment(memory); } private static MemoryModel GetMemoryModel(Z80_SNAPSHOT snapshot) diff --git a/Common/BinarySource/ZXSnaBinarySource.cs b/Common/BinarySource/ZXSnaBinarySource.cs index a0eb84a..92fa54c 100644 --- a/Common/BinarySource/ZXSnaBinarySource.cs +++ b/Common/BinarySource/ZXSnaBinarySource.cs @@ -26,13 +26,13 @@ public ArraySegment GetMemory(Stream source) catch (Exception e) { Out.Write($" Unable to process {e.Message}"); - return new ArraySegment(); + return new ArraySegment(); } } - private static ArraySegment Setup48KMemory(SNA_48K snapshot) + private static ArraySegment Setup48KMemory(SNA_48K snapshot) { Out.Write(" Loading as ZX Spectrum 48K"); - return new ArraySegment(snapshot.RAM); + return new ArraySegment(snapshot.RAM); } } \ No newline at end of file diff --git a/Common/ByteArrayEqualityComparer.cs b/Common/ByteArrayEqualityComparer.cs index c35b94d..f81ff0e 100644 --- a/Common/ByteArrayEqualityComparer.cs +++ b/Common/ByteArrayEqualityComparer.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace PixelWorld; -public class ByteArrayEqualityComparer : IEqualityComparer +public class ByteArrayEqualityComparer : IEqualityComparer { - public bool Equals(byte[]? x, byte[]? y) + public Boolean Equals(Byte[]? x, Byte[]? y) { return x != null && y != null && x[0] == y[0] @@ -17,7 +18,7 @@ public bool Equals(byte[]? x, byte[]? y) && x[7] == y[7]; } - public int GetHashCode(byte[] b) + public Int32 GetHashCode(Byte[] b) { return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24 ^ (b[4] | b[5] | b[6] | b[7]); diff --git a/Common/ByteArrayExtensions.cs b/Common/ByteArrayExtensions.cs index dd4e2b3..7b0e1fd 100644 --- a/Common/ByteArrayExtensions.cs +++ b/Common/ByteArrayExtensions.cs @@ -4,9 +4,9 @@ namespace PixelWorld; public static class ByteArrayExtensions { - public static string ToHex(this byte[] input) + public static String ToHex(this Byte[] input) { - var output = new char[input.Length * 2]; + var output = new Char[input.Length * 2]; for (var i = 0; i < input.Length; i++) { var r = i * 2; @@ -17,13 +17,13 @@ public static string ToHex(this byte[] input) return new String(output); } - public static void InvertBuffer(this byte[] buffer) + public static void InvertBuffer(this Byte[] buffer) { for (var i = 0; i < buffer.Length; i++) - buffer[i] = (byte)~buffer[i]; + buffer[i] = (Byte)~buffer[i]; } - public static bool IsEmpty(this byte[] buffer, int index, int rows = 8) + public static Boolean IsEmpty(this Byte[] buffer, Int32 index, Int32 rows = 8) { for (var e = 0; e < rows; e++) if (buffer[index + e] != 0) @@ -32,7 +32,7 @@ public static bool IsEmpty(this byte[] buffer, int index, int rows = 8) return true; } - public static bool IsFull(this byte[] buffer, int index, int rows = 8) + public static Boolean IsFull(this Byte[] buffer, Int32 index, Int32 rows = 8) { for (var e = 0; e < rows; e++) if (buffer[index + e] != 255) @@ -41,7 +41,7 @@ public static bool IsFull(this byte[] buffer, int index, int rows = 8) return true; } - public static int CountBlankGlyphs(this byte[] buffer, int index, int length, int height) + public static Int32 CountBlankGlyphs(this Byte[] buffer, Int32 index, Int32 length, Int32 height) { var count = 0; for (var i = index; i < index + length; i += height) @@ -52,7 +52,7 @@ public static int CountBlankGlyphs(this byte[] buffer, int index, int length, in return count; } - public static bool IsSame(this byte[] buffer, int firstIndex, int secondIndex) + public static Boolean IsSame(this Byte[] buffer, Int32 firstIndex, Int32 secondIndex) { for (var e = 0; e < 8; e++) if (buffer[firstIndex + e] != buffer[secondIndex + e]) @@ -61,7 +61,7 @@ public static bool IsSame(this byte[] buffer, int firstIndex, int secondIndex) return true; } - public static bool IsSame(this byte[] buffer, int firstIndex, byte[] character) + public static Boolean IsSame(this Byte[] buffer, Int32 firstIndex, Byte[] character) { for (var e = 0; e < 8; e++) if (buffer[firstIndex + e] != character[e]) @@ -70,12 +70,12 @@ public static bool IsSame(this byte[] buffer, int firstIndex, byte[] character) return true; } - public static int PixelCount(this byte[] buffer, int offset, char c) + public static Int32 PixelCount(this Byte[] buffer, Int32 offset, Char c) { var count = 0; for (var y = 0; y < 8; y++) { - int g = buffer[offset + c - 32 + y]; + Int32 g = buffer[offset + c - 32 + y]; for (var x = 0; x < 8; x++) { var f = 1 << x; diff --git a/Common/Common.csproj b/Common/Common.csproj index 7161299..d723ee7 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 PixelWorld PixelWorld Debug;Release;Debug Dump;Debug Dedupe;Organize;ConvertZXtoC64;Preview;ZXToFZX @@ -13,8 +13,8 @@ - - + + diff --git a/Common/Display/SpectrumDisplay.cs b/Common/Display/SpectrumDisplay.cs index a4ade48..65985b4 100644 --- a/Common/Display/SpectrumDisplay.cs +++ b/Common/Display/SpectrumDisplay.cs @@ -8,11 +8,11 @@ namespace PixelWorld.Display; public class SpectrumDisplay { - private const int AttributeWidth = 32; - private const int AttributeHeight = 24; - private const int PixelWidth = 8 * AttributeWidth; - private const int PixelHeight = 8 * AttributeHeight; - private const int AttributeOffset = PixelWidth * AttributeHeight; + private const Int32 AttributeWidth = 32; + private const Int32 AttributeHeight = 24; + private const Int32 PixelWidth = 8 * AttributeWidth; + private const Int32 PixelHeight = 8 * AttributeHeight; + private const Int32 AttributeOffset = PixelWidth * AttributeHeight; private static readonly UInt16[] lookupY = new UInt16[PixelHeight]; @@ -35,12 +35,12 @@ static SpectrumDisplay() } } - public static bool IsBlank(byte[] buffer, int offset) + public static Boolean IsBlank(Byte[] buffer, Int32 offset) { return buffer.Skip(offset).Take(768).All(b => b == 0); } - public static Image GetBitmap(byte[] buffer, int offset, bool altFlashFrame = false) + public static Image GetBitmap(Byte[] buffer, Int32 offset, Boolean altFlashFrame = false) { var image = new Image(PixelWidth, PixelHeight); @@ -69,14 +69,14 @@ public static Image GetBitmap(byte[] buffer, int offset, bool altFlashFra return image; } - public static byte[][] GetCandidates(byte[] buffer, int offset) + public static Byte[][] GetCandidates(Byte[] buffer, Int32 offset) { - var uniques = new HashSet(new ByteArrayEqualityComparer()); + var uniques = new HashSet(new ByteArrayEqualityComparer()); for (var ay = 0; ay < AttributeHeight; ay++) for (var ax = 0; ax < AttributeWidth; ax++) { - var block = new byte[8]; + var block = new Byte[8]; for (var py = 0; py < 8; py++) { var y = ay * 8 + py; @@ -93,6 +93,6 @@ public static byte[][] GetCandidates(byte[] buffer, int offset) return uniques.ToArray(); } - private static readonly byte[] EmptyChar = [0, 0, 0, 0, 0, 0, 0, 0]; - private static readonly byte[] FullChar = [255, 255, 255, 255, 255, 255, 255, 255]; + private static readonly Byte[] EmptyChar = [0, 0, 0, 0, 0, 0, 0, 0]; + private static readonly Byte[] FullChar = [255, 255, 255, 255, 255, 255, 255, 255]; } \ No newline at end of file diff --git a/Common/DumpScanners/SpectrumDumpScanner.cs b/Common/DumpScanners/SpectrumDumpScanner.cs index 3490c59..88b4fd4 100644 --- a/Common/DumpScanners/SpectrumDumpScanner.cs +++ b/Common/DumpScanners/SpectrumDumpScanner.cs @@ -1,4 +1,5 @@ -using PixelWorld.Display; +using System; +using PixelWorld.Display; using PixelWorld.Formatters; using PixelWorld.Machines; using PixelWorld.OffsetFinders; @@ -12,7 +13,7 @@ namespace PixelWorld.DumpScanners; public static class SpectrumDumpScanner { - public static List Read(BinaryReader reader, string name) + public static List Read(BinaryReader reader, String name) { var buffer = reader.ReadBytes(1024 * 2048); // 2MB is enough for any Speccy @@ -26,7 +27,7 @@ public static List Read(BinaryReader reader, string name) return fonts; } - private static IEnumerable GetOffsets(byte[] buffer) + private static IEnumerable GetOffsets(Byte[] buffer) { var address = buffer.Length == 65536 ? 16384 : 0; var candidates = SpectrumDisplay.GetCandidates(buffer, address); @@ -36,13 +37,13 @@ private static IEnumerable GetOffsets(byte[] buffer) var scr = CandidatesInWindowFinder.FindOffsets(buffer, candidates); var heu = GeneralHeuristicFinder.FindOffsets(buffer); - var offsets = new List(); + var offsets = new List(); offsets.AddRange(rst); offsets.AddRange(rom); offsets.AddRange(scr); offsets.AddRange(heu); - var dupes = new HashSet(offsets + var dupes = new HashSet(offsets .GroupBy(o => o) .Where(o => o.Count() > 1) .Select(g => g.Key)); @@ -52,10 +53,10 @@ private static IEnumerable GetOffsets(byte[] buffer) OutFinderDetail(scr, "SCREEN$ Tiles", dupes); OutFinderDetail(heu, "Heuristics", dupes); - return new HashSet(offsets); + return new HashSet(offsets); } - public static void OutFinderDetail(List offsets, string method, HashSet dupes) + public static void OutFinderDetail(List offsets, String method, HashSet dupes) { if (offsets.Count <= 0) return; @@ -63,12 +64,12 @@ public static void OutFinderDetail(List offsets, string method, HashSet 26; } - public static bool IsRomFont(byte[] buffer, int offset) + public static Boolean IsRomFont(Byte[] buffer, Int32 offset) { var sha1 = SHA384.Create().ComputeHash(buffer, offset, Spectrum.FontSize); return sha1.ToHex() == diff --git a/Common/Fonts/Font.cs b/Common/Fonts/Font.cs index bb05129..1a57cf7 100644 --- a/Common/Fonts/Font.cs +++ b/Common/Fonts/Font.cs @@ -9,11 +9,11 @@ namespace PixelWorld.Fonts; [DebuggerDisplay("Print(),nq")] -public class Font(string name, int height = 8) : IEquatable +public class Font(String name, Int32 height = 8) : IEquatable { - public readonly string Name = name; - public readonly int Height = height; - public Dictionary Glyphs { get; } = new(); + public readonly String Name = name; + public readonly Int32 Height = height; + public Dictionary Glyphs { get; } = new(); public Font Copy() { @@ -23,7 +23,7 @@ public Font Copy() return copied; } - public string Print(string input) + public String Print(String input) { var s = ""; @@ -46,7 +46,7 @@ public string Print(string input) return s; } - public bool Equals(Font? other) + public Boolean Equals(Font? other) { return other is not null && (ReferenceEquals(this, other) || string.Equals(Name, other.Name) @@ -56,18 +56,18 @@ public bool Equals(Font? other) StructuralComparisons.StructuralEqualityComparer)); } - public override bool Equals(object? obj) + public override Boolean Equals(Object? obj) { return obj is not null && (ReferenceEquals(this, obj) || obj.GetType() == GetType() && Equals((Font)obj)); } - public override int GetHashCode() + public override Int32 GetHashCode() { return HashCode.Combine(Name, Height, Glyphs); } - public Image CreateImage(int rows, bool transparent) + public Image CreateImage(Int32 rows, Boolean transparent) { var fullWidth = Glyphs.Sum(g => g.Value.Width); var previewWidth = fullWidth / rows; @@ -78,7 +78,7 @@ public Image CreateImage(int rows, bool transparent) return image; } - public void DrawImage(Image image, int glyphsPerRow, bool transparent) + public void DrawImage(Image image, Int32 glyphsPerRow, Boolean transparent) { var xOff = 0; var yOff = 0; @@ -102,7 +102,7 @@ public void DrawImage(Image image, int glyphsPerRow, bool transparent) } } - public void DrawImage(Image image, int glyphsPerRow, IReadOnlyDictionary targetCharset, Color foreground, Color background, int? padWidth = null) + public void DrawImage(Image image, Int32 glyphsPerRow, IReadOnlyDictionary targetCharset, Color foreground, Color background, Int32? padWidth = null) { var xOff = 0; var yOff = 0; diff --git a/Common/Fonts/Glyph.cs b/Common/Fonts/Glyph.cs index 6f45823..34d13a0 100644 --- a/Common/Fonts/Glyph.cs +++ b/Common/Fonts/Glyph.cs @@ -6,13 +6,13 @@ namespace PixelWorld.Fonts; [DebuggerDisplay("{Print(),nq}")] -public class Glyph(int width, int height, bool[,] data) : IEquatable +public class Glyph(Int32 width, Int32 height, Boolean[,] data) : IEquatable { - public int Height { get; } = height; - public int Width { get; } = width; - public bool[,] Data { get; } = data; + public Int32 Height { get; } = height; + public Int32 Width { get; } = width; + public Boolean[,] Data { get; } = data; - public bool Equals(Glyph? other) + public Boolean Equals(Glyph? other) { return other is not null && (ReferenceEquals(this, other) || Height == other.Height @@ -20,22 +20,22 @@ public bool Equals(Glyph? other) && SequenceEquals(Data, other.Data)); } - public static bool SequenceEquals(T[,] a, T[,] b) => a.Rank == b.Rank - && Enumerable.Range(0, a.Rank).All(d=> a.GetLength(d) == b.GetLength(d)) - && a.Cast().SequenceEqual(b.Cast()); + public static Boolean SequenceEquals(T[,] a, T[,] b) => a.Rank == b.Rank + && Enumerable.Range(0, a.Rank).All(d=> a.GetLength(d) == b.GetLength(d)) + && a.Cast().SequenceEqual(b.Cast()); - public override bool Equals(object? obj) + public override Boolean Equals(Object? obj) { return obj is not null && (ReferenceEquals(this, obj) || obj.GetType() == GetType() && Equals((Glyph)obj)); } - public override int GetHashCode() + public override Int32 GetHashCode() { return HashCode.Combine(Height, Width); } - public string Print() + public String Print() { var sb = new StringBuilder(); for (var y = 0; y < Height; y++) @@ -48,7 +48,7 @@ public string Print() return sb.ToString(); } - public bool IsBlank() + public Boolean IsBlank() { for (var y = 0; y < Height; y++) for (var x = 0; x < Width; x++) @@ -57,7 +57,7 @@ public bool IsBlank() return true; } - public bool IsRowBlank(int row) + public Boolean IsRowBlank(Int32 row) { for (var x = 0; x < Width; x++) if (Data[x, row]) @@ -65,7 +65,7 @@ public bool IsRowBlank(int row) return true; } - public bool IsColumnBlank(int column) + public Boolean IsColumnBlank(Int32 column) { for (var y = 0; y < Height; y++) if (Data[column, y]) diff --git a/Common/Formatters/AssemblyFontFormatter.cs b/Common/Formatters/AssemblyFontFormatter.cs index 25860f5..70d193b 100644 --- a/Common/Formatters/AssemblyFontFormatter.cs +++ b/Common/Formatters/AssemblyFontFormatter.cs @@ -8,7 +8,7 @@ namespace PixelWorld.Formatters; public static class AssemblyFontFormatter { - public static void CreateDefines(string language, string defineByteInstruction, string format, List fileNames, string outputFolder, string credit) + public static void CreateDefines(String language, String defineByteInstruction, String format, List fileNames, String outputFolder, String credit) { foreach (var fileName in fileNames) { @@ -17,7 +17,7 @@ public static void CreateDefines(string language, string defineByteInstruction, using var reader = new BinaryReader(source); var font = ByteFontFormatter.Create(reader, Path.GetFileNameWithoutExtension(fileName), 0, Spectrum.UK); var output = new StringBuilder(); - output.Append($"\t; {Path.GetFileNameWithoutExtension(fileName)} font {credit}\n"); + output.AppendLine($"\t; {Path.GetFileNameWithoutExtension(fileName)} font {credit}"); foreach (var glyph in font.Glyphs) { output.Append("\t" + defineByteInstruction); @@ -28,7 +28,7 @@ public static void CreateDefines(string language, string defineByteInstruction, for (var x = 0; x < charWidth; x++) { if (glyph.Value.Data[x, y]) - b |= (byte)(1 << charWidth - 1 - x); + b |= (Byte)(1 << charWidth - 1 - x); } if (y > 0) output.Append(','); @@ -41,36 +41,4 @@ public static void CreateDefines(string language, string defineByteInstruction, File.WriteAllText(Utils.MakeFileName(fileName, language + ".asm", outputFolder), output.ToString()); } } - - public static void GenZ80AsmBinary(List fileNames, string outputFolder, string credit) - { - foreach (var fileName in fileNames) - { - Out.Write($"Generating Z80 assembly file for {fileName}"); - using var source = File.OpenRead(fileName); - using var reader = new BinaryReader(source); - var font = ByteFontFormatter.Create(reader, Path.GetFileNameWithoutExtension(fileName), 0, Spectrum.UK); - var output = new StringBuilder(); - output.Append($"\t; {Path.GetFileNameWithoutExtension(fileName)} font {credit}\n"); - foreach (var glyph in font.Glyphs) - { - output.Append($"\t; {glyph.Key}\n"); - - for (var y = 0; y < font.Height; y++) - { - var b = new Byte(); - var charWidth = glyph.Value.Width; - for (var x = 0; x < charWidth; x++) - { - if (glyph.Value.Data[x, y]) - b |= (byte)(1 << charWidth - 1 - x); - } - var binary = "00000000" + Convert.ToString(b, 2); - output.Append($"\tdefb %{binary.Substring(binary.Length - 8, 8)}\n"); - } - } - - File.WriteAllText(Utils.MakeFileName(fileName, "z80.asm", outputFolder), output.ToString()); - } - } } \ No newline at end of file diff --git a/Common/Formatters/ByteFontFormatter.cs b/Common/Formatters/ByteFontFormatter.cs index 8f43a6b..23db2a9 100644 --- a/Common/Formatters/ByteFontFormatter.cs +++ b/Common/Formatters/ByteFontFormatter.cs @@ -7,19 +7,19 @@ namespace PixelWorld.Formatters; public static class ByteFontFormatter { - private const int CharWidth = 8; - private const int CharHeight = 8; - private static readonly ArraySegment BlankChar = new(new byte[8], 0, 8); - private static readonly Func> BlankWriter = _ => BlankChar; + private const Int32 CharWidth = 8; + private const Int32 CharHeight = 8; + private static readonly ArraySegment BlankChar = new(new Byte[8], 0, 8); + private static readonly Func> BlankWriter = _ => BlankChar; - public static Font Load(string fileName, IReadOnlyDictionary charset) + public static Font Load(String fileName, IReadOnlyDictionary charset) { using var source = File.OpenRead(fileName); using var reader = new BinaryReader(source); return Create(reader, Path.GetFileNameWithoutExtension(fileName), 0, charset); } - public static Font Create(BinaryReader reader, string name, int offset, IReadOnlyDictionary charset) + public static Font Create(BinaryReader reader, String name, Int32 offset, IReadOnlyDictionary charset) { var font = new Font(name); reader.BaseStream.Seek(offset, SeekOrigin.Begin); @@ -27,12 +27,12 @@ public static Font Create(BinaryReader reader, string name, int offset, IReadOnl return font; } - public static void Read(Font font, BinaryReader reader, IReadOnlyDictionary charset) + public static void Read(Font font, BinaryReader reader, IReadOnlyDictionary charset) { var c = 0; while (reader.BaseStream.Position < reader.BaseStream.Length) { - var data = new bool[CharWidth, CharHeight]; + var data = new Boolean[CharWidth, CharHeight]; for (var y = 0; y < CharHeight; y++) { if (reader.BaseStream.Position == reader.BaseStream.Length) return; @@ -49,7 +49,7 @@ public static void Read(Font font, BinaryReader reader, IReadOnlyDictionary charset, int length, Func>? fallback = null) + public static void Write(Font font, Stream output, IReadOnlyDictionary charset, Int32 length, Func>? fallback = null) { fallback ??= BlankWriter; @@ -64,14 +64,14 @@ public static void Write(Font font, Stream output, IReadOnlyDictionary fileNames, string outputFolder, string credit) + public static void CreateFontHeaderConst(String byteType, List fileNames, String outputFolder, String credit) { foreach (var fileName in fileNames) { @@ -39,7 +39,7 @@ public static void CreateFontHeaderConst(string byteType, List fileNames for (var x = 0; x < charWidth; x++) { if (glyph.Value.Data[x, y]) - b |= (byte)(1 << charWidth - 1 - x); + b |= (Byte)(1 << charWidth - 1 - x); } if (y > 0) output.Append(", "); output.Append($"0x{b:x2}"); diff --git a/Common/Formatters/FzxFontFormatter.cs b/Common/Formatters/FzxFontFormatter.cs index 06648b0..79a3f7f 100644 --- a/Common/Formatters/FzxFontFormatter.cs +++ b/Common/Formatters/FzxFontFormatter.cs @@ -8,7 +8,7 @@ namespace PixelWorld.Formatters; public static class FzxFontFormatter { - public static void Write(Font font, Stream output, bool makeProportional = false) + public static void Write(Font font, Stream output, Boolean makeProportional = false) { if (makeProportional) font = FontSpacer.MakeProportional(font, 0, 0, maxWidth: 16); @@ -16,12 +16,12 @@ public static void Write(Font font, Stream output, bool makeProportional = false using var writer = new BinaryWriter(output); // Header - writer.Write((byte) font.Height); - writer.Write((byte) (makeProportional ? 1 : 0)); - writer.Write((byte) 127); // Hard-coded to 7F/end of 7-bit ASCII + writer.Write((Byte) font.Height); + writer.Write((Byte) (makeProportional ? 1 : 0)); + writer.Write((Byte) 127); // Hard-coded to 7F/end of 7-bit ASCII // Figure out how many leading blank rows per char - var blankRows = new Dictionary>(); + var blankRows = new Dictionary>(); foreach (var glyph in font.Glyphs) blankRows[glyph.Key] = CountTopAndBottomBlankRows(glyph.Value); @@ -41,7 +41,7 @@ public static void Write(Font font, Stream output, bool makeProportional = false writer.Write((UInt16) relativeOffset); dataOffset += glyph.Value.Height - blanks.Item1 - blanks.Item2; - writer.Write((byte) ((shift << 4) | (glyph.Value.Width - 1))); + writer.Write((Byte) ((shift << 4) | (glyph.Value.Width - 1))); } // The "final word" is the relative offset to the end of data @@ -58,7 +58,7 @@ public static void Write(Font font, Stream output, bool makeProportional = false for (var x = 0; x < glyph.Value.Width; x++) { if (glyph.Value.Data[x, y]) - b |= (byte) (1 << 8 - x - 1); + b |= (Byte) (1 << 8 - x - 1); } writer.Write(b); @@ -66,7 +66,7 @@ public static void Write(Font font, Stream output, bool makeProportional = false } } - private static Tuple CountTopAndBottomBlankRows(Glyph glyph) + private static Tuple CountTopAndBottomBlankRows(Glyph glyph) { var top = 0; var topY = 0; diff --git a/Common/Formatters/ImageFontFormatter.cs b/Common/Formatters/ImageFontFormatter.cs index 965fe23..11db8fd 100644 --- a/Common/Formatters/ImageFontFormatter.cs +++ b/Common/Formatters/ImageFontFormatter.cs @@ -1,4 +1,5 @@ -using PixelWorld.Fonts; +using System; +using PixelWorld.Fonts; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats.Png; @@ -11,8 +12,8 @@ namespace PixelWorld.Formatters; public static class ImageFontFormatter { - private const int CharWidth = 8; - private const int CharHeight = 8; + private const Int32 CharWidth = 8; + private const Int32 CharHeight = 8; public static readonly IImageEncoder PngEncoder = new PngEncoder { @@ -28,7 +29,7 @@ public static class ImageFontFormatter TransparentColorMode = WebpTransparentColorMode.Preserve }; - public static void Read(Font font, Stream source, IReadOnlyDictionary charset) + public static void Read(Font font, Stream source, IReadOnlyDictionary charset) { using var image = Image.Load(source); @@ -44,7 +45,7 @@ public static void Read(Font font, Stream source, IReadOnlyDictionary { for (var charX = 0; charX < image.Width; charX += CharWidth) { - var data = new bool[CharWidth, CharHeight]; + var data = new Boolean[CharWidth, CharHeight]; for (var y = 0; y < CharHeight; y++) for (var x = 0; x < CharHeight; x++) data[x, y] = image[charX + x, charY + y] != offColor; @@ -55,7 +56,7 @@ public static void Read(Font font, Stream source, IReadOnlyDictionary } } - public static void Write(Font font, Stream output, IImageEncoder imageEncoder, bool transparent) + public static void Write(Font font, Stream output, IImageEncoder imageEncoder, Boolean transparent) { using var bitmap = font.CreateImage(3, transparent); bitmap.Save(output, imageEncoder); diff --git a/Common/Formatters/RustHeaderFontFormatter.cs b/Common/Formatters/RustHeaderFontFormatter.cs index 3b72d48..a550225 100644 --- a/Common/Formatters/RustHeaderFontFormatter.cs +++ b/Common/Formatters/RustHeaderFontFormatter.cs @@ -8,7 +8,7 @@ namespace PixelWorld.Formatters; public static class RustHeaderFontFormatter { - public static void CreateFontHeaderConst(List fileNames, string outputFolder, string credit) + public static void CreateFontHeaderConst(List fileNames, String outputFolder, String credit) { foreach (var fileName in fileNames) { @@ -33,7 +33,7 @@ public static void CreateFontHeaderConst(List fileNames, string outputFo for (var x = 0; x < charWidth; x++) { if (glyph.Value.Data[x, y]) - b |= (byte)(1 << charWidth - 1 - x); + b |= (Byte)(1 << charWidth - 1 - x); } if (y > 0) output.Append(", "); output.Append($"0x{b:x2}"); diff --git a/Common/Formatters/UfoFont.cs b/Common/Formatters/UfoFont.cs index 8d1b4f5..abe65b7 100644 --- a/Common/Formatters/UfoFont.cs +++ b/Common/Formatters/UfoFont.cs @@ -1,4 +1,5 @@ -using PixelWorld.Fonts; +using System; +using PixelWorld.Fonts; using System.Collections.Generic; using System.IO; using System.Xml; @@ -7,7 +8,7 @@ namespace PixelWorld.Formatters; public static class UfoFontFormatter { - private static readonly Dictionary CharToName = new() + private static readonly Dictionary CharToName = new() { { ' ', "space" }, { '!', "exclam" }, @@ -110,7 +111,7 @@ public static class UfoFontFormatter private static readonly XmlWriterSettings XmlWriterSettings = new() { Indent = true, NewLineChars = "\n" }; - public static void Write(Font font, string path) + public static void Write(Font font, String path) { var basePath = Path.Join(path, "glyphs"); Directory.CreateDirectory(basePath); @@ -137,7 +138,7 @@ public static void Write(Font font, string path) { var name = CharToName[key]; nameAttribute.Value = name; - hexAttribute.Value = ((int)key).ToString("X4"); + hexAttribute.Value = ((Int32)key).ToString("X4"); outlineElement.RemoveAll(); for (var y = 0; y < glyphData.Height; y++) @@ -156,7 +157,7 @@ public static void Write(Font font, string path) return; - void WriteDoc(string glyphName) + void WriteDoc(String glyphName) { if (glyphName.Length == 1 && char.IsUpper(glyphName[0])) glyphName += "_"; @@ -172,7 +173,7 @@ XmlElement CreatePixelComponent() return pixelComponent; } - XmlAttribute CreateAttribute(string name, string value) + XmlAttribute CreateAttribute(String name, String value) { var attr = doc.CreateAttribute(name); attr.Value = value; diff --git a/Common/Machines/Atari8.cs b/Common/Machines/Atari8.cs index a1921fe..2f00680 100644 --- a/Common/Machines/Atari8.cs +++ b/Common/Machines/Atari8.cs @@ -1,17 +1,18 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace PixelWorld.Machines; public static class Atari8 { - public static IReadOnlyDictionary US {get; } = ( + public static IReadOnlyDictionary US {get; } = ( " !\"#$%&'()*+,-./0123456789:;<=>?" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0abcdefghijklmnopqrstuvwxyz€" ).ToIndexedDictionary(); - public static int FontSize => 1024; + public static Int32 FontSize => 1024; - public static string Extension => "fnt"; + public static String Extension => "fnt"; } \ No newline at end of file diff --git a/Common/Machines/Commodore64.cs b/Common/Machines/Commodore64.cs index 7329a84..5f78952 100644 --- a/Common/Machines/Commodore64.cs +++ b/Common/Machines/Commodore64.cs @@ -1,16 +1,17 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace PixelWorld.Machines; public static class Commodore64 { - public static IReadOnlyDictionary BothUK { get; } = + public static IReadOnlyDictionary BothUK { get; } = "@abcdefghijklmnopqrstuvwxyz[£]\0\0 !\"#$%&'()*+,-./0123456789:;<=>?\0ABCDEFGHIJKLMNOPQRSTUVWXYZ" .ToIndexedDictionary(); - public static IReadOnlyDictionary UpperUK { get; } = + public static IReadOnlyDictionary UpperUK { get; } = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[£]\0\0 !\"#$%&'()*+,-./0123456789:;<=>?" .ToIndexedDictionary(); - public static int Length => 1024; + public static Int32 Length => 1024; } \ No newline at end of file diff --git a/Common/Machines/GameBoy.cs b/Common/Machines/GameBoy.cs index 124b4b3..97d5283 100644 --- a/Common/Machines/GameBoy.cs +++ b/Common/Machines/GameBoy.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using SixLabors.ImageSharp; namespace PixelWorld.Machines; public static class GameBoy { - public static IReadOnlyDictionary Studio { get; } = ( + public static IReadOnlyDictionary Studio { get; } = ( " !\"#$%&'()*+,-./" + "0123456789:;<=>?" + "@ABCDEFGHIJKLMNO" + diff --git a/Common/Machines/Msx.cs b/Common/Machines/Msx.cs index e5bbf94..d343a0a 100644 --- a/Common/Machines/Msx.cs +++ b/Common/Machines/Msx.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace PixelWorld.Machines; public static class Msx { - public static IReadOnlyDictionary International { get; } = ( + public static IReadOnlyDictionary International { get; } = ( " !\"#$%&'()*+,-./0123456789:;<=>?" + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" + "`abcdefghijklmnopqrstuvwxyz{|}~▵" + @@ -14,7 +15,7 @@ public static class Msx "αßΓπΣσµτΦΘΩδ∞⌀∈∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■" ).ToIndexedDictionary(); - public static int FontSize => 2048; + public static Int32 FontSize => 2048; - public static string Extension => "fnt"; + public static String Extension => "fnt"; } \ No newline at end of file diff --git a/Common/Machines/Spectrum.cs b/Common/Machines/Spectrum.cs index 88a1aca..bb2fc1c 100644 --- a/Common/Machines/Spectrum.cs +++ b/Common/Machines/Spectrum.cs @@ -1,12 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace PixelWorld.Machines; public static class Spectrum { - public static IReadOnlyDictionary UK { get; } = + public static IReadOnlyDictionary UK { get; } = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_£abcdefghijklmnopqrstuvwxyz{|}~©€" .ToIndexedDictionary(); - public static int FontSize => 768; + public static Int32 FontSize => 768; } \ No newline at end of file diff --git a/Common/OffsetFinders/CandidatesInWindowFinder.cs b/Common/OffsetFinders/CandidatesInWindowFinder.cs index 151d70b..b41014e 100644 --- a/Common/OffsetFinders/CandidatesInWindowFinder.cs +++ b/Common/OffsetFinders/CandidatesInWindowFinder.cs @@ -11,21 +11,21 @@ namespace PixelWorld.OffsetFinders; /// public static class CandidatesInWindowFinder { - private const int MinUniqueInWindow = 36; + private const Int32 MinUniqueInWindow = 36; - private class CandidateLocation(int offset, int candidate) + private class CandidateLocation(Int32 offset, Int32 candidate) { - public readonly int Offset = offset; - public readonly int Candidate = candidate; + public readonly Int32 Offset = offset; + public readonly Int32 Candidate = candidate; } - public static List FindOffsets(byte[] buffer, byte[][] candidates) + public static List FindOffsets(Byte[] buffer, Byte[][] candidates) { // We don't have enough candidates to even look - if (candidates.Length < MinUniqueInWindow) return new List(); + if (candidates.Length < MinUniqueInWindow) return new List(); var end = buffer.Length - Spectrum.FontSize; - var ranges = new Dictionary(); + var ranges = new Dictionary(); // This is our rolling window of candidates - we have one for each 'skew' as a matched glyph is // only valid on the 8 byte boundary @@ -85,7 +85,7 @@ public static List FindOffsets(byte[] buffer, byte[][] candidates) } // Okay, we now have a list of ranges and a count of the uniques they contain - var offsets = new List(); + var offsets = new List(); if (ranges.Count < 25) offsets.AddRange(ranges.Keys); return offsets.ToList(); diff --git a/Common/OffsetFinders/EnvironmentGuidedFinder.cs b/Common/OffsetFinders/EnvironmentGuidedFinder.cs index a0b4009..4c38680 100644 --- a/Common/OffsetFinders/EnvironmentGuidedFinder.cs +++ b/Common/OffsetFinders/EnvironmentGuidedFinder.cs @@ -1,17 +1,18 @@ -using PixelWorld.Machines; +using System; +using PixelWorld.Machines; using System.Collections.Generic; namespace PixelWorld.OffsetFinders; public static class EnvironmentGuidedFinder { - private const int CharsEnvVar = 23606; + private const Int32 CharsEnvVar = 23606; - public static List FindOffsets(byte[] buffer) + public static List FindOffsets(Byte[] buffer) { var spectrumSysChars = buffer[CharsEnvVar] + buffer[CharsEnvVar + 1] * 256 + 256; - var results = new List(); + var results = new List(); if (spectrumSysChars <= 16384) return results; // Was not pointing to the ROM if (spectrumSysChars + Spectrum.FontSize < buffer.Length && buffer.IsEmpty(spectrumSysChars)) diff --git a/Common/OffsetFinders/GeneralHeuristicFinder.cs b/Common/OffsetFinders/GeneralHeuristicFinder.cs index 8fabcc2..58b8a80 100644 --- a/Common/OffsetFinders/GeneralHeuristicFinder.cs +++ b/Common/OffsetFinders/GeneralHeuristicFinder.cs @@ -1,4 +1,5 @@ -using PixelWorld.Machines; +using System; +using PixelWorld.Machines; using System.Collections.Generic; using System.Linq; @@ -6,7 +7,7 @@ namespace PixelWorld.OffsetFinders; public static class GeneralHeuristicFinder { - private static bool HasLikelySymbolDensities(byte[] buffer, int offset) + private static Boolean HasLikelySymbolDensities(Byte[] buffer, Int32 offset) { return buffer.PixelCount(offset, '.') < buffer.PixelCount(offset, ':') && @@ -14,14 +15,14 @@ private static bool HasLikelySymbolDensities(byte[] buffer, int offset) buffer.PixelCount(offset, '-') < buffer.PixelCount(offset, '+'); } - private static bool HasLikelyUpperDensities(byte[] buffer, int offset) + private static Boolean HasLikelyUpperDensities(Byte[] buffer, Int32 offset) { return buffer.PixelCount(offset, 'D') < buffer.PixelCount(offset, 'B') && buffer.PixelCount(offset, 'C') < buffer.PixelCount(offset, 'O'); } - private static bool HasLikelyLowerDensities(byte[] buffer, int offset) + private static Boolean HasLikelyLowerDensities(Byte[] buffer, Int32 offset) { return buffer.PixelCount(offset, 'o') < buffer.PixelCount(offset, 'g') && @@ -29,16 +30,16 @@ private static bool HasLikelyLowerDensities(byte[] buffer, int offset) buffer.PixelCount(offset, 'j') < buffer.PixelCount(offset, 'u'); } - private static bool HasLikelyNumericDensities(byte[] buffer, int offset) + private static Boolean HasLikelyNumericDensities(Byte[] buffer, Int32 offset) { return buffer.PixelCount(offset, '1') < buffer.PixelCount(offset, '2') && buffer.PixelCount(offset, '3') < buffer.PixelCount(offset, '8'); } - public static List FindOffsets(byte[] buffer) + public static List FindOffsets(Byte[] buffer) { - var offsets = new List(); + var offsets = new List(); var end = buffer.Length - Spectrum.FontSize; @@ -51,17 +52,17 @@ public static List FindOffsets(byte[] buffer) return offsets; } - private static bool IsUnderscore(byte[] buffer, int i) + private static Boolean IsUnderscore(Byte[] buffer, Int32 i) { return buffer.IsEmpty(i, 5) && !buffer.IsEmpty(i + 5, 3); } - private static bool IsMinus(byte[] buffer, int i) + private static Boolean IsMinus(Byte[] buffer, Int32 i) { return buffer.IsEmpty(i, 2) && !buffer.IsEmpty(i + 2, 4) && buffer.IsEmpty(i + 6, 2); } - private static bool IsLikelyFont(byte[] buffer, int i) + private static Boolean IsLikelyFont(Byte[] buffer, Int32 i) { if (buffer.IsEmpty(i)) // Start with a space { @@ -121,7 +122,7 @@ private static bool IsLikelyFont(byte[] buffer, int i) return false; } - private static int SkewChecks(byte[] buffer, int offset) + private static Int32 SkewChecks(Byte[] buffer, Int32 offset) { var looksUnskewed = 0; if (buffer[offset + 94 * 8 + 7] == 0) diff --git a/Common/OffsetFinders/KnownCharPatternFinder.cs b/Common/OffsetFinders/KnownCharPatternFinder.cs index c63e2b7..5084e52 100644 --- a/Common/OffsetFinders/KnownCharPatternFinder.cs +++ b/Common/OffsetFinders/KnownCharPatternFinder.cs @@ -1,19 +1,20 @@ -using PixelWorld.Machines; +using System; +using PixelWorld.Machines; using System.Collections.Generic; namespace PixelWorld.OffsetFinders; -public class KnownCharPattern(int charCode, byte[] pattern) +public class KnownCharPattern(Int32 charCode, Byte[] pattern) { - public readonly int CharCode = charCode; - public readonly byte[] Pattern = pattern; + public readonly Int32 CharCode = charCode; + public readonly Byte[] Pattern = pattern; } public static class KnownCharPatternFinder { - public static List FindOffsets(byte[] buffer, KnownCharPattern[] knownFont) + public static List FindOffsets(Byte[] buffer, KnownCharPattern[] knownFont) { - var offsets = new HashSet(); + var offsets = new HashSet(); var end = buffer.Length - Spectrum.FontSize; diff --git a/Common/Out.cs b/Common/Out.cs index 1e9650c..8669b5c 100644 --- a/Common/Out.cs +++ b/Common/Out.cs @@ -5,14 +5,14 @@ namespace PixelWorld; public static class Out { - private static readonly List> logTargets = []; + private static readonly List> logTargets = []; - public static void Write(string output) { + public static void Write(String output) { foreach (var logTarget in logTargets) logTarget(output); } - public static void Attach(Action logTarget) { + public static void Attach(Action logTarget) { logTargets.Add(logTarget); } } \ No newline at end of file diff --git a/Common/Tools/ConvertTo.cs b/Common/Tools/ConvertTo.cs index 2f75974..7c7b407 100644 --- a/Common/Tools/ConvertTo.cs +++ b/Common/Tools/ConvertTo.cs @@ -1,22 +1,16 @@ using PixelWorld.Fonts; using PixelWorld.Formatters; -using PixelWorld.Machines; -using PixelWorld.Transformers; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Text.Json; -using SixLabors.ImageSharp; -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Formats.Png; namespace PixelWorld.Tools; public static class ConvertTo { - public static void Ufo(List fileNames, IReadOnlyDictionary sourceCharset, string outputFolder) + public static void Ufo(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder) { foreach (var sourceFileName in fileNames) { @@ -27,8 +21,8 @@ public static void Ufo(List fileNames, IReadOnlyDictionary so } } - public static void Atari8(List fileNames, IReadOnlyDictionary sourceCharset, string outputFolder, - string templatePath) + public static void Atari8(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder, + String templatePath) { var templateFilename = Path.Combine(templatePath, "atari8.fnt"); Out.Write($"Using template {templateFilename}"); @@ -40,12 +34,70 @@ public static void Atari8(List fileNames, IReadOnlyDictionary Out.Write($"Converting file {sourceFileName} to {targetFileName}"); var sourceFont = ByteFontFormatter.Load(sourceFileName, sourceCharset); using var target = File.Create(targetFileName); - ByteFontFormatter.Write(sourceFont, target, Machines.Atari8.US, 128, i => new ArraySegment(template, i, 8)); + ByteFontFormatter.Write(sourceFont, target, Machines.Atari8.US, 128, i => new ArraySegment(template, i, 8)); } } - public static void Fzx(List fileNames, IReadOnlyDictionary charset, bool makeProportional, - string outputFolder) + public static void CoCoVGA(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder, + String templatePath) + { + var templateFilename = Path.Combine(templatePath, "cocovga.chr"); + Out.Write($"Using template {templateFilename}"); + var buffer = File.ReadAllBytes(templateFilename); + if (buffer.Length != 3082) throw new Exception($"Template file {templateFilename} is not 3082 bytes"); + + // Create an array of a-z + var lower = @"£abcdefghijklmnopqrstuvwxyz{|}~©".ToCharArray(); + var upper = @"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_".ToCharArray(); + var symbols = " !\"#$%&'()*+,-./0123456789:;<=>?".ToCharArray(); + + foreach (var sourceFileName in fileNames) + { + var targetFileName = Utils.MakeFileName(sourceFileName, "chr", outputFolder); + Out.Write($"Converting file {sourceFileName} to {targetFileName}"); + var sourceFont = ByteFontFormatter.Load(sourceFileName, sourceCharset); + + using var target = File.Create(targetFileName); + var index = 0; + + WriteGlyphs(lower, false); + WriteGlyphs(symbols, true); + WriteGlyphs(upper, false); + WriteGlyphs(symbols, false); + + target.Write(buffer); + + void WriteGlyphs(Char[] chars, bool inverted) + { + foreach (var c in chars) + { + var glyph = sourceFont.Glyphs[c]; + var charOffset = 5 + index * 12; + + for (var y = 0; y < 8; y++) + { + Byte rowData = 0; + for (var x = 0; x < 8; x++) + { + if (glyph.Data[x, y]) + { + rowData |= (Byte)(1 << (7 - x)); + } + } + + if (inverted) rowData = (Byte)~rowData; + // +2 for vertical centering + buffer[charOffset + 2 + y] = rowData; + } + + index++; + } + } + } + } + + public static void Fzx(List fileNames, IReadOnlyDictionary charset, Boolean makeProportional, + String outputFolder) { foreach (var fileName in fileNames) { @@ -56,8 +108,8 @@ public static void Fzx(List fileNames, IReadOnlyDictionary ch } } - public static void AmstradCpc(List fileNames, IReadOnlyDictionary sourceCharset, string outputFolder, - string credit, int startLine) + public static void AmstradCpc(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder, + String credit, Int32 startLine) { foreach (var sourceFileName in fileNames) { @@ -71,7 +123,7 @@ public static void AmstradCpc(List fileNames, IReadOnlyDictionary fileNames, IReadOnlyDictionary fileNames, IReadOnlyDictionary sourceCharset, string outputFolder, - string templatePath) + public static void Msx(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder, + String templatePath) { var templateFilename = Path.Combine(templatePath, "msx.fnt"); Out.Write($"Using template {templateFilename}"); @@ -132,12 +184,12 @@ public static void Msx(List fileNames, IReadOnlyDictionary so using var target = File.Create(targetFileName); target.Write(template, 0, 32 * 8); // Low-ASCII ByteFontFormatter.Write(sourceFont, target, Machines.Msx.International, 224, - i => new ArraySegment(template, i, 8)); + i => new ArraySegment(template, i, 8)); } } - public static void Commodore64(List fileNames, IReadOnlyDictionary sourceCharset, string outputFolder, - string templatePath) + public static void Commodore64(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder, + String templatePath) { var bothCaseTemplate = Path.Combine(templatePath, "c64-both.ch8"); var upperCaseTemplate = Path.Combine(templatePath, "c64-upper.ch8"); @@ -169,10 +221,10 @@ public static void Commodore64(List fileNames, IReadOnlyDictionary new ArraySegment(template, i, 8)); + ByteFontFormatter.Write(sourceFont, memoryStream, charset, 128, i => new ArraySegment(template, i, 8)); using var targetFile = File.Create(targetFileName); - targetFile.Write(new byte[] { 0x00, 0x38 }); // 64C header + targetFile.Write("\08"u8); // 64C header memoryStream.WriteTo(targetFile); memoryStream.WriteTo(characterRom); diff --git a/Common/Tools/ConvertToGameBoy.cs b/Common/Tools/ConvertToGameBoy.cs index 9a5f48d..1fdc101 100644 --- a/Common/Tools/ConvertToGameBoy.cs +++ b/Common/Tools/ConvertToGameBoy.cs @@ -15,7 +15,7 @@ public static class ConvertToGameBoy { private static readonly PngEncoder gbPngEncoder = new() {ColorType = PngColorType.Palette}; - public static void GbStudio(List fileNames, IReadOnlyDictionary sourceCharset, string outputFolder, bool dark, bool proportional) + public static void GbStudio(List fileNames, IReadOnlyDictionary sourceCharset, String outputFolder, Boolean dark, Boolean proportional) { foreach (var fileName in fileNames) { @@ -54,7 +54,7 @@ public static void GbStudio(List fileNames, IReadOnlyDictionary fileNames, string outputFolder) + public static void Dump(List fileNames, String outputFolder) { Out.Write($"\nDumping {fileNames.Count} files"); @@ -20,7 +20,7 @@ public static void Dump(List fileNames, string outputFolder) } } - public static void ProcessStream(string fileName, Stream stream, Func, bool> processor, bool processUnknown = false) + public static void ProcessStream(String fileName, Stream stream, Func, Boolean> processor, Boolean processUnknown = false) { var extension = Path.GetExtension(fileName).ToLower(); switch (extension) @@ -59,7 +59,7 @@ public static void ProcessStream(string fileName, Stream stream, Func dump, string outputFolder) + public static Boolean WriteDumpToDisk(String fileName, ArraySegment dump, String outputFolder) { if (dump.Array is null) throw new ArgumentOutOfRangeException(nameof(dump), "Array is null"); diff --git a/Common/Tools/FontHunter.cs b/Common/Tools/FontHunter.cs index 75288b1..fa0389c 100644 --- a/Common/Tools/FontHunter.cs +++ b/Common/Tools/FontHunter.cs @@ -9,7 +9,7 @@ namespace PixelWorld.Tools; public static class FontHunter { - public static void Hunt(List fileNames, string outputFolder) + public static void Hunt(List fileNames, String outputFolder) { var inputsWithOutputsCount = 0; var outputCount = 0; @@ -29,16 +29,16 @@ public static void Hunt(List fileNames, string outputFolder) } Out.Write($"{inputsWithOutputsCount} files yielded {outputCount} results"); - Out.Write($"{Math.Floor((double)inputsWithOutputsCount / inputCount * 100)}% success rate"); + Out.Write($"{Math.Floor((Double)inputsWithOutputsCount / inputCount * 100)}% success rate"); } - private static int ExtractFontFromDumpFile(string fileName, string outputFolder) + private static Int32 ExtractFontFromDumpFile(String fileName, String outputFolder) { using var source = File.OpenRead(fileName); - return ExtractFontFromMemoryBuffer(fileName, new ArraySegment(source.ReadAllBytes()), outputFolder); + return ExtractFontFromMemoryBuffer(fileName, new ArraySegment(source.ReadAllBytes()), outputFolder); } - private static int ExtractFontFromMemoryBuffer(string fileName, ArraySegment dump, string outputFolder) + private static Int32 ExtractFontFromMemoryBuffer(String fileName, ArraySegment dump, String outputFolder) { if (dump.Array is null) throw new ArgumentOutOfRangeException(nameof(dump), "Array is null"); diff --git a/Common/Tools/Matcher.cs b/Common/Tools/Matcher.cs index b9e959a..52658ff 100644 --- a/Common/Tools/Matcher.cs +++ b/Common/Tools/Matcher.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using PixelWorld.Formatters; using PixelWorld.Machines; @@ -7,7 +8,7 @@ namespace PixelWorld.Tools; public static class Matcher { - public static void Match(List fileNames, string matchFile, string matchGlyphs) + public static void Match(List fileNames, String matchFile, String matchGlyphs) { Out.Write($"Reading match file {matchFile}"); using var matchReader = new BinaryReader(File.OpenRead(matchFile)); diff --git a/Common/Tools/TileExtractor.cs b/Common/Tools/TileExtractor.cs index a0f1eb2..b3d3305 100644 --- a/Common/Tools/TileExtractor.cs +++ b/Common/Tools/TileExtractor.cs @@ -7,7 +7,7 @@ namespace PixelWorld.Tools; public class TileExtractor { - public static void Extract(List fileNames, string outputFolder, int minTiles, int maxTiles) + public static void Extract(List fileNames, String outputFolder, Int32 minTiles, Int32 maxTiles) { var inputsWithOutputsCount = 0; var outputCount = 0; @@ -43,6 +43,6 @@ public static void Extract(List fileNames, string outputFolder, int minT } Out.Write($"{inputsWithOutputsCount} files yielded {outputCount} tiles"); - Out.Write($"{Math.Floor((double)inputsWithOutputsCount / inputCount * 100)}% success rate"); + Out.Write($"{Math.Floor((Double)inputsWithOutputsCount / inputCount * 100)}% success rate"); } } \ No newline at end of file diff --git a/Common/Transformers/FontSpacer.cs b/Common/Transformers/FontSpacer.cs index ccd9188..234adb4 100644 --- a/Common/Transformers/FontSpacer.cs +++ b/Common/Transformers/FontSpacer.cs @@ -1,11 +1,12 @@ -using PixelWorld.Fonts; +using System; +using PixelWorld.Fonts; using System.Linq; namespace PixelWorld.Transformers; public static class FontSpacer { - public static Font MakeProportional(Font source, int leftPad, int rightPad, int maxWidth) + public static Font MakeProportional(Font source, Int32 leftPad, Int32 rightPad, Int32 maxWidth) { var target = source.Copy(); var allKeys = target.Glyphs.Keys.ToList(); @@ -14,7 +15,7 @@ public static Font MakeProportional(Font source, int leftPad, int rightPad, int target.Glyphs[key] = GlyphSpacer.Proportional(target.Glyphs[key], leftPad, rightPad, maxWidth); var spaceWidth = target.Glyphs['{'].Width - leftPad - rightPad; - target.Glyphs[' '] = new Glyph(spaceWidth, source.Height, new bool[spaceWidth, source.Height]); + target.Glyphs[' '] = new Glyph(spaceWidth, source.Height, new Boolean[spaceWidth, source.Height]); return target; } diff --git a/Common/Transformers/GlyphInverter.cs b/Common/Transformers/GlyphInverter.cs index 0888f87..e2f6558 100644 --- a/Common/Transformers/GlyphInverter.cs +++ b/Common/Transformers/GlyphInverter.cs @@ -1,4 +1,5 @@ -using PixelWorld.Fonts; +using System; +using PixelWorld.Fonts; namespace PixelWorld.Transformers; @@ -9,9 +10,9 @@ public static Glyph Invert(Glyph source) return new Glyph(source.Width, source.Height, Invert(source.Data)); } - public static bool[,] Invert(bool[,] source) + public static Boolean[,] Invert(Boolean[,] source) { - var target = new bool[source.Length, source.GetUpperBound(1)]; + var target = new Boolean[source.Length, source.GetUpperBound(1)]; for (var x = 0; x < source.Length; x++) for (var y = 0; y < source.GetUpperBound(1); y++) diff --git a/Common/Transformers/GlyphShifter.cs b/Common/Transformers/GlyphShifter.cs index 9a9311c..af07614 100644 --- a/Common/Transformers/GlyphShifter.cs +++ b/Common/Transformers/GlyphShifter.cs @@ -1,15 +1,16 @@ -using PixelWorld.Fonts; +using System; +using PixelWorld.Fonts; namespace PixelWorld.Transformers; public static class GlyphShifter { - public static Glyph Shift(Glyph source, int horizontal, int vertical, bool wrap, int? newWidth = null, int? newHeight = null) + public static Glyph Shift(Glyph source, Int32 horizontal, Int32 vertical, Boolean wrap, Int32? newWidth = null, Int32? newHeight = null) { var width = newWidth ?? source.Width; var height = newHeight ?? source.Height; - var data = new bool[width, height]; + var data = new Boolean[width, height]; for (var y = 0; y < source.Height; y++) { diff --git a/Common/Transformers/GlyphSpacer.cs b/Common/Transformers/GlyphSpacer.cs index 6bab80f..c5f94e2 100644 --- a/Common/Transformers/GlyphSpacer.cs +++ b/Common/Transformers/GlyphSpacer.cs @@ -1,10 +1,11 @@ -using PixelWorld.Fonts; +using System; +using PixelWorld.Fonts; namespace PixelWorld.Transformers; public static class GlyphSpacer { - public static Glyph Proportional(Glyph source, int leftPad = 0, int rightPad = 0, int maxWidth = 8) + public static Glyph Proportional(Glyph source, Int32 leftPad = 0, Int32 rightPad = 0, Int32 maxWidth = 8) { var (right, left) = CountLeftAndRightBlankColumns(source); var actualWidth = source.Width - right - left; @@ -14,7 +15,7 @@ public static Glyph Proportional(Glyph source, int leftPad = 0, int rightPad = 0 return GlyphShifter.Shift(source, 0 - right + leftPad, 0, false, newWidth); } - private static (int right, int left) CountLeftAndRightBlankColumns(Glyph glyph) + private static (Int32 right, Int32 left) CountLeftAndRightBlankColumns(Glyph glyph) { var rightSpace = 0; var rightIndex = 0; diff --git a/Common/Utils.cs b/Common/Utils.cs index 11b1730..8051b30 100644 --- a/Common/Utils.cs +++ b/Common/Utils.cs @@ -9,7 +9,7 @@ namespace PixelWorld; public static class Utils { - public static List MatchGlobWithFiles(string inputPattern) + public static List MatchGlobWithFiles(String inputPattern) { var splitPoint = GetGlobSplitPoint(inputPattern); var pattern = inputPattern[splitPoint..]; @@ -23,25 +23,25 @@ public static List MatchGlobWithFiles(string inputPattern) return matchResults.Files.Select(f => Path.Combine(directory, f.Path)).ToList(); } - public static byte[] ReadAllBytes(this Stream stream) + public static Byte[] ReadAllBytes(this Stream stream) { var memory = new MemoryStream(); stream.CopyTo(memory); return memory.GetBuffer(); } - public static string MakeFileName(string fileName, string extension, string folder) + public static String MakeFileName(String fileName, String extension, String folder) { return Path.Combine(folder, Path.ChangeExtension(Path.GetFileName(fileName), extension)); } - public static int GetGlobSplitPoint(string pathGlob) + public static Int32 GetGlobSplitPoint(String pathGlob) { var doubleStar = pathGlob.IndexOf("**", StringComparison.Ordinal); return doubleStar > -1 ? doubleStar : pathGlob.LastIndexOf('\\') + 1; } - public static Dictionary ToIndexedDictionary(this string sequence) + public static Dictionary ToIndexedDictionary(this String sequence) { return sequence .Select((c, i) => Tuple.Create(c, i)) diff --git a/Directory.Build.props b/Directory.Build.props index 483aa3b..b080c35 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@  - 0.5.0 + 0.5.1 $(Version) $(Version) $(Version) diff --git a/README.md b/README.md index 1128b4e..498a203 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ It also contains bulk-ripping `dump` and `hunt` commands for obtaining ZX Spectr ## Commands -### Ripping +### Extraction - `dump` to RAM-dump snapshot files (currently supports `.z80` and `.sna` and recurses through `.zip` archives) - `hunt` to look through RAM dumps for possible bitmap fonts (currently supports only ZX Spectrum fonts) - `screenshot` to create a screenshots from RAM-dumps or snapshot files (in PNG, SCR or animated GIF format) - `extracttiles` to create a files with unique 8x8 character tiles found on the screen in RAM-dumps or snapshot files -### Conversions +### Conversion The following commands work with ZX Spectrum RAW 768 byte/.ch8 files: @@ -23,27 +23,35 @@ The following commands work with ZX Spectrum RAW 768 byte/.ch8 files: - `pngtozx` to convert a `.png` back to a ZX Spectrum `.ch8` - `c64tozx` to create a ZX Spectrum `.ch8` file from a C64 binary file -Any of the following assembly generating commands can use the `--base hex|decimal` flags. The z80 one can also use `--base binary`. +You can also generate directly-usable files (all binary except the CPC) + +- `zxtoa8` to create a `.fnt` binary version for the Atari 8-bit series +- `zxtoc64` to create `.c64` and `.bin` binary ROM versions for the Commodore 64 +- `zxtoccv` to create a `.chr` binary version for the CoCoVGA adapter +- `zxtocpc` to create a `.bas` BASIC file for use with the Amstrad CPC range +- `zxtofzx` to create a fixed-width `.fzx` font for the FZX renderer +- `zxtofzx --proportional` to create a proportional `.fzx` by auto left aligning and measuring widths +- `zxtogbs` to create a `.gbs` binary version for GameBoy Studio +- `zxtomsx` to create a `.msx` binary version for the MSX range +- `zxtoufo` to create a `.ufo` UFO font file for various tools and editors + +### Source generation + +You can convert ZX Spectrum RAW 768 byte/.ch8 files to a variety of assembly and header file formats. + +The following assembly generating commands can use the `--base hex|decimal` flags. The z80 one can also use `--base binary`. -- `z80asm` to create Zilog Z80 assembler source with `defb` hex -- `x86asm` to create Intel 8086 assembler source with `db` hex - `6502asm` to create MOS 6502 assembler source with `.byte` hex - `68000asm` to create Motorola 68000 assembler source with `DB.B` hex +- `x86asm` to create Intel 8086 assembler source with `db` hex +- `z80asm` to create Zilog Z80 assembler source with `defb` hex And the header-generating commands: - `chead` to generate C-compatible header files - `rusthead` to generate Rust-compatible header files -You can also generate directly-usable files (all binary except the CPC) - -- `zxtofzx` to create a fixed-width `.fzx` -- `zxtofzx --proportional` to create a proportional `.fzx` by auto left aligning and measuring widths -- `zxtocbm` to create `.c64` and `.bin` binary ROM versions for the Commodore 64 -- `zxtoa8` to create a `.fnt` binary version for the Atari 8-bit series -- `zxtocpc` to create a `.bas` BASIC file for use with the Amstrad CPC range - -### Comparisons +### Comparison - `findmatches` to find glyphs from a source font in as many possible target .ch8 files @@ -80,6 +88,7 @@ Some [template files are necessary for the conversions](https://github.com/damie - `atari8.fnt` - A dump of the Atari system font that includes all the symbols characters etc. - `c64-both.c64` - A dump of the Commodore 64 upper+lower case - `c64-upper.c64` - A dump of the Commodore 64 upper case + symbols +- `cocovga.chr` - A dump of the CoCoVGa font (3082 bytes) ## Example usage