示例#1
0
        public (bool equal, bool ALarger, bool output) AreEqual(bool a, bool b, bool aboveBitIsEqual,
                                                                bool aboveBitALarger)
        {
            var unequal = _xOr.Apply(a, b);
            var equal   = _not.Apply(unequal);
            var equalAndAboveBitEqual = _and.Apply(equal, aboveBitIsEqual);
            var aLarger = _and.Apply(aboveBitIsEqual, unequal, a);
            var aLargerOrAboveALarger = _or.Apply(aLarger, aboveBitALarger);

            return(equalAndAboveBitEqual, aLargerOrAboveALarger, unequal);
        }
示例#2
0
        public (bool Sum, bool CarryOut) Add(bool a, bool b, bool carryIn)
        {
            var aXorB = _xOr.Apply(a, b);
            var sum   = _xOr.Apply(aXorB, carryIn);

            var aAndB           = _and.Apply(a, b);
            var aXorBAndCarryIn = _and.Apply(aXorB, carryIn);
            var carryOut        = _or.Apply(aAndB, aXorBAndCarryIn);

            return(sum, carryOut);
        }
示例#3
0
        public StepperOutput Step(bool clk, bool reset)
        {
            var notReset = _not.Apply(reset);
            var notClk   = _not.Apply(clk);

            var resetOrNotClk = _or.Apply(notClk, reset);
            var clkOrReset    = _or.Apply(clk, reset);

            var m0  = _memoryGates[0].Apply(notReset, resetOrNotClk);
            var m1  = _memoryGates[1].Apply(m0, clkOrReset);
            var m2  = _memoryGates[2].Apply(m1, resetOrNotClk);
            var m3  = _memoryGates[3].Apply(m2, clkOrReset);
            var m4  = _memoryGates[4].Apply(m3, resetOrNotClk);
            var m5  = _memoryGates[5].Apply(m4, clkOrReset);
            var m6  = _memoryGates[6].Apply(m5, resetOrNotClk);
            var m7  = _memoryGates[7].Apply(m6, clkOrReset);
            var m8  = _memoryGates[8].Apply(m7, resetOrNotClk);
            var m9  = _memoryGates[9].Apply(m8, clkOrReset);
            var m10 = _memoryGates[10].Apply(m9, resetOrNotClk);
            var m11 = _memoryGates[11].Apply(m10, clkOrReset);

            var notM1  = _not.Apply(m1);
            var notM3  = _not.Apply(m3);
            var notM5  = _not.Apply(m5);
            var notM7  = _not.Apply(m7);
            var notM9  = _not.Apply(m9);
            var notM11 = _not.Apply(m11);

            var step1 = _or.Apply(reset, notM1);
            var step2 = _and.Apply(m1, notM3);
            var step3 = _and.Apply(m3, notM5);
            var step4 = _and.Apply(m5, notM7);
            var step5 = _and.Apply(m7, notM9);
            var step6 = _and.Apply(m9, notM11);

            _step7 = m11;

            var stepperArray = new[] { step1, step2, step3, step4, step5, step6, _step7 };

            return(new StepperOutput(stepperArray));
        }
示例#4
0
        public IByte Apply(params IByte[] input)
        {
            var groups = new List <List <bool> >();

            for (var i = 0; i < input[0].Count; i++)
            {
                var tempList = input.Select(t => t[i]).ToList();
                groups.Add(tempList);
            }

            var result = groups.Select(s => _or.Apply(s.ToArray())).ToArray();

            return(_byteFactory.Create(result));
        }
示例#5
0
        public IByte Apply(IByte input, bool bus1)
        {
            Input = input;
            Set   = bus1;
            var one          = input[0];
            var rest         = input.Skip(1).ToArray();
            var notBus1      = _not.Apply(bus1);
            var notAndRest   = rest.Select(s => _and.Apply(s, notBus1)).ToList();
            var orOneAndBus1 = _or.Apply(one, bus1);

            var output = notAndRest.Prepend(orOneAndBus1).ToArray();

            Output = _byteFactory.Create(output);
            _updateWire(Output);
            return(Output);
        }
        private void UpdateLoadStep4()
        {
            // setup
            var step43X80 = _and.Apply(Step4, PinStates.ThreeXEight[0]);
            var step43X81 = _and.Apply(Step4, PinStates.ThreeXEight[1]);

            var newState = _or.Apply(step43X80, step43X81);

            // enables
            PinStates.RegA.Enable = NewPinState(PinStates.RegA.Enable, newState);

            // sets
            PinStates.Mar = NewPinState(PinStates.Mar, ClkSAnd(newState));
        }
        public AluOutput Apply(IByte a, IByte b, bool carryIn, Op op)
        {
            var opDecoder = _byteDecoder.Decode(op.One, op.Two, op.Three);

            var xOr              = _byteXOr.Apply(a, b);
            var or               = _byteOr.Apply(a, b);
            var and              = _byteAnd.Apply(a, b);
            var not              = _inverter.Invert(a);
            var shiftLeft        = _leftByteShifter.Shift(a, carryIn);
            var shiftRight       = _rightByteShifter.Shift(a, carryIn);
            var adder            = _byteAdder.Add(a, b, carryIn);
            var comparatorResult = _byteComparator.AreEqual(a, b, true, false);

            var enabledAdd        = _byteEnabler.Apply(adder.Sum, opDecoder[0]);
            var enabledShiftRight = _byteEnabler.Apply(shiftRight.Ouput, opDecoder[1]);
            var enabledShiftLeft  = _byteEnabler.Apply(shiftLeft.Ouput, opDecoder[2]);
            var enabledNot        = _byteEnabler.Apply(not, opDecoder[3]);
            var enabledAnd        = _byteEnabler.Apply(and, opDecoder[4]);
            var enabledOr         = _byteEnabler.Apply(or, opDecoder[5]);
            var enabledXOr        = _byteEnabler.Apply(xOr, opDecoder[6]);
            var enabledComparator = _byteEnabler.Apply(comparatorResult.output, opDecoder[7]);

            var carryOutAdd        = _and.Apply(adder.CarryOut, opDecoder[0]);
            var carryOutShiftRight = _and.Apply(shiftRight.ShiftOut, opDecoder[1]);
            var carryOutShiftLeft  = _and.Apply(shiftLeft.ShiftOut, opDecoder[2]);
            var carryOut           = _or.Apply(carryOutAdd, carryOutShiftRight, carryOutShiftLeft);

            var output = _aluWire.Apply(enabledAdd, enabledShiftLeft, enabledShiftRight, enabledNot, enabledAnd,
                                        enabledOr, enabledXOr, enabledComparator);
            var zero = _isZeroGate.IsZero(output);

            var aluOutput = new AluOutput
            {
                ALarger  = comparatorResult.ALarger,
                CarryOut = carryOut,
                Equal    = comparatorResult.equal,
                Output   = output,
                Zero     = zero
            };

            _updateFlags(new Caez {
                C = aluOutput.CarryOut, A = aluOutput.ALarger, E = aluOutput.Equal, Z = aluOutput.Zero
            });
            _updateAcc(aluOutput.Output);
            return(aluOutput);
        }
示例#8
0
        public bool IsZero(IByte input)
        {
            var orRes = _or.Apply(input.ToArray());

            return(_not.Apply(orRes));
        }