public void Dispose() { EmulatedGameBoy.Pause(); EmulatedGameBoy.Dispose(); if (_romInformationWindow != null) { _romInformationWindow.Dispose(); } }
public ApplicationViewModel(IWindowManager windowService, IFileDialogService fileDialogService) { _zoomLevels = Array.AsReadOnly(Enumerable.Range(1, 8).Select(n => new ZoomLevelViewModel(this, n)).ToArray()); WindowService = windowService; FileDialogService = fileDialogService; EmulatedGameBoy = new EmulatedGameBoy { EnableFramerateLimiter = true }; _relativeSpeedUpdateStopwatch = Stopwatch.StartNew(); EmulatedGameBoy.NewFrame += OnNewFrame; }
public void LoadRom(string fileName) { var romFileInfo = new FileInfo(fileName); // Open only existing rom files if (!romFileInfo.Exists) { throw new FileNotFoundException(); } if (romFileInfo.Length < 512) { throw new InvalidOperationException("ROM files must be at least 512 bytes."); } if (romFileInfo.Length > 8 * 1024 * 1024) { throw new InvalidOperationException("ROM files cannot exceed 8MB."); } EmulatedGameBoy.LoadRom(MemoryUtility.ReadFile(romFileInfo, true)); //if (EmulatedGameBoy.RomInformation.HasRam && EmulatedGameBoy.RomInformation.HasBattery) //{ // var ramFileInfo = new FileInfo(Path.Combine(romFileInfo.DirectoryName, Path.GetFileNameWithoutExtension(romFileInfo.Name)) + ".sav"); // var ramSaveStream = ramFileInfo.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); // ramSaveStream.SetLength(EmulatedGameBoy.Mapper.SavedRamSize + (EmulatedGameBoy.RomInformation.HasTimer ? 48 : 0)); // ramSaveStream.Read(EmulatedGameBoy.ExternalRam, 0, EmulatedGameBoy.Mapper.SavedRamSize); // ramSaveWriter = new BinaryWriter(ramSaveStream); // if (EmulatedGameBoy.RomInformation.HasTimer) // { // var mbc3 = EmulatedGameBoy.Mapper as CrystalBoy.Emulation.Mappers.MemoryBankController3; // if (mbc3 != null) // { // var rtcState = mbc3.RtcState; // ramSaveReader = new BinaryReader(ramSaveStream); // rtcState.Frozen = true; // rtcState.Seconds = (byte)ramSaveReader.ReadInt32(); // rtcState.Minutes = (byte)ramSaveReader.ReadInt32(); // rtcState.Hours = (byte)ramSaveReader.ReadInt32(); // rtcState.Days = (short)((byte)ramSaveReader.ReadInt32() + ((byte)ramSaveReader.ReadInt32() << 8)); // rtcState.LatchedSeconds = (byte)ramSaveReader.ReadInt32(); // rtcState.LatchedMinutes = (byte)ramSaveReader.ReadInt32(); // rtcState.LatchedHours = (byte)ramSaveReader.ReadInt32(); // rtcState.LatchedDays = (short)((byte)ramSaveReader.ReadInt32() + ((byte)ramSaveReader.ReadInt32() << 8)); // rtcState.DateTime = new DateTime(1970, 1, 1) + TimeSpan.FromSeconds(ramSaveReader.ReadInt64()); // rtcState.Frozen = false; // } // } // EmulatedGameBoy.Mapper.RamUpdated += Mapper_RamUpdated; //} NotifyPropertyChanged(nameof(RomInformation)); EmulatedGameBoy.Run(); }