From d66326a6717195dc93602d2f9af24f3411b25dd9 Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 4 May 2016 15:31:43 +0100 Subject: First (bad) attempt at SNES checksum. --- src/snesout.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/snesout.c b/src/snesout.c index 1612a6b..911ee49 100644 --- a/src/snesout.c +++ b/src/snesout.c @@ -133,6 +133,16 @@ static int PokeS(Byte *mem, int addr, const char *str, int maxlen, char pad) return addr; } +static unsigned CalcChecksum(Byte *p, int len, unsigned csum) +{ + while(len-- > 0) + { + csum += *p++; + } + + return csum & 0xffff; +} + /* ---------------------------------------- INTERFACES */ @@ -198,6 +208,7 @@ int SNESOutput(const char *filename, const char *filename_bank, int base; int len; int f; + unsigned csum; /* If the ROM type is LOROM then we assume each bank holds 32Kb. Otherwise each bank is a full 64Kb. @@ -275,7 +286,17 @@ int SNESOutput(const char *filename, const char *filename_bank, PokeB(mem, 0xffd8, option.ram_size); - /* TODO: Need checksums? */ + /* Calculate checksum + */ + csum = 0; + + for(f = 0; f < count; f++) + { + csum = CalcChecksum(bank[f]->memory + base, len, csum); + } + + PokeW(mem, 0xffde, csum); + PokeW(mem, 0xffdc, 0xffffu - csum); /* Output ROM contents */ -- cgit v1.2.3