예제 #1
0
 private void mnuSaveState_Click(object sender, EventArgs e)
 {
     SaveFile("Save states (*.ss)|*.ss", (file) => {
         lock (_runLock) {
             UpdateRam();
             File.WriteAllBytes(file, CoreWrapper.getMemoryState(MemoryType.FullState));
         }
     });
 }
예제 #2
0
 private void btnExportPrgRam_Click(object sender, EventArgs e)
 {
     SaveFile("PRG RAM (*.pr)|*.pr", (file) => {
         lock (_runLock) {
             UpdateRam();
             File.WriteAllBytes(file, CoreWrapper.getMemoryState(MemoryType.PrgRam));
         }
     });
 }
예제 #3
0
        private void StartEmulationThread()
        {
            _emulationThread = Task.Run(() => {
                while (!_stopFlag)
                {
                    while (!_stopFlag && _stepsToRun > 0)
                    {
                        UpdateRam();

                        int stepsToRun = Math.Min(_refreshSpeed, _stepsToRun);
                        Interlocked.Add(ref _stepsToRun, -stepsToRun);

                        Stopwatch sw = new Stopwatch();
                        lock (_runLock) {
                            sw.Start();
                            CoreWrapper.step((UInt32)stepsToRun);
                            CoreWrapper.getState(ref _previousState);

                            _chrRamData       = CoreWrapper.getMemoryState(MemoryType.ChrRam);
                            _nametableRamData = CoreWrapper.getMemoryState(MemoryType.NametableRam);
                            _paletteData      = CoreWrapper.getMemoryState(MemoryType.PaletteRam);
                            _spriteData       = CoreWrapper.getMemoryState(MemoryType.SpriteRam);
                            _cpuRamData       = CoreWrapper.getMemoryState(MemoryType.CpuRam);
                            _prgRamData       = CoreWrapper.getMemoryState(MemoryType.PrgRam);

                            if (mnuShowSimulationState.Checked)
                            {
                                ctrlChipDisplay.ShowState = true;
                                ctrlChipDisplay.RefreshState(true);
                            }
                            sw.Stop();
                        }

                        this.BeginInvoke((MethodInvoker)(() => {
                            double emulatedHz = Stopwatch.Frequency / (double)sw.ElapsedTicks * stepsToRun / 2;
                            int nesMasterClockSpeed = 21477272;
                            double speedPercent = (emulatedHz / nesMasterClockSpeed) * 100;
                            lblHz.Text = string.Format("{0:0} ({1:0.0000}% of NES speed - {2:0.0000} FPM)", emulatedHz, speedPercent, speedPercent / 100 * 60.1 * 60);

                            UpdateUI();
                        }));
                    }

                    if (_autoRun)
                    {
                        Interlocked.Add(ref _stepsToRun, _refreshSpeed);
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(50);
                    }
                }
            });
        }
예제 #4
0
 private void SetMemoryState(MemoryType type, byte[] data)
 {
     lock (_runLock) {
         UpdateRam();
         CoreWrapper.setMemoryState(type, data);
         _chrRamData  = CoreWrapper.getMemoryState(MemoryType.ChrRam);
         _paletteData = CoreWrapper.getMemoryState(MemoryType.PaletteRam);
         _spriteData  = CoreWrapper.getMemoryState(MemoryType.SpriteRam);
         _cpuRamData  = CoreWrapper.getMemoryState(MemoryType.CpuRam);
         _prgRamData  = CoreWrapper.getMemoryState(MemoryType.PrgRam);
     }
     UpdateMemoryViews();
 }