Add VCS links
[debian-dgen.git] / tobin.c
blob74f79072478f82356399516f7e77a07d9cec179f
1 // A little utility to convert SMDs to BINs
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"
13 #undef main /* -Dmain=SDL_main */
14 int main(int argc, char *argv[])
16 size_t size;
17 FILE *out;
18 uint8_t *rom;
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;
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;
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;
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;