-
Notifications
You must be signed in to change notification settings - Fork 3
/
combine-roms.c
59 lines (47 loc) · 1.1 KB
/
combine-roms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
unsigned long int i, bufsize;
unsigned char *buf;
FILE *fin1, *fin2, *fout;
if (argc != 4) {
printf("syntax: combine-roms [input1] [input2] [output]\n");
return(1);
}
fin1 = fopen(argv[1], "rb");
if (!fin1) {
printf("[input1] missing!\n");
return(1);
} else {
// ok
}
fin2 = fopen(argv[2], "rb");
if (!fin2) {
printf("[input2] missing!\n");
return(1);
} else {
// ok
}
fout = fopen(argv[3], "wb");
if (!fout) {
printf("[output] error.\n");
return(1);
} else {
printf("creating [output] file.\n");
}
fseek(fin1, 0, SEEK_END);
bufsize = ftell(fin1);
fseek(fin1, 0, SEEK_SET);
printf("combining %u x2 bytes.\n", bufsize);
bufsize = bufsize;
buf = (unsigned char *)malloc(bufsize * 2);
for(i=0; i < bufsize; i++) {
fread(&buf[(i*2) + 0], 1, 1, fin1);
fread(&buf[(i*2) + 1], 1, 1, fin2);
}
fwrite(&buf[0], 1, bufsize * 2, fout);
free(buf);
fclose(fout);
fclose(fin2);
fclose(fin1);
}