private void InitIMemoryDomains()
        {
            var mmd = new List <MemoryDomain>();

            for (int i = 0;; i++)
            {
                IntPtr name;
                int    size;
                IntPtr data;
                if (!BizSwan.bizswan_getmemoryarea(Core, i, out name, out size, out data))
                {
                    break;
                }

                if (size == 0)
                {
                    continue;
                }

                string sname = Marshal.PtrToStringAnsi(name);
                mmd.Add(new MemoryDomainIntPtr(sname, MemoryDomain.Endian.Little, data, size, true, 1));
            }

            (ServiceProvider as BasicServiceProvider).Register <IMemoryDomains>(new MemoryDomainList(mmd));
        }
Esempio n. 2
0
        public void FrameAdvance(bool render, bool rendersound = true)
        {
            Frame++;
            IsLagFrame = true;

            if (Controller["Power"])
            {
                BizSwan.bizswan_reset(Core);
            }

            bool rotate        = false;
            int  soundbuffsize = sbuff.Length;

            IsLagFrame = BizSwan.bizswan_advance(Core, GetButtons(), !render, vbuff, sbuff, ref soundbuffsize, ref rotate);
            if (soundbuffsize == sbuff.Length)
            {
                throw new Exception();
            }
            sbuffcontains = soundbuffsize;
            InitVideo(rotate);

            if (IsLagFrame)
            {
                LagCount++;
            }
        }
        public bool FrameAdvance(IController controller, bool render, bool rendersound = true)
        {
            IsLagFrame = true;

            if (controller.IsPressed("Power"))
            {
                BizSwan.bizswan_reset(Core);
            }

            bool rotate        = false;
            int  soundbuffsize = sbuff.Length;

            IsLagFrame = BizSwan.bizswan_advance(Core, GetButtons(controller), !render, vbuff, sbuff, ref soundbuffsize, ref rotate);
            if (soundbuffsize == sbuff.Length)
            {
                throw new Exception();
            }
            sbuffcontains = soundbuffsize;
            InitVideo(rotate);

            if (IsLagFrame)
            {
                LagCount++;
            }

            Frame++;

            return(true);
        }
 public void StoreSaveRam(byte[] data)
 {
     if (!BizSwan.bizswan_saveramload(Core, data, data.Length))
     {
         throw new InvalidOperationException("bizswan_saveramload() returned false!");
     }
 }
Esempio n. 5
0
 void SetMemoryCallbacks()
 {
     BizSwan.bizswan_setmemorycallbacks(Core,
                                        MemoryCallbacks.HasReads ? ReadCallbackD : null,
                                        MemoryCallbacks.HasWrites ? WriteCallbackD : null,
                                        MemoryCallbacks.HasExecutes ? ExecCallbackD : null);
 }
Esempio n. 6
0
        public PutSettingsDirtyBits PutSettings(Settings o)
        {
            _settings = o;
            var native = _settings.GetNativeSettings();

            BizSwan.bizswan_putsettings(Core, ref native);
            return(PutSettingsDirtyBits.None);
        }
Esempio n. 7
0
        public bool PutSettings(Settings o)
        {
            _settings = o;
            var native = _settings.GetNativeSettings();

            BizSwan.bizswan_putsettings(Core, ref native);
            return(false);
        }
Esempio n. 8
0
        public bool PutSettings(object o)
        {
            _Settings = (Settings)o;
            var native = _Settings.GetNativeSettings();

            BizSwan.bizswan_putsettings(Core, ref native);
            return(false);
        }
 public byte[] CloneSaveRam()
 {
     if (!BizSwan.bizswan_saveramsave(Core, saverambuff, saverambuff.Length))
     {
         throw new InvalidOperationException("bizswan_saveramsave() returned false!");
     }
     return((byte[])saverambuff.Clone());
 }
