diff --git a/M6502/Disassembler.cs b/M6502/Disassembler.cs index 95416f1..e04b090 100644 --- a/M6502/Disassembler.cs +++ b/M6502/Disassembler.cs @@ -6,20 +6,13 @@ namespace EightBit { using System.Text; - public class Disassembler + public class Disassembler(Bus bus, M6502 processor, Symbols symbols) { - private readonly Bus bus; - private readonly M6502 processor; - private readonly Symbols symbols; + private readonly Bus bus = bus; + private readonly M6502 processor = processor; + private readonly Symbols symbols = symbols; private ushort address; - public Disassembler(Bus bus, M6502 processor, Symbols symbols) - { - this.bus = bus; - this.processor = processor; - this.symbols = symbols; - } - public static string DumpFlags(byte value) { var returned = new StringBuilder(); @@ -47,7 +40,7 @@ namespace EightBit var cell = this.bus.Peek(current); output.Append(DumpByteValue(cell)); - output.Append(" "); + output.Append(' '); var next = this.bus.Peek((ushort)(current + 1)); var relative = (ushort)(this.processor.PC.Word + 2 + (sbyte)next); diff --git a/M6502/M6502.cs b/M6502/M6502.cs index a9a22f4..4f10a43 100644 --- a/M6502/M6502.cs +++ b/M6502/M6502.cs @@ -6,13 +6,13 @@ namespace EightBit { using System; - public class M6502 : LittleEndianProcessor + public class M6502(Bus bus) : LittleEndianProcessor(bus) { private const byte IRQvector = 0xfe; // IRQ vector private const byte RSTvector = 0xfc; // RST vector private const byte NMIvector = 0xfa; // NMI vector - private readonly Register16 intermediate = new Register16(); + private readonly Register16 intermediate = new(); private byte crossedPage; private bool handlingRESET = false; @@ -25,54 +25,49 @@ namespace EightBit private PinLevel rdyLine = PinLevel.Low; private PinLevel rwLine = PinLevel.Low; - public M6502(Bus bus) - : base(bus) - { - } + public event EventHandler? ExecutingInstruction; - public event EventHandler ExecutingInstruction; + public event EventHandler? ExecutedInstruction; - public event EventHandler ExecutedInstruction; + public event EventHandler? RaisingNMI; - public event EventHandler RaisingNMI; + public event EventHandler? RaisedNMI; - public event EventHandler RaisedNMI; + public event EventHandler? LoweringNMI; - public event EventHandler LoweringNMI; + public event EventHandler? LoweredNMI; - public event EventHandler LoweredNMI; + public event EventHandler? RaisingSO; - public event EventHandler RaisingSO; + public event EventHandler? RaisedSO; - public event EventHandler RaisedSO; + public event EventHandler? LoweringSO; - public event EventHandler LoweringSO; + public event EventHandler? LoweredSO; - public event EventHandler LoweredSO; + public event EventHandler? RaisingSYNC; - public event EventHandler RaisingSYNC; + public event EventHandler? RaisedSYNC; - public event EventHandler RaisedSYNC; + public event EventHandler? LoweringSYNC; - public event EventHandler LoweringSYNC; + public event EventHandler? LoweredSYNC; - public event EventHandler LoweredSYNC; + public event EventHandler? RaisingRDY; - public event EventHandler RaisingRDY; + public event EventHandler? RaisedRDY; - public event EventHandler RaisedRDY; + public event EventHandler? LoweringRDY; - public event EventHandler LoweringRDY; + public event EventHandler? LoweredRDY; - public event EventHandler LoweredRDY; + public event EventHandler? RaisingRW; - public event EventHandler RaisingRW; + public event EventHandler? RaisedRW; - public event EventHandler RaisedRW; + public event EventHandler? LoweringRW; - public event EventHandler LoweringRW; - - public event EventHandler LoweredRW; + public event EventHandler? LoweredRW; public ref PinLevel NMI => ref this.nmiLine; diff --git a/M6502/Symbols.cs b/M6502/Symbols.cs index 6164970..f49f481 100644 --- a/M6502/Symbols.cs +++ b/M6502/Symbols.cs @@ -10,7 +10,7 @@ namespace EightBit public class Symbols { - private readonly Dictionary>> parsed; + private readonly Dictionary>> parsed = []; public Symbols() : this(string.Empty) @@ -19,12 +19,6 @@ namespace EightBit public Symbols(string path) { - this.Labels = new Dictionary(); - this.Constants = new Dictionary(); - this.Scopes = new Dictionary(); - this.Addresses = new Dictionary(); - this.parsed = new Dictionary>>(); - if (path.Length > 0) { this.Parse(path); @@ -33,13 +27,13 @@ namespace EightBit } } - public Dictionary Labels { get; } + public Dictionary Labels { get; } = []; - public Dictionary Constants { get; } + public Dictionary Constants { get; } = []; - public Dictionary Scopes { get; } + public Dictionary Scopes { get; } = []; - public Dictionary Addresses { get; } + public Dictionary Addresses { get; } = []; private void AssignScopes() { @@ -48,7 +42,7 @@ namespace EightBit { var parsedScope = parsedScopeElement.Value; var name = parsedScope["name"]; - var trimmedName = name.Substring(1, name.Length - 2); + var trimmedName = name[1..^1]; var size = parsedScope["size"]; this.Scopes[trimmedName] = ushort.Parse(size); } @@ -61,8 +55,8 @@ namespace EightBit { var symbol = symbolElement.Value; var name = symbol["name"]; - var trimmedName = name.Substring(1, name.Length - 2); - var value = symbol["val"].Substring(2); + var trimmedName = name[1..^1]; + var value = symbol["val"][2..]; var number = Convert.ToUInt16(value, 16); var symbolType = symbol["type"]; if (symbolType == "lab") @@ -79,37 +73,37 @@ namespace EightBit private void Parse(string path) { - using (var reader = new StreamReader(path)) + using var reader = new StreamReader(path); + while (!reader.EndOfStream) { - while (!reader.EndOfStream) + var line = reader.ReadLine(); + if (line == null) + break; + var lineElements = line.Split(' ', '\t'); + if (lineElements.Length == 2) { - var line = reader.ReadLine(); - var lineElements = line.Split(' ', '\t'); - if (lineElements.Length == 2) + var type = lineElements[0]; + var dataElements = lineElements[1].Split(','); + var data = new Dictionary(); + foreach (var dataElement in dataElements) { - var type = lineElements[0]; - var dataElements = lineElements[1].Split(','); - var data = new Dictionary(); - foreach (var dataElement in dataElements) + var definition = dataElement.Split('='); + if (definition.Length == 2) { - var definition = dataElement.Split('='); - if (definition.Length == 2) - { - data[definition[0]] = definition[1]; - } + data[definition[0]] = definition[1]; + } + } + + if (data.ContainsKey("id")) + { + if (!this.parsed.ContainsKey(type)) + { + this.parsed[type] = new Dictionary>(); } - if (data.ContainsKey("id")) - { - if (!this.parsed.ContainsKey(type)) - { - this.parsed[type] = new Dictionary>(); - } - - var id = data["id"]; - data.Remove("id"); - this.parsed[type][id] = data; - } + var id = data["id"]; + data.Remove("id"); + this.parsed[type][id] = data; } } }