Exemplo n.º 1
0
        void Application_Idle(object sender, EventArgs e)
        {
            while (AppStillIdle())
            {
                if (nes.Cpu.Paused)
                {
                    return;
                }

                const float  deadZone = 0.3f;
                GamePadState state    = GamePad.GetState(PlayerIndex.One);
                nes.Controller1.A      = state.Buttons.A == (Microsoft.Xna.Framework.Input.ButtonState.Pressed);
                nes.Controller1.B      = state.Buttons.X == (Microsoft.Xna.Framework.Input.ButtonState.Pressed);
                nes.Controller1.Start  = state.Buttons.Start == (Microsoft.Xna.Framework.Input.ButtonState.Pressed);
                nes.Controller1.Select = state.Buttons.Back == (Microsoft.Xna.Framework.Input.ButtonState.Pressed);
                nes.Controller1.Left   = state.ThumbSticks.Left.X < -deadZone;
                nes.Controller1.Right  = state.ThumbSticks.Left.X > deadZone;
                nes.Controller1.Up     = state.ThumbSticks.Left.Y > deadZone;
                nes.Controller1.Down   = state.ThumbSticks.Left.Y < -deadZone;

                double deltaT = (double)sw.ElapsedTicks / (double)Stopwatch.Frequency;
                deltaT *= 5;
                sw.Reset();
                sw.Start();
                if (deltaT > 0.1f)
                {
                    deltaT = 0.1f;
                }
                double clockRate = 341 * 262 * 60;

                int cycles = (int)Math.Round(clockRate * deltaT);
                //Console.WriteLine("{0:0} ms = {1} cycles", deltaT * 1000.0, cycles);

                //bool render=false;

                /*while (!nes.Cpu.Paused && cycles > 0)
                 * {
                 *  bool tmpRender = false;
                 *  cycles = nes.Run(cycles, out tmpRender);
                 *
                 *  if(tmpRender)
                 *      render = true;
                 * }*/
                nes.RunOneFrame();

                if (nes.Cpu.Paused)
                {
                    UpdateTitle();
                    UpdateScreen();
                    disassembly2.SelectAddress(nes.Cpu.PC);
                    return;
                }

                //if(render)
                outputWindow.Invalidate();

                counter++;
                if (counter > 10)
                {
                    outputWindow.Text = String.Format("NES Emulator - {0:0.0} FPS", nes.FPS);
                    counter           = 0;
                }
            }
        }