Esempio n. 10
0
 public void Dispose()
 {
     if (Core != IntPtr.Zero)
     {
         BizSwan.bizswan_delete(Core);
         Core = IntPtr.Zero;
     }
 }
Esempio n. 11
0
 void SetDebugCallbacks()
 {
     BizSwan.bizswan_setmemorycallbacks(Core,
                                        CoreComm.MemoryCallbackSystem.HasReads ? ReadCallbackD : null,
                                        CoreComm.MemoryCallbackSystem.HasWrites ? WriteCallbackD : null,
                                        CoreComm.MemoryCallbackSystem.HasExecutes ? ExecCallbackD : null);
     BizSwan.bizswan_setbuttoncallback(Core,
                                       CoreComm.InputCallback.Has ? ButtonCallbackD : null);
 }
        public byte[] CloneSaveRam()
        {
            if (!BizSwan.bizswan_saveramsave(Core, _saveramBuff, _saveramBuff.Length))
            {
                throw new InvalidOperationException($"{nameof(BizSwan.bizswan_saveramsave)}() returned false!");
            }

            return((byte[])_saveramBuff.Clone());
        }
Esempio n. 13
0
        public void LoadStateText(TextReader reader)
        {
            var s = (TextState <TextStateData>)ser.Deserialize(reader, typeof(TextState <TextStateData>));

            s.Prepare();
            var ff = s.GetFunctionPointersLoad();

            BizSwan.bizswan_txtstateload(Core, ref ff);
            LoadTextStateData(s.ExtraData);
        }
Esempio n. 14
0
        public void SaveStateText(TextWriter writer)
        {
            var s = new TextState <TextStateData>();

            s.Prepare();
            var ff = s.GetFunctionPointersSave();

            BizSwan.bizswan_txtstatesave(Core, ref ff);
            SaveTextStateData(s.ExtraData);
            ser.Serialize(writer, s);
        }
Esempio n. 15
0
        public IDictionary <string, RegisterValue> GetCpuFlagsAndRegisters()
        {
            var ret = new Dictionary <string, RegisterValue>();

            for (int i = (int)BizSwan.NecRegsMin; i <= (int)BizSwan.NecRegsMax; i++)
            {
                BizSwan.NecRegs en  = (BizSwan.NecRegs)i;
                uint            val = BizSwan.bizswan_getnecreg(Core, en);
                ret[Enum.GetName(typeof(BizSwan.NecRegs), en)] = (ushort)val;
            }
            return(ret);
        }
Esempio n. 16
0
        public void LoadStateText(TextReader reader)
        {
            var s = (TextState <TextStateData>)ser.Deserialize(reader, typeof(TextState <TextStateData>));

            s.Prepare();
            var ff = s.GetFunctionPointersLoad();

            BizSwan.bizswan_txtstateload(Core, ref ff);
            IsLagFrame = s.ExtraData.IsLagFrame;
            LagCount   = s.ExtraData.LagCount;
            Frame      = s.ExtraData.Frame;
        }
