Author Topic: 8xp File Header generation  (Read 2457 times)

0 Members and 1 Guest are viewing this topic.

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
8xp File Header generation
« on: October 19, 2011, 05:27:21 pm »
I'm completely rewriting my 8xp library for TBEXE (now called BexIDE), and everything works fine (as far as I can tell) except for the header generation. I think the problem is somewhere in the part having to do with the "mystery" byte or the Type ID part, but I can't be exactly sure. I'm definitely going to be investigating further tonight (unless someone beats me to it), but I have to go out for my birthday dinner right now ;)

So yeah, I guess I'm just asking for theories on what's going wrong, if there are any, or what I'm doing wrong.

Code: (le code) [Select]
int i, j = 0;                                                               //i: loops, j: current pos
byte[] len = getDataLength(false);                                          //The length of the data section
byte[] header = new byte[73];                                               //To be returned
//Copy bytes from the file header
for (i = 0; i < FILEHEADER.Length; i++) {                                   //FILEHEADER is the "**TI83F*" stuff as a byte array
    header[j] = FILEHEADER[i]; j++;
}
//Copy bytes from the sub-header
for (i = 0; i < FILESUBHEADER.Length; i++) {                                //FILESUBHEADER is $1A, $0A, $00
    header[j] = FILESUBHEADER[i]; j++;
}
//Copy the comment
for (i = 0; i < Prgm.Comment.Length; i++) {                                 //The comment is a byte array whose length is 42
    header[j] = Prgm.Comment[i]; j++;
}
//Copy data length
for (i = 0; i < len.Length; i++) {
    header[j] = len[i]; j++;
}
header[j] = (byte)0x0B; j++;                                                //Add the "mystery" byte (maybe $0D?)
//Copy data length (again)
for (i = 0; i < len.Length; i++) {
    header[j] = len[i]; j++;
}
header[j] = Prgm.IsProtected ? (byte)0x06 : (byte)0x05; j++;                //Add protection flag
//Copy the program name
for (i = 0; i < Prgm.Name.Length; i++) {                                    //The name is a byte array whose length is 8
    header[j] = Prgm.Name[i]; j++;
}
j++;                                                                        //Skip the version (makes it $00)
header[j] = Prgm.IsArchived ? (byte)0x80 : (byte)0x00; j++;                 //Add the archive flag
//Copy data length (again)
for (i = 0; i < len.Length; i++) {
    header[j] = len[i]; j++;
}
len = getDataLength(true);                                                  //Get the length of the data / 2
//Copy the data length / 2
for (i = 0; i < len.Length; i++) {
    header[j] = len[i]; j++;
}
return header;                                                              //Return the full header
« Last Edit: October 19, 2011, 06:48:44 pm by Michael_Lee »

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: 8xp File Header generation
« Reply #1 on: October 19, 2011, 06:48:06 pm »
I believe that the 'mystery' byte is in fact _two_ bytes: 0x0B00 or 0x0D00.

Also, you're making sure that the data length is always exactly two bytes long, right?

In your program, you skip the version (which is usually 0x00).  My notes suggest that if you want to archive your program, the mystery value must be 0x0D00, not 0x0B00, and the version must be a non-zero value.  I'm not sure if that's true, but it's something to look for.

Finally, make sure you have a checksum.

Happy birthday, btw!

(I'm also removing your spoiler tags because people with Chrome can't see code in spoiler tags, hope you don't mind).

My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: 8xp File Header generation
« Reply #2 on: October 19, 2011, 07:43:07 pm »
Huh... Alright, well, I fixed the "mystery" byte thing (by doing j += 2 and changing the array to 74 instead of 73), and I checked the array and everything matches up perfectly, it seems. Visual Studio makes integers into byte arrays by making them 4 long, so in my getDataLength method, I do that, reverse the order (originally it would be something like {0, 0, 10, 12}), then cut off the two zeroes at the end. I'll change the version to $01 and see what happens. As for the "mystery" value, I had something like "header[j] = Prgm.IsArchived ? (byte)0x0D : (byte)0x0B; j++;" but I thought that might've been the problem, so I removed it temporarily. And yeah, I have the checksum part (and data section part) all done, I just needed to work on the header.

As for the spoilers, it doesn't make any difference to me lol.

EDIT: Ok, so, I fixed it and it still doesn't work. Granted, it may not be the header. I checked my ASCII parsing, and everything works, except for Ans, which registers as 'A', 'n', '?' so I need to work on that, but that *shouldn't* be the problem. It seems to be the checksum, but would that throw an error in Wabbit?
« Last Edit: October 19, 2011, 08:05:14 pm by BlakPilar »