Пример #1
0
        private void InitSaveStateBuff()
        {
            int size = 0;

            LibQuickNES.ThrowStringError(QN.qn_state_size(Context, ref size));
            _saveStateBuff = new byte[size];
        }
Пример #2
0
        private void InitSaveRamBuff()
        {
            int size = 0;

            LibQuickNES.ThrowStringError(QN.qn_battery_ram_size(Context, ref size));
            _saveRamBuff = new byte[size];
        }
Пример #3
0
        public void FrameAdvance(bool render, bool rendersound = true)
        {
            using (FP.Save())
            {
                if (Controller["Power"])
                {
                    LibQuickNES.qn_reset(Context, true);
                }
                if (Controller["Reset"])
                {
                    LibQuickNES.qn_reset(Context, false);
                }

                int j1, j2;
                SetPads(out j1, out j2);

                Frame++;
                LibQuickNES.ThrowStringError(LibQuickNES.qn_emulate_frame(Context, j1, j2));
                IsLagFrame = LibQuickNES.qn_get_joypad_read_count(Context) == 0;
                if (IsLagFrame)
                {
                    LagCount++;
                }

                Blit();
                DrainAudio();
            }
        }
Пример #4
0
        void InitSaveStateBuff()
        {
            int size = 0;

            LibQuickNES.ThrowStringError(LibQuickNES.qn_state_size(Context, ref size));
            SaveStateBuff  = new byte[size];
            SaveStateBuff2 = new byte[size + 13];
        }
Пример #5
0
 public void SaveStateBinary(System.IO.BinaryWriter writer)
 {
     LibQuickNES.ThrowStringError(LibQuickNES.qn_state_save(Context, SaveStateBuff, SaveStateBuff.Length));
     writer.Write(SaveStateBuff.Length);
     writer.Write(SaveStateBuff);
     // other variables
     writer.Write(IsLagFrame);
     writer.Write(LagCount);
     writer.Write(Frame);
 }
Пример #6
0
        public bool FrameAdvance(IController controller, bool render, bool rendersound = true)
        {
            CheckDisposed();
            using (FP.Save())
            {
                if (controller.IsPressed("Power"))
                {
                    QN.qn_reset(Context, true);
                }
                if (controller.IsPressed("Reset"))
                {
                    QN.qn_reset(Context, false);
                }

                int j1, j2;
                SetPads(controller, out j1, out j2);

                if (Tracer.Enabled)
                {
                    QN.qn_set_tracecb(Context, _tracecb);
                }
                else
                {
                    QN.qn_set_tracecb(Context, null);
                }

                Frame++;
                LibQuickNES.ThrowStringError(QN.qn_emulate_frame(Context, j1, j2));
                IsLagFrame = QN.qn_get_joypad_read_count(Context) == 0;
                if (IsLagFrame)
                {
                    LagCount++;
                }

                if (render)
                {
                    Blit();
                }
                if (rendersound)
                {
                    DrainAudio();
                }

                if (CB1 != null)
                {
                    CB1();
                }
                if (CB2 != null)
                {
                    CB2();
                }
            }

            return(true);
        }
Пример #7
0
        public QuickNES(CoreComm comm, byte[] file, object Settings, object SyncSettings)
        {
            using (FP.Save())
            {
                ServiceProvider = new BasicServiceProvider(this);
                CoreComm        = comm;

                Context = QN.qn_new();
                if (Context == IntPtr.Zero)
                {
                    throw new InvalidOperationException("qn_new() returned NULL");
                }
                try
                {
                    file = fix_ines_header(file);
                    unsafe
                    {
                        fixed(byte *p = file)
                        {
                            Console.WriteLine((IntPtr)p);
                            LibQuickNES.ThrowStringError(QN.qn_loadines(Context, file, file.Length));
                        }
                    }



                    InitSaveRamBuff();
                    InitSaveStateBuff();
                    InitAudio();
                    InitMemoryDomains();

                    int    mapper     = 0;
                    string mappername = Marshal.PtrToStringAnsi(QN.qn_get_mapper(Context, ref mapper));
                    Console.WriteLine("QuickNES: Booted with Mapper #{0} \"{1}\"", mapper, mappername);
                    BoardName         = mappername;
                    CoreComm.VsyncNum = 39375000;
                    CoreComm.VsyncDen = 655171;
                    PutSettings((QuickNESSettings)Settings ?? new QuickNESSettings());

                    _syncSettings     = (QuickNESSyncSettings)SyncSettings ?? new QuickNESSyncSettings();
                    _syncSettingsNext = _syncSettings.Clone();

                    SetControllerDefinition();
                    ComputeBootGod();

                    ConnectTracer();
                }
                catch
                {
                    Dispose();
                    throw;
                }
            }
        }
Пример #8
0
        public void SaveStateBinary(BinaryWriter writer)
        {
            CheckDisposed();
            LibQuickNES.ThrowStringError(QN.qn_state_save(Context, _saveStateBuff, _saveStateBuff.Length));
            writer.Write(_saveStateBuff.Length);
            writer.Write(_saveStateBuff);

            // other variables
            writer.Write(IsLagFrame);
            writer.Write(LagCount);
            writer.Write(Frame);
        }
