]> git.sur5r.net Git - cc65/blob - util/gamate/gamate-fixcart.c
goto.c warning fix for implicit truncation
[cc65] / util / gamate / gamate-fixcart.c
1
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 FILE *in;
6 unsigned int n, i, c;
7
8 void usage(char *arg)
9 {
10     printf("usage: %s [file]\n", arg);
11     exit(-1);
12 }
13
14 int main(int argc, char *argv[]) {
15     if (argc < 2) {
16         usage(argv[0]);
17         exit(-1);
18     }
19
20     if (!(in = fopen(argv[1], "r+b"))) {
21         fprintf(stderr, "couldnt open: '%s'\n", argv[1]);
22         exit(-1);
23     }
24     /* read 0x1000 bytes from 0x7000-0x7fff (offset 0x1000) */
25     fseek(in, 0x1000, SEEK_SET);
26     n = 0; for (i = 0; i < 0x1000; i++) {
27         c =  fgetc(in);
28         n += c;
29     }
30     /* write checksum to header */
31     fseek(in, 0, SEEK_SET);
32     fputc(n & 0xff, in);
33     fputc((n >> 8) & 0xff, in);
34
35     fclose(in);
36     return (0);
37 }