News: 11 March 2016 - Forum Rules

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tetrismegistus

Pages: [1]
1
Programming / unable to correctly calculate checksum for one SNES game
« on: March 01, 2018, 03:02:08 pm »
Hi,

So I made myself a little SNES rom info tool:

https://github.com/tetrismegistus/snes_rom_info

It seems to be working as intended so far, except when I try to verify the Checksum on two different Final Fantasy III roms.

Code: [Select]
Game Title: b'FINAL FANTASY 3     '
SMC Header: No
Rom Mapping: HiRom + FastROM
Rom Type: ROM and Save RAM
Rom Size: 32 MegaBits
SRAM Size: 64 Kilobits
Country: USA
Licensee: Nintendo
Game Version: 1
Checksum Complement: 759f
Specified Checksum: 8a60
Calculated checksum: 9606

000ffc0  46 49 4e 41 4c 20 46 41  4e 54 41 53 59 20 33 20  |FINAL FANTASY 3 |
000ffd0  20 20 20 20 20 31 02 0c  03 01 33 01 9f 75 60 8a  |     1....3..u`.|

Code: [Select]
Game Title: b'FINAL FANTASY 3     '
SMC Header: No
Rom Mapping: HiRom + FastROM
Rom Type: ROM and Save RAM
Rom Size: 32 MegaBits
SRAM Size: 64 Kilobits
Country: USA
Licensee: Nintendo
Game Version: 0
Checksum Complement: a0cd
Specified Checksum: 5f32
Calculated checksum: 6ad8

000ffc0  46 49 4e 41 4c 20 46 41  4e 54 41 53 59 20 33 20  |FINAL FANTASY 3 |
000ffd0  20 20 20 20 20 31 02 0c  03 01 33 00 cd a0 32 5f  |     1....3...2_|

In both examples the Specified Checksum (the one in the ROM Header) differs from Calculated checksum.

In every other game I've tried, those with and without SMC headers:

Breath of Fire II (USA).sfc
Final Fantasy II (USA).sfc
Secret of Mana (USA).sfc
Shadowrun (USA).sfc
Super Mario World (USA).sfc
Super Metroid (Japan, USA) (En,Ja).sfc

I get the expected checksum.  What could I be doing wrong with Final Fantasy III?

See the link above to see the source code, the checksum calculation is basically:

Code: [Select]


    def calculate_checksum(self):
        f = open(self.filename, 'rb')
        f.seek(self.smc_offset)
        chunk_sums = []
        for chunk in read_in_chunks(f):
            total = 0
            for byte in chunk:
                total += byte
            chunk_sums.append(total)

        total = 0

        for csum in chunk_sums:
            total += csum

        return '{:04x}'.format(total & int('FFFF', 16))


def read_in_chunks(file_object, chunk_size=500000):
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data


Pages: [1]