void LoadRom(string filename) { byte[] rom = File.ReadAllBytes(filename); if ((rom[6] & 0x08) == 0x08) { CoreWrapper.setMirroringType(MirroringType.FourScreens); } else { CoreWrapper.setMirroringType((rom[6] & 0x01) == 0x01 ? MirroringType.Vertical : MirroringType.Horizontal); } int prgRamSize = rom[4] * 0x4000; int chrRamSize = rom[5] * 0x2000; byte[] prgRam = new byte[prgRamSize]; byte[] chrRam = new byte[chrRamSize]; Array.Copy(rom, 16, prgRam, 0, prgRamSize); Array.Copy(rom, 16 + prgRamSize, chrRam, 0, chrRamSize); if (prgRamSize == 0x4000) { Array.Resize(ref prgRam, 0x8000); Array.Copy(prgRam, 0, prgRam, 0x4000, 0x4000); } lock (_runLock) { Stop(); Reset(false); CoreWrapper.setMemoryState(MemoryType.ChrRam, chrRam); CoreWrapper.setMemoryState(MemoryType.PrgRam, prgRam); } }
private void UpdateRam() { lock (_runLock) { if (_chrRamChanged) { CoreWrapper.setMemoryState(MemoryType.ChrRam, ((StaticByteProvider)hexChrRam.ByteProvider).Bytes.ToArray()); } if (_nametableRamChanged) { CoreWrapper.setMemoryState(MemoryType.NametableRam, ((StaticByteProvider)hexNametableRam.ByteProvider).Bytes.ToArray()); } if (_paletteRamChanged) { CoreWrapper.setMemoryState(MemoryType.PaletteRam, ((StaticByteProvider)hexPaletteRam.ByteProvider).Bytes.ToArray()); } if (_spriteRamChanged) { CoreWrapper.setMemoryState(MemoryType.SpriteRam, ((StaticByteProvider)hexSpriteRam.ByteProvider).Bytes.ToArray()); } if (_cpuRamChanged) { CoreWrapper.setMemoryState(MemoryType.CpuRam, ((StaticByteProvider)hexCpuRam.ByteProvider).Bytes.ToArray()); } if (_prgRamChanged) { CoreWrapper.setMemoryState(MemoryType.PrgRam, ((StaticByteProvider)hexPrgRam.ByteProvider).Bytes.ToArray()); } } _chrRamChanged = false; _nametableRamChanged = false; _paletteRamChanged = false; _spriteRamChanged = false; _cpuRamChanged = false; _prgRamChanged = false; }
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(); }
private void mnuLoadState_Click(object sender, EventArgs e) { LoadFile("Save states (*.ss)|*.ss", (file) => { lock (_runLock) { CoreWrapper.setMemoryState(MemoryType.FullState, File.ReadAllBytes(file)); _chrRamChanged = false; _paletteRamChanged = false; _spriteRamChanged = false; _cpuRamChanged = false; _prgRamChanged = false; Step(1); } }); }