示例#1
0
        /// <summary>
        /// Stores a <see cref="byte"/> at the specified location in memory.
        /// </summary>
        /// <param name="address">Address to store at.</param>
        /// <param name="value">Data to store.</param>
        public void SetU8(ushort address, byte value)
        {
            if (!ValidAddress(address, sizeof(byte)))
            {
                throw MemoryException(address);
            }

            memory[address] = value;

            MemoryWrite?.Invoke(this, new MemoryWriteEventArgs(address, value));
        }
示例#2
0
        public AdaFruitST7735(
            Cpu.Pin chipSelect, 
            Cpu.Pin dc, 
            Cpu.Pin reset, 
            SPI.SPI_module spiModule = SPI.SPI_module.SPI1, 
            uint speedKHz = (uint)9500, 
            VirtualMemory vm = null)
        {
            Width = 128;
            Height = 160;

            AutoRefreshScreen = false;

            DataCommand = new OutputPort(dc, false);
            Reset = new OutputPort(reset, true);

            var extendedSpiConfig = new ExtendedSpiConfiguration(
                SPI_mod: spiModule,
                ChipSelect_Port: chipSelect,
                ChipSelect_ActiveState: false,
                ChipSelect_SetupTime: 0,
                ChipSelect_HoldTime: 0,
                Clock_IdleState: false,
                Clock_Edge: true,
                Clock_RateKHz: speedKHz,
                BitsPerTransfer: 8);

            Spi = new SPI(extendedSpiConfig);

            if (vm == null) {
                SpiBuffer = new byte[Width * Height * sizeof(ushort)];
                MemoryWriteFunction = SpiBufferWrite;
            } else {
                VM = vm;
                MemoryWriteFunction = VirtualMemoryWrite;
            }

            Initialize();
        }
        private BitwiseMultiwayMux m_gJumpMux;//an example of a control unit compnent - a mux that controls whether a jump is made


        private void ConnectControls()
        {
            //1. connect control of mux 1 (selects entrance to register A)
            m_gAMux.ConnectControl(Instruction[Type]);
            //2. connect control to mux 2 (selects A or M entrance to the ALU)
            m_gMAMux.ConnectControl(Instruction[A]);
            //3. consider all instruction bits only if C type instruction (MSB of instruction is 1)

            //4. connect ALU control bits
            m_gALU.ZeroX.ConnectInput(Instruction[C1]);
            m_gALU.NotX.ConnectInput(Instruction[C2]);
            m_gALU.ZeroY.ConnectInput(Instruction[C3]);
            m_gALU.NotY.ConnectInput(Instruction[C4]);
            m_gALU.F.ConnectInput(Instruction[C5]);
            m_gALU.NotOutput.ConnectInput(Instruction[C6]);
            //5. connect control to register D (very simple)
            and_D.ConnectInput1(Instruction[D2]);
            and_D.ConnectInput2(Instruction[Type]);
            m_rD.Load.ConnectInput(and_D.Output);
            //6. connect control to register A (a bit more complicated)
            not_A.ConnectInput(Instruction[Type]);
            or_A.ConnectInput1(not_A.Output);
            or_A.ConnectInput2(Instruction[D1]);
            m_rA.Load.ConnectInput(or_A.Output);
            //7. connect control to MemoryWrite
            and_MW.ConnectInput1(Instruction[D3]);
            and_MW.ConnectInput2(Instruction[Type]);
            MemoryWrite.ConnectInput(and_MW.Output);
            //8. create inputs for jump mux
            not_Zero.ConnectInput(m_gALU.Zero);
            not_Neg.ConnectInput(m_gALU.Negative);
            and_JMP.ConnectInput1(not_Zero.Output);
            and_JMP.ConnectInput2(not_Neg.Output);
            //not3.ConnectInput(m_gALU.Negative);
            or_JMP.ConnectInput2(m_gALU.Negative);
            or_JMP.ConnectInput1(m_gALU.Zero);
            //not4.ConnectInput(m_gALU.Zero);
            //or2.ConnectInput1(m_gALU.Zero);
            //or2.ConnectInput2(m_gALU.Negative);

            //9. connect jump mux (this is the most complicated part)
            m_gJumpMux = new BitwiseMultiwayMux(1, 3);
            J_0.ConnectInput(wi1);
            m_gJumpMux.Inputs[0][0].ConnectInput(J_0);
            JGT.ConnectInput(and_JMP.Output);
            m_gJumpMux.Inputs[1][0].ConnectInput(JGT);
            JEQ.ConnectInput(m_gALU.Zero);
            m_gJumpMux.Inputs[2][0].ConnectInput(JEQ);
            JGE.ConnectInput(not_Neg.Output);
            m_gJumpMux.Inputs[3][0].ConnectInput(JGE);
            JLT.ConnectInput(m_gALU.Negative);
            m_gJumpMux.Inputs[4][0].ConnectInput(JLT);
            JNE.ConnectInput(not_Zero.Output);
            m_gJumpMux.Inputs[5][0].ConnectInput(JNE);
            JLE.ConnectInput(or_JMP.Output);
            m_gJumpMux.Inputs[6][0].ConnectInput(JLE);
            wi2.Value = 1;
            J_1.ConnectInput(wi2);
            m_gJumpMux.Inputs[7][0].ConnectInput(J_1);
            and_JM2.ConnectInput1(Instruction[Type]);
            and_JM2.ConnectInput2(Instruction[J1]);
            and_JM1.ConnectInput1(Instruction[Type]);
            and_JM1.ConnectInput2(Instruction[J2]);
            and_JM0.ConnectInput1(Instruction[Type]);
            and_JM0.ConnectInput2(Instruction[J3]);
            JMP[2].ConnectInput(and_JM2.Output);
            JMP[1].ConnectInput(and_JM1.Output);
            JMP[0].ConnectInput(and_JM0.Output);
            m_gJumpMux.ConnectControl(JMP);
            //10. connect PC load control
            m_rPC.ConnectLoad(m_gJumpMux.Output[0]);
        }
