internal static List <HexRecord> ToHexRecords(this IMemory memory)
        {
            List <HexRecord> hexRecordList = new List <HexRecord>();

            byte[]           line = new byte[16];
            bool             firstSegmentAddress = false;
            AddressHexRecord addressHexRecord    = null;

            for (long i = 0; i < memory.Size; i++)
            {
                if ((i & 0xFFFF) == 0)
                {
                    HexRecordType type = (memory.IsExtendedMemory == true) ?
                                         HexRecordType.ExtendedLinearAddress :
                                         HexRecordType.ExtendedSegmentAddress;
                    addressHexRecord    = new AddressHexRecord(type, i);
                    firstSegmentAddress = true;
                }
                line[i & 0x0F] = memory[i];
                if ((int)(i & 0x0F) == 0xF)
                {
                    if (!line.IsEmpty())
                    {
                        if (firstSegmentAddress)
                        {
                            firstSegmentAddress = false;
                            hexRecordList.Add(addressHexRecord);
                        }
                        hexRecordList.Add(new DataHexRecord(HexRecordType.Data, i - 0xF, line.Copy()));
                    }
                }
            }
            return(hexRecordList);
        }
        public void Validate(string record)
        {
            HexRecordType type = record.GetRecordType();
            Regex         rgx  = new Regex(patterns[type]);

            if (!rgx.IsMatch(record))
            {
                throw new HexRecordValidationException(string.Format(Resources.RecordDoesNotMatchThePattern, record, patterns[type]));
            }
        }
Example #3
0
        public HexLineContent(string line)
        {
            var bcount = Convert.ToByte(line.Substring(1, 2), 16);

            LineStartAddr = Convert.ToUInt16(line.Substring(3, 4), 16);
            Type          = (HexRecordType)Convert.ToByte(line.Substring(7, 2), 16);
            var data = new List <byte>();

            for (var i = 0; i < bcount; i++)
            {
                data.Add(Convert.ToByte(line.Substring(9 + i * 2, 2), 16));
            }
            Data = data.ToArray();
            var cksum = Convert.ToByte(line.Substring(9 + bcount * 2, 2), 16);

            if (cksum != CalcCheckSum())
            {
                throw new Exception();
            }
        }
Example #4
0
 internal AddressHexRecord(string record)
 {
     _type    = record.GetRecordType();
     _address = record.GetAddress();
 }
Example #5
0
 internal AddressHexRecord(HexRecordType type, long address)
 {
     _type    = type;
     _address = address;
 }
Example #6
0
 internal DataHexRecord(string record)
 {
     _type    = record.GetRecordType();
     _address = record.GetAddress();
     _data    = record.GetDataBytes();
 }
Example #7
0
 internal DataHexRecord(HexRecordType type, long address, byte[] data)
 {
     _type    = type;
     _address = address;
     _data    = data;
 }
Example #8
0
 public HexLineContent(string line)
 {
     var bcount = Convert.ToByte(line.Substring(1, 2), 16);
     LineStartAddr = Convert.ToUInt16(line.Substring(3, 4), 16);
     Type = (HexRecordType)Convert.ToByte(line.Substring(7, 2), 16);
     var data = new List<byte>();
     for (var i = 0; i < bcount; i++) {
         data.Add(Convert.ToByte(line.Substring(9 + i * 2, 2), 16));
     }
     Data = data.ToArray();
     var cksum = Convert.ToByte(line.Substring(9 + bcount * 2, 2), 16);
     if (cksum != CalcCheckSum()) {
         throw new Exception();
     }
 }
Example #9
0
 internal DataHexRecord(string record)
 {
     _type = record.GetRecordType();
     _address = record.GetAddress();
     _data = record.GetDataBytes();
 }
Example #10
0
 internal DataHexRecord(HexRecordType type, long address, byte[] data)
 {
     _type = type;
     _address = address;
     _data = data;
 }
Example #11
0
 internal AddressHexRecord(string record)
 {
     _type = record.GetRecordType();
     _address = record.GetAddress();
 }
Example #12
0
 internal AddressHexRecord(HexRecordType type, long address)
 {
     _type = type;
     _address = address;
 }