1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-26 08:32:00 +00:00
cc65/util/gamate/gamate-fixcart.c

38 lines
720 B
C
Raw Normal View History

2015-11-29 00:14:59 +00:00
#include <stdlib.h>
#include <stdio.h>
2015-11-29 20:15:10 +00:00
FILE *in;
unsigned int n, i, c;
void usage(char *arg)
{
printf("usage: %s [file]\n", arg);
exit(-1);
}
2015-11-29 00:14:59 +00:00
int main(int argc, char *argv[]) {
2015-11-29 20:15:10 +00:00
if (argc < 2) {
usage(argv[0]);
2015-11-29 00:14:59 +00:00
exit(-1);
}
2015-11-29 20:15:10 +00:00
if (!(in = fopen(argv[1], "r+b"))) {
fprintf(stderr, "couldnt open: '%s'\n", argv[1]);
exit(-1);
}
2015-11-29 20:15:10 +00:00
/* read 0x1000 bytes from 0x7000-0x7fff (offset 0x1000) */
fseek(in, 0x1000, SEEK_SET);
n = 0; for (i = 0; i < 0x1000; i++) {
c = fgetc(in);
n += c;
2015-11-29 00:14:59 +00:00
}
2015-11-29 20:15:10 +00:00
/* write checksum to header */
fseek(in, 0, SEEK_SET);
fputc(n & 0xff, in);
fputc((n >> 8) & 0xff, in);
2015-11-29 00:14:59 +00:00
fclose(in);
return (0);
2015-11-29 00:14:59 +00:00
}