projects
/
dcpu16
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
generalized list handling of instructions and labels
[dcpu16]
/
vm-dcpu16.c
diff --git
a/vm-dcpu16.c
b/vm-dcpu16.c
index 522682a6732e871ff50157323a227b85e619e76e..b59c253ee0700fa561a55ddb221650bb9d9f3632 100644
(file)
--- a/
vm-dcpu16.c
+++ b/
vm-dcpu16.c
@@
-43,7
+43,8
@@
void sigint_handler_(int sig) {
#define VERBOSE_PRINTF(...) do { if (opt_.verbose) printf(__VA_ARGS__); } while (0)
#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, '/');
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"
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_);
"\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;
}
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;
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) {
f = fopen(filename, "rb");
if (f == NULL) {
@@
-185,7
+190,7
@@
struct command_ {
COMMAND_IMPL(quit) {
(void)vm, (void)arg_count, (void)arg_vector;
COMMAND_IMPL(quit) {
(void)vm, (void)arg_count, (void)arg_vector;
- VERBOSE_PRINTF("done\n");
+
return -1;
}
COMMAND_HELP(quit) {
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;
COMMAND_IMPL(load) {
int addr = 0;
@@
-230,8
+250,8
@@
COMMAND_IMPL(dump) {
int i;
for (i = 1; i < arg_count; i++) {
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;
}
fprintf(stderr, "address '%s' is not a valid word: %s\n", arg_vector[i], strerror(errno));
return 0;
}
@@
-261,8
+281,8
@@
COMMAND_IMPL(disassemble) {
int i;
for (i = 1; i < arg_count; i++) {
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;
}
fprintf(stderr, "address '%s' is not a valid word: %s\n", arg_vector[i], strerror(errno));
return 0;
}
@@
-275,8
+295,11
@@
COMMAND_IMPL(disassemble) {
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;
}
return 0;
}
@@
-308,12
+331,11
@@
COMMAND_IMPL(step) {
}
while (count--) {
}
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);
dcpu16_step(vm);
- if (opt_.verbose)
+ if (
count > 1 &&
opt_.verbose)
dcpu16_state_print(vm);
}
dcpu16_state_print(vm);
}
@@
-341,8
+363,12
@@
COMMAND_IMPL(run) {
while(running_) {
dcpu16_step(vm);
while(running_) {
dcpu16_step(vm);
- if (opt_.verbose)
+ if (opt_.verbose
> 1
)
dcpu16_state_print(vm);
dcpu16_state_print(vm);
+ else if (opt_.verbose) {
+ dcpu16_disassemble_print(vm, vm->pc);
+ printf("\n");
+ }
}
/* restore the old interrupt signal handler */
}
/* restore the old interrupt signal handler */
@@
-351,7
+377,7
@@
COMMAND_IMPL(run) {
return -1;
}
return -1;
}
-
VERBOSE_PRINTF
("interrupted...\n");
+
printf
("interrupted...\n");
return 0;
}
return 0;
}
@@
-359,7
+385,8
@@
COMMAND_HELP(run) {
fprintf(f, "\trun\n");
if (summary) return;
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 */
}
/* gather all these together into a searchable table */
@@
-376,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(disassemble, 0, 2),
COMMAND_ENTRY(step, 0, 1),
COMMAND_ENTRY(run, 0, 0),
+ COMMAND_ENTRY(reset, 0, 0),
{ NULL, 0, 0, NULL, NULL }
};
{ NULL, 0, 0, NULL, NULL }
};
@@
-404,7
+432,7
@@
COMMAND_HELP(help) {
fprintf(f, "\thelp [command]\n");
if (summary) return;
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");
}
}
@@
-442,7
+470,7
@@
int main(int argc, char **argv) {
argv += optind;
if ((vm = dcpu16_new()) == NULL) {
argv += optind;
if ((vm = dcpu16_new()) == NULL) {
- fprintf(stderr, "could not allocate new dcpu instance\n");
+ fprintf(stderr, "could not allocate new dcpu
16
instance\n");
exit(EX_UNAVAILABLE);
}
exit(EX_UNAVAILABLE);
}