Exemplo n.º 1
0
        public Gameboy(CoreComm comm, GameInfo game, byte[] file, object Settings, object SyncSettings, bool deterministic)
        {
            var ser = new BasicServiceProvider(this);

            ser.Register <IDisassemblable>(new GBDisassembler());
            ServiceProvider = ser;
            Tracer          = new TraceBuffer
            {
                Header = "Z80: PC, opcode, registers (A, B, C, D, E, F, H, L, LY, SP, CY)"
            };
            ser.Register <ITraceable>(Tracer);
            InitMemoryCallbacks();
            CoreComm = comm;

            comm.VsyncNum            = 262144;
            comm.VsyncDen            = 4389;
            comm.RomStatusAnnotation = null;
            comm.RomStatusDetails    = null;
            comm.NominalWidth        = 160;
            comm.NominalHeight       = 144;

            ThrowExceptionForBadRom(file);
            BoardName = MapperName(file);

            DeterministicEmulation = deterministic;

            GambatteState = LibGambatte.gambatte_create();

            if (GambatteState == IntPtr.Zero)
            {
                throw new InvalidOperationException("gambatte_create() returned null???");
            }

            try
            {
                this._syncSettings = (GambatteSyncSettings)SyncSettings ?? new GambatteSyncSettings();
                // copy over non-loadflag syncsettings now; they won't take effect if changed later
                zerotime      = (uint)this._syncSettings.RTCInitialTime;
                real_rtc_time = DeterministicEmulation ? false : this._syncSettings.RealTimeRTC;

                LibGambatte.LoadFlags flags = 0;

                if (this._syncSettings.ForceDMG)
                {
                    flags |= LibGambatte.LoadFlags.FORCE_DMG;
                }
                if (this._syncSettings.GBACGB)
                {
                    flags |= LibGambatte.LoadFlags.GBA_CGB;
                }
                if (this._syncSettings.MulticartCompat)
                {
                    flags |= LibGambatte.LoadFlags.MULTICART_COMPAT;
                }

                if (LibGambatte.gambatte_load(GambatteState, file, (uint)file.Length, GetCurrentTime(), flags) != 0)
                {
                    throw new InvalidOperationException("gambatte_load() returned non-zero (is this not a gb or gbc rom?)");
                }

                // set real default colors (before anyone mucks with them at all)
                PutSettings((GambatteSettings)Settings ?? new GambatteSettings());

                InitSound();

                Frame      = 0;
                LagCount   = 0;
                IsLagFrame = false;

                InputCallback = new LibGambatte.InputGetter(ControllerCallback);

                LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);

                InitMemoryDomains();

                CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
                                                          game.Name,
                                                          file.HashSHA1(),
                                                          file.HashMD5());

                {
                    byte[] buff = new byte[32];
                    LibGambatte.gambatte_romtitle(GambatteState, buff);
                    string romname = System.Text.Encoding.ASCII.GetString(buff);
                    Console.WriteLine("Core reported rom name: {0}", romname);
                }

                TimeCallback = new LibGambatte.RTCCallback(GetCurrentTime);
                LibGambatte.gambatte_setrtccallback(GambatteState, TimeCallback);

                CDCallback = new LibGambatte.CDCallback(CDCallbackProc);

                NewSaveCoreSetBuff();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
        public Gameboy(CoreComm comm, GameInfo game, byte[] file, object settings, object syncSettings, bool deterministic)
        {
            var ser = new BasicServiceProvider(this);

            ser.Register <IDisassemblable>(new GBDisassembler());
            ServiceProvider = ser;
            Tracer          = new TraceBuffer
            {
                Header = "Z80: PC, opcode, registers (A, B, C, D, E, F, H, L, LY, SP, CY)"
            };
            ser.Register <ITraceable>(Tracer);
            InitMemoryCallbacks();
            CoreComm = comm;

            comm.RomStatusAnnotation = null;
            comm.RomStatusDetails    = null;
            comm.NominalWidth        = 160;
            comm.NominalHeight       = 144;

            ThrowExceptionForBadRom(file);
            BoardName = MapperName(file);

            DeterministicEmulation = deterministic;

            GambatteState = LibGambatte.gambatte_create();

            if (GambatteState == IntPtr.Zero)
            {
                throw new InvalidOperationException("gambatte_create() returned null???");
            }

            Console.WriteLine(game.System);

            byte[] BiosRom;

            if (game.System == "GB")
            {
                BiosRom = new byte[256];
                BiosRom = comm.CoreFileProvider.GetFirmware("GB", "World", false);
            }
            else
            {
                BiosRom = new byte[2304];
                BiosRom = comm.CoreFileProvider.GetFirmware("GBC", "World", false);
            }

            int bios_length = BiosRom == null ? 0 : BiosRom.Length;

            try
            {
                _syncSettings = (GambatteSyncSettings)syncSettings ?? new GambatteSyncSettings();

                // copy over non-loadflag syncsettings now; they won't take effect if changed later
                zerotime = (uint)_syncSettings.RTCInitialTime;

                real_rtc_time = !DeterministicEmulation && _syncSettings.RealTimeRTC;

                LibGambatte.LoadFlags flags = 0;

                if (_syncSettings.ConsoleMode == "GB")
                {
                    flags |= LibGambatte.LoadFlags.FORCE_DMG;

                    // we need to change the BIOS to GB bios
                    if (game.System == "GBC")
                    {
                        BiosRom     = null;
                        BiosRom     = new byte[256];
                        BiosRom     = comm.CoreFileProvider.GetFirmware("GB", "World", false);
                        bios_length = BiosRom.Length;
                    }
                }
                else if (_syncSettings.ConsoleMode == "GBC")
                {
                    BiosRom     = null;
                    BiosRom     = new byte[2304];
                    BiosRom     = comm.CoreFileProvider.GetFirmware("GBC", "World", false);
                    bios_length = BiosRom.Length;
                }
                else
                {
                    if (game.System == "GB")
                    {
                        flags |= LibGambatte.LoadFlags.FORCE_DMG;
                    }
                }

                if (_syncSettings.EnableBIOS && BiosRom == null)
                {
                    throw new MissingFirmwareException("Boot Rom not found");
                }

                // to disable BIOS loading into gambatte, just set bios_length to 0
                if (!_syncSettings.EnableBIOS)
                {
                    bios_length = 0;
                }

                if (_syncSettings.GBACGB)
                {
                    flags |= LibGambatte.LoadFlags.GBA_CGB;
                }

                if (_syncSettings.MulticartCompat)
                {
                    flags |= LibGambatte.LoadFlags.MULTICART_COMPAT;
                }

                if (LibGambatte.gambatte_load(GambatteState, file, (uint)file.Length, BiosRom, (uint)bios_length, GetCurrentTime(), flags) != 0)
                {
                    throw new InvalidOperationException("gambatte_load() returned non-zero (is this not a gb or gbc rom?)");
                }

                // set real default colors (before anyone mucks with them at all)
                PutSettings((GambatteSettings)settings ?? new GambatteSettings());

                InitSound();

                Frame      = 0;
                LagCount   = 0;
                IsLagFrame = false;

                InputCallback = new LibGambatte.InputGetter(ControllerCallback);

                LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);

                InitMemoryDomains();

                CoreComm.RomStatusDetails = $"{game.Name}\r\nSHA1:{file.HashSHA1()}\r\nMD5:{file.HashMD5()}\r\n";

                byte[] buff = new byte[32];
                LibGambatte.gambatte_romtitle(GambatteState, buff);
                string romname = System.Text.Encoding.ASCII.GetString(buff);
                Console.WriteLine("Core reported rom name: {0}", romname);

                TimeCallback = new LibGambatte.RTCCallback(GetCurrentTime);
                LibGambatte.gambatte_setrtccallback(GambatteState, TimeCallback);

                _cdCallback = new LibGambatte.CDCallback(CDCallbackProc);

                NewSaveCoreSetBuff();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Exemplo n.º 3
0
        public Gameboy(CoreComm comm, GameInfo game, byte[] file, object settings, object syncSettings, bool deterministic)
        {
            var ser = new BasicServiceProvider(this);

            ser.Register <IDisassemblable>(new GBDisassembler());
            ServiceProvider = ser;
            Tracer          = new TraceBuffer
            {
                Header = "Z80: PC, opcode, registers (A, B, C, D, E, F, H, L, LY, SP, CY)"
            };
            ser.Register <ITraceable>(Tracer);
            InitMemoryCallbacks();
            CoreComm = comm;

            comm.RomStatusAnnotation = null;
            comm.RomStatusDetails    = null;
            comm.NominalWidth        = 160;
            comm.NominalHeight       = 144;

            ThrowExceptionForBadRom(file);
            BoardName = MapperName(file);

            DeterministicEmulation = deterministic;

            GambatteState = LibGambatte.gambatte_create();

            if (GambatteState == IntPtr.Zero)
            {
                throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_create)}() returned null???");
            }

            Console.WriteLine(game.System);

            try
            {
                _syncSettings = (GambatteSyncSettings)syncSettings ?? new GambatteSyncSettings();

                // copy over non-loadflag syncsettings now; they won't take effect if changed later
                zerotime = (uint)_syncSettings.RTCInitialTime;

                real_rtc_time = !DeterministicEmulation && _syncSettings.RealTimeRTC;

                DivInternal = _syncSettings.GetInitialDivInternal();

                LibGambatte.LoadFlags flags = 0;

                switch (_syncSettings.ConsoleMode)
                {
                case GambatteSyncSettings.ConsoleModeType.GB:
                    flags |= LibGambatte.LoadFlags.FORCE_DMG;
                    break;

                case GambatteSyncSettings.ConsoleModeType.GBC:
                    break;

                default:
                    if (game.System == "GB")
                    {
                        flags |= LibGambatte.LoadFlags.FORCE_DMG;
                    }
                    break;
                }

                if (_syncSettings.GBACGB)
                {
                    flags |= LibGambatte.LoadFlags.GBA_CGB;
                }

                if (_syncSettings.MulticartCompat)
                {
                    flags |= LibGambatte.LoadFlags.MULTICART_COMPAT;
                }

                if (LibGambatte.gambatte_load(GambatteState, file, (uint)file.Length, GetCurrentTime(), flags, DivInternal) != 0)
                {
                    throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_load)}() returned non-zero (is this not a gb or gbc rom?)");
                }

                if ((flags & LibGambatte.LoadFlags.FORCE_DMG) == LibGambatte.LoadFlags.FORCE_DMG)
                {
                    byte[] Bios = comm.CoreFileProvider.GetFirmware("GB", "World", true, "BIOS Not Found, Cannot Load");

                    IsCgb = false;

                    if (LibGambatte.gambatte_loaddmgbios(GambatteState, Bios) != 0)
                    {
                        throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_loaddmgbios)}() returned non-zero (bios error)");
                    }
                }
                else
                {
                    byte[] Bios = comm.CoreFileProvider.GetFirmware("GBC", "World", true, "BIOS Not Found, Cannot Load");

                    IsCgb = true;

                    if (LibGambatte.gambatte_loadgbcbios(GambatteState, Bios) != 0)
                    {
                        throw new InvalidOperationException($"{nameof(LibGambatte.gambatte_loadgbcbios)}() returned non-zero (bios error)");
                    }
                }

                // set real default colors (before anyone mucks with them at all)
                PutSettings((GambatteSettings)settings ?? new GambatteSettings());

                InitSound();

                Frame      = 0;
                LagCount   = 0;
                IsLagFrame = false;

                InputCallback = new LibGambatte.InputGetter(ControllerCallback);

                LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);

                InitMemoryDomains();

                CoreComm.RomStatusDetails = $"{game.Name}\r\nSHA1:{file.HashSHA1()}\r\nMD5:{file.HashMD5()}\r\n";

                byte[] buff = new byte[32];
                LibGambatte.gambatte_romtitle(GambatteState, buff);
                string romname = System.Text.Encoding.ASCII.GetString(buff);
                Console.WriteLine("Core reported rom name: {0}", romname);

                TimeCallback = new LibGambatte.RTCCallback(GetCurrentTime);
                LibGambatte.gambatte_setrtccallback(GambatteState, TimeCallback);

                _cdCallback = new LibGambatte.CDCallback(CDCallbackProc);

                NewSaveCoreSetBuff();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Exemplo n.º 4
