Exemplo n.º 1
0
        //Save states and rom loading
        private void HandleIO()
        {
            if (queueLoadState)
            {
                queueLoadState = false;
                using (FileStream FS = new FileStream(saveStatePath, FileMode.Open))
                {
                    ReadStateFromStream(FS);
                }
                RewindManager.Reset();
            }

            else if (queueSaveState)
            {
                queueSaveState = false;
                using (FileStream FS = new FileStream(saveStatePath, FileMode.OpenOrCreate))
                {
                    WriteStateToStream(FS);
                }
            }

            else if (queueLoad)
            {
                queueLoad = false;

                GamePak = new GamePak(romPath);
                Mapper  = Mapper.Create(this);
                CPU.Reset();
                PPU.Reset();
                APU.Reset();
                RewindManager.Reset();

                State = EmulatorState.Running;
            }
        }
Exemplo n.º 2
0
        internal void WriteStateToStream(Stream stream)
        {
            BinaryFormatter BF = new BinaryFormatter();

            object[] data;
            if (GamePak.UsesCharRAM)
            {
                data = new object[] { CPU, PPU, APU, Mapper, GamePak.GetCharRAM() };
            }
            else
            {
                data = new object[] { CPU, PPU, APU, Mapper };
            }
            BF.Serialize(stream, data);
        }
Exemplo n.º 3
0
        internal void ReadStateFromStream(Stream stream)
        {
            BinaryFormatter BF = new BinaryFormatter();

            object[] data = (object[])BF.Deserialize(stream);
            //Make sure to fix dead references from serialization
            CPU = (CPU)data[0];
            CPU.RefreshEmulatorReference(this);
            CPU.Memory.RefreshEmulatorReference(this);
            PPU = (PPU)data[1];
            PPU.RefreshEmulatorReference(this);
            PPU.Memory.RefreshEmulatorReference(this);
            APU = (APU)data[2];
            APU.RefreshEmulatorReference(this);
            Mapper = (Mapper)data[3];
            Mapper.RefreshEmulatorReference(this);
            if (GamePak.UsesCharRAM)
            {
                GamePak.LoadCharRAM((byte[])data[4]);
            }
        }