-
Notifications
You must be signed in to change notification settings - Fork 0
/
64drive_writerom.c
62 lines (49 loc) · 1.25 KB
/
64drive_writerom.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
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// 64drive_writerom.c
//
// usb64drive; A open-source 64drive library.
// Copyright (C) 2014, Tyler J. Stachecki.
//
// This file is subject to the terms and conditions defined in
// 'LICENSE', which is part of this source code package.
//
#include "usb64drive.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[]) {
const char *file, *device;
unsigned version;
FILE *f;
int fd;
if (argc < 2 || argc > 3) {
printf("Usage: %s [device path] <rom path>\n", argv[0]);
return EXIT_SUCCESS;
}
file = argc > 2 ? argv[2] : argv[1];
device = argc > 2 ? argv[1] : "/dev/ttyUSB0";
if ((f = fopen(file, "r")) == NULL) {
printf("Failed to open: %s\n", file);
return EXIT_FAILURE;
}
if ((fd = usb64drive_open(device)) < 0) {
printf("Failed to open: %s\n", device);
fclose(f);
return EXIT_FAILURE;
}
if (usb64drive_get_version(fd, &version)) {
printf("Failed to query version.\n");
fclose(f);
usb64drive_close(fd);
return EXIT_FAILURE;
}
if (usb64drive_write_rom(fd, f)) {
printf("Failed to write the ROM image.\n");
fclose(f);
usb64drive_close(fd);
return EXIT_FAILURE;
}
fclose(f);
usb64drive_close(fd);
return EXIT_SUCCESS;
}