Calculating Checksums
This document will cover information about the GameBoy checksum byte. Where
to locate it and calculate it. This version of the document
does not yet cover the calculation of the compliment.
I'd like to thank DiskDude of Damaged Cybernetics for helping out!
C source code will be provided as an additional reference to this document.
A precompiled version is also available.
Note: This document is still in draft, if you have any corrections that need to be made, please email us.
Details...
The checksum is used for validating the integrity of the GameBoy ROM image.
There are reasons to believe that the GameBoy does not use this value,
because there are many bad GameBoy images floating around that work fine. Also I haven't seen any
GameBoy software that enforces it either.
Incorrect checksums can result from:
- Patching the game to enable/enforce unintentional features.
- Buggy copiers. (It has been reported that SmartCard will not copy correctly!)
- Pirate groups that change text in the game. This is usually done to keep
reminding you who released it (Annoying).
- Media corruption (magnetic, CD, cart ROMs)
However having an invalid checksum does not mean that the image won't work. Not
all images fill up to its ROM size.
It is unknown if the GameBoy checksum/compliment values extend to any Super GameBoy data.
The location of GameBoy checksum/compliment (without a copier header):
| Offset | Size in Bytes | Definition
|
| 0x14D | 1 | Compliment
|
| 0x14E | 2 | Checksum
|
When reading or writing the checksum on the PC (or any Little Edian platform)
, we will need to convert it to Big Edian. This involves shifting the
LSB 8 bits left 8 bits and shifting the MSB 8 bits right 8 bits.
i.e. Example C routine to convert to Little/Big Edian values
uiCheckSum = (uiCheckSum >> 8) || (uiCheckSum << 8)
Calculating...
Nintendo designed the checksum calculation to be very simple. Accumlate each
byte value in the rom image into a 32bit integer. Excluding the 16bit check
sum that is present in the image. After we accumlated the values, take the
lower 16bits. This is stored in Big Edian format in the ROM image.
Here is some core library routines, written in C, that demostrates this.
If you cannot compile these routines you can download a precompile version.
Damaged Cybernetics is not connected or affiliated with any mentioned
company in any way. The opinions of Damaged Cybernetics do not reflect the
views of the various companies mentioned here. Companies and all products
pertaining to that company are trademarks of that company. Please contact
that company for trademark and copyright information.
© 1996 Damaged Cybernetics All Rights Reserved
|