示例#1
0
            public void Should_advance_program_counter_if_instruction_jumped_in_previous_execution()
            {
                TestedInstruction = new TestInstruction(1)
                {
                    ExecuteInternalAction = (self, givenState) =>
                    {
                        var jmp = self.PublicGetParameterValue(1);
                        if (jmp > 0)
                        {
                            self.PublicJump(jmp);
                        }
                    },
                    ParameterModes = 1
                };

                var state = new ComputerState
                {
                    Memory = new[] { 0, 2, 1, 0 }
                };

                TestedInstruction.Execute(state);
                TestedInstruction.Execute(state);

                Assert.Equal(4, state.ProgramCounter);
            }
示例#2
0
    /// <summary>
    /// Called when a computer randomly crashes
    /// </summary>
    private void crashComputer()
    {
        // Only allow waiting to crash computers to crash
        if (_state == ComputerState.WaitingToCrash || _state == ComputerState.RaptorCrashingComputer)
        {
            SetComputerColour(_state == ComputerState.WaitingToCrash ? Color.magenta : Color.yellow);
            _state = ComputerState.Crashed;

            if (linkedDoor != null)
            {
                linkedDoor.ReleaseTheRaptor();
            }

            _crashTimer  = CM.TimeFromCrashToExplode;
            _timerLength = _crashTimer;
            pBar.gameObject.SetActive(true);
            // Release the raptor (if it hasn't already been released and there is one associated with this computer
            if (currentRaptorUser != null)
            {
                currentRaptorUser.FindNewTarget();
                currentRaptorUser._rState = RaptorAI.RaptorState.HeadingToTarget;
                currentRaptorUser         = null;
            }
        }
    }
示例#3
0
            public void Should_write_existing_input_before_awaiting_more_input(
                int[] inputsAtStart,
                int executions)
            {
                var testOpCode = 1;
                var prg        = AssembleTestProgram(executions, testOpCode);

                var state = new ComputerState
                {
                    Memory = prg.ToArray(),
                    Inputs = new List <int>(inputsAtStart)
                };

                for (int i = 0; i < executions; i++)
                {
                    TestedInstruction.Execute(state);
                }

                for (int i = 0; i < executions - 1; i++)
                {
                    Assert.Equal(inputsAtStart[i], state.Memory[i * 2]);
                }
                Assert.Equal(
                    testOpCode,
                    state.Memory[(executions - 1) * 2]);
            }
示例#4
0
 private void On_Click(object sender, RoutedEventArgs e)
 {
     Screen.Items.Add(computer.ComputerOn());
     computerState = ComputerState.ON;
     Monitor.Fill  = Brushes.Yellow;
     countPrograms = 0;
 }
示例#5
0
            public void Should_resume_reading_input_after_input_has_been_added(
                int[] inputsAtStart,
                int executions,
                int addedInput)
            {
                var testOpCode = 11;
                var prg        = AssembleTestProgram(executions, testOpCode);

                var state = new ComputerState
                {
                    Memory = prg.ToArray(),
                    Inputs = new List <int>(inputsAtStart)
                };

                for (int i = 0; i < executions; i++)
                {
                    TestedInstruction.Execute(state);
                }

                state.Inputs.Add(addedInput);
                TestedInstruction.Execute(state);

                Assert.Equal(
                    addedInput,
                    state.Memory[(executions - 1) * 2]);
            }
        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);
        }
示例#7
0
    // Start is called before the first frame update
    void Start()
    {
        if (pBar == null)
        {
            pBar = this.gameObject.GetComponentInChildren <LinearProgressBarController> (true);
        }

        computerSpeaker = GetComponent <AudioSource> ();


        CC = GetComponent <CrashController> ();
        CM = FindObjectOfType <ComputerManager> ();

        if (computerID == 0)
        {
            computerID = Random.Range(0, 100);
        }

        // Pick a random computer type
        computerType = (ComputerType)Random.Range(0, System.Enum.GetValues(typeof(ComputerType)).Length);
        _state       = ComputerState.WaitingToCrash;

        // if the timer is greater than 0, we must have set it in the ComputerManager->start, so don't over write it
        if (_crashTimer <= 0)
        {
            _crashTimer = Random.Range(CM.MinDefaultComputerCrashTime, CM.MaxDefaultComputerCrashTime);
        }
    }
示例#8
0
 void resetComputerToNeutral()
 {
     if (computerState != ComputerState.NOT_COMPUTER)
     {
         computerState = ComputerState.NEUTRAL;
     }
 }
