CodeWalrus

Development => Calculators => Calculator News, Coding, Help & Talk => Topic started by: utz on November 02, 2015, 09:45:54 PM

Title: 8*p files checksum calculation
Post by: utz on November 02, 2015, 09:45:54 PM
Fiddeling with a new TI-Z80 program packer because I'm not happy with any of the existing ones. Now I noticed something strange regarding checksum calculation for 82p files.

It seems the 82 actually doesn't care about the checksum at all. I've compared outputs of a few different utilities (original CrASH packer, bin8x, and my own oysterpac.pl), and they all give different checksum values, however all the files run just fine in CrASH.

The "holy" Link Guide states that the checksum is "the lower 16 bits of the sum of all bytes in the data section." However, that's certainly not what bin8x and crprgm82.exe are doing.
So what exactly is the 'correct' way of calculating the checksum? Can one just supply a random value and assume CrASH to correct it at relocation time? Also, how is this handled on other models? Seems I'm not getting away with this on TI83 for example.
Title: Re: 8*p files checksum calculation
Post by: Snektron on November 02, 2015, 09:59:35 PM
i made a java binpack 8xp a while ago, but i think that uses the same way to calcuate it as binpack 8xp.
IIRC i only made it because the ohter one was in python and relative paths were doing weird
Title: Re: 8*p files checksum calculation
Post by: Adriweb on November 02, 2015, 10:03:54 PM
Here are my PHP and C++ implementations of the checksum calculation/retrieval (several ways: one from instance data when a file has been opened, one when it's created from scratch, and one just reading from the file):
- https://github.com/adriweb/tivars_lib/blob/master/src/TIVarFile.php#L179-L218
- https://github.com/adriweb/tivars_lib_cpp/blob/master/src/TIVarFile.cpp#L151-L191
(they're identical, just the language-syntax changes, basically, so take your pick)
Title: Re: 8*p files checksum calculation
Post by: utz on November 02, 2015, 10:51:52 PM
@Adriweb: Damn, that looks so much more professional than my n00bish fumblings, I should just use that. But then again I need to learn some high level coding, so I'm probably gonna stick with mine. ... So in essence, seems you're sticking to the Link Guide, ie. calculating the checksum from file offset 55. crprgm82 on the other hand calculates it from offset 60, then subtracts 86 from the value.  ???  :crazy:
Title: Re: 8*p files checksum calculation
Post by: Adriweb on November 02, 2015, 10:58:36 PM
I don't know crprgm82 but from the way you describe it, it's probably just hardcoding things specific for the program vartypes (0x05 and 0x06), and it simply adds the known partial checksum + the data len after that (adds to the checksum once calculated, I mean), so it doesn't need to start at 55 like I do (to handle other vartypes) but 60, right where the actual custom data starts.

Anyway, you're welcome to use my lib if you want, it's not open-source and under the MIT License for nothing :)
If you do so, check out the tests.{php,cpp} file, it should get you started.