Exemple #1
0
        public Yabause(CoreComm CoreComm, DiscSystem.Disc CD, object syncSettings)
        {
            ServiceProvider = new BasicServiceProvider(this);
            byte[] bios = CoreComm.CoreFileProvider.GetFirmware("SAT", "J", true, "Saturn BIOS is required.");
            CoreComm.RomStatusDetails = string.Format("Disk partial hash:{0}", new DiscSystem.DiscHasher(CD).OldHash());
            this.CoreComm             = CoreComm;
            this.CD          = CD;
            DiscSectorReader = new DiscSystem.DiscSectorReader(CD);

            SyncSettings = (SaturnSyncSettings)syncSettings ?? new SaturnSyncSettings();

            if (this.SyncSettings.UseGL && glContext == null)
            {
                glContext = CoreComm.RequestGLContext(2, 0, false);
            }

            ResetCounters();

            ActivateGL();
            Init(bios);

            InputCallbackH = new LibYabause.InputCallback(() => InputCallbacks.Call());
            LibYabause.libyabause_setinputcallback(InputCallbackH);
            ConnectTracer();
            DriveLightEnabled = true;

            DeactivateGL();
        }
Exemple #2
0
        public Yabause(CoreComm CoreComm, DiscSystem.Disc CD, object SyncSettings)
        {
            byte[] bios = CoreComm.CoreFileProvider.GetFirmware("SAT", "J", true, "Saturn BIOS is required.");
            CoreComm.RomStatusDetails = string.Format("Disk partial hash:{0}", CD.GetHash());
            this.CoreComm             = CoreComm;
            this.CD = CD;

            this.SyncSettings = (SaturnSyncSettings)SyncSettings ?? new SaturnSyncSettings();

            if (this.SyncSettings.UseGL && glContext == null)
            {
                glContext = CoreComm.RequestGLContext();
            }


            ResetCounters();

            ActivateGL();
            Init(bios);

            InputCallbackH = new LibYabause.InputCallback(() => CoreComm.InputCallback.Call());
            LibYabause.libyabause_setinputcallback(InputCallbackH);
            CoreComm.UsesDriveLed = true;

            DeactivateGL();
        }
 public byte[] CloneSaveRam()
 {
     if (Disposed)
     {
         if (DisposedSaveRam != null)
         {
             return((byte[])DisposedSaveRam.Clone());
         }
         else
         {
             return(new byte[0]);
         }
     }
     else
     {
         var ms = new MemoryStream();
         var fp = new FilePiping();
         fp.Get(ms);
         bool success = LibYabause.libyabause_savesaveram(fp.GetPipeNameNative());
         fp.Finish();
         if (!success)
         {
             throw new Exception("libyabause_savesaveram() failed!");
         }
         var ret = ms.ToArray();
         ms.Dispose();
         return(ret);
     }
 }
Exemple #4
0
 public void ClearSaveRam()
 {
     if (Disposed)
     {
         throw new Exception("It's a bit late for that");
     }
     else
     {
         LibYabause.libyabause_clearsaveram();
     }
 }
        private void InitMemoryDomains()
        {
            var ret  = new List <MemoryDomain>();
            var nmds = LibYabause.libyabause_getmemoryareas_ex();

            foreach (var nmd in nmds)
            {
                ret.Add(new MemoryDomainIntPtr(nmd.name, MemoryDomain.Endian.Little, nmd.data, nmd.length, true, 4));
            }

            // main memory is in position 2
            _memoryDomains            = new MemoryDomainList(ret);
            _memoryDomains.MainMemory = _memoryDomains["Work Ram Low"];

            (ServiceProvider as BasicServiceProvider).Register <IMemoryDomains>(_memoryDomains);
        }
Exemple #6
0
        void InitMemoryDomains()
        {
            var ret  = new List <MemoryDomain>();
            var nmds = LibYabause.libyabause_getmemoryareas_ex();

            foreach (var nmd in nmds)
            {
                int    l = nmd.length;
                IntPtr d = nmd.data;
                ret.Add(new MemoryDomain(
                            nmd.name,
                            nmd.length,
                            MemoryDomain.Endian.Little,
                            delegate(int addr)
                {
                    if (addr < 0 || addr >= l)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    unsafe
                    {
                        byte *p = (byte *)d;
                        return(p[addr]);
                    }
                },
                            delegate(int addr, byte val)
                {
                    if (addr < 0 || addr >= l)
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    unsafe
                    {
                        byte *p = (byte *)d;
                        p[addr] = val;
                    }
                }
                            ));
            }
            // fulfill the prophecy of MainMemory always being MemoryDomains[0]
            var tmp = ret[2];

            ret[2]        = ret[0];
            ret[0]        = tmp;
            MemoryDomains = new MemoryDomainList(ret);
        }
Exemple #7
0
        private byte[] SaveCoreBinary()
        {
            var ms = new MemoryStream();
            var fp = new FilePiping();

            fp.Get(ms);
            bool succeed = LibYabause.libyabause_savestate(fp.GetPipeNameNative());

            fp.Finish();
            var ret = ms.ToArray();

            ms.Close();
            if (!succeed)
            {
                throw new Exception("libyabause_savestate() failed");
            }
            return(ret);
        }
