Ejemplo n.º 1
0
        public byte ReadByte(ushort address)
        {
            if (address == 0xFF00)
            {
                // request latest input from interface
                GBCoreInput newInputState = _inputSource.PollInput();

                // check to see if a button is pressed in this input state
                // that was not pressed the previous state, if so, raise the
                // input interrupt
                if (ButtonPressed(_inputState, newInputState))
                {
                    _interruptController.RequestInterrupt(Interrupt.Input);
                }

                _inputState = newInputState;

                int p14Value = 0x0F;
                int p15Value = 0x0F;

                if (_p14)
                {
                    p14Value = (_inputState.Down  ? 0 : (1 << 3)) |
                               (_inputState.Up    ? 0 : (1 << 2)) |
                               (_inputState.Left  ? 0 : (1 << 1)) |
                               (_inputState.Right ? 0 : (1 << 0));
                }

                if (_p15)
                {
                    p15Value = (_inputState.Start  ?  0 : (1 << 3)) |
                               (_inputState.Select ?  0 : (1 << 2)) |
                               (_inputState.B      ?  0 : (1 << 1)) |
                               (_inputState.A      ?  0 : (1 << 0));
                }

                return((byte)(0xC0 | _inputSelect | (p14Value & p15Value)));
            }
            else
            {
                throw new ArgumentException("Invalid memory address passed to InputController.ReadByte", "address");
            }
        }