5 #define OUT_SIZE 0x400000
6 static unsigned char buff[OUT_SIZE], buff_in[IN_SIZE];
8 int main(int argc, char *argv[])
15 fprintf(stderr, "usage:\n%s <sms ROM> <mx img>\n", argv[0]);
19 fi = fopen(argv[1], "rb");
21 fprintf(stderr, "can't open: %s\n", argv[1]);
25 fo = fopen(argv[2], "wb");
27 fprintf(stderr, "can't open: %s\n", argv[2]);
31 fseek(fi, 0, SEEK_END);
33 fseek(fi, 0, SEEK_SET);
36 fprintf(stderr, "ROMs > 32k won't work\n");
40 if (fread(buff_in, 1, size, fi) != size)
41 fprintf(stderr, "failed to read %s\n", argv[1]);
43 memset(buff, 0, sizeof(buff));
45 for (bsize = 1; bsize < size; bsize <<= 1)
48 for (i = o = 0; o < sizeof(buff); i = (i + 1) & (bsize - 1), o += 2)
49 buff[o+1] = buff_in[i];
51 if (fwrite(buff, 1, OUT_SIZE, fo) != OUT_SIZE)
52 fprintf(stderr, "failed to write to %s\n", argv[2]);