private void _loadRom() { c8CHIP8.Init(); c8CHIP8.LoadRom(ofdOpenRomFileDialog.FileName); this.Text = "CHIP-8 Emulator - " + Path.GetFileName(ofdOpenRomFileDialog.FileName); isRunning = true; EmuState = EmulationState.Running; }
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(); } }