Remove obsolescent macro AM_PROG_CC_C_O
[emu8051.git] / src / options.c
index 7b6143d..420cc85 100644 (file)
@@ -45,8 +45,9 @@ static const char args_doc[] = "[FILENAME]";
 /* The options we understand. */
 static struct argp_option argp_options[] = {
        {"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)" },
+       {"stop",  's', "addr",  0,  "Automatically run program and stop at address" },
        { 0 }
 };
 
@@ -67,43 +68,54 @@ 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 max_size;
        int *dest;
 
-       if (memid == INT_MEM_ID) {
-               max_size = INT_MEM_SIZE;
+       if (memid == PGM_MEM_ID)
+               dest = &options.pram_size;
+       else if (memid == INT_MEM_ID)
                dest = &options.iram_size;
-       } else {
-               max_size = EXT_MEM_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");
+               log_err("Invalid memory size");
                argp_usage(state);
        }
+}
+
+static void
+decode_address(char *arg, struct argp_state *state, uint16_t *dest)
+{
+       char *endptr;
 
-       if (*dest > max_size) {
-               log_fail_no_exit("Invalid maximum memory size (max = %d)",
-                       max_size);
+       *dest = strtol(arg, &endptr, 0);
+
+       if (*endptr != '\0') {
+               log_err("Invalid address");
                argp_usage(state);
        }
 }
@@ -119,6 +131,12 @@ parse_opt(int key, char *arg, struct argp_state *state)
        case 'i':
                decode_memory_size(arg, state, INT_MEM_ID);
                break;
+       case 'p':
+               decode_memory_size(arg, state, PGM_MEM_ID);
+               break;
+       case 's':
+               decode_address(arg, state, &options.stop_address);
+               break;
        case 'x':
                decode_memory_size(arg, state, EXT_MEM_ID);
                break;
@@ -155,8 +173,11 @@ parse_command_line_options(int argc, char *argv[])
 
        /* Setting default values. */
        options.filename = NULL;
-       options.iram_size = INT_MEM_SIZE;
+       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;
+       options.stop_address = 0; /* 0 means stop address is disabled. */
 
        /* Parse our arguments. */
        argp_parse(&argp, argc, argv, 0, 0, NULL);