コード例 #1
0
ファイル: SDLVideo.cs プロジェクト: jizang/FamicomEmu
        public SDLVideo(TVSystem system)
        {
            LoadSettings();
            initialized = false;
            canRender   = false;
            Console.WriteLine("->Initializing video ...");
            fontPath = System.IO.Path.Combine(Program.ApplicationFolder, "FreeSans.ttf");
            // Initialize the video
            Video.Initialize();
            Video.WindowIcon();
            Video.WindowCaption         = "My Nes SDL";
            fullscreenModes             = Video.ListModes();
            Video.GLDoubleBufferEnabled = !ImmediateMode;
            windowW = 256 * stretchMultiply;
            switch (system)
            {
            case TVSystem.NTSC:
            {
                Events.TargetFps = 60;
                break;
            }

            case TVSystem.PALB:
            case TVSystem.DENDY:
            {
                Events.TargetFps = 50;
                break;
            }
            }
            if (cutLines)
            {
                if (system == TVSystem.NTSC)
                {
                    scanlines  = 224;
                    firstToCut = 8;
                }
                else
                {
                    scanlines  = 238;
                    firstToCut = 1;
                }
            }
            else
            {
                scanlines  = 240;
                firstToCut = 0;
            }
            screenBufferSize = 256 * scanlines;
            originalRect     = new Rectangle(0, 0, 256, scanlines);
            screen_back      = new Surface(256, scanlines, 32);

            windowH = scanlines * stretchMultiply;

            pointer        = screen_back.Pixels;
            screen_pointer = (int *)screen_back.Pixels;
            NesEmu.SetupVideoRenderer(this, true, screen_back.Pixels, firstToCut * 256, 256 * (240 - firstToCut));
            // Create texts
            Console.WriteLine("-->Loading fonts ...");
            fpsTextSprite                         = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15));
            fpsTextSprite.Color                   = Color.White;
            fpsTextSprite.BackgroundColor         = Color.Black;
            notTextSprite                         = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15));
            notTextSprite.BackgroundColor         = Color.Black;
            soundRecordTextSprite                 = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15));
            soundRecordTextSprite.BackgroundColor = Color.Black;
            statusTextSprite                      = new TextSprite(new SdlDotNet.Graphics.Font(fontPath, 15));
            statusTextSprite.BackgroundColor      = Color.Black;
            // set video mode.
            Resize(FullScreen, true, windowW, windowH);
            Events.VideoResize     += VideoResize;
            Events.MouseButtonDown += Events_MouseButtonDown;
            Events.MouseButtonUp   += Events_MouseButtonUp;
            Events.Tick            += OnTick;
            canRender   = true;
            initialized = true;
            Console.WriteLine("->Video initialized successfully");
        }
コード例 #2
0
ファイル: SDLVideo.cs プロジェクト: jizang/FamicomEmu
        private void Resize(bool fullScreen, bool resizable, int w, int h)
        {
            if (Settings.Video_AutoResizeToFitEmu && NesEmu.EmulationON)
            {
                w = 256 * stretchMultiply;
                h = scanlines * stretchMultiply;
            }
            switch (NesEmu.TVFormat)
            {
            case TVSystem.NTSC:
            {
                Events.TargetFps = 60;
                scanlines        = 224;
                firstToCut       = 8;
                break;
            }

            case TVSystem.PALB:
            case TVSystem.DENDY:
            {
                Events.TargetFps = 50;
                scanlines        = 238;
                firstToCut       = 1;
                break;
            }
            }
            if (!cutLines)
            {
                scanlines  = 240;
                firstToCut = 0;
            }
            screenBufferSize = 256 * scanlines;
            originalRect     = new Rectangle(0, 0, 256, scanlines);
            screen_back      = new Surface(256, scanlines, 32);

            windowH = scanlines * stretchMultiply;

            pointer        = screen_back.Pixels;
            screen_pointer = (int *)screen_back.Pixels;
            NesEmu.SetupVideoRenderer(this, true, screen_back.Pixels, firstToCut * 256, 256 * (240 - firstToCut));
            // setup rectangles
            if (FullScreen)
            {
                if (!keepAspectRatio)
                {
                    destinationRect = new Rectangle(0, 0, fullscreenModes[FullScreenModeIndex].Width, fullscreenModes[FullScreenModeIndex].Height);
                }
                else
                {
                    destinationRect = GetRatioStretchRectangle(fullscreenModes[FullScreenModeIndex].Width, fullscreenModes[FullScreenModeIndex].Height);
                }
                if (!NesEmu.IsZapperConnected)
                {
                    SdlDotNet.Input.Mouse.ShowCursor = false;
                }
            }
            else
            {
                if (!keepAspectRatio)
                {
                    destinationRect = new Rectangle(0, 0, w, h);
                }
                else
                {
                    destinationRect = GetRatioStretchRectangle(w, h);
                }
                SdlDotNet.Input.Mouse.ShowCursor = true;
                Settings.Video_ScreenWidth       = w;
                Settings.Video_ScreenHeight      = h;
            }

            fpsTextSprite.X     = destinationRect.X + 2;
            fpsTextSprite.Y     = 2;
            fpsTextSprite.Color = Color.White;
            fpsTextSprite.Text  = "0/0";

            notTextSprite.X     = destinationRect.X + 2;
            notTextSprite.Y     = destinationRect.Height - 40;
            notTextSprite.Color = Color.White;
            notTextSprite.Text  = " ";

            soundRecordTextSprite.X     = destinationRect.X + 2;
            soundRecordTextSprite.Y     = 22;
            soundRecordTextSprite.Color = Color.White;
            soundRecordTextSprite.Text  = " ";

            statusTextSprite.X     = destinationRect.X + 2;
            statusTextSprite.Y     = 2;
            statusTextSprite.Color = Color.White;
            statusTextSprite.Text  = "0/0";
            // set video mode.
            if (fullScreen)
            {
                screen = Video.SetVideoMode(fullscreenModes[FullScreenModeIndex].Width, fullscreenModes[FullScreenModeIndex].Height, 32, resizable, openGL, true);
            }
            else
            {
                screen = Video.SetVideoMode(w, h, 32, resizable, openGL, false);
            }
        }