Exemplo n.º 1
0
        public void LuigiFormatRom_LoadStandardLuigi_VerifyTargetDeviceUniqueId()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.True(string.IsNullOrEmpty(rom.TargetDeviceUniqueId));
        }
Exemplo n.º 2
0
        public void LuigiFormatRom_LoadScrambledForAnyLuigiWithMetadataRequestTestBlock_VerifyTestBlockNotFound()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiWithMetadatdaScrambledForAnyDevicePath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.Null(rom.LocateDataBlock <LuigiTestDataBlock>());
        }
Exemplo n.º 3
0
        public void LuigiFormatRom_Load_VerifyCrc24()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.Equal(0x0035f671u, rom.Crc24);
        }
Exemplo n.º 4
0
        public void LuigiFormatRom_LoadScrambledForAnyLuigi_VerifyTargetDeviceUniqueId()
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiScrambledForAnyDevicePath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            Assert.Equal(LuigiScrambleKeyBlock.AnyLTOFlashId, rom.TargetDeviceUniqueId);
        }
Exemplo n.º 5
0
        public void LuigiFormatRom_LoadScrambledLuigis_VerifyTargetDeviceUniqueIds()
        {
            var paths = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiScrambledForDevice0Path, TestRomResources.TestLuigiScrambledForDevice1Path);
            var rom0  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(paths[0], null));
            var rom1  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(paths[1], null));

            Assert.NotEqual(rom0.TargetDeviceUniqueId, rom1.TargetDeviceUniqueId);
            Assert.Equal(TestRomResources.TestLuigiScrambledForDevice0UniqueId, rom0.TargetDeviceUniqueId);
            Assert.Equal(TestRomResources.TestLuigiScrambledForDevice1UniqueId, rom1.TargetDeviceUniqueId);
        }
