47cce11fe35ec8840ffb4de59755cfacb4200c03
[fw/sdcc] / sim / ucsim / sim.src / option.cc
1 /*
2  * Simulator of microcontrollers (option.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 <stdio.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include "i_string.h"
34
35 #include "stypes.h"
36
37 #include "optioncl.h"
38 #include "simcl.h"
39
40
41 /*
42  * Base class for option's objects
43  *____________________________________________________________________________
44  *
45  */
46
47 cl_option::cl_option(void *opt, char *Iid, char *Ihelp):
48   cl_base()
49 {
50   option= opt;
51   id    = strdup(Iid);
52   help  = strdup(Ihelp);
53 }
54
55 cl_option::~cl_option(void)
56 {
57   free(id);
58   free(help);
59 }
60
61
62 /*
63  * BOOL type of option
64  *____________________________________________________________________________
65  *
66  */
67
68 cl_bool_opt::cl_bool_opt(bool *opt, char *Iid, char *Ihelp):
69   cl_option(opt, Iid, Ihelp)
70 {}
71
72 void
73 cl_bool_opt::print(FILE *f)
74 {
75   if (*(bool *)option)
76     fprintf(f, "TRUE");
77   else
78     fprintf(f, "FALSE");
79 }
80
81 bool
82 cl_bool_opt::get_value(void)
83 {
84   return(*((bool *)option));
85 }
86
87 void
88 cl_bool_opt::set_value(bool opt)
89 {
90   *((bool *)option)= opt;
91 }
92
93 void
94 cl_bool_opt::set_value(char *s)
95 {
96   char c;
97
98   if (s)
99     {
100       c= toupper(*s);
101       if (c == '1' ||
102           c == 'T' ||
103           c == 'Y')
104         *(bool *)option= DD_TRUE;
105       else
106         *(bool *)option= DD_FALSE;
107     }
108 };
109
110
111 /*
112  * Debug on console
113  */
114
115 cl_cons_debug_opt::cl_cons_debug_opt(class cl_sim *Asim,
116                                      char *Iid,
117                                      char *Ihelp):
118   cl_option(0, Iid, Ihelp)
119 {
120   sim= Asim;
121 }
122
123 void
124 cl_cons_debug_opt::print(FILE *f)
125 {
126   if (sim->cmd->actual_console &&
127       sim->cmd->actual_console->flags & CONS_DEBUG)
128     fprintf(f, "TRUE");
129   else
130     fprintf(f, "FALSE");
131 }
132
133 bool
134 cl_cons_debug_opt::get_value(void)
135 {
136   return(sim->cmd->actual_console?
137          (sim->cmd->actual_console->flags & CONS_DEBUG):
138          0);
139 }
140
141 void
142 cl_cons_debug_opt::set_value(bool opt)
143 {
144   if (sim->cmd->actual_console)
145     {
146       if (opt)
147         sim->cmd->actual_console->flags|= CONS_DEBUG;
148       else
149         sim->cmd->actual_console->flags&= ~CONS_DEBUG;
150     }
151     
152 }
153
154 void
155 cl_cons_debug_opt::set_value(char *s)
156 {
157   char c;
158
159   if (s &&
160       sim->cmd->actual_console)
161     {
162       c= toupper(*s);
163       if (c == '1' ||
164           c == 'T' ||
165           c == 'Y')
166         sim->cmd->actual_console->flags|= CONS_DEBUG;
167       else
168         sim->cmd->actual_console->flags&= ~CONS_DEBUG;
169     }
170 }
171
172
173 /* End of option.cc */