- 8XP Making
- 12 Mar 2011 01:43:31 pm
- Last edited by ephan on 12 Mar 2011 02:45:46 pm; edited 1 time in total
I decided to create a whole new thread for this, since I'm restarting my code so I can finally release Assemblex 1.0.0 (I mean the 8xp making code).
The first change I decided to make in the code is to make it all in bytearrays.
Code:
So I have a working code for writing files in binary and it works just perfectly.
Then I decided to add header to the code:
Code:
I'm also commenting everything to make it easier for you to understand it and help me with it.
Now I'm going to start coding the code to get the size of the program data.
This used to be my code:
Code:
I was given this code by Deep Thought and I don't fully get it, so I want to know what you think of it and if it okay in all circumstances.
The first change I decided to make in the code is to make it all in bytearrays.
Code:
programData = self.inputText.GetValue() #This gets the hex code
myByteArray = bytearray()
for i in range(0, len(programData), 2):
myByteArray.append( chr( int (programData[i:i+2], 16 ) ) ) #This loops converts the hex code string to bytes and appends it to the bytearray
filehandle.write(myByteArray) #This writes the file
So I have a working code for writing files in binary and it works just perfectly.
Then I decided to add header to the code:
Code:
programData = self.inputText.GetValue() #Gets the hex code typed by the user
strHeader = "2A2A54493833462A1A0A0046696c652067656e65726174656420627920417373656d626c6578202d20446176696420476f6d657300" #This is a fixed header that never changes
programData = strHeader + programData #Add the header before the program data
myByteArray = bytearray() #Initialize bytearray
for i in range(0, len(programData), 2): #Loop to convert string to bytes
myByteArray.append( chr( int (programData[i:i+2], 16 ) ) ) #Loop to convert string to bytes
filehandle.write(myByteArray) #Writing the file
I'm also commenting everything to make it easier for you to understand it and help me with it.
Now I'm going to start coding the code to get the size of the program data.
This used to be my code:
Code:
dataLengthBigEndian = len(programData)/2 #Gets the code from the user (TYPED CODE, WITHOUT HEADER) and divides its length by 2
littleEndian = hex(dataLengthBigEndian % 256 * 256 + (dataLengthBigEndian / 256))[2:] #Converts its length to little endian
if len(littleEndian) == 3: #If the little endian code length is 3..
littleEndian= '0' + littleEndian #... add a 0 before it
I was given this code by Deep Thought and I don't fully get it, so I want to know what you think of it and if it okay in all circumstances.