Example #1
0
File: Ram.cs Project: 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);
            };
        }
Example #2
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);
            };
        }
Example #3
0
 /// <summary>
 /// Constructor for injecting an observed set of registers for unit testing.
 /// </summary>
 /// <param name="mmu">
 /// Memory subsystem of the Game Boy
 /// </param>
 /// <param name="reg">
 /// A Set of registers that the CPU needs. Here the registers are being injected,
 /// so that they can be observed by unit tests.
 /// </param>
 public CPU(MMU mmu, IRegisters reg)
 {
     Registers   = reg;
     clock       = new Clock();
     this.mmu    = mmu;
     ControlUnit = new ControlUnit(mmu, reg);
 }
Example #4
0
 public CPU(MMU mmu, Clock clock)
 {
     this.clock       = clock;
     this.mmu         = mmu;
     this.Registers   = new Registers(mmu);
     this.ControlUnit = new ControlUnit(mmu, this.Registers);
 }
Example #5
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);
            };
        }
Example #6
0
 /// <summary>
 /// Checks whether control unit is null
 /// </summary>
 /// <param name="unit">Control unit to check</param>
 /// <exception cref="ArgumentNullException">If control unit is null</exception>
 protected void CheckControlUnitOnNull(IControlUnit unit)
 {
     if (Object.ReferenceEquals(unit, null))
     {
         throw new ArgumentNullException("Control unit you passed as a param is null");
     }
 }
Example #7
0
 /// <summary>
 /// Create new vending machine
 /// </summary>
 /// <param name="controlUnit">Control unit</param>
 /// <exception cref="ArgumentNullException">If control unit is null</exception>
 public VendingMachine(IControlUnit controlUnit)
 {
     if (controlUnit == null)
     {
         throw new ArgumentNullException("Control unit you passed as a param is null.");
     }
     ControlUnit = controlUnit;
     controlUnit.SwitchToState(new InsertCoinState(controlUnit));
 }
        public void SetUp()
        {
            // arrange
            controlUnit = new ControlUnit(
                new[] { 0, 1, 2, 3, 4, 5, 6, 7 },
                new[] { 'A', 'B', 'C', 'D', 'E', 'F' });

            ModelInitializer.Initialize(controlUnit);
        }
Example #9
0
File: Clock.cs Project: Y2JB/8-Bit
        public Clock(IControlUnit controlUnit)
        {
            //HltLine = controlUnit.GetControlLine(ControlLineId.HLT);
            FrequencyHz = 1;
            ClockMode   = Mode.Stepped;

            clockConnectedComponents = new List <IClockConnectedComponent>();

            HltLine = controlUnit.GetControlLine(ControlLineId.HLT);
        }
Example #10
0
 /// <summary>
 /// Create new InsertCoinState, respect previous state properties
 /// </summary>
 /// <param name="state">Previous state of this machine</param>
 /// <param name="unit">Control unit</param>
 /// <exception cref="ArgumentNullException">If control unit is null</exception>
 public InsertCoinState(IState state, IControlUnit unit)
 {
     base.CheckControlUnitOnNull(unit);
     ControlUnit = unit;
     ControlUnit.SwitchToState(this);
     if (state != null)
     {
         Credit = state.Credit;
         SelectedCoordinates = state.SelectedCoordinates;
     }
 }
Example #11
0
        public void PushesPops()
        {
            cu = new ControlUnit(mmu, reg);
            var spStart = --reg.SP;

            cu.Push(0xfe1b);
            cu.Push(0x1f2e);

            Assert.That(cu.POP(), Is.EqualTo(0x1f2e));
            Assert.That(cu.POP(), Is.EqualTo(0xfe1b));
        }
 /// <summary>
 /// Create new ConfirmOrderState​, respect previous state properties
 /// </summary>
 /// <param name="state">Previous state of this machine</param>
 /// <param name="unit">Control unit</param>
 /// <exception cref="ArgumentNullException">If control unit is null</exception>
 public ConfirmOrderState​(IState state, IControlUnit unit)
 {
     if (state == null)
     {
         unit.SwitchToState(new InsertCoinState(unit));
     }
     base.CheckControlUnitOnNull(unit);
     ControlUnit         = unit;
     Credit              = state.Credit;
     SelectedCoordinates = state.SelectedCoordinates;
 }
