mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-22 17:02:18 +00:00
Assert that which needs to be checked, but not thrown
This commit is contained in:
1 parent
2999db5c5a
commit
291266e4fc
14 files changed
+60
-44
No files matched your search
@@ -1,6 +1,9 @@
|
||||
// <copyright file="BigEndianProcessor.cs" company="Adrian Conlon">
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
public abstract class BigEndianProcessor(Bus memory) : Processor(memory)
|
||||
@@ -14,14 +17,14 @@ namespace EightBit
|
||||
|
||||
public override void PokeShort(ushort address, Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.Bus.Poke(address, value.High);
|
||||
this.Bus.Poke(++address, value.Low);
|
||||
}
|
||||
|
||||
protected override void FetchInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.FetchByte();
|
||||
into.High = this.Bus.Data;
|
||||
this.FetchByte();
|
||||
@@ -30,7 +33,7 @@ namespace EightBit
|
||||
|
||||
protected override void GetInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.MemoryRead();
|
||||
into.High = this.Bus.Data;
|
||||
this.Bus.Address.Increment();
|
||||
@@ -40,7 +43,7 @@ namespace EightBit
|
||||
|
||||
protected override void GetPagedInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.MemoryRead();
|
||||
into.High = this.Bus.Data;
|
||||
++this.Bus.Address.Low;
|
||||
@@ -50,7 +53,7 @@ namespace EightBit
|
||||
|
||||
protected override void PopInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.Pop();
|
||||
into.High = this.Bus.Data;
|
||||
this.Pop();
|
||||
@@ -59,14 +62,14 @@ namespace EightBit
|
||||
|
||||
protected override void PushShort(Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.Push(value.Low);
|
||||
this.Push(value.High);
|
||||
}
|
||||
|
||||
protected override void SetShort(Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.MemoryWrite(value.High);
|
||||
this.Bus.Address.Increment();
|
||||
this.MemoryWrite(value.Low);
|
||||
@@ -74,7 +77,7 @@ namespace EightBit
|
||||
|
||||
protected override void SetPaged(Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.MemoryWrite(value.High);
|
||||
++this.Bus.Address.Low;
|
||||
this.MemoryWrite(value.Low);
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ namespace EightBit
|
||||
|
||||
public byte Peek(Register16 absolute)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(absolute);
|
||||
Debug.Assert(absolute is not null, "absolute cannot be null");
|
||||
return this.Peek(absolute.Joined);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace EightBit
|
||||
|
||||
public void Poke(Register16 absolute, byte value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(absolute);
|
||||
Debug.Assert(absolute is not null, "absolute cannot be null");
|
||||
this.Poke(absolute.Joined, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
public sealed class InputOutput
|
||||
@@ -22,7 +24,7 @@ namespace EightBit
|
||||
|
||||
public byte ReadInputPort(Register16 port)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
Debug.Assert(port is not null, "port cannot be null");
|
||||
ReadingPort?.Invoke(this, new PortEventArgs(port));
|
||||
var value = this._input[port.Joined];
|
||||
ReadPort?.Invoke(this, new PortEventArgs(port));
|
||||
@@ -33,7 +35,7 @@ namespace EightBit
|
||||
|
||||
public void WriteInputPort(Register16 port, byte value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
Debug.Assert(port is not null, "port cannot be null");
|
||||
this.WriteInputPort(port.Joined, value);
|
||||
}
|
||||
|
||||
@@ -41,7 +43,7 @@ namespace EightBit
|
||||
|
||||
public void WriteOutputPort(Register16 port, byte value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
Debug.Assert(port is not null, "port cannot be null");
|
||||
WritingPort?.Invoke(this, new PortEventArgs(port));
|
||||
this._output[port.Joined] = value;
|
||||
WrittenPort?.Invoke(this, new PortEventArgs(port));
|
||||
@@ -51,7 +53,7 @@ namespace EightBit
|
||||
|
||||
public byte ReadOutputPort(Register16 port)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(port);
|
||||
Debug.Assert(port is not null, "port cannot be null");
|
||||
return this.ReadOutputPort(port.Joined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
public abstract class LittleEndianProcessor(Bus memory) : Processor(memory)
|
||||
@@ -15,14 +17,14 @@ namespace EightBit
|
||||
|
||||
public override void PokeShort(ushort address, Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.Bus.Poke(address, value.Low);
|
||||
this.Bus.Poke(++address, value.High);
|
||||
}
|
||||
|
||||
protected override void FetchInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.FetchByte();
|
||||
into.Low = this.Bus.Data;
|
||||
this.FetchByte();
|
||||
@@ -31,7 +33,7 @@ namespace EightBit
|
||||
|
||||
protected override void GetInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.MemoryRead();
|
||||
into.Low = this.Bus.Data;
|
||||
this.Bus.Address.Increment();
|
||||
@@ -41,7 +43,7 @@ namespace EightBit
|
||||
|
||||
protected override void GetPagedInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.MemoryRead();
|
||||
into.Low = this.Bus.Data;
|
||||
++this.Bus.Address.Low;
|
||||
@@ -51,7 +53,7 @@ namespace EightBit
|
||||
|
||||
protected override void PopInto(Register16 into)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.Pop();
|
||||
into.Low = this.Bus.Data;
|
||||
this.Pop();
|
||||
@@ -60,14 +62,14 @@ namespace EightBit
|
||||
|
||||
protected override void PushShort(Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.Push(value.High);
|
||||
this.Push(value.Low);
|
||||
}
|
||||
|
||||
protected override void SetShort(Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.MemoryWrite(value.Low);
|
||||
this.Bus.Address.Increment();
|
||||
this.MemoryWrite(value.High);
|
||||
@@ -75,7 +77,7 @@ namespace EightBit
|
||||
|
||||
protected override void SetPaged(Register16 value)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(value);
|
||||
Debug.Assert(value is not null, "value cannot be null");
|
||||
this.MemoryWrite(value.Low);
|
||||
++this.Bus.Address.Low;
|
||||
this.MemoryWrite(value.High);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
public abstract class Processor(Bus memory) : ClockedChip
|
||||
@@ -236,7 +238,7 @@ namespace EightBit
|
||||
|
||||
protected void GetPagedInto(byte page, byte offset, Register16 into)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(into);
|
||||
Debug.Assert(into is not null, "into cannot be null");
|
||||
this.Bus.Address.Assign(offset, page);
|
||||
this.GetPagedInto(into);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// Copyright (c) Adrian Conlon. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
public sealed class Register16
|
||||
@@ -38,7 +40,7 @@ namespace EightBit
|
||||
|
||||
public Register16(Register16 rhs)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(rhs);
|
||||
Debug.Assert(rhs is not null, "rhs cannot be null");
|
||||
this.Low = rhs.Low;
|
||||
this.High = rhs.High;
|
||||
}
|
||||
@@ -59,7 +61,7 @@ namespace EightBit
|
||||
|
||||
public static bool operator ==(Register16 left, Register16 right)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(left);
|
||||
Debug.Assert(left is not null, "left cannot be null");
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
@@ -83,7 +85,7 @@ namespace EightBit
|
||||
|
||||
public void Assign(Register16 from)
|
||||
{
|
||||
//ArgumentNullException.ThrowIfNull(from);
|
||||
Debug.Assert(from is not null, "from cannot be null");
|
||||
this.Low = from.Low;
|
||||
this.High = from.High;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
namespace LR35902
|
||||
{
|
||||
using EightBit;
|
||||
using System.Diagnostics;
|
||||
|
||||
public class ObjectAttribute
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace LR35902
|
||||
|
||||
public ObjectAttribute(Ram ram, ushort address)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(ram);
|
||||
Debug.Assert(ram is not null, "ram cannot be null");
|
||||
this.PositionY = ram.Peek(address);
|
||||
this.PositionX = ram.Peek(++address);
|
||||
this.Pattern = ram.Peek(++address);
|
||||
|
||||
@@ -119,8 +119,8 @@
|
||||
|
||||
private bool Check(string what, string? expected, string? actual)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(expected);
|
||||
ArgumentNullException.ThrowIfNull(actual);
|
||||
Debug.Assert(expected is not null, "expected cannot be null");
|
||||
Debug.Assert(actual is not null, "actual cannot be null");
|
||||
var success = actual == expected;
|
||||
if (!success)
|
||||
{
|
||||
@@ -341,7 +341,7 @@
|
||||
|
||||
private void DumpCycle(ushort address, byte? value, string? action)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
Debug.Assert(action is not null, "action cannot be null");
|
||||
this.Messages.Add($"Address: {address:X4}, value: {value:X2}, action: {action}");
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@
|
||||
|
||||
private void DumpCycles(IEnumerable<Cycle>? cycles)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(cycles);
|
||||
Debug.Assert(cycles is not null, "cycles cannot be null");
|
||||
foreach (var cycle in cycles)
|
||||
{
|
||||
this.DumpCycle(cycle);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace SM83.HarteTest
|
||||
|
||||
public Cycle(List<object> input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
|
||||
@@ -113,8 +113,8 @@
|
||||
|
||||
private bool Check(string what, string? expected, string? actual)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(expected);
|
||||
ArgumentNullException.ThrowIfNull(actual);
|
||||
Debug.Assert(expected is not null, "expected cannot be null");
|
||||
Debug.Assert(actual is not null, "actual cannot be null");
|
||||
var success = actual == expected;
|
||||
if (!success)
|
||||
{
|
||||
@@ -292,7 +292,7 @@
|
||||
|
||||
private void DumpCycle(ushort address, byte value, string? action)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
Debug.Assert(action is not null, "action cannot be null");
|
||||
this.Messages.Add($"Address: {address:X4}, value: {value:X2}, action: {action}");
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@
|
||||
|
||||
private void DumpCycles(IEnumerable<Cycle>? cycles)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(cycles);
|
||||
Debug.Assert(cycles is not null, "cycles cannot be null");
|
||||
foreach (var cycle in cycles)
|
||||
{
|
||||
this.DumpCycle(cycle);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace M6502.HarteTest
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace M6502.HarteTest
|
||||
{
|
||||
internal sealed class Cycle
|
||||
{
|
||||
@@ -17,7 +19,7 @@
|
||||
|
||||
public Cycle(List<object> input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
|
||||
@@ -142,8 +142,8 @@
|
||||
|
||||
private bool Check(string what, string? expected, string? actual)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(expected);
|
||||
ArgumentNullException.ThrowIfNull(actual);
|
||||
Debug.Assert(expected is not null, "expected cannot be null");
|
||||
Debug.Assert(actual is not null, "actual cannot be null");
|
||||
var success = actual == expected;
|
||||
if (!success)
|
||||
{
|
||||
@@ -414,7 +414,7 @@
|
||||
|
||||
private static string ExpandCycle(string prefix, ushort address, byte? value, string? action)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(action);
|
||||
Debug.Assert(action is not null, "action cannot be null");
|
||||
return value is null
|
||||
? $"{prefix}: Address: {address:X4}, action: {action}"
|
||||
: $"{prefix}: Address: {address:X4}, value: {value:X2}, action: {action}";
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
public Cycle(List<object> input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Z80.HarteTest
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Z80.HarteTest
|
||||
{
|
||||
// Cycle-by-cycle breakdown of bus activity
|
||||
internal sealed class Port
|
||||
@@ -19,7 +21,7 @@
|
||||
|
||||
public Port(List<object> input)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
Debug.Assert(input is not null, "input cannot be null");
|
||||
|
||||
if (input.Count != 3)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user