From 0f98327ed353861d9958cf77a0e00549d5147b56 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Tue, 22 Oct 2013 23:16:35 -0400 Subject: [PATCH] Add option to specify maximum memory sizes --- src/memwin.c | 6 ++++-- src/options.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/options.h | 2 ++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/memwin.c b/src/memwin.c index 446f9d4..58ce1d2 100644 --- a/src/memwin.c +++ b/src/memwin.c @@ -33,9 +33,11 @@ #include "regwin.h" #include "memwin.h" #include "emugtk.h" +#include "options.h" #include "app-config.h" extern struct app_config_t *cfg; +extern struct options_t options; static int COL_ASCII; static int N_COLUMNS; @@ -201,9 +203,9 @@ compute_data_rows(int memory_id) int data_rows; if (memory_id == INT_MEM_ID) { - data_rows = (INT_MEM_SIZE / cfg->bits_per_row); + data_rows = options.iram_size / cfg->bits_per_row; } else if (memory_id == EXT_MEM_ID) { - data_rows = 1024 / cfg->bits_per_row; + data_rows = options.xram_size / cfg->bits_per_row; } else { log_fail("Invalid memory type"); exit(1); diff --git a/src/options.c b/src/options.c index 94f1063..c5833b3 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,9 @@ 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" }, + {"xram", 'x', "size", 0, "Set external ram size" }, { 0 } }; @@ -76,6 +79,35 @@ 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 max_size; + int *dest; + + if (memid == INT_MEM_ID) { + max_size = INT_MEM_SIZE; + dest = &options.iram_size; + } else { + max_size = EXT_MEM_SIZE; + dest = &options.xram_size; + } + + *dest = strtol(arg, &endptr, 0); + + if (*endptr != '\0') { + log_fail_no_exit("Invalid memory size"); + argp_usage(state); + } + + if (*dest > max_size) { + log_fail_no_exit("Invalid maximum memory size (max = %d)", + max_size); + argp_usage(state); + } +} + /* Parse a single option. */ static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -84,6 +116,12 @@ 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 '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 +155,8 @@ parse_command_line_options(int argc, char *argv[]) /* Setting default values. */ options.filename = NULL; + options.iram_size = INT_MEM_SIZE; + options.xram_size = EXT_MEM_SIZE; /* Parse our arguments. */ argp_parse(&argp, argc, argv, 0, 0, NULL); diff --git a/src/options.h b/src/options.h index f71427f..b58b636 100644 --- a/src/options.h +++ b/src/options.h @@ -28,6 +28,8 @@ " -version display version information and exit\n" struct options_t { + int iram_size; /* Maximum internal ram size. */ + int xram_size; /* Maximum external ram size. */ char *filename; } options_t; -- 2.20.1