Exemple #8
0
 public void Dispose()
 {
     if (!Disposed)
     {
         ActivateGL();
         if (SaveRamModified)
         {
             DisposedSaveRam = ReadSaveRam();
         }
         LibYabause.libyabause_setvidbuff(IntPtr.Zero);
         LibYabause.libyabause_setsndbuff(IntPtr.Zero);
         LibYabause.libyabause_deinit();
         VideoHandle.Free();
         SoundHandle.Free();
         Disposed = true;
         DeactivateGL();
     }
 }
Exemple #9
0
 public void StoreSaveRam(byte[] data)
 {
     if (Disposed)
     {
         throw new Exception("It's a bit late for that");
     }
     else
     {
         var fp = new FilePiping();
         fp.Offer(data);
         bool success = LibYabause.libyabause_loadsaveram(fp.GetPipeNameNative());
         fp.Finish();
         if (!success)
         {
             throw new Exception("libyabause_loadsaveram() failed!");
         }
     }
 }
Exemple #10
0
        private void LoadCoreBinary(byte[] data)
        {
            var fp = new FilePiping();

            fp.Offer(data);

            //loadstate can trigger GL work
            ActivateGL();

            bool succeed = LibYabause.libyabause_loadstate(fp.GetPipeNameNative());

            DeactivateGL();

            fp.Finish();
            if (!succeed)
            {
                throw new Exception("libyabause_loadstate() failed");
            }
        }
Exemple #11
0
 public void Dispose()
 {
     if (!Disposed)
     {
         ActivateGL();
         if (SaveRamModified)
         {
             DisposedSaveRam = CloneSaveRam();
         }
         LibYabause.libyabause_setvidbuff(IntPtr.Zero);
         LibYabause.libyabause_setsndbuff(IntPtr.Zero);
         LibYabause.libyabause_deinit();
         VideoHandle.Free();
         SoundHandle.Free();
         CD.Dispose();
         Disposed = true;
         DeactivateGL();
         CoreComm.ReleaseGLContext(glContext);
     }
 }
Exemple #12
0
        public void SetGLRes(int factor, int width, int height)
        {
            if (!GLMode)
            {
                return;
            }

            if (factor < 0)
            {
                factor = 0;
            }
            if (factor > 4)
            {
                factor = 4;
            }

            int maxwidth, maxheight;

            if (factor == 0)
            {
                maxwidth  = width;
                maxheight = height;
            }
            else
            {
                maxwidth  = 704 * factor;
                maxheight = 512 * factor;
            }
            if (maxwidth * maxheight > VideoBuffer.Length)
            {
                VideoHandle.Free();
                VideoBuffer = new int[maxwidth * maxheight];
                VideoHandle = GCHandle.Alloc(VideoBuffer, GCHandleType.Pinned);
                LibYabause.libyabause_setvidbuff(VideoHandle.AddrOfPinnedObject());
            }
            LibYabause.libyabause_glsetnativefactor(factor);
            if (factor == 0)
            {
                LibYabause.libyabause_glresize(width, height);
            }
        }
