示例#1
0
        protected void SetData(IMemoryOwner <byte>?data)
        {
            CheckDisposed();

            // This method could be called to recalculate existing data.
            // In this case we do not want to unload the memory.
            if (!ReferenceEquals(Data, data))
            {
                UnloadRomData();
                Data = data;

                if (Data is null)
                {
                    Header = RomHeader.None;
                    Size   = RomSize.Empty;
                }
            }

            if (Data is not null)
            {
                Header = RomHeader.Create(Data.Memory.Span);
                Size   = new RomSize((ulong)Data.Memory.Span.Length);
            }

            Header ??= RomHeader.None;
            Size ??= RomSize.Empty;
        }
示例#2
0
        /// <summary>
        /// Obtains the <see cref="RomHeader"/> for the ROM data in the stream.
        /// </summary>
        /// <param name="romStream">The stream containing the ROM data.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static async ValueTask <RomHeader> GetHeaderFromStreamAsync(Stream romStream, CancellationToken cancellationToken)
        {
            byte[] headerBuffer = new byte[RomHeader.Length];

            await romStream.ReadAsync(headerBuffer, cancellationToken);

            return(RomHeader.Create(headerBuffer));
        }
示例#3
0
        /// <summary>
        /// Obtains the <see cref="RomHeader"/> for the ROM data in the stream.
        /// </summary>
        /// <param name="romStream">The stream containing the ROM data.</param>
        public static RomHeader GetHeaderFromStream(Stream romStream)
        {
            Span <byte> headerBuffer = stackalloc byte[RomHeader.Length];

            romStream.Read(headerBuffer);

            return(RomHeader.Create(headerBuffer));
        }
示例#4
0
        /// <summary>
        /// Obtains the <see cref="RomHeader"/> for the ROM data in the file.
        /// </summary>
        /// <param name="file">The file containing the ROM data.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static async ValueTask <RomHeader> GetHeaderFromFileAsync(FileInfo file, CancellationToken cancellationToken)
        {
            using var fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
            byte[] headerBuffer = new byte[RomHeader.Length];

            await fs.ReadAsync(headerBuffer, cancellationToken);

            return(RomHeader.Create(headerBuffer));
        }
示例#5
0
        /// <summary>
        /// Obtains the <see cref="RomHeader"/> for the ROM data in the file.
        /// </summary>
        /// <param name="file">The file containing the ROM data.</param>
        public static RomHeader GetHeaderFromFile(FileInfo file)
        {
            using var fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
            Span <byte> headerBuffer = stackalloc byte[RomHeader.Length];

            fs.Read(headerBuffer);

            return(RomHeader.Create(headerBuffer));
        }
示例#6
0
        /// <summary>
        /// Returns the ROM header using the data from the provided memory region.
        /// </summary>
        /// <param name="romData">The ROM data.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static ValueTask <RomHeader> GetHeaderAsync(ReadOnlySpan <byte> romData, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            return(new ValueTask <RomHeader>(RomHeader.Create(romData)));
        }
示例#7
0
 /// <summary>
 /// Returns the ROM header using the data from the provided memory region.
 /// </summary>
 /// <param name="romData">The ROM data.</param>
 public static RomHeader GetHeader(ReadOnlySpan <byte> romData)
 {
     return(RomHeader.Create(romData));
 }