diff --git a/M6502/M6502.Symbols/IdentifiableSection.cs b/M6502/M6502.Symbols/IdentifiableSection.cs index 066cb71..9ce6bde 100644 --- a/M6502/M6502.Symbols/IdentifiableSection.cs +++ b/M6502/M6502.Symbols/IdentifiableSection.cs @@ -12,43 +12,25 @@ : base(container) { } - private bool MaybeExtractFromParsed(string key, out string value) + private bool MaybeExtractFromParsed(string key, out string? value) { Debug.Assert(this._parsed != null); var found = this._parsed.TryGetValue(key, out var extracted); - if (found) - { - Debug.Assert(extracted != null); - value = extracted; - } - else - { - value = string.Empty; - } + value = extracted; return found; } private bool MaybeExtractIntegerFromParsed(string key, out int value) { var available = this.MaybeExtractFromParsed(key, out var extracted); - if (!available) - { - value = 0; - return false; - } - value = ExtractInteger(extracted); + value = extracted == null ? 0 : ExtractInteger(extracted); return available; } protected bool MaybeExtractCompoundInteger(string key, out List value) { var available = this.MaybeExtractFromParsed(key, out var extracted); - if (!available) - { - value = []; - return false; - } - value = ExtractCompoundInteger(extracted); + value = extracted == null ? [] : ExtractCompoundInteger(extracted); return available; } diff --git a/M6502/M6502.Symbols/Information.cs b/M6502/M6502.Symbols/Information.cs index 05390bf..b9e7a18 100644 --- a/M6502/M6502.Symbols/Information.cs +++ b/M6502/M6502.Symbols/Information.cs @@ -4,34 +4,34 @@ [M6502.Symbols.Section("info")] public sealed class Information(Parser container) : Section(container) { - [M6502.Symbols.SectionProperty("csym")] + [SectionProperty("csym")] public int CSymbol { get; private set; } - [M6502.Symbols.SectionProperty("file")] + [SectionProperty("file")] public int File { get; private set; } - [M6502.Symbols.SectionProperty("lib")] + [SectionProperty("lib")] public int Library { get; private set; } - [M6502.Symbols.SectionProperty("line")] + [SectionProperty("line")] public int Line { get; private set; } - [M6502.Symbols.SectionProperty("mod")] + [SectionProperty("mod")] public int Module { get; private set; } - [M6502.Symbols.SectionProperty("scope")] + [SectionProperty("scope")] public int Scope { get; private set; } - [M6502.Symbols.SectionProperty("seg")] + [SectionProperty("seg")] public int Segment { get; private set; } - [M6502.Symbols.SectionProperty("span")] + [SectionProperty("span")] public int Span { get; private set; } - [M6502.Symbols.SectionProperty("sym")] + [SectionProperty("sym")] public int Symbol { get; private set; } - [M6502.Symbols.SectionProperty("type")] + [SectionProperty("type")] public int Type { get; private set; } public int Count(string key) => this.GetValueT(key); diff --git a/M6502/M6502.Symbols/Parser.cs b/M6502/M6502.Symbols/Parser.cs index a3bc620..5581b7c 100644 --- a/M6502/M6502.Symbols/Parser.cs +++ b/M6502/M6502.Symbols/Parser.cs @@ -282,7 +282,7 @@ private void VerifyInformationCount(string key, int actual) { Debug.Assert(this._information != null); - var expected = this._information?.Count(key); + var expected = this._information.Count(key); if (expected != actual) { throw new InvalidOperationException($"information count mismatch for {key}. Expected {expected}, actual {actual}"); @@ -316,7 +316,7 @@ } using var reader = new StreamReader(path); - await this.ParseAsync(reader); + await this.ParseAsync(reader).ConfigureAwait(false); this.ExtractSections(); this.ExtractReferences(); @@ -330,7 +330,7 @@ { while (!reader.EndOfStream) { - var line = await reader.ReadLineAsync(); + var line = await reader.ReadLineAsync().ConfigureAwait(false); if (line == null) { break; @@ -408,8 +408,8 @@ throw new InvalidOperationException("Version has not yet been parsed"); } - var major = this._version?.Major; - var minor = this._version?.Minor; + var major = this._version.Major; + var minor = this._version.Minor; var valid = major == 2 && minor == 0; if (!valid) { diff --git a/M6502/M6502.Symbols/ReflectedSectionProperties.cs b/M6502/M6502.Symbols/ReflectedSectionProperties.cs index 5173ee6..142e650 100644 --- a/M6502/M6502.Symbols/ReflectedSectionProperties.cs +++ b/M6502/M6502.Symbols/ReflectedSectionProperties.cs @@ -154,7 +154,7 @@ if (attribute is SectionReferenceAttribute) { this.ReferenceAttributes.Add(key, new Tuple(name, originalType)); - } else if (attribute is SectionReferencesAttribute referencesAttribute) + } else if (attribute is SectionReferencesAttribute) { this.ReferencesAttributes.Add(key, new Tuple(name, originalType)); } diff --git a/M6502/M6502.Symbols/SectionAttribute.cs b/M6502/M6502.Symbols/SectionAttribute.cs index 5877e8c..da9a703 100644 --- a/M6502/M6502.Symbols/SectionAttribute.cs +++ b/M6502/M6502.Symbols/SectionAttribute.cs @@ -1,7 +1,7 @@ namespace M6502.Symbols { [AttributeUsage(AttributeTargets.Class)] - internal class SectionAttribute(string key, string? referencing = null) : Attribute + internal sealed class SectionAttribute(string key, string? referencing = null) : Attribute { public string Key { get; private set; } = key; diff --git a/M6502/M6502.Test/Board.cs b/M6502/M6502.Test/Board.cs index 3d34e94..6113e31 100644 --- a/M6502/M6502.Test/Board.cs +++ b/M6502/M6502.Test/Board.cs @@ -27,7 +27,7 @@ namespace M6502.Test private bool keyHandled; private bool keyAvailable; - private bool inputting = false; + private bool inputting; public Board(Configuration configuration) { diff --git a/M6502/M6502.Test/TestHarness.cs b/M6502/M6502.Test/TestHarness.cs index 13df767..cbda837 100644 --- a/M6502/M6502.Test/TestHarness.cs +++ b/M6502/M6502.Test/TestHarness.cs @@ -7,22 +7,13 @@ namespace M6502.Test using System; using System.Diagnostics; - internal class TestHarness(Configuration configuration) : IDisposable + internal sealed class TestHarness(Configuration configuration) { - private readonly Process process = Process.GetCurrentProcess(); private readonly Stopwatch timer = new(); private readonly Board board = new(configuration); - private long totalCycles = 0; + private long totalCycles; private TimeSpan totalUserProcessorTime; - private bool disposed = false; - - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - public long ElapsedMilliseconds => this.timer.ElapsedMilliseconds; public float ElapsedSeconds => this.ElapsedMilliseconds / 1000.0f; @@ -31,40 +22,32 @@ namespace M6502.Test public void Run() { - this.timer.Start(); - var startingUsage = this.process.UserProcessorTime; - - this.board.Initialize(); - this.board.RaisePOWER(); - - var cpu = this.board.CPU; - while (cpu.Powered) + using var process = Process.GetCurrentProcess(); { - this.totalCycles += cpu.Step(); - } + this.timer.Start(); + var startingUsage = process.UserProcessorTime; - var finishingUsage = this.process.UserProcessorTime; - this.timer.Stop(); - this.totalUserProcessorTime = finishingUsage - startingUsage; - } + this.board.Initialize(); + this.board.RaisePOWER(); - protected virtual void Dispose(bool disposing) - { - if (!this.disposed) - { - if (disposing) + var cpu = this.board.CPU; + while (cpu.Powered) { - System.Console.Out.WriteLine(); - - System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles:N0}"); - System.Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}"); - - System.Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz"); - System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime.TotalSeconds:g}"); + this.totalCycles += cpu.Step(); } - this.disposed = true; + var finishingUsage = process.UserProcessorTime; + this.timer.Stop(); + this.totalUserProcessorTime = finishingUsage - startingUsage; } + + System.Console.Out.WriteLine(); + + System.Console.Out.WriteLine($"Guest cycles = {this.totalCycles:N0}"); + System.Console.Out.WriteLine($"Seconds = {this.ElapsedSeconds}"); + + System.Console.Out.WriteLine($"{this.CyclesPerSecond / 1000000} MHz"); + System.Console.Out.WriteLine($"Processor time = {this.totalUserProcessorTime.TotalSeconds:g}"); } } } diff --git a/Z80/Z80.Test/TestHarness.cs b/Z80/Z80.Test/TestHarness.cs index 7ef86ed..13b3d3f 100644 --- a/Z80/Z80.Test/TestHarness.cs +++ b/Z80/Z80.Test/TestHarness.cs @@ -7,20 +7,13 @@ namespace Z80.Test using System; using System.Diagnostics; - internal class TestHarness(Configuration configuration) : IDisposable + internal class TestHarness(Configuration configuration) { private readonly Stopwatch timer = new(); private readonly Board board = new(configuration); private long totalCycles; private TimeSpan totalUserProcessorTime; - private bool disposed; - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } public long ElapsedMilliseconds => timer.ElapsedMilliseconds; public float ElapsedSeconds => ElapsedMilliseconds / 1000.0f; @@ -47,25 +40,14 @@ namespace Z80.Test timer.Stop(); totalUserProcessorTime = finishingUsage - startingUsage; } - } - protected virtual void Dispose(bool disposing) - { - if (!disposed) - { - if (disposing) - { - System.Console.Out.WriteLine(); + System.Console.Out.WriteLine(); - System.Console.Out.WriteLine($"Guest cycles = {totalCycles:N0}"); - System.Console.Out.WriteLine($"Seconds = {ElapsedSeconds}"); + System.Console.Out.WriteLine($"Guest cycles = {totalCycles:N0}"); + System.Console.Out.WriteLine($"Seconds = {ElapsedSeconds}"); - System.Console.Out.WriteLine($"{CyclesPerSecond / 1000000} MHz"); - System.Console.Out.WriteLine($"Processor time = {totalUserProcessorTime.TotalSeconds:g}"); - } - - disposed = true; - } + System.Console.Out.WriteLine($"{CyclesPerSecond / 1000000} MHz"); + System.Console.Out.WriteLine($"Processor time = {totalUserProcessorTime.TotalSeconds:g}"); } } }