Exemple #13
0
        public void FrameAdvance(bool render, bool rendersound = true)
        {
            int w, h, nsamp;

            ActivateGL();

            LibYabause.Buttons1 p11 = (LibYabause.Buttons1) 0xff;
            LibYabause.Buttons2 p12 = (LibYabause.Buttons2) 0xff;
            LibYabause.Buttons1 p21 = (LibYabause.Buttons1) 0xff;
            LibYabause.Buttons2 p22 = (LibYabause.Buttons2) 0xff;

            if (Controller["P1 A"])
            {
                p11 &= ~LibYabause.Buttons1.A;
            }
            if (Controller["P1 B"])
            {
                p11 &= ~LibYabause.Buttons1.B;
            }
            if (Controller["P1 C"])
            {
                p11 &= ~LibYabause.Buttons1.C;
            }
            if (Controller["P1 Start"])
            {
                p11 &= ~LibYabause.Buttons1.S;
            }
            if (Controller["P1 Left"])
            {
                p11 &= ~LibYabause.Buttons1.L;
            }
            if (Controller["P1 Right"])
            {
                p11 &= ~LibYabause.Buttons1.R;
            }
            if (Controller["P1 Up"])
            {
                p11 &= ~LibYabause.Buttons1.U;
            }
            if (Controller["P1 Down"])
            {
                p11 &= ~LibYabause.Buttons1.D;
            }
            if (Controller["P1 L"])
            {
                p12 &= ~LibYabause.Buttons2.L;
            }
            if (Controller["P1 R"])
            {
                p12 &= ~LibYabause.Buttons2.R;
            }
            if (Controller["P1 X"])
            {
                p12 &= ~LibYabause.Buttons2.X;
            }
            if (Controller["P1 Y"])
            {
                p12 &= ~LibYabause.Buttons2.Y;
            }
            if (Controller["P1 Z"])
            {
                p12 &= ~LibYabause.Buttons2.Z;
            }

            if (Controller["P2 A"])
            {
                p21 &= ~LibYabause.Buttons1.A;
            }
            if (Controller["P2 B"])
            {
                p21 &= ~LibYabause.Buttons1.B;
            }
            if (Controller["P2 C"])
            {
                p21 &= ~LibYabause.Buttons1.C;
            }
            if (Controller["P2 Start"])
            {
                p21 &= ~LibYabause.Buttons1.S;
            }
            if (Controller["P2 Left"])
            {
                p21 &= ~LibYabause.Buttons1.L;
            }
            if (Controller["P2 Right"])
            {
                p21 &= ~LibYabause.Buttons1.R;
            }
            if (Controller["P2 Up"])
            {
                p21 &= ~LibYabause.Buttons1.U;
            }
            if (Controller["P2 Down"])
            {
                p21 &= ~LibYabause.Buttons1.D;
            }
            if (Controller["P2 L"])
            {
                p22 &= ~LibYabause.Buttons2.L;
            }
            if (Controller["P2 R"])
            {
                p22 &= ~LibYabause.Buttons2.R;
            }
            if (Controller["P2 X"])
            {
                p22 &= ~LibYabause.Buttons2.X;
            }
            if (Controller["P2 Y"])
            {
                p22 &= ~LibYabause.Buttons2.Y;
            }
            if (Controller["P2 Z"])
            {
                p22 &= ~LibYabause.Buttons2.Z;
            }


            if (Controller["Reset"])
            {
                LibYabause.libyabause_softreset();
            }
            if (Controller["Power"])
            {
                LibYabause.libyabause_hardreset();
            }

            LibYabause.libyabause_setpads(p11, p12, p21, p22);

            DriveLightOn = false;

            if (Tracer.Enabled)
            {
                LibYabause.libyabause_settracecallback(trace_cb);
            }
            else
            {
                LibYabause.libyabause_settracecallback(null);
            }

            IsLagFrame   = LibYabause.libyabause_frameadvance(out w, out h, out nsamp);
            BufferWidth  = w;
            BufferHeight = h;
            SoundNSamp   = nsamp;
            Frame++;
            if (IsLagFrame)
            {
                LagCount++;
            }
            //Console.WriteLine(nsamp);

            //CheckStates();

            DeactivateGL();
        }
Exemple #14
0
        void Init(byte[] bios)
        {
            bool GL = SyncSettings.UseGL;

            if (AttachedCore != null)
            {
                AttachedCore.Dispose();
                AttachedCore = null;
            }
            VideoHandle = GCHandle.Alloc(VideoBuffer, GCHandleType.Pinned);
            SoundHandle = GCHandle.Alloc(SoundBuffer, GCHandleType.Pinned);

            LibYabause.CDInterface CDInt = new LibYabause.CDInterface();
            CDInt.InitFunc          = InitH = new LibYabause.CDInterface.Init(CD_Init);
            CDInt.DeInitFunc        = DeInitH = new LibYabause.CDInterface.DeInit(CD_DeInit);
            CDInt.GetStatusFunc     = GetStatusH = new LibYabause.CDInterface.GetStatus(CD_GetStatus);
            CDInt.ReadTOCFunc       = ReadTOCH = new LibYabause.CDInterface.ReadTOC(CD_ReadTOC);
            CDInt.ReadSectorFADFunc = ReadSectorFADH = new LibYabause.CDInterface.ReadSectorFAD(CD_ReadSectorFAD);
            CDInt.ReadAheadFADFunc  = ReadAheadFADH = new LibYabause.CDInterface.ReadAheadFAD(CD_ReadAheadFAD);

            var    fp       = new FilePiping();
            string BiosPipe = fp.GetPipeNameNative();

            fp.Offer(bios);

            int basetime;

            if (SyncSettings.RealTimeRTC)
            {
                basetime = 0;
            }
            else
            {
                basetime = (int)((SyncSettings.RTCInitialTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds);
            }

            if (!LibYabause.libyabause_init
                (
                    ref CDInt,
                    BiosPipe,
                    GL,
                    SyncSettings.CartType,
                    SyncSettings.SkipBios,
                    !SyncSettings.RealTimeRTC,
                    basetime
                ))
            {
                throw new Exception("libyabause_init() failed!");
            }

            fp.Finish();

            LibYabause.libyabause_setvidbuff(VideoHandle.AddrOfPinnedObject());
            LibYabause.libyabause_setsndbuff(SoundHandle.AddrOfPinnedObject());
            AttachedCore = this;

            // with or without GL, this is the guaranteed frame -1 size; (unless you do a gl resize)
            BufferWidth  = 320;
            BufferHeight = 224;

            InitMemoryDomains();

            GLMode = GL;
            // if in GL mode, this will trigger the initial GL resize
            PutSyncSettings(this.SyncSettings);
        }