X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Foptions.c;h=138507e12182dddadd9779a4839f9e8ca7b4cee5;hb=add152ddb851575c885208c12b008887e68b9f48;hp=94f1063e43f4898cda8497270515d817309fffc9;hpb=7b400e8dd6a3f1a50247b74283c76e34f9e20ba1;p=emu8051.git diff --git a/src/options.c b/src/options.c index 94f1063..138507e 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 } }; @@ -76,6 +80,33 @@ decode_debug_option(char *arg, struct argp_state *state) log_set_level(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_fail_no_exit("Invalid memory size"); + argp_usage(state); + } +} + /* Parse a single option. */ static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -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,9 @@ 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; /* Parse our arguments. */ argp_parse(&argp, argc, argv, 0, 0, NULL);