Example #1
0
        /// <summary>
        /// Reads LDA data blocks
        /// </summary>
        /// <remarks>
        /// The format of LDA blocks is:
        /// +------+
        /// | 0001 | - word16 - Magic
        /// |------|
        /// | BC   | - word16 - Count
        /// |------|
        /// | ADDR | - word16 - Absolute load address
        /// |------|
        /// | Data | - byte[] - Data (`Count` bytes)
        ///   ...  
        /// |------|
        /// | Chk  | - byte - Checksum
        /// +------+
        /// </remarks>
        /// <param name="rdr"></param>
        /// <returns></returns>
        public ImageSegment ReadDataBlock(LeImageReader rdr)
        {
            ushort w;
            ushort count;
            ushort uAddr;
            byte b;
            if (!rdr.TryReadLeUInt16(out w) || w != 0x0001)
                return null;
            if (!rdr.TryReadLeUInt16(out count))
                return null;
            if (!rdr.TryReadLeUInt16(out uAddr))
                return null;
            var data = rdr.ReadBytes(count);
            if (data == null || data.Length < count)
                return null;
            if (!rdr.TryReadByte(out b))
                return null;

            Debug.Print("Data block: {0:X4} {1:X4}", uAddr, count);
            return new ImageSegment(
                string.Format("seg{0:X4}", uAddr),
                new MemoryArea(Address.Ptr16(uAddr), data),
                AccessMode.ReadWriteExecute);
        }