示例#1
0
        internal void Run(int cycleCount)
        {
            var completedCycles = 0;

            while (completedCycles++ < cycleCount)
            {
                _gameBoy.AdvanceMachineCycle(Input.JoypadState.None);
            }
        }
示例#2
0
        public void Emulation_in_release_mode_must_be_at_least_twice_as_fast_as_real_gameboy()
        {
#if DEBUG
            var expectedPerformance = 100.0;
#else
            var expectedPerformance = 50.0;
#endif
            var gameBoy = new GameBoy("PerformanceTests/Roms/cpu_instrs_looped.gb");

            Stopwatch stopWatch = new Stopwatch();
            if (!Stopwatch.IsHighResolution)
            {
                Assert.Fail("No high res timer available in system!");
            }

            stopWatch.Start();

            var multiplier = 10000;
            var cycle      = 0;

            var cycles = 17556 * multiplier;
            while (cycle++ < cycles)
            {
                gameBoy.AdvanceMachineCycle(JoypadState.None);
            }

            stopWatch.Stop();

            var actualPerformance = 100 * stopWatch.ElapsedMilliseconds / (16.74 * multiplier);

            Console.WriteLine($"Performance: {actualPerformance}%");

            if (actualPerformance < expectedPerformance)
            {
                Assert.Pass($"RunTime: {actualPerformance}%");
            }
            else
            {
                Assert.Fail($"RunTime: {actualPerformance}% is worse than expected runtime: {expectedPerformance}%");
            }
        }
示例#3
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            var timespan = _stopwatch.Elapsed;

            if (timespan.TotalMilliseconds >= (16 + _stopwatchOvershoot) || _fastForward == true)
            {
                _stopwatchOvershoot = 16 - timespan.TotalMilliseconds;
                if (_stopwatchOvershoot > 0)
                {
                    _stopwatchOvershoot = 0;
                }

                _stopwatch.Restart();

                _joypadState = GetJoypadState();

                for (int i = 0; i < 17000; i++)
                {
                    _soundPlayer.QueueAudioSample(Channels.Channel1, _gameBoy.GetAudioSample(Channels.Channel1));
                    _soundPlayer.QueueAudioSample(Channels.Channel2, _gameBoy.GetAudioSample(Channels.Channel2));
                    _soundPlayer.QueueAudioSample(Channels.Channel3, _gameBoy.GetAudioSample(Channels.Channel3));
                    _soundPlayer.QueueAudioSample(Channels.Channel4, _gameBoy.GetAudioSample(Channels.Channel4));

                    _gameBoy.AdvanceMachineCycle(_joypadState);
                }
            }

            if (KeyboardState.IsKeyDown(Key.Escape))
            {
                Close();
            }

            if (KeyboardState.IsKeyDown(Key.Tab))
            {
                _fastForward = true;
            }
            else
            {
                _fastForward = false;
            }

            if (KeyboardState.IsKeyDown(Key.P) && LastKeyboardState.IsKeyUp(Key.P))
            {
                if (Size.X < 640)
                {
                    Size = new OpenToolkit.Mathematics.Vector2i(ClientSize.X + 160, ClientSize.Y + 144);
                }
            }

            if (KeyboardState.IsKeyDown(Key.M) && LastKeyboardState.IsKeyUp(Key.M))
            {
                if (Size.X > 160)
                {
                    Size = new OpenToolkit.Mathematics.Vector2i(ClientSize.X - 160, ClientSize.Y - 144);
                }
            }

            if (KeyboardState.IsKeyDown(Key.L) && LastKeyboardState.IsKeyUp(Key.L))
            {
                _gameBoy.EnableLogging();
            }

            base.OnUpdateFrame(e);
        }