-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
46 lines (44 loc) · 1.42 KB
/
main.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
#include <stdio.h>
int main(int argc, char **argv)
{
printf("dat2cf: Convert 8-bit images to 16-bit images\n");
printf("---------------------------------------------\n");
printf("For use with retro adaptors and peripheral technology such as the RetroClinic Datacentre.\n\n");
if(argc==3) {
printf("Input file: %s\n", argv[1]);
printf("Output file: %s\n\n", argv[2]);
} else {
printf("Wrong number of command line parameters. Expected 2 parameters: Input file and output files\n");
printf("Usage: dat2cf <input file path> <output file path>\n");
return 1;
}
FILE *fp = fopen(argv[1], "rb");
FILE *ofp = fopen(argv[2], "wb");
if(fp && ofp)
{
printf("Commencing with conversion....\n");
unsigned char buffer[4096];
size_t sz;
long writeByte = 0;
int blank = 0;
while ((sz = fread(buffer, 1, sizeof(buffer), fp)) > 0)
{
for(int i = 0; i < sz; i++)
{
fwrite(&buffer[i], 1, 1, ofp);
writeByte++;
fwrite(&blank, 1, 1, ofp);
writeByte++;
}
}
printf("%ld bytes written.\n", writeByte);
} else {
if(!fp) {
printf("Error opening input file. Please check path and try again.\n");
}
else {
printf("Error opening files.\n");
}
}
return 0;
}