Beispiel #1
0
        public void GetVideoInfo()
        {
            IntPtr videoInfoPtr = Sdl.SDL_GetVideoInfo();

            Assert.IsNotNull(videoInfoPtr);

            Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)

                                          Marshal.PtrToStructure(videoInfoPtr,

                                                                 typeof(Sdl.SDL_VideoInfo));

            Console.WriteLine(videoInfo.hw_available);

            Console.WriteLine(videoInfo.wm_available);

            Console.WriteLine(videoInfo.video_mem);

            Console.WriteLine(videoInfo.current_h);

            Console.WriteLine(videoInfo.current_w);


            Sdl.SDL_FreeSurface(videoInfoPtr);
        }
Beispiel #2
0
        private GraphicsAdapter()
        {
            IntPtr infoPtr = Sdl.SDL_GetVideoInfo();

            Sdl.SDL_VideoInfo info = (Sdl.SDL_VideoInfo)Marshal.PtrToStructure(infoPtr, typeof(Sdl.SDL_VideoInfo));
            currentDisplayMode = new DisplayMode(info.current_w, info.current_h, -1, SurfaceFormat.Bgr32);

            hardwareCapabilities = new GraphicsDeviceCapabilities();
            findGLCapabilities();
        }
Beispiel #3
0
        private void Go()
        {
            splashscreen = new Splash();
            splashscreen.Show();
            splashscreen.BringToFront();
            splashscreen.Refresh();
            Core.Init(null, null, null, new ProgressHandler(UpdateMessage), true);
            world = new WorldDefinition(new Distance(150, 150, 7), 3);
            WorldDefinition.World = world;
            mainWindowMDI         = new MainWindow();
            timer = new System.Windows.Forms.Timer();
            Events.KeyboardDown    += new EventHandler <KeyboardEventArgs>(this.KeyDown);
            Events.MouseButtonDown +=
                new EventHandler <MouseButtonEventArgs>(this.MouseButtonDown);
            Events.MouseButtonUp +=
                new EventHandler <MouseButtonEventArgs>(this.MouseButtonUp);
            Events.Quit          += new EventHandler <QuitEventArgs>(this.Quit);
            Events.Tick          += new EventHandler <TickEventArgs>(this.Tick);
            Events.VideoResize   += new EventHandler <SdlDotNet.Graphics.VideoResizeEventArgs>(this.Resize);
            Events.MusicFinished +=
                new EventHandler <MusicFinishedEventArgs>(this.MusicFinished);
            Events.MouseMotion     += new EventHandler <MouseMotionEventArgs>(this.MouseMotion);
            dragStartMousePosition  = new Point(0, 0);
            dragStartScrollPosition = new Point(0, 0);
            ScrollPosition          = new Point(0, 0);
            this.width  = Properties.Settings.Default.RenderWindowWidth;
            this.height = Properties.Settings.Default.RenderWindowHeight;

            try
            {
                SdlDotNet.Graphics.Video.WindowIcon();
                SdlDotNet.Graphics.Video.WindowCaption = Translation.GetString("MAIN_WINDOW_TITLE");
                SdlDotNet.Graphics.Video.Initialize();
                splashscreen.BringToFront();
            }
            catch
            {
                MessageBox.Show(Translation.GetString("SDL_NOT_FOUND"));
                return;
            }

            Mixer.Initialize();

            SdlMixer.MusicFinishedDelegate musicStopped = new SdlMixer.MusicFinishedDelegate(MusicHasStopped);
            SdlMixer.Mix_HookMusicFinished(musicStopped);


            screen = SdlDotNet.Graphics.Video.SetVideoMode(width, height, currentBpp, true);
            screen.SourceColorKey = Color.Magenta;
            IntPtr videoInfoPointer = Sdl.SDL_GetVideoInfo();

            if (videoInfoPointer != IntPtr.Zero)
            {
                videoInfo   = (Sdl.SDL_VideoInfo)Marshal.PtrToStructure(videoInfoPointer, typeof(Sdl.SDL_VideoInfo));
                pixelFormat = (Sdl.SDL_PixelFormat)Marshal.PtrToStructure(videoInfo.vfmt, typeof(Sdl.SDL_PixelFormat));
            }
            splashscreen.status.AppendText("FreeTrain SDL Starting...");
            splashscreen.status.AppendText("\n");
            splashscreen.Refresh();

            FinalDraw();

            splashscreen.status.AppendText("Loading plugins...");
            splashscreen.status.AppendText("\n");
            splashscreen.Refresh();
            FinalDraw();


            weatherOverlay = NullWeatherOverlay.theInstance;
            FinalDraw();
            qView = new QuarterViewDrawer(world, new Rectangle(0, 0, world.Size.x * 32 - 16, (world.Size.y - 2 * world.Size.z - 1) * 8));
            qView.OffscreenBuffer = new Surface(world.Size.x * 32 - 16, (world.Size.y - 2 * world.Size.z - 1) * 8, screen.CreateCompatibleSurface().Pixels);
            qView.OffscreenBuffer.SourceColorKey = Color.Magenta;
            qView.RecreateDrawBuffer(new Size(width, height), true);
            splashscreen.status.AppendText("Creating Map...");
            splashscreen.status.AppendText("\n");
            splashscreen.Refresh();
            FinalDraw();

            qView.Draw(new Rectangle(0, 0, world.Size.x * 32 - 16, (world.Size.y - 2 * world.Size.z - 1) * 8), null);
            timer.Tick    += new EventHandler(TimerTick);
            timer.Interval = 33;
            timer.Enabled  = true;
            timer.Start();

            mainWindowMDI.Show();
            splashscreen.BringToFront();
            splashscreen.Close();

            Events.Run();
        }
