/[pcsx2_0.9.7]/trunk/fps2bios/ps2romgen.c
ViewVC logotype

Contents of /trunk/fps2bios/ps2romgen.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 2 months ago) by william
File MIME type: text/plain
File size: 1934 byte(s)
committing r3113 initial commit again...
1 // little prog for bios image repack by Florin Sasu 2002-10-03
2
3 #include <stdio.h>
4 #include <string.h>
5
6 struct romdir{
7 char name[10];
8 short ext;
9 int size;
10 } rd[200]; //increase the number if needed; 200 is enough
11
12 char buffer[10000];
13
14 #define min(a,b) (a<b?a:b)
15
16 void fillfile(FILE *f, int size, char c){
17 memset(buffer, c, 10000);
18 while(size>0){
19 fwrite(buffer, 1, min(size, 10000), f);
20 size-=10000;
21 }
22 }
23
24 void writefile(FILE *f, char *name, int offset, int size){
25 FILE *fi=fopen(name, "rb");
26 if (fi) fseek(fi, 0, SEEK_END);
27 if ((!fi) || (ftell(fi)!=size)){
28 printf("Could not find a file %s of %d bytes\n", name, size);
29 if (fi) fclose(fi);
30 return;
31 }
32
33 printf("%10s\t%8X\t%8X\n", name, offset, size);
34 fillfile(f, offset-ftell(f), 0);
35 fseek(fi, 0, SEEK_SET);
36 while (size>0){
37 fread(buffer, 1, min(10000, size), fi);
38 fwrite(buffer, 1, min(10000, size), f);
39 size-=10000;
40 }
41
42 fclose(fi);
43 }
44
45 int main(int argc, char* argv[]){
46 int i, n, offset;
47 FILE *f;
48 //////////////////////////////////
49 printf("PS2 ROMGEN v0.1 Florin Sasu 2002-10-03 (florinsasu@yahoo.com) no padding\n");
50 if (argc<2){
51 printf("Usage: ps2biosgen <filename>\n\tfilename=name of the biosfile to create\n");
52 printf("\n\tPut in the same directory with ps2romgen all the files from bios\n");
53 return 1;
54 }
55 //////////////////////////////////
56 f=fopen("ROMDIR", "rb");
57 if (!f){
58 printf("Could not find the ROMDIR file\n");
59 return 1;
60 }
61
62 for (n=0; !feof(f) && (fread(&rd[n], 16, 1, f)==1) && rd[n].name[0]; n++);
63
64 fclose(f);
65 //////////////////////////////////
66 printf("\n Name Offset(hex) Size(hex)"
67 "\n----------------------------------------\n");
68 f=fopen(argv[1], "wb");
69
70 for (i=0, offset=0; i<n; offset=(rd[i++].size+offset+15) & 0xFFFFFFF0)
71 if (rd[i].name[0]!='-')
72 writefile(f, rd[i].name, offset, rd[i].size);
73
74 fclose(f);
75 //////////////////////////////////
76 printf("Done (%s)\n", argv[1]);
77
78 return 0;
79 }
80

  ViewVC Help
Powered by ViewVC 1.1.22