Esempio n. 1
0
        public HexBlocks SplitBlocks(int pageSize, int maxSuperPage = int.MaxValue)
        {
            pageSize = Math.Max(1, pageSize);
            var      sp    = new Queue <BlockInfo>(JoinBlocks(GetPages(pageSize), pageSize, maxSuperPage));
            var      res   = new HexBlocks();
            HexBlock block = null;

            foreach (var line in _lines)
            {
                for (var index = 0; index < line.Bytes.Length; index++)
                {
                    var bt = line.Bytes[index];
                    if (bt.Value.HasValue)
                    {
                        var address = line.Address + index;
                        if (block != null && (address < block.Address || address >= block.Address + block.Data.Length))
                        {
                            block = null;
                        }
                        if (block == null)
                        {
                            var info = sp.Dequeue();
                            block = CreateBlock(info.Address, info.Length);
                            res.Blocks.Add(block);
                        }
                        block.Data[address - block.Address] = bt.Value.Value;
                    }
                }
            }

            return(res);
        }
Esempio n. 2
0
        private static HexBlock CreateBlock(int start, int size)
        {
            var block = new HexBlock {
                Address = start, Data = new byte[size]
            };

            for (var i = 0; i < size; i++)
            {
                block.Data[i] = 0xff;
            }
            return(block);
        }