Ejemplo n.º 1
0
        public void Setup()
        {
            _byteFactory = TestUtils.CreateByteFactory();
            _fullByte    = _byteFactory.Create(255);

            Instruction = _byteFactory.Create(0);
            Flags       = new Caez();

            var cpuPinStates = new CpuPinStates(TestUtils.CreateClock(), TestUtils.CreateStepper(), Instruction, Flags,
                                                TestUtils.CreateAnd(), TestUtils.CreateOr(), TestUtils.CreateNot(), TestUtils.CreateDecoder(),
                                                _byteFactory);

            var bus = new Bus <IByte>(new BusMessage <IByte> {
                Data = new Byte(), Name = "Bus"
            });
            var ioBus = new Bus <IByte>(new BusMessage <IByte> {
                Data = new Byte(), Name = "IoBus"
            });
            var byteRegisterFactory = TestUtils.CreateByteRegisterFactory();
            var ram           = TestUtils.CreateRam(bus);
            var computerState = new ComputerState(byteRegisterFactory, ram, TestUtils.CreateBus1Factory(),
                                                  new ArithmeticLogicUnitFactory(), TestUtils.CreateCaezRegisterFactory(), new BitRegisterFactory(TestUtils.CreateMemoryGateFactory()), bus, ioBus);

            _sut = new Computer(cpuPinStates, computerState);
        }
        public void CanConvertFromByteToAscii(IByte inputByte, string expectedChar)
        {
            var result = new ByteToAsciiConverter(new ByteToBase10Converter(
                                                      new ByteFactory(new Base10Converter()), new Base10Converter())).ToAscii(inputByte);

            Assert.AreEqual(expectedChar, result);
        }
Ejemplo n.º 3
0
        public static ByteRegister CreateRegister(this IByte input, bool set = true, bool enable = true)
        {
            var register = CreateRegister(set, enable);

            register.Input = input;
            return(register);
        }
Ejemplo n.º 4
0
 public void SetMemoryAddress(IByte address)
 {
     MemoryAddressRegister.Set = true;
     MemoryAddressRegister.Apply(address);
     MemoryAddressRegister.Set = false;
     Apply();
 }
        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));
        }
Ejemplo n.º 6
0
        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));
        }
        public void CanConvertFromAsciiToByte(IByte outputByte, string inputChar)
        {
            var result =
                new ByteToAsciiConverter(new ByteToBase10Converter(new ByteFactory(new Base10Converter()),
                                                                   new Base10Converter()))
                .ToByte(inputChar);

            for (var i = 0; i < outputByte.Count; i++)
            {
                Assert.AreEqual(outputByte[i], result[i]);
            }
        }
Ejemplo n.º 8
0
        public (bool equal, bool ALarger, IByte output) AreEqual(IByte a, IByte b, bool aboveBitIsEqual,
                                                                 bool aboveBitALarger)
        {
            var output = new bool[8];

            for (var i = a.Count - 1; i >= 0; i--)
            {
                var(eq, lg, op) = _bitComparator.AreEqual(a[i], b[i], aboveBitIsEqual, aboveBitALarger);
                aboveBitIsEqual = eq;
                aboveBitALarger = lg;
                output[i]       = op;
            }

            return(aboveBitIsEqual, aboveBitALarger, _byteFactory.Create(output));
        }
Ejemplo n.º 9
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 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]);
        }
Ejemplo n.º 11
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);
        }
        public void Setup()
        {
            _byteFactory = TestUtils.CreateByteFactory();
            _fullByte    = _byteFactory.Create(255);
            var bus = new Bus <IByte>(new BusMessage <IByte> {
                Data = new Byte(), Name = "Bus"
            });
            var ioBus = new Bus <IByte>(new BusMessage <IByte> {
                Data = new Byte(), Name = "IoBus"
            });
            var byteRegisterFactory = TestUtils.CreateByteRegisterFactory();
            var ram = TestUtils.CreateRam(bus);

            _pinStates = new PinStates();
            _sut       = new ComputerState(byteRegisterFactory, ram, TestUtils.CreateBus1Factory(),
                                           new ArithmeticLogicUnitFactory(), TestUtils.CreateCaezRegisterFactory(), new BitRegisterFactory(TestUtils.CreateMemoryGateFactory()), bus, ioBus);
        }
        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);
        }
Ejemplo n.º 14
0
 public CpuPinStates(
     IClock clock,
     IStepper stepper,
     IByte instruction,
     Caez caez,
     IAnd and,
     IOr or,
     INot not,
     IDecoder decoder,
     IByteFactory byteFactory)
 {
     _clock       = clock;
     _stepper     = stepper;
     _instruction = instruction;
     _caez        = caez;
     _and         = and;
     _or          = or;
     _not         = not;
     _decoder     = decoder;
     _byteFactory = byteFactory;
 }
Ejemplo n.º 15
0
 public PinStates Step(IByte instruction, Caez flags)
 {
     _instruction = instruction;
     _caez        = flags;
     return(Step());
 }
Ejemplo n.º 16
0
 public uint ToInt(IByte input)
 {
     return(_base10Converter.ToInt(input));
 }
Ejemplo n.º 17
0
 public IByte Invert(IByte input)
 {
     return(_byteFactory.Create(input.Select(s => _not.Apply(s)).ToArray()));
 }
Ejemplo n.º 18
0
        public string ToAscii(IByte input)
        {
            var intInput = _byteToBase10Converter.ToInt(input);

            return(Ascii.Codes[intInput]);
        }
Ejemplo n.º 19
0
 public static bool[] ToBits(this IByte input)
 {
     return(new[]
            { input.One, input.Two, input.Three, input.Four, input.Five, input.Six, input.Seven, input.Eight });
 }
Ejemplo n.º 20
0
        public bool IsZero(IByte input)
        {
            var orRes = _or.Apply(input.ToArray());

            return(_not.Apply(orRes));
        }