static Bios7800 PickFirstBios7800(IEnumerable <ImportedSpecialBinaryInfo> specialBinaryInfoSet)
 => specialBinaryInfoSet
 .Select(sbi => DatastoreService.GetRomBytes(sbi.StorageKey))
 .Where(b => b.Length == 4096 || b.Length == 16384)
 .Take(1)
 .Select(b => new Bios7800(b))
 .FirstOrDefault() ?? Bios7800.Default;
Exemple #2
0
        public static IList <GameProgramInfo> GetGameProgramInfos(string romPath)
        {
            var bytes            = DatastoreService.GetRomBytes(romPath);
            var md5key           = RomBytesService.ToMD5Key(bytes);
            var romPropertiesCsv = AssetService.GetAssetByLines(Asset.ROMProperties);

            return(RomPropertiesService.ToGameProgramInfo(romPropertiesCsv)
                   .Where(gpi => gpi.MD5 == md5key)
                   .ToList());
        }
        static void Import(IEnumerable <string> paths)
        {
            DirectoryScanCompleted = false;
            CancelRequested        = false;
            FilesExamined          = 0;
            FilesRecognized        = 0;

            var romPropertiesCsv               = AssetService.GetAssetByLines(Asset.ROMProperties);
            var gameProgramInfoSet             = RomPropertiesService.ToGameProgramInfo(romPropertiesCsv);
            var gameProgramInfoMd5Dict         = gameProgramInfoSet.GroupBy(r => r.MD5).ToDictionary(g => g.Key, g => g.ToList());
            var importedGameProgramInfoMd5Dict = new Dictionary <string, ImportedGameProgramInfo>();
            var importedSpecialBinaryInfoSet   = new List <ImportedSpecialBinaryInfo>();

            DirectoryScanCompleted = true;

            foreach (var path in paths)
            {
                if (CancelRequested)
                {
                    break;
                }

                FilesExamined++;

                var bytes = DatastoreService.GetRomBytes(path);

                if (bytes.Length == 0)
                {
                    continue;
                }

                var md5key = RomBytesService.ToMD5Key(bytes);

                if (!gameProgramInfoMd5Dict.TryGetValue(md5key, out var gpiList))
                {
                    var specialBinaryType = RomBytesService.ToSpecialBinaryType(md5key);
                    if (specialBinaryType != SpecialBinaryType.None)
                    {
                        var sbi = new ImportedSpecialBinaryInfo {
                            Type = specialBinaryType, StorageKey = path
                        };
                        importedSpecialBinaryInfoSet.Add(sbi);
                    }
                    continue;
                }

                FilesRecognized++;

                foreach (var gpi in gpiList)
                {
                    if (!importedGameProgramInfoMd5Dict.TryGetValue(md5key, out var igpi))
                    {
                        igpi = new(gpi);
                        igpi.PersistedStateAt = DatastoreService.PersistedMachineAt(gpi);
                        importedGameProgramInfoMd5Dict.Add(md5key, igpi);
                    }
                    igpi.StorageKeySet.Add(path);
                }
            }

            if (CancelRequested)
            {
                return;
            }

            DatastoreService.ImportedGameProgramInfo = importedGameProgramInfoMd5Dict.Values
                                                       .Where(igpi => igpi.StorageKeySet.Count > 0)
                                                       .OrderBy(igpi => igpi.GameProgramInfo.Title);

            DatastoreService.ImportedSpecialBinaryInfo = importedSpecialBinaryInfoSet;
        }
 public static void Import()
 => Import(DatastoreService.QueryROMSFolder());
        public static MachineStateInfo Create(ImportedGameProgramInfo importedGameProgramInfo, bool use7800Bios = false, bool use7800Hsc = false)
        {
            if (importedGameProgramInfo.StorageKeySet.Count == 0)
            {
                throw new ArgumentException("importedGameProgramInfo.StorageKeySet", nameof(importedGameProgramInfo));
            }

            var romBytes = importedGameProgramInfo.StorageKeySet
                           .Select(sk => DatastoreService.GetRomBytes(sk))
                           .FirstOrDefault(b => b.Length > 0) ?? Array.Empty <byte>();

            if (romBytes.Length == 0)
            {
                Error("MachineFactory.Create: No ROM bytes");
                return(MachineStateInfo.Default);
            }

            romBytes = RomBytesService.RemoveA78HeaderIfNecessary(romBytes);

            var gameProgramInfo = importedGameProgramInfo.GameProgramInfo;

            if (gameProgramInfo.CartType == CartType.Unknown)
            {
                var inferredCartType = RomBytesService.InferCartTypeFromSize(gameProgramInfo.MachineType, romBytes.Length);
                if (inferredCartType != gameProgramInfo.CartType)
                {
                    gameProgramInfo = gameProgramInfo with {
                        CartType = inferredCartType
                    };
                }
            }

            if (gameProgramInfo.MachineType != MachineType.A7800NTSC &&
                gameProgramInfo.MachineType != MachineType.A7800PAL)
            {
                use7800Bios = use7800Hsc = false;
            }

            var bios7800 = use7800Bios ? GetBios7800(gameProgramInfo) : Bios7800.Default;
            var hsc7800  = use7800Hsc ? GetHSC7800() : HSC7800.Default;

            Cart cart;

            try
            {
                cart = Cart.Create(romBytes, gameProgramInfo.CartType);
            }
            catch (Emu7800Exception ex)
            {
                Error("MachineFactory.Create: Unable to create Cart: " + ex.Message);
                return(MachineStateInfo.Default);
            }

            MachineBase machine;

            try
            {
                machine = MachineBase.Create(gameProgramInfo.MachineType, cart, bios7800, hsc7800,
                                             gameProgramInfo.LController, gameProgramInfo.RController, NullLogger.Default);
            }
            catch (Emu7800Exception ex)
            {
                Error("MachineFactory.Create: Unable to create Machine: " + ex.Message);
                return(MachineStateInfo.Default);
            }

            return(new()
            {
                FramesPerSecond = machine.FrameHZ,
                CurrentPlayerNo = 1,
                GameProgramInfo = gameProgramInfo,
                Machine = machine
            });
        }
 static HSC7800 PickFirstHSC7800(IEnumerable <ImportedSpecialBinaryInfo> specialBinaryInfoSet)
 => specialBinaryInfoSet
 .Select(sbi => DatastoreService.GetRomBytes(sbi.StorageKey))
 .Where(b => b.Length > 0)
 .Select(b => new HSC7800(b))
 .FirstOrDefault() ?? HSC7800.Default;