0 Members and 2 Guests are viewing this topic.
def ExporTo8xp(event): def to_binary(hex_string): ints = [int(hex_string[i:i+2], 16) for i in range(0,len(hex_string),2)] return struct.pack('B' * len(ints), *ints) dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "8XP Files (*.8xp)|*.8xp", \ wx.SAVE | wx.OVERWRITE_PROMPT) if dlg.ShowModal() == wx.ID_OK: programData = self.inputText.GetValue() self.filename=dlg.GetFilename() self.dirname=dlg.GetDirectory() filehandle=open(os.path.join(self.dirname, self.filename),'wb') filehandle.write(to_binary(finalProgram)) filehandle.close() self.SetTitle('Assemblex - '+self.filename) dlg.Destroy()
programData = self.inputText.GetValue()
2A2A54493833462A1A0A0046696C652067656E657261746564206279205761626269745369676E000000000000000000000000000029000D0018000650524F4752414D00000018001600BB6DCE0B
This is a sample code of an assembly program, I need to change the size of the program. I can count the length of it, so let's say it is 98 bytes:> How can I make 98 bytes, what is the size of the program in the hex code of it?I know this is very general, I'll try to give you more details when I can.
I think he means: "How do I find the size of the file? And how do I get the checksum?"
53 (35h) 2 bytes Length, in bytes, of the data section of the file. This number should be 57 (39h) bytes less than the file size.
Quote from: Binder News on February 12, 2011, 05:29:14 pmI think he means: "How do I find the size of the file? And how do I get the checksum?"No I don't. I mean I can get a size in bytes, I just can't make that size little endian...Quote53 (35h) 2 bytes Length, in bytes, of the data section of the file. This number should be 57 (39h) bytes less than the file size.http://www.cemetech.net/forum/viewtopic.php?p=132898#132898Just like Deep Thought says there, I need the size - 57 bytes in little endian.So let's say the file is 98 bytes (I can get that value, no issues there), 98-57 is 41. Then 41 in little endian is 4100. That is easy, but with larger files I don't know how to.It's a python question. Any ideas?
Oh, that's easy. Take the number %256 (modulus), insert it as the first byte, then put the number /256 into the byte after it.
Quote from: Deep Thought on February 12, 2011, 05:48:55 pmOh, that's easy. Take the number %256 (modulus), insert it as the first byte, then put the number /256 into the byte after it.Sorry, I can't understand.Let's say the size, in bytes, is 98.98-57=41Then 41 in hex is 29.29 in little endian is 2900.I need a python code for that, the problem is the little endian/hex :S
le = be % 256 * 256 + (be / 256)
littleEndian = dataLengthBigEndian% 256 * 256 + (dataLengthBigEndian / 256)
littleEndian = dataLengthBigEndian% 256 * 256 + (dataLengthBigEndian / 256)TypeError: not all arguments converted during string formatting
littleEndian = dataLengthBigEndian% hex(256) * hex(256) + (dataLengthBigEndian / hex(256))
No, never use hex(. hex( just converts a number into a hex string. Remember that a number is a number whether it's a decimal or a hex. 0x226B is exactly the same as 8811, so don't bother converting it to hex. To the computer it's all the same, anyway.The only real time you'd ever use hex( would be if you wanted to display something that way.Hope this helps?
dataLengthBigEndian = len(programData)/2
In Python, hex( will turn values into hex variables, so neither integers nor strings.This makes it impossible to make calculus with it, I think, so you can use the integer values of hexadecimal variables for this type of calculus.
def to_binary(hex_string): ints = [int(hex_string[i:i+2], 16) for i in range(0,len(hex_string),2)] return struct.pack('B' * len(ints), *ints)programData = self.inputText.GetValue() dataLengthBigEndian = len(programData)/2 littleEndian = dataLengthBigEndian % 256 * 256 + (dataLengthBigEndian / 256) sample8xp = "2A2A54493833462A1A0A0046696C652067656E657261746564206279205761626269745369676E0000000000000000000000000000"""+str(littleEndian)+"0D0018000650524F4752414D00000018001600BB6D"+programData+"CE0B" self.filename=dlg.GetFilename() self.dirname=dlg.GetDirectory() filehandle=open(os.path.join(self.dirname, self.filename),'wb') filehandle.write(to_binary(sample8xp)) filehandle.close()
In Python, hex( will turn values into hex variables, so neither integers nor strings.
Now, the size in the 8xp file created is 1024, which is certainly wrong since my program data size, in bytes, is 2 (bytes). This would make the little endian code be 0200, so something in my code is wrong: