public Sameboy(byte[] rom, CoreComm comm, bool sgb, Settings settings, SyncSettings syncSettings, bool deterministic) : base(comm, new Configuration { DefaultWidth = sgb && (settings == null || settings.ShowSgbBorder) ? 256 : 160, DefaultHeight = sgb && (settings == null || settings.ShowSgbBorder) ? 224 : 144, MaxWidth = sgb ? 256 : 160, MaxHeight = sgb ? 224 : 144, MaxSamples = 1024, DefaultFpsNumerator = sgb ? TICKSPERSECOND_SGB : TICKSPERSECOND, DefaultFpsDenominator = TICKSPERFRAME, SystemId = sgb ? "SGB" : "GB" }) { _corePrinterCallback = PrinterCallbackRelay; _coreScanlineCallback = ScanlineCallbackRelay; _core = PreInit <LibSameboy>(new WaterboxOptions { Filename = "sameboy.wbx", SbrkHeapSizeKB = 192, InvisibleHeapSizeKB = 12, SealedHeapSizeKB = 9 * 1024, PlainHeapSizeKB = 4, MmapHeapSizeKB = 1024, SkipCoreConsistencyCheck = comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck), SkipMemoryConsistencyCheck = comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck), }, new Delegate[] { _corePrinterCallback, _coreScanlineCallback }); _cgb = (rom[0x143] & 0xc0) == 0xc0 && !sgb; _sgb = sgb; Console.WriteLine("Automaticly detected CGB to " + _cgb); _syncSettings = syncSettings ?? new SyncSettings(); _settings = settings ?? new Settings(); var bios = _syncSettings.UseRealBIOS && !sgb ? comm.CoreFileProvider.GetFirmwareOrThrow(new(_cgb ? "GBC" : "GB", "World")) : Util.DecompressGzipFile(new MemoryStream(_cgb ? Resources.SameboyCgbBoot.Value : Resources.SameboyDmgBoot.Value)); var spc = sgb ? Util.DecompressGzipFile(new MemoryStream(Resources.SgbCartPresent_SPC.Value)) : null; _exe.AddReadonlyFile(rom, "game.rom"); _exe.AddReadonlyFile(bios, "boot.rom"); if (!_core.Init(_cgb, spc, spc?.Length ?? 0)) { throw new InvalidOperationException("Core rejected the rom!"); } _exe.RemoveReadonlyFile("game.rom"); _exe.RemoveReadonlyFile("boot.rom"); _core.GetGpuMemory(_cachedGpuPointers); PostInit(); DeterministicEmulation = deterministic || !_syncSettings.UseRealTime; InitializeRtc(_syncSettings.InitialTime); }
public Sameboy(byte[] rom, CoreComm comm, bool sgb, Settings settings, SyncSettings syncSettings, bool deterministic) : base(comm, new Configuration { DefaultWidth = sgb && (settings == null || settings.ShowSgbBorder) ? 256 : 160, DefaultHeight = sgb && (settings == null || settings.ShowSgbBorder) ? 224 : 144, MaxWidth = sgb ? 256 : 160, MaxHeight = sgb ? 224 : 144, MaxSamples = 1024, DefaultFpsNumerator = sgb ? TICKSPERSECOND_SGB : TICKSPERSECOND, DefaultFpsDenominator = TICKSPERFRAME, SystemId = sgb ? "SGB" : "GB" }) { _core = PreInit <LibSameboy>(new PeRunnerOptions { Filename = "sameboy.wbx", SbrkHeapSizeKB = 192, InvisibleHeapSizeKB = 12, SealedHeapSizeKB = 9 * 1024, PlainHeapSizeKB = 4, MmapHeapSizeKB = 1024 }); _cgb = (rom[0x143] & 0xc0) == 0xc0 && !sgb; _sgb = sgb; Console.WriteLine("Automaticly detected CGB to " + _cgb); _syncSettings = syncSettings ?? new SyncSettings(); _settings = settings ?? new Settings(); var bios = _syncSettings.UseRealBIOS && !sgb ? comm.CoreFileProvider.GetFirmware(_cgb? "GBC" : "GB", "World", true) : Util.DecompressGzipFile(new MemoryStream(_cgb ? Resources.SameboyCgbBoot : Resources.SameboyDmgBoot)); var spc = sgb ? Util.DecompressGzipFile(new MemoryStream(Resources.SgbCartPresent_SPC)) : null; _exe.AddReadonlyFile(rom, "game.rom"); _exe.AddReadonlyFile(bios, "boot.rom"); if (!_core.Init(_cgb, spc, spc?.Length ?? 0)) { throw new InvalidOperationException("Core rejected the rom!"); } _exe.RemoveReadonlyFile("game.rom"); _exe.RemoveReadonlyFile("boot.rom"); PostInit(); var scratch = new IntPtr[4]; _core.GetGpuMemory(scratch); _gpuMemory = new GPUMemoryAreas(scratch[0], scratch[1], scratch[3], scratch[2], _exe); DeterministicEmulation = deterministic || !_syncSettings.UseRealTime; InitializeRtc(_syncSettings.InitialTime); }