Ejemplo n.º 1
0
        void Application_Idle(object sender, EventArgs e)
        {
            _iWidth  = this.ClientRectangle.Width;
            _iHeight = this.ClientRectangle.Height - msMenuStrip.Height;
            _iLeft   = this.ClientRectangle.X;
            _iTop    = this.ClientRectangle.Y + msMenuStrip.Height;

            while (IsApplicationIdle())
            {
                // call this at the beginning of ever loop to capture the events
                _sdlSDLWrapper.HandleEvents();

                if (c8CHIP8.ROMLoaded && isRunning)
                {
                    c8CHIP8.EmulateCycle();
                    if (c8CHIP8.GraphicsMemoryChanged)
                    {
                        SimpleSDLWrapperDotNET.Color[] caPixelPile = new SimpleSDLWrapperDotNET.Color[CHIP8.GRAPHICS_WIDTH * CHIP8.GRAPHICS_HEIGHT];
                        for (int i = 0; i < caPixelPile.Length; i++)
                        {
                            caPixelPile[i] = _palette[c8CHIP8.GraphicsMemory[i]];
                            //caPixelPile[i] = new SimpleSDLWrapperDotNET.Color((byte)_rnd.Next(255), (byte)_rnd.Next(255), (byte)_rnd.Next(255), (byte)255);
                        }
                        _txDisplayTexture.Lock();
                        _txDisplayTexture.SetPixels(caPixelPile);
                        _txDisplayTexture.Unlock();

                        c8CHIP8.GraphicsMemoryChanged = false;
                    }
                    if (c8CHIP8.MemoryChanged)
                    {
                        memMap.UpdateTable(c8CHIP8.Memory);
                        c8CHIP8.MemoryChanged = false;
                    }
                    // update the debug window
                    if (dbgWindow.Visible)
                    {
                        dbgWindow.PC         = c8CHIP8.PC;
                        dbgWindow.I          = c8CHIP8.I;
                        dbgWindow.OpCode     = c8CHIP8.OpCode;
                        dbgWindow.Cycle      = c8CHIP8.CycleCounter;
                        dbgWindow.SP         = c8CHIP8.SP;
                        dbgWindow.SoundTimer = c8CHIP8.SoundTimer;
                        dbgWindow.DelayTimer = c8CHIP8.DelayTimer;
                        dbgWindow.Stack      = c8CHIP8.stack.ToArray();
                        dbgWindow.Registers  = c8CHIP8.V;
                        dbgWindow.UpdateValues();
                    }

                    if (EmuState == EmulationState.Paused && isRunning)
                    { // for the step
                        isRunning = false;
                    }
                }


                //sdl.FrameRateCapper();

                _sdlSDLWrapper.ClearScreen();
                if (c8CHIP8.ROMLoaded)
                {
                    _sdlSDLWrapper.RenderTexture(_txDisplayTexture, null, new SimpleSDLWrapperDotNET.Rectangle(_iLeft, _iTop, _iWidth, _iHeight));
                    //_sdlSDLWrapper.RenderTexture(_txDisplayTexture, null, new SimpleSDLWrapperDotNET.Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y + msMenuStrip.Height, this.ClientRectangle.Width, this.ClientRectangle.Height - msMenuStrip.Height));
                }
                else
                {
                    _sdlSDLWrapper.RenderTexture(_txLogoTexture, null, new SimpleSDLWrapperDotNET.Rectangle(_iLeft + (_iWidth / 2) - (_txLogoTexture.Width / 2), _iTop + (_iHeight / 2) - (_txLogoTexture.Height / 2), _txLogoTexture.Width /*_iWidth / 3*/, _txLogoTexture.Height /*_iHeight / 3*/));
                }
                _sdlSDLWrapper.Render();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            c8CHIP8.Init();
            string sFileName = string.Empty;

            if (args.Length > 0)
            {
                sFileName = args[0];
            }
            else
            {
                sFileName = @"..\..\..\roms\Zero Demo [zeroZshadow, 2007].ch8";
            }
            string sWindowTitle = new FileInfo(sFileName).Name;

            c8CHIP8.LoadRom(sFileName);
            c8CHIP8.onPlaySound += c8CHIP8_onPlaySound;

            System.Windows.Forms.Form f = new System.Windows.Forms.Form();
            f.Width  = CHIP8.GRAPHICS_WIDTH * sizeMultiplier;
            f.Height = CHIP8.GRAPHICS_HEIGHT * sizeMultiplier;


            System.Windows.Forms.MenuStrip         menuStrip1            = new System.Windows.Forms.MenuStrip();
            System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();

            menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                fileToolStripMenuItem
            });
            menuStrip1.Location = new System.Drawing.Point(0, 0);
            menuStrip1.Name     = "menuStrip1";
            menuStrip1.Size     = new System.Drawing.Size(171, 24);
            menuStrip1.TabIndex = 2;
            menuStrip1.Text     = "menuStrip1";
            menuStrip1.Visible  = false;
            //
            // fileToolStripMenuItem
            //
            fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
                openToolStripMenuItem,
                exitToolStripMenuItem
            });
            fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            fileToolStripMenuItem.Text = "File";
            //
            // openToolStripMenuItem
            //
            openToolStripMenuItem.Name = "openToolStripMenuItem";
            openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            openToolStripMenuItem.Text = "Open";
            //
            // exitToolStripMenuItem
            //
            exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            exitToolStripMenuItem.Text = "Exit";

            f.Controls.Add(menuStrip1);
            f.Height += menuStrip1.Height;


            // set up the graphics
            SDLWrapper sdl = new SDLWrapper();

            sdl.Initialize();
            //sdl.CreateWindow(sWindowTitle, 100, 100, CHIP8.GRAPHICS_WIDTH * sizeMultiplier, CHIP8.GRAPHICS_HEIGHT * sizeMultiplier, WindowFlags.WINDOW_SHOWN);
            sdl.CreateWindowFor(f.Handle);
            sdl.CreateRenderer(SDLWrapper.DEFAULT_RENDERING_DRIVER, RendererFlags.RENDERER_ACCELERATED /* | RendererFlags.RENDERER_PRESENTVSYNC*/);
            //sdl.CreateRendererForWindow(f.Handle, SDLWrapper.DEFAULT_RENDERING_DRIVER, RendererFlags.RENDERER_SOFTWARE);
            Texture txDisplayTexture = sdl.CreateDynamicTexture(CHIP8.GRAPHICS_WIDTH, CHIP8.GRAPHICS_HEIGHT);

            f.Show();

            sdl.OnQuit        += sdl_onQuit;
            sdl.OnKeyPressed  += sdl_OnKeyPressedOrReleased;
            sdl.OnKeyReleased += sdl_OnKeyPressedOrReleased;

            SDLMixerWrapper mixer = new SDLMixerWrapper();

            mixer.Initialize();
            sample = mixer.LoadSample(@"Ding.wav");

            Color[] palette = new Color[] {
                new Color(0, 0, 0, 255),
                new Color(128, 255, 0, 255)
            };

            // set up the debug windows
            Registers winRegisters = new Registers();

            winRegisters.InitializeRegisters(CHIP8.REGISTERCOUNT);
            winRegisters.Show();


            bRunning = true;
            while (bRunning)
            {
                // call this at the beginning of ever loop to capture the events
                sdl.HandleEvents();

                //sdl.FrameRateCapper();
                System.Threading.Thread.Sleep(delay);

                c8CHIP8.EmulateCycle();
                if (winRegisters.Visible)
                {
                    winRegisters.UpdateRegisters(c8CHIP8.V);
                }

                if (c8CHIP8.GraphicsMemoryChanged)
                {
                    Color[] caPixelPile = new Color[CHIP8.GRAPHICS_WIDTH * CHIP8.GRAPHICS_HEIGHT];
                    for (int i = 0; i < caPixelPile.Length; i++)
                    {
                        caPixelPile[i] = palette[c8CHIP8.GraphicsMemory[i]];
                    }
                    txDisplayTexture.Lock();
                    txDisplayTexture.SetPixels(caPixelPile);
                    txDisplayTexture.Unlock();

                    c8CHIP8.GraphicsMemoryChanged = false;
                }

                sdl.ClearScreen();
                sdl.RenderTexture(txDisplayTexture, null, new Rectangle(0, menuStrip1.Height, 640, 320 - menuStrip1.Height));
                sdl.Render();
            }
        }