1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00

Adding hex2hex file in python

-Script working!
-Still need to finish the emf format
-Still need to finish proper script commands
This commit is contained in:
Andreas.Olofsson 2020-02-04 20:10:09 -05:00
parent f7012f8369
commit 9bb84ebe20

45
scripts/hex2hex Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
#############################################################################
# hex2hex <hexfile> <memory-width> [-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)