Exemplo n.º 1
0
        public ControlUnitOutput Do(Byte2 data, bool clock)
        {
            var decodedInstruction = InstructionDecoder.Decode(data);

            var selectedSourceMemory =
                Select16.Do(decodedInstruction.SourceMemory,
                            _memoryOutput.Ram,
                            _memoryOutput.A);

            _aluOutput =
                ArithmeticLogicUnit.Do(decodedInstruction.Operation,
                                       _memoryOutput.D,
                                       selectedSourceMemory);

            _selectedBasedOnComputationInstruction =
                Select16.Do(decodedInstruction.ComputationInstruction,
                            _aluOutput,
                            decodedInstruction.w);

            _memoryOutput = _memory.Do(decodedInstruction.Destination,
                                       _selectedBasedOnComputationInstruction,
                                       clock);

            var isCondition =
                ArithmeticLogicUnit.Evaluate(decodedInstruction.Condition,
                                             _aluOutput);

            return(new ControlUnitOutput(isCondition, _memoryOutput.A));
        }
        public static Byte2 Do(bool zero, bool negate, Byte2 data)
        {
            var selectZero = Select16.Do(zero, new Byte2(0), data);

            var selectNegate = Select16.Do(negate, Gates.Invert16(selectZero), selectZero);

            return(selectNegate);
        }
Exemplo n.º 3
0
        /// <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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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 Byte2 Do(InstructionDecoder.Operation operation,
                               Byte2 dataX,
                               Byte2 dataY)
        {
            var transformedDataX = UnaryArithmeticLogicUnit.Do(operation.zx, operation.nx, dataX);

            var transformedDataY = UnaryArithmeticLogicUnit.Do(operation.zy, operation.ny, dataY);

            var and = Gates.And16(transformedDataX, transformedDataY);

            var add = Arithmetics.AddByte2(transformedDataX, transformedDataY, false);

            var selected = Select16.Do(operation.Function, add.Low, and);

            var inverted = Gates.Invert16(selected);

            var output = Select16.Do(operation.NegateOutput, inverted, selected);

            return(output);
        }