Exemplo n.º 1
0
        private void OnVmStep(Object vm, VirtualMachineStepArgs args)
        {
            if (args.Score != 0.0)
            {
                _scoreLabel.Text = args.Score.ToString();
            }

            _fuelLabel.Text = args.Fuel.ToString();
            _orbitVisualizer.SetOrbiterPos(new Vector2d(args.X, args.Y));
            _orbitVisualizer.Invalidate();
            _offsetLabel.Text = ((int)(args.Distance - args.TargetRadius)).ToString();
        }
Exemplo n.º 2
0
        private void OnVmStep(Object vm, VirtualMachineStepArgs args)
        {
            if (args.Score != 0.0)
            {
                _scoreLabel.Text = args.Score.ToString();
            }

            _elapsed++;

            _fuelLabel.Text = args.Fuel.ToString();
            _orbitVisualizer.SetOrbiterPos(args.Position);
            _orbitVisualizer.SetTargetPos(args.TargetPosition);
            _orbitVisualizer.Invalidate();
            _offsetLabel.Text       = ((int)(args.OrbitRadius - args.TargetOrbitRadius)).ToString();
            _targetOffsetLabel.Text = ((int)((args.Position - args.TargetPosition).length())).ToString();
        }
Exemplo n.º 3
0
        public VirtualMachineStepArgs Step()
        {
            Debug.Assert(Configuration != 0.0);

            for (int ip = 0; ip <= _program.Length; ip++)
            {
                #region Interpreter
                int frame = _program.Instructions[ip];
                if ((frame & (0xF0000000)) == 0) // S-Type
                {
                    int op  = frame >> 24;
                    int imm = (frame >> 21) & 0x07;
                    int r1  = frame & 0x3FFF;

                    switch (op)
                    {
                    case 0x0:     // noop
                        break;

                    case 0x1:     // Cmpz
                        switch (imm)
                        {
                        case 0x0:         // <
                            _status = _memory[r1] < 0.0;
                            break;

                        case 0x1:         // <=
                            _status = _memory[r1] <= 0.0;
                            break;

                        case 0x2:         // ==
                            _status = _memory[r1] == 0.0;
                            break;

                        case 0x3:         // >=
                            _status = _memory[r1] >= 0.0;
                            break;

                        case 0x4:         // >
                            _status = _memory[r1] > 0.0;
                            break;

                        default:
                            Debug.Assert(false, "Illegal S-Type ImmCode: " + String.Format("0x{0:x4}", imm));
                            break;
                        }
                        break;

                    case 0x2:     // Sqrt
                        _memory[ip] = Math.Sqrt(_memory[r1]);
                        break;

                    case 0x3:     // Copy
                        _memory[ip] = _memory[r1];
                        break;

                    case 0x4:     // Input
                        _memory[ip] = _input[r1];
                        break;

                    default:
                        Debug.Assert(false, "Illegal S-Type Opcode: " + String.Format("0x{0:x4}", op));
                        break;
                    }
                }
                else // D-Type
                {
                    int op = frame >> 28;
                    int r1 = (frame & 0x0FFFFFFF) >> 14;
                    int r2 = frame & 0x3FFF;

                    switch (op)
                    {
                    case 0x1:     // Add
                        _memory[ip] = _memory[r1] + _memory[r2];
                        break;

                    case 0x2:     // Subtract
                        _memory[ip] = _memory[r1] - _memory[r2];
                        break;

                    case 0x3:     // Multiply
                        _memory[ip] = _memory[r1] * _memory[r2];
                        break;

                    case 0x4:     // Divide
                        if (_memory[r2] == 0.0)
                        {
                            _memory[ip] = 0.0;
                        }
                        else
                        {
                            _memory[ip] = _memory[r1] / _memory[r2];
                        }
                        break;

                    case 0x5:     // Output
                        _output[r1] = _memory[r2];
                        break;

                    case 0x6:     // Phi
                        _memory[ip] = _status ? _memory[r1] : _memory[r2];
                        break;

                    default:
                        Debug.Assert(false, "Illegal D-Type Opcode: " + String.Format("0x{0:x4}", op));
                        break;
                    }
                }
                #endregion
            }

            if (_traceFile != null && _changes.Count > 0)
            {
                Debug.Assert(_output[0x0] == 0.0); // blow up if we change something on the last frame
                Debug.WriteLine("recording " + _changes.Count + " changes (Elapsed = " + Elapsed + ")");
                _traceFile.Write(Elapsed);
                _traceFile.Write(_changes.Count);
                foreach (var change in _changes)
                {
                    _traceFile.Write(change.Address);
                    _traceFile.Write(change.Value);
                }

                _changes.Clear();
            }

            if (_traceFile != null && _output[0x0] != 0.0)
            {
                this.EndTrace();
            }

            Elapsed = Elapsed + 1;
            var args = new VirtualMachineStepArgs(Elapsed, _output[0x0], _output[0x1], _output[0x2], _output[0x3], _output[0x4], _output[0x5]);

            if (OnStep != null)
            {
                OnStep(this, args);
            }

            return(args);
        } // Step()