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(const 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(class cl_uc *uc)
133 return(get_address(uc, &(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(class cl_uc *uc)
154 value.memory.memory= uc->memory(s_value);
155 value.memory.address_space= 0;
156 value.memory.memchip= 0;
157 if (value.memory.memory)
159 if (value.memory.memory->is_chip())
160 value.memory.memchip=
161 dynamic_cast<class cl_memory_chip *>(value.memory.memory);
162 if (value.memory.memory->is_address_space())
163 value.memory.address_space=
164 dynamic_cast<class cl_address_space *>(value.memory.memory);
166 return(value.memory.memory != 0);
170 cl_cmd_arg::as_hw(class cl_uc *uc)
176 cl_cmd_arg::as_string(void)
178 char *s= get_svalue();
182 value.string.string= proc_escape(s, &value.string.len);
185 value.string.string= strdup(s);
186 value.string.len= strlen(s);
188 return(interpreted_as_string= value.string.string != NULL);
192 cl_cmd_arg::as_bit(class cl_uc *uc)
194 return(get_bit_address(uc,
196 &(value.bit.mem_address),
201 /* Interger number */
203 cl_cmd_int_arg::cl_cmd_int_arg(/*class cl_uc *iuc,*/ long addr):
204 cl_cmd_arg(/*iuc,*/ addr)
208 cl_cmd_int_arg::get_address(class cl_uc *uc, t_addr *addr)
212 bool b= get_ivalue(&iv);
219 cl_cmd_int_arg::get_bit_address(class cl_uc *uc, // input
220 class cl_address_space **mem, // outputs
226 if (!get_address(uc, &bit_addr))
230 *mem= uc->bit2mem(bit_addr, mem_addr, bit_mask);
235 cl_cmd_int_arg::as_string(void)
237 value.string.string= (char*)malloc(100);
238 sprintf(value.string.string, "%ld", i_value);
239 value.string.len= strlen(value.string.string);
240 return(interpreted_as_string= value.string.string != NULL);
246 cl_cmd_sym_arg::cl_cmd_sym_arg(/*class cl_uc *iuc,*/ const char *sym):
247 cl_cmd_arg(/*iuc,*/ sym)
251 cl_cmd_sym_arg::as_string(void)
253 char *s= get_svalue();
256 value.string.string= strdup(s);
257 value.string.len= strlen(s);
258 return(interpreted_as_string= value.string.string != NULL);
262 cl_cmd_sym_arg::get_address(class cl_uc *uc, t_addr *addr)
264 struct name_entry *ne;
266 if ((ne= get_name_entry(uc->sfr_tbl(),
278 cl_cmd_sym_arg::get_bit_address(class cl_uc *uc, // input
279 class cl_address_space **mem, // outputs
283 struct name_entry *ne;
285 ne= get_name_entry(uc->bit_tbl(), get_svalue(), uc);
289 *mem= uc->bit2mem(ne->addr, mem_addr, bit_mask);
294 cl_cmd_sym_arg::as_address(class cl_uc *uc)
296 struct name_entry *ne;
297 //printf("SYM %s as addr?\n",get_svalue());
298 if ((ne= get_name_entry(uc->sfr_tbl(), get_svalue(), uc)) != NULL)
300 value.address= ne->addr;
307 cl_cmd_sym_arg::as_hw(class cl_uc *uc)
312 hw= found= uc->get_hw(get_svalue(), &i);
316 found= uc->get_hw(get_svalue(), &i);
326 cl_cmd_str_arg::cl_cmd_str_arg(/*class cl_uc *iuc,*/ const char *str):
327 cl_cmd_arg(/*iuc,*/ str)
334 cl_cmd_bit_arg::cl_cmd_bit_arg(/*class cl_uc *iuc,*/
335 class cl_cmd_arg *asfr, class cl_cmd_arg *abit):
336 cl_cmd_arg(/*iuc,*/ (long)0)
342 cl_cmd_bit_arg::~cl_cmd_bit_arg(void)
351 cl_cmd_bit_arg::get_address(class cl_uc *uc, t_addr *addr)
354 return(sfr->get_address(uc, addr));
359 cl_cmd_bit_arg::get_bit_address(class cl_uc *uc, // input
360 class cl_address_space **mem, // outputs
366 *mem= uc->address_space(MEM_SFR_ID);
373 !sfr->get_address(uc, mem_addr))
381 if (!bit->get_ivalue(&l) ||
392 cl_cmd_array_arg::cl_cmd_array_arg(/*class cl_uc *iuc,*/
393 class cl_cmd_arg *aname,
394 class cl_cmd_arg *aindex):
395 cl_cmd_arg(/*iuc,*/ (long)0)
401 cl_cmd_array_arg::~cl_cmd_array_arg(void)
410 cl_cmd_array_arg::as_hw(class cl_uc *uc)
417 (n= name_arg->get_svalue()) == NULL ||
418 !index->get_address(uc, &a))
421 value.hw= uc->get_hw(n, a, NULL);
422 return(value.hw != NULL);
428 *----------------------------------------------------------------------------
431 cl_prg_arg::cl_prg_arg(char sn, char *ln, long lv):
435 long_name = ln?strdup(ln):0;
438 cl_prg_arg::cl_prg_arg(char sn, char *ln, char *sv):
442 long_name = ln?strdup(ln):0;
445 cl_prg_arg::cl_prg_arg(char sn, char *ln, double fv):
449 long_name = ln?strdup(ln):0;
452 cl_prg_arg::cl_prg_arg(char sn, char *ln, void *pv):
456 long_name = ln?strdup(ln):0;
459 cl_prg_arg::~cl_prg_arg(void)
468 *----------------------------------------------------------------------------
472 cl_arguments::arg_avail(char nam)
477 for (i= 0; i < count; i++)
479 a= (class cl_prg_arg *)(at(i));
480 if (a->short_name == nam)
487 cl_arguments::arg_avail(char *nam)
492 for (i= 0; i < count; i++)
494 a= (class cl_prg_arg *)(at(i));
496 strcmp(a->long_name, nam) == 0)
503 cl_arguments::get_iarg(char sname, char *lname)
508 for (i= 0; i < count; i++)
510 a= (class cl_prg_arg *)(at(i));
511 if ((sname && a->short_name == sname) ||
512 (lname && a->long_name && strcmp(a->long_name, lname) == 0))
515 if (a->get_ivalue(&iv))
526 cl_arguments::get_sarg(char sname, char *lname)
531 for (i= 0; i < count; i++)
533 a= (class cl_prg_arg *)(at(i));
534 if ((sname && a->short_name == sname) ||
535 (lname && a->long_name && strcmp(a->long_name, lname) == 0))
536 return(a->get_svalue());
543 cl_arguments::get_farg(char sname, char *lname)
548 for (i= 0; i < count; i++)
550 a= (class cl_prg_arg *)(at(i));
551 if ((sname && a->short_name == sname) ||
552 (lname && a->long_name && strcmp(a->long_name, lname) == 0))
553 return(a->get_fvalue());
559 cl_arguments::get_parg(char sname, char *lname)
564 for (i= 0; i < count; i++)
566 a= (class cl_prg_arg *)(at(i));
567 if ((sname && a->short_name == sname) ||
568 (lname && a->long_name && strcmp(a->long_name, lname) == 0))
569 return(a->get_pvalue());