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