Example #1
0
        public CoreDriver(UIWindow uiWindow, Configuration config)
        {
            IsDisposed = false;

            try
            {
                _config = config;

                _inputAggregator = new InputAggregator();
                _buttonStates = SnesJoypadButtons.None;

                _workerThread = new WorkerThread();

                _workerThread.DoWork(() =>
                {
                    _uiWindow = uiWindow;

                    _snes = new Snes();
                    _snes.VideoUpdated += Snes_VideoUpdated;
                    _snes.AudioUpdated += Snes_AudioUpdated;
                    _snes.SetControllerPortDevice(1, SnesDevice.Joypad);

                    _inputAggregator.InputReceived += InputAggregator_InputReceived;

                    _isAudioSynced = true;
                    _isVideoSynced = false;

                    _isRunning = false;

                    _stopwatch = new Stopwatch();
                    _stopwatch.Start();
                    _frameCount = 0;
                });
                _workerThread.WaitFor();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Example #2
0
        void InputAggregator_InputReceived(object sender, InputReceivedEventArgs e)
        {
            var de = e as DigitalInputReceivedEventArgs;
            if (de == null || de.Input.ID.DeviceName != "Keyboard0") { return; }

            InputSection inputConfig = _config.Input;

            if (de.State)
            {
                if (inputConfig.Joypad1.Up.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Up; }
                if (inputConfig.Joypad1.Down.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Down; }
                if (inputConfig.Joypad1.Left.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Left; }
                if (inputConfig.Joypad1.Right.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Right; }
                if (inputConfig.Joypad1.B.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.B; }
                if (inputConfig.Joypad1.A.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.A; }
                if (inputConfig.Joypad1.Y.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Y; }
                if (inputConfig.Joypad1.X.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.X; }
                if (inputConfig.Joypad1.L.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.L; }
                if (inputConfig.Joypad1.R.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.R; }
                if (inputConfig.Joypad1.Start.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Start; }
                if (inputConfig.Joypad1.Select.HasBindingTo(de.Input.ID)) { _buttonStates |= SnesJoypadButtons.Select; }

                _snes.SetInputState(1, 0, (int)_buttonStates, 0, 0);
            }
            else
            {
                if (inputConfig.Joypad1.Up.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Up; }
                if (inputConfig.Joypad1.Down.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Down; }
                if (inputConfig.Joypad1.Left.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Left; }
                if (inputConfig.Joypad1.Right.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Right; }
                if (inputConfig.Joypad1.B.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.B; }
                if (inputConfig.Joypad1.A.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.A; }
                if (inputConfig.Joypad1.Y.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Y; }
                if (inputConfig.Joypad1.X.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.X; }
                if (inputConfig.Joypad1.L.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.L; }
                if (inputConfig.Joypad1.R.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.R; }
                if (inputConfig.Joypad1.Start.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Start; }
                if (inputConfig.Joypad1.Select.HasBindingTo(de.Input.ID)) { _buttonStates &= ~SnesJoypadButtons.Select; }

                _snes.SetInputState(1, 0, (int)_buttonStates, 0, 0);
            }
        }