Beispiel #4
0
        public int CreateDevice(int width, int height, int colorDepth, bool fullscreen)
        {
            this.width      = width;
            this.height     = height;
            this.colorDepth = colorDepth;
            this.fullscreen = fullscreen;
            videoFlags      = Sdl.SDL_OPENGL | Sdl.SDL_GL_DOUBLEBUFFER | Sdl.SDL_RESIZABLE | Sdl.SDL_HWPALETTE;

            if (Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO) < 0)
            {
                EngineLog.Get().Error("Error init SDL: " + Sdl.SDL_GetError(), "Graphics");
                Sdl.SDL_Quit();
                return(-1);
            }

            if (-1 == SdlTtf.TTF_Init())
            {
                EngineLog.Get().Error("Error init SDL TTF: " + SdlTtf.TTF_GetError(), "Graphics");
                return(-1);
            }
            else
            {
                EngineLog.Get().Info("SDL TTF initialized", "Graphics");
            }

            if (this.fullscreen)
            {
                videoFlags |= Sdl.SDL_FULLSCREEN | Sdl.SDL_ANYFORMAT;
                EngineLog.Get().Info("Switching to Fullscreen", "Graphics");
            }
            else
            {
                EngineLog.Get().Info("Switching to Window", "Graphics");
            }

            IntPtr videoInfoPtr = Sdl.SDL_GetVideoInfo();

            if (IntPtr.Zero == videoInfoPtr)
            {
                EngineLog.Get().Error("GetVideoInfo failed", "Graphics");
                return(1);
            }

            Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)Marshal.PtrToStructure(
                videoInfoPtr, typeof(Sdl.SDL_VideoInfo));

            // This doesn't work

            /*if(1 == videoInfo.hw_available)
             * {
             *      EngineLog.Get().Info("Hardware Surface", "Graphics");
             *      videoFlags |= Sdl.SDL_HWSURFACE;
             * } else   {
             *      EngineLog.Get().Warn("Software Surface", "Graphics");
             *      videoFlags |= Sdl.SDL_SWSURFACE;
             * }*/
            videoFlags |= Sdl.SDL_HWSURFACE;

            if (1 == videoInfo.blit_hw)
            {
                EngineLog.Get().Info("Hardware Blitting", "Graphics");
                videoFlags |= Sdl.SDL_HWACCEL;
            }
            else
            {
                EngineLog.Get().Warn("No Hardware Blitting", "Graphics");
            }

            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 5);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 5);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 5);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DEPTH_SIZE, 16);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1);

            sdlSurface = Sdl.SDL_SetVideoMode(width, height, colorDepth, videoFlags);
            if (0 == sdlSurface.ToInt32())
            {
                EngineLog.Get().Error("Set video mode: " + Sdl.SDL_GetError(), "Graphics");
                return(1);
            }
            else
            {
                EngineLog.Get().Info("Set video mode to " + width + "x" + height + "x" + colorDepth, "Graphics");
            }

            Gl.glShadeModel(Gl.GL_SMOOTH);
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

            Gl.glClearDepth(1.0f);
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LEQUAL);

            Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
            Gl.glEnable(Gl.GL_TEXTURE_2D);

            Gl.glEnable(Gl.GL_CULL_FACE);
            Gl.glCullFace(Gl.GL_BACK);

            string glVendor    = Gl.glGetString(Gl.GL_VENDOR);
            string glVersion   = Gl.glGetString(Gl.GL_VERSION);
            string glVideoCard = Gl.glGetString(Gl.GL_RENDERER);
            string glExt       = Gl.glGetString(Gl.GL_EXTENSIONS);

            EngineLog.Get().Info("OpenGL Vendor: " + glVendor, "Graphics");
            EngineLog.Get().Info("OpenGL Version " + glVersion, "Graphics");
            EngineLog.Get().Info("OpenGL Renderer: " + glVideoCard, "Graphics");
            EngineLog.Get().Info("OpenGL Extensions: " + glExt, "Graphics");

            if (!Gl.IsExtensionSupported("GL_ARB_multitexture"))
            {
                EngineLog.Get().Error("Extension GL_ARB_multitexture not supported!", "Graphics");
                return(1);
            }

            // New TAO Framwork loads all extensions on startup

            /*if(false == GlExtensionLoader.LoadExtension("GL_ARB_multitexture"))
             * {
             *      EngineLog.Get().Error("Load OpenGL Extension: GL_ARB_multitexture", "Graphics");
             *      return 1;
             * }*/

            isRunning = true;
            isOrtho   = false;
            fpsTime   = Sdl.SDL_GetTicks();
            frameTime = Sdl.SDL_GetTicks();

            ResizeWindow(width, height);

            return(0);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        public void Run()
        {
            int  flags    = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT);
            int  bpp      = 16;
            int  width    = 640;
            int  height   = 480;
            bool quitFlag = false;

            Random rand = new Random();

            string filepath = @"../../";

            if (File.Exists("Data/SdlExamples.Rectangles.sound.ogg"))
            {
                filepath = "";
            }

            string musicFile = filepath + "Data/SdlExamples.Rectangles.sound.ogg";

            Sdl.SDL_Event evt;

            try
            {
                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption("Tao.Sdl Example - Rectangles", "");
                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(
                    width,
                    height,
                    bpp,
                    flags);

                int result = SdlMixer.Mix_OpenAudio(
                    SdlMixer.MIX_DEFAULT_FREQUENCY,
                    (short)SdlMixer.MIX_DEFAULT_FORMAT,
                    2,
                    1024);
                IntPtr chunkPtr = SdlMixer.Mix_LoadMUS(musicFile);

                SdlMixer.MusicFinishedDelegate musicStopped =
                    new SdlMixer.MusicFinishedDelegate(this.musicHasStopped);
                SdlMixer.Mix_HookMusicFinished(musicStopped);

                result = SdlMixer.Mix_PlayMusic(chunkPtr, 1);
                if (result == -1)
                {
                    Console.WriteLine("Music Error: " + Sdl.SDL_GetError());
                }

                int rmask = 0x00000000;
                int gmask = 0x00ff0000;
                int bmask = 0x0000ff00;
                int amask = 0x000000ff;

                IntPtr rgbSurfacePtr = Sdl.SDL_CreateRGBSurface(
                    flags,
                    width,
                    height,
                    bpp,
                    rmask,
                    gmask,
                    bmask,
                    amask);

                Sdl.SDL_Rect rect = new Sdl.SDL_Rect(
                    0,
                    0,
                    (short)width,
                    (short)height);
                result = Sdl.SDL_FillRect(rgbSurfacePtr, ref rect, 0);

                Sdl.SDL_Rect rect2;

                IntPtr videoInfoPointer = Sdl.SDL_GetVideoInfo();
                if (videoInfoPointer == IntPtr.Zero)
                {
                    throw new ApplicationException(string.Format("Video query failed: {0}", Sdl.SDL_GetError()));
                }

                Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)
                                              Marshal.PtrToStructure(videoInfoPointer,
                                                                     typeof(Sdl.SDL_VideoInfo));
                Console.WriteLine("Hi There");

                Sdl.SDL_PixelFormat pixelFormat = (Sdl.SDL_PixelFormat)
                                                  Marshal.PtrToStructure(videoInfo.vfmt,
                                                                         typeof(Sdl.SDL_PixelFormat));

                Console.WriteLine(videoInfo.hw_available);
                Console.WriteLine(videoInfo.wm_available);
                Console.WriteLine(videoInfo.blit_hw);
                Console.WriteLine(videoInfo.blit_hw_CC);
                Console.WriteLine(videoInfo.blit_hw_A);
                Console.WriteLine(videoInfo.blit_sw);
                Console.WriteLine(videoInfo.blit_hw_CC);
                Console.WriteLine(videoInfo.blit_hw_A);
                Console.WriteLine(videoInfo.blit_fill);
                Console.WriteLine(videoInfo.video_mem);
                Console.WriteLine(pixelFormat.BitsPerPixel);
                Console.WriteLine(pixelFormat.BytesPerPixel);
                Console.WriteLine(pixelFormat.Rmask);
                Console.WriteLine(pixelFormat.Gmask);
                Console.WriteLine(pixelFormat.Bmask);
                Console.WriteLine(pixelFormat.Amask);

                int             numevents = 10;
                Sdl.SDL_Event[] events    = new Sdl.SDL_Event[numevents];
                events[0].type           = Sdl.SDL_KEYDOWN;
                events[0].key.keysym.sym = (int)Sdl.SDLK_p;
                events[1].type           = Sdl.SDL_KEYDOWN;
                events[1].key.keysym.sym = (int)Sdl.SDLK_z;
                int result2 = Sdl.SDL_PeepEvents(events, numevents, Sdl.SDL_ADDEVENT, Sdl.SDL_KEYDOWNMASK);
                Console.WriteLine("Addevent result: " + result2);

                while (quitFlag == false)
                {
                    result = Sdl.SDL_PollEvent(out evt);

                    if (evt.type == Sdl.SDL_QUIT)
                    {
                        quitFlag = true;
                    }
                    else if (evt.type == Sdl.SDL_KEYDOWN)
                    {
                        if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                            (evt.key.keysym.sym == (int)Sdl.SDLK_q))
                        {
                            quitFlag = true;
                        }
                        if (evt.key.keysym.sym == (int)Sdl.SDLK_p)
                        {
                            Console.WriteLine("Key p event was added");
                        }
                        if (evt.key.keysym.sym == (int)Sdl.SDLK_z)
                        {
                            Console.WriteLine("Key z event was added");
                        }
                    }

                    rect2 = new Sdl.SDL_Rect(
                        (short)rand.Next(-300, width),
                        (short)rand.Next(-300, height),
                        (short)rand.Next(20, 300),
                        (short)rand.Next(20, 300));

                    try
                    {
                        result = Sdl.SDL_FillRect(
                            surfacePtr,
                            ref rect2,
                            rand.Next(100000));
                        result = Sdl.SDL_BlitSurface(
                            rgbSurfacePtr,
                            ref rect2,
                            surfacePtr,
                            ref rect);
                        result = Sdl.SDL_Flip(surfacePtr);
                    }
                    catch (Exception) {}
                }
            }
            catch
            {
                Sdl.SDL_Quit();
                throw;
            }
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        public void Run()
        {
            //sLogToFile=Environment.NewLine+"//  Comment:  Starting Window.  "+HTMLPage.DateTimePathString(true);
            bool bGood = true;

            retroengine = new RetroEngine(RetroEngine.sDataFolderSlash + "website.html", 800, 600);
            sFuncNow    = "Run()";
            int flags = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT);

            bGood = UpdateScreenVars(24);           //called again after surface bitdepth is found
            bool   bContinue      = true;
            Random rand           = new Random();
            string sFileTestMusic = RetroEngine.sDataFolderSlash + "music-test.ogg";
            string sFileTestSound = RetroEngine.sDataFolderSlash + "sound-test.wav";

            Sdl.SDL_Event sdleventX;
            try {
                int    iResultInit           = Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                IntPtr iptrSurfaceBackbuffer = Sdl.SDL_SetVideoMode(
                    iTargetWidth,
                    iTargetHeight,
                    iTargetBPP,
                    flags);

                //debug NYI: replace with Tao.OpenAl

                int iResult = SdlMixer.Mix_OpenAudio(
                    SdlMixer.MIX_DEFAULT_FREQUENCY,
                    (short)SdlMixer.MIX_DEFAULT_FORMAT,
                    2,
                    1024);

                /*
                 * IntPtr iptrChunkMusic = SdlMixer.Mix_LoadMUS(sFileTestMusic);
                 * IntPtr iptrChunkSound = SdlMixer.Mix_LoadWAV(sFileTestSound);
                 * SdlMixer.MusicFinishedDelegate delMusicFinished=new SdlMixer.MusicFinishedDelegate(this.MusicHasStopped);
                 * SdlMixer.Mix_HookMusicFinished(delMusicFinished);
                 *
                 * iResult = SdlMixer.Mix_PlayMusic (iptrChunkMusic, 2);
                 * if (iResult == -1) {
                 *      sLastErr="Music Error: " + Sdl.SDL_GetError();
                 * }
                 * iResult = SdlMixer.Mix_PlayChannel(1,iptrChunkSound,1);
                 * if (iResult == -1) {
                 *      sLastErr="Sound Error: " + Sdl.SDL_GetError();
                 * }
                 */

                int rmask = 0x00000000;                //doesn't matter since shifted all the way right
                int gmask = 0x00ff0000;
                int bmask = 0x0000ff00;
                int amask = 0x000000ff;

                IntPtr videoInfoPointer = Sdl.SDL_GetVideoInfo();
                if (videoInfoPointer == IntPtr.Zero)
                {
                    throw new ApplicationException(string.Format("Video query failed: {0}", Sdl.SDL_GetError()));
                }

                Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)
                                              Marshal.PtrToStructure(videoInfoPointer,
                                                                     typeof(Sdl.SDL_VideoInfo));

                Sdl.SDL_PixelFormat pixelFormat = (Sdl.SDL_PixelFormat)
                                                  Marshal.PtrToStructure(videoInfo.vfmt,
                                                                         typeof(Sdl.SDL_PixelFormat));
                try {
                    UpdateScreenVars(pixelFormat.BitsPerPixel);
                    retroengine.WriteLine("hw_available:" + videoInfo.hw_available);
                    retroengine.WriteLine("wm_available:" + videoInfo.wm_available);
                    retroengine.WriteLine("blit_hw:" + videoInfo.blit_hw);
                    retroengine.WriteLine("blit_hw_CC:" + videoInfo.blit_hw_CC);
                    retroengine.WriteLine("blit_hw_A:" + videoInfo.blit_hw_A);
                    retroengine.WriteLine("blit_sw:" + videoInfo.blit_sw);
                    retroengine.WriteLine("blit_hw_CC:" + videoInfo.blit_hw_CC);
                    retroengine.WriteLine("blit_hw_A:" + videoInfo.blit_hw_A);
                    retroengine.WriteLine("blit_fill:" + videoInfo.blit_fill);
                    retroengine.WriteLine("video_mem:" + videoInfo.video_mem);
                    retroengine.WriteLine("BitsPerPixel:" + pixelFormat.BitsPerPixel);
                    retroengine.WriteLine("BytesPerPixel:" + pixelFormat.BytesPerPixel);
                    retroengine.WriteLine("Rmask:" + pixelFormat.Rmask);
                    retroengine.WriteLine("Gmask:" + pixelFormat.Gmask);
                    retroengine.WriteLine("Bmask:" + pixelFormat.Bmask);
                    retroengine.WriteLine("Amask:" + pixelFormat.Amask);
                }
                catch (Exception exn) {
                    sLastErr = "Exception error displaying screen info--" + e.ToString();
                }
                int             numeventarr = 10;
                Sdl.SDL_Event[] eventarr    = new Sdl.SDL_Event[numeventarr];
                //eventarr[0].type = Sdl.SDL_KEYDOWN;
                //eventarr[0].key.keysym.sym = (int)Sdl.SDLK_p;
                //eventarr[1].type = Sdl.SDL_KEYDOWN;
                //eventarr[1].key.keysym.sym = (int)Sdl.SDLK_z;
                //int iResult2 = Sdl.SDL_PeepEvents(eventarr, numeventarr, Sdl.SDL_ADDEVENT, Sdl.SDL_KEYDOWNMASK);
                //retroengine.WriteLine("Addevent iResult: " + iResult2);
                //TODO: discard clicks if interface is in a transition

                int   iSDLKeys        = 65536;
                int   iNow            = 0;
                int[] iarrAsciiOfSDLK = new int[iSDLKeys];
                try {
                    //debug NYI finish this:
                    iNow = (int)Sdl.SDLK_ASTERISK;
                    if (iNow >= iSDLKeys)
                    {
                        iSDLKeys = iNow + 1;
                    }
                    iarrAsciiOfSDLK[iNow]            = 42;
                    iarrAsciiOfSDLK[Sdl.SDLK_0]      = 48;
                    iarrAsciiOfSDLK[Sdl.SDLK_a]      = 97;
                    iarrAsciiOfSDLK[Sdl.SDLK_RSHIFT] = -32;                  //since a - 32 is A
                    iarrAsciiOfSDLK[Sdl.SDLK_LSHIFT] = -32;                  //since a - 32 is A
                    //debug NYI the rest of the above integers
                    retroengine.TextMessage("This is a long test sentence to test writing text over the edge of the screen.");
                }
                catch (Exception exn) {
                    sLastErr = "Exception while setting iarrAsciiOfSDLK; maximum array size needed was " + iSDLKeys.ToString() + "--" + e.ToString();
                }
                Sdl.SDL_WM_SetCaption(retroengine.sCaption, "default");
                Sdl.SDL_EnableKeyRepeat(0, 9999);
                Sdl.SDL_EnableUNICODE(1);
                #region Main Event Loop
                while (bContinue == true)
                {
                    Sdl.SDL_PumpEvents();
                    iResult = Sdl.SDL_PollEvent(out sdleventX);
                    try {
                        if (sdleventX.type == Sdl.SDL_QUIT)
                        {
                            try {
                                if (true)
                                {
                                    bContinue = false;                                    //TODO: if (retroengine.ConfirmQuit()) bContinue=false;
                                }
                            }
                            catch (Exception exn) {
                                sFuncNow = "Run()";
                                sLastErr = "Exception error trying to confirm, so quitting without confirmation--" + e.ToString();
                            }
                        }
                        else if (sdleventX.type == Sdl.SDL_KEYDOWN)
                        {
                            try {
                                if (sdleventX.key.keysym.sym == (int)Sdl.SDLK_ESCAPE)
                                {
                                    //((sdleventX.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                                    //(sdleventX.key.keysym.sym == (int)Sdl.SDLK_q))
                                    try {
                                        if (true)
                                        {
                                            bContinue = false;                                             //TODO: if (retroengine.ConfirmQuit()) bContinue=false;
                                        }
                                    }
                                    catch (Exception exn) {
                                        sFuncNow = "Run()";
                                        sLastErr = "Exception error trying to confirm Esc (escape), so quitting without confirmation--" + e.ToString();
                                    }
                                }
                                //else if (sdleventX.key.keysym.sym == (int)Sdl.SDLK_p) {
                                //	retroengine.WriteLine("Key p event was added");
                                //}
                                //else if (sdleventX.key.keysym.sym == (int)Sdl.SDLK_z) {
                                //	retroengine.WriteLine("Key z event was added");
                                //}
                                if ((int)sdleventX.key.keysym.sym != 0)
                                {
                                    retroengine.KeyEvent(sdleventX.key.keysym.sym, sdleventX.key.keysym.unicode, true);
                                    //string sNow=Char.ToString((char)sdleventX.key.keysym.unicode);
                                    //short shNow=sdleventX.key.keysym.unicode;
                                    //retroengine.WriteLine("key="+shNow.ToString()+"    ");
                                }
                            }
                            catch (Exception exn) {
                                sLastErr = "Exception during KEYDOWN processing--" + e.ToString();
                            }
                        }
                        else if (sdleventX.type == Sdl.SDL_KEYUP)
                        {
                            //Sdl.SDL_
                            //byarrKeysNow=Sdl.SDL_GetKeyState(256); //debug internationalization
                            //ushort wKey=Base.GetUnsignedLossless(sdleventX.key.keysym.scancode);
                            //sdleventX.key.type
                            retroengine.KeyEvent(sdleventX.key.keysym.sym, 0, false);
                            //retroengine.WriteLine("keyup="+sdleventX.key.keysym.sym.ToString()+"    ");
                        }
                        else if (sdleventX.type == Sdl.SDL_MOUSEMOTION)
                        {
                            retroengine.WriteLine("mousemove=(" + sdleventX.motion.x + "," + sdleventX.motion.y + ")");
                        }
                        else if (sdleventX.type == Sdl.SDL_MOUSEBUTTONDOWN)
                        {
                            retroengine.WriteLine("mousedown=(" + sdleventX.button.x + "," + sdleventX.motion.y + ")");
                        }
                        else if (sdleventX.type == Sdl.SDL_MOUSEBUTTONUP)
                        {
                            retroengine.WriteLine("mouseup=(" + sdleventX.button.x + "," + sdleventX.motion.y + ")");
                        }
                    }
                    catch (Exception exn) {
                        sLastErr = "Exception during controller input processing--" + e.ToString();
                    }

                    try {
                        //if (iTryNow<iTargetBytesTotal){
                        //	byarrTemp[iTryNow]=255;
                        //	iTryNow++;
                        //}
                        //if (iTryNow%30!=0) continue;

                        //debug performance: run Draw code below as separate thread.
                        bGood   = retroengine.DrawFrame();
                        iResult = Sdl.SDL_LockSurface(iptrSurfaceBackbuffer);
                        if (iTargetBPP == 32)
                        {
                            fixed(byte *lpSrc = retroengine.gbScreen.byarrData)
                            {
                                byte *lpSrcNow = lpSrc;

                                Sdl.SDL_Surface *lpsurface = (Sdl.SDL_Surface *)iptrSurfaceBackbuffer;
                                byte *           lpDestNow = (byte *)lpsurface->pixels;

                                for (int i = iTargetChunks64Total; i != 0; i--)
                                {
                                    *((UInt64 *)lpDestNow) = *((UInt64 *)lpSrcNow);
                                    lpDestNow += 8;
                                    lpSrcNow  += 8;
                                }
                            }
                        }
                        else if (iTargetBPP == 24)
                        {
                            fixed(byte *lpSrc = retroengine.gbScreen.byarrData)
                            {
                                byte *lpSrcNow = lpSrc;

                                Sdl.SDL_Surface *lpsurface = (Sdl.SDL_Surface *)iptrSurfaceBackbuffer;
                                byte *           lpDestNow = (byte *)lpsurface->pixels;

                                for (int i = (iTargetBytesTotal / 3) - 1; i != 0; i--)                          //-1 to avoid overwrite problems
                                {
                                    *((UInt32 *)lpDestNow) = *((UInt32 *)lpSrcNow);
                                    lpDestNow += 3;
                                    lpSrcNow  += 4;
                                }
                                //now copy the odd pixel:
                                *lpDestNow = *lpSrcNow;
                                lpDestNow++;
                                lpSrcNow++;
                                *lpDestNow = *lpSrcNow;
                                lpDestNow++;
                                lpSrcNow++;
                                *lpDestNow = *lpSrcNow;
                            }
                        }
                        else if (iTargetBPP < 24)
                        {
                            //NYI add other bit depths.
                            sLastErr  = "Wrong bit depth.";
                            bContinue = false;
                        }
                        iResult = Sdl.SDL_UnlockSurface(iptrSurfaceBackbuffer);
                        iResult = Sdl.SDL_Flip(iptrSurfaceBackbuffer);
                    }
                    catch (Exception) {
                        sLastErr = "Exception error copying buffer to screen";
                    }
                }                //end while bContinue
                #endregion Main Event Loop

                if (iTargetBPP < 24)
                {
                    MessageBox.Show("You must change your Display settings to 32-bit (recommended) or at least 24-bit to run this program.");
                }
            }
            catch (Exception exn) {
                sFuncNow = "Run()";
                sLastErr = "Exception error--" + e.ToString();
                //Sdl.SDL_Quit();
            }
            try {
                if (true)                  //TODO: if (RetroEngine.statusq.TrackedErrors>0) {
                {
                    RetroEngine.statusq.Enq(".statusq {"
                                            + RetroEngine.statusq.DumpTrackedErrorsToStyleNotation()
                                            + "}"
                                            );
                }
            }
            catch (Exception exn) {
                sFuncNow = "Run, after main event loop";
                sLastErr = "Exception error saving exception stats--" + e.ToString();
            }
        }