From 87388f510f800aa4bc1bb78e35b488ea5636ce87 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 8 Jul 2023 10:04:27 +0100 Subject: CLI and no sound option --- src/main.c | 38 ++++++++++++++++++++++++++++++++++++-- src/sound.c | 5 +++-- src/sound.h | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index d5b9df8..c18318e 100644 --- a/src/main.c +++ b/src/main.c @@ -12,10 +12,25 @@ #include "menu.h" #include "game.h" +#define GAME_NAME "Gold Mine Run!" +#define GAME_VERSION "A0" +#define GAME_URL "https://git.usebox.net/dos-jam-2023/about/" + /* disable paging because our int handlers are written in C */ int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY; -void free_all() +static void run_help(const char *argv0) +{ + printf("usage: %s\n\n" + " -h\tthis help screen\n" + " -v\tprint version and exit\n" + " -ns\trun the game with no sound\n\n" + "More info and updates:\n" + " " GAME_URL "\n\n", + argv0); +} + +static void free_all() { timer_free(); keyb_free(); @@ -24,7 +39,26 @@ void free_all() int main(int argc, char *argv[]) { - if (!sound_init()) + uint8_t nosound = 0; + + if (argc > 1) + { + for (uint8_t i = 1; i < argc; i++) + if (!strcmp(argv[i], "-h")) + { + run_help(argv[0]); + return 0; + } + else if (!strcmp(argv[i], "-v")) + { + printf(GAME_NAME " " GAME_VERSION "\n"); + return 0; + } + else if (!strcmp(argv[i], "-ns")) + nosound = 1; + } + + if (!sound_init(nosound)) { fprintf(stderr, "ERROR: failed to init sound\n"); return 1; diff --git a/src/sound.c b/src/sound.c index f19b7ff..0a10ae4 100644 --- a/src/sound.c +++ b/src/sound.c @@ -35,11 +35,12 @@ static MODULE *music = NULL; static uint8_t queue[MAX_QUEUE]; static uint8_t queue_top; -uint8_t sound_init() +uint8_t sound_init(uint8_t nosound) { MikMod_InitThreads(); - MikMod_RegisterDriver(&drv_sb); + if (!nosound) + MikMod_RegisterDriver(&drv_sb); MikMod_RegisterDriver(&drv_nos); MikMod_RegisterLoader(&load_it); diff --git a/src/sound.h b/src/sound.h index be4df88..cd7c20c 100644 --- a/src/sound.h +++ b/src/sound.h @@ -11,7 +11,7 @@ enum { EFX_DEATH, }; -uint8_t sound_init(); +uint8_t sound_init(uint8_t nosound); void sound_free(); void sound_update(); -- cgit v1.2.3