I just made a neat Python tool to help me and you code (while I doubt this will only be useful to me and Zeda):
Code:
You enter hex code like 2101000EF0745 and it returns:
Code:
It is aware of the 31 arguments limit, so here's an example for bigger code:
Code:
I also made code to turn it to .dw code and it will even make it big endian. However, it doesn't count 31 arguments (yet):
Code:
What do you think?
Code:
def hexToDb(hex):
"""Takes a big endian hex string and turns it to little endian"""
splitHex = [hex[x:x+2] for x in xrange(0,len(hex),2)]
finalString = ".db"
counter = 0
for i in range(0,len(splitHex)):
if counter==29:
finalString+=" $"+splitHex[i]+"\n.db"
counter = 0
else:
finalString+=" $"+splitHex[i]+","
counter+=1
return finalString[0:len(finalString)-1]
def main():
print "Choose:\n1. Type hexadecimal code\n2. Open from file"
option = input()
if option==1:
hexCode = raw_input("Type hexadecimal code: ")
g = open('dbCode.txt','w')
g.write(hexToDb(hexCode))
g.close()
else:
fileName = raw_input("Enter name of ASCII file: ")
f = open(fileName,'r')
hexCode = f.read().replace(' ','').replace('\n','').replace('\r','')
f.close()
g = open('dbCode.txt','w')
g.write(hexToDb(hexCode))
g.close()
if __name__=='__main__':
main()
You enter hex code like 2101000EF0745 and it returns:
Code:
.db $21, $01, $00, $EF, $07, $45
It is aware of the 31 arguments limit, so here's an example for bigger code:
Code:
.db $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77
.db $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9
.db $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D
.db $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00
.db $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40
.db $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F
.db $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48
.db $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF
.db $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00
.db $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45
.db $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72
.db $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65
.db $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A
.db $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22
.db $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD
.db $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C
.db $64, $21, $00
I also made code to turn it to .dw code and it will even make it big endian. However, it doesn't count 31 arguments (yet):
Code:
def bibEndianToLittleEndian(hex):
"""Takes a big endian hex string and turns it to little endian"""
splitHex = [hex[x:x+4] for x in xrange(0,len(hex),4)]
for i in range(0,len(splitHex)):
splitHex[i] = splitHex[i][2]+splitHex[i][3]+splitHex[i][0]+splitHex[i][1]
return "".join(splitHex)
def littleEndianToDw(hex):
"""Takes a little endian string as an argument and turns it to .dw blocks"""
#.dw $CBFD,$AE00
finalString = ".dw"
splitHex = [hex[x:x+4] for x in xrange(0,len(hex),4)]
for i in range(0,len(splitHex)):
finalString+= " $"+splitHex[i]+","
return finalString[0:len(finalString)-1]
def main():
print "Choose:\n1. Type hexadecimal code\n2. Open from file"
option = input()
if option==1:
hexCode = raw_input("Type hexadecimal code: ")
g = open('dwCode.txt','w')
g.write(littleEndianToDw(bibEndianToLittleEndian(hexCode)))
g.close()
else:
fileName = raw_input("Enter name of ASCII file: ")
f = open(fileName,'r')
hexCode = f.read()
f.close()
g = open('dwCode.txt','w')
g.write(littleEndianToDw(bibEndianToLittleEndian(hexCode)))
g.close()
if __name__=='__main__':
main()
What do you think?