示例#4
0
        private void ConnectControls()
        {
            or       = new OrGate();
            muxArray = new MuxGate[9];
            NotGate not = new NotGate();

            JGT      = new AndGate();
            JGE      = new OrGate();
            JLE      = new OrGate();
            JNE      = new NotGate();
            notArray = new NotGate[2];

            for (int i = 0; i < notArray.Length; i++)
            {
                notArray[i] = new NotGate();
            }

            m_gJumpMux = new BitwiseMultiwayMux(1, 3);
            jump       = new WireSet(3);

            andForPCLoad = new AndGate();
            Wire PCLoad = new Wire();

            //1.
            m_gAMux.ConnectControl(Instruction[Type]);

            //2. connect control to mux 2 (selects A or M entrance to the ALU)
            m_gMAMux.ConnectControl(Instruction[A]);

            //3. consider all instruction bits only if C type instruction (MSB of instruction is 1)
            for (int i = 0; i < muxArray.Length; i++)
            {
                muxArray[i] = new MuxGate();
                muxArray[i].ConnectInput1(new Wire());
                muxArray[i].ConnectInput2(Instruction[i + 3]);
                muxArray[i].ConnectControl(Instruction[Type]);
            }
            //4. connect ALU control bits
            m_gALU.ZeroX.ConnectInput(muxArray[C1 - 3].Output);
            m_gALU.NotX.ConnectInput(muxArray[C2 - 3].Output);
            m_gALU.ZeroY.ConnectInput(muxArray[C3 - 3].Output);
            m_gALU.NotY.ConnectInput(muxArray[C4 - 3].Output);
            m_gALU.F.ConnectInput(muxArray[C5 - 3].Output);
            m_gALU.NotOutput.ConnectInput(muxArray[C6 - 3].Output);

            //5. connect control to register D (very simple)
            m_rD.Load.ConnectInput(muxArray[D2 - 3].Output);

            //6. connect control to register A (a bit more complicated)
            not.ConnectInput(Instruction[Type]);
            or.ConnectInput1(not.Output);
            or.ConnectInput2(muxArray[D1 - 3].Output);
            m_rA.Load.ConnectInput(or.Output);

            //7. connect control to MemoryWrite
            MemoryWrite.ConnectInput(muxArray[D3 - 3].Output);
            //8. create inputs for jump mux
            notArray[0].ConnectInput(m_gALU.Zero);
            notArray[1].ConnectInput(m_gALU.Negative);
            //JGT:
            JGT.ConnectInput1(notArray[0].Output);
            JGT.ConnectInput2(notArray[1].Output);
            //JGE:
            JGE.ConnectInput1(m_gALU.Zero);
            JGE.ConnectInput2(notArray[1].Output);
            //JNE:
            JNE.ConnectInput(notArray[0].Output);
            //JLE:
            JLE.ConnectInput1(m_gALU.Zero);
            JLE.ConnectInput2(m_gALU.Negative);


            WireSet JGTOut = new WireSet(1);
            WireSet JEQOut = new WireSet(1);
            WireSet JLTOut = new WireSet(1);
            WireSet JGEOut = new WireSet(1);
            WireSet JNEOut = new WireSet(1);
            WireSet JLEOut = new WireSet(1);

            JGTOut[0].ConnectInput(JGT.Output);
            JEQOut[0].ConnectInput(m_gALU.Zero);
            JLTOut[0].ConnectInput(m_gALU.Negative);
            JGEOut[0].ConnectInput(JGE.Output);
            JNEOut[0].ConnectInput(JNE.Output);
            JLEOut[0].ConnectInput(JLE.Output);

            //9. connect jump mux (this is the most complicated part)
            jump[0].ConnectInput(Instruction[J3]);
            jump[1].ConnectInput(Instruction[J2]);
            jump[2].ConnectInput(Instruction[J1]);
            m_gJumpMux.ConnectControl(jump);
            m_gJumpMux.ConnectInput(0, new WireSet(1));
            m_gJumpMux.ConnectInput(1, JGTOut);
            m_gJumpMux.ConnectInput(2, JEQOut);
            m_gJumpMux.ConnectInput(3, JGEOut);
            m_gJumpMux.ConnectInput(4, JLTOut);
            m_gJumpMux.ConnectInput(5, JNEOut);
            m_gJumpMux.ConnectInput(6, JLEOut);
            m_gJumpMux.Inputs[7].Value = 1;
            //10. connect PC load control
            andForPCLoad.ConnectInput1(m_gJumpMux.Output[0]);
            andForPCLoad.ConnectInput2(Instruction[Type]);
            m_rPC.ConnectLoad(andForPCLoad.Output);
        }
