Beispiel #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((ProgramIdentifier.GetHashCode() * 397) ^ LineNumber);
     }
 }
 internal void AddEntries(TestProgramInformation information)
 {
     foreach (var crcData in information.Crcs.Cast <CrcDataAdvanced>())
     {
         var programIdentifier = new ProgramIdentifier(crcData.Crc, crcData.CfgCrc);
         _entries[programIdentifier] = information;
     }
 }
        public void ProgramRomInformationBuilder_BuildWithId_ResultsInExpectedId()
        {
            var builder = CreateBuilderWithRequiredFields("Testing Id");

            var expectedId            = new ProgramIdentifier(4u, 8u);
            var programRomInformation = builder.WithId(expectedId).Build();

            Assert.Equal(expectedId, programRomInformation.Id);
        }
        public void ProgramIdentifier_ToString_ProducesCorrectString()
        {
            var dataPart       = 0xFEDCBA98u;
            var otherPart      = 0x76543210u;
            var expectedString = string.Format(CultureInfo.InvariantCulture, "{0:X8},{1:X8}", dataPart, otherPart);

            var identifier = new ProgramIdentifier(dataPart, otherPart);

            Assert.Equal(expectedString, identifier.ToString());
        }
        public void ProgramIdentifier_CreateWithDataCrc_CreatesProperIdentifier()
        {
            var dataPart   = 0xFEDBADu;
            var expectedId = ((ulong)dataPart) << 32;

            var identifier = new ProgramIdentifier(dataPart);

            Assert.Equal(dataPart, identifier.DataCrc);
            Assert.Equal(0u, identifier.OtherData);
            Assert.Equal(expectedId, identifier.Id);
        }
        public void ProgramIdentifier_GetHashcode_ProducesCorrectHash()
        {
            var dataPart   = 0x123u;
            var otherPart  = 0x456u;
            var identifier = new ProgramIdentifier(dataPart, otherPart);

            var combinedParts = (((ulong)dataPart) << 32) | otherPart;
            var expectedHash  = combinedParts.GetHashCode();

            Assert.Equal(expectedHash, identifier.GetHashCode());
        }
        public void ProgramIdentifier_ImplicitOperator_CreatesProperIdentifier()
        {
            var crc        = 0x48736251u;
            var expectedId = ((ulong)crc) << 32;

            ProgramIdentifier identifier = crc;

            Assert.Equal(crc, identifier.DataCrc);
            Assert.Equal(0u, identifier.OtherData);
            Assert.Equal(expectedId, identifier.Id);
        }
        public void ProgramIdentifier_CreateWithId_CreatesProperIdentifier()
        {
            var expectedId        = 0x01234567FEDCBA98u;
            var expectedData      = (uint)(expectedId >> 32);
            var expectedOtherData = (uint)(expectedId & 0xFFFFFFFF);

            var identifier = new ProgramIdentifier(expectedId);

            Assert.Equal(expectedData, identifier.DataCrc);
            Assert.Equal(expectedOtherData, identifier.OtherData);
            Assert.Equal(expectedId, identifier.Id);
        }
        public void ProgramIdentifier_CreateWithDataAndOtherCrcs_CreatesProperIdentifier()
        {
            var dataPart   = 0xFEDCBA98u;
            var otherPart  = 0x76543210u;
            var expectedId = (((ulong)dataPart) << 32) | otherPart;

            var identifier = new ProgramIdentifier(dataPart, otherPart);

            Assert.Equal(dataPart, identifier.DataCrc);
            Assert.Equal(otherPart, identifier.OtherData);
            Assert.Equal(expectedId, identifier.Id);
        }
Beispiel #10
0
        public void Ecs_IRomCompatibleWithEcsRom_IsTrue()
        {
            var ecs = new Ecs();
            var programInformationTable = ProgramInformationTable.Initialize(Enumerable.Empty <ProgramInformationTableDescriptor>().ToArray());
            var mindStrikeProgramId     = new ProgramIdentifier(0x9D57498F);
            var mindStrikeInfo          = programInformationTable.FindProgram(mindStrikeProgramId);

            Assert.NotNull(mindStrikeInfo);
            var mindStrikeDescription = new ProgramDescription(mindStrikeProgramId.DataCrc, null, mindStrikeInfo);

            Assert.True(ecs.IsRomCompatible(mindStrikeDescription));
        }
