Пример #1
0
Файл: Ram.cs Проект: Y2JB/8-Bit
        public Ram(IBus bus, IControlUnit controlUnit, IRegister mar)
        {
            this.Bus      = bus;
            busOutputLine = controlUnit.GetControlLine(ControlLineId.RAM_OUT);
            busInputLine  = controlUnit.GetControlLine(ControlLineId.RAM_IN);

            this.mar = mar;

            // Setup the callback for when the bus output line goes high or low. Depending on which, we either start or stop driving the bus
            busOutputLine.onTransition = () =>
            {
                if (busOutputLine.State == true)
                {
                    Bus.Driver = this;
                }
                else
                {
                    if (Bus.Driver == this)
                    {
                        Bus.Driver = null;
                    }
                }
                return(true);
            };

            // Setup the callback for when the bus output line goes high or low. Depending on which, we either start or stop driving the bus
            busInputLine.onTransition = () =>
            {
                if (busInputLine.State == true)
                {
                    Write(Bus.Value);
                }
                return(true);
            };
        }
Пример #2
0
        public ProgramCounter(IClock clock, IBus bus, IControlUnit controlUnit)
        {
            this.Bus        = bus;
            busOutputLine   = controlUnit.GetControlLine(ControlLineId.PC_OUT);
            countEnableLine = controlUnit.GetControlLine(ControlLineId.PC_ENABLE);
            busInputLine    = controlUnit.GetControlLine(ControlLineId.PC_IN);
            clock.AddConnectedComponent(this);

            // Setup the callback for when the bus output line goes high or low. Depending on which, we either start or stop driving the bus
            busOutputLine.onTransition = () =>
            {
                if (busOutputLine.State == true)
                {
                    Bus.Driver = this;
                }
                else
                {
                    if (Bus.Driver == this)
                    {
                        Bus.Driver = null;
                    }
                }
                return(true);
            };
        }
Пример #3
0
        public Alu(IBus bus, IControlUnit controlUnit, IRegister aReg, IRegister bReg)
        {
            Bus = bus;

            this.aReg = aReg;
            this.bReg = bReg;

            busOutputLine = controlUnit.GetControlLine(ControlLineId.SUM_OUT);

            subLine = controlUnit.GetControlLine(ControlLineId.SUBTRACT);
            subLine.onTransition = () =>
            {
                // When the sub line changes, pull the value to refresh it, and the flags
                byte val = Value;
                return(true);
            };


            busOutputLine.onTransition = () =>
            {
                if (busOutputLine.State == true)
                {
                    Bus.Driver = this;
                }
                else
                {
                    if (Bus.Driver == this)
                    {
                        Bus.Driver = null;
                    }
                }
                return(true);
            };
        }
Пример #4
0
        public Clock(IControlUnit controlUnit)
        {
            //HltLine = controlUnit.GetControlLine(ControlLineId.HLT);
            FrequencyHz = 1;
            ClockMode   = Mode.Stepped;

            clockConnectedComponents = new List <IClockConnectedComponent>();

            HltLine = controlUnit.GetControlLine(ControlLineId.HLT);
        }
Пример #5
0
        public FlagsRegister4Bit(SystemRegister id, IClock clock, IControlUnit controlUnit, IAlu alu)
        {
            this.id = id;
            Value   = 0;

            this.controlUnit = controlUnit;

            this.alu = alu;

            clock.AddConnectedComponent(this);

            updateFlagsLine = controlUnit.GetControlLine(ControlLineId.UPDATE_FLAGS);
        }
Пример #6
0
        public Register(SystemRegister id, IClock clock, IBus bus, IControlUnit controlUnit)
        {
            this.id = id;
            Bus     = bus;
            Value   = 0;

            this.controlUnit = controlUnit;

            clock.AddConnectedComponent(this);

            switch (id)
            {
            case SystemRegister.A:
                busOutputLine = controlUnit.GetControlLine(ControlLineId.A_REG_OUT);
                busInputLine  = controlUnit.GetControlLine(ControlLineId.A_REG_IN);
                break;

            case SystemRegister.B:
                busOutputLine = controlUnit.GetControlLine(ControlLineId.B_REG_OUT);
                busInputLine  = controlUnit.GetControlLine(ControlLineId.B_REG_IN);
                break;

            case SystemRegister.MAR:
                busOutputLine = null;
                busInputLine  = controlUnit.GetControlLine(ControlLineId.MAR_IN);
                break;

            case SystemRegister.IR:
                busOutputLine = null;
                busInputLine  = controlUnit.GetControlLine(ControlLineId.IR_IN);
                break;

            case SystemRegister.IR_PARAM:
                busOutputLine = controlUnit.GetControlLine(ControlLineId.IR_PARAM_OUT);
                busInputLine  = controlUnit.GetControlLine(ControlLineId.IR_PARAM_IN);
                break;

            case SystemRegister.OUT:
                busOutputLine = null;
                busInputLine  = controlUnit.GetControlLine(ControlLineId.OUT_REG_IN);
                break;

            default:
                throw new ArgumentException("missing reg type");
            }

            // Setup the callback for when the bus output line goes high or low. Depending on which, we either start or stop driving the bus
            if (busOutputLine != null)
            {
                busOutputLine.onTransition = () =>
                {
                    if (busOutputLine.State == true)
                    {
                        Bus.Driver = this;
                    }
                    else
                    {
                        if (Bus.Driver == this)
                        {
                            Bus.Driver = null;
                        }
                    }
                    return(true);
                };
            }
        }