From e7b4d2cddf76c95a5de81802e69f0d22484455ce Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 3 Mar 2018 22:43:52 +0100 Subject: [PATCH] Add command line options --- src/mercenary/main.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/src/mercenary/main.c b/src/mercenary/main.c index 4057676..10d002a 100644 --- a/src/mercenary/main.c +++ b/src/mercenary/main.c @@ -77,6 +77,72 @@ static const char *home_dir; static int quit = 0; +int parse_args(int argc, char *argv[]) +{ + int i = 1; + + while (argc > i) { + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + printf("Usage: %s\n", argv[0]); + printf(" -s --amiga-speed original | full\n"); + printf(" Set speed of rendering to original Amiga or full speed.\n"); + printf(" -v --video-filter on | off\n"); + printf(" Set video filter.\n"); + printf(" -a --audio-filter on | off\n"); + printf(" Set audio filter.\n"); + return -1; + } else + if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--amiga-speed")) { + i++; + if (argc == i) { +missing_parameter: + printf("Missing parameter, use '--help'!\n"); + return -1; + } + if (!strcmp(argv[i], "original")) + config_amiga_speed = 1; + else + if (!strcmp(argv[i], "full")) + config_amiga_speed = 0; + else { +illegal_parameter: + printf("Illegal parameter, use '--help'!\n"); + return -1; + } + } else + if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--video-filter")) { + i++; + if (argc == i) + goto missing_parameter; + if (!strcmp(argv[i], "on")) + config_video_filter = 1; + else + if (!strcmp(argv[i], "off")) + config_video_filter = 0; + else + goto illegal_parameter; + } else + if (!strcmp(argv[i], "-a") || !strcmp(argv[i], "--audio-filter")) { + i++; + if (argc == i) + goto missing_parameter; + if (!strcmp(argv[i], "on")) + config_audio_filter = 1; + else + if (!strcmp(argv[i], "off")) + config_audio_filter = 0; + else + goto illegal_parameter; + } else { + printf("Illegal option '%s', use '--help'!\n", argv[i]); + return -1; + } + i++; + } + + return 0; +} + static void main_loop(void) { int had_first_irq = 0; @@ -174,7 +240,7 @@ static void main_loop(void) } } -int main(int __attribute__((unused)) argc, char *argv[]) +int main(int argc, char *argv[]) { int rc; int sdl_sound_chunk; @@ -183,6 +249,10 @@ int main(int __attribute__((unused)) argc, char *argv[]) if (!home_dir) home_dir = ""; + rc = parse_args(argc, argv); + if (rc) + return 0; + /* allocate image */ image = calloc(IMAGE_WIDTH * IMAGE_HEIGHT, 3); if (!image) { @@ -251,14 +321,16 @@ int main(int __attribute__((unused)) argc, char *argv[]) /* start cpu */ reset_cpu(); - printf("Welcome to Mercenary Reloaded!\n\n"); + printf("**********************************\n"); + printf("* Welcome to Mercenary Reloaded! *\n"); + printf("**********************************\n\n"); printf("Press CTRL + cursor keys to select inventory or pickup/drop item.\n"); printf("Press CTRL + f to toggle full screen.\n"); printf("Press CTRL + s to toggle rendering speed.\n"); printf("Press CTRL + v to toggle video filter.\n"); printf("Press CTRL + a to toggle audio filter.\n"); - printf("Press CTRL + c to exit game.\n"); - printf("\n"); + printf("Press CTRL + c to exit game.\n\n"); + printf("Use '--help' as command line option for configuration settings.\n\n"); /* run game */ main_loop(); -- 2.13.6