2 * Simulator of microcontrollers (arg.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
51 cl_arg::cl_arg(long lv):
58 cl_arg::cl_arg(char *sv):
61 s_value= sv?strdup(sv):0;
64 cl_arg::cl_arg(double fv):
71 cl_arg::cl_arg(void *pv):
86 * Getting value of the argument
90 cl_arg::get_ivalue(long *value)
98 cl_arg::get_svalue(void)
104 cl_arg::get_fvalue(void)
110 cl_arg::get_pvalue(void)
118 *----------------------------------------------------------------------------
121 cl_cmd_arg::~cl_cmd_arg(void)
123 if (interpreted_as_string)
125 if (value.string.string)
126 free(value.string.string);
131 cl_cmd_arg::as_address(void)
133 return(get_address(&(value.address)));
137 cl_cmd_arg::as_number(void)
139 return(get_ivalue(&(value.number)));
143 cl_cmd_arg::as_data(void)
146 bool ret= get_ivalue(&l);
152 cl_cmd_arg::as_memory(void)
154 value.memory= uc->mem(s_value);
155 return(value.memory != 0);
159 cl_cmd_arg::as_hw(class cl_uc *uc)
165 cl_cmd_arg::as_string(void)
167 char *s= get_svalue();
171 value.string.string= proc_escape(s, &value.string.len);
174 value.string.string= strdup(s);
175 value.string.len= strlen(s);
177 return(interpreted_as_string= value.string.string != NULL);
181 cl_cmd_arg::as_bit(class cl_uc *uc)
183 return(get_bit_address(uc,
185 &(value.bit.mem_address),
190 /* Interger number */
192 cl_cmd_int_arg::cl_cmd_int_arg(class cl_uc *iuc, long addr):
193 cl_cmd_arg(iuc, addr)
197 cl_cmd_int_arg::get_address(t_addr *addr)
201 bool b= get_ivalue(&iv);
208 cl_cmd_int_arg::get_bit_address(class cl_uc *uc, // input
209 class cl_mem **mem, // outputs
215 if (!get_address(&bit_addr))
217 return(uc->extract_bit_address(bit_addr, mem, mem_addr, bit_mask));
221 cl_cmd_int_arg::as_string(void)
223 value.string.string= (char*)malloc(100);
224 sprintf(value.string.string, "%ld", i_value);
225 value.string.len= strlen(value.string.string);
226 return(interpreted_as_string= value.string.string != NULL);
232 cl_cmd_sym_arg::cl_cmd_sym_arg(class cl_uc *iuc, char *sym):
237 cl_cmd_sym_arg::as_string(void)
239 char *s= get_svalue();
242 value.string.string= strdup(s);
243 value.string.len= strlen(s);
244 return(interpreted_as_string= value.string.string != NULL);
248 cl_cmd_sym_arg::get_address(t_addr *addr)
250 struct name_entry *ne;
252 if ((ne= get_name_entry(uc->sfr_tbl(),
264 cl_cmd_sym_arg::get_bit_address(class cl_uc *uc, // input
265 class cl_mem **mem, // outputs
269 struct name_entry *ne;
271 if ((ne= get_name_entry(uc->bit_tbl(),
275 return(uc->extract_bit_address(ne->addr, mem, mem_addr, bit_mask));
279 cl_cmd_sym_arg::as_address(void)
281 struct name_entry *ne;
282 //printf("SYM %s as addr?\n",get_svalue());
283 if ((ne= get_name_entry(uc->sfr_tbl(), get_svalue(), uc)) != NULL)
285 value.address= ne->addr;
292 cl_cmd_sym_arg::as_hw(class cl_uc *uc)
297 hw= found= uc->get_hw(get_svalue(), &i);
301 found= uc->get_hw(get_svalue(), &i);
311 cl_cmd_str_arg::cl_cmd_str_arg(class cl_uc *iuc, char *str):
318 cl_cmd_bit_arg::cl_cmd_bit_arg(class cl_uc *iuc,
319 class cl_cmd_arg *asfr, class cl_cmd_arg *abit):
320 cl_cmd_arg(iuc, (long)0)
326 cl_cmd_bit_arg::~cl_cmd_bit_arg(void)
335 cl_cmd_bit_arg::get_address(t_addr *addr)
338 return(sfr->get_address(addr));
343 cl_cmd_bit_arg::get_bit_address(class cl_uc *uc, // input
344 class cl_mem **mem, // outputs
350 *mem= uc->mem(MEM_SFR);
356 !sfr->get_address(mem_addr))
368 if (!bit->get_ivalue(&l) ||
381 cl_cmd_array_arg::cl_cmd_array_arg(class cl_uc *iuc,
382 class cl_cmd_arg *aname,
383 class cl_cmd_arg *aindex):
384 cl_cmd_arg(iuc, (long)0)
390 cl_cmd_array_arg::~cl_cmd_array_arg(void)
399 cl_cmd_array_arg::as_hw(class cl_uc *uc)
406 (n= name->get_svalue()) == NULL ||
407 !index->get_address(&a))
410 value.hw= uc->get_hw(n, a, NULL);
411 return(value.hw != NULL);
417 *----------------------------------------------------------------------------
420 cl_prg_arg::cl_prg_arg(char sn, char *ln, long lv):
424 long_name = ln?strdup(ln):0;
427 cl_prg_arg::cl_prg_arg(char sn, char *ln, char *sv):
431 long_name = ln?strdup(ln):0;
434 cl_prg_arg::cl_prg_arg(char sn, char *ln, double fv):
438 long_name = ln?strdup(ln):0;
441 cl_prg_arg::cl_prg_arg(char sn, char *ln, void *pv):
445 long_name = ln?strdup(ln):0;
448 cl_prg_arg::~cl_prg_arg(void)