diff --git a/scripts/hex2hex b/scripts/hex2hex new file mode 100755 index 0000000..fb3f214 --- /dev/null +++ b/scripts/hex2hex @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +############################################################################# +# hex2hex [-emf] [-offset] +# +# Script that converts a byte-format memh hex file to a hex file +# of a specific memory width. +# +# The script assumes the hex file has max 16 byte entries per line +# +# Script also supports creating EMF transactions with one address per data +# +############################################################################# +import sys +import re + +hexfile = sys.argv[1] +width = int(int(sys.argv[2])/8) #needed for both +emf = 0 # emf +offset = 0 #TODO: specify as hex offset, only for emf + +#1. Read file into list and strip off trail junk +list = [line.rstrip(' \n') for line in open(hexfile)] + +#2. Loop through byte list +for line in list: + if (~line.find('@')): #detects new memory section + address = offset + int(line.replace('@','',1),16) + if(emf): + print ("Not Implemented") + else : + print("@"+format(address, 'x')) + else: #process data one line at a time + bytes=line.split(' ') + length=len(bytes) + for i in range(0,(16-length)): # zero extend buffer for simplicity + bytes.append("00") + for i in range(0,16,width): + sublist=bytes[i:i+width] + sublist.reverse() + word="" + word=word.join(sublist) + if(emf): + print ("Not Implemented") + else : + print(word)