Exemplo n.º 1
0
        public void UpdateKeyState(ControllerKey controllerKey, bool state)
        {
            // This is correct - key states are inverted in the MMIO
            // 1 = not pressed, 0 = pressed
            if (state)
            {
                BitUtil.ClearBit(ref PressedKeys, (int)controllerKey);
            }
            else
            {
                BitUtil.SetBit(ref PressedKeys, (int)controllerKey);
            }

            // Check if we should raise an interrupt
            if (InterruptsEnabled)
            {
                bool condition;
                if (InterruptCondition == ControllerInterruptCondition.LogicalOr)
                {
                    condition = (~PressedKeys & InterruptBitfield) != 0;
                }
                else // AND
                {
                    condition = (~PressedKeys & InterruptBitfield) == InterruptBitfield;
                }

                if (condition)
                {
                    Cpu.RaiseInterrupt(InterruptType.Key);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return user input direction keys - can return two keys.
        /// </summary>
        /// <returns></returns>
        public ControllerKey GetDirectionKeys()
        {
            ControllerKey state = ControllerKey.Stationary;

            // Get USB controller state if present.
            ControllerKey usbState = _usb.ControllerInput;

            // Exclusive Left or Right
            if (_keyboardState.IsKeyDown(Keys.Left) || usbState == ControllerKey.Left)
            {
                state |= ControllerKey.Left;
            }
            else if (_keyboardState.IsKeyDown(Keys.Right) || usbState == ControllerKey.Right)
            {
                state |= ControllerKey.Right;
            }

            // Exclusive Up or Down
            if (_keyboardState.IsKeyDown(Keys.Up) || usbState == ControllerKey.Up)
            {
                state |= ControllerKey.Up;
            }
            else if (_keyboardState.IsKeyDown(Keys.Down) || usbState == ControllerKey.Down)
            {
                state |= ControllerKey.Down;
            }

            return(state);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets player horizontal movement and jump commands from input.
        /// </summary>
        private void GetInput(ControllerKey direction, bool isBackgroundMoving)
        {
            // If any digital horizontal movement input is found, override the analog movement.
            if (direction.HasFlag(ControllerKey.Left))
            {
                directionChanged  = previousDirection != ControllerKey.Left;
                previousDirection = ControllerKey.Left;

                movement = -1.0f;
            }
            else if (direction.HasFlag(ControllerKey.Right))
            {
                directionChanged  = previousDirection != ControllerKey.Right;
                previousDirection = ControllerKey.Right;

                if (!isBackgroundMoving)
                {
                    // We're only moving right when the background isn't moving
                    movement = 1.0f;
                }
            }

            // Check if the player wants to jump.
            isJumping = direction.HasFlag(ControllerKey.Up);
        }
Exemplo n.º 4
0
        public void update(World world)
        {
            if (Keyboard.IsKeyPressed(Keyboard.Key.Return))
            {
                ControllerKey controllerKey = new ControllerKey(0, ControllDevice.GamePad);
                if (!players.ContainsKey(controllerKey))
                {
                    players[controllerKey] = new Player(world, Vector2.Zero, new KeyboardController());
                }
            }


            GamePadInputManager padInputManager = Program.gamePadInputManager;

            foreach (uint padIndex in padInputManager.connectedPadIndices)
            {
                if (padInputManager.isClicked(GamePadButton.Start, padIndex))
                {
                    ControllerKey controllerKey = new ControllerKey(padIndex, ControllDevice.GamePad);
                    if (!players.ContainsKey(controllerKey))
                    {
                        players[controllerKey] = new Player(world, Vector2.Zero, new GamePadController(padIndex));
                    }
                }
            }

            foreach (Player player in players.Values)
            {
                player.update();
            }
        }
Exemplo n.º 5
0
        public ControllerPressedEventArgs(ControllerKey[] keyNumbers)
        {
            if (null == keyNumbers || 0 == keyNumbers.Length)
                return;

            if (null == Keys)
                Keys = new List<ControllerKey>(keyNumbers.Length);
            Keys.AddRange(keyNumbers);
        }
        public void UpdateKeyState_ChangeStateToPressedAndCheckBitfield_BitSet(ControllerKey key)
        {
            AgbMemoryMap  memoryMap  = new AgbMemoryMap();
            AgbController controller = new AgbController(memoryMap, null);

            controller.UpdateKeyState(key, true);

            ushort mmioValue = memoryMap.ReadU16(0x4000130);

            Assert.True(BitUtil.IsBitSet(mmioValue, (int)key));
        }
        public virtual ControllerBase CreateController(HttpContextBase context, String controllerName)
        {
            // var areaName = context.Request.RequestContext.RouteData.DataTokens["area"] as string;

            var key = new ControllerKey(controllerName, null);
            ControllerFactory factory;

            if (_controllerMap.TryGetValue(key, out factory))
            {
                return(factory.Create(context));
            }

            throw new HttpException(404, "Controller '" + controllerName + "' not found");
        }
        public virtual ControllerContainer RegisterController(string controllerName, string areaName,
                                                              Func <HttpContextBase, ControllerBase> controllerFactory)
        {
            if (string.IsNullOrEmpty(controllerName))
            {
                throw new ArgumentNullException("controllerName");
            }

            var key = new ControllerKey(controllerName, areaName);

            _controllerMap.Add(key, new ControllerFactory(controllerFactory));

            return(this);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Changing direction switched the atlas image range between left facing and right facing.
        /// </summary>
        /// <param name="direction"></param>
        ///
        private void ChangeDirection(ControllerKey direction)
        {
            if (direction.HasFlag(ControllerKey.Left))
            {
                _firstFrame = _atlas.LeftMovingAnimationStartFrame;
                _lastFrame  = _atlas.LeftMovingAnimationEndFrame;
            }
            else
            {
                _firstFrame = _atlas.RightMovingAnimationStartFrame;
                _lastFrame  = _atlas.RightMovingAnimationEndFrame;
            }

            // Reset first frame to start of new image range and update direction.
            _currentFrame = _firstFrame;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Updates the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="direction">The direction.</param>
        /// <param name="isBackgroundMoving">if set to <c>true</c> [is background moving].</param>
        /// <param name="speed">The speed.</param>
        public void Update(GameTime gameTime, ControllerKey direction, bool isBackgroundMoving, int speed)
        {
            GetInput(direction, isBackgroundMoving);

            ApplyPhysics(gameTime);

            // If nothing is really moving, don't bother reanimating
            if (Math.Abs(Velocity.X) - 0.01f > 0 || Math.Abs(Velocity.Y) - 0.01f > 0)
            {
                DoAnimation(gameTime, direction);
            }

            // Clear input.
            movement  = 0.0f;
            isJumping = false;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NintendoControllerState" /> struct.
        /// </summary>
        /// <param name="state">The state of the keys on the <see cref="NintendoController"/>.</param>
        public NintendoControllerState(ControllerKey state)
        {
            this._state           = (Buttons)0;
            this._isConnected     = true;
            this._nintendoButtons = new NintendoControllerButtons(state);
            this._dpad            = new NintendoControllerDPad(state);

            // Calculate the button states
            this._state |= state.HasFlag(ControllerKey.A) ? Microsoft.Xna.Framework.Input.Buttons.A : 0;
            this._state |= state.HasFlag(ControllerKey.B) ? Microsoft.Xna.Framework.Input.Buttons.B : 0;
            this._state |= state.HasFlag(ControllerKey.Select) ? Microsoft.Xna.Framework.Input.Buttons.Back : 0;
            this._state |= state.HasFlag(ControllerKey.Start) ? Microsoft.Xna.Framework.Input.Buttons.Start : 0;

            // Calculate the directional pad states
            this._state |= state.HasFlag(ControllerKey.Up) ? Microsoft.Xna.Framework.Input.Buttons.DPadUp : 0;
            this._state |= state.HasFlag(ControllerKey.Down) ? Microsoft.Xna.Framework.Input.Buttons.DPadDown : 0;
            this._state |= state.HasFlag(ControllerKey.Left) ? Microsoft.Xna.Framework.Input.Buttons.DPadLeft : 0;
            this._state |= state.HasFlag(ControllerKey.Right) ? Microsoft.Xna.Framework.Input.Buttons.DPadRight : 0;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Does the animation.
        /// </summary>
        /// <param name="gametime">The gametime.</param>
        /// <param name="direction">The direction.</param>
        private void DoAnimation(GameTime gametime, ControllerKey direction)
        {
            if (directionChanged)
            {
                ChangeDirection(direction);
            }

            if (!isOnGround)
            {
                if (previousDirection.HasFlag(ControllerKey.Left))
                {
                    _currentFrame = _atlas.JumpingLeftFrame;
                }
                else
                {
                    _currentFrame = _atlas.JumpingRightFrame;
                }
            }
            else
            {
                if (direction == ControllerKey.Stationary)
                {
                    _currentFrame = _firstFrame;
                }
                else if (direction.HasFlag(ControllerKey.Right) || direction.HasFlag(ControllerKey.Left))
                {
                    AnimationTime += (float)gametime.ElapsedGameTime.TotalSeconds;

                    if (AnimationTime >= animationGovernor)
                    {
                        _currentFrame++;
                        AnimationTime = 0.0f;
                    }

                    // If the current frame is equal to last frame wrap it back to the beginning.
                    if (_currentFrame == _lastFrame)
                    {
                        _currentFrame = _firstFrame;
                    }
                }
            }
        }
Exemplo n.º 13
0
        protected override void Update(GameTime gameTime)
        {
            // Check for key press.
            _userInput.PollUserInput();
            ControllerKey direction = _userInput.GetDirectionKeys();

            CheckCollisions();

            _isBackgroundMoving = (_player.Position.X > 350 && direction.HasFlag(ControllerKey.Right));

            _player.Update(gameTime, direction, _isBackgroundMoving, _speed);

            _scrollingBG.Update(_speed, _isBackgroundMoving);

            _sprites.ForEach(s => s.Update(_isBackgroundMoving, _speed));

            // If any sprites thing they were destroyed... finish the job.
            _sprites.RemoveAll(s => s.IsDestroyed);

            base.Update(gameTime);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get user button press information.  Directions are formed by
        /// calling GetDirection().
        /// </summary>
        /// <returns></returns>
        public ControllerKey GetAllKeys()
        {
            ControllerKey key = GetDirectionKeys();

            // For developers - map remaining Nintendo keys to keyboard.
            if (_keyboardState.IsKeyDown(Keys.F1))
            {
                key |= ControllerKey.Select;
            }
            if (_keyboardState.IsKeyDown(Keys.F2))
            {
                key |= ControllerKey.Start;
            }
            if (_keyboardState.IsKeyDown(Keys.F3))
            {
                key |= ControllerKey.B;
            }
            if (_keyboardState.IsKeyDown(Keys.F4))
            {
                key |= ControllerKey.A;
            }

            return(key);
        }
 public ControllerKeyMap GetKeyMap()
 {
     ControllerKeyMap map = new ControllerKeyMap();
     for (int i = 0; i < lvKeyMap.Items.Count; i++) {
         ListViewItem item = lvKeyMap.Items[i];
         ControllerKey[] keys = new ControllerKey[2];
         keys[0] = ControllerKey.FromString(item.SubItems[1].Text);
         keys[1] = ControllerKey.FromString(item.SubItems[2].Text);
         map.Add(item.Text.ToLower(), keys);
     }
     return map;
 }
Exemplo n.º 16
0
        public virtual string Translate(ControllerKey key)
        {
            if (null == this.KeyMap)
                return null;

            string action = string.Empty;
            foreach (KeyValuePair<string, ControllerKey[]> item in this.KeyMap) {
                if (null == item.Value || string.IsNullOrEmpty(item.Key))
                    continue;

                ControllerKey[] keys = item.Value;
                for (int i = 0; i < keys.Length; i++) {
                    if (key.EqualsTo(keys[i])) {
                        action = item.Key;
                        break;
                    }
                }
            }

            return action;
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NintendoControllerButtons"/> struct.
 /// </summary>
 /// <param name="buttons">
 /// The state of the keys on the <see cref="NintendoController"/>.
 /// </param>
 public NintendoControllerDPad(ControllerKey state)
 {
     this._state = state;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Return true if all buttons passed in ControllerKey enum are pressed.
        /// This method uses GetDirection() so only certain simultaneous direction
        /// keys are detectable.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool IsPressed(ControllerKey value)
        {
            ControllerKey state = GetAllKeys() & value;

            return(state == value);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NintendoControllerButtons"/> struct.
 /// </summary>
 /// <param name="buttons">
 /// The state of the keys on the <see cref="NintendoController"/>.
 /// </param>
 public NintendoControllerButtons(ControllerKey state)
 {
     this._state = state;
 }
Exemplo n.º 20
0
        private static void Control(Player player, NesParser nes, ControllerKey key)
        {
            try
            {
                switch (key)
                {
                case ControllerKey.None:
                    break;

                case ControllerKey.Zero:
                    break;

                case ControllerKey.One:
                    break;

                case ControllerKey.Two:
                    break;

                case ControllerKey.Three:
                    break;

                case ControllerKey.Four:
                    break;

                case ControllerKey.Five:
                    break;

                case ControllerKey.Six:
                    break;

                case ControllerKey.Seven:
                    break;

                case ControllerKey.Eight:
                    break;

                case ControllerKey.Nine:
                    break;

                case ControllerKey.Star:
                    break;

                case ControllerKey.Sharp:
                    NesUtil.Shutdown(player, nes);
                    break;

                case ControllerKey.Up:
                    player.PlayPrevious();
                    break;

                case ControllerKey.Down:
                    player.PlayNext();
                    break;

                case ControllerKey.Left:
                    player.SubVolume();
                    break;

                case ControllerKey.Right:
                    player.IncreaseVolume();
                    break;

                case ControllerKey.Ok:
                    player.Pause();
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(key), key, null);
                }
            }
            catch (Exception)
            {
                player.Dispose();
                nes.Dispose();
                Main(_args);
            }
        }
        /// <summary>
        /// Called asynchronously with input from USB.
        /// </summary>
        /// <param name="ar"></param>
        private void GetInputReportData(IAsyncResult ar)
        {
            byte[] inputReportBuffer = new byte[0];

            try
            {
                inputReportBuffer = (byte[])ar.AsyncState;

                fileStreamDeviceData.EndRead(ar);

                if (ar.IsCompleted)
                {
                    // Parse controller state and create report for game.
                    ControllerKey key = ControllerKey.Stationary;

                    // Check Left/Right.  Unpressed = 0x7F.
                    if (inputReportBuffer[USB_INPUT_REPORT_LEFT_RIGHT] == 0x00)
                    {
                        key |= ControllerKey.Left;
                    }
                    else if (inputReportBuffer[USB_INPUT_REPORT_LEFT_RIGHT] == 0xFF)
                    {
                        key |= ControllerKey.Right;
                    }

                    // Check Up/Down.  Unpressed = 0x7F.
                    if (inputReportBuffer[USB_INPUT_REPORT_UP_DOWN] == 0x00)
                    {
                        key |= ControllerKey.Up;
                    }
                    else if (inputReportBuffer[USB_INPUT_REPORT_UP_DOWN] == 0xFF)
                    {
                        key |= ControllerKey.Down;
                    }

                    // Remaining non-exclusive bits.
                    if ((inputReportBuffer[USB_INPUT_REPORT_A_B] & USB_INPUT_REPORT_MASK_A)
                        == USB_INPUT_REPORT_MASK_A)
                    {
                        key |= ControllerKey.A;
                    }
                    if ((inputReportBuffer[USB_INPUT_REPORT_A_B] & USB_INPUT_REPORT_MASK_B)
                        == USB_INPUT_REPORT_MASK_B)
                    {
                        key |= ControllerKey.B;
                    }
                    if ((inputReportBuffer[USB_INPUT_REPORT_START_SELECT] & USB_INPUT_REPORT_MASK_SELECT)
                        == USB_INPUT_REPORT_MASK_SELECT)
                    {
                        key |= ControllerKey.Select;
                    }
                    if ((inputReportBuffer[USB_INPUT_REPORT_START_SELECT] & USB_INPUT_REPORT_MASK_START)
                        == USB_INPUT_REPORT_MASK_START)
                    {
                        key |= ControllerKey.Start;
                    }

                    // Save result then clear input buffer to increase input speed.
                    _lastRead = key;
                    MyHid.FlushQueue(hidHandle);

                    Debug.WriteLineIf(WRITE_DEBUG_INFO,
                                      MyDebugging.ResultOfAPICall("MyHid.FlushQueue after Async buffer read"));
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                transferInProgress = false;
            }
        }
        public void SetKey(ControllerKey key)
        {
            //ControllerKeyMap map = GetKeyMap();
            //map.Delete(key);

            for (int i = 0; i < lvKeyMap.Items.Count; i++) {
                ListViewItem item = lvKeyMap.Items[i];
                if (ControllerKey.FromString(item.SubItems[1].Text).EqualsTo(key)) {
                    item.SubItems[1].Text = "-";
                    break;
                }
                if (ControllerKey.FromString(item.SubItems[2].Text).EqualsTo(key)) {
                    item.SubItems[2].Text = "-";
                    break;
                }
            }
            if (null != this.SelectedSubItem)
                this.SelectedSubItem.Text = key.ToString();
        }