示例#5
0
文件: CPU16.cs 项目: boaz23/ECS
 private void ConnectMemoryWrite()
 {
     MemoryWrite.ConnectInput(m_gInstructionMux.Output[D3]);
 }
示例#6
0
文件: CPU16.cs 项目: LueeAkasha/ECS
        private void ConnectControls()
        {
            //1. connect control of mux 1 (selects entrance to register A)

            m_gAMux.ConnectControl(Instruction[Type]); // opcode

            //2. connect control to mux 2 (selects A or M entrance to the ALU)

            m_gMAMux.ConnectControl(Instruction[A]);  //  a/m

            //3. consider all instruction bits only if C type instruction (MSB of instruction is 1)


            //4. connect ALU control bits

            m_gALU.ZeroX.ConnectInput(Instruction[C1]);
            m_gALU.NotX.ConnectInput(Instruction[C2]);
            m_gALU.ZeroY.ConnectInput(Instruction[C3]);
            m_gALU.NotY.ConnectInput(Instruction[C4]);
            m_gALU.F.ConnectInput(Instruction[C5]);
            m_gALU.NotOutput.ConnectInput(Instruction[C6]);

            //5. connect control to register D (very simple)
            and = new AndGate();
            and.ConnectInput1(Instruction[Type]);
            and.ConnectInput2(Instruction[D2]);
            m_rD.Load.ConnectInput(and.Output);


            //6. connect control to register A (a bit more complicated)
            orOfA = new OrGate(); // shortcut for what we did in lesson "instead using and & not gates"

            // to implement as in lecture
            andOfA = new AndGate();
            notOfA = new NotGate();
            notOfA.ConnectInput(Instruction[Type]);
            andOfA.ConnectInput1(Instruction[Type]);
            andOfA.ConnectInput2(Instruction[D1]);
            orOfA.ConnectInput1(andOfA.Output);
            orOfA.ConnectInput2(notOfA.Output);
            m_rA.Load.ConnectInput(orOfA.Output);
            //7. connect control to MemoryWritea
            andOfMemoryWrite = new AndGate();
            andOfMemoryWrite.ConnectInput1(Instruction[Type]);
            andOfMemoryWrite.ConnectInput2(Instruction[D3]);
            MemoryWrite.ConnectInput(andOfMemoryWrite.Output);

            //8. create inputs for jump mux
            Wire on = new Wire();

            on.Value = 1;
            Wire off = new Wire();

            off.Value = 0;

            m_gJumpMux = new BitwiseMultiwayMux(1, 3);  // so i'm gonna use it as jump box in lesson
            jumpOr1    = new OrGate();
            jumpOr1.ConnectInput1(m_gALU.Zero);
            jumpOr1.ConnectInput2(m_gALU.Negative);
            jumpNot1 = new NotGate();
            jumpNot1.ConnectInput(jumpOr1.Output);
            jumpNot2 = new NotGate();
            jumpNot2.ConnectInput(m_gALU.Negative);
            jumpNot3 = new NotGate();
            jumpNot3.ConnectInput(m_gALU.Zero);
            jumpOr2 = new OrGate();
            jumpOr2.ConnectInput1(m_gALU.Zero);
            jumpOr2.ConnectInput2(m_gALU.Negative);

            Wire input1 = off; // we did somthing like this in practical session
            Wire input2 = jumpNot1.Output;
            Wire input3 = m_gALU.Zero;
            Wire input4 = jumpNot2.Output;
            Wire input5 = m_gALU.Negative;
            Wire input6 = jumpNot3.Output;
            Wire input7 = jumpOr2.Output;
            Wire input8 = on;


            //9. connect jump mux (this is the most complicated part
            m_gJumpMux.Inputs[0][0].ConnectInput(input1);
            m_gJumpMux.Inputs[1][0].ConnectInput(input2);
            m_gJumpMux.Inputs[2][0].ConnectInput(input3);
            m_gJumpMux.Inputs[3][0].ConnectInput(input4);
            m_gJumpMux.Inputs[4][0].ConnectInput(input5);
            m_gJumpMux.Inputs[5][0].ConnectInput(input6);
            m_gJumpMux.Inputs[6][0].ConnectInput(input7);
            m_gJumpMux.Inputs[7][0].ConnectInput(input8);

            m_gJumpMux.Control[0].ConnectInput(Instruction[J3]);
            m_gJumpMux.Control[1].ConnectInput(Instruction[J2]);
            m_gJumpMux.Control[2].ConnectInput(Instruction[J1]);

            //10. connect PC load control
            andOfpc = new AndGate();
            andOfpc.ConnectInput1(Instruction[Type]);
            andOfpc.ConnectInput2(m_gJumpMux.Output[0]);


            m_rPC.ConnectLoad(andOfpc.Output);
        }