summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mixutils/mixvm_command.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/mixutils/mixvm_command.c b/mixutils/mixvm_command.c
index 4014ede..53d98e0 100644
--- a/mixutils/mixvm_command.c
+++ b/mixutils/mixvm_command.c
@@ -62,6 +62,7 @@ DEC_FUN (cabp_);
DEC_FUN (compile_);
DEC_FUN (edit_);
DEC_FUN (weval_);
+DEC_FUN (w2d_);
DEC_FUN (quit_);
/* A structure which contains information on the commands this program
@@ -97,8 +98,7 @@ COMMAND commands[] = {
{ "sover", cmd_sover_, N_("Set overflow flag value"), "sover T | F" },
{ "smem", cmd_smem_, N_("Set memory contents in given address"),
"smem ADDRESS VALUE" },
- { "ssym", cmd_ssym_, N_("Set the value of an existing of newly defined symbol"),
- "ssym SYMBOL WEXPR" },
+ { "ssym", cmd_ssym_, N_("Set a symbol\'s value"), "ssym SYMBOL WEXPR" },
{ "sbp", cmd_sbp_, N_("Set break point at given line"), "sbp LINENO" },
{ "cbp", cmd_cbp_, N_("Clear break point at given line"), "cbp LINENO" },
{ "sbpa", cmd_sbpa_, N_("Set break point at given address"),
@@ -109,6 +109,8 @@ COMMAND commands[] = {
{ "compile", cmd_compile_, N_("Compile a source file"), "compile FILENAME"},
{ "edit", cmd_edit_, N_("Edit a source file"), "edit FILENAME"},
{ "weval", cmd_weval_, N_("Evaluate a given W-expres sion"), "weval WEXPR"},
+ { "w2d", cmd_w2d_, N_("Convert a MIX word to its decimal value"),
+ "w2d WORD" },
{ "quit", cmd_quit_, N_("Quit the program"), "quit" },
{ (char *)NULL, (Function *)NULL, (char *)NULL }
};
@@ -880,6 +882,51 @@ cmd_weval_ (char *arg)
return TRUE;
}
+static int
+cmd_w2d_ (char *arg)
+{
+ if ( strlen (arg) == 0 )
+ return cmd_help_ ("w2d");
+ else
+ {
+ gchar *cp = g_strdup (arg), *a = cp;
+ mix_byte_t bytes[5] = {0, 0, 0, 0, 0};
+ gchar *b;
+ guint k = 0;
+ gboolean is_n = (a[0] == '-'), success = TRUE;
+ if (a[0] == '+' || a[0] == '-') ++a;
+ b = strtok (a, " \t");
+ while (b != NULL && k < 5)
+ {
+ if (strlen (b) != 2 || !isdigit(b[0]) || !isdigit(b[1]))
+ {
+ fprintf (stderr, _("Incorrect byte specification: %s\n"), b);
+ success = FALSE;
+ b = NULL;
+ }
+ else
+ {
+ bytes[k++] = mix_byte_new (atoi (b));
+ b = strtok (NULL, " \t");
+ }
+ }
+ if (success)
+ {
+ if (strtok (NULL, "\t") != NULL)
+ fprintf (stderr, _("The expression %s does not fit in a word\n"),
+ arg);
+ else
+ {
+ mix_word_t w = mix_bytes_to_word (bytes, k);
+ fprintf (stdout, "%s%ld\n", is_n? "-":"+",
+ mix_word_magnitude (w));
+ }
+ }
+ g_free (cp);
+ }
+
+ return TRUE;
+}
/* external interface */