Beispiel #1
0
 public Bus1(IAnd and, INot not, IOr or, IByteFactory byteFactory, Action <IByte> updateWire)
 {
     _and         = and;
     _not         = not;
     _or          = or;
     _byteFactory = byteFactory;
     _updateWire  = updateWire;
     Input        = _byteFactory.Create(0);
     Output       = _byteFactory.Create(0);
 }
Beispiel #2
0
 public ByteRegister(IByteMemoryGate byteMemoryGate, IByteEnabler byteEnabler, IByteFactory byteFactory, Action <IByte> updateWire)
 {
     _byteMemoryGate = byteMemoryGate;
     _byteEnabler    = byteEnabler;
     _updateWire     = updateWire;
     Input           = byteFactory.Create();
     Output          = byteFactory.Create();
     Data            = byteFactory.Create();
     Set             = false;
     Enable          = false;
 }
        private void Update3X8()
        {
            var threeXEightDecoded = _decoder.Apply(_instruction[1], _instruction[2], _instruction[3]);
            var notAluFlag         = _not.Apply(_instruction[0]);

            PinStates.ThreeXEight =
                _byteFactory.Create(threeXEightDecoded.Select(bit => _and.Apply(notAluFlag, bit)).ToArray());
        }
        public IByte Apply(IByte input, bool set)
        {
            var newState = new bool[8];

            for (var i = 0; i < input.Count; i++)
            {
                newState[i] = _memoryGates[i].Apply(input[i], set);
            }

            return(_byteFactory.Create(newState));
        }
        public IByte Apply(IByte input, bool set)
        {
            var bits = new bool[8];

            for (var i = 0; i < input.Count; i++)
            {
                bits[i] = _andGate.Apply(input[i], set);
            }

            return(_byteFactory.Create(bits));
        }
Beispiel #6
0
        public IByte ToByte(uint input)
        {
            if (255 < input)
            {
                throw new OutOfMemoryException("Number must be between 0 and 255");
            }

            var result = _base10Converter.ToBit(input).ToList();

            if (result.Count == 8)
            {
                return(_byteFactory.Create(result.ToArray()));
            }

            var toAdd = 8 - result.Count;

            result.AddRange(toAdd.BitListOfLength());

            return(_byteFactory.Create(result.ToArray()));
        }
        public ArithmeticLogicUnit(
            IByteXOr byteXOr,
            IByteOr byteOr,
            IByteAnd byteAnd,
            IInverter inverter,
            IByteAdder byteAdder,
            IByteEnabler byteEnabler,
            IAnd and,
            IIsZeroGate isZeroGate,
            IByteDecoder byteDecoder,
            IRightByteShifter rightByteShifter,
            ILeftByteShifter leftByteShifter,
            IOr or,
            IAluWire aluWire,
            IByteComparator byteComparator,
            Action <Caez> updateFlags,
            Action <IByte> updateAcc,
            IByteFactory byteFactory)
        {
            _byteXOr          = byteXOr;
            _byteOr           = byteOr;
            _byteAnd          = byteAnd;
            _inverter         = inverter;
            _byteAdder        = byteAdder;
            _byteEnabler      = byteEnabler;
            _and              = and;
            _isZeroGate       = isZeroGate;
            _byteDecoder      = byteDecoder;
            _rightByteShifter = rightByteShifter;
            _leftByteShifter  = leftByteShifter;
            _or             = or;
            _aluWire        = aluWire;
            _byteComparator = byteComparator;
            _updateFlags    = updateFlags;
            _updateAcc      = updateAcc;

            InputA = byteFactory.Create();
            InputB = byteFactory.Create();
            Op     = new Op();
        }
Beispiel #8
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 => _xOr.Apply(s.ToArray())).ToArray();

            return(_byteFactory.Create(result));
        }
        public (IByte Ouput, bool ShiftOut) Shift(IByte input, bool shiftIn)
        {
            var shift = new[]
            {
                shiftIn,
                input[0],
                input[1],
                input[2],
                input[3],
                input[4],
                input[5],
                input[6]
            };

            return(_byteFactory.Create(shift), input[7]);
        }
Beispiel #10
0
        public (IByte Sum, bool CarryOut) Add(IByte a, IByte b, bool carryIn)
        {
            var carryOut = carryIn;
            var output   = new bool[8];

            for (var i = 0; i < a.Count; i++)
            {
                var(sum, carry) = _bitAdder.Add(a[i], b[i], carryOut);
                output[i]       = sum;
                carryOut        = carry;
            }

            var outputByte = _byteFactory.Create(output);

            return(outputByte, carryOut);
        }
Beispiel #11
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);
        }
 public IByte Invert(IByte input)
 {
     return(_byteFactory.Create(input.Select(s => _not.Apply(s)).ToArray()));
 }
 public IByte Apply(params IByte[] input)
 {
     return(input.LastOrDefault(w => w.Any(a => a)) ?? _byteFactory.Create(0));
 }
Beispiel #14
0
 public IByte Decode(bool a, bool b, bool c)
 {
     return(_byteFactory.Create(_decoder.Apply(a, b, c).ToArray()));
 }