Example #1
0
        public void FrameAdvance(bool render, bool rendersound = true)
        {
            Frame++;

            if (Controller["Power"])
            {
                LibVBANext.Reset(Core);
            }

            SyncTraceCallback();

            IsLagFrame = LibVBANext.FrameAdvance(Core, GetButtons(Controller), videobuff, soundbuff, out numsamp, videopalette);

            if (IsLagFrame)
            {
                LagCount++;
            }
        }
Example #2
0
        public void FrameAdvance(IController controller, bool render, bool rendersound = true)
        {
            Frame++;

            if (controller.IsPressed("Power"))
            {
                LibVBANext.Reset(Core);
            }

            SyncTraceCallback();

            IsLagFrame = LibVBANext.FrameAdvance(Core, GetButtons(controller), _videobuff, _soundbuff, out _numsamp, _videopalette);

            if (IsLagFrame)
            {
                LagCount++;
            }
        }
        public void SetScanlineCallback(Action callback, int scanline)
        {
            if (scanline < 0 || scanline > 227)
            {
                throw new ArgumentOutOfRangeException(nameof(scanline), "Scanline must be in [0, 227]!");
            }

            if (callback == null)
            {
                scanlinecb = null;
                LibVBANext.SetScanlineCallback(Core, scanlinecb, 0);
            }
            else
            {
                scanlinecb = new LibVBANext.StandardCallback(callback);
                LibVBANext.SetScanlineCallback(Core, scanlinecb, scanline);
            }
        }
Example #4
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 (!LibVBANext.BinStateLoad(Core, _savebuff, _savebuff.Length))
            {
                throw new InvalidOperationException("Core's BinStateLoad() returned false!");
            }

            // other variables
            IsLagFrame = reader.ReadBoolean();
            LagCount   = reader.ReadInt32();
            Frame      = reader.ReadInt32();
        }
        public void SaveStateText(TextWriter writer)
        {
            var s = new TextState <TextStateData>();

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

            LibVBANext.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);

            //Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
        }