0
		public Gameboy(CoreComm comm, GameInfo game, byte[] romdata, object Settings, object SyncSettings, bool deterministic)
		{
			CoreComm = comm;

			comm.VsyncNum = 262144;
			comm.VsyncDen = 4389;
			comm.RomStatusAnnotation = null;
			comm.RomStatusDetails = null;
			comm.CpuTraceAvailable = true;
			comm.NominalWidth = 160;
			comm.NominalHeight = 144;

			ThrowExceptionForBadRom(romdata);
			BoardName = MapperName(romdata);

			DeterministicEmulation = deterministic;

			GambatteState = LibGambatte.gambatte_create();

			if (GambatteState == IntPtr.Zero)
				throw new InvalidOperationException("gambatte_create() returned null???");

			try
			{
				this._SyncSettings = (GambatteSyncSettings)SyncSettings ?? new GambatteSyncSettings();
				// copy over non-loadflag syncsettings now; they won't take effect if changed later
				zerotime = (uint)this._SyncSettings.RTCInitialTime;
				real_rtc_time = DeterministicEmulation ? false : this._SyncSettings.RealTimeRTC;

				LibGambatte.LoadFlags flags = 0;

				if (this._SyncSettings.ForceDMG)
					flags |= LibGambatte.LoadFlags.FORCE_DMG;
				if (this._SyncSettings.GBACGB)
					flags |= LibGambatte.LoadFlags.GBA_CGB;
				if (this._SyncSettings.MulticartCompat)
					flags |= LibGambatte.LoadFlags.MULTICART_COMPAT;

				if (LibGambatte.gambatte_load(GambatteState, romdata, (uint)romdata.Length, GetCurrentTime(), flags) != 0)
					throw new InvalidOperationException("gambatte_load() returned non-zero (is this not a gb or gbc rom?)");

				// set real default colors (before anyone mucks with them at all)
				PutSettings(Settings ?? new GambatteSettings());

				InitSound();

				Frame = 0;
				LagCount = 0;
				IsLagFrame = false;

				InputCallback = new LibGambatte.InputGetter(ControllerCallback);

				LibGambatte.gambatte_setinputgetter(GambatteState, InputCallback);

				InitMemoryDomains();

				CoreComm.RomStatusDetails = string.Format("{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
					game.Name,
					romdata.HashSHA1(),
					romdata.HashMD5());

				{
					byte[] buff = new byte[32];
					LibGambatte.gambatte_romtitle(GambatteState, buff);
					string romname = System.Text.Encoding.ASCII.GetString(buff);
					Console.WriteLine("Core reported rom name: {0}", romname);
				}

				TimeCallback = new LibGambatte.RTCCallback(GetCurrentTime);
				LibGambatte.gambatte_setrtccallback(GambatteState, TimeCallback);

				NewSaveCoreSetBuff();
			}
			catch
			{
				Dispose();
				throw;
			}
		}