1 // A little utility to convert SMDs to BINs
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <stdint.h>
6 #include <string.h>
7 #include <errno.h>
8 #ifndef __MINGW32__
9 #include <signal.h>
10 #endif
11 #include "romload.h"
12 
13 #undef main /* -Dmain=SDL_main */
main(int argc,char * argv[])14 int main(int argc, char *argv[])
15 {
16 	size_t size;
17 	FILE *out;
18 	uint8_t *rom;
19 
20 #ifndef __MINGW32__
21 	signal(SIGPIPE, SIG_IGN);
22 #endif
23 	if (argc != 3) {
24 		fprintf(stderr, "Usage: %s {from.smd} {to.bin}\n", argv[0]);
25 		return EXIT_FAILURE;
26 	}
27 	rom = load_rom(&size, argv[1]);
28 	if (rom == NULL) {
29 		fprintf(stderr, "%s: `%s': Unable to load ROM\n", argv[0],
30 			argv[1]);
31 		return EXIT_FAILURE;
32 	}
33 	out = fopen(argv[2], "wb");
34 	if (out == NULL) {
35 		fprintf(stderr, "%s: `%s': %s\n", argv[0], argv[2],
36 			strerror(errno));
37 		unload_rom(rom);
38 		return EXIT_FAILURE;
39 	}
40 	size = fwrite(rom, size, 1, out);
41 	fclose(out);
42 	unload_rom(rom);
43 	if (size == 1)
44 		return EXIT_SUCCESS;
45 	fprintf(stderr, "%s: `%s': %s\n", argv[0], argv[2], strerror(errno));
46 	return EXIT_FAILURE;
47 }
48