2 * Simulator of microcontrollers (sim51.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
44 #include "uc89c51rcl.h"
49 cl_sim51::cl_sim51(int iargc, char *iargv[]):
50 cl_sim("t:s:S:hH", iargc, iargv)
54 print_help(char *name)
56 printf("%s: %s\n", name, VERSIONSTR);
57 printf("Usage: %s [-hHVvP] [-p prompt] [-t CPU] [-X freq[k|M]]\n"
58 " [-c file] [-s file] [-S optionlist]"
63 " [files...]\n", name);
67 " -t CPU Type of CPU: 51, C52, 251, etc.\n"
68 " -X freq[k|M] XTAL frequency\n"
69 " -c file Open command console on `file'\n"
71 " -Z portnum Use localhost:portnumber for command console\n"
73 " -s file Connect serial interface to `file'\n"
74 " -S options `options' is a comma separated list of options\n"
75 " according to serial interface. Know options are:\n"
76 " in=file serial input will be read from file named `file'\n"
77 " out=file serial output will be written to `file'\n"
78 " -p prompt Specify string for prompt\n"
79 " -P Prompt is a null ('\\0') character\n"
81 " -v Print out version number\n"
82 " -H Print out types of known CPUs\n"
83 " -h Print out this help\n"
92 static const char *S_opts[]= {
94 /*[SOPT_OUT]=*/ "out",
99 cl_sim51::proc_arg(char optopt, char *optarg)
101 char *cpu_type= NULL, *cp;
103 char *subopts, *value;
112 cpu_type= strdup(optarg);
113 for (cp= cpu_type; *cp; *cp= toupper(*cp), cp++);
114 arguments->add(new cl_prg_arg('t', 0, cpu_type));
119 FILE *Ser_in, *Ser_out;
122 fprintf(stderr, "-s option can not be used more than once.\n");
125 arguments->add(new cl_prg_arg('s', 0, (long long)1));
126 if ((Ser_in= fopen(optarg, "r")) == NULL)
129 "Can't open `%s': %s\n", optarg, strerror(errno));
132 arguments->add(new cl_prg_arg(0, "Ser_in", Ser_in));
133 if ((Ser_out= fopen(optarg, "w")) == NULL)
136 "Can't open `%s': %s\n", optarg, strerror(errno));
139 arguments->add(new cl_prg_arg(0, "Ser_out", Ser_out));
146 while (*subopts != '\0')
147 switch (get_sub_opt(&subopts, S_opts, &value))
149 FILE *Ser_in, *Ser_out;
152 fprintf(stderr, "No value for -S in\n");
155 if (arg_avail("Ser_in"))
157 fprintf(stderr, "Serial input specified more than once.\n");
160 if ((Ser_in= fopen(value, "r")) == NULL)
163 "Can't open `%s': %s\n", value, strerror(errno));
166 arguments->add(new cl_prg_arg(0, "Ser_in", Ser_in));
170 fprintf(stderr, "No value for -S out\n");
173 if (arg_avail("Ser_out"))
175 fprintf(stderr, "Serial output specified more than once.\n");
178 if ((Ser_out= fopen(value, "w")) == NULL)
181 "Can't open `%s': %s\n", value, strerror(errno));
184 arguments->add(new cl_prg_arg(0, "Ser_out", Ser_out));
187 /* Unknown suboption. */
188 fprintf(stderr, "Unknown suboption `%s' for -S\n", value);
202 while (cpus_51[i].type_str != NULL)
204 printf("%s\n", cpus_51[i].type_str);
213 fprintf(stderr, "Unknown option `-%c'.\n", optopt);
215 fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
220 // should never happen...
227 cl_sim51::mk_commander(void)
229 class cl_commander *cmd= new cl_51cmd(this);
234 cl_sim51::mk_controller(void)
239 if (get_sarg('t', 0) == NULL)
240 simulator->arguments->add(new cl_prg_arg('t', 0, "C51"));
241 while ((cpus_51[i].type_str != NULL) &&
242 (strcmp(get_sarg('t', 0), cpus_51[i].type_str) != 0))
244 if (cpus_51[i].type_str == NULL)
246 fprintf(stderr, "Unknown processor type. "
247 "Use -H option to see known types.\n");
250 switch (cpus_51[i].type)
252 case CPU_51: case CPU_31:
253 return(new t_uc51(cpus_51[i].type, cpus_51[i].technology, this));
254 case CPU_52: case CPU_32:
255 return(new t_uc52(cpus_51[i].type, cpus_51[i].technology, this));
257 return(new t_uc51r(cpus_51[i].type, cpus_51[i].technology, this));
259 return(new t_uc89c51r(cpus_51[i].type, cpus_51[i].technology, this));
261 return(new t_uc251(cpus_51[i].type, cpus_51[i].technology, this));
267 cl_sim51::build_cmd_set(void)
269 cl_sim::build_cmd_set();
274 /* End of s51.src/sim51.cc */