示例#1
0
			public CoreInfo(IEmulator emu)
			{
				TypeName = emu.GetType().ToString();
				CoreName = emu.Attributes().CoreName;
				Released = emu.Attributes().Released;
				Services = new Dictionary<string, ServiceInfo>();
				var ser = emu.ServiceProvider;
				foreach (Type t in ser.AvailableServices.Where(type => type != emu.GetType()))
				{
					var si = new ServiceInfo(t, ser.GetService(t));
					Services.Add(si.TypeName, si);
				}

				var notapplicableAttr = ((ServiceNotApplicable)Attribute
					.GetCustomAttribute(emu.GetType(), typeof(ServiceNotApplicable)));

				if (notapplicableAttr != null)
				{
					NotApplicableTypes = notapplicableAttr.NotApplicableTypes
					.Select(x => x.ToString())
					.ToList();
				}
				else
				{
					NotApplicableTypes = new List<string>();
				}
			}
示例#2
0
            public CoreInfo(IEmulator emu)
            {
                CoreName = emu.Attributes().CoreName;
                Released = emu.Attributes().Released;
                Services = new Dictionary <string, ServiceInfo>();
                var ser = emu.ServiceProvider;

                foreach (Type t in ser.AvailableServices.Where(type => type != emu.GetType()))
                {
                    var si = new ServiceInfo(t, ser.GetService(t));
                    Services.Add(si.TypeName, si);
                }

                var notApplicableAttribute = ((ServiceNotApplicableAttribute)Attribute
                                              .GetCustomAttribute(emu.GetType(), typeof(ServiceNotApplicableAttribute)));

                if (notApplicableAttribute != null)
                {
                    NotApplicableTypes = notApplicableAttribute.NotApplicableTypes
                                         .Select(x => x.ToString())
                                         .ToList();
                }
                else
                {
                    NotApplicableTypes = new List <string>();
                }
            }
示例#3
0
        public static string DisplayName(this IEmulator core)
        {
            var attr = (CoreAttribute)Attribute.GetCustomAttribute(core.GetType(), typeof(CoreAttribute));

            if (attr == null)
            {
                return(core.GetType().Name);
            }

            return(attr.DisplayName ?? attr.CoreName);
        }
示例#4
0
        public SettingsAdapter(IEmulator e)
        {
            emu = e;

            Type impl = e.GetType().GetInterfaces()
                        .Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ISettable <,>)).FirstOrDefault();

            if (impl == null)
            {
                HasSettings     = false;
                HasSyncSettings = false;
            }
            else
            {
                var tt = impl.GetGenericArguments();
                settingtype     = tt[0];
                synctype        = tt[1];
                HasSettings     = settingtype != typeof(object);             // object is used for a placeholder where an emu doesn't have both s and ss
                HasSyncSettings = synctype != typeof(object);

                if (HasSettings)
                {
                    gets = impl.GetMethod("GetSettings");
                    puts = impl.GetMethod("PutSettings");
                }
                if (HasSyncSettings)
                {
                    getss = impl.GetMethod("GetSyncSettings");
                    putss = impl.GetMethod("PutSyncSettings");
                }
            }
        }
示例#5
0
        public BasicServiceProvider(IEmulator core)
        {
            // simplified logic here doesn't scan for possible services; just adds what it knows is implemented by the core
            // this removes the possibility of automagically picking up a service in a nested class, (find the type, then
            // find the field), but we're going to keep such logic out of the basic provider.  anything the passed
            // core doesn't implement directly needs to be added with Register()
            // this also fully allows services that are not IEmulatorService
            Type coreType = core.GetType();

            var services = coreType.GetInterfaces()
                           .Where(t => typeof(IEmulatorService).IsAssignableFrom(t))
                           .Where(t => t != typeof(IEmulatorService));

            foreach (Type service in services)
            {
                Services.Add(service, core);
            }

            // add the actual instantiated type and any types in the hierarchy
            // except for object because that would be dumb (or would it?)
            while (coreType != typeof(object))
            {
                Services.Add(coreType, core);
                coreType = coreType.BaseType;
            }
        }
