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 ByteAndRunsAsExpected()
        {
            var byteFactory = new ByteFactory(new Base10Converter());
            var sut         = new ByteAnd(new And(), new ByteFactory(new Base10Converter()));

            var result = sut.Apply(byteFactory.Create(0), byteFactory.Create(255));

            Assert.IsFalse(result.Any(a => a));
        }
        public void InvertsAllInputs()
        {
            var byteFactory    = new ByteFactory(new Base10Converter());
            var sut            = new Inverter(new Not(), byteFactory);
            var input          = byteFactory.Create(255);
            var expectedOutput = byteFactory.Create(0);

            var result = sut.Invert(input);

            for (var i = 0; i < expectedOutput.Count; i++)
            {
                Assert.AreEqual(expectedOutput[i], result[i]);
            }
        }
Esempio n. 4
0
        public void CanAddTwoNumbers()
        {
            var a        = _byteFactory.Create(100);
            var b        = _byteFactory.Create(50);
            var expected = _byteFactory.Create(150);

            var(sum, carry) = _sut.Add(a, b, false);

            for (var i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], sum[i]);
            }

            Assert.IsFalse(carry);
        }
Esempio n. 5
0
        public void Apply(IRegister <IByte> inputRegister, IRegister <IByte> outputRegister)
        {
            inputRegister.Apply();
            var secondRegisterInput = GetShifter(inputRegister);

            outputRegister.Input = _byteFactory.Create(secondRegisterInput);
            outputRegister.Apply();
        }
        public void AluOutputMapsToFlagsRegisterInput()
        {
            var byteOne = _byteFactory.Create(100);
            var byteTwo = _byteFactory.Create(100);

            var opCode = OpCodes.Add;

            _sut.Flags.Set = true;

            var result = _sut.Alu.Apply(byteOne, byteTwo, false, opCode);

            Assert.AreEqual(result.CarryOut, _sut.Flags.Data.C);
            Assert.AreEqual(result.ALarger, _sut.Flags.Data.A);
            Assert.AreEqual(result.Equal, _sut.Flags.Data.E);
            Assert.AreEqual(result.Zero, _sut.Flags.Data.Z);
        }
        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);
        }
Esempio n. 8
0
        public void CanAndByte()
        {
            var a        = new[] { true, true, true, true, true, true, true, true };
            var b        = a.Select(s => !s).ToArray();
            var expected = b;

            var opCode = OpCodes.And;

            var actual = _sut.Apply(_byteFactory.Create(a), _byteFactory.Create(b), false, opCode);

            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual.Output[i]);
            }
        }
        public void MarIsSetToAddressInIarInStepOne()
        {
            _sut.ComputerState.Iar.ApplyOnce(_byteFactory.Create(255));

            StepFull(1);

            var result = _sut.ComputerState.Ram.MemoryAddressRegister.Data;

            Assert.IsTrue(result.All(a => a));
        }