Version 0.3.2-pre1
[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
32 // sim
33 #include "simcl.h"
34 #include "optioncl.h"
35
36 // local
37 #include "setcl.h"
38 #include "cmdutil.h"
39
40
41 /*
42  * Command: set memory
43  *----------------------------------------------------------------------------
44  */
45
46 //int
47 //cl_set_mem_cmd::do_work(class cl_sim *sim,
48 //                      class cl_cmdline *cmdline, class cl_console *con)
49 COMMAND_DO_WORK_UC(cl_set_mem_cmd)
50 {
51   class cl_mem *mem= 0;
52   class cl_cmd_arg *params[4]= { cmdline->param(0),
53                                  cmdline->param(1),
54                                  cmdline->param(2),
55                                  cmdline->param(3) };
56
57   if (cmdline->syntax_match(uc, MEMORY ADDRESS DATALIST)) {
58     mem= params[0]->value.memory;
59     t_addr start= params[1]->value.address;
60     t_mem *array= params[2]->value.data_list.array;
61     int len= params[2]->value.data_list.len;
62     
63     if (len == 0)
64       con->printf("Error: no data\n");
65     else
66       {
67         int i;
68         t_addr addr;
69         for (i= 0, addr= start;
70              i < len && addr < mem->size;
71              i++, addr++)
72           mem->write(addr, &(array[i]));
73         mem->dump(start, start+len-1, 8, con);
74       }
75   }
76   else
77     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
78   
79   return(DD_FALSE);;
80 }
81
82
83 /*
84  * Command: set bit
85  *----------------------------------------------------------------------------
86  */
87
88 //int
89 //cl_set_bit_cmd::do_work(class cl_sim *sim,
90 //                      class cl_cmdline *cmdline, class cl_console *con)
91 COMMAND_DO_WORK_UC(cl_set_bit_cmd)
92 {
93   class cl_mem *mem;
94   t_addr mem_addr= 0;
95   t_mem bit_mask= 0;
96   class cl_cmd_arg *params[4]= { cmdline->param(0),
97                                  cmdline->param(1),
98                                  cmdline->param(2),
99                                  cmdline->param(3) };
100   
101   if (cmdline->syntax_match(uc, BIT NUMBER)) {
102     mem= params[0]->value.bit.mem;
103     mem_addr= params[0]->value.bit.mem_address;
104     bit_mask= params[0]->value.bit.mask;
105     if (params[1]->value.number)
106       mem->set_bit1(mem_addr, bit_mask);
107     else
108       mem->set_bit0(mem_addr, bit_mask);
109     mem->dump(mem_addr, mem_addr, 1, con);
110   }
111   else
112     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
113
114   return(DD_FALSE);;
115 }
116
117
118 /*
119  * Command: set port
120  *----------------------------------------------------------------------------
121  */
122
123 //int
124 //cl_set_port_cmd::do_work(class cl_sim *sim,
125 //                       class cl_cmdline *cmdline, class cl_console *con)
126 COMMAND_DO_WORK_UC(cl_set_port_cmd)
127 {
128   class cl_hw *hw;
129   long l= 0, pn= -1;
130   class cl_cmd_arg *params[4]= { cmdline->param(0),
131                                  cmdline->param(1),
132                                  cmdline->param(2),
133                                  cmdline->param(3) };
134   
135   if (cmdline->syntax_match(uc, HW NUMBER)) {
136     hw= params[0]->value.hw;
137     pn= hw->id;
138     l= params[1]->value.number;
139   }
140   else if (cmdline->syntax_match(uc, NUMBER NUMBER)) {
141     pn= params[0]->value.number;
142     l= params[1]->value.number;
143   }
144   else
145     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
146   if (pn < 0 ||
147       pn > 3)
148     con->printf("Error: wrong port\n");
149   else
150     uc->port_pins[pn]= l;
151   return(DD_FALSE);;
152 }
153
154
155 /*
156  * Command: set option
157  *----------------------------------------------------------------------------
158  */
159
160 //int
161 //cl_set_option_cmd::do_work(class cl_sim *sim,
162 //                         class cl_cmdline *cmdline, class cl_console *con)
163 COMMAND_DO_WORK_UC(cl_set_option_cmd)
164 {
165   char *id= 0, *s= 0;
166   class cl_cmd_arg *params[4]= { cmdline->param(0),
167                                  cmdline->param(1),
168                                  cmdline->param(2),
169                                  cmdline->param(3) };
170   
171   if (cmdline->syntax_match(uc, STRING STRING)) {
172     id= params[0]->value.string.string;
173     s= params[1]->value.string.string;
174   }
175   else
176     con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
177   if (!id ||
178       !s)
179     {
180       con->printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
181       return(DD_FALSE);
182     }
183
184   int i;
185   for (i= 0; i < uc->options->count; i++)
186     {
187       class cl_option *o= (class cl_option *)(uc->options->at(i));
188       if (!strcmp(id, o->id))
189         {
190           o->set_value(s);
191           break;
192         }
193     }
194   return(DD_FALSE);;
195 }
196
197
198 /* End of cmd.src/set.cc */