Use IDE suggested changes

This commit is contained in:
Adrian Conlon
2024-05-21 21:49:10 +01:00
parent bd1f7c285b
commit f4ea6a0b13
3 changed files with 62 additions and 80 deletions

View File

@@ -6,20 +6,13 @@ namespace EightBit
{ {
using System.Text; using System.Text;
public class Disassembler public class Disassembler(Bus bus, M6502 processor, Symbols symbols)
{ {
private readonly Bus bus; private readonly Bus bus = bus;
private readonly M6502 processor; private readonly M6502 processor = processor;
private readonly Symbols symbols; private readonly Symbols symbols = symbols;
private ushort address; 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) public static string DumpFlags(byte value)
{ {
var returned = new StringBuilder(); var returned = new StringBuilder();
@@ -47,7 +40,7 @@ namespace EightBit
var cell = this.bus.Peek(current); var cell = this.bus.Peek(current);
output.Append(DumpByteValue(cell)); output.Append(DumpByteValue(cell));
output.Append(" "); output.Append(' ');
var next = this.bus.Peek((ushort)(current + 1)); var next = this.bus.Peek((ushort)(current + 1));
var relative = (ushort)(this.processor.PC.Word + 2 + (sbyte)next); var relative = (ushort)(this.processor.PC.Word + 2 + (sbyte)next);

View File

@@ -6,13 +6,13 @@ namespace EightBit
{ {
using System; using System;
public class M6502 : LittleEndianProcessor public class M6502(Bus bus) : LittleEndianProcessor(bus)
{ {
private const byte IRQvector = 0xfe; // IRQ vector private const byte IRQvector = 0xfe; // IRQ vector
private const byte RSTvector = 0xfc; // RST vector private const byte RSTvector = 0xfc; // RST vector
private const byte NMIvector = 0xfa; // NMI vector private const byte NMIvector = 0xfa; // NMI vector
private readonly Register16 intermediate = new Register16(); private readonly Register16 intermediate = new();
private byte crossedPage; private byte crossedPage;
private bool handlingRESET = false; private bool handlingRESET = false;
@@ -25,54 +25,49 @@ namespace EightBit
private PinLevel rdyLine = PinLevel.Low; private PinLevel rdyLine = PinLevel.Low;
private PinLevel rwLine = PinLevel.Low; private PinLevel rwLine = PinLevel.Low;
public M6502(Bus bus) public event EventHandler<EventArgs>? ExecutingInstruction;
: base(bus)
{
}
public event EventHandler<EventArgs> ExecutingInstruction; public event EventHandler<EventArgs>? ExecutedInstruction;
public event EventHandler<EventArgs> ExecutedInstruction; public event EventHandler<EventArgs>? RaisingNMI;
public event EventHandler<EventArgs> RaisingNMI; public event EventHandler<EventArgs>? RaisedNMI;
public event EventHandler<EventArgs> RaisedNMI; public event EventHandler<EventArgs>? LoweringNMI;
public event EventHandler<EventArgs> LoweringNMI; public event EventHandler<EventArgs>? LoweredNMI;
public event EventHandler<EventArgs> LoweredNMI; public event EventHandler<EventArgs>? RaisingSO;
public event EventHandler<EventArgs> RaisingSO; public event EventHandler<EventArgs>? RaisedSO;
public event EventHandler<EventArgs> RaisedSO; public event EventHandler<EventArgs>? LoweringSO;
public event EventHandler<EventArgs> LoweringSO; public event EventHandler<EventArgs>? LoweredSO;
public event EventHandler<EventArgs> LoweredSO; public event EventHandler<EventArgs>? RaisingSYNC;
public event EventHandler<EventArgs> RaisingSYNC; public event EventHandler<EventArgs>? RaisedSYNC;
public event EventHandler<EventArgs> RaisedSYNC; public event EventHandler<EventArgs>? LoweringSYNC;
public event EventHandler<EventArgs> LoweringSYNC; public event EventHandler<EventArgs>? LoweredSYNC;
public event EventHandler<EventArgs> LoweredSYNC; public event EventHandler<EventArgs>? RaisingRDY;
public event EventHandler<EventArgs> RaisingRDY; public event EventHandler<EventArgs>? RaisedRDY;
public event EventHandler<EventArgs> RaisedRDY; public event EventHandler<EventArgs>? LoweringRDY;
public event EventHandler<EventArgs> LoweringRDY; public event EventHandler<EventArgs>? LoweredRDY;
public event EventHandler<EventArgs> LoweredRDY; public event EventHandler<EventArgs>? RaisingRW;
public event EventHandler<EventArgs> RaisingRW; public event EventHandler<EventArgs>? RaisedRW;
public event EventHandler<EventArgs> RaisedRW; public event EventHandler<EventArgs>? LoweringRW;
public event EventHandler<EventArgs> LoweringRW; public event EventHandler<EventArgs>? LoweredRW;
public event EventHandler<EventArgs> LoweredRW;
public ref PinLevel NMI => ref this.nmiLine; public ref PinLevel NMI => ref this.nmiLine;

View File

@@ -10,7 +10,7 @@ namespace EightBit
public class Symbols public class Symbols
{ {
private readonly Dictionary<string, Dictionary<string, Dictionary<string, string>>> parsed; private readonly Dictionary<string, Dictionary<string, Dictionary<string, string>>> parsed = [];
public Symbols() public Symbols()
: this(string.Empty) : this(string.Empty)
@@ -19,12 +19,6 @@ namespace EightBit
public Symbols(string path) public Symbols(string path)
{ {
this.Labels = new Dictionary<ushort, string>();
this.Constants = new Dictionary<ushort, string>();
this.Scopes = new Dictionary<string, ushort>();
this.Addresses = new Dictionary<string, ushort>();
this.parsed = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
if (path.Length > 0) if (path.Length > 0)
{ {
this.Parse(path); this.Parse(path);
@@ -33,13 +27,13 @@ namespace EightBit
} }
} }
public Dictionary<ushort, string> Labels { get; } public Dictionary<ushort, string> Labels { get; } = [];
public Dictionary<ushort, string> Constants { get; } public Dictionary<ushort, string> Constants { get; } = [];
public Dictionary<string, ushort> Scopes { get; } public Dictionary<string, ushort> Scopes { get; } = [];
public Dictionary<string, ushort> Addresses { get; } public Dictionary<string, ushort> Addresses { get; } = [];
private void AssignScopes() private void AssignScopes()
{ {
@@ -48,7 +42,7 @@ namespace EightBit
{ {
var parsedScope = parsedScopeElement.Value; var parsedScope = parsedScopeElement.Value;
var name = parsedScope["name"]; var name = parsedScope["name"];
var trimmedName = name.Substring(1, name.Length - 2); var trimmedName = name[1..^1];
var size = parsedScope["size"]; var size = parsedScope["size"];
this.Scopes[trimmedName] = ushort.Parse(size); this.Scopes[trimmedName] = ushort.Parse(size);
} }
@@ -61,8 +55,8 @@ namespace EightBit
{ {
var symbol = symbolElement.Value; var symbol = symbolElement.Value;
var name = symbol["name"]; var name = symbol["name"];
var trimmedName = name.Substring(1, name.Length - 2); var trimmedName = name[1..^1];
var value = symbol["val"].Substring(2); var value = symbol["val"][2..];
var number = Convert.ToUInt16(value, 16); var number = Convert.ToUInt16(value, 16);
var symbolType = symbol["type"]; var symbolType = symbol["type"];
if (symbolType == "lab") if (symbolType == "lab")
@@ -79,11 +73,12 @@ namespace EightBit
private void Parse(string path) 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(); var line = reader.ReadLine();
if (line == null)
break;
var lineElements = line.Split(' ', '\t'); var lineElements = line.Split(' ', '\t');
if (lineElements.Length == 2) if (lineElements.Length == 2)
{ {
@@ -115,4 +110,3 @@ namespace EightBit
} }
} }
} }
}