forked from AKuHAK/fps2bios
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ps2romgen.c
91 lines (77 loc) · 1.96 KB
/
ps2romgen.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
// little prog for bios image repack by Florin Sasu 2002-10-03
#include <stdio.h>
#include <string.h>
struct romdir
{
char name[10];
short ext;
int size;
} rd[200]; //increase the number if needed; 200 is enough
char buffer[10000];
#define min(a, b) (a < b ? a : b)
void fillfile(FILE* f, int size, char c)
{
memset(buffer, c, 10000);
while (size > 0)
{
fwrite(buffer, 1, min(size, 10000), f);
size -= 10000;
}
}
void writefile(FILE* f, char* name, int offset, int size)
{
FILE* fi = fopen(name, "rb");
if (fi)
fseek(fi, 0, SEEK_END);
if ((!fi) || (ftell(fi) != size))
{
printf("Could not find a file %s of %d bytes\n", name, size);
if (fi)
fclose(fi);
return;
}
printf("%10s\t%8X\t%8X\n", name, offset, size);
fillfile(f, offset - ftell(f), 0);
fseek(fi, 0, SEEK_SET);
while (size > 0)
{
fread(buffer, 1, min(10000, size), fi);
fwrite(buffer, 1, min(10000, size), f);
size -= 10000;
}
fclose(fi);
}
int main(int argc, char* argv[])
{
int i, n, offset;
FILE* f;
//////////////////////////////////
printf("PS2 ROMGEN v0.1 Florin Sasu 2002-10-03 ([email protected]) no padding\n");
if (argc < 2)
{
printf("Usage: ps2biosgen <filename>\n\tfilename=name of the biosfile to create\n");
printf("\n\tPut in the same directory with ps2romgen all the files from bios\n");
return 1;
}
//////////////////////////////////
f = fopen("ROMDIR", "rb");
if (!f)
{
printf("Could not find the ROMDIR file\n");
return 1;
}
for (n = 0; !feof(f) && (fread(&rd[n], 16, 1, f) == 1) && rd[n].name[0]; n++)
;
fclose(f);
//////////////////////////////////
printf("\n Name Offset(hex) Size(hex)"
"\n----------------------------------------\n");
f = fopen(argv[1], "wb");
for (i = 0, offset = 0; i < n; offset = (rd[i++].size + offset + 15) & 0xFFFFFFF0)
if (rd[i].name[0] != '-')
writefile(f, rd[i].name, offset, rd[i].size);
fclose(f);
//////////////////////////////////
printf("Done (%s)\n", argv[1]);
return 0;
}