Correct Very Happy A byte of chocolate cake is always better than a nibble of the same cake Wink

Edit: Umm, *bite?
_player1537 wrote:
Correct Very Happy A byte of chocolate cake is always better than a nibble of the same cake Wink

Edit: Umm, *bite?
Sure, something like that. Razz
I can *easily* calculate the size of the program before making it :S

However, "converting" it to little endian is my problem.
ScoutDavid wrote:
I can *easily* calculate the size of the program before making it :S

However, "converting" it to little endian is my problem.
There's no endianness in conversion of the program itself; it's just bytes. The only place that endianness comes into play is in the size words in the header of the program.
Note: I moved this topic from the "z80 Assembly" section to the "General" section.
merthsoft wrote:
Note: I moved this topic from the "z80 Assembly" section to the "General" section.
Thanks for that, Merth. Smile
Deep Thought helped me making the size of the data section ok and here's a file I made:


Code:
2A2A54493833462A
1A0A0046696C6520
67656E6572617465
6420627920576162
6269745369676E00
0000000000000000
000000000008000D
0018000650524F47
52414D0000001800
1600BB6DEF40450E
F72409C9CE0B


WabbitEmu won't accept it, the size is OK (0800) for the data (EF4045ef7249c9). Any idea what's wrong?


Code:
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()
         
         dataLengthBigEndian = len(programData)/2
         
         littleEndian = hex(dataLengthBigEndian % 256 * 256 + (dataLengthBigEndian / 256))[2:]
         
         if len(littleEndian) == 3:
             littleEndian= '0' + littleEndian
         
         sample8xp = "2A2A54493833462A1A0A0046696C652067656E6572
6174656420627920576162626974536967
6E000000000000000
0000000000000"""+littleEndian+"0D00180006
50524F4752414D00000018001600BB6D"+programData+"CE0B"
         
         print littleEndian
         print dataLengthBigEndian
         
         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()
            
         self.SetTitle('Assemblex - '+self.filename)
         
      dlg.Destroy()


Also, this is the code.
What's with that massive string of zeroes in the middle? Can you give us the ASCII equivalents next to the hex?

Edit: Also, don't forget that from the TI File Format and Link Protocol Guide that you need the size twice, the second smaller than the first.
KermMartian wrote:
What's with that massive string of zeroes in the middle? Can you give us the ASCII equivalents next to the hex?

Edit: Also, don't forget that from the TI File Format and Link Protocol Guide that you need the size twice, the second smaller than the first.


Four times, right? Once for the size including the header stuff, twice for the data section, and once for the data section not counting the size bytes.

Why did TI have to make it so confusing? O_x
Well, there's the header length at +53d, aka file_size-57d. Then there's the one at +57d and at +70d, so three all together. Two copies make sense because of the group file type; the third one is a little weird.
KermMartian wrote:
What's with that massive string of zeroes in the middle? Can you give us the ASCII equivalents next to the hex?

Edit: Also, don't forget that from the TI File Format and Link Protocol Guide that you need the size twice, the second smaller than the first.


Oh! I missed that, I have to recheck that. Also all those 0's is the hex code for a string that credits SPASM for the file. I haven't edited that to make it Assemblex-made.
Another point: you have variable program data with a fixed checksum. I think you still don't understand what the point of the checksum (the last two bytes of the data) is.
KermMartian wrote:
Another point: you have variable program data with a fixed checksum. I think you still don't understand what the point of the checksum (the last two bytes of the data) is.


CE0B

That?
Yes.
ScoutDavid wrote:
KermMartian wrote:
Another point: you have variable program data with a fixed checksum. I think you still don't understand what the point of the checksum (the last two bytes of the data) is.


CE0B

That?


Yeah, it's meant to be a check when you download the program to your calc whether the file is valid or not. The checksum is a sum of all the bytes in the data region. So if you change your data, your checksum's gotta change, too, because different numbers add up to different numbers Razz
Deep Thought wrote:
ScoutDavid wrote:
KermMartian wrote:
Another point: you have variable program data with a fixed checksum. I think you still don't understand what the point of the checksum (the last two bytes of the data) is.


CE0B

That?


Yeah, it's meant to be a check when you download the program to your calc whether the file is valid or not. The checksum is a sum of all the bytes in the data region. So if you change your data, your checksum's gotta change, too, because different numbers add up to different numbers Razz
And conversely, if the checksum doesn't match the sum of the bytes in the data section, TI-Connect, WabbitEmu, and other applications assume that the file is corrupt.
That's it! That must be it, that must be what's wrong!


Code:
sum=0
for i in hexArray[55:]:
        sum += hexArray[i]


I only have one doubt... What would hexArray be? An array like this?:


Code:
['21','01','00','EF','07','45']


Thanks.
No, because addition of strings is concatenation. You want to sum bytes. Also, did you fix the fact that you don't have the size word in three different places (with two different values) as you need?
Yeah, I know...
Quote:
For the actual variable data:

It starts with two bytes holding the size of the rest of the data. This is kinda weird, but basically it's just two less than the value of #2 and #7 above (because these two bytes are counted as part of the data in #2 and #7 (hope this makes sense)).


This is what's missing me, but I will make the checksum first.

Also, you mentioned I have to sum bytes, but like the number of bytes, or sum the integer value of the nibbles?

Edit by Merth: Please use quote tags when quoting, not code tags.
You want to sum up the integer value of the bytes, not the nibbles. So if hex array is ['21','01','00','EF','07','45'], you'll want to sum up the values [33, 1, 0, 239, 7, 69] = 349 = 0x15D0 (big endian) = 0xD015 (little endian) (if I've done all that right).
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement