EightBitNet/EightBit/PinLevelExtensions.cs
Adrian Conlon efbd576624 Resurrect the concept of pin level matching. Allows for easier device wiring.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2019-05-06 09:58:50 +01:00

31 lines
907 B
C#

// <copyright file="PinLevelExtensions.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace EightBit
{
public static class PinLevelExtensions
{
public static bool Raised(this PinLevel line) => line == PinLevel.High;
public static bool Lowered(this PinLevel line) => line == PinLevel.Low;
public static void Raise(this ref PinLevel line) => line = PinLevel.High;
public static void Lower(this ref PinLevel line) => line = PinLevel.Low;
public static void Match(this ref PinLevel line, int condition) => Match(ref line, condition != 0);
public static void Match(this ref PinLevel line, bool condition)
{
if (condition)
{
line.Raise();
}
else
{
line.Lower();
}
}
}
}