Esempio n. 17
0
        public WonderSwan(CoreComm comm, byte[] rom, bool deterministicEmulation, object Settings, object SyncSettings)
        {
            CoreComm      = comm;
            _Settings     = (Settings)Settings ?? new Settings();
            _SyncSettings = (SyncSettings)SyncSettings ?? new SyncSettings();

            DeterministicEmulation = deterministicEmulation;             // when true, remember to force the RTC flag!
            Core = BizSwan.bizswan_new();
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException("bizswan_new() returned NULL!");
            }
            try
            {
                var ss = _SyncSettings.GetNativeSettings();
                if (deterministicEmulation)
                {
                    ss.userealtime = false;
                }

                bool rotate = false;

                if (!BizSwan.bizswan_load(Core, rom, rom.Length, ref ss, ref rotate))
                {
                    throw new InvalidOperationException("bizswan_load() returned FALSE!");
                }

                // for future uses of ClearSaveRam(), it's important that we save this
                _DONTTOUCHME = ss;

                CoreComm.VsyncNum = 3072000;                 // master CPU clock, also pixel clock
                CoreComm.VsyncDen = (144 + 15) * (224 + 32); // 144 vislines, 15 vblank lines; 224 vispixels, 32 hblank pixels

                saverambuff = new byte[BizSwan.bizswan_saveramsize(Core)];

                InitVideo(rotate);
                PutSettings(_Settings);
                SetMemoryDomains();

                savebuff  = new byte[BizSwan.bizswan_binstatesize(Core)];
                savebuff2 = new byte[savebuff.Length + 13];

                InitDebugCallbacks();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Esempio n. 18
0
        public void SaveStateBinary(BinaryWriter writer)
        {
            if (!BizSwan.bizswan_binstatesave(Core, savebuff, savebuff.Length))
            {
                throw new InvalidOperationException("bizswan_binstatesave() returned false!");
            }
            writer.Write(savebuff.Length);
            writer.Write(savebuff);

            // other variables
            writer.Write(IsLagFrame);
            writer.Write(LagCount);
            writer.Write(Frame);
        }
Esempio n. 19
0
        public void SaveStateBinary(BinaryWriter writer)
        {
            if (!BizSwan.bizswan_binstatesave(Core, savebuff, savebuff.Length))
            {
                throw new InvalidOperationException($"{nameof(BizSwan.bizswan_binstatesave)}() returned false!");
            }
            writer.Write(savebuff.Length);
            writer.Write(savebuff);

            var d = new TextStateData();

            SaveTextStateData(d);
            BinaryQuickSerializer.Write(d, writer);
        }
Esempio n. 20
0
        public WonderSwan(CoreComm comm, byte[] file, bool deterministic, object Settings, object SyncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            CoreComm        = comm;
            _Settings       = (Settings)Settings ?? new Settings();
            _SyncSettings   = (SyncSettings)SyncSettings ?? new SyncSettings();

            DeterministicEmulation = deterministic;             // when true, remember to force the RTC flag!
            Core = BizSwan.bizswan_new();
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException("bizswan_new() returned NULL!");
            }
            try
            {
                var ss = _SyncSettings.GetNativeSettings();
                if (deterministic)
                {
                    ss.userealtime = false;
                }

                bool rotate = false;

                if (!BizSwan.bizswan_load(Core, file, file.Length, ref ss, ref rotate))
                {
                    throw new InvalidOperationException("bizswan_load() returned FALSE!");
                }

                CoreComm.VsyncNum = 3072000;                 // master CPU clock, also pixel clock
                CoreComm.VsyncDen = (144 + 15) * (224 + 32); // 144 vislines, 15 vblank lines; 224 vispixels, 32 hblank pixels

                InitISaveRam();

                InitVideo(rotate);
                PutSettings(_Settings);
                InitIMemoryDomains();

                InitIStatable();
                InitDebugCallbacks();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Esempio n. 21
0
        public void LoadStateBinary(BinaryReader reader)
        {
            int length = reader.ReadInt32();

            if (length != savebuff.Length)
            {
                throw new InvalidOperationException("Save buffer size mismatch!");
            }
            reader.Read(savebuff, 0, length);
            if (!BizSwan.bizswan_binstateload(Core, savebuff, savebuff.Length))
            {
                throw new InvalidOperationException($"{nameof(BizSwan.bizswan_binstateload)}() returned false!");
            }

            var d = BinaryQuickSerializer.Create <TextStateData>(reader);

            LoadTextStateData(d);
        }
Esempio n. 22
0
        public WonderSwan(CoreComm comm, byte[] file, bool deterministic, object settings, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            CoreComm        = comm;
            _settings       = (Settings)settings ?? new Settings();
            _syncSettings   = (SyncSettings)syncSettings ?? new SyncSettings();

            DeterministicEmulation = deterministic;             // when true, remember to force the RTC flag!
            Core = BizSwan.bizswan_new();
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException($"{nameof(BizSwan.bizswan_new)}() returned NULL!");
            }
            try
            {
                var ss = _syncSettings.GetNativeSettings();
                if (deterministic)
                {
                    ss.userealtime = false;
                }

                bool rotate = false;

                if (!BizSwan.bizswan_load(Core, file, file.Length, ref ss, ref rotate))
                {
                    throw new InvalidOperationException($"{nameof(BizSwan.bizswan_load)}() returned FALSE!");
                }

                InitISaveRam();

                InitVideo(rotate);
                PutSettings(_settings);
                InitIMemoryDomains();

                InitIStatable();
                InitDebugCallbacks();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Esempio n. 23
0
        public void LoadStateBinary(BinaryReader reader)
        {
            int length = reader.ReadInt32();

            if (length != savebuff.Length)
            {
                throw new InvalidOperationException("Save buffer size mismatch!");
            }
            reader.Read(savebuff, 0, length);
            if (!BizSwan.bizswan_binstateload(Core, savebuff, savebuff.Length))
            {
                throw new InvalidOperationException("bizswan_binstateload() returned false!");
            }

            // other variables
            IsLagFrame = reader.ReadBoolean();
            LagCount   = reader.ReadInt32();
            Frame      = reader.ReadInt32();
        }
Esempio n. 24
0
        unsafe void SetMemoryDomains()
        {
            var mmd = new List <MemoryDomain>();

            for (int i = 0; ; i++)
            {
                IntPtr name;
                int    size;
                IntPtr data;
                if (!BizSwan.bizswan_getmemoryarea(Core, i, out name, out size, out data))
                {
                    break;
                }
                if (size == 0)
                {
                    continue;
                }
                string sname = Marshal.PtrToStringAnsi(name);
                byte * p     = (byte *)data;
                mmd.Add(new MemoryDomain(
                            sname,
                            size,
                            MemoryDomain.Endian.Little,
                            delegate(int addr)
                {
                    if (addr < 0 || addr >= size)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    return(p[addr]);
                },
                            delegate(int addr, byte value)
                {
                    if (addr < 0 || addr >= size)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    p[addr] = value;
                }));
            }
            MemoryDomains = new MemoryDomainList(mmd, 0);
        }
Esempio n. 25
0
        public void SaveStateText(TextWriter writer)
        {
            var s = new TextState <TextStateData>();

            s.Prepare();
            var ff = s.GetFunctionPointersSave();

            BizSwan.bizswan_txtstatesave(Core, ref ff);
            s.ExtraData.IsLagFrame = IsLagFrame;
            s.ExtraData.LagCount   = LagCount;
            s.ExtraData.Frame      = Frame;

            ser.Serialize(writer, s);
            // write extra copy of stuff we don't use
            writer.WriteLine();
            writer.WriteLine("Frame {0}", Frame);

            // debug
            //Console.WriteLine(Util.Hash_SHA1(SaveStateBinary()));
        }
Esempio n. 26
0
 void SetInputCallback()
 {
     BizSwan.bizswan_setbuttoncallback(Core, InputCallbacks.Any() ? ButtonCallbackD : null);
 }
Esempio n. 27
0
 public void ClearSaveRam()
 {
     BizSwan.bizswan_saveramclearhacky(Core, ref _DONTTOUCHME);
     //throw new InvalidOperationException("A new core starts with a clear saveram.  Instantiate a new core if you want this.");
 }
 void InitISaveRam()
 {
     saverambuff = new byte[BizSwan.bizswan_saveramsize(Core)];
 }
 private void InitISaveRam()
 {
     _saveramBuff = new byte[BizSwan.bizswan_saveramsize(Core)];
 }
Esempio n. 30
0
 private void InitIStatable()
 {
     savebuff  = new byte[BizSwan.bizswan_binstatesize(Core)];
     savebuff2 = new byte[savebuff.Length + 13];
 }