Esempio n. 1
0
        /// <summary>
        /// Creates a new instance of a RomMetadataBlock by inflating it from a BinaryReader.
        /// </summary>
        /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param>
        /// <returns>A new instance of a RomMetadataBlock.</returns>
        /// <remarks>It is assumed that the reader is currently positioned at the beginning of a serialized ROM metadata block.</remarks>
        public static RomMetadataBlock Inflate(INTV.Core.Utility.BinaryReader reader)
        {
            RomMetadataBlock metadataBlock = null;
            int additionalBytesInPayloadLength;
            var payloadLength     = DecodeLength(reader, out additionalBytesInPayloadLength);
            var metadataBlockType = (RomMetadataIdTag)reader.ReadByte();

            switch (metadataBlockType)
            {
            case RomMetadataIdTag.Title:
            case RomMetadataIdTag.ShortTitle:
            case RomMetadataIdTag.License:
            case RomMetadataIdTag.Description:
            case RomMetadataIdTag.Version:
            case RomMetadataIdTag.UrlContactInfo:
                metadataBlock = new RomMetadataString(payloadLength, metadataBlockType);
                break;

            case RomMetadataIdTag.ReleaseDate:
            case RomMetadataIdTag.BuildDate:
                metadataBlock = new RomMetadataDate(payloadLength, metadataBlockType);
                break;

            case RomMetadataIdTag.Features:
                metadataBlock = new RomMetadataFeatures(payloadLength);
                break;

            case RomMetadataIdTag.Publisher:
                metadataBlock = new RomMetadataPublisher(payloadLength);
                break;

            case RomMetadataIdTag.Credits:
                metadataBlock = new RomMetadataCredits(payloadLength);
                break;

            case RomMetadataIdTag.ControllerBindings:
                metadataBlock = new RomMetadataControllerBindings(payloadLength);
                break;

            default:
                metadataBlock = new RomMetadataBlock(payloadLength, metadataBlockType);
                break;
            }
            metadataBlock._deserializeByteCount = (int)payloadLength + additionalBytesInPayloadLength + 1 + CrcByteCount + sizeof(RomMetadataIdTag);
            metadataBlock.Deserialize(reader);

            // Re-reading the block is more expensive than having a running CRC16 but it's easier to implement. :P
            var numBytesInForCrc = metadataBlock._deserializeByteCount - CrcByteCount;

            reader.BaseStream.Seek(-numBytesInForCrc, System.IO.SeekOrigin.Current);
            var payload = reader.ReadBytes(numBytesInForCrc);

            metadataBlock.Crc = (ushort)(((int)reader.ReadByte() << 8) | reader.ReadByte());
            metadataBlock.ValidatePayloadCrc(payload);

            return(metadataBlock);
        }
