コード例 #1
0
 static GameProgramInfoViewItem ToGameProgramInfoViewItem(ImportedGameProgramInfo igpi, Func <ImportedGameProgramInfo, string> subTitleFunc)
 => new(igpi, subTitleFunc(igpi));
コード例 #2
0
        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
            });
        }