cleaned up verbosity in vm-dcpu16.c
[dcpu16] / vm-dcpu16.c
index 17effb6a558db14d11698cfceaf56d452c202252..b59c253ee0700fa561a55ddb221650bb9d9f3632 100644 (file)
@@ -43,7 +43,8 @@ void sigint_handler_(int sig) {
 
 #define VERBOSE_PRINTF(...) do { if (opt_.verbose) printf(__VA_ARGS__); } while (0)
 
-static void usage_(char *prog, unsigned int full) {
+static
+void usage_(char *prog, unsigned int full) {
     FILE *f = full ? stdout : stderr;
     char *x = strrchr(prog, '/');
 
@@ -60,7 +61,7 @@ static void usage_(char *prog, unsigned int full) {
     if (full) {
         fprintf(f, "\nOptions:\n"
                 "\t [file] -- ram image to load initially\n"
-                "\t -v -- verbose execution tracing\n"
+                "\t -v -- displays slightly more information\n"
                 "\t -h -- this screen\n");
 
         fprintf(f, "\n%78s\n", src_id_);
@@ -130,13 +131,17 @@ int buf_tok_vect_(char ***v, int *c, char *buf) {
     return 0;
 }
 
-/* resets the instance and loads an image into ram starting at addr */
+/*
+    resets the vm if addr is zero then
+    loads an image from filename into ram starting at addr
+*/
 static
 int file_load_(struct dcpu16 *vm, char *filename, DCPU16_WORD addr) {
     FILE *f;
     size_t r;
 
-    dcpu16_reset(vm);
+    if (!addr)
+        dcpu16_reset(vm);
 
     f = fopen(filename, "rb");
     if (f == NULL) {
@@ -185,7 +190,7 @@ struct command_ {
 
 COMMAND_IMPL(quit) {
     (void)vm, (void)arg_count, (void)arg_vector;
-    VERBOSE_PRINTF("done\n");
+
     return -1;
 }
 COMMAND_HELP(quit) {
@@ -196,6 +201,21 @@ COMMAND_HELP(quit) {
 }
 
 
+COMMAND_IMPL(reset) {
+    (void)arg_count, (void)arg_vector;
+
+    dcpu16_reset(vm);
+    printf("initialized\n");
+    return 0;
+}
+COMMAND_HELP(reset) {
+    fprintf(f, "\treset\n");
+    if (summary) return;
+
+    fprintf(f, "Clears and reinitializes emulator.\n");
+}
+
+
 COMMAND_IMPL(load) {
     int addr = 0;
 
@@ -311,12 +331,11 @@ COMMAND_IMPL(step) {
     }
 
     while (count--) {
-        VERBOSE_PRINTF("executing next cycle, instruction: ");
-        dcpu16_disassemble_print(vm, vm->pc), printf("\n");
-
+        dcpu16_disassemble_print(vm, vm->pc);
+        printf("\n");
         dcpu16_step(vm);
 
-        if (opt_.verbose)
+        if (count > 1 && opt_.verbose)
             dcpu16_state_print(vm);
     }
 
@@ -344,8 +363,12 @@ COMMAND_IMPL(run) {
 
     while(running_) {
         dcpu16_step(vm);
-        if (opt_.verbose)
+        if (opt_.verbose > 1)
             dcpu16_state_print(vm);
+        else if (opt_.verbose) {
+            dcpu16_disassemble_print(vm, vm->pc);
+            printf("\n");
+        }
     }
 
     /* restore the old interrupt signal handler */
@@ -354,7 +377,7 @@ COMMAND_IMPL(run) {
         return -1;
     }
 
-    VERBOSE_PRINTF("interrupted...\n");
+    printf("interrupted...\n");
 
     return 0;
 }
@@ -362,7 +385,8 @@ COMMAND_HELP(run) {
     fprintf(f, "\trun\n");
     if (summary) return;
 
-    fprintf(f, "Begins executing continuously.\n");
+    fprintf(f, "Begins executing continuously.\n"
+               "May be interrupted with SIGINT.\n");
 }
 
 /* gather all these together into a searchable table */
@@ -379,6 +403,7 @@ static struct command_ command_table_[] = {
     COMMAND_ENTRY(disassemble, 0, 2),
     COMMAND_ENTRY(step, 0, 1),
     COMMAND_ENTRY(run, 0, 0),
+    COMMAND_ENTRY(reset, 0, 0),
     { NULL, 0, 0, NULL, NULL }
 };
 
@@ -407,7 +432,7 @@ COMMAND_HELP(help) {
         fprintf(f, "\thelp [command]\n");
         if (summary) return;
 
-    fprintf(f, "Displays a list of available commands, or help on a specific command.\n");
+    fprintf(f, "Displays a list of available commands, or detailed help on a specific command.\n");
 }
 
 
@@ -445,7 +470,7 @@ int main(int argc, char **argv) {
     argv += optind;
 
     if ((vm = dcpu16_new()) == NULL) {
-        fprintf(stderr, "could not allocate new dcpu instance\n");
+        fprintf(stderr, "could not allocate new dcpu16 instance\n");
         exit(EX_UNAVAILABLE);
     }