unsafe public void Reset() { if (!running) { return; } NesCore.SaveRam(); NesCore.LimitFPS = LimitFPS; NesCore.rom_file_name = rom_file_name; NesCore.VideoOutput -= new EventHandler(VideoOutputDeal); NesCore._event.Reset(); while (NesCore.screen_lock) { Thread.Sleep(1); } if (RenderObj != null) { RenderObj.freeMem(); } RenderObj = (InterfaceGraphic)Activator.CreateInstance(Type.GetType("AprNes.Render_" + AppConfigure["filter"] + "_" + ScreenSize + "x")); RenderObj.init(NesCore.ScreenBuf1x, grfx); NesCore.VideoOutput += new EventHandler(VideoOutputDeal); NesCore._event.Set(); NesCore.SoftReset(); }
unsafe private void button1_Click(object sender, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "nes file (*.nes *.zip)|*.nes;*.zip"; if (fd.ShowDialog() != DialogResult.OK) { return; } FileInfo fi = new FileInfo(fd.FileName); if (fi.Extension.ToLower() == ".zip") { // tks!! https://github.com/yallie/unzip good! // replace with .net use framework 4.6 https://msdn.microsoft.com/zh-tw/library/system.io.compression.zipfile(v=vs.110).aspx ZipArchive archive = ZipFile.OpenRead(fi.FullName); foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.ToLower().EndsWith(".nes")) { nes_name = entry.Name; Stream fs = entry.Open(); long length = entry.Length; rom_bytes = new byte[length]; fs.Read(rom_bytes, 0, (int)length); fs.Close(); } } } else { nes_name = new FileInfo(fd.FileName).Name; rom_bytes = File.ReadAllBytes(fd.FileName); } rom_file_name = fd.FileName.Remove(fd.FileName.Length - 4, 4); if (nes_t != null) { try { NesCore.exit = true; Thread.Sleep(50); nes_t.Abort(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } NesCore.SaveRam(); NesCore.exit = false; NesCore.LimitFPS = LimitFPS; NesCore.rom_file_name = rom_file_name; bool init_result = NesCore.init(rom_bytes); if (RenderObj != null) { RenderObj.freeMem(); } RenderObj = (InterfaceGraphic)Activator.CreateInstance(Type.GetType("AprNes.Render_" + AppConfigure["filter"] + "_" + ScreenSize + "x")); RenderObj.init(NesCore.ScreenBuf1x, grfx); NesCore.VideoOutput -= new EventHandler(VideoOutputDeal); NesCore.VideoOutput += new EventHandler(VideoOutputDeal); Console.WriteLine("init finsih"); if (!init_result) { fps_count_timer.Enabled = false; running = false; label3.Text = "fps : "; MessageBox.Show("fail !"); return; } nes_t = new Thread(NesCore.run); nes_t.IsBackground = true; nes_t.Start(); fps_count_timer.Enabled = true; running = true; }