summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2015-01-05 23:05:37 -0600
committerBobby Bingham <koorogi@koorogi.info>2015-09-15 22:43:32 -0500
commitd6f12cdb4b333af94c9195e51218a9301aa58a7e (patch)
tree449c1c9c773522669b0ce2cdddf868ccdf625538
parente9ee32b27041de24d66b984c1eff568169a1e23d (diff)
allow specifying supported peripherals
-rw-r--r--src/satmkboot.c47
-rw-r--r--src/symbols.c20
-rw-r--r--src/symbols.h1
3 files changed, 52 insertions, 16 deletions
diff --git a/src/satmkboot.c b/src/satmkboot.c
index 7faaf4c..d3b5958 100644
--- a/src/satmkboot.c
+++ b/src/satmkboot.c
@@ -14,7 +14,7 @@ static struct systemid sysid = {
.reldate = "20000101",
.device = "CD-1/1 ",
.regions = " ",
- .peripherals = "J ",
+ .peripherals = " ",
.bootsize = 0xe00,
.stack_master = 0,
.stack_slave = 0,
@@ -130,19 +130,22 @@ static void usage(const char *progname)
const int width = 20;
fprintf(stderr, "usage: %s -h\n", progname);
- fprintf(stderr, " %s -io[r]\n\n", progname);
+ fprintf(stderr, " %s -io[pr]\n\n", progname);
fprintf(stderr, "\t%-*s%s\n", width, "-h", "Show this help text");
fprintf(stderr, "\t%-*s%s\n", width, "-i ip.bin", "Initial program code file");
fprintf(stderr, "\t%-*s%s\n", width, "-o output", "Output file");
- fprintf(stderr, "\t%-*s%s\n", width, "-r regions", "Geographical regions (default all):");
+ fprintf(stderr, "\t%-*s%s\n", width, "-p peripherals", "Supported peripherals (default: control pad):");
+ print_symbols(stderr, width, peripheraldefs);
+ fprintf(stderr, "\t%-*s%s\n", width, "-r regions", "Geographical regions (default: all):");
print_symbols(stderr, width, regiondefs);
}
-#define ERR_UNKNOWN_OPTION 0
-#define ERR_MISSING_OPTION 1
-#define ERR_DUPLICATE_INPUT 2
-#define ERR_DUPLICATE_OUTPUT 3
-#define ERR_REGION_OVERFLOW 4
+#define ERR_UNKNOWN_OPTION 0
+#define ERR_MISSING_OPTION 1
+#define ERR_DUPLICATE_INPUT 2
+#define ERR_DUPLICATE_OUTPUT 3
+#define ERR_REGION_OVERFLOW 4
+#define ERR_PERIPHERAL_OVERFLOW 5
static const char *errmsgs[] = {
"Unknown extra argument",
@@ -150,6 +153,7 @@ static const char *errmsgs[] = {
"Duplicate -i parameter",
"Duplicate -o parameter",
"Too many regions specified (max 10)",
+ "Too many peripherals specified (max 16)",
};
static int show_arg_error(const char *progname, int prev_errors, int error)
@@ -159,6 +163,16 @@ static int show_arg_error(const char *progname, int prev_errors, int error)
return prev_errors | 1 << error;
}
+static void process_symbols(const char *progname, char *list, size_t size, const char *arg, int *errors, int overflow)
+{
+ for (; *arg; arg++) {
+ if (append_symbol(list, size, *arg)) {
+ *errors = show_arg_error(progname, *errors, overflow);
+ return;
+ }
+ }
+}
+
static int process_args(int argc, char **argv)
{
int errors = 0, fail = 0, help = 0;
@@ -166,7 +180,7 @@ static int process_args(int argc, char **argv)
extern char *optarg;
extern int optind, optopt;
- while ((opt = getopt(argc, argv, "hi:o:r:")) != -1) {
+ while ((opt = getopt(argc, argv, "hi:o:r:p:")) != -1) {
switch (opt) {
case 'h':
help = 1;
@@ -186,13 +200,12 @@ static int process_args(int argc, char **argv)
outfile = optarg;
break;
+ case 'p':
+ process_symbols(argv[0], sysid.peripherals, sizeof sysid.peripherals, optarg, &errors, ERR_PERIPHERAL_OVERFLOW);
+ break;
+
case 'r':
- for (; *optarg; optarg++) {
- if (append_symbol(sysid.regions, sizeof sysid.regions, *optarg)) {
- errors = show_arg_error(argv[0], errors, ERR_REGION_OVERFLOW);
- break;
- }
- }
+ process_symbols(argv[0], sysid.regions, sizeof sysid.regions, optarg, &errors, ERR_REGION_OVERFLOW);
break;
default:
@@ -227,7 +240,9 @@ int main(int argc, char **argv)
return 1;
}
- if (sysid.regions[0] == ' ') strcpy(sysid.regions, "JTUBKAEL");
+ if (sysid.regions[0] == ' ') strcpy(sysid.regions, "JTUBKAEL");
+ if (sysid.peripherals[0] == ' ') sysid.peripherals[0] = 'J';
+
for (int i = 0; i < 10 && sysid.regions[i] != ' '; i++) {
const struct symbolname *region = find_symbol(regiondefs, sysid.regions[i]);
if (region) ipout = serialize_region_code(ipout, region);
diff --git a/src/symbols.c b/src/symbols.c
index 4bb73bb..4f9a25f 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -14,6 +14,26 @@ const struct symbolname regiondefs[] = {
{ 0 }
};
+const struct symbolname peripheraldefs[] = {
+ { .symbol = 'A', .name = "Analog Controller" },
+ { .symbol = 'C', .name = "Link Cable" },
+ { .symbol = 'D', .name = "Modem" },
+ { .symbol = 'E', .name = "3D Control Pad" },
+ { .symbol = 'F', .name = "Floppy Drive" },
+ { .symbol = 'G', .name = "Virtua Gun" },
+ { .symbol = 'J', .name = "Control Pad" },
+ { .symbol = 'K', .name = "Keyboard" },
+ { .symbol = 'M', .name = "Mouse" },
+ { .symbol = 'P', .name = "Video CD Card" },
+ { .symbol = 'Q', .name = "Pachinko Controller" },
+ { .symbol = 'R', .name = "ROM Catridge" },
+ { .symbol = 'S', .name = "Steering Wheel" },
+ { .symbol = 'T', .name = "Multi-Tap" },
+ { .symbol = 'W', .name = "RAM Cartridge" },
+ { .symbol = 'X', .name = "XBAND Modem" },
+ { 0 }
+};
+
const struct symbolname *find_symbol(const struct symbolname *symbols, char symbol)
{
for (; symbols->symbol; symbols++) {
diff --git a/src/symbols.h b/src/symbols.h
index 78888ba..d588216 100644
--- a/src/symbols.h
+++ b/src/symbols.h
@@ -7,6 +7,7 @@ struct symbolname {
};
extern const struct symbolname regiondefs[];
+extern const struct symbolname peripheraldefs[];
const struct symbolname *find_symbol(const struct symbolname *symbols, char symbol);