-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.c
98 lines (89 loc) · 2.42 KB
/
split.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <errno.h>
void write(FILE *in, FILE *out, int amount) {
char data[amount];
fread(data, amount,1, in);
fwrite(data, amount,1, out);
}
int main(int argc, char* argv[]) {
if(argc < 3) {
fprintf(stderr, "usage: split rom_folder type\n eg pinmame32_23/roms/game_name/ (note trailing slash)\ntype: sys3, sys4, sys6 or sys7");
return 1;
}
char* folder = argv[1];
FILE *in = fopen("rom.764", "rb");
if(!in) {
fprintf(stderr, "could not open rom.764, errno %i", (errno));
return 3;
}
char path[100];
FILE *a, *b, *c, *aa, *bb, *cc;
if (!strcmp(argv[2], "sys7")) {
sprintf(path, "%sic14.716", folder);
a = fopen(path, "wb");
sprintf(path, "%sic20.716", folder);
b = fopen(path, "wb");
sprintf(path, "%sic17.532", folder);
c = fopen(path, "wb");
aa = fopen("ic14.716", "wb");
bb = fopen("ic20.716", "wb");
cc = fopen("ic17.532", "wb");
fseek(in, 0x0000, SEEK_SET);
write(in, a, 2048);
fseek(in, 0x0000, SEEK_SET);
write(in, aa, 2048);
fseek(in, 0x800, SEEK_SET);
write(in, b, 2048);
fseek(in, 0x800, SEEK_SET);
write(in, bb, 2048);
fseek(in, 0x1000, SEEK_SET);
write(in, c, 2048*2);
fseek(in, 0x1000, SEEK_SET);
write(in, cc, 2048*2);
} else {
char* color;
if (strcmp(argv[2], "sys3") == 0)
color = "white";
else if (strcmp(argv[2], "sys4") == 0)
color = "yellow";
else if (strcmp(argv[2], "sys6") == 0)
color = "green";
else {
fprintf(stderr, "unknown type '%s'\n", argv[2]);
return 2;
}
sprintf(path, "%sgamerom.716", folder);
a = fopen(path, "wb");
sprintf(path, "%s%s1.716", folder, color);
b = fopen(path, "wb");
sprintf(path, "%s%s2.716", folder, color);
c = fopen(path, "wb");
aa = fopen("gamerom.716", "wb");
sprintf(path, "%s1.716", color);
bb = fopen(path, "wb");
sprintf(path, "%s2.716", color);
cc = fopen(path, "wb");
fseek(in, 0x0000, SEEK_SET);
write(in, a, 2048);
fseek(in, 0x0000, SEEK_SET);
write(in, aa, 2048);
fseek(in, 0x1000, SEEK_SET);
write(in, b, 2048);
fseek(in, 0x1000, SEEK_SET);
write(in, bb, 2048);
fseek(in, 0x1800, SEEK_SET);
write(in, c, 2048);
fseek(in, 0x1800, SEEK_SET);
write(in, cc, 2048);
}
fseek(in, 0x0000, SEEK_END);
if(ftell(in)!=8192) {
fprintf(stderr, "file overflow! %i", ftell(in));
return 1;
}
fclose(a);
fclose(b);
fclose(c);
fclose(in);
return 0;
}