mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-04-19 15:16:41 +00:00
Follow most of the guideline suggestions from VS2019 preview. Pretty good suggestions!
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
+9
-18
@@ -4,29 +4,21 @@
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
using System.Text;
|
||||
|
||||
public class Disassembler
|
||||
{
|
||||
private readonly Bus bus;
|
||||
|
||||
private bool prefixCB = false;
|
||||
private bool prefixDD = false;
|
||||
private bool prefixED = false;
|
||||
private bool prefixFD = false;
|
||||
|
||||
public Disassembler(Bus bus)
|
||||
{
|
||||
this.bus = bus;
|
||||
}
|
||||
public Disassembler(Bus bus) => this.Bus = bus;
|
||||
|
||||
public Bus Bus => this.bus;
|
||||
public Bus Bus { get; }
|
||||
|
||||
public static string AsFlag(byte value, StatusBits flag, string represents) => (value & (byte)flag) != 0 ? represents : "-";
|
||||
|
||||
public static string AsFlags(byte value)
|
||||
{
|
||||
return $"{AsFlag(value, StatusBits.SF, "S")}"
|
||||
public static string AsFlags(byte value) =>
|
||||
$"{AsFlag(value, StatusBits.SF, "S")}"
|
||||
+ $"{AsFlag(value, StatusBits.ZF, "Z")}"
|
||||
+ $"{AsFlag(value, StatusBits.YF, "Y")}"
|
||||
+ $"{AsFlag(value, StatusBits.HC, "H")}"
|
||||
@@ -34,7 +26,6 @@ namespace EightBit
|
||||
+ $"{AsFlag(value, StatusBits.PF, "P")}"
|
||||
+ $"{AsFlag(value, StatusBits.NF, "N")}"
|
||||
+ $"{AsFlag(value, StatusBits.CF, "C")}";
|
||||
}
|
||||
|
||||
public static string State(Z80 cpu)
|
||||
{
|
||||
@@ -147,10 +138,10 @@ namespace EightBit
|
||||
|
||||
var output = $"{opCode:x2}";
|
||||
|
||||
string specification = string.Empty;
|
||||
var specification = string.Empty;
|
||||
if (this.prefixCB)
|
||||
{
|
||||
output += this.DisassembleCB(cpu, pc, ref specification, ref dumpCount, x, y, z, p, q);
|
||||
output += this.DisassembleCB(ref specification, x, y, z);
|
||||
}
|
||||
else if (this.prefixED)
|
||||
{
|
||||
@@ -161,7 +152,7 @@ namespace EightBit
|
||||
output += this.DisassembleOther(cpu, pc, ref specification, ref dumpCount, x, y, z, p, q);
|
||||
}
|
||||
|
||||
for (int i = 0; i < dumpCount; ++i)
|
||||
for (var i = 0; i < dumpCount; ++i)
|
||||
{
|
||||
output += $"{this.Bus.Peek((ushort)(pc + i + 1)):x2}";
|
||||
}
|
||||
@@ -184,9 +175,9 @@ namespace EightBit
|
||||
return output;
|
||||
}
|
||||
|
||||
private string DisassembleCB(Z80 cpu, ushort pc, ref string specification, ref int dumpCount, int x, int y, int z, int p, int q)
|
||||
private string DisassembleCB(ref string specification, int x, int y, int z)
|
||||
{
|
||||
string output = string.Empty;
|
||||
var output = string.Empty;
|
||||
switch (x)
|
||||
{
|
||||
case 0: // rot[y] r[z]
|
||||
|
||||
+5
-20
@@ -15,15 +15,9 @@ namespace EightBit
|
||||
this.variable = (byte)(value & (byte)Mask.Mask7);
|
||||
}
|
||||
|
||||
public static implicit operator byte(RefreshRegister input)
|
||||
{
|
||||
return ToByte(input);
|
||||
}
|
||||
public static implicit operator byte(RefreshRegister input) => ToByte(input);
|
||||
|
||||
public static implicit operator RefreshRegister(byte input)
|
||||
{
|
||||
return FromByte(input);
|
||||
}
|
||||
public static implicit operator RefreshRegister(byte input) => FromByte(input);
|
||||
|
||||
public static RefreshRegister operator ++(RefreshRegister value) => Increment(value);
|
||||
|
||||
@@ -31,10 +25,7 @@ namespace EightBit
|
||||
|
||||
public static bool operator !=(RefreshRegister left, RefreshRegister right) => !(left == right);
|
||||
|
||||
public static byte ToByte(RefreshRegister input)
|
||||
{
|
||||
return (byte)((input.high << 7) | (input.variable & (byte)Mask.Mask7));
|
||||
}
|
||||
public static byte ToByte(RefreshRegister input) => (byte)((input.high << 7) | (input.variable & (byte)Mask.Mask7));
|
||||
|
||||
public static RefreshRegister Increment(RefreshRegister value)
|
||||
{
|
||||
@@ -42,15 +33,9 @@ namespace EightBit
|
||||
return value;
|
||||
}
|
||||
|
||||
public static RefreshRegister FromByte(byte input)
|
||||
{
|
||||
return new RefreshRegister(input);
|
||||
}
|
||||
public static RefreshRegister FromByte(byte input) => new RefreshRegister(input);
|
||||
|
||||
public byte ToByte()
|
||||
{
|
||||
return ToByte(this);
|
||||
}
|
||||
public byte ToByte() => ToByte(this);
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
||||
+7
-14
@@ -46,7 +46,6 @@ namespace Z80.Test
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
var programFilename = this.configuration.Program;
|
||||
var programPath = this.configuration.RomDirectory + "/" + this.configuration.Program;
|
||||
var loadAddress = this.configuration.LoadAddress;
|
||||
this.ram.Load(programPath, loadAddress.Word);
|
||||
@@ -68,15 +67,15 @@ namespace Z80.Test
|
||||
|
||||
private void BDOS()
|
||||
{
|
||||
switch (CPU.C)
|
||||
switch (this.CPU.C)
|
||||
{
|
||||
case 0x2:
|
||||
System.Console.Out.Write(CPU.E.ToString());
|
||||
System.Console.Out.Write(this.CPU.E.ToString());
|
||||
break;
|
||||
case 0x9:
|
||||
for (ushort i = CPU.DE.Word; Peek(i) != '$'; ++i)
|
||||
for (var i = this.CPU.DE.Word; this.Peek(i) != '$'; ++i)
|
||||
{
|
||||
System.Console.Out.Write((char)Peek(i));
|
||||
System.Console.Out.Write((char)this.Peek(i));
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -95,21 +94,15 @@ namespace Z80.Test
|
||||
|
||||
break;
|
||||
case 0x5: // BDOS
|
||||
BDOS();
|
||||
this.BDOS();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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($"{EightBit.Disassembler.State(this.CPU)}\t{this.disassembler.Disassemble(this.CPU)}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace Z80.Test
|
||||
#if DEBUG
|
||||
configuration.DebugMode = true;
|
||||
#endif
|
||||
// configuration.DebugMode = true;
|
||||
|
||||
using (var harness = new TestHarness(configuration))
|
||||
{
|
||||
|
||||
@@ -12,14 +12,10 @@ namespace Z80.Test
|
||||
private readonly Stopwatch timer = new Stopwatch();
|
||||
private readonly Board board;
|
||||
private long totalCycles = 0;
|
||||
private long instructions = 0;
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
public TestHarness(Configuration configuration)
|
||||
{
|
||||
this.board = new Board(configuration);
|
||||
}
|
||||
public TestHarness(Configuration configuration) => this.board = new Board(configuration);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -38,7 +34,6 @@ namespace Z80.Test
|
||||
while (cpu.Powered)
|
||||
{
|
||||
this.totalCycles += cpu.Step();
|
||||
++this.instructions;
|
||||
}
|
||||
|
||||
this.timer.Stop();
|
||||
|
||||
+17
-66
@@ -28,7 +28,6 @@ namespace EightBit
|
||||
private bool prefixCB = false;
|
||||
private bool prefixDD = false;
|
||||
private bool prefixED = false;
|
||||
private bool prefixFD = false;
|
||||
|
||||
private PinLevel nmiLine = PinLevel.Low;
|
||||
private PinLevel m1Line = PinLevel.Low;
|
||||
@@ -40,10 +39,7 @@ namespace EightBit
|
||||
private bool displaced = false;
|
||||
|
||||
public Z80(Bus bus, InputOutput ports)
|
||||
: base(bus)
|
||||
{
|
||||
this.ports = ports;
|
||||
}
|
||||
: base(bus) => this.ports = ports;
|
||||
|
||||
public event EventHandler<EventArgs> ExecutingInstruction;
|
||||
|
||||
@@ -130,7 +126,7 @@ namespace EightBit
|
||||
this.Exx();
|
||||
this.IX.Word = this.IY.Word = this.BC.Word = this.DE.Word = this.HL.Word = (ushort)Mask.Mask16;
|
||||
|
||||
this.prefixCB = this.prefixDD = this.prefixED = this.prefixFD = false;
|
||||
this.prefixCB = this.prefixDD = this.prefixED = false;
|
||||
}
|
||||
|
||||
public virtual void RaiseNMI()
|
||||
@@ -204,7 +200,7 @@ namespace EightBit
|
||||
this.OnExecutingInstruction();
|
||||
if (this.Powered)
|
||||
{
|
||||
this.displaced = this.prefixCB = this.prefixDD = this.prefixED = this.prefixFD = false;
|
||||
this.displaced = this.prefixCB = this.prefixDD = this.prefixED = false;
|
||||
this.LowerM1();
|
||||
if (this.RESET().Lowered())
|
||||
{
|
||||
@@ -295,22 +291,11 @@ namespace EightBit
|
||||
|
||||
private static byte ClearFlag(byte f, StatusBits flag, int condition) => ClearFlag(f, (byte)flag, condition);
|
||||
|
||||
private static byte ClearFlag(byte f, StatusBits flag, bool condition) => ClearFlag(f, (byte)flag, condition);
|
||||
private static byte AdjustSign(byte input, byte value) => SetFlag(input, StatusBits.SF, value & (byte)StatusBits.SF);
|
||||
|
||||
private static byte AdjustSign(byte input, byte value)
|
||||
{
|
||||
return SetFlag(input, StatusBits.SF, value & (byte)StatusBits.SF);
|
||||
}
|
||||
private static byte AdjustZero(byte input, byte value) => ClearFlag(input, StatusBits.ZF, value);
|
||||
|
||||
private static byte AdjustZero(byte input, byte value)
|
||||
{
|
||||
return ClearFlag(input, StatusBits.ZF, value);
|
||||
}
|
||||
|
||||
private static byte AdjustParity(byte input, byte value)
|
||||
{
|
||||
return SetFlag(input, StatusBits.PF, EvenParity(value));
|
||||
}
|
||||
private static byte AdjustParity(byte input, byte value) => SetFlag(input, StatusBits.PF, EvenParity(value));
|
||||
|
||||
private static byte AdjustSZ(byte input, byte value)
|
||||
{
|
||||
@@ -342,15 +327,9 @@ namespace EightBit
|
||||
return AdjustXY(input, value);
|
||||
}
|
||||
|
||||
private static byte AdjustHalfCarryAdd(byte input, byte before, byte value, int calculation)
|
||||
{
|
||||
return SetFlag(input, StatusBits.HC, CalculateHalfCarryAdd(before, value, calculation));
|
||||
}
|
||||
private static byte AdjustHalfCarryAdd(byte input, byte before, byte value, int calculation) => SetFlag(input, StatusBits.HC, CalculateHalfCarryAdd(before, value, calculation));
|
||||
|
||||
private static byte AdjustHalfCarrySub(byte input, byte before, byte value, int calculation)
|
||||
{
|
||||
return SetFlag(input, StatusBits.HC, CalculateHalfCarrySub(before, value, calculation));
|
||||
}
|
||||
private static byte AdjustHalfCarrySub(byte input, byte before, byte value, int calculation) => SetFlag(input, StatusBits.HC, CalculateHalfCarrySub(before, value, calculation));
|
||||
|
||||
private static byte AdjustOverflowAdd(byte input, int beforeNegative, int valueNegative, int afterNegative)
|
||||
{
|
||||
@@ -358,10 +337,7 @@ namespace EightBit
|
||||
return SetFlag(input, StatusBits.VF, overflow);
|
||||
}
|
||||
|
||||
private static byte AdjustOverflowAdd(byte input, byte before, byte value, byte calculation)
|
||||
{
|
||||
return AdjustOverflowAdd(input, before & (byte)StatusBits.SF, value & (byte)StatusBits.SF, calculation & (byte)StatusBits.SF);
|
||||
}
|
||||
private static byte AdjustOverflowAdd(byte input, byte before, byte value, byte calculation) => AdjustOverflowAdd(input, before & (byte)StatusBits.SF, value & (byte)StatusBits.SF, calculation & (byte)StatusBits.SF);
|
||||
|
||||
private static byte AdjustOverflowSub(byte input, int beforeNegative, int valueNegative, int afterNegative)
|
||||
{
|
||||
@@ -369,20 +345,11 @@ namespace EightBit
|
||||
return SetFlag(input, StatusBits.VF, overflow);
|
||||
}
|
||||
|
||||
private static byte AdjustOverflowSub(byte input, byte before, byte value, byte calculation)
|
||||
{
|
||||
return AdjustOverflowSub(input, before & (byte)StatusBits.SF, value & (byte)StatusBits.SF, calculation & (byte)StatusBits.SF);
|
||||
}
|
||||
private static byte AdjustOverflowSub(byte input, byte before, byte value, byte calculation) => AdjustOverflowSub(input, before & (byte)StatusBits.SF, value & (byte)StatusBits.SF, calculation & (byte)StatusBits.SF);
|
||||
|
||||
private static byte RES(int n, byte operand)
|
||||
{
|
||||
return (byte)(operand & ~(1 << n));
|
||||
}
|
||||
private static byte RES(int n, byte operand) => (byte)(operand & ~(1 << n));
|
||||
|
||||
private static byte SET(int n, byte operand)
|
||||
{
|
||||
return (byte)(operand | (1 << n));
|
||||
}
|
||||
private static byte SET(int n, byte operand) => (byte)(operand | (1 << n));
|
||||
|
||||
private void DisableInterrupts() => this.IFF1 = this.IFF2 = false;
|
||||
|
||||
@@ -531,7 +498,6 @@ namespace EightBit
|
||||
|
||||
private void ExecuteCB(int x, int y, int z)
|
||||
{
|
||||
var memoryY = y == 6;
|
||||
var memoryZ = z == 6;
|
||||
var indirect = (!this.displaced && memoryZ) || this.displaced;
|
||||
var direct = !indirect;
|
||||
@@ -620,8 +586,6 @@ namespace EightBit
|
||||
|
||||
private void ExecuteED(int x, int y, int z, int p, int q)
|
||||
{
|
||||
var memoryY = y == 6;
|
||||
var memoryZ = z == 6;
|
||||
switch (x)
|
||||
{
|
||||
case 0:
|
||||
@@ -647,14 +611,7 @@ namespace EightBit
|
||||
case 1: // Output to port with 16-bit address
|
||||
this.MEMPTR.Word = this.Bus.Address.Word = this.BC.Word;
|
||||
this.MEMPTR.Word++;
|
||||
if (y != 6)
|
||||
{
|
||||
this.Bus.Data = this.R(y); // OUT (C),r[y]
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Bus.Data = 0; // OUT (C),0
|
||||
}
|
||||
this.Bus.Data = y != 6 ? this.R(y) : (byte)0;
|
||||
|
||||
this.WritePort();
|
||||
this.Tick(12);
|
||||
@@ -1132,7 +1089,7 @@ namespace EightBit
|
||||
case 1: // 8-bit loading
|
||||
if (!(memoryZ && memoryY))
|
||||
{
|
||||
bool normal = true;
|
||||
var normal = true;
|
||||
if (this.displaced)
|
||||
{
|
||||
if (memoryZ || memoryY)
|
||||
@@ -1365,7 +1322,7 @@ namespace EightBit
|
||||
this.Execute(this.FetchByte());
|
||||
break;
|
||||
case 3: // FD prefix
|
||||
this.displaced = this.prefixFD = true;
|
||||
this.displaced = true;
|
||||
this.LowerM1();
|
||||
this.Execute(this.FetchByte());
|
||||
break;
|
||||
@@ -2038,10 +1995,7 @@ namespace EightBit
|
||||
++this.MEMPTR.Low;
|
||||
}
|
||||
|
||||
private void WritePort()
|
||||
{
|
||||
this.ports.Write(this.Bus.Address.Low, this.Bus.Data);
|
||||
}
|
||||
private void WritePort() => this.ports.Write(this.Bus.Address.Low, this.Bus.Data);
|
||||
|
||||
private byte ReadPort(byte port)
|
||||
{
|
||||
@@ -2050,9 +2004,6 @@ namespace EightBit
|
||||
return this.ReadPort();
|
||||
}
|
||||
|
||||
private byte ReadPort()
|
||||
{
|
||||
return this.Bus.Data = this.ports.Read(this.Bus.Address.Low);
|
||||
}
|
||||
private byte ReadPort() => this.Bus.Data = this.ports.Read(this.Bus.Address.Low);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user