Exemplo n.º 6
0
        public void LuigiFormatRom_GetComparisonIgnoreRanges_ReturnsCorrectNumberOfExcludeRanges(bool excludeFeatureBits, int expectedNumberOfExcludeRanges)
        {
            var romPath = LuigiFormatRomTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).First();
            var rom     = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(romPath, null));

            // Three ranges of values are ignored in this case:
            // 1. Feature flags (depends on value of excludeFeatureBits)
            // 2. The UID (which for this specific test ROM is the CRC32 of the .BIN and the CRC32 of the .CFG of the original ROM
            // 3. The CRC of the header
            var rangesToIgnore = rom.GetComparisonIgnoreRanges(excludeFeatureBits);

            Assert.Equal(expectedNumberOfExcludeRanges, rangesToIgnore.Count());
        }
        public void LuigiFileMetadataProgramInformation_AddCrc_ThrowsInvalidOperationException()
        {
            var path = LuigiFileMetadataProgramInformationTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).Single();
            var rom  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(path, null));

            Assert.NotNull(rom);
            var metadataBlock = rom.LocateDataBlock <LuigiMetadataBlock>();

            Assert.Null(metadataBlock);

            var information = new LuigiFileMetadataProgramInformation(rom.Header, metadataBlock);

            Assert.Throws <InvalidOperationException>(() => information.AddCrc(1u, "version", IncompatibilityFlags.None));
        }
        public void LuigiFileMetadataProgramInformation_CreateWithMetadatda_DataOriginIsCorrect()
        {
            var path = LuigiFileMetadataProgramInformationTestStorageAccess.Initialize(TestRomResources.TestLuigiWithMetadataPath).Single();
            var rom  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(path, null));

            Assert.NotNull(rom);
            var metadataBlock = rom.LocateDataBlock <LuigiMetadataBlock>();

            Assert.NotNull(metadataBlock);

            var information = new LuigiFileMetadataProgramInformation(rom.Header, metadataBlock);

            VerifyMetadataInformation(information);
        }
        public void CfgFileMetadataProgramInformation_CreateUsingRomWithUnknownMetadataBlockType_ContainsValidMetadata()
        {
            var romPaths = CfgFileMetadataProgramInformationTestStorageAccess.Initialize(TestRomResources.TestBinPath, TestRomResources.TestCfgMetadataPath);
            var rom      = Rom.AsSpecificRomType <BinFormatRom>(Rom.Create(romPaths[0], romPaths[1]));

            rom.MetadataCacheEnabled = true;
            Assert.NotNull(rom.Metadata);
            var metadata = (List <CfgVarMetadataBlock>)rom.Metadata;

            metadata.Add(new CfgVarMetadataFeatureCompatibility(CfgVarMetadataIdTag.Invalid));

            var cfgMetadataInformation = new CfgFileMetadataProgramInformation(rom);

            Assert.NotNull(cfgMetadataInformation.Metadata);
        }
        public void LuigiFileMetadataProgramInformation_CreateWithNoMetadatda_VerifySetYear()
        {
            var path = LuigiFileMetadataProgramInformationTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).Single();
            var rom  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(path, null));

            Assert.NotNull(rom);
            var metadataBlock = rom.LocateDataBlock <LuigiMetadataBlock>();

            Assert.Null(metadataBlock);
            var information = new LuigiFileMetadataProgramInformation(rom.Header, metadataBlock);

            Assert.Null(information.Year);

            var testYear = "1989";

            information.Year = testYear;
            Assert.Equal(testYear, information.Year);
        }
        public void LuigiFileMetadataProgramInformation_CreateWithNoMetadatda_VerifySetFeatures()
        {
            var path = LuigiFileMetadataProgramInformationTestStorageAccess.Initialize(TestRomResources.TestLuigiFromBinPath).Single();
            var rom  = Rom.AsSpecificRomType <LuigiFormatRom>(Rom.Create(path, null));

            Assert.NotNull(rom);
            var metadataBlock = rom.LocateDataBlock <LuigiMetadataBlock>();

            Assert.Null(metadataBlock);
            var information     = new LuigiFileMetadataProgramInformation(rom.Header, metadataBlock);
            var currentFeatures = information.Features;

            Assert.NotNull(currentFeatures);

            var testFeatures = currentFeatures.Clone();

            testFeatures.Ecs     = EcsFeatures.Printer;
            information.Features = testFeatures;

            Assert.NotEqual(testFeatures, currentFeatures);
            Assert.True(object.ReferenceEquals(testFeatures, information.Features));
        }
        public void CfgFileMetadataProgramInformation_CreateUsingRomWithZeroSizeJlpFlash_ContainsValidMetadata()
        {
            IReadOnlyList <string> romPaths;
            var storage = CfgFileMetadataProgramInformationTestStorageAccess.Initialize(out romPaths, TestRomResources.TestBinPath, TestRomResources.TestCfgMetadataPath);

            using (var cfgFile = storage.Open(romPaths[1]))
            {
                var cfgContent = "[vars]\njlp=2\njlp_flash=0\n";
                var cfgBytes   = Encoding.UTF8.GetBytes(cfgContent);
                cfgFile.Write(cfgBytes, 0, cfgBytes.Length);
                cfgFile.SetLength(cfgBytes.Length);
            }
            var rom = Rom.AsSpecificRomType <BinFormatRom>(Rom.Create(romPaths[0], romPaths[1]));

            rom.MetadataCacheEnabled = true;
            Assert.NotNull(rom.Metadata);

            var cfgMetadataInformation = new CfgFileMetadataProgramInformation(rom);

            Assert.NotNull(cfgMetadataInformation.Metadata);
            Assert.Equal((ushort)0, cfgMetadataInformation.Features.JlpFlashMinimumSaveSectors);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="INTV.Core.Model.Program.RomFileMetadataProgramInformation"/> class.
        /// </summary>
        /// <param name="rom">The ROM whose metadata program information is desired. If not a RomFormatRom, the
        /// metadata will be empty, and the features will be generic unrecognized ROM features.</param>
        public RomFileMetadataProgramInformation(IRom rom)
        {
            _features = ProgramFeatures.GetUnrecognizedRomFeatures();
            Metadata  = Enumerable.Empty <RomMetadataBlock>();
            var romFormatRom = Rom.AsSpecificRomType <RomFormatRom>(rom);

            if (romFormatRom != null)
            {
                Metadata = romFormatRom.Metadata;
                var stringMetaData = Metadata.FirstOrDefault(m => m.Type == RomMetadataIdTag.Title) as RomMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _title = stringMetaData.StringValue;
                }
                stringMetaData = Metadata.FirstOrDefault(m => m.Type == RomMetadataIdTag.ShortTitle) as RomMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _shortName = stringMetaData.StringValue;
                }
                var date = Metadata.OfType <RomMetadataDate>().FirstOrDefault(d => d.Type == RomMetadataIdTag.ReleaseDate);
                if ((date != null) && date.Date.Flags.HasFlag(MetadataDateTimeFlags.Year))
                {
                    _year = date.Date.Date.Year.ToString();
                }
                var vendor = Metadata.OfType <RomMetadataPublisher>().FirstOrDefault();
                if (vendor != null)
                {
                    _vendor = vendor.Publisher;
                }
                var features = Metadata.OfType <RomMetadataFeatures>().FirstOrDefault();
                if (features != null)
                {
                    _features = features.Features;
                }
                _crc = new CrcData(romFormatRom.Crc, string.Empty, _features.ToIncompatibilityFlags());
            }
        }
