2c1387eb6036736d1e5da260dacc647f0a679ee2
[fw/sdcc] / sim / ucsim / cmd.src / set.cc
1 /*
2  * Simulator of microcontrollers (cmd.src/set.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 #include <ctype.h>
31 #include "i_string.h"
32
33 // sim
34 #include "simcl.h"
35 #include "optioncl.h"
36
37 // local
38 #include "setcl.h"
39 #include "cmdutil.h"
40
41
42 /*
43  * Command: set memory
44  *----------------------------------------------------------------------------
45  */
46
47 //int
48 //cl_set_mem_cmd::do_work(class cl_sim *sim,
49 //                      class cl_cmdline *cmdline, class cl_console *con)
50 COMMAND_DO_WORK_UC(cl_set_mem_cmd)
51 {
52   class cl_mem *mem= 0;
53   class cl_cmd_arg *params[4]= { cmdline->param(0),
54                                  cmdline->param(1),
55                                  cmdline->param(2),
56                                  cmdline->param(3) };
57
58   if (cmdline->syntax_match(uc, MEMORY ADDRESS DATALIST)) {
59     mem= params[0]->value.memory;
60     t_addr start= params[1]->value.address;
61     t_mem *array= params[2]->value.data_list.array;
62     int len= params[2]->value.data_list.len;
63     
64     if (len == 0)
65       con->dd_printf("Error: no data\n");
66     else
67       {
68         int i;
69         t_addr addr;
70         for (i= 0, addr= start;
71              i < len && addr <= mem->size;
72              i++, addr++)
73           mem->set(addr, array[i]);
74         uc->check_errors();
75         mem->dump(start, start+len-1, 8, con);
76       }
77   }
78   else
79     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
80   
81   return(DD_FALSE);;
82 }
83
84
85 /*
86  * Command: set bit
87  *----------------------------------------------------------------------------
88  */
89
90 //int
91 //cl_set_bit_cmd::do_work(class cl_sim *sim,
92 //                      class cl_cmdline *cmdline, class cl_console *con)
93 COMMAND_DO_WORK_UC(cl_set_bit_cmd)
94 {
95   class cl_mem *mem;
96   t_addr mem_addr= 0;
97   t_mem bit_mask= 0;
98   class cl_cmd_arg *params[4]= { cmdline->param(0),
99                                  cmdline->param(1),
100                                  cmdline->param(2),
101                                  cmdline->param(3) };
102   
103   if (cmdline->syntax_match(uc, BIT NUMBER)) {
104     mem= params[0]->value.bit.mem;
105     mem_addr= params[0]->value.bit.mem_address;
106     bit_mask= params[0]->value.bit.mask;
107     if (params[1]->value.number)
108       mem->set_bit1(mem_addr, bit_mask);
109     else
110       mem->set_bit0(mem_addr, bit_mask);
111     mem->dump(mem_addr, mem_addr, 1, con);
112   }
113   else
114     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
115
116   return(DD_FALSE);;
117 }
118
119
120 /*
121  * Command: set hw
122  *----------------------------------------------------------------------------
123  */
124
125 COMMAND_DO_WORK_UC(cl_set_hw_cmd)
126 {
127   class cl_hw *hw= 0;
128   class cl_cmd_arg *params[1]= { cmdline->param(0)/*,
129                                  cmdline->param(1),
130                                  cmdline->param(2),
131                                  cmdline->param(3)*/ };
132   
133   if (/*cmdline->syntax_match(uc, HW)*/params[0]->as_hw(uc)) {
134     hw= params[0]->value.hw;
135     //pn= hw->id;
136     //l= params[1]->value.number;
137   }
138   /*else if (cmdline->syntax_match(uc, NUMBER NUMBER)) {
139     pn= params[0]->value.number;
140     l= params[1]->value.number;
141     hw= uc->get_hw(HW_PORT, pn, 0);
142     }*/
143   else
144     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
145   /*if (pn < 0 ||
146       pn > 3)
147     con->dd_printf("Error: wrong port\n");
148     else*/
149     {
150       if (hw)
151         {
152           cmdline->shift();
153           hw->set_cmd(cmdline, con);
154         }
155       else
156         con->dd_printf("Error: no hw\n");
157     }
158   return(DD_FALSE);;
159 }
160
161
162 /*
163  * Command: set option
164  *----------------------------------------------------------------------------
165  */
166
167 //int
168 //cl_set_option_cmd::do_work(class cl_sim *sim,
169 //                         class cl_cmdline *cmdline, class cl_console *con)
170 COMMAND_DO_WORK_APP(cl_set_option_cmd)
171 {
172   char *id= 0, *s= 0;
173   int idx;
174   class cl_cmd_arg *params[4]= { cmdline->param(0),
175                                  cmdline->param(1),
176                                  cmdline->param(2),
177                                  cmdline->param(3) };
178   class cl_option *option= 0;
179
180   if (cmdline->syntax_match(0, STRING STRING STRING)) {
181     id= params[0]->value.string.string;
182     char *cr= params[1]->value.string.string;
183     s= params[2]->value.string.string;
184     int n= app->options->nuof_options(id, cr);
185     if (n > 1)
186       {
187         con->dd_printf("Ambiguous option name, use number instead\n");
188         return(DD_FALSE);
189       }
190     else if (n == 0)
191       ;//con->dd_printf("Named option does not exist\n");
192     else
193       {
194         if ((option= app->options->get_option(id, cr)) == 0)
195           option= app->options->get_option(cr, id);
196       }
197   }
198   else if (cmdline->syntax_match(0/*app->get_uc()*/, NUMBER STRING)) {
199     idx= params[0]->value.number;
200     s= params[1]->value.string.string;
201     option= app->options->get_option(idx);
202   }
203   else if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) {
204     id= params[0]->value.string.string;
205     s= params[1]->value.string.string;
206     int n= app->options->nuof_options(id);
207     if (n > 1)
208       {
209         con->dd_printf("Ambiguous option name, use number instead\n");
210         return(DD_FALSE);
211       }
212     else if (n == 0)
213       ;//con->dd_printf("Named option does not exist\n");
214     else
215       option= app->options->get_option(id);
216   }
217   else
218     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
219   if (!option)
220     {
221       con->dd_printf("Option does not exist\n");
222       return(DD_FALSE);
223     }
224
225   option->set_value(s);
226
227   return(DD_FALSE);;
228 }
229
230
231 /* End of cmd.src/set.cc */