Beispiel #11
0
        /// <summary>
        /// Checks if the given ROM's CRC data matches the given program identifier with selectable strictness. See remarks.
        /// </summary>
        /// <param name="rom">The ROM to check for a match.</param>
        /// <param name="programIdentifier">The program identifier to match.</param>
        /// <param name="cfgCrcMustMatch">If <c>true</c> and a .BIN format ROM is being checked, determines whether the CRC of the config file must match as well.</param>
        /// <returns><c>true</c> if <paramref name="rom"/>'s CRC data matches the given <paramref name="programIdentifier"/>, <c>false</c> otherwise.</returns>
        /// <remarks><para>For .BIN format ROMs, there is the possibility, depending on the value if <paramref name="cfgCrcMustMatch"/>, that a match is reported, even though
        /// the .CFG file could have a profound impact on the actual ROM being used. The .CFG file can actually cause modifications to the ROM itself, or describe different
        /// features in the ROM (e.g. different compatibility or metadata). While metadata and compatibility differences could be considered cosmetic only, they can affect
        /// how the ROM is handled by hardware in the case of LTO Flash! for example. Most important of course is the matter of the memory map, RAM mappings, or actual
        /// code modification (e.g. the patch for Dreadnaught Factor for PAL systems). That said, until .CFG CRC values are computed on a 'canonicalized' form of the .CFG
        /// file, it is important to note that mere whitespace changes will cause .CFG mismatches, making it fragile to do full compares when working with database.</para>
        /// <para>Similarly, when working with the .ROM format, it is important to note that at this time, the CRC is computed for the entire file, including metadata that
        /// may be provided. This means that mismatches can occur because a documentation credit was modified in the metadata of one version of the file, even though
        /// the executable ROM itself was not changed.</para>
        /// <para>Finally, for the LUIGI format, there is an additional challenge. To this point, this ROM format is only used as the destination format for ROMs copied to
        /// the LTO Flash! hardware, though the jzIntv emulator supports it as well. As such, it is more than a container format for .BIN or .ROM formats, as it is different
        /// in several important ways. However, it has not yet (and possibly will never become) a target ROM format. It addresses some deficiencies in the original .ROM format
        /// that parallel the limitations of the original Intellicart and CuttleCart 3 hardware. That said, in theory the LUIGI header's UID entry poses a challenge. If the
        /// LUIGI file was created from a .ROM-format ROM, it is unambiguous. However, thereafter it is not clear if the file was created directly from the assembler, in which
        /// case the UID contains an as-yet-to-be-defined strong hash of something, or wither it contains a pair of 32-bit CRC values, one from the .BIN file, the other from
        /// the corresponding .CFG file. Given the nature of more modern Intellivision programs to commonly stray from the standard set of common .CFG files (and memory maps),
        /// it will be an interesting challenge to distinguish a LUIGI created via bin2luigi from one created directly by the assembler. In such a case, most likely we'd want
        /// to bump the version number of the LUIGI header and at least set a flag somewhere in the sea of bits that we swim through to figure out all these intricacies.</para></remarks>
        public static bool MatchesProgramIdentifier(this IRom rom, ProgramIdentifier programIdentifier, bool cfgCrcMustMatch)
        {
            var match = false;

            if (rom != null)
            {
                switch (rom.Format)
                {
                case RomFormat.Bin:
                    match = (programIdentifier.DataCrc == rom.Crc) && (!cfgCrcMustMatch || (programIdentifier.OtherData == rom.CfgCrc));
                    break;

                case RomFormat.Rom:
                case RomFormat.CuttleCart3:
                case RomFormat.CuttleCart3Advanced:
                    match = programIdentifier.DataCrc == rom.Crc;
                    break;

                case RomFormat.Luigi:
                    var luigiHeader = rom.GetLuigiHeader();
                    if (luigiHeader != null)
                    {
                        match = programIdentifier.Id == luigiHeader.Uid;     // probably will never use this result, but...
                        if (luigiHeader.OriginalRomFormat == RomFormat.Bin)
                        {
                            match = (programIdentifier.DataCrc == luigiHeader.OriginalRomCrc32) && (!cfgCrcMustMatch || (programIdentifier.OtherData == luigiHeader.OriginalCfgCrc32));
                        }
                        else if (luigiHeader.OriginalRomFormat == RomFormat.Rom)
                        {
                            match = programIdentifier.DataCrc == luigiHeader.OriginalRomCrc32;
                        }

                        // else .. Should we throw here? This situation (as of 2. Sept. 2018) cannot exist.
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
            return(match);
        }
        public void MergedProgramInformationTable_FindRomWithProgramIdentifier_FindsInformationAsExpected()
        {
            var mergedInformationTable = new MergedProgramInformationTable();
            var testProgramIdentifier  = new ProgramIdentifier(0x123u, 0x456u);
            var testProgramInformation = new TestProgramInformation()
            {
                Title = "Buffy Buckingham", Features = ProgramFeatures.GetUnrecognizedRomFeatures()
            };

            testProgramInformation.AddCrcs(3);
            testProgramInformation.AddCrc(testProgramIdentifier.DataCrc, "Version 0", IncompatibilityFlags.Tutorvision, testProgramIdentifier.OtherData);
            var table = new TestProgramInformationTable();

            table.AddEntries(testProgramInformation);
            mergedInformationTable.MergeTable(table);

            var foundInformation = mergedInformationTable.FindProgram(testProgramIdentifier);

            Assert.NotNull(foundInformation);
        }
Beispiel #13
0
            public IProgramInformation FindProgram(ProgramIdentifier programIdentifier)
            {
                var information = _entries.FirstOrDefault(e => e.Key == programIdentifier.DataCrc).Value;

                return(information);
            }
 /// <inheritdoc />
 public IProgramInformation FindProgram(ProgramIdentifier programIdentifier)
 {
     return(FindProgram(programIdentifier.DataCrc));
 }
 public void ProgramIdentifier_OperatorNotEqual_ComparesIdentifiersCorrectly(ProgramIdentifier lhs, ProgramIdentifier rhs, bool expectedEqual)
 {
     Assert.NotEqual(expectedEqual, lhs != rhs);
 }
 public void ProgramIdentifier_EqualsObject_ComparesAsExpected(ProgramIdentifier identifier, object other, bool expectedEqual)
 {
     Assert.Equal(expectedEqual, identifier.Equals(other));
 }