示例#9
0
 public ComputerState(ComputerState state)
     : base(state)
 {
     Address      = state.Address;
     MacAddress   = state.MacAddress;
     Power        = state.Power;
     MonitorPower = state.MonitorPower;
 }
示例#10
0
            public void Should_set_halt_to_true_on_state()
            {
                var state = new ComputerState();

                TestedInstruction.Execute(state);

                Assert.True(state.Halt);
            }
示例#11
0
            public void Should_call_ExecuteInternal_on_derived_class_with_given_state()
            {
                var state = new ComputerState();

                TestedInstruction.Execute(state);

                Assert.True(_executeInternalExecuted, "ExecuteInternal not called.");
            }
示例#12
0
 public string ComputerOn()
 {
     if (State == ComputerState.OFF)
     {
         State = ComputerState.ON;
     }
     return("Включение");
 }
示例#13
0
 public string ComputerOff()
 {
     if (State == ComputerState.ON)
     {
         State = ComputerState.OFF;
     }
     return("Выключение");
 }
示例#14
0
 public void RaptorInterferenceInterferedWith()
 {
     _state        = ComputerState.WaitingToCrash;
     pBar.progress = 0;
     pBar.gameObject.SetActive(false);
     currentRaptorUser = null;
     _crashTimer       = Random.Range(CM.MinDefaultComputerCrashTime, CM.MaxDefaultComputerCrashTime);
 }
示例#15
0
    public void rebootComputer()
    {
        if (_state == ComputerState.Crashed)
        {
            _state      = ComputerState.WaitingToCrash;
            _crashTimer = Random.Range(3f, 20f);

            SetComputerColour(Color.white);
        }
    }
示例#16
0
 // Start is called before the first frame update
 void Start()
 {
     if (computerID == 0)
     {
         computerID = Random.Range(0, 100);
     }
     computerType = (ComputerType)Random.Range(0, System.Enum.GetValues(typeof(ComputerType)).Length);
     _state       = ComputerState.WaitingToCrash;
     _crashTimer  = Random.Range(3f, 20f);
 }
 public void StopDiscovery()
 {
     if (discovered)
     {
         State = ComputerState.Online;
     }
     else
     {
         State = ComputerState.Offline;
     }
 }
示例#18
0
            public void Should_advance_program_counter_with_length_of_instruction()
            {
                var state = new ComputerState
                {
                    Memory = new[] { 0, 0 }
                };

                TestedInstruction.Execute(state);

                Assert.Equal(1, state.ProgramCounter);
            }
示例#19
0
        private bool UpdateNextInstructions(int jmpNextInstruction)
        {
            m_CurrentInstruction += jmpNextInstruction;
            if (m_CurrentInstruction < m_Instructions.Count)
            {
                return(true);
            }

            State = ComputerState.Finished;
            return(false);
        }
示例#20
0
        public int Run()
        {
            ComputerState = ComputerState.Running;
            while (ComputerState == ComputerState.Running)
            {
                var operation = GetOperation(instructions[pointer]);
                Execute(operation);
            }

            return(instructions[0]);
        }
示例#21
0
 private void TrainedRaptorAtComputer()
 {
     SetComputerColour(Color.cyan);
     _crashTimer = 0;
     _state      = ComputerState.RaptorSafelyUsingComputer;
     pBar.gameObject.SetActive(false);           // Ensure the progress bar gets hidden
     CC.CancelCrashEffects();
     CM.ContentRaptors++;
     // So player can't click on computer anymore
     this.gameObject.layer = LayerMask.NameToLayer("NonComputer");
 }
示例#22
0
 /// <summary>
 /// If the first parameter is zero,
 /// it sets the instruction pointer to the value from the second parameter.
 /// Otherwise, it does nothing.
 /// </summary>
 private static long JumpIfFalse(ComputerState state, ref long i, Mode[] modes)
 {
     if (state.Get(i + 1, modes[0]) == 0)
     {
         i = state.Get(i + 2, modes[1]);
         return(0);// 0 to skip incrementing and let this ref change take precedence
     }
     else
     {
         return(2);
     }
 }
示例#23
0
            public void Should_write_value_from_addr1_to_state_output(
                int[] prg)
            {
                var state = new ComputerState
                {
                    Memory = (int[])prg.Clone()
                };

                TestedInstruction.Execute(state);

                Assert.Equal(1, state.Output[0]);
            }
示例#24
0
 public void rebootComputer()
 {
     if (_state == ComputerState.Crashed || _state == ComputerState.RaptorCrashingComputer)
     {
         _state       = ComputerState.Rebooting;
         _crashTimer  = rebootTime;
         _timerLength = _crashTimer;
         pBar.gameObject.SetActive(true);
         SetComputerColour(Color.green);
         FindObjectOfType <PlayerControl> ()._pState = PlayerControl.playerState.RebootingComputer;
     }
 }
