diff --git a/Fuse/Lines.cs b/Fuse/Lines.cs index fa2bf1b..cf77a3e 100644 --- a/Fuse/Lines.cs +++ b/Fuse/Lines.cs @@ -3,7 +3,6 @@ // namespace Fuse { - using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; diff --git a/Intel8080/Disassembler.cs b/Intel8080/Disassembler.cs index 541d292..b755148 100644 --- a/Intel8080/Disassembler.cs +++ b/Intel8080/Disassembler.cs @@ -2,9 +2,10 @@ // Copyright (c) Adrian Conlon. All rights reserved. // -namespace EightBit +namespace Intel8080 { - using System; + using EightBit; + using System.Globalization; public class Disassembler(Bus bus) { @@ -24,6 +25,8 @@ namespace EightBit public static string State(Intel8080 cpu) { + ArgumentNullException.ThrowIfNull(cpu); + var pc = cpu.PC.Word; var sp = cpu.SP.Word; @@ -47,7 +50,11 @@ namespace EightBit + $"H={h:x2} L={l:x2}"; } - public string Disassemble(Intel8080 cpu) => this.Disassemble(cpu, cpu.PC.Word); + public string Disassemble(Intel8080 cpu) + { + ArgumentNullException.ThrowIfNull(cpu); + return this.Disassemble(cpu, cpu.PC.Word); + } private static string CC(int flag) => flag switch { @@ -59,7 +66,7 @@ namespace EightBit 5 => "PE", 6 => "P", 7 => "M", - _ => throw new System.ArgumentOutOfRangeException(nameof(flag)), + _ => throw new ArgumentOutOfRangeException(nameof(flag)), }; private static string ALU(int which) => which switch @@ -72,7 +79,7 @@ namespace EightBit 5 => "XRA", // XOR n 6 => "ORA", // OR n 7 => "CMP", // CP n - _ => throw new System.ArgumentOutOfRangeException(nameof(which)), + _ => throw new ArgumentOutOfRangeException(nameof(which)), }; private static string ALU2(int which) => which switch @@ -85,7 +92,7 @@ namespace EightBit 5 => "XRI", // XOR n 6 => "ORI", // OR n 7 => "CPI", // CP n - _ => throw new System.ArgumentOutOfRangeException(nameof(which)), + _ => throw new ArgumentOutOfRangeException(nameof(which)), }; private static Tuple Disassemble(int x, int y, int z, int p, int q) @@ -124,6 +131,8 @@ namespace EightBit case 1: // ADD HL,rp specification = $"DAD {RP(p)}"; break; + default: + break; } break; @@ -147,6 +156,8 @@ namespace EightBit specification = "STA {1:X4}H"; dumpCount += 2; break; + default: + break; } break; @@ -167,8 +178,12 @@ namespace EightBit specification = "LDA {1:X4}H"; dumpCount += 2; break; + default: + break; } + break; + default: break; } @@ -182,6 +197,8 @@ namespace EightBit case 1: // DEC rp specification = $"DCX {RP(p)}"; break; + default: + break; } break; @@ -222,8 +239,12 @@ namespace EightBit case 7: specification = "CMC"; break; + default: + break; } + break; + default: break; } @@ -260,8 +281,12 @@ namespace EightBit case 3: // LD SP,HL specification = "SPHL"; break; + default: + break; } + break; + default: break; } @@ -299,6 +324,8 @@ namespace EightBit case 7: // EI specification = "EI"; break; + default: + break; } break; @@ -325,8 +352,12 @@ namespace EightBit break; case 3: // FD prefix break; + default: + break; } + break; + default: break; } @@ -338,8 +369,12 @@ namespace EightBit case 7: // Restart: RST y * 8 specification = $"RST {y * 8:X2}"; break; + default: + break; } + break; + default: break; } @@ -352,7 +387,7 @@ namespace EightBit 1 => "D", 2 => "H", 3 => "SP", - _ => throw new System.ArgumentOutOfRangeException(nameof(rp)), + _ => throw new ArgumentOutOfRangeException(nameof(rp)), }; private static string RP2(int rp) => rp switch @@ -361,7 +396,7 @@ namespace EightBit 1 => "D", 2 => "H", 3 => "PSW", - _ => throw new System.ArgumentOutOfRangeException(nameof(rp)), + _ => throw new ArgumentOutOfRangeException(nameof(rp)), }; private static string R(int r) => r switch @@ -374,7 +409,7 @@ namespace EightBit 5 => "L", 6 => "M", 7 => "A", - _ => throw new System.ArgumentOutOfRangeException(nameof(r)), + _ => throw new ArgumentOutOfRangeException(nameof(r)), }; private string Disassemble(Intel8080 cpu, ushort pc) @@ -407,7 +442,7 @@ namespace EightBit } output += '\t'; - output += string.Format(specification, (int)immediate, (int)absolute, relative, (int)displacement, indexedImmediate); + output += string.Format(CultureInfo.InvariantCulture, specification, (int)immediate, (int)absolute, relative, (int)displacement, indexedImmediate); return output; } diff --git a/Intel8080/Intel8080.Test/Board.cs b/Intel8080/Intel8080.Test/Board.cs index b18f245..73743dd 100644 --- a/Intel8080/Intel8080.Test/Board.cs +++ b/Intel8080/Intel8080.Test/Board.cs @@ -46,7 +46,7 @@ namespace Intel8080.Test { var programPath = this.configuration.RomDirectory + "/" + this.configuration.Program; var loadAddress = this.configuration.LoadAddress; - this.ram.Load(programPath, loadAddress.Word); + _ = this.ram.Load(programPath, loadAddress.Word); this.CPU.LoweredHALT += this.CPU_LoweredHALT; this.CPU.ExecutingInstruction += this.CPU_ExecutingInstruction_CPM; @@ -80,7 +80,7 @@ namespace Intel8080.Test } } - private void CPU_ExecutingInstruction_CPM(object sender, System.EventArgs e) + private void CPU_ExecutingInstruction_CPM(object? sender, System.EventArgs e) { switch (this.CPU.PC.Word) { @@ -99,8 +99,8 @@ namespace Intel8080.Test } } - private void CPU_LoweredHALT(object sender, System.EventArgs e) => this.LowerPOWER(); + private void CPU_LoweredHALT(object? sender, System.EventArgs e) => this.LowerPOWER(); - private void CPU_ExecutingInstruction_Debug(object sender, System.EventArgs e) => System.Console.Error.WriteLine($"{EightBit.Disassembler.State(this.CPU)}\t{this.disassembler.Disassemble(this.CPU)}"); + private void CPU_ExecutingInstruction_Debug(object? sender, System.EventArgs e) => System.Console.Error.WriteLine($"{Disassembler.State(this.CPU)}\t{this.disassembler.Disassemble(this.CPU)}"); } } diff --git a/Intel8080/Intel8080.cs b/Intel8080/Intel8080.cs index 6969ba5..246843c 100644 --- a/Intel8080/Intel8080.cs +++ b/Intel8080/Intel8080.cs @@ -2,9 +2,10 @@ // Copyright (c) Adrian Conlon. All rights reserved. // -namespace EightBit + +namespace Intel8080 { - using System; + using EightBit; public class Intel8080(Bus bus, InputOutput ports) : IntelProcessor(bus) { @@ -12,7 +13,7 @@ namespace EightBit private readonly InputOutput ports = ports; - private bool interruptEnable = false; + private bool interruptEnable; public override Register16 AF { @@ -195,6 +196,8 @@ namespace EightBit case 0: // NOP this.Tick(4); break; + default: + break; } break; @@ -357,7 +360,7 @@ namespace EightBit else { this.R(y, this.R(z)); - if ((y == 6) || (z == 6)) + if (y == 6 || z == 6) { this.Tick(3); // M operations } @@ -436,6 +439,8 @@ namespace EightBit this.SP.Word = this.HL.Word; this.Tick(4); break; + default: + break; } break; @@ -479,6 +484,8 @@ namespace EightBit this.EnableInterrupts(); this.Tick(4); break; + default: + break; } break; @@ -504,6 +511,8 @@ namespace EightBit this.CallIndirect(); this.Tick(17); break; + default: + break; } break; @@ -553,6 +562,8 @@ namespace EightBit throw new NotSupportedException("Invalid operation mode"); } + break; + default: break; } } @@ -703,12 +714,12 @@ namespace EightBit var before = this.A; var carry = (this.F & (byte)StatusBits.CF) != 0; byte addition = 0; - if (((this.F & (byte)StatusBits.AC) != 0) || (LowNibble(before) > 9)) + if ((this.F & (byte)StatusBits.AC) != 0 || LowNibble(before) > 9) { addition = 0x6; } - if (((this.F & (byte)StatusBits.CF) != 0) || HighNibble(before) > 9 || (HighNibble(before) >= 9 && LowNibble(before) > 9)) + if ((this.F & (byte)StatusBits.CF) != 0 || HighNibble(before) > 9 || (HighNibble(before) >= 9 && LowNibble(before) > 9)) { addition |= 0x60; carry = true; diff --git a/Intel8080/StatusBits.cs b/Intel8080/StatusBits.cs index 0bfff31..c2c09d0 100644 --- a/Intel8080/StatusBits.cs +++ b/Intel8080/StatusBits.cs @@ -2,9 +2,9 @@ // Copyright (c) Adrian Conlon. All rights reserved. // -namespace EightBit +namespace Intel8080 { - using System; + using EightBit; [Flags] public enum StatusBits