#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, '/');
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_);
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) {
COMMAND_IMPL(quit) {
(void)vm, (void)arg_count, (void)arg_vector;
- VERBOSE_PRINTF("done\n");
+
return -1;
}
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;
int i;
for (i = 1; i < arg_count; i++) {
- addr[i] = str_to_word_(arg_vector[i]);
- if (addr[i] < 0) {
+ addr[i-1] = str_to_word_(arg_vector[i]);
+ if (addr[i-1] < 0) {
fprintf(stderr, "address '%s' is not a valid word: %s\n", arg_vector[i], strerror(errno));
return 0;
}
int i;
for (i = 1; i < arg_count; i++) {
- addr[i] = str_to_word_(arg_vector[i]);
- if (addr[i] < 0) {
+ addr[i-1] = str_to_word_(arg_vector[i]);
+ if (addr[i-1] < 0) {
fprintf(stderr, "address '%s' is not a valid word: %s\n", arg_vector[i], strerror(errno));
return 0;
}
return 0;
}
- for (i = addr[0]; i <= addr[1]; i++)
- dcpu16_disassemble_print(vm, i), printf("\n");
+ for (i = addr[0]; i <= addr[1]; /* */ ) {
+ printf("0x%04x: ", i);
+ i += dcpu16_disassemble_print(vm, i);
+ printf("\n");
+ }
return 0;
}
}
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);
}
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 */
return -1;
}
- VERBOSE_PRINTF("interrupted...\n");
+ printf("interrupted...\n");
return 0;
}
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 */
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 }
};
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");
}
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);
}