示例#25
0
            public void Should_handle_position_mode_for_parameters(
                int[] prg,
                int expected)
            {
                var state = new ComputerState
                {
                    Memory = prg
                };

                TestedInstruction.Execute(state);

                Assert.Equal(expected, _actual);
            }
示例#26
0
 /// <summary>
 /// Called the moment a Raptor starts to interact with a computer and puts it on the shortcut to crashing
 /// </summary>
 private void RaptorVisitsComputer(RaptorAI raptor)
 {
     if (_state == ComputerState.WaitingToCrash)
     {
         _state       = ComputerState.RaptorCrashingComputer;
         _crashTimer  = CM.TimeToCrashWithRaptor;
         _timerLength = _crashTimer;
         pBar.gameObject.SetActive(true);
         raptor._rState    = RaptorAI.RaptorState.FiddlingWithComputer;
         currentRaptorUser = raptor;
         computerSpeaker.PlayOneShot(CM.TypingSound);
     }
 }
示例#27
0
            public void Should_handle_immediate_mode_for_parameters(
                int[] prg,
                int expected)
            {
                var state = new ComputerState
                {
                    Memory = prg
                };

                TestedInstruction.ParameterModes = 1 << (prg[0] - 1);

                TestedInstruction.Execute(state);

                Assert.Equal(expected, _actual);
            }
示例#28
0
        public void Execute(ComputerState state)
        {
            _jumped = false;

            State = state;

            ExecuteInternal();

            if (_jumped)
            {
                return;
            }

            state.ProgramCounter += Length;
        }
示例#29
0
            public void Should_store_state_input_at_addr1(
                int[] prg)
            {
                var state = new ComputerState
                {
                    Memory = (int[])prg.Clone(),
                    Inputs = new List <int> {
                        9
                    }
                };

                TestedInstruction.Execute(state);

                Assert.Equal(state.Inputs[0], state.Memory[prg[1]]);
            }
示例#30
0
            public void Should_reset_halt_and_awaitingInput_flags_after_resuming_successfully()
            {
                var prg = AssembleTestProgram(1);

                var state = new ComputerState
                {
                    Memory = prg.ToArray()
                };

                TestedInstruction.Execute(state);
                state.Inputs.Add(1337);
                state.Halt = false;
                TestedInstruction.Execute(state);

                Assert.False(state.AwaitingInput, "State waiting for input.");
            }
示例#31
0
    private void FinishedRoutines(ComputerState state)
    {
        switch (state)
        {
            case ComputerState.Nothing:
                //nothing to do here
                break;
            case ComputerState.Close:
                Gtk.Application.Invoke(delegate
                {
                    int lefttime = 30;
                    while (lefttime > 0)
                    {
                        if (ProcessCancelled) { UpdateInfo(InfoType.Default, 0); ProcessCancelled = false; return; }
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                        lefttime--;
                        InfoLabel.Text = "Will close DeSERt in "+ lefttime.ToString() +" seconds!";
                    }
                    InfoLabel.Text = "The end is near!";

                    Quit(ClosingReason.Program);
                });
                break;
            case ComputerState.Shutdown:
                Gtk.Application.Invoke(delegate
                {
                    int lefttime = 30;
                    while (lefttime > 0)
                    {
                        if (ProcessCancelled) { UpdateInfo(InfoType.Default, 0); ProcessCancelled = false; return; }
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                        lefttime--;
                        InfoLabel.Text = "Will shut down in " + lefttime.ToString() + " seconds!";
                    }
                    InfoLabel.Text = "The end is near!";

                    Process.Start("shutdown", "/s /t 0");
                });
                break;
            case ComputerState.Suspend:
                Gtk.Application.Invoke(delegate
                {
                    int lefttime = 30;
                    while (lefttime > 0)
                    {
                        if (ProcessCancelled) { UpdateInfo(InfoType.Default, 0); ProcessCancelled = false; return; }
                        Thread.Sleep(TimeSpan.FromSeconds(1));
                        lefttime--;
                        InfoLabel.Text = "Will suspend in " + lefttime.ToString() + " seconds!";
                    }
                    InfoLabel.Text = "Set computer to suspend state!";

                    SetSuspendState(false, true, true);
                });
                break;
        }
    }
示例#32
0
 public ComputerState(ComputerState state)
     : base(state)
 {
     Address = state.Address;
     MacAddress = state.MacAddress;
     Power = state.Power;
     MonitorPower = state.MonitorPower;
 }