2 * Simulator of microcontrollers (arg.cc)
4 * Copyright (C) 1999 Drotos Daniel
6 * To contact author send email to dr.dkdb@gmail.com
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
28 //#include "ddconfig.h"
33 //#include "i_string.h"
42 //#include "cmdutil.h"
52 cl_arg::cl_arg(long lv
):
59 cl_arg::cl_arg(const char *sv
):
62 s_value
= sv
?strdup(sv
):0;
65 cl_arg::cl_arg(double fv
):
72 cl_arg::cl_arg(void *pv
):
87 * Getting value of the argument
91 cl_arg::get_ivalue(long *value
)
99 cl_arg::get_svalue(void)
105 cl_arg::get_fvalue(void)
111 cl_arg::get_pvalue(void)
119 *----------------------------------------------------------------------------
122 cl_cmd_arg::~cl_cmd_arg(void)
124 if (interpreted_as_string
)
126 if (value
.string
.string
)
127 free(value
.string
.string
);
132 cl_cmd_arg::init(void)
138 cl_cmd_arg::as_address(class cl_uc
*uc
)
140 return(get_address(uc
, &(value
.address
)));
144 cl_cmd_arg::as_number(void)
146 return(get_ivalue(&(value
.number
)));
150 cl_cmd_arg::as_data(void)
153 bool ret
= get_ivalue(&l
);
159 cl_cmd_arg::as_memory(class cl_uc
*uc
)
161 value
.memory
.memory
= uc
->memory(get_svalue());
162 value
.memory
.address_space
= 0;
163 value
.memory
.memchip
= 0;
164 if (value
.memory
.memory
)
166 if (value
.memory
.memory
->is_chip())
167 value
.memory
.memchip
=
168 (class cl_memory_chip
*)(value
.memory
.memory
);
169 if (value
.memory
.memory
->is_address_space())
170 value
.memory
.address_space
=
171 (class cl_address_space
*)(value
.memory
.memory
);
173 return(value
.memory
.memory
!= 0);
177 cl_cmd_arg::as_hw(class cl_uc
*uc
)
183 cl_cmd_arg::as_cell(class cl_uc
*uc
)
189 cl_cmd_arg::as_string(void)
191 char *s
= get_svalue();
195 value
.string
.string
= proc_escape(s
, &value
.string
.len
);
198 value
.string
.string
= strdup(s
);
199 value
.string
.len
= strlen(s
);
201 return(interpreted_as_string
= value
.string
.string
!= NULL
);
205 cl_cmd_arg::as_bit(class cl_uc
*uc
)
207 if (interpreted_as_string
)
209 interpreted_as_string
= false;
210 if (value
.string
.string
)
211 free(value
.string
.string
);
214 return(get_bit_address(uc
,
216 &(value
.bit
.mem_address
),
217 &(value
.bit
.bitnr_high
),
218 &(value
.bit
.bitnr_low
)));
224 cl_cmd_int_arg::cl_cmd_int_arg(long addr
):
229 cl_cmd_int_arg::get_address(class cl_uc
*uc
, t_addr
*addr
)
233 bool b
= get_ivalue(&iv
);
240 cl_cmd_int_arg::get_bit_address(class cl_uc
*uc
, // input
241 class cl_memory
**mem
, // outputs
248 if (!get_address(uc
, &bit_addr
))
257 if (!(*mem
= uc
->bit2mem(bit_addr
, mem_addr
, bitnr_high
, bitnr_low
)))
264 cl_cmd_int_arg::as_string(void)
266 value
.string
.string
= (char*)malloc(100);
267 sprintf(value
.string
.string
, "%ld", i_value
);
268 value
.string
.len
= strlen(value
.string
.string
);
269 return(interpreted_as_string
= value
.string
.string
!= NULL
);
275 cl_cmd_sym_arg::cl_cmd_sym_arg(const char *sym
):
280 cl_cmd_sym_arg::as_string(void)
282 char *s
= get_svalue();
285 value
.string
.string
= strdup(s
);
286 value
.string
.len
= strlen(s
);
287 return(interpreted_as_string
= value
.string
.string
!= NULL
);
291 cl_cmd_sym_arg::get_address(class cl_uc
*uc
, t_addr
*addr
)
295 if (uc
->symbol2address(get_svalue(), NULL
, &a
))
305 cl_cmd_sym_arg::get_bit_address(class cl_uc
*uc
, // input
306 class cl_memory
**mem
, // outputs
312 if (uc
->vars
->by_name
.search(get_svalue(), i
))
314 class cl_var
*v
= (cl_var
*)uc
->vars
->by_name
.at(i
);
318 *mem_addr
= v
->get_addr();
320 *bitnr_high
= v
->bitnr_high
;
322 *bitnr_low
= v
->bitnr_low
;
329 cl_cmd_sym_arg::as_address(class cl_uc
*uc
)
332 if (uc
->symbol2address(get_svalue(), NULL
, &a
))
341 cl_cmd_sym_arg::as_hw(class cl_uc
*uc
)
346 hw
= found
= uc
->get_hw(get_svalue(), &i
);
349 if (hw
&& (strcmp(get_svalue(), "cpu")==0))
350 return value
.hw
= hw
, true;
352 found
= uc
->get_hw(get_svalue(), &i
);
360 cl_cmd_sym_arg::as_cell(class cl_uc
*uc
)
362 class cl_memory
*mem
;
363 class cl_memory_cell
*cell
;
366 if (uc
->symbol2address(get_svalue(), &mem
, &addr
))
368 if (mem
->is_address_space())
370 value
.cell
= ((cl_address_space
*)mem
)->get_cell(addr
);
371 return value
.cell
!= NULL
;
375 else if (uc
->symbol2cell(get_svalue(), &cell
))
386 cl_cmd_str_arg::cl_cmd_str_arg(const char *str
):
394 cl_cmd_bit_arg::cl_cmd_bit_arg(class cl_cmd_arg
*asfr
, class cl_cmd_arg
*abit_low
, class cl_cmd_arg
*abit_high
):
402 cl_cmd_bit_arg::~cl_cmd_bit_arg(void)
413 cl_cmd_bit_arg::get_address(class cl_uc
*uc
, t_addr
*addr
)
416 return(sfr
->get_address(uc
, addr
));
421 cl_cmd_bit_arg::get_bit_address(class cl_uc
*uc
, // input
422 class cl_memory
**mem
, // outputs
427 if (!sfr
|| !bitnr_high
|| !bitnr_low
)
430 if ((mem
|| mem_addr
) && !sfr
->get_bit_address(uc
, mem
, mem_addr
, NULL
, NULL
))
436 !bit_low
->get_ivalue(&l
) ||
438 l
>= (long)sizeof(t_mem
)*8)
440 *bitnr_low
= *bitnr_high
= l
;
444 if (!bit_high
->get_ivalue(&l
) ||
446 l
>= (long)sizeof(t_mem
)*8)
451 if (*bitnr_low
> *bitnr_high
)
454 *bitnr_low
= *bitnr_high
;
464 cl_cmd_array_arg::cl_cmd_array_arg(class cl_cmd_arg
*aname
,
465 class cl_cmd_arg
*aindex
):
472 cl_cmd_array_arg::~cl_cmd_array_arg(void)
481 cl_cmd_array_arg::get_bit_address(class cl_uc
*uc
, // input
482 class cl_memory
**mem
, // outputs
487 // address_space[address]
492 (n
= name_arg
->get_svalue()) == NULL
||
493 !index
->get_address(uc
, &a
))
495 class cl_memory
*m
= uc
->memory(n
);
497 !m
->valid_address(a
))
511 cl_cmd_array_arg::as_hw(class cl_uc
*uc
)
518 (n
= name_arg
->get_svalue()) == NULL
||
519 !index
->get_address(uc
, &a
))
522 value
.hw
= uc
->get_hw(n
, a
, NULL
);
523 return(value
.hw
!= NULL
);
527 cl_cmd_array_arg::as_cell(class cl_uc
*uc
)
529 class cl_memory
*mem
;
534 if (get_bit_address(uc
, &mem
, &addr
, NULL
, NULL
) &&
535 mem
->is_address_space())
536 value
.cell
= ((cl_address_space
*)mem
)->get_cell(addr
);
538 return value
.cell
!= NULL
;
542 /* End of sim.src/arg.cc */