示例#6
0
        // TODO: This doesn't really belong here, but not sure where to put it
        public static void PopulateWithDefaultHeaderValues(
            this IMovie movie,
            IEmulator emulator,
            IGameInfo game,
            FirmwareManager firmwareManager,
            string author)
        {
            movie.Author                  = author;
            movie.EmulatorVersion         = VersionInfo.GetEmuVersion();
            movie.OriginalEmulatorVersion = VersionInfo.GetEmuVersion();
            movie.SystemID                = emulator.SystemId;

            var settable = new SettingsAdapter(emulator);

            if (settable.HasSyncSettings)
            {
                movie.SyncSettingsJson = ConfigService.SaveWithType(settable.GetSyncSettings());
            }

            if (game.IsNullInstance())
            {
                movie.GameName = "NULL";
            }
            else
            {
                movie.GameName = game.FilesystemSafeName();
                movie.Hash     = game.Hash;
                if (game.FirmwareHash != null)
                {
                    movie.FirmwareHash = game.FirmwareHash;
                }
            }

            if (emulator.HasBoardInfo())
            {
                movie.BoardName = emulator.AsBoardInfo().BoardName;
            }

            if (emulator.HasRegions())
            {
                var region = emulator.AsRegionable().Region;
                if (region == Emulation.Common.DisplayType.PAL)
                {
                    movie.HeaderEntries.Add(HeaderKeys.Pal, "1");
                }
            }

            if (firmwareManager.RecentlyServed.Any())
            {
                foreach (var firmware in firmwareManager.RecentlyServed)
                {
                    var key = $"{firmware.SystemId}_Firmware_{firmware.FirmwareId}";

                    if (!movie.HeaderEntries.ContainsKey(key))
                    {
                        movie.HeaderEntries.Add(key, firmware.Hash);
                    }
                }
            }

            if (emulator is GBHawk gbHawk && gbHawk.IsCGBMode())
            {
                movie.HeaderEntries.Add("IsCGBMode", "1");
            }

            if (emulator is SubGBHawk subgbHawk)
            {
                if (subgbHawk._GBCore.IsCGBMode())
                {
                    movie.HeaderEntries.Add("IsCGBMode", "1");
                }

                movie.HeaderEntries.Add(HeaderKeys.CycleCount, "0");
            }

            if (emulator is Gameboy gb)
            {
                if (gb.IsCGBMode())
                {
                    movie.HeaderEntries.Add("IsCGBMode", "1");
                }

                movie.HeaderEntries.Add(HeaderKeys.CycleCount, "0");
            }

            if (emulator is SMS sms)
            {
                if (sms.IsSG1000)
                {
                    movie.HeaderEntries.Add("IsSGMode", "1");
                }

                if (sms.IsGameGear)
                {
                    movie.HeaderEntries.Add("IsGGMode", "1");
                }
            }

            if (emulator is GPGX gpgx && gpgx.IsMegaCD)
            {
                movie.HeaderEntries.Add("IsSegaCDMode", "1");
            }

            if (emulator is PicoDrive pico && pico.Is32XActive)
            {
                movie.HeaderEntries.Add("Is32X", "1");
            }

            if (emulator is SubNESHawk)
            {
                movie.HeaderEntries.Add(HeaderKeys.VBlankCount, "0");
            }

            movie.Core = ((CoreAttribute)Attribute
                          .GetCustomAttribute(emulator.GetType(), typeof(CoreAttribute)))
                         .CoreName;
        }
