public void MergeHex(HexLoader other) { bool bStartOver = true; UInt32[] rowWords; uint rowIndex; while (other.EnumerateRows(bStartOver, out rowWords, out rowIndex)) { bStartOver = false; uint address = rowIndex * InstructionWordsPerRow * 4; // Address in hex file increment four per 3-byte instruction word. // Trim unused instruction words. uint startWordIndex = 0; uint endWordIndex = InstructionWordsPerRow; while ((endWordIndex > 0) && (rowWords[endWordIndex - 1] == 0x00FFFFFF)) { endWordIndex--; } if (endWordIndex == 0) { continue; // Empty row. } while (rowWords[startWordIndex] == 0x00FFFFFF) { startWordIndex++; } address += 4 * startWordIndex; // Copy the next row into row. byte[] row = new byte[4 * (endWordIndex - startWordIndex)]; uint dstByte = 0; for (uint wordIndex = startWordIndex; wordIndex < endWordIndex; wordIndex++) { uint word = rowWords[wordIndex]; for (int shift = 0; shift < 32; shift += 8) { row[dstByte++] = (byte)(word >> shift); } } AddData(address, row); } }
// Static method to create a HexLoader. Throws an Exception on failure. public static HexLoader LoadHexFile(string hexFileName, bool bBootLoader) { if (hexFileName != null) { try { HexLoader loader = new HexLoader(hexFileName, bBootLoader); if (loader.hexLoaded) { return(loader); } } catch (Exception ex) { throw new Exception("Error: Could not open file: '" + hexFileName + "'. Reason: " + ex.Message); } } return(null); }