diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-12 20:52:36 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-12 20:52:36 -0400 |
commit | 1f373e3c596ec99e0f3d23fdb863931e8f0a6956 (patch) | |
tree | f27d6d099ef9edcf3c2fcae7d8865ef8c927f679 | |
parent | bb30630206d4386b39ebad49db8c91bc4c202f5c (diff) |
misc: Add initial argument parsing
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | emux64/src/main.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/emux64/src/main.c b/emux64/src/main.c index cacd6b3..4396eb5 100644 --- a/emux64/src/main.c +++ b/emux64/src/main.c @@ -29,13 +29,55 @@ #include <stdio.h> #include <stdlib.h> +#include <unistd.h> #include <cpu/cpu.h> +#include <string.h> + +static char *rom_file = NULL; + +static void +help(void) +{ + printf( + "- OSMX64 emulator -\n" + "[-h] Show this help menu\n" + "[-r] <rom_file>\n" + ); +} + +static void +cleanup(void) +{ + if (rom_file != NULL) { + free(rom_file); + rom_file = NULL; + } +} int -main(void) +main(int argc, char **argv) { struct osmx_core core; int error; + int c; + + atexit(cleanup); + while ((c = getopt(argc, argv, "hr:")) != -1) { + switch (c) { + case 'h': + help(); + return 0; + case 'r': + rom_file = strdup(optarg); + break; + } + } + + if (rom_file == NULL) { + printf("** please select a ROM file\n"); + help(); + return -1; + } if ((error = cpu_reset(&core)) < 0) { printf("error: failed to power up vcore\n"); |