Ejemplo n.º 1
0
 public bool Equals(HexRecord other)
 {
     if (other.Type != this.Type)
     {
         return(false);
     }
     if (this.Data.Count != other.Data.Count)
     {
         return(false);
     }
     return(Type == RecordType.Data ? Array.Equals(this.Data.ToArray(), other.Data.ToArray()) : true);
 }
Ejemplo n.º 2
0
        void ReadRawData(Stream data)
        {
            AddressStart = -1;
            AddressEnd   = -1;
            StreamReader sr = new StreamReader(data);

            byteData = new Dictionary <int, byte>();
            int    addru = 0;
            int    addrl = 0;
            string line;
            int    lineno = 0;

            records = new List <HexRecord>();
            while ((line = sr.ReadLine()) != null)
            {
                lineno++;
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                line = line.Trim();
                if (line.Length < 11 || line[0] != ':')
                {
                    throw new Exception("Bad line at " + lineno);
                }
                var record = new HexRecord(line);
                records.Add(record); // used for debuggin
                string dline = record.ToString();
                switch (record.Type)
                {
                case RecordType.Data:
                {
                    int addr = record.Address + (addrl | (addru << 16));         // add segment if I ever get around to setting it up
                    if (addr < AddressStart)
                    {
                        AddressStart = addr;
                    }
                    foreach (var b in record)
                    {
                        byteData.Add(addr++, b);
                    }
                    if (addr > AddressEnd)
                    {
                        AddressEnd = addr;
                    }
                }
                break;

                case RecordType.EndOfFile:
                    if (record.Count != 0)
                    {
                        throw new Exception("Extra Data at end of file at line " + lineno);
                    }
                    return;

                case RecordType.StartSegmentAddress:
                case RecordType.ExtendedSegmentAddress:
                    throw new Exception("Segments not suppored as I am lazy at line " + lineno);

                case RecordType.StartLinearAddress:
                    throw new Exception("Not many cpus support EIP do they?  Why do we use this format again? at line " + lineno);

                case RecordType.ExtendedLinearAddress:
                    if (record.Count != 2)
                    {
                        new Exception("Extended Linear Address must have a byte count of 2 at line " + lineno);
                    }
                    addru = (record[0] << 8) | record[1];
                    break;

                default:
                    throw new Exception("Bad Rec type at line at line " + lineno);
                }
            }
            throw new Exception("No end of file marker found");
        }