X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Foptions.c;h=39efd5727400013491cc94113921913e2a6a4c1d;hb=c2ef73ab945d0c668e000aef58a1ad227d8910c1;hp=94f1063e43f4898cda8497270515d817309fffc9;hpb=7b400e8dd6a3f1a50247b74283c76e34f9e20ba1;p=emu8051.git diff --git a/src/options.c b/src/options.c index 94f1063..39efd57 100644 --- a/src/options.c +++ b/src/options.c @@ -26,6 +26,7 @@ #include "common.h" #include "options.h" +#include "memory.h" const char *argp_program_version = PACKAGE_VERSION; const char *argp_program_bug_address = PACKAGE_BUGREPORT; @@ -43,7 +44,10 @@ static const char args_doc[] = "[FILENAME]"; /* The options we understand. */ static struct argp_option argp_options[] = { - {"debug", 'd', "level", 0, "Produce debugging output" }, + {"debug", 'd', "level", 0, "Produce debugging output" }, + {"iram", 'i', "size", 0, "Set internal ram size" }, + {"pram", 'p', "size", 0, "Set program memory size" }, + {"xram", 'x', "size", 0, "Set external ram size (default is 1024)" }, { 0 } }; @@ -64,16 +68,43 @@ decode_debug_option(char *arg, struct argp_state *state) log_level = strtol(arg, &endptr, 0); if (*endptr != '\0') { - log_fail_no_exit("Invalid log level"); + log_err("Invalid log level"); argp_usage(state); } if (log_level > LOG_LEVEL_DEBUG) { - log_fail_no_exit("Invalid log level"); + log_err("Invalid log level (0 to 3)"); argp_usage(state); } - log_set_level(log_level); + options.log = log_level; +} + +static void +decode_memory_size(char *arg, struct argp_state *state, int memid) +{ + char *endptr; + int *dest; + + if (memid == PGM_MEM_ID) + dest = &options.pram_size; + else if (memid == INT_MEM_ID) + dest = &options.iram_size; + else if (memid == EXT_MEM_ID) + dest = &options.xram_size; + else + exit(1); /* Programming error. */ + + /* + * Sizes versus max memory sizes will be checked when calling + * memory_init(). + */ + *dest = strtol(arg, &endptr, 0); + + if (*endptr != '\0') { + log_err("Invalid memory size"); + argp_usage(state); + } } /* Parse a single option. */ @@ -84,6 +115,15 @@ parse_opt(int key, char *arg, struct argp_state *state) case 'd': decode_debug_option(arg, state); break; + case 'i': + decode_memory_size(arg, state, INT_MEM_ID); + break; + case 'p': + decode_memory_size(arg, state, PGM_MEM_ID); + break; + case 'x': + decode_memory_size(arg, state, EXT_MEM_ID); + break; case ARGP_KEY_ARG: if (state->arg_num >= ARGS_COUNT) { /* Too many arguments. */ @@ -117,6 +157,10 @@ parse_command_line_options(int argc, char *argv[]) /* Setting default values. */ options.filename = NULL; + options.pram_size = PGM_MEM_DEFAULT_SIZE; + options.iram_size = INT_MEM_MAX_SIZE; + options.xram_size = EXT_MEM_DEFAULT_SIZE; + options.log = LOG_LEVEL_ERR; /* Parse our arguments. */ argp_parse(&argp, argc, argv, 0, 0, NULL);