0 Members and 1 Guest are viewing this topic.
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()
Ah cool, I like this, Scout. However, TASM can only handle so many extra arguments. For example, if this has three arguments: .dw $AA00,$BB00,$CC00Then I cap it at 24 arguments per .dw, but I think 31 is the max. Also, if you could make a code for .db statements (also only handling 31 arguments), that might be easier for the code, too.
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()
.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
This is great, Scout! It works so nicely! Is there a way to change the output file? I can definitely use this for BatLib ♥ The next step is to create a program that converts a file of all hex into a .hex file (in the proper format). If that can be done, I will no longer have to worry about using TASM !
Hehe, I am already making a version in Python (or at least attempting it)!
Well, I am reading and writing to files and I can input the file to read and write to. Please, I feel insulted that you think I cannot do it. So for now, I am going to leave until I accomplish this.
Thanks I think I will make one, too. Here is my hex to .db converter, by the way You input the file to read, then the file to write to and it will convert it Also, the hex doesn't need to be an even number on each line, but if there is an odd number of chars in all, the last one won't be included. It writes 24 arguments to each .db I won't guarantee that it is optimised, because as you said, I just started learning today, but it is a good start, right?If I think I can do something, I usually have good reason to believe so I will also try to write a converter to convert to .8xp and possibly .8xk. That will be a little later on down the road, though...
Also, the hex doesn't need to be an even number on each line, but if there is an odd number of chars in all, the last one won't be included.
def hexToDb(hex): 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]
If I think I can do something, I usually have good reason to believe so I will also try to write a converter to convert to .8xp and possibly .8xk. That will be a little later on down the road, though...