From 262a16f4f5d8e1aa1bf24a15ffd6e017d8e59622 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 15 Mar 2009 14:55:22 +0000 Subject: [PATCH] sms conversion tool --- mx/linux/sms2mx.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 mx/linux/sms2mx.c diff --git a/mx/linux/sms2mx.c b/mx/linux/sms2mx.c new file mode 100644 index 0000000..2dd4292 --- /dev/null +++ b/mx/linux/sms2mx.c @@ -0,0 +1,57 @@ +#include +#include + +#define IN_SIZE 0x8000 +static unsigned char buff[0x400000], buff_in[IN_SIZE]; + +int main(int argc, char *argv[]) +{ + FILE *fi, *fo; + int size, bsize; + int i, o; + + if (argc != 3) { + fprintf(stderr, "usage:\n%s \n", argv[0]); + return 1; + } + + fi = fopen(argv[1], "rb"); + if (fi == NULL) { + fprintf(stderr, "can't open: %s\n", argv[1]); + return 1; + } + + fo = fopen(argv[2], "wb"); + if (fo == NULL) { + fprintf(stderr, "can't open: %s\n", argv[2]); + return 1; + } + + fseek(fi, 0, SEEK_END); + size = ftell(fi); + fseek(fi, 0, SEEK_SET); + + if (size > IN_SIZE) { + fprintf(stderr, "ROMs > 32k won't work\n"); + size = IN_SIZE; + } + + if (fread(buff_in, 1, size, fi) != size) + fprintf(stderr, "failed to read %s\n", argv[1]); + + memset(buff, 0, sizeof(buff)); + + for (bsize = 1; bsize < size; bsize <<= 1) + ; + + for (i = 0, o = 0; o < sizeof(buff); i = (i + 1) & (bsize - 1), o += 2) + buff[o] = buff[o+1] = buff_in[i]; + + if (fwrite(buff, 1, 0x400000, fo) != 0x400000) + fprintf(stderr, "failed to write to %s\n", argv[2]); + fclose(fi); + fclose(fo); + + return 0; +} + -- 2.39.5