Esempio n. 2
0
        /// <inheritdoc/>
        protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader)
        {
            var publisherId = (PublisherId)reader.ReadByte();

            Publisher = PublisherIdToString(publisherId, (int)Length, reader);
            return(Length);
        }
        /// <inheritdoc/>
        protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader)
        {
            var bytesParsed       = 0u;
            var descriptionBuffer = new List <byte>();
            var currentController = Controller.None;

            while (bytesParsed < Length)
            {
                var value = reader.ReadByte();
                ++bytesParsed;
                var input      = (InputSource)value;
                var controller = GetController(input);
                if (controller == Controller.None)
                {
                    descriptionBuffer.Add(value);
                }
                else
                {
                    // Finished previous.
                    AddControllerToBindings(currentController, descriptionBuffer);
                    currentController = controller;
                    descriptionBuffer.Clear();
                }
            }
            AddControllerToBindings(currentController, descriptionBuffer);
            return(Length);
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override int Deserialize(INTV.Core.Utility.BinaryReader reader)
        {
            FileType = (FileType)reader.ReadByte();
            Color    = (INTV.Core.Model.Stic.Color)reader.ReadByte();

            var nameBuffer = reader.ReadBytes(FileSystemConstants.MaxShortNameLength);
            var nameLength = System.Array.IndexOf(nameBuffer, (byte)0);

            if (nameLength < 0)
            {
                nameLength = FileSystemConstants.MaxShortNameLength;
            }
            if (nameLength > 0)
            {
                ShortName = System.Text.Encoding.ASCII.GetString(nameBuffer, 0, nameLength);
            }

            nameBuffer = reader.ReadBytes(FileSystemConstants.MaxLongNameLength);
            nameLength = System.Array.IndexOf(nameBuffer, (byte)0);
            if (nameLength < 0)
            {
                nameLength = FileSystemConstants.MaxLongNameLength;
            }
            if (nameLength > 0)
            {
                LongName = System.Text.Encoding.ASCII.GetString(nameBuffer, 0, nameLength);
            }

            GlobalDirectoryNumber = reader.ReadByte();
            Reserved = reader.ReadByte();

            for (int i = (int)ForkKind.FirstKind; i < (int)ForkKind.NumberOfForkKinds; ++i)
            {
                _forks[i] = reader.ReadUInt16();
            }
            return(DeserializeByteCount);
        }
Esempio n. 5
0
        /// <inheritdoc/>
        protected override uint DeserializePayload(INTV.Core.Utility.BinaryReader reader)
        {
            var remainingPayload = Length;

            if (remainingPayload < 3)
            {
                System.Diagnostics.Debug.WriteLine("Too few bytes in feature metadata!");
            }
            if (remainingPayload > 0)
            {
                // The first byte contains compatibility:
                // .   7   6   5   4   3   2   1   0
                // +---+---+---+---+---+---+---+---+
                // |  ECS  | rsvd | VOICE | KEYBD |    byte 0
                // +---+---+---+---+---+---+---+---+
                Features = ProgramFeatures.DefaultFeatures.Clone();
                var featureBits = reader.ReadByte();
                --remainingPayload;

                // Bits 0,1 are Keyboard Component compatibility.
                var compatibility = RawFeatureToFeatureCompatibility(featureBits & FeatureMask);
                Features.KeyboardComponent = (KeyboardComponentFeatures)compatibility;

                // Bits 2,3 are Intellivoice compatibility.
                compatibility         = RawFeatureToFeatureCompatibility((featureBits >> 2) & FeatureMask);
                Features.Intellivoice = compatibility;

                // Bits 4,5 are reserved (used to be 4-controller capability) (ignored)
                ////compatibility = RawFeatureToFeatureCompatibility((featureBits >> 4) & FeatureMask);

                // Bits 6,7 are ECS compatibility.
                compatibility = RawFeatureToFeatureCompatibility((featureBits >> 6) & FeatureMask);
                Features.Ecs  = (EcsFeatures)compatibility;
            }
            if (remainingPayload > 0)
            {
                // The second byte contains more compatibility:
                // .   7   6   5   4   3   2   1   0
                // +---+---+---+---+---+---+---+---+
                // | rsvd  | rsvd  | TUTOR | INTY2 |    byte 1
                // +---+---+---+---+---+---+---+---+
                var featureBits = reader.ReadByte();
                --remainingPayload;

                // Bits 0,1 are Intellivision II compatibility.
                var compatibility = RawFeatureToFeatureCompatibility(featureBits & FeatureMask);
                Features.IntellivisionII = compatibility;

                // Bits 2,3 are TutorVision compatibility.
                compatibility        = RawFeatureToFeatureCompatibility((featureBits >> 2) & FeatureMask);
                Features.Tutorvision = compatibility;
            }
            if (remainingPayload > 0)
            {
                // The third byte contains emulator-specific guidance.
                // .    7    6    5    4    3    2    1    0
                // +----+----+----+----+----+----+----+----+
                // |rsvd|rsvd|rsvd|rsvd|rsvd|rsvd|rsvd|rsvd|    byte 2
                // +----+----+----+----+----+----+----+----+

                // We're going to ignore this byte.
                reader.ReadByte();
                --remainingPayload;
            }
            if (remainingPayload > 1)
            {
                // These two bytes contain JLP compatibility.
                // .    7    6    5    4    3    2    1    0
                // +----+----+----+----+----+----+----+----+
                // |JLP Accel|LTOM|   Reserved   |JLPf 9..8|    byte 3
                // +----+----+----+----+----+----+----+----+
                var featureBits = reader.ReadByte();
                --remainingPayload;
                var compatibility = (FeatureCompatibility)((featureBits >> 6) & FeatureMask);
                Features.Jlp = (JlpFeatures)compatibility;
                if (((1 << 5) & featureBits) != 0)
                {
                    Features.LtoFlash |= LtoFlashFeatures.LtoFlashMemoryMapped;
                }
                var flashSectors = (ushort)((featureBits & FeatureMask) << 8);

                // .    7    6    5    4    3    2    1    0
                // +----+----+----+----+----+----+----+----+
                // |          JLP Flash bits 7..0          |    byte 4
                // +----+----+----+----+----+----+----+----+
                flashSectors |= reader.ReadByte();
                --remainingPayload;
                Features.JlpFlashMinimumSaveSectors = flashSectors;
                if (Features.Jlp != JlpFeatures.Incompatible)
                {
                    Features.JlpHardwareVersion = JlpHardwareVersion.Jlp03; // Assume minimal hardware version needed
                }
            }
            if (remainingPayload > 0)
            {
                reader.BaseStream.Seek(remainingPayload, System.IO.SeekOrigin.Current);
            }
            return(Length);
        }