private readonly byte[] _disasmbuf = new byte[100];         // todo: is this big enough?

        public Ares64Disassembler(LibAres64 core)
        {
            _core = core;
        }
Example #2
0
        public Ares64(CoreLoadParameters <Ares64Settings, Ares64SyncSettings> lp)
            : base(lp.Comm, new Configuration
        {
            DefaultWidth          = 640,
            DefaultHeight         = 480,
            MaxWidth              = 640,
            MaxHeight             = 576,
            MaxSamples            = 1024,
            DefaultFpsNumerator   = 60,
            DefaultFpsDenominator = 1,
            SystemId              = VSystemID.Raw.N64,
        })
        {
            _settings     = lp.Settings ?? new();
            _syncSettings = lp.SyncSettings ?? new();

            ControllerSettings = new[]
            {
                _syncSettings.P1Controller,
                _syncSettings.P2Controller,
                _syncSettings.P3Controller,
                _syncSettings.P4Controller,
            };

            N64Controller = CreateControllerDefinition(ControllerSettings);

            _core = PreInit <LibAres64>(new WaterboxOptions
            {
                Filename                   = "ares64.wbx",
                SbrkHeapSizeKB             = 2 * 1024,
                SealedHeapSizeKB           = 4,
                InvisibleHeapSizeKB        = 6 * 1024,
                PlainHeapSizeKB            = 4,
                MmapHeapSizeKB             = 512 * 1024,
                SkipCoreConsistencyCheck   = CoreComm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck),
                SkipMemoryConsistencyCheck = CoreComm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck),
            });

            var rom = lp.Roms[0].RomData;

            Region = rom[0x3E] switch
            {
                0x44 or 0x46 or 0x49 or 0x50 or 0x53 or 0x55 or 0x58 or 0x59 => DisplayType.PAL,
                _ => DisplayType.NTSC,
            };

            var pal = Region == DisplayType.PAL;

            if (pal)
            {
                VsyncNumerator   = 50;
                VsyncDenominator = 1;
            }

            LibAres64.LoadFlags loadFlags = 0;
            if (_syncSettings.RestrictAnalogRange)
            {
                loadFlags |= LibAres64.LoadFlags.RestrictAnalogRange;
            }
            if (pal)
            {
                loadFlags |= LibAres64.LoadFlags.Pal;
            }
            if (_settings.Deinterlacer == LibAres64.DeinterlacerType.Bob)
            {
                loadFlags |= LibAres64.LoadFlags.BobDeinterlace;
            }

            var pif = Util.DecompressGzipFile(new MemoryStream(pal ? Resources.PIF_PAL_ROM.Value : Resources.PIF_NTSC_ROM.Value));

            var gbRoms    = new byte[][] { null, null, null, null };
            var numGbRoms = lp.Roms.Count - 1;

            for (int i = 0; i < numGbRoms; i++)
            {
                gbRoms[i] = lp.Roms[i + 1].RomData;
            }

            unsafe
            {
                fixed(byte *pifPtr = pif, romPtr = rom, gb1RomPtr = gbRoms[0], gb2RomPtr = gbRoms[1], gb3RomPtr = gbRoms[2], gb4RomPtr = gbRoms[3])
                {
                    var loadData = new LibAres64.LoadData()
                    {
                        PifData    = (IntPtr)pifPtr,
                        PifLen     = pif.Length,
                        RomData    = (IntPtr)romPtr,
                        RomLen     = rom.Length,
                        Gb1RomData = (IntPtr)gb1RomPtr,
                        Gb1RomLen  = gbRoms[0]?.Length ?? 0,
                        Gb2RomData = (IntPtr)gb2RomPtr,
                        Gb2RomLen  = gbRoms[1]?.Length ?? 0,
                        Gb3RomData = (IntPtr)gb3RomPtr,
                        Gb3RomLen  = gbRoms[2]?.Length ?? 0,
                        Gb4RomData = (IntPtr)gb4RomPtr,
                        Gb4RomLen  = gbRoms[3]?.Length ?? 0,
                    };

                    if (!_core.Init(ref loadData, ControllerSettings, loadFlags))
                    {
                        throw new InvalidOperationException("Init returned false!");
                    }
                }
            }

            PostInit();

            DeterministicEmulation = lp.DeterministicEmulationRequested || (!_syncSettings.UseRealTime);
            InitializeRtc(_syncSettings.InitialTime);
        }