Example #6
0
        public VBANext(byte[] file, CoreComm comm, GameInfo game, bool deterministic, object syncsettings)
        {
            var ser = new BasicServiceProvider(this);

            ser.Register <IDisassemblable>(new ArmV4Disassembler());
            ServiceProvider = ser;

            CoreComm = comm;

            byte[] biosfile = CoreComm.CoreFileProvider.GetFirmware("GBA", "Bios", true, "GBA bios file is mandatory.");
            if (file.Length > 32 * 1024 * 1024)
            {
                throw new ArgumentException("ROM is too big to be a GBA ROM!");
            }
            if (biosfile.Length != 16 * 1024)
            {
                throw new ArgumentException("BIOS file is not exactly 16K!");
            }

            LibVBANext.FrontEndSettings FES = new LibVBANext.FrontEndSettings();
            FES.saveType        = (LibVBANext.FrontEndSettings.SaveType)game.GetInt("saveType", 0);
            FES.flashSize       = (LibVBANext.FrontEndSettings.FlashSize)game.GetInt("flashSize", 0x10000);
            FES.enableRtc       = game.GetInt("rtcEnabled", 0) != 0;
            FES.mirroringEnable = game.GetInt("mirroringEnabled", 0) != 0;

            Console.WriteLine("GameDB loaded settings: saveType={0}, flashSize={1}, rtcEnabled={2}, mirroringEnabled={3}",
                              FES.saveType, FES.flashSize, FES.enableRtc, FES.mirroringEnable);

            _syncSettings          = (SyncSettings)syncsettings ?? new SyncSettings();
            DeterministicEmulation = deterministic;

            FES.skipBios       = _syncSettings.SkipBios;
            FES.RTCUseRealTime = _syncSettings.RTCUseRealTime;
            FES.RTCwday        = (int)_syncSettings.RTCInitialDay;
            FES.RTCyear        = _syncSettings.RTCInitialTime.Year % 100;
            FES.RTCmonth       = _syncSettings.RTCInitialTime.Month - 1;
            FES.RTCmday        = _syncSettings.RTCInitialTime.Day;
            FES.RTChour        = _syncSettings.RTCInitialTime.Hour;
            FES.RTCmin         = _syncSettings.RTCInitialTime.Minute;
            FES.RTCsec         = _syncSettings.RTCInitialTime.Second;
            if (DeterministicEmulation)
            {
                // FES.skipBios = false; // this is OK; it is deterministic and probably accurate
                FES.RTCUseRealTime = false;
            }

            Core = LibVBANext.Create();
            if (Core == IntPtr.Zero)
            {
                throw new InvalidOperationException("Create() returned nullptr!");
            }
            try
            {
                if (!LibVBANext.LoadRom(Core, file, (uint)file.Length, biosfile, (uint)biosfile.Length, FES))
                {
                    throw new InvalidOperationException("LoadRom() returned false!");
                }

                Tracer = new TraceBuffer();
                ser.Register <ITraceable>(Tracer);

                CoreComm.VsyncNum      = 262144;
                CoreComm.VsyncDen      = 4389;
                CoreComm.NominalWidth  = 240;
                CoreComm.NominalHeight = 160;

                GameCode = Encoding.ASCII.GetString(file, 0xac, 4);
                Console.WriteLine("Game code \"{0}\"", GameCode);

                savebuff  = new byte[LibVBANext.BinStateSize(Core)];
                savebuff2 = new byte[savebuff.Length + 13];
                InitMemoryDomains();
                InitRegisters();
                InitCallbacks();

                // todo: hook me up as a setting
                SetupColors();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Example #7
0
 void SyncTraceCallback()
 {
     LibVBANext.SetTraceCallback(Core, Tracer.Enabled ? tracecb : null);
 }
Example #8
0
 void SyncMemoryCallbacks()
 {
     LibVBANext.SetFetchCallback(Core, MemoryCallbacks.HasExecutes ? fetchcb : null);
     LibVBANext.SetReadCallback(Core, MemoryCallbacks.HasReads ? readcb : null);
     LibVBANext.SetWriteCallback(Core, MemoryCallbacks.HasWrites ? writecb : null);
 }
Example #9
0
 void SyncPadCallback()
 {
     LibVBANext.SetPadCallback(Core, InputCallbacks.Any() ? padcb : null);
 }
Example #10
0
        private void InitMemoryDomains()
        {
            var mm = new List <MemoryDomain>();
            var s  = new LibVBANext.MemoryAreas();
            var l  = MemoryDomain.Endian.Little;

            LibVBANext.GetMemoryAreas(Core, s);
            mm.Add(MemoryDomain.FromIntPtr("IWRAM", 32 * 1024, l, s.iwram, true, 4));
            mm.Add(MemoryDomain.FromIntPtr("EWRAM", 256 * 1024, l, s.ewram, true, 4));
            mm.Add(MemoryDomain.FromIntPtr("BIOS", 16 * 1024, l, s.bios, false, 4));
            mm.Add(MemoryDomain.FromIntPtr("PALRAM", 1024, l, s.palram, false, 4));
            mm.Add(MemoryDomain.FromIntPtr("VRAM", 96 * 1024, l, s.vram, true, 4));
            mm.Add(MemoryDomain.FromIntPtr("OAM", 1024, l, s.oam, true, 4));
            mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom, true, 4));
            mm.Add(MemoryDomain.FromIntPtr("SRAM", s.sram_size, l, s.sram, true, 4));

            mm.Add(new MemoryDomainDelegate("System Bus", 0x10000000, l,
                                            delegate(long addr)
            {
                if (addr < 0 || addr >= 0x10000000)
                {
                    throw new ArgumentOutOfRangeException();
                }
                return(LibVBANext.SystemBusRead(Core, (int)addr));
            },
                                            delegate(long addr, byte val)
            {
                if (addr < 0 || addr >= 0x10000000)
                {
                    throw new ArgumentOutOfRangeException();
                }
                LibVBANext.SystemBusWrite(Core, (int)addr, val);
            }, 4));
            // special combined ram memory domain
            {
                var          ew = mm[1];
                var          iw = mm[0];
                MemoryDomain cr = new MemoryDomainDelegate("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
                                                           delegate(long addr)
                {
                    if (addr < 0 || addr >= (256 + 32) * 1024)
                    {
                        throw new IndexOutOfRangeException();
                    }
                    if (addr >= 256 * 1024)
                    {
                        return(iw.PeekByte(addr & 32767));
                    }
                    else
                    {
                        return(ew.PeekByte(addr));
                    }
                },
                                                           delegate(long addr, byte val)
                {
                    if (addr < 0 || addr >= (256 + 32) * 1024)
                    {
                        throw new IndexOutOfRangeException();
                    }
                    if (addr >= 256 * 1024)
                    {
                        iw.PokeByte(addr & 32767, val);
                    }
                    else
                    {
                        ew.PokeByte(addr, val);
                    }
                }, 4);
                mm.Add(cr);
            }

            _memoryDomains = new MemoryDomainList(mm);
            (ServiceProvider as BasicServiceProvider).Register <IMemoryDomains>(_memoryDomains);
        }
Example #11
0
		public static extern bool BizAdvance(IntPtr ctx, LibVBANext.Buttons keys, int[] vbuff, ref int nsamp, short[] sbuff,
			long time, short gyrox, short gyroy, short gyroz, byte luma);