Exemplo n.º 1
0
        private void ProcessLine(string line)
        {
            HexLine hexLine = HexLine.Parse(line);


            Address baseAddress = 0x000000; //always 0, not used currently

            switch (hexLine.RecordType)
            {
            case RecordType.Data:
                List <Word> words       = hexLine.Data.ToLittleEndians();           //Reading little endian data
                Address     byteAddress = (Address)(baseAddress + hexLine.Address); //not used. correcting address if it is Extended Address
                Address     wordAddress = (Address)(byteAddress >> 1);              //Byte to Word address
                blocks.Add(new MemoryBlock(wordAddress, words));
                break;

            case RecordType.EndOfFile:
                MergeBlocks();
                break;

            case RecordType.ExtendedSegmentAddress:
            //baseAddress = ((Address)hexLine.Data.ReadBigEndianWord(0)) << 4;
            //break;
            case RecordType.ExtendedLinearAddress:
            //baseAddress = ((Address)hexLine.Data.ReadBigEndianWord(0)) << 16;
            //break;
            case RecordType.StartSegmentAddress:
            case RecordType.StartLinearAddress:
                throw new NotSupportedException();

            default:
                throw new Exception($"Unknown {nameof(RecordType)} {hexLine.RecordType:X}");
            }
        }
Exemplo n.º 2
0
        public bool Parse(string fn, int maxBlockSize = 256)
        {
            var ret = false;

            try
            {
                using (var reader = File.OpenText(fn))
                {
                    string line;
                    UInt32 addrPrefix = 0;
                    while ((line = reader.ReadLine()) != null)
                    {
                        HexLine hexLine = new HexLine();
                        if (!hexLine.Parse(line))
                        {
                            return(false);
                        }

                        if (hexLine.Type == HexLine.HexLineType.ExtendedLinearAddress)
                        {
                            addrPrefix = hexLine.Addr << 16;
                        }
                        else if (hexLine.Type == HexLine.HexLineType.StartLinearAddress)
                        {
                            EntryPoint = hexLine.Addr;
                        }
                        else if (hexLine.Type == HexLine.HexLineType.EndOfFile)
                        {
                            ret = true;
                            break;
                        }
                        else if (hexLine.Type == HexLine.HexLineType.Data)
                        {
                            var         addr  = addrPrefix | hexLine.Addr;
                            MemoryBlock block = null;
                            try
                            {
                                block = Blocks.Find(v =>
                                                    v.StartAddr < addr && v.StartAddr + v.Length == addr && v.Length + hexLine.Content.Length <= maxBlockSize);
                            }
                            catch (Exception)
                            {
                                // ignore
                            }
                            if (block == null)
                            {
                                block           = new MemoryBlock();
                                block.StartAddr = addr;
                                Blocks.Add(block);
                            }
                            block.Content.AddRange(hexLine.Content);
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignore
            }

            return(ret);
        }