summaryrefslogtreecommitdiff
path: root/tools/getpsxiso.c
blob: 76cfc72e57bd15c340b61d2b327f1247c8adb76a (plain) (blame)
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
// Converts a bin suitable for burning for the PlayStation
// to an ISO by getting only the 2048 data bytes of each sector
// The reverse of mkpsxiso

// Written by Giuseppe Gatta, 2010

#include <stdio.h>

int main(int argc, char *argv[])
{
	FILE *i, *o;
	int x, s;
	char buf[2352];

	if (argc < 3)
	{
		printf("getpsxiso <input> <output>\n");
		return -1;
	}
	
	i = fopen(argv[1], "rb");
	
	if(i == NULL)
	{
		printf("Could not open specified input file.\n");
		return -1;
	}
	
	fseek(i, 0, SEEK_END);
	s = ftell(i) / 2352;
	fseek(i, 0, SEEK_SET);
	
	if(s % 2352 == 0)
	{
		printf("Input file size not a multiplier of 2352.\n");
		printf("Aborting.\n");
		return -1;
	}
	
	o = fopen(argv[2], "wb");
	
	for(x = 0; x < s; x++)
	{
		fread(buf, sizeof(char), 2352, i);
		fwrite(buf + 24, sizeof(char), 2048, o);
		printf("Sector %d/%d written\r", x+1, s);
	}
	
	printf("\n");
	
	fclose(i);
	fclose(o);
	
	return 0;
}