b7e48ae4998d2c9eaea62ba37e59677241fbd1f6
[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_UC(cl_set_option_cmd)
171 {
172   char *id= 0, *s= 0;
173   class cl_cmd_arg *params[4]= { cmdline->param(0),
174                                  cmdline->param(1),
175                                  cmdline->param(2),
176                                  cmdline->param(3) };
177   
178   if (cmdline->syntax_match(uc, STRING STRING)) {
179     id= params[0]->value.string.string;
180     s= params[1]->value.string.string;
181   }
182   else
183     con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
184   if (!id ||
185       !s)
186     {
187       con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
188       return(DD_FALSE);
189     }
190
191   int i;
192   for (i= 0; i < uc->options->count; i++)
193     {
194       class cl_option *o= (class cl_option *)(uc->options->at(i));
195       if (!strcmp(id, o->id))
196         {
197           o->set_value(s);
198           break;
199         }
200     }
201   return(DD_FALSE);;
202 }
203
204
205 /* End of cmd.src/set.cc */