Exemplo n.º 14
0
        public CfgFileMetadataProgramInformation(IRom rom)
        {
            _features = ProgramFeatures.GetUnrecognizedRomFeatures();
            Metadata  = Enumerable.Empty <CfgVarMetadataBlock>();
            var binFormatRom = Rom.AsSpecificRomType <BinFormatRom>(rom);

            if (binFormatRom != null)
            {
                Metadata = binFormatRom.Metadata;
                var stringMetaData = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.Name) as CfgVarMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _title = stringMetaData.StringValue;
                }
                stringMetaData = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.ShortName) as CfgVarMetadataString;
                if ((stringMetaData != null) && !string.IsNullOrEmpty(stringMetaData.StringValue))
                {
                    _shortName = stringMetaData.StringValue;
                }
                var date = Metadata.OfType <CfgVarMetadataDate>().FirstOrDefault(d => d.Type == CfgVarMetadataIdTag.ReleaseDate);
                if ((date != null) && date.Date.Flags.HasFlag(MetadataDateTimeFlags.Year))
                {
                    _year = date.Date.Date.Year.ToString();
                }
                var vendor = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.Publisher) as CfgVarMetadataString;
                if (vendor != null)
                {
                    _vendor = vendor.StringValue;
                }

                // NOTE: If these are specified multiple times, the 'last one wins' rule will be in effect.
                // That's technically OK, since the behavior is unspecified. From as1600.txt:
                //
                // Lines marked with a "*" can be repeated.  For example, if a game has multiple
                // authors, you can list them all with their own author variable.  Likewise, if
                // a program was released multiple times, you can give a list of release dates.
                //
                // For other values, repeating a variable does not have a well defined meaning.
                // Typically (but not always), the first instance takes precedence.
                //
                // So in the case of specifying features multiple times, this code will result in
                // 'last one wins'.
                foreach (var feature in Metadata.OfType <CfgVarMetadataFeatureCompatibility>())
                {
                    switch (feature.Type)
                    {
                    case CfgVarMetadataIdTag.Ecs:
                    case CfgVarMetadataIdTag.EcsCompatibility:
                        _features.Ecs = (EcsFeatures)feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.Voice:
                    case CfgVarMetadataIdTag.IntellivoiceCompatibility:
                        _features.Intellivoice = feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.IntellivisionII:
                    case CfgVarMetadataIdTag.IntellivisionIICompatibility:
                        _features.IntellivisionII = feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.KeyboardComponentCompatibility:
                        _features.KeyboardComponent = (KeyboardComponentFeatures)feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.TutorvisionCompatibility:
                        _features.Tutorvision = feature.Compatibility;
                        break;

                    case CfgVarMetadataIdTag.JlpAccelerators:
                    case CfgVarMetadataIdTag.Jlp:
                        _features.Jlp = (JlpFeatures)feature.Compatibility;
                        if (_features.Jlp != JlpFeatures.Incompatible)
                        {
                            _features.JlpHardwareVersion = JlpHardwareVersion.Jlp03;     // Assume minimal hardware version needed
                            if (_features.Jlp > JlpFeatures.Tolerates)
                            {
                                // Flash storage is indicated, so check for it.
                                var flashStorage = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.JlpFlash) as CfgVarMetadataInteger;
                                if ((flashStorage != null) && (flashStorage.IntegerValue > 0))
                                {
                                    // TODO: Min value checking here?
                                    _features.JlpFlashMinimumSaveSectors = (ushort)flashStorage.IntegerValue;
                                    _features.Jlp |= JlpFeatures.SaveDataRequired;
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
                var ltoMapper = Metadata.FirstOrDefault(m => m.Type == CfgVarMetadataIdTag.LtoFlashMapper) as CfgVarMetadataBoolean;
                if (ltoMapper != null)
                {
                    _features.LtoFlash = LtoFlashFeatures.Requires | LtoFlashFeatures.LtoFlashMemoryMapped;
                }
                _crc = new CrcData(binFormatRom.Crc, string.Empty, _features.ToIncompatibilityFlags());
            }
        }