Пример #9
0
        public void LoadStateBinary(System.IO.BinaryReader reader)
        {
            int len = reader.ReadInt32();

            if (len != SaveStateBuff.Length)
            {
                throw new InvalidOperationException("Unexpected savestate buffer length!");
            }
            reader.Read(SaveStateBuff, 0, SaveStateBuff.Length);
            LibQuickNES.ThrowStringError(LibQuickNES.qn_state_load(Context, SaveStateBuff, SaveStateBuff.Length));
            // other variables
            IsLagFrame = reader.ReadBoolean();
            LagCount   = reader.ReadInt32();
            Frame      = reader.ReadInt32();
        }
Пример #10
0
        public QuickNES(CoreComm comm, byte[] file, object settings, object syncSettings)
        {
            FP = OSTailoredCode.IsUnixHost
                                ? (IFPCtrl) new Unix_FPCtrl()
                                : new Win32_FPCtrl();

            using (FP.Save())
            {
                ServiceProvider = new BasicServiceProvider(this);
                CoreComm        = comm;

                Context = QN.qn_new();
                if (Context == IntPtr.Zero)
                {
                    throw new InvalidOperationException($"{nameof(QN.qn_new)}() returned NULL");
                }

                try
                {
                    file = FixInesHeader(file);
                    LibQuickNES.ThrowStringError(QN.qn_loadines(Context, file, file.Length));

                    InitSaveRamBuff();
                    InitSaveStateBuff();
                    InitAudio();
                    InitMemoryDomains();

                    int    mapper     = 0;
                    string mappername = Marshal.PtrToStringAnsi(QN.qn_get_mapper(Context, ref mapper));
                    Console.WriteLine("QuickNES: Booted with Mapper #{0} \"{1}\"", mapper, mappername);
                    BoardName = mappername;
                    PutSettings((QuickNESSettings)settings ?? new QuickNESSettings());

                    _syncSettings     = (QuickNESSyncSettings)syncSettings ?? new QuickNESSyncSettings();
                    _syncSettingsNext = _syncSettings.Clone();

                    SetControllerDefinition();
                    ComputeBootGod();

                    ConnectTracer();
                }
                catch
                {
                    Dispose();
                    throw;
                }
            }
        }
Пример #11
0
        public bool FrameAdvance(IController controller, bool render, bool rendersound = true)
        {
            CheckDisposed();
            using (FP.Save())
            {
                if (controller.IsPressed("Power"))
                {
                    QN.qn_reset(Context, true);
                }
                if (controller.IsPressed("Reset"))
                {
                    QN.qn_reset(Context, false);
                }

                SetPads(controller, out var j1, out var j2);

                QN.qn_set_tracecb(Context, Tracer.IsEnabled() ? _traceCb : null);

                LibQuickNES.ThrowStringError(QN.qn_emulate_frame(Context, j1, j2));
                IsLagFrame = QN.qn_get_joypad_read_count(Context) == 0;
                if (IsLagFrame)
                {
                    LagCount++;
                }

                if (render)
                {
                    Blit();
                }
                if (rendersound)
                {
                    DrainAudio();
                }

                _callBack1?.Invoke();
                _callBack2?.Invoke();

                Frame++;

                return(true);
            }
        }
Пример #12
0
        public QuickNES(CoreComm nextComm, byte[] Rom, object Settings)
        {
            using (FP.Save())
            {
                CoreComm = nextComm;

                Context = LibQuickNES.qn_new();
                if (Context == IntPtr.Zero)
                {
                    throw new InvalidOperationException("qn_new() returned NULL");
                }
                try
                {
                    LibQuickNES.ThrowStringError(LibQuickNES.qn_loadines(Context, Rom, Rom.Length));

                    InitSaveRamBuff();
                    InitSaveStateBuff();
                    InitVideo();
                    InitAudio();
                    InitMemoryDomains();

                    int    mapper     = 0;
                    string mappername = Marshal.PtrToStringAnsi(LibQuickNES.qn_get_mapper(Context, ref mapper));
                    Console.WriteLine("QuickNES: Booted with Mapper #{0} \"{1}\"", mapper, mappername);
                    BoardName         = mappername;
                    CoreComm.VsyncNum = 39375000;
                    CoreComm.VsyncDen = 655171;
                    PutSettings(Settings ?? new QuickNESSettings());

                    ComputeBootGod();
                }
                catch
                {
                    Dispose();
                    throw;
                }
            }
        }
Пример #13
0
 public void StoreSaveRam(byte[] data)
 {
     LibQuickNES.ThrowStringError(QN.qn_battery_ram_load(Context, data, data.Length));
 }
 private void InitAudio()
 {
     LibQuickNES.ThrowStringError(QN.qn_set_sample_rate(Context, 44100));
 }
Пример #15
0
 public void ClearSaveRam()
 {
     LibQuickNES.ThrowStringError(LibQuickNES.qn_battery_ram_clear(Context));
 }
Пример #16
0
 public byte[] CloneSaveRam()
 {
     LibQuickNES.ThrowStringError(QN.qn_battery_ram_save(Context, _saveRamBuff, _saveRamBuff.Length));
     return((byte[])_saveRamBuff.Clone());
 }
Пример #17
0
 public byte[] ReadSaveRam()
 {
     LibQuickNES.ThrowStringError(LibQuickNES.qn_battery_ram_save(Context, SaveRamBuff, SaveRamBuff.Length));
     return(SaveRamBuff);
 }