1 // Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
2 // Licensed under the terms of the GNU GPL, version 2
3 // http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
11 static void slot_checksum(u8
*x
)
17 for (i
= 0; i
< 0x0a8c; i
++)
19 nsum
= -(sum
+ 0x0a8c);
21 wbe32(x
+ 0x0a8c, sum
);
22 wbe32(x
+ 0x0a90, nsum
);
25 static void save_checksum(u8
*x
)
31 slot_checksum(x
+ 8 + 0x0a94);
32 slot_checksum(x
+ 8 + 2*0x0a94);
35 for (i
= 0; i
< 0x0ffe; i
++)
37 nsum
= -(sum
+ 0x0ffe);
39 wbe16(x
+ 0x1ffc, sum
);
40 wbe16(x
+ 0x1ffe, nsum
);
43 int main(int argc
, char **argv
)
48 fprintf(stderr
, "Usage: %s <zeldaTp.dat>\n", argv
[0]);
52 fp
= fopen(argv
[1], "rb+");
54 fatal("open %s", argv
[1]);
55 if (fread(buf
, 0x4000, 1, fp
) != 1)
56 fatal("read %s", argv
[1]);
59 save_checksum(buf
+ 0x2000);
61 if (fseek(fp
, 0, SEEK_SET
))
63 if (fwrite(buf
, 0x4000, 1, fp
) != 1)
64 fatal("write %s", argv
[1]);