Including missing i_string.h
[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->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->write(addr, &(array[i]));
74         mem->dump(start, start+len-1, 8, con);
75       }
76   }
77   else
78     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
79   
80   return(DD_FALSE);;
81 }
82
83
84 /*
85  * Command: set bit
86  *----------------------------------------------------------------------------
87  */
88
89 //int
90 //cl_set_bit_cmd::do_work(class cl_sim *sim,
91 //                      class cl_cmdline *cmdline, class cl_console *con)
92 COMMAND_DO_WORK_UC(cl_set_bit_cmd)
93 {
94   class cl_mem *mem;
95   t_addr mem_addr= 0;
96   t_mem bit_mask= 0;
97   class cl_cmd_arg *params[4]= { cmdline->param(0),
98                                  cmdline->param(1),
99                                  cmdline->param(2),
100                                  cmdline->param(3) };
101   
102   if (cmdline->syntax_match(uc, BIT NUMBER)) {
103     mem= params[0]->value.bit.mem;
104     mem_addr= params[0]->value.bit.mem_address;
105     bit_mask= params[0]->value.bit.mask;
106     if (params[1]->value.number)
107       mem->set_bit1(mem_addr, bit_mask);
108     else
109       mem->set_bit0(mem_addr, bit_mask);
110     mem->dump(mem_addr, mem_addr, 1, con);
111   }
112   else
113     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
114
115   return(DD_FALSE);;
116 }
117
118
119 /*
120  * Command: set port
121  *----------------------------------------------------------------------------
122  */
123
124 //int
125 //cl_set_port_cmd::do_work(class cl_sim *sim,
126 //                       class cl_cmdline *cmdline, class cl_console *con)
127 COMMAND_DO_WORK_UC(cl_set_port_cmd)
128 {
129   class cl_hw *hw;
130   long l= 0, pn= -1;
131   class cl_cmd_arg *params[4]= { cmdline->param(0),
132                                  cmdline->param(1),
133                                  cmdline->param(2),
134                                  cmdline->param(3) };
135   
136   if (cmdline->syntax_match(uc, HW NUMBER)) {
137     hw= params[0]->value.hw;
138     pn= hw->id;
139     l= params[1]->value.number;
140   }
141   else if (cmdline->syntax_match(uc, NUMBER NUMBER)) {
142     pn= params[0]->value.number;
143     l= params[1]->value.number;
144   }
145   else
146     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
147   if (pn < 0 ||
148       pn > 3)
149     con->printf("Error: wrong port\n");
150   else
151     uc->port_pins[pn]= l;
152   return(DD_FALSE);;
153 }
154
155
156 /*
157  * Command: set option
158  *----------------------------------------------------------------------------
159  */
160
161 //int
162 //cl_set_option_cmd::do_work(class cl_sim *sim,
163 //                         class cl_cmdline *cmdline, class cl_console *con)
164 COMMAND_DO_WORK_UC(cl_set_option_cmd)
165 {
166   char *id= 0, *s= 0;
167   class cl_cmd_arg *params[4]= { cmdline->param(0),
168                                  cmdline->param(1),
169                                  cmdline->param(2),
170                                  cmdline->param(3) };
171   
172   if (cmdline->syntax_match(uc, STRING STRING)) {
173     id= params[0]->value.string.string;
174     s= params[1]->value.string.string;
175   }
176   else
177     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
178   if (!id ||
179       !s)
180     {
181       con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
182       return(DD_FALSE);
183     }
184
185   int i;
186   for (i= 0; i < uc->options->count; i++)
187     {
188       class cl_option *o= (class cl_option *)(uc->options->at(i));
189       if (!strcmp(id, o->id))
190         {
191           o->set_value(s);
192           break;
193         }
194     }
195   return(DD_FALSE);;
196 }
197
198
199 /* End of cmd.src/set.cc */