示例#7
0
        void LoadOne(string f)
        {
            current = new Result {
                Filename = f
            };
            bool result = false;

            try
            {
                result = ldr.LoadRom(f, Comm);
            }
            catch (Exception e)
            {
                current.Status = Result.EStatus.ExceptOnLoad;
                current.Messages.Add(e.ToString());
                Results.Add(current);
                current = null;
                return;
            }
            current.Fullname = ldr.CanonicalFullPath;
            if (current.Status == Result.EStatus.ErrorOnLoad)
            {
                Results.Add(current);
                current = null;
                return;
            }
            if (result == false)
            {
                current.Status = Result.EStatus.FalseOnLoad;
                Results.Add(current);
                current = null;
                return;
            }

            using (IEmulator emu = ldr.LoadedEmulator)
            {
                current.GI        = ldr.Game;
                current.CoreType  = emu.GetType();
                emu.Controller    = new Controller(emu.ControllerDefinition);
                current.BoardName = emu.BoardName;
                // hack
                if (emu is Emulation.Cores.Nintendo.GBA.VBANext)
                {
                    current.BoardName = (emu as Emulation.Cores.Nintendo.GBA.VBANext).GameCode;
                }

                current.Frames       = 0;
                current.LaggedFrames = 0;

                for (int i = 0; i < numframes; i++)
                {
                    try
                    {
                        int     nsamp;
                        short[] samp;
                        emu.FrameAdvance(true, true);
                        // some cores really really really like it if you drain their audio every frame
                        emu.SyncSoundProvider.GetSamples(out samp, out nsamp);
                        current.Frames++;
                        if (emu.CanPollInput() && emu.AsInputPollable().IsLagFrame)
                        {
                            current.LaggedFrames++;
                        }
                    }
                    catch (Exception e)
                    {
                        current.Messages.Add(e.ToString());
                        current.Status = Result.EStatus.ExceptOnAdv;
                        Results.Add(current);
                        current = null;
                        return;
                    }
                }
            }
            current.Status = Result.EStatus.Success;
            Results.Add(current);
            current = null;
            return;
        }
示例#8
0
 public static CoreAttribute Attributes(this IEmulator core)
 {
     return((CoreAttribute)Attribute.GetCustomAttribute(core.GetType(), typeof(CoreAttribute)));
 }
示例#9
0
        private void LoadOne(string f)
        {
            _current = new Result {
                Filename = f
            };
            bool result;

            try
            {
                result = _ldr.LoadRom(f, _comm, null);
            }
            catch (Exception e)
            {
                _current.Status = Result.EStatus.ExceptOnLoad;
                _current.Messages.Add(e.ToString());
                _results.Add(_current);
                _current = null;
                return;
            }

            _current.Fullname = _ldr.CanonicalFullPath;
            if (_current.Status == Result.EStatus.ErrorOnLoad)
            {
                _results.Add(_current);
                _current = null;
                return;
            }

            if (result == false)
            {
                _current.Status = Result.EStatus.FalseOnLoad;
                _results.Add(_current);
                _current = null;
                return;
            }

            using (IEmulator emu = _ldr.LoadedEmulator)
            {
                _current.Game     = _ldr.Game;
                _current.CoreType = emu.GetType();
                var controller = new Controller(emu.ControllerDefinition);
                _current.BoardName = emu.HasBoardInfo() ? emu.AsBoardInfo().BoardName : null;

                _current.Frames       = 0;
                _current.LaggedFrames = 0;

                for (int i = 0; i < _numFrames; i++)
                {
                    try
                    {
                        emu.FrameAdvance(controller, true);

                        // some cores really really really like it if you drain their audio every frame
                        if (emu.HasSoundProvider())
                        {
                            emu.AsSoundProvider().GetSamplesSync(out _, out _);
                        }

                        _current.Frames++;
                        if (emu.CanPollInput() && emu.AsInputPollable().IsLagFrame)
                        {
                            _current.LaggedFrames++;
                        }
                    }
                    catch (Exception e)
                    {
                        _current.Messages.Add(e.ToString());
                        _current.Status = Result.EStatus.ExceptOnAdv;
                        _results.Add(_current);
                        _current = null;
                        return;
                    }
                }
            }
            _current.Status = Result.EStatus.Success;
            _results.Add(_current);
            _current = null;
        }