Correctly comment which bit the beep program uses
[fw/altos] / s51 / s51-parse.c
index ba0d611cb570470817c4ad2cb10184ea683e4166..aba454859b94394e8711b60d76a2b6fc8dc6c687 100644 (file)
 
 #include "s51.h"
 
-struct command_function {
-       char                    *name;
-       char                    *alias;
-       enum command_result     (*func)(FILE *output, int argc, char **argv);
-       char                    *usage;
-       char                    *help;
-};
-
 static struct command_function functions[] = {
        { "help",   "?",  command_help, "help",         "Print this list\n" },
        { "quit",   "q",  command_quit, "[q]uit",       "Quit\n" },
@@ -35,11 +27,13 @@ static struct command_function functions[] = {
                "Dump sprs\n" },
        { "dx",     "dx", command_dx,   "dx <start> <end>",
                "Dump xaddr\n" },
-       { "set",    "t",  command_set,  "se[t] mem <prefix> <start> <end>",
-               "Set mem {xram|rom|iram|sfr} <start> <end>\n"
+       { "set",    "t",  command_set,  "se[t] mem <prefix> <address> <data> ...",
+               "Set mem {xram|rom|iram|sfr}\n"
                "set bit <addr>\n" },
        { "dump",   "d",  command_dump, "[d]ump <prefix> <start> <end>",
                "Dump {xram|rom|iram|sfr} <start> <end>\n" },
+       { "file", "file", command_file, "file <filename>",
+               "Pretend to load executable from <filename>\n" },
        { "pc",     "p",  command_pc, "[p]c [addr]",
                "Get or set pc value\n" },
        { "break",  "b",  command_break,"[b]reak <addr>",
@@ -48,6 +42,8 @@ static struct command_function functions[] = {
                "Clear break point\n" },
        { "run",    "r",  command_run, "[r]un [start] [stop]",
                "Run with optional start and temp breakpoint addresses\n" },
+       { "go",     "g",  command_run, "[g]o [start] [stop]",
+               "Run with optional start and temp breakpoint addresses\n" },
        { "next",   "n",  command_next, "[n]ext",
                "Step over one instruction, past any call\n" },
        { "step",   "s",  command_step, "[s]tep",
@@ -58,10 +54,15 @@ static struct command_function functions[] = {
                "Halt the processor\n" },
        { "reset","res",command_reset,  "[res]et",
                "Reset the CPU\n" },
+       { "status","status",command_status, "status",
+               "Display CC1111 debug status\n" },
+       { "info",   "i",  command_info, "[i]info",
+               "Get information\n" },
+       { "stop",  "stop", command_stop, "stop",
+               "Ignored\n" },
+       { NULL, NULL, NULL, NULL, NULL },
 };
 
-#define NUM_FUNCTIONS (sizeof functions / sizeof functions[0])
-
 #ifndef FALSE
 #define FALSE 0
 #define TRUE 1
@@ -102,17 +103,41 @@ string_to_int(char *s, int *v)
     return TRUE;
 }
 
-static struct command_function *
-command_string_to_function(char *name)
+struct command_function *
+command_string_to_function(struct command_function *functions, char *name)
 {
        int i;
-       for (i = 0; i < NUM_FUNCTIONS; i++)
+       for (i = 0; functions[i].name; i++)
                if (!strcmp(name, functions[i].name) ||
                    !strcmp(name, functions[i].alias))
                        return &functions[i];
        return NULL;
 }    
 
+enum command_result
+command_function_help(struct command_function *functions, int argc, char **argv)
+{
+       int i;
+       struct command_function *func;
+
+       if (argc == 1) {
+               for (i = 0; functions[i].name; i++)
+                       s51_printf("%-10s%s\n", functions[i].name,
+                              functions[i].usage);
+       } else {
+               for (i = 1; i < argc; i++) {
+                       func = command_string_to_function(functions, argv[i]);
+                       if (!func) {
+                               s51_printf("%-10s unknown command\n", argv[i]);
+                               return command_syntax;
+                       }
+                       s51_printf("%-10s %s\n%s", func->name,
+                              func->usage, func->help);
+               }
+       }
+       return command_debug;
+}
+
 static int
 command_split_into_words(char *line, char **argv)
 {
@@ -147,40 +172,22 @@ command_split_into_words(char *line, char **argv)
 }
 
 enum command_result
-command_help(FILE *output, int argc, char **argv)
+command_help(int argc, char **argv)
 {
-       int i;
-       struct command_function *func;
-
-       if (argc == 1) {
-               for (i = 0; i < NUM_FUNCTIONS; i++)
-                       fprintf(output, "%-10s%s\n", functions[i].name,
-                              functions[i].usage);
-       } else {
-               for (i = 1; i < argc; i++) {
-                       func = command_string_to_function(argv[i]);
-                       if (!func) {
-                               fprintf(output, "%-10s unknown command\n", argv[i]);
-                               return command_syntax;
-                       }
-                       fprintf(output, "%-10s %s\n%s", func->name,
-                              func->usage, func->help);
-               }
-       }
-       return command_debug;
+       return command_function_help(functions, argc, argv);
 }
     
-static void
-command_syntax_error(FILE *output, int argc, char **argv)
+void
+command_syntax_error(int argc, char **argv)
 {
-       fprintf(output, "Syntax error in:");
+       s51_printf("Syntax error in:");
        while (*argv)
-               fprintf(output, " %s", *argv++);
-       fprintf(output, "\n");
+               s51_printf(" %s", *argv++);
+       s51_printf("\n");
 }
 
 void
-command_read (FILE *input, FILE *output)
+command_read (void)
 {
        int argc;
        char line[1024];
@@ -194,31 +201,34 @@ command_read (FILE *input, FILE *output)
                exit(1);
        }
        ccdbg_debug_mode(s51_dbg);
-       fprintf(output, "Welcome to the non-simulated processor\n");
+       ccdbg_halt(s51_dbg);
+       s51_printf("Welcome to the non-simulated processor\n");
        for (;;) {
-               if (s51_prompt)
-                       fprintf(output, "%s", s51_prompt);
-               else
-                       putc('\0', output);
-               fflush(output);
-               if (!fgets (line, sizeof line, input))
+               if (s51_read_line (line, sizeof line) == 0)
                        break;
+               s51_interrupted = 0;
                argc = command_split_into_words(line, argv);
                if (argc > 0) {
-                       func = command_string_to_function(argv[0]);
+                       func = command_string_to_function(functions, argv[0]);
                        if (!func)
-                               command_syntax_error(output, argc, argv);
+                               command_syntax_error(argc, argv);
                        else
                        {
-                               result = (*func->func)(output, argc, argv);
+                               result = (*func->func)(argc, argv);
+                               if (s51_interrupted)
+                                       result = command_interrupt;
                                switch (result) {
                                case command_syntax:
-                                       command_syntax_error(output, argc, argv);
+                                       command_syntax_error(argc, argv);
                                        break;
                                case command_error:
-                                       fprintf(output, "Error\n");
+                                       s51_printf("Error\n");
+                                       break;
+                               case command_success:
                                        break;
-                               case command_proceed:
+                               case command_interrupt:
+                                       ccdbg_halt(s51_dbg);
+                                       s51_printf("Interrupted\n");
                                        break;
                                default:
                                        break;
@@ -227,6 +237,6 @@ command_read (FILE *input, FILE *output)
                }
        }
        ccdbg_close(s51_dbg);
-       fprintf(output, "...\n");
+       s51_printf("...\n");
 }