-
Notifications
You must be signed in to change notification settings - Fork 0
/
tobin.c
48 lines (45 loc) · 1.01 KB
/
tobin.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
46
47
48
// A little utility to convert SMDs to BINs
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#ifndef __MINGW32__
#include <signal.h>
#endif
#include "romload.h"
#undef main /* -Dmain=SDL_main */
int main(int argc, char *argv[])
{
size_t size;
FILE *out;
uint8_t *rom;
char *error_msg;
#ifndef __MINGW32__
signal(SIGPIPE, SIG_IGN);
#endif
if (argc != 3) {
fprintf(stderr, "Usage: %s {from.smd} {to.bin}\n", argv[0]);
return EXIT_FAILURE;
}
rom = load_rom(&size, argv[1], error_msg);
if (rom == NULL) {
fprintf(stderr, "%s: `%s': Unable to load ROM\n", argv[0],
argv[1]);
return EXIT_FAILURE;
}
out = fopen(argv[2], "wb");
if (out == NULL) {
fprintf(stderr, "%s: `%s': %s\n", argv[0], argv[2],
strerror(errno));
unload_rom(rom);
return EXIT_FAILURE;
}
size = fwrite(rom, size, 1, out);
fclose(out);
unload_rom(rom);
if (size == 1)
return EXIT_SUCCESS;
fprintf(stderr, "%s: `%s': %s\n", argv[0], argv[2], strerror(errno));
return EXIT_FAILURE;
}