aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2016-05-04 15:31:43 +0100
committerIan C <ianc@noddybox.co.uk>2016-05-04 15:31:43 +0100
commitd66326a6717195dc93602d2f9af24f3411b25dd9 (patch)
tree6aa7c4ef432417ab17317692d2b87e062ef52509 /src
parenta395d7bf01456620806ae521878a60bdad8dc6e5 (diff)
First (bad) attempt at SNES checksum.
Diffstat (limited to 'src')
-rw-r--r--src/snesout.c23
1 files changed, 22 insertions, 1 deletions
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
*/