Example #13
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);
        }
Example #14
0
 public ControlTimerService(
     IControlUnit controlUnit,
     IPressureContainer pressureContainer,
     IPressureSensor pressureSensor,
     IHubContext <ReactorHub> reactorHub,
     ILogger <ControlTimerService> logger)
 {
     _controlUnit       = controlUnit;
     _pressureContainer = pressureContainer;
     _pressureSensor    = pressureSensor;
     _reactorHub        = reactorHub;
     _logger            = logger;
 }
Example #15
0
        /// <summary>
        /// Initializes vending machine with several stocks
        /// </summary>
        /// <param name="controlUnit"></param>
        public static void Initialize(IControlUnit controlUnit)
        {
            var cocaCola     = CreateStock("Coca Cola 250ml", 30, 8);
            var sprite       = CreateStock("Sprite 250ml", 25, 6);
            var bakeRolls    = CreateStock("Bake Rolls 150g", 35, 4);
            var snickers     = CreateStock("Snickers 50g", 20, 9);
            var evian        = CreateStock("Evian 500ml", 30, 1);
            var bohemiaChips = CreateStock("Bohemia Chips 25g", 25, 4);
            var twix         = CreateStock("Twix 40g", 15, 0);
            var mattoni      = CreateStock("Mattoni 250ml", 25, 5);

            controlUnit.SetStockOnCoordinates(new Coordinates(3, 'D'), cocaCola);
            controlUnit.SetStockOnCoordinates(new Coordinates(2, 'D'), sprite);
            controlUnit.SetStockOnCoordinates(new Coordinates(0, 'A'), bakeRolls);
            controlUnit.SetStockOnCoordinates(new Coordinates(5, 'B'), snickers);
            controlUnit.SetStockOnCoordinates(new Coordinates(2, 'F'), evian);
            controlUnit.SetStockOnCoordinates(new Coordinates(7, 'E'), bohemiaChips);
            controlUnit.SetStockOnCoordinates(new Coordinates(4, 'C'), twix);
            controlUnit.SetStockOnCoordinates(new Coordinates(7, 'F'), mattoni);
        }
 /// <summary>
 /// Create new 'blank' ConfirmOrderState​ (but in fact this will just create new 'blank' InsertCoinState(IControlUnit)
 /// </summary>
 /// <param name="unit">Control unit</param>
 public ConfirmOrderState​(IControlUnit unit) : this(null, unit)
 {
 }
Example #17
0
 /// <summary>
 /// Create new 'blank' SelectCoordinatesState (but in fact this will just create new 'blank' InsertCoinState(IControlUnit)
 /// </summary>
 /// <param name="unit">Control unit</param>
 public SelectCoordinatesState(IControlUnit unit) : this(null, unit)
 {
 }
Example #18
0
 public ICompositeObject AddControlUnit(IControlUnit unit)
 {
     AddContolUnitInternal(unit);
     return(this);
 }
Example #19
0
 protected void AddContolUnitInternal(IControlUnit unit)
 {
     _all.Add(unit);
     unit.Parent = this;
 }
Example #20
0
 protected void AddContolUnitInternal(IControlUnit unit)
 {
     _all.Add(unit);
 }
Example #21
0
 public MicrostepCounter(IClock clock, IControlUnit controlUnit)
 {
     clock.AddConnectedComponent(this);
     this.controlUnit = controlUnit;
 }
Example #22
0
 public ICompositeObject AddControlUnit(IControlUnit unit)
 {
     AddContolUnitInternal(unit);
     return this;
 }
Example #23
0
 protected void AddContolUnitInternal(IControlUnit unit)
 {
     _all.Add(unit);
     unit.Parent = this;
 }
Example #24
0
 /// <summary>
 /// Create new 'blank' InsertCoinState
 /// </summary>
 /// <param name="unit">Control unit</param>
 public InsertCoinState(IControlUnit unit) : this(null, unit)
 {
 }
Example #25
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);
                };
            }
        }
Example #26
0
 public Machine(IControlUnit control, IItemProvider provider)
 {
     _provider              = provider;
     _provider.ItemArrived += control.item_handler;
 }