public static bool Do(bool s, bool d1, bool d0) { var nand1 = Gates.Nand(s, d1); var nand2 = Gates.Nand(Gates.Invert(s), d0); return(Gates.Nand(nand1, nand2)); }
/// <summary> /// Sends a data bit to one of two output channels. /// </summary> /// <param name="s">Determines if the data bit is dispatched through c1 or c0</param> /// <param name="data">Data</param> public static Channels Do(bool s, bool data) { var invS = Gates.Invert(s); var channel0 = Gates.And(invS, data); var channel1 = Gates.And(s, data); return(new Channels(channel0, channel1)); }
/// <summary> /// A latch component stores and outputs a single bit. /// When st(store) is 1, the value on d is stored and emitted. /// When st is 0, the value of d is ignored, and the previously stored value is still emitted. /// </summary> /// <param name="st">Store: yes/no</param> /// <param name="d">Data</param> /// <param name="clock">Clock signal</param> /// <returns>The previously stored value</returns> public bool Do(bool st, bool d, bool clock) { var invertedCLock = Gates.Invert(clock); var storeButNotClockTick = Gates.And(st, invertedCLock); var output = _latch1.Do(storeButNotClockTick, d); return(_latch2.Do(clock, output)); }
/// <summary> /// Bit 15 of the input indicates the kind of instruction: /// Bit 15 | Instruction kind /// -------+----------------- /// 0 | data /// 1 | computation /// /// For a data instruction, W(data word) should reflect the input, the a flag should be 1 and all other flags should be 0. /// For a computation instruction, the ci(computation instruction) flag should be 1, W should be 0. All other flags should be mapped from the bits in the input as follows: /// Input Output /// Bit Group flag /// 14 (ignored) - /// 13 (ignored) - /// 12 source sm /// 11 computation zx /// 10 computation nx /// 9 computation zy /// 8 computation ny /// 7 computation f /// 6 computation no /// 5 destination a /// 4 destination d /// 3 destination* a /// 2 condition gt /// 1 condition eq /// 0 condition lt /// </summary> /// <param name="instruction"></param> /// <returns></returns> public static DecodedInstruction Decode(Byte2 instruction) { var isNegative = Arithmetics.IsLessThanZero(instruction); var inverted = Gates.Invert(isNegative); var s = Select16.Do(inverted, new Byte2(0), instruction); var instructionOrZero = Select16.Do(isNegative, new Byte2(0), instruction); return(new DecodedInstruction(isNegative, s.Twelve, new Operation(s.Eleven, s.Ten, s.Nine, s.Eight, s.Seven, s.Six), new Destination(Gates.Or(inverted, s.Five), s.Four, s.Three), new Condition(s.Two, s.One, s.Zero), instructionOrZero)); }
public Byte2 Do(bool store, Byte2 data, bool clock) { var invertedClock = Gates.Invert(clock); incremented = Arithmetics.Increment(registeredOutput); _selectedData = Select16.Do(store, data, incremented); registeredOutput = register.Do(invertedClock, _selectedData, clock); return(registeredOutput); }
public Byte2 Do(Nibble address, bool store, Byte2 data, bool clock) { var invertedAddress = Gates.Invert(address.Three); var storeAtRam0 = Gates.And(invertedAddress, store); var storeAtRam1 = Gates.And(address.Three, store); var output0 = _ram0.Do(address, storeAtRam0, data, clock); var output1 = _ram1.Do(address, storeAtRam1, data, clock); var outputTotal = Select16.Do(address.Three, output1, output0); return(outputTotal); }
public Byte2 Do(bool address, bool store, Byte2 data, bool clock) { var storeAtBank1 = Gates.And(address, store); var invertedAddress = Gates.Invert(address); var storeAtBank0 = Gates.And(invertedAddress, store); _output1 = _register1.Do(storeAtBank1, data, clock); _output0 = _register0.Do(storeAtBank0, data, clock); var outputTotal = Select16.Do(address, _output1, _output0); return(outputTotal); }
public static bool Evaluate(Condition condition, Byte2 data) { var isLessThanZero = Arithmetics.IsLessThanZero(data); var andIsLessThanZero = Gates.And(condition.LessThanZero, isLessThanZero); var equalsZero = Arithmetics.EqualsZero(data); var andIsEqualToZero = Gates.And(condition.EqualToZero, equalsZero); var isGreaterThanZero = Gates.And(condition.GreaterThanZero, Gates.And(Gates.Invert(isLessThanZero), Gates.Invert(equalsZero))); var lessOrEqual = Gates.Or(andIsLessThanZero, andIsEqualToZero); var lessOrEqualOrGreater = Gates.Or(lessOrEqual, isGreaterThanZero); return(lessOrEqualOrGreater); }
public static bool EqualsZero(Bit2 a) { var orA = Gates.Or(a.High, a.Low); return(Gates.Invert(orA)); }
public void False_should_return_true() { var res = Gates.Invert(false); res.Should().BeTrue(); }
public void True_should_return_false() { var res = Gates.Invert(true); res.Should().BeFalse(); }