* sim/ucsim/cmd.src/newcmdposix.cc, sim/ucsim/cmd.src/newcmdposixcl.h,
[fw/sdcc] / sim / ucsim / cmd.src / set.cc
index a00d1b9f6dc5b7592916cb8895eff6b51d970f1e..dc5cbb762e9d1fc188498192d4b69df0a3da2ad5 100644 (file)
@@ -7,27 +7,33 @@
  *
  */
 
-/* This file is part of microcontroller simulator: ucsim.
-
-UCSIM is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-UCSIM is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with UCSIM; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+/*
+  This file is part of microcontroller simulator: ucsim.
+
+  UCSIM is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  UCSIM is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with UCSIM; see the file COPYING.  If not, write to the Free
+  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+  02111-1307, USA.
+*/
 /*@1@*/
 
 #include "ddconfig.h"
 
 #include <ctype.h>
+#include "i_string.h"
+
+// prj
+#include "errorcl.h"
 
 // sim
 #include "simcl.h"
@@ -43,37 +49,42 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  *----------------------------------------------------------------------------
  */
 
-int
-cl_set_mem_cmd::do_work(class cl_sim *sim,
-                       class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_mem_cmd::do_work(class cl_sim *sim,
+//                      class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_UC(cl_set_mem_cmd)
 {
-  class cl_mem *mem= 0;
+  class cl_memory *mem= 0;
   class cl_cmd_arg *params[4]= { cmdline->param(0),
-                                cmdline->param(1),
-                                cmdline->param(2),
-                                cmdline->param(3) };
+                                 cmdline->param(1),
+                                 cmdline->param(2),
+                                 cmdline->param(3) };
 
-  if (cmdline->syntax_match(sim, MEMORY ADDRESS DATALIST)) {
-    mem= params[0]->value.memory;
+  if (cmdline->syntax_match(uc, MEMORY ADDRESS DATALIST)) {
+    mem= params[0]->value.memory.memory;
     t_addr start= params[1]->value.address;
     t_mem *array= params[2]->value.data_list.array;
     int len= params[2]->value.data_list.len;
     
     if (len == 0)
-      con->printf("Error: no data\n");
+      con->dd_printf("Error: no data\n");
+    else if (start < mem->get_start_address())
+      con->dd_printf("Start address less then 0x%"_A_"x\n",
+                     mem->get_start_address());
     else
       {
-       int i;
-       t_addr addr;
-       for (i= 0, addr= start;
-            i < len && addr < mem->size;
-            i++, addr++)
-         mem->write(addr, &(array[i]));
-       mem->dump(start, start+len-1, 8, con);
+        int i;
+        t_addr addr;
+        for (i= 0, addr= start;
+             i < len && mem->valid_address(addr);
+             i++, addr++)
+          mem->write(addr, array[i]);
+        uc->check_errors();
+        mem->dump(start, start+len-1, 8, con);
       }
   }
   else
-    con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+    con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
   
   return(DD_FALSE);;
 }
@@ -84,19 +95,20 @@ cl_set_mem_cmd::do_work(class cl_sim *sim,
  *----------------------------------------------------------------------------
  */
 
-int
-cl_set_bit_cmd::do_work(class cl_sim *sim,
-                       class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_bit_cmd::do_work(class cl_sim *sim,
+//                      class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_UC(cl_set_bit_cmd)
 {
-  class cl_mem *mem;
+  class cl_memory *mem;
   t_addr mem_addr= 0;
   t_mem bit_mask= 0;
   class cl_cmd_arg *params[4]= { cmdline->param(0),
-                                cmdline->param(1),
-                                cmdline->param(2),
-                                cmdline->param(3) };
+                                 cmdline->param(1),
+                                 cmdline->param(2),
+                                 cmdline->param(3) };
   
-  if (cmdline->syntax_match(sim, BIT NUMBER)) {
+  if (cmdline->syntax_match(uc, BIT NUMBER)) {
     mem= params[0]->value.bit.mem;
     mem_addr= params[0]->value.bit.mem_address;
     bit_mask= params[0]->value.bit.mask;
@@ -107,44 +119,50 @@ cl_set_bit_cmd::do_work(class cl_sim *sim,
     mem->dump(mem_addr, mem_addr, 1, con);
   }
   else
-    con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+    con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
 
   return(DD_FALSE);;
 }
 
 
 /*
- * Command: set port
+ * Command: set hw
  *----------------------------------------------------------------------------
  */
 
-int
-cl_set_port_cmd::do_work(class cl_sim *sim,
-                        class cl_cmdline *cmdline, class cl_console *con)
+COMMAND_DO_WORK_UC(cl_set_hw_cmd)
 {
-  class cl_hw *hw;
-  long l= 0, pn= -1;
-  class cl_cmd_arg *params[4]= { cmdline->param(0),
-                                cmdline->param(1),
-                                cmdline->param(2),
-                                cmdline->param(3) };
+  class cl_hw *hw= 0;
+  class cl_cmd_arg *params[1]= { cmdline->param(0)/*,
+                                 cmdline->param(1),
+                                 cmdline->param(2),
+                                 cmdline->param(3)*/ };
   
-  if (cmdline->syntax_match(sim, HW NUMBER)) {
+  if (params[0] && /*cmdline->syntax_match(uc, HW)*/params[0]->as_hw(uc)) {
     hw= params[0]->value.hw;
-    pn= hw->id;
-    l= params[1]->value.number;
+    //pn= hw->id;
+    //l= params[1]->value.number;
   }
-  else if (cmdline->syntax_match(sim, NUMBER NUMBER)) {
+  /*else if (cmdline->syntax_match(uc, NUMBER NUMBER)) {
     pn= params[0]->value.number;
     l= params[1]->value.number;
-  }
+    hw= uc->get_hw(HW_PORT, pn, 0);
+    }*/
   else
-    con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
-  if (pn < 0 ||
+    con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+  /*if (pn < 0 ||
       pn > 3)
-    con->printf("Error: wrong port\n");
-  else
-    sim->uc->port_pins[pn]= l;
+    con->dd_printf("Error: wrong port\n");
+    else*/
+    {
+      if (hw)
+        {
+          cmdline->shift();
+          hw->set_cmd(cmdline, con);
+        }
+      else
+        con->dd_printf("Error: no hw\n");
+    }
   return(DD_FALSE);;
 }
 
@@ -154,40 +172,124 @@ cl_set_port_cmd::do_work(class cl_sim *sim,
  *----------------------------------------------------------------------------
  */
 
-int
-cl_set_option_cmd::do_work(class cl_sim *sim,
-                          class cl_cmdline *cmdline, class cl_console *con)
+//int
+//cl_set_option_cmd::do_work(class cl_sim *sim,
+//                         class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_APP(cl_set_option_cmd)
 {
   char *id= 0, *s= 0;
+  int idx;
   class cl_cmd_arg *params[4]= { cmdline->param(0),
-                                cmdline->param(1),
-                                cmdline->param(2),
-                                cmdline->param(3) };
-  
-  if (cmdline->syntax_match(sim, STRING STRING)) {
+                                 cmdline->param(1),
+                                 cmdline->param(2),
+                                 cmdline->param(3) };
+  class cl_option *option= 0;
+
+  if (cmdline->syntax_match(0/*app->get_uc()*/, NUMBER STRING)) {
+    idx= params[0]->value.number;
+    s= params[1]->value.string.string;
+    option= app->options->get_option(idx);
+  }
+  else if (cmdline->syntax_match(0, STRING STRING STRING)) {
+    id= params[0]->value.string.string;
+    char *cr= params[1]->value.string.string;
+    s= params[2]->value.string.string;
+    int n= app->options->nuof_options(id, cr);
+    if (n > 1)
+      {
+        con->dd_printf("Ambiguous option name, use number instead\n");
+        return(DD_FALSE);
+      }
+    else if (n == 0)
+      ;//con->dd_printf("Named option does not exist\n");
+    else
+      {
+        if ((option= app->options->get_option(id, cr)) == 0)
+          option= app->options->get_option(cr, id);
+      }
+  }
+  else if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) {
     id= params[0]->value.string.string;
     s= params[1]->value.string.string;
+    int n= app->options->nuof_options(id);
+    if (n > 1)
+      {
+        con->dd_printf("Ambiguous option name, use number instead\n");
+        return(DD_FALSE);
+      }
+    else if (n == 0)
+      ;//con->dd_printf("Named option does not exist\n");
+    else
+      option= app->options->get_option(id);
   }
   else
-    con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
-  if (!id ||
-      !s)
+    con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+  if (!option)
     {
-      con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+      con->dd_printf("Option does not exist\n");
       return(DD_FALSE);
     }
 
-  int i;
-  for (i= 0; i < sim->uc->options->count; i++)
+  option->set_value(s);
+
+  return(DD_FALSE);
+}
+
+
+/*
+ * Command: set error
+ *----------------------------------------------------------------------------
+ */
+
+//int
+//cl_set_option_cmd::do_work(class cl_sim *sim,
+//                         class cl_cmdline *cmdline, class cl_console_base *con)
+COMMAND_DO_WORK_APP(cl_set_error_cmd)
+{
+  class cl_cmd_arg *params[4]= { cmdline->param(0),
+                                 cmdline->param(1),
+                                 cmdline->param(2),
+                                 cmdline->param(3) };
+  char *error_name= NIL, *value= NIL;
+
+  if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) {
+    error_name= params[0]->value.string.string;
+    value= params[1]->value.string.string;
+  }
+  else
+    con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+
+  class cl_list *registered_errors = cl_error_registry::get_list();
+  if (error_name &&
+      value &&
+      registered_errors)
     {
-      class cl_option *o= (class cl_option *)(sim->uc->options->at(i));
-      if (!strcmp(id, o->id))
-       {
-         o->set_value(s);
-         break;
-       }
+      int i;
+      for (i= 0; i < registered_errors->count; i++)
+        {
+          class cl_error_class *e=
+            dynamic_cast<class cl_error_class *>(registered_errors->object_at(i));
+          if (e->is_inamed(error_name))
+            {
+              if (strchr("uU-?", *value) != NULL)
+                e->set_on(ERROR_PARENT);
+              else if (strchr("1tTyY", *value) != NULL ||
+                       (strlen(value) > 1 &&
+                        strchr("nN", value[2]) != NULL))
+                e->set_on(ERROR_ON);
+              else if (strchr("0fFnN", *value) != NULL ||
+                       (strlen(value) > 1 &&
+                        strchr("fF", value[2]) != NULL))
+                e->set_on(ERROR_OFF);
+              else
+                con->dd_printf("Bad value (%s)\n", value);
+              return(DD_FALSE);
+            }
+        }
     }
-  return(DD_FALSE);;
+  con->dd_printf("Error %s not found\n", error_name);
+
+  return(DD_FALSE);
 }