+2006-08-30 Borut Razem <borut.razem AT siol.net>
+
+ * sim/ucsim/cmd.src/newcmdposix.cc, sim/ucsim/cmd.src/newcmdposixcl.h,
+ sim/ucsim/cmd.src/newcmdwin32.cc, sim/ucsim/cmd.src/newcmdwin32cl.h,
+ sim/ucsim/app.cc, sim/ucsim/appcl.h, sim/ucsim/configure,
+ sim/ucsim/configure.in, sim/ucsim/ddconfig_in.h, sim/ucsim/error.cc,
+ sim/ucsim/errorcl.h, sim/ucsim/option.cc, sim/ucsim/optioncl.h,
+ sim/ucsim/utils.cc, sim/ucsim/utils.h, sim/ucsim/cmd.src/Makefile.in,
+ sim/ucsim/avr.src/avr.cc, sim/ucsim/avr.src/avrcl.h,
+ sim/ucsim/cmd.src/bp.cc, sim/ucsim/cmd.src/bpcl.h,
+ sim/ucsim/cmd.src/cmdconf.cc, sim/ucsim/cmd.src/cmdgui.cc,
+ sim/ucsim/cmd.src/cmdmem.cc, sim/ucsim/cmd.src/cmdset.cc,
+ sim/ucsim/cmd.src/cmdsetcl.h, sim/ucsim/cmd.src/cmdstat.cc,
+ sim/ucsim/cmd.src/cmduc.cc, sim/ucsim/cmd.src/cmduccl.h,
+ sim/ucsim/cmd.src/cmdutil.cc, sim/ucsim/cmd.src/cmdutil.h,
+ sim/ucsim/cmd.src/command.cc, sim/ucsim/cmd.src/commandcl.h,
+ sim/ucsim/cmd.src/get.cc, sim/ucsim/cmd.src/getcl.h,
+ sim/ucsim/cmd.src/info.cc, sim/ucsim/cmd.src/newcmd.cc,
+ sim/ucsim/cmd.src/newcmdcl.h, sim/ucsim/cmd.src/set.cc,
+ sim/ucsim/cmd.src/show.cc, sim/ucsim/cmd.src/timer.cc,
+ sim/ucsim/hc08.src/hc08.cc, sim/ucsim/hc08.src/hc08cl.h,
+ sim/ucsim/s51.src/Makefile.in, sim/ucsim/s51.src/interrupt.cc,
+ sim/ucsim/s51.src/interruptcl.h, sim/ucsim/s51.src/pca.cc,
+ sim/ucsim/s51.src/pcacl.h, sim/ucsim/s51.src/port.cc,
+ sim/ucsim/s51.src/portcl.h, sim/ucsim/s51.src/serial.cc,
+ sim/ucsim/s51.src/serialcl.h, sim/ucsim/s51.src/timer0.cc,
+ sim/ucsim/s51.src/timer0cl.h, sim/ucsim/s51.src/timer1.cc,
+ sim/ucsim/s51.src/timer1cl.h, sim/ucsim/s51.src/timer2.cc,
+ sim/ucsim/s51.src/timer2cl.h, sim/ucsim/s51.src/uc390.cc,
+ sim/ucsim/s51.src/uc390cl.h, sim/ucsim/s51.src/uc390hw.cc,
+ sim/ucsim/s51.src/uc390hwcl.h, sim/ucsim/s51.src/uc51.cc,
+ sim/ucsim/s51.src/uc51cl.h, sim/ucsim/s51.src/wdt.cc,
+ sim/ucsim/s51.src/wdtcl.h, sim/ucsim/sim.src/hw.cc,
+ sim/ucsim/sim.src/hwcl.h, sim/ucsim/sim.src/mem.cc,
+ sim/ucsim/sim.src/memcl.h, sim/ucsim/sim.src/obsolete.cc,
+ sim/ucsim/sim.src/obsolete.h, sim/ucsim/sim.src/sim.cc,
+ sim/ucsim/sim.src/simcl.h, sim/ucsim/sim.src/stack.cc,
+ sim/ucsim/sim.src/stackcl.h, sim/ucsim/sim.src/test_mem_speed.cc,
+ sim/ucsim/sim.src/uc.cc, sim/ucsim/sim.src/uccl.h,
+ sim/ucsim/xa.src/xa.cc, sim/ucsim/xa.src/xacl.h,
+ sim/ucsim/z80.src/z80.cc, sim/ucsim/z80.src/z80cl.h:
+ ucsim WIN32 native port
+
2006-08-30 Jesus Calvino-Fraga <jesusc at ece.ubc.ca>
* doc/sdccman.lyx: added note on dynamic memory heap initialization
* Simulator of microcontrollers (app.cc)
*
* Copyright (C) 2001,01 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#include "showcl.h"
#include "getcl.h"
#include "setcl.h"
+#ifdef _WIN32
+#include "newcmdwin32cl.h"
+#else
+#include "newcmdposixcl.h"
+#endif
/*
int done= 0;
while (!done &&
- going)
+ going)
{
if (sim)
- {
- if (sim->state & SIM_GO)
- {
- if (commander->input_avail())
- done= commander->proc_input();
- else
- sim->step();
- }
- else
- {
- commander->wait_input();
- done= commander->proc_input();
- }
- }
+ {
+ if (sim->state & SIM_GO)
+ {
+ if (commander->input_avail())
+ done= commander->proc_input();
+ else
+ sim->step();
+ }
+ else
+ {
+ commander->wait_input();
+ done= commander->proc_input();
+ }
+ }
else
- {
- commander->wait_input();
- done= commander->proc_input();
- }
+ {
+ commander->wait_input();
+ done= commander->proc_input();
+ }
}
return(0);
}
{
printf("%s: %s\n", name, VERSIONSTR);
printf("Usage: %s [-hHVvP] [-p prompt] [-t CPU] [-X freq[k|M]]\n"
- " [-c file] [-s file] [-S optionlist]"
+ " [-c file] [-s file] [-S optionlist]"
#ifdef SOCKET_AVAIL
- " [-Z portnum] [-k portnum]"
+ " [-Z portnum] [-k portnum]"
#endif
- "\n"
- " [files...]\n", name);
+ "\n"
+ " [files...]\n", name);
printf
(
"Options:\n"
switch (c)
{
case 'c':
- if (!options->set_value("console_on", this, optarg))
- fprintf(stderr, "Warning: No \"console_on\" option found "
- "to set by -c\n");
- break;
+ if (!options->set_value("console_on", this, optarg))
+ fprintf(stderr, "Warning: No \"console_on\" option found "
+ "to set by -c\n");
+ break;
case 'C':
- if (!options->set_value("config_file", this, optarg))
- fprintf(stderr, "Warning: No \"config_file\" option found to set "
- "parameter of -C as config file\n");
- break;
+ if (!options->set_value("config_file", this, optarg))
+ fprintf(stderr, "Warning: No \"config_file\" option found to set "
+ "parameter of -C as config file\n");
+ break;
#ifdef SOCKET_AVAIL
case 'Z': case 'r':
- {
- // By Sandeep
- // Modified by DD
- class cl_option *o;
- options->new_option(o= new cl_number_option(this, "port_number",
- "Listen on port (-Z)"));
- o->init();
- o->hide();
- if (!options->set_value("port_number", this, strtol(optarg, NULL, 0)))
- fprintf(stderr, "Warning: No \"port_number\" option found"
- " to set parameter of -Z as pot number to listen on\n");
- break;
- }
+ {
+ // By Sandeep
+ // Modified by DD
+ class cl_option *o;
+ options->new_option(o= new cl_number_option(this, "port_number",
+ "Listen on port (-Z)"));
+ o->init();
+ o->hide();
+ if (!options->set_value("port_number", this, strtol(optarg, NULL, 0)))
+ fprintf(stderr, "Warning: No \"port_number\" option found"
+ " to set parameter of -Z as pot number to listen on\n");
+ break;
+ }
#endif
case 'p': {
- if (!options->set_value("prompt", this, optarg))
- fprintf(stderr, "Warning: No \"prompt\" option found to set "
- "parameter of -p as default prompt\n");
- break;
+ if (!options->set_value("prompt", this, optarg))
+ fprintf(stderr, "Warning: No \"prompt\" option found to set "
+ "parameter of -p as default prompt\n");
+ break;
}
case 'P':
- if (!options->set_value("null_prompt", this, bool(DD_TRUE)))
- fprintf(stderr, "Warning: No \"null_prompt\" option found\n");
- break;
+ if (!options->set_value("null_prompt", this, bool(DD_TRUE)))
+ fprintf(stderr, "Warning: No \"null_prompt\" option found\n");
+ break;
case 'X':
- {
- double XTAL;
- for (cp= optarg; *cp; *cp= toupper(*cp), cp++);
- XTAL= strtod(optarg, &cp);
- if (*cp == 'K')
- XTAL*= 1e3;
- if (*cp == 'M')
- XTAL*= 1e6;
- if (XTAL == 0)
- {
- fprintf(stderr, "Xtal frequency must be greather than 0\n");
- exit(1);
- }
- if (!options->set_value("xtal", this, XTAL))
- fprintf(stderr, "Warning: No \"xtal\" option found to set "
- "parameter of -X as XTAL frequency\n");
- break;
- }
+ {
+ double XTAL;
+ for (cp= optarg; *cp; *cp= toupper(*cp), cp++);
+ XTAL= strtod(optarg, &cp);
+ if (*cp == 'K')
+ XTAL*= 1e3;
+ if (*cp == 'M')
+ XTAL*= 1e6;
+ if (XTAL == 0)
+ {
+ fprintf(stderr, "Xtal frequency must be greather than 0\n");
+ exit(1);
+ }
+ if (!options->set_value("xtal", this, XTAL))
+ fprintf(stderr, "Warning: No \"xtal\" option found to set "
+ "parameter of -X as XTAL frequency\n");
+ break;
+ }
case 'v':
- printf("%s: %s\n", argv[0], VERSIONSTR);
+ printf("%s: %s\n", argv[0], VERSIONSTR);
exit(0);
break;
case 'V':
- if (!options->set_value("debug", this, (bool)DD_TRUE))
- fprintf(stderr, "Warning: No \"debug\" option found to set "
- "by -V parameter\n");
- break;
+ if (!options->set_value("debug", this, (bool)DD_TRUE))
+ fprintf(stderr, "Warning: No \"debug\" option found to set "
+ "by -V parameter\n");
+ break;
case 't':
- {
- if (cpu_type)
- free(cpu_type);
- cpu_type= case_string(case_upper, optarg);
- if (!options->set_value("cpu_type", this, /*optarg*/cpu_type))
- fprintf(stderr, "Warning: No \"cpu_type\" option found to set "
- "parameter of -t as type of controller\n");
- break;
- }
+ {
+ if (cpu_type)
+ free(cpu_type);
+ cpu_type= case_string(case_upper, optarg);
+ if (!options->set_value("cpu_type", this, /*optarg*/cpu_type))
+ fprintf(stderr, "Warning: No \"cpu_type\" option found to set "
+ "parameter of -t as type of controller\n");
+ break;
+ }
case 's':
{
- FILE *Ser_in, *Ser_out;
- if (s_done)
- {
- fprintf(stderr, "-s option can not be used more than once.\n");
- break;
- }
- s_done= DD_TRUE;
- if ((Ser_in= fopen(optarg, "r")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", optarg, strerror(errno));
- return(4);
- }
- if (!options->set_value("serial_in_file", this, (void*)Ser_in))
- fprintf(stderr, "Warning: No \"serial_in_file\" option found to set "
- "parameter of -s as serial input file\n");
- if ((Ser_out= fopen(optarg, "w")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", optarg, strerror(errno));
- return(4);
- }
- if (!options->set_value("serial_out_file", this, Ser_out))
- fprintf(stderr, "Warning: No \"serial_out_file\" option found "
- "to set parameter of -s as serial output file\n");
- break;
+#ifdef _WIN32
+ /* TODO: this code should be probably used for all platforms? */
+ FILE *Ser;
+ if (s_done)
+ {
+ fprintf(stderr, "-s option can not be used more than once.\n");
+ break;
+ }
+ s_done= DD_TRUE;
+ if ((Ser= fopen(optarg, "r+")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", optarg, strerror(errno));
+ return(4);
+ }
+ if (!options->set_value("serial_in_file", this, Ser))
+ fprintf(stderr, "Warning: No \"serial_in_file\" option found to set "
+ "parameter of -s as serial input file\n");
+ if (!options->set_value("serial_out_file", this, Ser))
+ fprintf(stderr, "Warning: No \"serial_out_file\" option found "
+ "to set parameter of -s as serial output file\n");
+#else
+ FILE *Ser_in, *Ser_out;
+ if (s_done)
+ {
+ fprintf(stderr, "-s option can not be used more than once.\n");
+ break;
+ }
+ s_done= DD_TRUE;
+ if ((Ser_in= fopen(optarg, "r")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", optarg, strerror(errno));
+ return(4);
+ }
+ if (!options->set_value("serial_in_file", this, Ser_in))
+ fprintf(stderr, "Warning: No \"serial_in_file\" option found to set "
+ "parameter of -s as serial input file\n");
+ if ((Ser_out= fopen(optarg, "w")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", optarg, strerror(errno));
+ return(4);
+ }
+ if (!options->set_value("serial_out_file", this, Ser_out))
+ fprintf(stderr, "Warning: No \"serial_out_file\" option found "
+ "to set parameter of -s as serial output file\n");
+#endif
+ break;
}
#ifdef SOCKET_AVAIL
// socket serial I/O by Alexandre Frey <Alexandre.Frey@trusted-logic.fr>
case 'k':
- {
- FILE *Ser_in, *Ser_out;
- int sock;
- unsigned short serverport;
- int client_sock;
-
- if (k_done) {
- fprintf(stderr, "Serial input specified more than once.\n");
- }
- k_done= DD_TRUE;
-
- serverport = atoi(optarg);
- sock= make_server_socket(serverport);
- if (listen(sock, 1) < 0) {
- fprintf(stderr, "Listen on port %d: %s\n", serverport,
- strerror(errno));
- return (4);
- }
- fprintf(stderr, "Listening on port %d for a serial connection.\n",
- serverport);
- if ((client_sock= accept(sock, NULL, NULL)) < 0) {
- fprintf(stderr, "accept: %s\n", strerror(errno));
- }
- fprintf(stderr, "Serial connection established.\n");
-
- if ((Ser_in= fdopen(client_sock, "r")) == NULL) {
- fprintf(stderr, "Can't create input stream: %s\n", strerror(errno));
- return (4);
- }
- if (!options->set_value("serial_in_file", this, (void*)Ser_in))
- fprintf(stderr, "Warning: No \"serial_in_file\" option found to "
- "set parameter of -s as serial input file\n");
- if ((Ser_out= fdopen(client_sock, "w")) == NULL) {
- fprintf(stderr, "Can't create output stream: %s\n", strerror(errno));
- return (4);
- }
- if (!options->set_value("serial_out_file", this, Ser_out))
- fprintf(stderr, "Warning: No \"serial_out_file\" option found "
- "to set parameter of -s as serial output file\n");
- break;
- }
+ {
+ FILE *Ser_in, *Ser_out;
+ UCSOCKET_T sock;
+ unsigned short serverport;
+ UCSOCKET_T client_sock;
+
+ if (k_done)
+ {
+ fprintf(stderr, "Serial input specified more than once.\n");
+ }
+ k_done= DD_TRUE;
+
+ serverport = atoi(optarg);
+ sock = make_server_socket(serverport);
+#ifdef _WIN32
+ if (SOCKET_ERROR == listen((SOCKET)sock, 1))
+ {
+ fprintf(stderr, "Listen on port %d: %d\n", serverport,
+ WSAGetLastError());
+ return (4);
+ }
+ fprintf(stderr, "Listening on port %d for a serial connection.\n",
+ serverport);
+ if (INVALID_SOCKET == (client_sock = accept(sock, NULL, NULL)))
+ {
+ fprintf(stderr, "accept: %d\n", WSAGetLastError());
+ return (4);
+ }
+ fprintf(stderr, "Serial connection established.\n");
+
+ int fh = _open_osfhandle((intptr_t)client_sock, 0);
+ if (-1 == fh)
+ {
+ perror("_open_osfhandle");
+ return (4);
+ }
+ if (NULL == (Ser_in = fdopen(fh, "r")))
+ {
+ fprintf(stderr, "Can't create input stream: %s\n", strerror(errno));
+ return (4);
+ }
+
+ fh = _open_osfhandle((intptr_t)client_sock, 0);
+ if (-1 == fh)
+ {
+ perror("_open_osfhandle");
+ }
+ if (NULL == (Ser_out = fdopen(fh, "w"))) {
+ fprintf(stderr, "Can't create output stream: %s\n", strerror(errno));
+ return (4);
+ }
+#else
+ if (listen(sock, 1) < 0) {
+ fprintf(stderr, "Listen on port %d: %s\n", serverport,
+ strerror(errno));
+ return (4);
+ }
+ fprintf(stderr, "Listening on port %d for a serial connection.\n",
+ serverport);
+ if ((client_sock= accept(sock, NULL, NULL)) < 0) {
+ fprintf(stderr, "accept: %s\n", strerror(errno));
+ }
+ fprintf(stderr, "Serial connection established.\n");
+
+ if ((Ser_in= fdopen(client_sock, "r")) == NULL) {
+ fprintf(stderr, "Can't create input stream: %s\n", strerror(errno));
+ return (4);
+ }
+ if ((Ser_out= fdopen(client_sock, "w")) == NULL) {
+ fprintf(stderr, "Can't create output stream: %s\n", strerror(errno));
+ return (4);
+ }
+#endif
+ if (!options->set_value("serial_in_file", this, (void*)Ser_in))
+ fprintf(stderr, "Warning: No \"serial_in_file\" option found to "
+ "set parameter of -s as serial input file\n");
+ if (!options->set_value("serial_out_file", this, Ser_out))
+ fprintf(stderr, "Warning: No \"serial_out_file\" option found "
+ "to set parameter of -s as serial output file\n");
+ break;
+ }
#endif
case 'S':
- subopts= optarg;
- while (*subopts != '\0')
- switch (get_sub_opt(&subopts, S_opts, &value))
- {
- FILE *Ser_in, *Ser_out;
- case SOPT_IN:
- if (value == NULL) {
- fprintf(stderr, "No value for -S in\n");
- exit(1);
- }
- if (S_i_done)
- {
- fprintf(stderr, "Serial input specified more than once.\n");
- break;
- }
- S_i_done= DD_TRUE;
- if ((Ser_in= fopen(value, "r")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", value, strerror(errno));
- exit(4);
- }
- if (!options->set_value("serial_in_file", this, (void*)Ser_in))
- fprintf(stderr, "Warning: No \"serial_in_file\" option found "
- "to set parameter of -s as serial input file\n");
- break;
- case SOPT_OUT:
- if (value == NULL) {
- fprintf(stderr, "No value for -S out\n");
- exit(1);
- }
- if (S_o_done)
- {
- fprintf(stderr, "Serial output specified more than once.\n");
- break;
- }
- if ((Ser_out= fopen(value, "w")) == NULL)
- {
- fprintf(stderr,
- "Can't open `%s': %s\n", value, strerror(errno));
- exit(4);
- }
- if (!options->set_value("serial_out_file", this, Ser_out))
- fprintf(stderr, "Warning: No \"serial_out_file\" option found "
- "to set parameter of -s as serial output file\n");
- break;
- default:
- /* Unknown suboption. */
- fprintf(stderr, "Unknown suboption `%s' for -S\n", value);
- exit(1);
- break;
- }
- break;
+ subopts= optarg;
+ while (*subopts != '\0')
+ switch (get_sub_opt(&subopts, S_opts, &value))
+ {
+ FILE *Ser_in, *Ser_out;
+ case SOPT_IN:
+ if (value == NULL) {
+ fprintf(stderr, "No value for -S in\n");
+ exit(1);
+ }
+ if (S_i_done)
+ {
+ fprintf(stderr, "Serial input specified more than once.\n");
+ break;
+ }
+ S_i_done= DD_TRUE;
+ if ((Ser_in= fopen(value, "r")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", value, strerror(errno));
+ exit(4);
+ }
+ if (!options->set_value("serial_in_file", this, (void*)Ser_in))
+ fprintf(stderr, "Warning: No \"serial_in_file\" option found "
+ "to set parameter of -s as serial input file\n");
+ break;
+ case SOPT_OUT:
+ if (value == NULL) {
+ fprintf(stderr, "No value for -S out\n");
+ exit(1);
+ }
+ if (S_o_done)
+ {
+ fprintf(stderr, "Serial output specified more than once.\n");
+ break;
+ }
+ if ((Ser_out= fopen(value, "w")) == NULL)
+ {
+ fprintf(stderr,
+ "Can't open `%s': %s\n", value, strerror(errno));
+ exit(4);
+ }
+ if (!options->set_value("serial_out_file", this, Ser_out))
+ fprintf(stderr, "Warning: No \"serial_out_file\" option found "
+ "to set parameter of -s as serial output file\n");
+ break;
+ default:
+ /* Unknown suboption. */
+ fprintf(stderr, "Unknown suboption `%s' for -S\n", value);
+ exit(1);
+ break;
+ }
+ break;
case 'h':
- print_help("s51");
- exit(0);
- break;
+ print_help("s51");
+ exit(0);
+ break;
case 'H':
- {
- if (!cpus)
- {
- fprintf(stderr, "CPU type is not selectable\n");
- exit(0);
- }
- i= 0;
- while (cpus[i].type_str != NULL)
- {
- printf("%s\n", cpus[i].type_str);
- i++;
- }
- exit(0);
- break;
- }
+ {
+ if (!cpus)
+ {
+ fprintf(stderr, "CPU type is not selectable\n");
+ exit(0);
+ }
+ i= 0;
+ while (cpus[i].type_str != NULL)
+ {
+ printf("%s\n", cpus[i].type_str);
+ i++;
+ }
+ exit(0);
+ break;
+ }
case '?':
- if (isprint(optopt))
- fprintf(stderr, "Unknown option `-%c'.\n", optopt);
- else
- fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
- return(1);
- break;
+ if (isprint(optopt))
+ fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+ else
+ fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
+ return(1);
+ break;
default:
- exit(c);
+ exit(c);
}
for (i= optind; i < argc; i++)
if (sim)
remove_simulator();
sim= simulator;
-
+
}
void
"conf Configuration",
"long help of conf"));
cmd->init();
- cset->add(cmd= new cl_conf_objects_cmd("objects", 0,
+ cset->add(cmd= new cl_conf_objects_cmd("objects", 0,
"conf objects Show object tree",
"long help of conf objects"));
cmd->init();
cset= new cl_cmdset();
cset->init();
}
- cset->add(cmd= new cl_show_copying_cmd("copying", 0,
+ cset->add(cmd= new cl_show_copying_cmd("copying", 0,
"show copying Conditions for redistributing copies of uCsim",
"long help of show copying"));
cmd->init();
- cset->add(cmd= new cl_show_warranty_cmd("warranty", 0,
+ cset->add(cmd= new cl_show_warranty_cmd("warranty", 0,
"show warranty Various kinds of warranty you do not have",
"long help of show warranty"));
cmd->init();
class cl_option *o;
options->new_option(o= new cl_bool_option(this, "null_prompt",
- "Use \\0 as prompt (-P)"));
+ "Use \\0 as prompt (-P)"));
o->init();
options->new_option(o= new cl_pointer_option(this, "serial_in_file",
- "Input file for serial line (-s)"));
+ "Input file for serial line (-s)"));
o->init();
o->hide();
options->new_option(o= new cl_pointer_option(this, "serial_out_file",
- "Output file for serial line (-s)"));
+ "Output file for serial line (-s)"));
o->init();
o->hide();
options->new_option(o= new cl_string_option(this, "prompt",
- "String of prompt (-p)"));
+ "String of prompt (-p)"));
o->init();
options->new_option(o= new cl_bool_option(this, "debug",
- "Print debug messages (-V)"));
+ "Print debug messages (-V)"));
o->init();
options->new_option(o= new cl_string_option(this, "console_on",
- "Open console on this file (-c)"));
+ "Open console on this file (-c)"));
o->init();
o->hide();
options->new_option(o= new cl_string_option(this, "config_file",
- "Execute this file at startup (-C)"));
+ "Execute this file at startup (-C)"));
o->init();
o->hide();
options->new_option(o= new cl_float_option(this, "xtal",
- "Frequency of XTAL in Hz"));
+ "Frequency of XTAL in Hz"));
o->init();
o->set_value(11059200.0);
options->new_option(o= new cl_string_option(this, "cpu_type",
- "Type of controller (-t)"));
+ "Type of controller (-t)"));
o->init();
o->hide();
}
class cl_app: public cl_base
{
protected:
- class cl_commander *commander;
+ class cl_commander_base *commander;
public:
class cl_sim *sim;
class cl_ustrings *in_files;
public:
class cl_sim *get_sim(void) { return(sim); }
class cl_uc *get_uc(void);
- class cl_commander *get_commander(void) { return(commander); }
+ class cl_commander_base *get_commander(void) { return(commander); }
virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline);
public: // messages to broadcast
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= rom/*address_space(MEM_ROM_ID)*/,
- chip, 0, 0xffff, 0);
+ chip, 0, 0xffff, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= ram/*address_space(MEM_IRAM_ID)*/,
- chip, 0, 0x7f, 0);
+ chip, 0, 0x7f, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
code= get_mem(MEM_ROM_ID, addr);
i= 0;
while ((code & dis_tbl()[i].mask) != dis_tbl()[i].code &&
- dis_tbl()[i].mnemonic)
+ dis_tbl()[i].mnemonic)
i++;
if (dis_tbl()[i].mnemonic == NULL)
{
while (*b)
{
if (*b == '%')
- {
- b++;
- switch (*(b++))
- {
- case 'd': // Rd .... ...d dddd .... 0<=d<=31
- if (!get_name(data= (code&0x01f0)>>4, sfr_tbl(), temp))
- sprintf(temp, "r%d", data);
- break;
- case 'D': // Rd .... .... dddd .... 16<=d<=31
- if (!get_name(data= 16+((code&0xf0)>>4), sfr_tbl(), temp))
- sprintf(temp, "r%d", data);
- break;
- case 'K': // K .... KKKK .... KKKK 0<=K<=255
- sprintf(temp, "%d", ((code&0xf00)>>4)|(code&0xf));
- break;
- case 'r': // Rr .... ..r. .... rrrr 0<=r<=31
- if (!get_name(data= ((code&0x0200)>>5)|(code&0x000f),
- sfr_tbl(), temp))
- sprintf(temp, "r%d", data);
- break;
- case '2': // Rdl .... .... ..dd .... dl= {24,26,28,30}
- if (!get_name(data= 24+(2*((code&0x0030)>>4)),
- sfr_tbl(), temp))
- sprintf(temp, "r%d", data);
- break;
- case '6': // K .... .... KK.. KKKK 0<=K<=63
- sprintf(temp, "%d", ((code&0xc0)>>2)|(code&0xf));
- break;
- case 's': // s .... .... .sss .... 0<=s<=7
- sprintf(temp, "%d", (code&0x70)>>4);
- break;
- case 'b': // b .... .... .... .bbb 0<=b<=7
- sprintf(temp, "%d", code&0x7);
- break;
- case 'k': // k .... ..kk kkkk k... -64<=k<=+63
- {
- int k= (code&0x3f8)>>3;
- if (code&0x200)
- k|= -128;
- sprintf(temp, "0x%06x", k+1+(signed int)addr);
- break;
- }
- case 'A': // k .... ...k kkkk ...k 0<=k<=64K
- // kkkk kkkk kkkk kkkk 0<=k<=4M
- sprintf(temp, "0x%06x",
- (((code&0x1f0)>>3)|(code&1))*0x10000+
- (uint)get_mem(MEM_ROM_ID, addr+1));
- break;
- case 'P': // P .... .... pppp p... 0<=P<=31
- data= (code&0xf8)>>3;
- if (!get_name(data+0x20, sfr_tbl(), temp))
- sprintf(temp, "%d", data);
- break;
- case 'p': // P .... .PP. .... PPPP 0<=P<=63
- data= ((code&0x600)>>5)|(code&0xf);
- if (!get_name(data+0x20, sfr_tbl(), temp))
- sprintf(temp, "%d", data);
- break;
- case 'q': // q ..q. qq.. .... .qqq 0<=q<=63
- sprintf(temp, "%d",
- ((code&0x2000)>>8)|((code&0xc00)>>7)|(code&7));
- break;
- case 'R': // k SRAM address on second word 0<=k<=65535
- sprintf(temp, "0x%06x", (uint)get_mem(MEM_ROM_ID, addr+1));
- break;
- case 'a': // k .... kkkk kkkk kkkk -2k<=k<=2k
- {
- int k= code&0xfff;
- if (code&0x800)
- k|= -4096;
- sprintf(temp, "0x%06"_A_"x",
- rom->validate_address(k+1+(signed int)addr));
- break;
- }
- default:
- strcpy(temp, "?");
- break;
- }
- t= temp;
- while (*t)
- *(p++)= *(t++);
- }
+ {
+ b++;
+ switch (*(b++))
+ {
+ case 'd': // Rd .... ...d dddd .... 0<=d<=31
+ if (!get_name(data= (code&0x01f0)>>4, sfr_tbl(), temp))
+ sprintf(temp, "r%d", data);
+ break;
+ case 'D': // Rd .... .... dddd .... 16<=d<=31
+ if (!get_name(data= 16+((code&0xf0)>>4), sfr_tbl(), temp))
+ sprintf(temp, "r%d", data);
+ break;
+ case 'K': // K .... KKKK .... KKKK 0<=K<=255
+ sprintf(temp, "%d", ((code&0xf00)>>4)|(code&0xf));
+ break;
+ case 'r': // Rr .... ..r. .... rrrr 0<=r<=31
+ if (!get_name(data= ((code&0x0200)>>5)|(code&0x000f),
+ sfr_tbl(), temp))
+ sprintf(temp, "r%d", data);
+ break;
+ case '2': // Rdl .... .... ..dd .... dl= {24,26,28,30}
+ if (!get_name(data= 24+(2*((code&0x0030)>>4)),
+ sfr_tbl(), temp))
+ sprintf(temp, "r%d", data);
+ break;
+ case '6': // K .... .... KK.. KKKK 0<=K<=63
+ sprintf(temp, "%d", ((code&0xc0)>>2)|(code&0xf));
+ break;
+ case 's': // s .... .... .sss .... 0<=s<=7
+ sprintf(temp, "%d", (code&0x70)>>4);
+ break;
+ case 'b': // b .... .... .... .bbb 0<=b<=7
+ sprintf(temp, "%d", code&0x7);
+ break;
+ case 'k': // k .... ..kk kkkk k... -64<=k<=+63
+ {
+ int k= (code&0x3f8)>>3;
+ if (code&0x200)
+ k|= -128;
+ sprintf(temp, "0x%06x", k+1+(signed int)addr);
+ break;
+ }
+ case 'A': // k .... ...k kkkk ...k 0<=k<=64K
+ // kkkk kkkk kkkk kkkk 0<=k<=4M
+ sprintf(temp, "0x%06x",
+ (((code&0x1f0)>>3)|(code&1))*0x10000+
+ (uint)get_mem(MEM_ROM_ID, addr+1));
+ break;
+ case 'P': // P .... .... pppp p... 0<=P<=31
+ data= (code&0xf8)>>3;
+ if (!get_name(data+0x20, sfr_tbl(), temp))
+ sprintf(temp, "%d", data);
+ break;
+ case 'p': // P .... .PP. .... PPPP 0<=P<=63
+ data= ((code&0x600)>>5)|(code&0xf);
+ if (!get_name(data+0x20, sfr_tbl(), temp))
+ sprintf(temp, "%d", data);
+ break;
+ case 'q': // q ..q. qq.. .... .qqq 0<=q<=63
+ sprintf(temp, "%d",
+ ((code&0x2000)>>8)|((code&0xc00)>>7)|(code&7));
+ break;
+ case 'R': // k SRAM address on second word 0<=k<=65535
+ sprintf(temp, "0x%06x", (uint)get_mem(MEM_ROM_ID, addr+1));
+ break;
+ case 'a': // k .... kkkk kkkk kkkk -2k<=k<=2k
+ {
+ int k= code&0xfff;
+ if (code&0x800)
+ k|= -4096;
+ sprintf(temp, "0x%06"_A_"x",
+ rom->validate_address(k+1+(signed int)addr));
+ break;
+ }
+ default:
+ strcpy(temp, "?");
+ break;
+ }
+ t= temp;
+ while (*t)
+ *(p++)= *(t++);
+ }
else
- *(p++)= *(b++);
+ *(p++)= *(b++);
}
*p= '\0';
if (sep == NULL)
{
while (strlen(buf) < 6)
- strcat(buf, " ");
+ strcat(buf, " ");
}
else
strcat(buf, sep);
void
-cl_avr::print_regs(class cl_console *con)
+cl_avr::print_regs(class cl_console_base *con)
{
uchar data, sreg= ram->get(SREG);
uint x, y, z;
ram->dump(0, 31, 16, con);
con->dd_printf("ITHSVNZC SREG= 0x%02x %3d %c\n",
- sreg, sreg, isprint(sreg)?sreg:'.');
+ sreg, sreg, isprint(sreg)?sreg:'.');
con->dd_printf("%c%c%c%c%c%c%c%c ",
- (sreg&BIT_I)?'1':'0',
- (sreg&BIT_T)?'1':'0',
- (sreg&BIT_H)?'1':'0',
- (sreg&BIT_S)?'1':'0',
- (sreg&BIT_V)?'1':'0',
- (sreg&BIT_N)?'1':'0',
- (sreg&BIT_Z)?'1':'0',
- (sreg&BIT_C)?'1':'0');
+ (sreg&BIT_I)?'1':'0',
+ (sreg&BIT_T)?'1':'0',
+ (sreg&BIT_H)?'1':'0',
+ (sreg&BIT_S)?'1':'0',
+ (sreg&BIT_V)?'1':'0',
+ (sreg&BIT_N)?'1':'0',
+ (sreg&BIT_Z)?'1':'0',
+ (sreg&BIT_C)?'1':'0');
con->dd_printf("SP = 0x%06x\n", ram->get(SPH)*256+ram->get(SPL));
x= ram->get(XH)*256 + ram->get(XL);
data= ram->get(x);
con->dd_printf("X= 0x%04x [X]= 0x%02x %3d %c ", x,
- data, data, isprint(data)?data:'.');
+ data, data, isprint(data)?data:'.');
y= ram->get(YH)*256 + ram->get(YL);
data= ram->get(y);
con->dd_printf("Y= 0x%04x [Y]= 0x%02x %3d %c ", y,
- data, data, isprint(data)?data:'.');
+ data, data, isprint(data)?data:'.');
z= ram->get(ZH)*256 + ram->get(ZL);
data= ram->get(z);
con->dd_printf("Z= 0x%04x [Z]= 0x%02x %3d %c\n", z,
- data, data, isprint(data)?data:'.');
+ data, data, isprint(data)?data:'.');
print_disass(PC, con);
}
{
case 0x0000:
{
- // 0x0...
- switch (code & 0xfc00)
- {
- case 0x0000:
- {
- switch (code & 0xff00)
- {
- case 0x0100: return(movw_Rd_Rr(code));
- case 0x0200: return(muls_Rd_Rr(code));
- case 0x0300:
- {
- switch (code & 0xff88)
- {
- case 0x0300: return(mulsu_Rd_Rr(code));
- case 0x0308: return(fmul_Rd_Rr(code));
- case 0x0380: return(fmuls_Rd_Rr(code));
- case 0x0388: return(fmulsu_Rd_Rr(code));
- }
- break;
- }
- break;
- }
- break;
- }
- case 0x0400: return(cpc_Rd_Rr(code));
- case 0x0800: return(sbc_Rd_Rr(code));
- case 0x0c00: return(add_Rd_Rr(code));
- }
- break;
+ // 0x0...
+ switch (code & 0xfc00)
+ {
+ case 0x0000:
+ {
+ switch (code & 0xff00)
+ {
+ case 0x0100: return(movw_Rd_Rr(code));
+ case 0x0200: return(muls_Rd_Rr(code));
+ case 0x0300:
+ {
+ switch (code & 0xff88)
+ {
+ case 0x0300: return(mulsu_Rd_Rr(code));
+ case 0x0308: return(fmul_Rd_Rr(code));
+ case 0x0380: return(fmuls_Rd_Rr(code));
+ case 0x0388: return(fmulsu_Rd_Rr(code));
+ }
+ break;
+ }
+ break;
+ }
+ break;
+ }
+ case 0x0400: return(cpc_Rd_Rr(code));
+ case 0x0800: return(sbc_Rd_Rr(code));
+ case 0x0c00: return(add_Rd_Rr(code));
+ }
+ break;
}
case 0x1000:
{
- // 0x1...
- switch (code & 0xfc00)
- {
- case 0x1000: return(cpse_Rd_Rr(code));
- case 0x1400: return(cp_Rd_Rr(code));
- case 0x1800: return(sub_Rd_Rr(code));
- case 0x1c00: return(adc_Rd_Rr(code));
- }
- break;
+ // 0x1...
+ switch (code & 0xfc00)
+ {
+ case 0x1000: return(cpse_Rd_Rr(code));
+ case 0x1400: return(cp_Rd_Rr(code));
+ case 0x1800: return(sub_Rd_Rr(code));
+ case 0x1c00: return(adc_Rd_Rr(code));
+ }
+ break;
}
case 0x2000:
{
- // 0x2...
- switch (code & 0xfc00)
- {
- case 0x2000: return(and_Rd_Rr(code));
- case 0x2400: return(eor_Rd_Rr(code));
- case 0x2800: return(or_Rd_Rr(code));
- case 0x2c00: return(mov_Rd_Rr(code));
- }
- break;
+ // 0x2...
+ switch (code & 0xfc00)
+ {
+ case 0x2000: return(and_Rd_Rr(code));
+ case 0x2400: return(eor_Rd_Rr(code));
+ case 0x2800: return(or_Rd_Rr(code));
+ case 0x2c00: return(mov_Rd_Rr(code));
+ }
+ break;
}
case 0x8000:
{
- // 0x8...
- switch (code &0xf208)
- {
- case 0x8000: return(ldd_Rd_Z_q(code));
- case 0x8008: return(ldd_Rd_Y_q(code));
- case 0x8200: return(std_Z_q_Rr(code));
- case 0x8208: return(std_Y_q_Rr(code));
- }
- break;
+ // 0x8...
+ switch (code &0xf208)
+ {
+ case 0x8000: return(ldd_Rd_Z_q(code));
+ case 0x8008: return(ldd_Rd_Y_q(code));
+ case 0x8200: return(std_Z_q_Rr(code));
+ case 0x8208: return(std_Y_q_Rr(code));
+ }
+ break;
}
case 0x9000:
{
- // 0x9...
- if ((code & 0xff0f) == 0x9509)
- return(icall(code));
- if ((code & 0xff0f) == 0x9409)
- return(ijmp(code));
- if ((code & 0xff00) == 0x9600)
- return(adiw_Rdl_K(code));
- if ((code & 0xff00) == 0x9700)
- return(sbiw_Rdl_K(code));
- switch (code & 0xfc00)
- {
- case 0x9000:
- {
- switch (code & 0xfe0f)
- {
- case 0x9000: return(lds_Rd_k(code));
- case 0x9001: return(ld_Rd_ZS(code));
- case 0x9002: return(ld_Rd_SZ(code));
- case 0x9004: return(lpm_Rd_Z(code));
- case 0x9005: return(lpm_Rd_ZS(code));
- case 0x9006: return(elpm_Rd_Z(code));
- case 0x9007: return(elpm_Rd_ZS(code));
- case 0x9009: return(ld_Rd_YS(code));
- case 0x900a: return(ld_Rd_SY(code));
- case 0x900c: return(ld_Rd_X(code));
- case 0x900d: return(ld_Rd_XS(code));
- case 0x900e: return(ld_Rd_SX(code));
- case 0x900f: return(pop_Rd(code));
- case 0x9200: return(sts_k_Rr(code));
- case 0x9201: return(st_ZS_Rr(code));
- case 0x9202: return(st_SZ_Rr(code));
- case 0x9209: return(st_YS_Rr(code));
- case 0x920a: return(st_SY_Rr(code));
- case 0x920c: return(st_X_Rr(code));
- case 0x920d: return(st_XS_Rr(code));
- case 0x920e: return(st_SX_Rr(code));
- case 0x920f: return(push_Rr(code));
- }
- break;
- }
- case 0x9400:
- {
- switch (code & 0xfe0f)
- {
- case 0x9400: return(com_Rd(code));
- case 0x9401: return(neg_Rd(code));
- case 0x9402: return(swap_Rd(code));
- case 0x9403: return(inc_Rd(code));
- case 0x9405: return(asr_Rd(code));
- case 0x9406: return(lsr_Rd(code));
- case 0x9407: return(ror_Rd(code));
- case 0x940a: return(dec_Rd(code));
- case 0x940c: case 0x940d: return(jmp_k(code));
- case 0x940e: case 0x940f: return(call_k(code));
- }
- break;
- }
- case 0x9800:
- {
- switch (code & 0xff00)
- {
- case 0x9800: return(cbi_A_b(code));
- case 0x9900: return(sbic_P_b(code));
- case 0x9a00: return(sbi_A_b(code));
- case 0x9b00: return(sbis_P_b(code));
- }
- break;
- }
- case 0x9c00: return(mul_Rd_Rr(code));
- }
- break;
+ // 0x9...
+ if ((code & 0xff0f) == 0x9509)
+ return(icall(code));
+ if ((code & 0xff0f) == 0x9409)
+ return(ijmp(code));
+ if ((code & 0xff00) == 0x9600)
+ return(adiw_Rdl_K(code));
+ if ((code & 0xff00) == 0x9700)
+ return(sbiw_Rdl_K(code));
+ switch (code & 0xfc00)
+ {
+ case 0x9000:
+ {
+ switch (code & 0xfe0f)
+ {
+ case 0x9000: return(lds_Rd_k(code));
+ case 0x9001: return(ld_Rd_ZS(code));
+ case 0x9002: return(ld_Rd_SZ(code));
+ case 0x9004: return(lpm_Rd_Z(code));
+ case 0x9005: return(lpm_Rd_ZS(code));
+ case 0x9006: return(elpm_Rd_Z(code));
+ case 0x9007: return(elpm_Rd_ZS(code));
+ case 0x9009: return(ld_Rd_YS(code));
+ case 0x900a: return(ld_Rd_SY(code));
+ case 0x900c: return(ld_Rd_X(code));
+ case 0x900d: return(ld_Rd_XS(code));
+ case 0x900e: return(ld_Rd_SX(code));
+ case 0x900f: return(pop_Rd(code));
+ case 0x9200: return(sts_k_Rr(code));
+ case 0x9201: return(st_ZS_Rr(code));
+ case 0x9202: return(st_SZ_Rr(code));
+ case 0x9209: return(st_YS_Rr(code));
+ case 0x920a: return(st_SY_Rr(code));
+ case 0x920c: return(st_X_Rr(code));
+ case 0x920d: return(st_XS_Rr(code));
+ case 0x920e: return(st_SX_Rr(code));
+ case 0x920f: return(push_Rr(code));
+ }
+ break;
+ }
+ case 0x9400:
+ {
+ switch (code & 0xfe0f)
+ {
+ case 0x9400: return(com_Rd(code));
+ case 0x9401: return(neg_Rd(code));
+ case 0x9402: return(swap_Rd(code));
+ case 0x9403: return(inc_Rd(code));
+ case 0x9405: return(asr_Rd(code));
+ case 0x9406: return(lsr_Rd(code));
+ case 0x9407: return(ror_Rd(code));
+ case 0x940a: return(dec_Rd(code));
+ case 0x940c: case 0x940d: return(jmp_k(code));
+ case 0x940e: case 0x940f: return(call_k(code));
+ }
+ break;
+ }
+ case 0x9800:
+ {
+ switch (code & 0xff00)
+ {
+ case 0x9800: return(cbi_A_b(code));
+ case 0x9900: return(sbic_P_b(code));
+ case 0x9a00: return(sbi_A_b(code));
+ case 0x9b00: return(sbis_P_b(code));
+ }
+ break;
+ }
+ case 0x9c00: return(mul_Rd_Rr(code));
+ }
+ break;
}
case 0xa000:
{
- // 0xa...
- switch (code &0xf208)
- {
- case 0xa000: return(ldd_Rd_Z_q(code));
- case 0xa008: return(ldd_Rd_Y_q(code));
- case 0xa200: return(std_Z_q_Rr(code));
- case 0xa208: return(std_Y_q_Rr(code));
- }
- break;
+ // 0xa...
+ switch (code &0xf208)
+ {
+ case 0xa000: return(ldd_Rd_Z_q(code));
+ case 0xa008: return(ldd_Rd_Y_q(code));
+ case 0xa200: return(std_Z_q_Rr(code));
+ case 0xa208: return(std_Y_q_Rr(code));
+ }
+ break;
}
case 0xb000:
{
- // 0xb...
- switch (code & 0xf800)
- {
- case 0xb000: return(in_Rd_A(code));
- case 0xb800: return(out_A_Rr(code));
- }
- break;
+ // 0xb...
+ switch (code & 0xf800)
+ {
+ case 0xb000: return(in_Rd_A(code));
+ case 0xb800: return(out_A_Rr(code));
+ }
+ break;
}
case 0xe000:
{
- // 0xe...
- switch (code & 0xff0f)
- {
- case 0xef0f: return(ser_Rd(code));
- }
- break;
+ // 0xe...
+ switch (code & 0xff0f)
+ {
+ case 0xef0f: return(ser_Rd(code));
+ }
+ break;
}
case 0xf000:
{
- // 0xf...
- switch (code & 0xfc00)
- {
- case 0xf000: return(brbs_s_k(code));
- case 0xf400: return(brbc_s_k(code));
- case 0xf800: case 0xfc00:
- {
- switch (code & 0xfe08)
- {
- case 0xf800: return(bld_Rd_b(code));
- case 0xfa00: return(bst_Rd_b(code));
- case 0xfc00: case 0xfc08: return(sbrc_Rr_b(code));
- case 0xfe00: case 0xfe08: return(sbrs_Rr_b(code));
- }
- break;
- }
- }
- break;
+ // 0xf...
+ switch (code & 0xfc00)
+ {
+ case 0xf000: return(brbs_s_k(code));
+ case 0xf400: return(brbc_s_k(code));
+ case 0xf800: case 0xfc00:
+ {
+ switch (code & 0xfe08)
+ {
+ case 0xf800: return(bld_Rd_b(code));
+ case 0xfa00: return(bst_Rd_b(code));
+ case 0xfc00: case 0xfc08: return(sbrc_Rr_b(code));
+ case 0xfe00: case 0xfe08: return(sbrs_Rr_b(code));
+ }
+ break;
+ }
+ }
+ break;
}
}
/*if (PC)
virtual struct name_entry *sfr_tbl(void);
virtual struct name_entry *bit_tbl(void);
virtual char *disass(t_addr addr, char *sep);
- virtual void print_regs(class cl_console *con);
+ virtual void print_regs(class cl_console_base *con);
virtual int exec_inst(void);
CFLAGS = @CFLAGS@ -Wall
CXXFLAGS = @CXXFLAGS@ -Wall
M_OR_MM = @M_OR_MM@
+WINSOCK_AVAIL = @WINSOCK_AVAIL@
prefix = @prefix@
exec_prefix = @exec_prefix@
srcdir = @srcdir@
VPATH = @srcdir@
-OBJECTS = cmdset.o command.o newcmd.o cmdutil.o syntax.o \
+OBJECTS = cmdset.o command.o cmdutil.o syntax.o \
get.o set.o timer.o bp.o info.o show.o cmdgui.o cmdconf.o \
cmduc.o cmdstat.o cmdmem.o \
- cmdpars.o cmdlex.o
+ cmdpars.o cmdlex.o newcmd.o
+
+ifeq ($(WINSOCK_AVAIL), 1)
+OBJECTS += newcmdwin32.o
+else
+OBJECTS += newcmdposix.o
+endif
DEVEL = $(shell ( bash -c "test -e $(top_builddir)devel && echo yes" ))
dep: Makefile.dep
Makefile.dep: $(srcdir)/*.cc $(srcdir)/*.h
- $(CXXCPP) $(CPPFLAGS) $(M_OR_MM) $(filter %.cc,$^) >Makefile.dep
+ $(CXXCPP) $(CPPFLAGS) $(M_OR_MM) $(addprefix $(srcdir)/, $(OBJECTS:.o=.cc)) >Makefile.dep
include Makefile.dep
include $(srcdir)/clean.mk
//int
//cl_break_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_break_cmd)
{
t_addr addr= 0;
char op;
class cl_address_space *mem;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, ADDRESS)) {
addr= params[0]->value.address;
void
cl_break_cmd::do_fetch(class cl_uc *uc,
- t_addr addr, int hit, class cl_console *con)
+ t_addr addr, int hit, class cl_console_base *con)
{
if (hit > 99999)
{
else
{
class cl_brk *b= new cl_fetch_brk(uc->address_space(MEM_ROM_ID),
- uc->make_new_brknr(),
- addr, perm, hit);
+ uc->make_new_brknr(),
+ addr, perm, hit);
b->init();
uc->fbrk->add_bp(b);
char *s= uc->disass(addr, NULL);
void
cl_break_cmd::do_event(class cl_uc *uc,
- class cl_address_space *mem,
- char op, t_addr addr, int hit,
- class cl_console *con)
+ class cl_address_space *mem,
+ char op, t_addr addr, int hit,
+ class cl_console_base *con)
{
class cl_ev_brk *b= NULL;
//int
//cl_clear_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_clear_cmd)
{
int idx;
if (cmdline->param(0) == 0)
{
if (!brk)
- {
- con->dd_printf("No breakpoint at this address.\n");
- return(0);
- }
+ {
+ con->dd_printf("No breakpoint at this address.\n");
+ return(0);
+ }
uc->fbrk->del_bp(uc->PC);
return(0);
}
{
t_addr addr;
if (!param->as_address(uc))
- return(DD_FALSE);
+ return(DD_FALSE);
addr= param->value.address;
if (uc->fbrk->bp_at(addr) == 0)
- con->dd_printf("No breakpoint at 0x%06x\n", addr);
+ con->dd_printf("No breakpoint at 0x%06x\n", addr);
else
- uc->fbrk->del_bp(addr);
+ uc->fbrk->del_bp(addr);
}
return(DD_FALSE);
//int
//cl_delete_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_delete_cmd)
{
if (cmdline->param(0) == 0)
int i= 0;
class cl_cmd_arg *param;
while ((param= cmdline->param(i++)))
- {
- long num;
- if (param->get_ivalue(&num))
- {
- if (!uc->rm_brk(num))
- con->dd_printf("Error\n");
- }
- }
+ {
+ long num;
+ if (param->get_ivalue(&num))
+ {
+ if (!uc->rm_brk(num))
+ con->dd_printf("Error\n");
+ }
+ }
}
return(DD_FALSE);
}
enum brk_perm perm;
COMMAND_METHODS_ON(uc,cl_break_cmd)
virtual void do_fetch(class cl_uc *uc,
- t_addr addr, int hit, class cl_console *con);
+ t_addr addr, int hit, class cl_console_base *con);
virtual void do_event(class cl_uc *uc,
- class cl_address_space *mem,
- char op, t_addr addr, int hit,
- class cl_console *con);
+ class cl_address_space *mem,
+ char op, t_addr addr, int hit,
+ class cl_console_base *con);
COMMAND_TAIL;
// TBREAK
{
public:
cl_tbreak_cmd(char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp):
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp):
cl_break_cmd(aname, can_rep, short_hlp, long_hlp) {perm=brkDYNAMIC;}
};
//int
//cl_conf_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_conf_cmd)
{
int i;
con->dd_printf("ucsim version %s\n", VERSIONSTR);
con->dd_printf("Type of microcontroller: %s\n", uc->id_string());
con->dd_printf("Controller has %d hardware element(s).\n",
- uc->hws->count);
+ uc->hws->count);
for (i= 0; i < uc->hws->count; i++)
{
class cl_hw *hw= (class cl_hw *)(uc->hws->at(i));
*/
static void
-conf_objects_cmd_print_node(class cl_console *con,
- int indent, class cl_base *node)
+conf_objects_cmd_print_node(class cl_console_base *con,
+ int indent, class cl_base *node)
{
if (!node)
return;
//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_APP(cl_conf_objects_cmd)
{
//class cl_address_space *mem= 0;
/*class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };*/
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };*/
class cl_error *cl_error_base = new cl_error();
conf_objects_cmd_print_node(con, 0, /*application*/cl_error_base->get_class());
delete cl_error_base;
//int
//cl_gui_start_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_gui_start_cmd)
{
class cl_hw *hw;
class cl_memory *mem;
t_addr start, end;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, HW)) {
hw= params[0]->value.hw;
else
{
con->dd_printf("Error: wrong syntax\n"
- "%s\n", short_help?short_help:"no help");
+ "%s\n", short_help?short_help:"no help");
}
return(DD_FALSE);;
//int
//cl_gui_stop_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_gui_stop_cmd)
{
return(DD_FALSE);;
//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_memory_createchip_cmd)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
char *memid= NULL;
int size= -1;
int width= 8;
//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_memory_createaddressspace_cmd)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
char *memid= NULL;
int start= 0, size= -1, width= 8;
else
{
class cl_address_space *mem=
- new cl_address_space(memid, start, size, width);
+ new cl_address_space(memid, start, size, width);
mem->init();
uc->address_spaces->add(mem);
mem->set_uc(uc);
//int
//cl_conf_addmem_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_memory_createaddressdecoder_cmd)
{
class cl_cmd_arg *params[5]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3),
- cmdline->param(4) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3),
+ cmdline->param(4) };
class cl_memory *as= 0, *chip= 0;
t_addr as_begin= 0, as_end= 0, chip_begin= 0;
else if (chip_begin >= chip->get_size())
con->dd_printf("Wrong chip area specification\n");
else if (as_begin < as->start_address ||
- as_end >= as->highest_valid_address())
+ as_end >= as->highest_valid_address())
con->dd_printf("Specified area is out of address space\n");
else if (as_end-as_begin > chip->get_size()-chip_begin)
con->dd_printf("Specified area is out of chip size\n");
else
{
class cl_address_decoder *d=
- new cl_address_decoder(as, chip, as_begin, as_end, chip_begin);
+ new cl_address_decoder(as, chip, as_begin, as_end, chip_begin);
((class cl_address_space *)as)->decoders->add(d);
d->activate(con);
}
//int
//cl_run_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_SIM(cl_run_cmd)
{
class cl_brk *b;
t_addr start, end;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (params[0])
if (!(params[0]->get_address(sim->uc, &start)))
{
- con->dd_printf("Error: wrong start address\n");
- return(DD_FALSE);
+ con->dd_printf("Error: wrong start address\n");
+ return(DD_FALSE);
}
if (params[1])
if (!(params[1]->get_address(sim->uc, &end)))
{
- con->dd_printf("Error: wromg end address\n");
- return(DD_FALSE);
+ con->dd_printf("Error: wromg end address\n");
+ return(DD_FALSE);
}
if (params[0])
{
if (!sim->uc->inst_at(start))
- con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start);
+ con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start);
sim->uc->PC= start;
if (params[1])
- {
- if (start == end)
- {
- con->dd_printf("Addresses must be different.\n");
- return(DD_FALSE);
- }
- if ((b= sim->uc->fbrk_at(end)))
- {
- }
- else
- {
- b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID),
- sim->uc->make_new_brknr(), end,
- brkDYNAMIC, 1);
- sim->uc->fbrk->add_bp(b);
- }
- }
+ {
+ if (start == end)
+ {
+ con->dd_printf("Addresses must be different.\n");
+ return(DD_FALSE);
+ }
+ if ((b= sim->uc->fbrk_at(end)))
+ {
+ }
+ else
+ {
+ b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID),
+ sim->uc->make_new_brknr(), end,
+ brkDYNAMIC, 1);
+ sim->uc->fbrk->add_bp(b);
+ }
+ }
}
con->dd_printf("Simulation started, PC=0x%06x\n", sim->uc->PC);
if (sim->uc->fbrk_at(sim->uc->PC))
//int
//cl_stop_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_SIM(cl_stop_cmd)
{
sim->stop(resUSER);
//int
//cl_step_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_step_cmd)
{
//printf("step %x\n",uc->PC);
//int
//cl_next_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_SIM(cl_next_cmd)
{
class cl_brk *b;
int i= 0;
de= &(sim->uc->dis_tbl()[i]);
while ((code & de->mask) != de->code &&
- de->mnemonic)
+ de->mnemonic)
{
i++;
de= &(sim->uc->dis_tbl()[i]);
{
next= sim->uc->PC + inst_len;
if (!sim->uc->fbrk_at(next))
- {
- b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID),
- sim->uc->make_new_brknr(),
- next, brkDYNAMIC, 1);
+ {
+ b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID),
+ sim->uc->make_new_brknr(),
+ next, brkDYNAMIC, 1);
- b->init();
-// sim->uc->fbrk->add_bp(b);
+ b->init();
+// sim->uc->fbrk->add_bp(b);
- sim->uc->fbrk->add(b);
- b->activate();
- }
+ sim->uc->fbrk->add(b);
+ b->activate();
+ }
if (sim->uc->fbrk_at(sim->uc->PC))
- sim->uc->do_inst(1);
+ sim->uc->do_inst(1);
sim->start(con);
//sim->uc->do_inst(-1);
}
//int
//cl_help_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_APP(cl_help_cmd)
{
class cl_sim *sim;
- class cl_commander *commander;
+ class cl_commander_base *commander;
class cl_cmdset *cmdset= 0;
int i;
class cl_cmd_arg *parm= cmdline->param(0);
if (!parm) {
for (i= 0; i < cmdset->count; i++)
{
- class cl_cmd *c= (class cl_cmd *)(cmdset->at(i));
- if (c->short_help)
- con->dd_printf("%s\n", c->short_help);
- else
- con->dd_printf("%s\n", (char*)(c->names->at(0)));
+ class cl_cmd *c= (class cl_cmd *)(cmdset->at(i));
+ if (c->short_help)
+ con->dd_printf("%s\n", c->short_help);
+ else
+ con->dd_printf("%s\n", (char*)(c->names->at(0)));
}
}
else
matches= 0;
do_set(cmdline, 0, cmdset, con);
if (matches == 1 &&
- cmd_found)
- {
- int names;
- con->dd_printf("Names of command:");
- for (names= 0; names < cmd_found->names->count; names++)
- con->dd_printf(" %s", (char*)(cmd_found->names->at(names)));
- con->dd_printf("\n");
- class cl_cmdset *subset= cmd_found->get_subcommands();
- if (subset)
- {
- con->dd_printf("\"%s\" must be followed by the name of a "
- "subcommand\nList of subcommands:\n",
- (char*)(cmd_found->names->at(0)));
- for (i= 0; i < subset->count; i++)
- {
- class cl_cmd *c=
- dynamic_cast<class cl_cmd *>(subset->object_at(i));
- con->dd_printf("%s\n", c->short_help);
- }
- }
- if (cmd_found->long_help)
- con->dd_printf("%s\n", cmd_found->long_help);
- }
+ cmd_found)
+ {
+ int names;
+ con->dd_printf("Names of command:");
+ for (names= 0; names < cmd_found->names->count; names++)
+ con->dd_printf(" %s", (char*)(cmd_found->names->at(names)));
+ con->dd_printf("\n");
+ class cl_cmdset *subset= cmd_found->get_subcommands();
+ if (subset)
+ {
+ con->dd_printf("\"%s\" must be followed by the name of a "
+ "subcommand\nList of subcommands:\n",
+ (char*)(cmd_found->names->at(0)));
+ for (i= 0; i < subset->count; i++)
+ {
+ class cl_cmd *c=
+ dynamic_cast<class cl_cmd *>(subset->object_at(i));
+ con->dd_printf("%s\n", c->short_help);
+ }
+ }
+ if (cmd_found->long_help)
+ con->dd_printf("%s\n", cmd_found->long_help);
+ }
if (!matches ||
- !cmd_found)
- con->dd_printf("No such command.\n");
+ !cmd_found)
+ con->dd_printf("No such command.\n");
//return(DD_FALSE);
/*
int pari;
for (pari= 0; pari < cmdline->nuof_params(); pari++)
- {
- class cl_cmd_arg *act_param;
- act_param= (class cl_cmd_arg *)(cmdline->param(pari));
- for (i= 0; i < cmdset->count; i++)
- {
- class cl_cmd *c= (class cl_cmd *)(cmdset->at(i));
- if (!c->name_match(act_param->s_value, DD_FALSE))
- continue;
- if (c->short_help)
- con->dd_printf("%s\n", c->short_help);
- else
- con->dd_printf("%s\n", (char*)(c->names->at(0)));
- if (pari < cmdline->nuof_params()-1)
- continue;
- cmdset= c->get_subcommands();
- if (!cmdset)
- return(DD_FALSE);
- }
- }
+ {
+ class cl_cmd_arg *act_param;
+ act_param= (class cl_cmd_arg *)(cmdline->param(pari));
+ for (i= 0; i < cmdset->count; i++)
+ {
+ class cl_cmd *c= (class cl_cmd *)(cmdset->at(i));
+ if (!c->name_match(act_param->s_value, DD_FALSE))
+ continue;
+ if (c->short_help)
+ con->dd_printf("%s\n", c->short_help);
+ else
+ con->dd_printf("%s\n", (char*)(c->names->at(0)));
+ if (pari < cmdline->nuof_params()-1)
+ continue;
+ cmdset= c->get_subcommands();
+ if (!cmdset)
+ return(DD_FALSE);
+ }
+ }
return(DD_FALSE);
*/
}
matches= 0;
for (i= 0; i < cmdset->count; i++)
{
- c= (class cl_cmd *)(cmdset->at(i));
- if (c->name_match(parm->value.string.string, DD_FALSE))
- matches++;
+ c= (class cl_cmd *)(cmdset->at(i));
+ if (c->name_match(parm->value.string.string, DD_FALSE))
+ matches++;
}
if (!matches)
con->dd_printf("No such command\n");
else if (matches > 1)
for (i= 0; i < cmdset->count; i++)
- {
- c= (class cl_cmd *)(cmdset->at(i));
- if (!c->name_match(parm->value.string.string, DD_FALSE))
- continue;
- if (c->short_help)
- con->dd_printf("%s\n", c->short_help);
- else
- con->dd_printf("%s\n", (char*)(c->names->at(0)));
- }
+ {
+ c= (class cl_cmd *)(cmdset->at(i));
+ if (!c->name_match(parm->value.string.string, DD_FALSE))
+ continue;
+ if (c->short_help)
+ con->dd_printf("%s\n", c->short_help);
+ else
+ con->dd_printf("%s\n", (char*)(c->names->at(0)));
+ }
else
for (i= 0; i < cmdset->count; i++)
- {
- c= (class cl_cmd *)(cmdset->at(i));
- if (!c->name_match(parm->value.string.string, DD_FALSE))
- continue;
- if (c->short_help)
- con->dd_printf("%s\n", c->short_help);
- else
- con->dd_printf("%s\n", (char*)(c->names->at(0)));
- int names;
- con->dd_printf("Names of command:");
- for (names= 0; names < c->names->count; names++)
- con->dd_printf(" %s", (char*)(c->names->at(names)));
- con->dd_printf("\n");
- if (c->long_help)
- con->dd_printf("%s\n", c->long_help);
- else
- con->dd_printf("%s\n", (char*)(c->names->at(0)));
- }
+ {
+ c= (class cl_cmd *)(cmdset->at(i));
+ if (!c->name_match(parm->value.string.string, DD_FALSE))
+ continue;
+ if (c->short_help)
+ con->dd_printf("%s\n", c->short_help);
+ else
+ con->dd_printf("%s\n", (char*)(c->names->at(0)));
+ int names;
+ con->dd_printf("Names of command:");
+ for (names= 0; names < c->names->count; names++)
+ con->dd_printf(" %s", (char*)(c->names->at(names)));
+ con->dd_printf("\n");
+ if (c->long_help)
+ con->dd_printf("%s\n", c->long_help);
+ else
+ con->dd_printf("%s\n", (char*)(c->names->at(0)));
+ }
}
else
con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax");
bool
cl_help_cmd::do_set(class cl_cmdline *cmdline, int pari,
- class cl_cmdset *cmdset,
- class cl_console *con)
+ class cl_cmdset *cmdset,
+ class cl_console_base *con)
{
int i;
for (i= 0; i < cmdset->count; i++)
{
class cl_cmd *cmd= dynamic_cast<class cl_cmd *>(cmdset->object_at(i));
if (!cmd)
- continue;
+ continue;
if (pari >= cmdline->nuof_params())
- return(DD_FALSE);
+ return(DD_FALSE);
class cl_cmd_arg *param= cmdline->param(pari);
if (!param)
- return(DD_FALSE);
+ return(DD_FALSE);
class cl_cmdset *next_set= cmd->get_subcommands();
if (cmd->name_match(param->s_value, DD_FALSE))
- {
- if (pari+1 >= cmdline->nuof_params())
- {
- matches++;
- cmd_found= cmd;
- if (cmd->short_help)
- con->dd_printf("%s\n", cmd->short_help);
- else
- con->dd_printf("%s\n", (char*)(cmd->names->at(0)));
- //continue;
- }
- else
- if (next_set)
- do_set(cmdline, pari+1, next_set, con);
- }
+ {
+ if (pari+1 >= cmdline->nuof_params())
+ {
+ matches++;
+ cmd_found= cmd;
+ if (cmd->short_help)
+ con->dd_printf("%s\n", cmd->short_help);
+ else
+ con->dd_printf("%s\n", (char*)(cmd->names->at(0)));
+ //continue;
+ }
+ else
+ if (next_set)
+ do_set(cmdline, pari+1, next_set, con);
+ }
}
return(DD_TRUE);
}
//int
//cl_quit_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline */*cmdline*/, class cl_console */*con*/)
+// class cl_cmdline */*cmdline*/, class cl_console_base */*con*/)
COMMAND_DO_WORK(cl_quit_cmd)
{
return(1);
//int
//cl_kill_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline */*cmdline*/, class cl_console */*con*/)
+// class cl_cmdline */*cmdline*/, class cl_console_base */*con*/)
COMMAND_DO_WORK_APP(cl_kill_cmd)
{
app->going= 0;
else
con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
- class cl_commander *c= app->get_commander();
- class cl_console *cons= con->clone_for_exec(fn);
+ class cl_commander_base *c= app->get_commander();
+ class cl_console_base *cons= con->clone_for_exec(fn);
if (cons)
{
cons->flags|= CONS_NOWELCOME;
int matches;
class cl_cmd *cmd_found;
bool do_set(class cl_cmdline *cmdline, int pari, class cl_cmdset *cmdset,
- class cl_console *con);
+ class cl_console_base *con);
COMMAND_TAIL;
COMMAND(cl_quit_cmd);
//int
//cl_stat_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_statistic_cmd)
{
class cl_hw *hw;
t_addr start= 0, end= 0;
bool addresses= DD_FALSE;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, HW)) {
hw= params[0]->value.hw;
}
else
{
- /*con->dd_printf("Error: wrong syntax\n"
- "%s\n", short_help?short_help:"no help");*/
- int i;
- unsigned long wr, ww;
- for (i= 0; i < uc->address_spaces->count; i++)
- {
- mem= (class cl_address_space *)(uc->address_spaces->at(i));
- wr= mem->get_nuof_reads();
- ww= mem->get_nuof_writes();
- con->dd_printf("%s writes= %10lu "
- "reads= %10lu "
- "(%10lu operations)\n",
- mem->get_name("mem"), ww, wr, ww+wr);
- }
+ /*con->dd_printf("Error: wrong syntax\n"
+ "%s\n", short_help?short_help:"no help");*/
+ int i;
+ unsigned long wr, ww;
+ for (i= 0; i < uc->address_spaces->count; i++)
+ {
+ mem= (class cl_address_space *)(uc->address_spaces->at(i));
+ wr= mem->get_nuof_reads();
+ ww= mem->get_nuof_writes();
+ con->dd_printf("%s writes= %10lu "
+ "reads= %10lu "
+ "(%10lu operations)\n",
+ mem->get_name("mem"), ww, wr, ww+wr);
+ }
}
if (mem)
{
- t_addr i;
- unsigned long wr, ww;
- wr= mem->get_nuof_reads();
- ww= mem->get_nuof_writes();
- if (!addresses)
- con->dd_printf("%s writes= %10lu "
- "reads= %10lu\n", mem->get_name("mem"), ww, wr);
- else
- for (i= start; i <= end; i++)
- {
- class cl_memory_cell *c= mem->get_cell(i);
- unsigned long w= c->nuof_writes, r= c->nuof_reads;
- double dr= wr?((double(r)*100.0)/double(wr)):0.0;
- double dw= ww?((double(w)*100.0)/double(ww)):0.0;
- con->dd_printf("%s[0x%06x] writes= %10lu (%6.2lf%%) "
- "reads= %10lu (%6.2lf%%)\n",
- mem->get_name("mem"), i, w, dw, r, dr);
- }
+ t_addr i;
+ unsigned long wr, ww;
+ wr= mem->get_nuof_reads();
+ ww= mem->get_nuof_writes();
+ if (!addresses)
+ con->dd_printf("%s writes= %10lu "
+ "reads= %10lu\n", mem->get_name("mem"), ww, wr);
+ else
+ for (i= start; i <= end; i++)
+ {
+ class cl_memory_cell *c= mem->get_cell(i);
+ unsigned long w= c->nuof_writes, r= c->nuof_reads;
+ double dr= wr?((double(r)*100.0)/double(wr)):0.0;
+ double dw= ww?((double(w)*100.0)/double(ww)):0.0;
+ con->dd_printf("%s[0x%06x] writes= %10lu (%6.2lf%%) "
+ "reads= %10lu (%6.2lf%%)\n",
+ mem->get_name("mem"), i, w, dw, r, dr);
+ }
}
}
//int
//cl_state_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_state_cmd)
{
con->dd_printf("CPU state= %s PC= 0x%06x XTAL= %g\n",
- get_id_string(cpu_states, uc->state),
- uc->PC,
- uc->xtal);
+ get_id_string(cpu_states, uc->state),
+ uc->PC,
+ uc->xtal);
con->dd_printf("Total time since last reset= %g sec (%lu clks)\n",
- uc->get_rtime(), uc->ticks->ticks);
+ uc->get_rtime(), uc->ticks->ticks);
con->dd_printf("Time in isr = %g sec (%lu clks) %3.2g%%\n",
- uc->isr_ticks->get_rtime(uc->xtal),
- uc->isr_ticks->ticks,
- (uc->ticks->ticks == 0)?0.0:
- (100.0*((double)(uc->isr_ticks->ticks)/
- (double)(uc->ticks->ticks))));
+ uc->isr_ticks->get_rtime(uc->xtal),
+ uc->isr_ticks->ticks,
+ (uc->ticks->ticks == 0)?0.0:
+ (100.0*((double)(uc->isr_ticks->ticks)/
+ (double)(uc->ticks->ticks))));
con->dd_printf("Time in idle= %g sec (%lu clks) %3.2g%%\n",
- uc->idle_ticks->get_rtime(uc->xtal),
- uc->idle_ticks->ticks,
- (uc->ticks->ticks == 0)?0.0:
- (100.0*((double)(uc->idle_ticks->ticks)/
- (double)(uc->ticks->ticks))));
+ uc->idle_ticks->get_rtime(uc->xtal),
+ uc->idle_ticks->ticks,
+ (uc->ticks->ticks == 0)?0.0:
+ (100.0*((double)(uc->idle_ticks->ticks)/
+ (double)(uc->ticks->ticks))));
con->dd_printf("Max value of stack pointer= 0x%06x, avg= 0x%06x\n",
- uc->sp_max, uc->sp_avg);
+ uc->sp_max, uc->sp_avg);
return(0);
}
//int
//cl_file_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_file_cmd)
{
char *fname= 0;
//int
//cl_dl_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_dl_cmd)
{
long l;
//int
//cl_pc_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_pc_cmd)
{
t_addr addr;
if (params[0])
{
if (!(params[0]->get_address(uc, &addr)))
- {
- con->dd_printf("Error: wrong parameter\n");
- return(DD_FALSE);
- }
+ {
+ con->dd_printf("Error: wrong parameter\n");
+ return(DD_FALSE);
+ }
class cl_address_space *rom= uc->address_space(MEM_ROM_ID);
if (rom)
- {
- if (addr > rom->highest_valid_address())
- addr= rom->highest_valid_address();
- }
+ {
+ if (addr > rom->highest_valid_address())
+ addr= rom->highest_valid_address();
+ }
if (!uc->inst_at(addr))
- con->dd_printf("Warning: maybe not instruction at 0x%06x\n", addr);
+ con->dd_printf("Warning: maybe not instruction at 0x%06x\n", addr);
uc->PC= addr;
}
uc->print_disass(uc->PC, con);
//int
//cl_reset_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_reset_cmd)
{
uc->reset();
//int
//cl_dump_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_dump_cmd)
{
class cl_memory *mem= 0;
long bpl= 8;
t_addr start= 0, end;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (params[0] &&
params[0]->as_bit(uc))
{
int i= 0;
while (params[0] &&
- params[0]->as_bit(uc))
- {
- t_mem m;
- mem= params[0]->value.bit.mem;
- m= mem->read(params[0]->value.bit.mem_address);
- char *sn=
- uc->symbolic_bit_name((t_addr)-1,
- mem,
- params[0]->value.bit.mem_address,
- params[0]->value.bit.mask);
- con->dd_printf("%10s ", sn?sn:"");
- con->dd_printf(mem->addr_format, params[0]->value.bit.mem_address);
- con->dd_printf(" ");
- con->dd_printf(mem->data_format, m);
- con->dd_printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0');
- i++;
- params[0]= cmdline->param(i);
- }
+ params[0]->as_bit(uc))
+ {
+ t_mem m;
+ mem= params[0]->value.bit.mem;
+ m= mem->read(params[0]->value.bit.mem_address);
+ char *sn=
+ uc->symbolic_bit_name((t_addr)-1,
+ mem,
+ params[0]->value.bit.mem_address,
+ params[0]->value.bit.mask);
+ con->dd_printf("%10s ", sn?sn:"");
+ con->dd_printf(mem->addr_format, params[0]->value.bit.mem_address);
+ con->dd_printf(" ");
+ con->dd_printf(mem->data_format, m);
+ con->dd_printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0');
+ i++;
+ params[0]= cmdline->param(i);
+ }
if (params[0])
- con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+ con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
}
else
{
if (!params[0] ||
- !params[0]->as_memory(uc))
- {
- con->dd_printf("No memory specified. Use \"info memory\" for available memories\n");
- return(DD_FALSE);
- }
+ !params[0]->as_memory(uc))
+ {
+ con->dd_printf("No memory specified. Use \"info memory\" for available memories\n");
+ return(DD_FALSE);
+ }
if (cmdline->syntax_match(uc, MEMORY))
- {
- mem= params[0]->value.memory.memory;
- mem->dump(con);
- }
+ {
+ mem= params[0]->value.memory.memory;
+ mem->dump(con);
+ }
else if (cmdline->syntax_match(uc, MEMORY ADDRESS)) {
- mem = params[0]->value.memory.memory;
- start= params[1]->value.address;
- end = start+10*8-1;
- mem->dump(start, end, bpl, con);
+ mem = params[0]->value.memory.memory;
+ start= params[1]->value.address;
+ end = start+10*8-1;
+ mem->dump(start, end, bpl, con);
}
else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) {
- mem = params[0]->value.memory.memory;
- start= params[1]->value.address;
- end = params[2]->value.address;
- mem->dump(start, end, bpl, con);
+ mem = params[0]->value.memory.memory;
+ start= params[1]->value.address;
+ end = params[2]->value.address;
+ mem->dump(start, end, bpl, con);
}
else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
- mem = params[0]->value.memory.memory;
- start= params[1]->value.address;
- end = params[2]->value.address;
- bpl = params[3]->value.number;
- mem->dump(start, end, bpl, con);
+ mem = params[0]->value.memory.memory;
+ start= params[1]->value.address;
+ end = params[2]->value.address;
+ bpl = params[3]->value.number;
+ mem->dump(start, end, bpl, con);
}
else
- con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
+ con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n");
}
return(DD_FALSE);;
//int
//cl_di_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_di_cmd)
{
cmdline->insert_param(0, new cl_cmd_sym_arg("iram"));
//int
//cl_dx_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_dx_cmd)
{
cmdline->insert_param(0, new cl_cmd_sym_arg("xram"));
//int
//cl_dch_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_dch_cmd)
{
cmdline->insert_param(0, new cl_cmd_sym_arg("rom"));
//int
//cl_ds_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_ds_cmd)
{
cmdline->insert_param(0, new cl_cmd_sym_arg("sfr"));
//int
//cl_dc_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_dc_cmd)
{
t_addr start= last, end= last+20;
class cl_cmd_arg *params[2]= { cmdline->param(0),
- cmdline->param(1) };
+ cmdline->param(1) };
class cl_address_space *rom= uc->address_space(MEM_ROM_ID);
if (!rom)
//int
//cl_disassemble_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_disassemble_cmd)
{
t_addr start, realstart;
int offset= -1, dir, lines= 20;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
start= disass_last_stop;
if (params[0] == 0) ;
if (!rom)
return(DD_FALSE);
while (realstart <= rom->highest_valid_address() &&
- !uc->inst_at(realstart))
+ !uc->inst_at(realstart))
realstart= realstart+1;
if (offset)
{
dir= (offset < 0)?-1:+1;
while (offset)
- {
- realstart= rom->inc_address(realstart, dir);
- while (!uc->inst_at(realstart))
- realstart= rom->inc_address(realstart, dir);
- offset+= -dir;
- }
+ {
+ realstart= rom->inc_address(realstart, dir);
+ while (!uc->inst_at(realstart))
+ realstart= rom->inc_address(realstart, dir);
+ offset+= -dir;
+ }
}
while (lines)
uc->print_disass(realstart, con);
realstart= rom->inc_address(realstart, +1) + rom->start_address;
while (!uc->inst_at(realstart))
- realstart= rom->inc_address(realstart, +1) + rom->start_address;
+ realstart= rom->inc_address(realstart, +1) + rom->start_address;
lines--;
}
//int
//cl_fill_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_fill_cmd)
{
class cl_memory *mem= 0;
t_mem what= 0;
t_addr start= 0, end;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) {
mem = params[0]->value.memory.memory;
t_addr i;
for (i= start; i <= end; i++)
{
- t_mem d;
- d= what;
- mem->write(i, d);
+ t_mem d;
+ d= what;
+ mem->write(i, d);
}
}
else
int
cl_where_cmd::do_real_work(class cl_uc *uc,
- class cl_cmdline *cmdline, class cl_console *con,
- bool case_sensitive)
+ class cl_cmdline *cmdline, class cl_console_base *con,
+ bool case_sensitive)
{
class cl_memory *mem= 0;
class cl_cmd_arg *params[2]= { cmdline->param(0),
- cmdline->param(1) };
+ cmdline->param(1) };
if (cmdline->syntax_match(uc, MEMORY DATALIST)) {
mem= params[0]->value.memory.memory;
int len= params[1]->value.data_list.len;
if (!len)
{
- con->dd_printf("Error: nothing to search for\n");
- return(DD_FALSE);
+ con->dd_printf("Error: nothing to search for\n");
+ return(DD_FALSE);
}
t_addr addr= 0;
bool found= mem->search_next(case_sensitive, array, len, &addr);
while (found)
{
- mem->dump(addr, addr+len-1, 8, con);
- addr++;
- found= mem->search_next(case_sensitive, array, len, &addr);
+ mem->dump(addr, addr+len-1, 8, con);
+ addr++;
+ found= mem->search_next(case_sensitive, array, len, &addr);
}
}
else
//int
//cl_where_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_where_cmd)
{
return(do_real_work(uc, cmdline, con, DD_FALSE));
//int
//cl_Where_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_Where_cmd)
{
return(do_real_work(uc, cmdline, con, DD_TRUE));
public: int last;
COMMAND_METHODS_ON(uc,cl_where_cmd)
virtual int do_real_work(class cl_uc *uc,
- class cl_cmdline *cmdline, class cl_console *con,
- bool case_sensitive);
+ class cl_cmdline *cmdline, class cl_console_base *con,
+ bool case_sensitive);
COMMAND_TAIL;
COMMAND_DATA_ANCESTOR_ON(uc,cl_Where_cmd,cl_where_cmd,int last);
* Simulator of microcontrollers (cmd.src/cmdutil.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+#include <assert.h>
#include <sys/types.h>
#ifdef SOCKET_AVAIL
# include HEADER_SOCKET
# include <arpa/inet.h>
# endif
#endif
+#ifdef _WIN32
+#include <malloc.h>
+#endif
+
#include "i_string.h"
#include "stypes.h"
#include "globals.h"
#include "uccl.h"
+#include "cmdutil.h"
/*
*/
#ifdef SOCKET_AVAIL
+#ifdef _WIN32
+static void
+init_winsock(void)
+{
+ static bool is_initialized = false;
+
+ if (!is_initialized)
+ {
+ WSADATA wsaData;
+
+ // Initialize Winsock
+ int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
+ if (iResult != 0)
+ {
+ printf("WSAStartup failed: %d\n", iResult);
+ exit(1);
+ }
+ }
+}
+
+SOCKET
+make_server_socket(unsigned short int port)
+{
+ init_winsock();
+
+ struct sockaddr_in name;
+
+ /* Create the socket. */
+ SOCKET sock = WSASocket(PF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
+ if (INVALID_SOCKET == sock)
+ {
+ fprintf(stderr, "socket: %d\n", WSAGetLastError());
+ return INVALID_SOCKET;
+ }
+
+ name.sin_family = AF_INET;
+ name.sin_port = htons(port);
+ name.sin_addr.s_addr= htonl(INADDR_ANY);
+ if (SOCKET_ERROR == bind(sock, (struct sockaddr *)&name, sizeof(name)))
+ {
+ fprintf(stderr, "bind: %d\n", WSAGetLastError());
+ return INVALID_SOCKET;
+ }
+
+ return sock;
+}
+#else
int
make_server_socket(unsigned short int port)
{
int sock, i;
struct sockaddr_in name;
-
+
/* Create the socket. */
sock= socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0)
perror("socket");
return(0);
}
-
+
/* Give the socket a name. */
i= 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&i, sizeof(i)) < 0)
return(sock);
}
#endif
+#endif
+#if _WIN32
+enum e_handle_type
+get_handle_type(HANDLE handle)
+{
+ DWORD file_type = GetFileType(handle);
-/*
- * Printing out an integer in binary format
- */
+ switch (file_type)
+ {
+ case FILE_TYPE_CHAR:
+ {
+ DWORD err;
+
+ if (!ClearCommError(handle, &err, NULL))
+ {
+ if (ERROR_INVALID_HANDLE == GetLastError())
+ return CH_CONSOLE;
+ }
+ }
+ return CH_SERIAL;
+
+ case FILE_TYPE_DISK:
+ return CH_FILE;
+ }
+
+ char sockbuf[256];
+ int optlen = sizeof(sockbuf);
-/*void
-print_bin(long data, int bits, class cl_console *con)
+ if (SOCKET_ERROR != getsockopt((SOCKET)handle, SOL_SOCKET, SO_TYPE, sockbuf, &optlen) ||
+ WSAENOTSOCK != WSAGetLastError())
+ return CH_SOCKET;
+
+ assert(false);
+ return CH_UNDEF;
+}
+
+bool
+input_avail(HANDLE handle, e_handle_type type)
{
- long mask= 1;
+ if (CH_UNDEF == type)
+ type = get_handle_type(handle);
- mask= mask << ((bits >= 1)?(bits-1):0);
- while (bits--)
+ switch (type)
{
- con->printf("%c", (data&mask)?'1':'0');
- mask>>= 1;
+ case CH_SOCKET:
+ {
+ struct timeval tv = {0, 0};
+
+ assert(INVALID_HANDLE_VALUE != handle);
+
+ fd_set s;
+ FD_ZERO(&s);
+ FD_SET((SOCKET)handle, &s);
+
+ int ret = select(0, &s, NULL, NULL, &tv);
+ if (SOCKET_ERROR == ret)
+ fprintf(stderr, "Can't select: %d\n", WSAGetLastError());
+
+ return ret != SOCKET_ERROR && ret != 0;
+ }
+
+ case CH_FILE:
+ return true;
+
+ case CH_CONSOLE:
+ {
+ PINPUT_RECORD pIRBuf;
+ DWORD NumPending;
+ DWORD NumPeeked;
+
+ /*
+ * Peek all pending console events
+ */
+ if (INVALID_HANDLE_VALUE == handle ||
+ !GetNumberOfConsoleInputEvents(handle, &NumPending) ||
+ NumPending == 0 ||
+ NULL == (pIRBuf = (PINPUT_RECORD)_alloca(NumPending * sizeof(INPUT_RECORD))))
+ return FALSE;
+
+ if (PeekConsoleInput(handle, pIRBuf, NumPending, &NumPeeked) &&
+ NumPeeked != 0L &&
+ NumPeeked <= NumPending)
+ {
+
+ /*
+ * Scan all of the peeked events to determine if any is a key event
+ * which should be recognized.
+ */
+ for ( ; NumPeeked > 0 ; NumPeeked--, pIRBuf++ )
+ {
+ if (KEY_EVENT == pIRBuf->EventType &&
+ pIRBuf->Event.KeyEvent.bKeyDown &&
+ pIRBuf->Event.KeyEvent.uChar.AsciiChar)
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ case CH_SERIAL:
+ {
+ DWORD err;
+ COMSTAT comStat;
+
+ bool res = ClearCommError(handle, &err, &comStat);
+ assert(res);
+
+ return res ? comStat.cbInQue > 0 : false;
+ }
+
+ default:
+ assert(false);
+ return false;
}
-}*/
+}
+#else
+bool
+input_avail(UCSOCKET_T fd)
+{
+ assert(0 <= fd);
+
+ fd_set s;
+ FD_ZERO(&s);
+ FD_SET(fd, &s);
+
+ struct timeval tv = {0, 0};
+ int i = select(fd + 1, &s, NULL, NULL, &tv);
+ if (i < 0)
+ perror("select");
+
+ return i > 0;
+}
+#endif
/*
* Searching for a name in the specified table
char *sym, bitnumstr[2];
struct name_entry *ne;
int bitnum, i;
-
+
if ((dot= strchr(name, '.')) != NULL)
{
*dot++= '\0';
* Simulator of microcontrollers (cmd.src/cmdutil.h)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#ifndef CMD_CMDUTIL_HEADER
#define CMD_CMDUTIL_HEADER
+#ifdef SOCKET_AVAIL
+# include HEADER_SOCKET
+#endif
+
#include "ddconfig.h"
#include "uccl.h"
-
-extern int make_server_socket(unsigned short int port);
-//extern void print_bin(long data, int bits, class cl_console *con);
+#ifdef SOCKET_AVAIL
+extern UCSOCKET_T make_server_socket(unsigned short int port);
+#endif
+#ifdef _WIN32
+enum e_handle_type { CH_UNDEF, CH_FILE, CH_SOCKET, CH_CONSOLE, CH_SERIAL,};
+enum e_handle_type get_handle_type(HANDLE handle);
+bool input_avail(HANDLE handle, e_handle_type type = CH_UNDEF);
+#else
+bool input_avail(UCSOCKET_T handle);
+#endif
+//extern void print_bin(long data, int bits, class cl_console_base *con);
extern struct name_entry *get_name_entry(struct name_entry tabl[],
char *name,
class cl_uc *uc);
*/
cl_cmdline::cl_cmdline(class cl_app *the_app,
- char *acmd, class cl_console *acon):
+ char *acmd, class cl_console_base *acon):
cl_base()
{
app= the_app;
cl_cmdline::skip_delims(char *start)
{
while (*start &&
- strchr(" \t\v\r,", *start))
+ strchr(" \t\v\r,", *start))
start++;
return(start);
}
{
char *end= start, *param_str;
if (*start == '"')
- split_out_string(&start, &end);
+ split_out_string(&start, &end);
else if (*start == '>')
- split_out_output_redirection(&start, &end);
+ split_out_output_redirection(&start, &end);
else
- {
- char *dot;
+ {
+ char *dot;
i= strcspn(start, " \t\v\r,");
end= start+i;
param_str= (char *)malloc(i+1);
strncpy(param_str, start, i);
- param_str[i]= '\0';
- tokens->add(strdup(param_str));
- if ((dot= strchr(param_str, '.')) != NULL)
- split_out_bit(dot, param_str);
- else if ((dot= strchr(param_str, '[')) != NULL)
- split_out_array(dot, param_str);
- else if (strchr("0123456789-+", *param_str) != NULL)
- {
- // number
- params->add(arg= new cl_cmd_int_arg((long)
- strtol(param_str, 0, 0)));
- arg->init();
- }
- else
- {
- // symbol
- params->add(arg= new cl_cmd_sym_arg(param_str));
- arg->init();
- }
- free(param_str);
- }
+ param_str[i]= '\0';
+ tokens->add(strdup(param_str));
+ if ((dot= strchr(param_str, '.')) != NULL)
+ split_out_bit(dot, param_str);
+ else if ((dot= strchr(param_str, '[')) != NULL)
+ split_out_array(dot, param_str);
+ else if (strchr("0123456789-+", *param_str) != NULL)
+ {
+ // number
+ params->add(arg= new cl_cmd_int_arg((long)
+ strtol(param_str, 0, 0)));
+ arg->init();
+ }
+ else
+ {
+ // symbol
+ params->add(arg= new cl_cmd_sym_arg(param_str));
+ arg->init();
+ }
+ free(param_str);
+ }
start= end;
start= skip_delims(start);
}
if (s && *s)
{
while (*s &&
- strchr(" \t\v\r,", *s) == NULL)
- s++;
+ strchr(" \t\v\r,", *s) == NULL)
+ s++;
s= skip_delims(s);
char *p= strdup(s);
free(cmd);
params= new cl_list(2, 2, "params");
split();
if (strcmp(get_name(), "\n") == 0)
- set_name(0);
+ set_name(0);
}
return(have_real_name());
}
{
char *n;
return((n= get_name()) &&
- *n == '\n');
+ *n == '\n');
}
class cl_cmd_arg *
int iparam= 0;
class cl_cmd_arg *parm= (class cl_cmd_arg *)(params->at(iparam));
while (*p &&
- parm)
+ parm)
{
//printf("***Checking %s as %c\n",parm->get_svalue(),*p);
if (uc)
- switch (*p)
- {
- case SY_ADDR:
- if (!parm->as_address(uc))
- return(DD_FALSE);
- //printf("ADDRESS match %lx\n",parm->value.address);
- break;
- case SY_MEMORY:
- if (!parm->as_memory(uc))
- return(DD_FALSE);
- //printf("MEMORY match %s\n",parm->value.memory->class_name);
- break;
- case SY_BIT:
- if (!parm->as_bit(uc))
- return(DD_FALSE);
- break;
- }
+ switch (*p)
+ {
+ case SY_ADDR:
+ if (!parm->as_address(uc))
+ return(DD_FALSE);
+ //printf("ADDRESS match %lx\n",parm->value.address);
+ break;
+ case SY_MEMORY:
+ if (!parm->as_memory(uc))
+ return(DD_FALSE);
+ //printf("MEMORY match %s\n",parm->value.memory->class_name);
+ break;
+ case SY_BIT:
+ if (!parm->as_bit(uc))
+ return(DD_FALSE);
+ break;
+ }
switch (*p)
- {
- case SY_ADDR: case SY_MEMORY: case SY_BIT: break;
- case SY_NUMBER:
- if (!parm->as_number())
- return(DD_FALSE);
- break;
- case SY_DATA:
- if (!parm->as_data())
- return(DD_FALSE);
- break;
- case SY_HW:
- if (!parm->as_hw(uc))
- return(DD_FALSE);
- break;
- case SY_STRING:
- if (!parm->as_string())
- return(DD_FALSE);
- break;
- case SY_DATALIST:
- if (!set_data_list(parm, &iparam))
- return(DD_FALSE);
- break;
- default:
- return(DD_FALSE);
- }
+ {
+ case SY_ADDR: case SY_MEMORY: case SY_BIT: break;
+ case SY_NUMBER:
+ if (!parm->as_number())
+ return(DD_FALSE);
+ break;
+ case SY_DATA:
+ if (!parm->as_data())
+ return(DD_FALSE);
+ break;
+ case SY_HW:
+ if (!parm->as_hw(uc))
+ return(DD_FALSE);
+ break;
+ case SY_STRING:
+ if (!parm->as_string())
+ return(DD_FALSE);
+ break;
+ case SY_DATALIST:
+ if (!set_data_list(parm, &iparam))
+ return(DD_FALSE);
+ break;
+ default:
+ return(DD_FALSE);
+ }
p++;
iparam++;
if (iparam < params->count)
- parm= (class cl_cmd_arg *)(params->at(iparam));
+ parm= (class cl_cmd_arg *)(params->at(iparam));
else
- parm= 0;
+ parm= 0;
}
if (!*p &&
!parm)
for (i= *iparm, next_parm= param(i); next_parm; i++, next_parm= param(i))
{
if (next_parm->is_string())
- {
- int l;
- char *s;
- //s= proc_escape(next_parm->get_svalue(), &l);
- if (!next_parm->as_string())
- continue;
- s= next_parm->value.string.string;
- l= next_parm->value.string.len;
- if (!array)
- array= (t_mem*)malloc(sizeof(t_mem)*l);
- else
- array= (t_mem*)realloc(array, sizeof(t_mem)*(l+len));
- for (j= 0; j < l; j++)
- {
- array[len]= s[j];
- len++;
- }
- //if (s)
- //free(s);
- }
+ {
+ int l;
+ char *s;
+ //s= proc_escape(next_parm->get_svalue(), &l);
+ if (!next_parm->as_string())
+ continue;
+ s= next_parm->value.string.string;
+ l= next_parm->value.string.len;
+ if (!array)
+ array= (t_mem*)malloc(sizeof(t_mem)*l);
+ else
+ array= (t_mem*)realloc(array, sizeof(t_mem)*(l+len));
+ for (j= 0; j < l; j++)
+ {
+ array[len]= s[j];
+ len++;
+ }
+ //if (s)
+ //free(s);
+ }
else
- {
- if (!next_parm->as_data())
- {
- if (array)
- free(array);
- return(DD_FALSE);
- }
- if (!array)
- array= (t_mem*)malloc(sizeof(t_mem));
- else
- array= (t_mem*)realloc(array, sizeof(t_mem)*(1+len));
- array[len]= next_parm->value.data;
- len++;
- }
+ {
+ if (!next_parm->as_data())
+ {
+ if (array)
+ free(array);
+ return(DD_FALSE);
+ }
+ if (!array)
+ array= (t_mem*)malloc(sizeof(t_mem));
+ else
+ array= (t_mem*)realloc(array, sizeof(t_mem)*(1+len));
+ array[len]= next_parm->value.data;
+ len++;
+ }
}
*iparm= i;
parm->value.data_list.array= array;
*/
cl_cmd::cl_cmd(enum cmd_operate_on op_on,
- char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp):
+ char *aname,
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp):
cl_base()
{
operate_on= op_on;
if (strict)
{
for (i= 0; i < names->count; i++)
- {
- char *n= (char*)(names->at(i));
- if (strcmp(aname, n) == 0)
- return(1);
- }
+ {
+ char *n= (char*)(names->at(i));
+ if (strcmp(aname, n) == 0)
+ return(1);
+ }
}
else
{
for (i= 0; i < names->count; i++)
- {
- char *n= (char*)(names->at(i));
- if (strstr(n, aname) == n)
- return(1);
- }
+ {
+ char *n= (char*)(names->at(i));
+ if (strstr(n, aname) == n)
+ return(1);
+ }
}
return(0);
}
int
cl_cmd::work(class cl_app *app,
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
{
if (!syntax_ok(cmdline))
return(0);
{
case operate_on_app:
if (!app)
- {
- con->dd_printf("There is no application to work on!\n");
- return(DD_TRUE);
- }
+ {
+ con->dd_printf("There is no application to work on!\n");
+ return(DD_TRUE);
+ }
return(do_work(app, cmdline, con));
case operate_on_sim:
if (!sim)
- {
- con->dd_printf("There is no simulator to work on!\n");
- return(DD_TRUE);
- }
+ {
+ con->dd_printf("There is no simulator to work on!\n");
+ return(DD_TRUE);
+ }
return(do_work(sim, cmdline, con));
case operate_on_uc:
if (!sim)
- {
- con->dd_printf("There is no microcontroller to work on!\n");
- return(DD_TRUE);
- }
+ {
+ con->dd_printf("There is no microcontroller to work on!\n");
+ return(DD_TRUE);
+ }
return(do_work(uc, cmdline, con));
default:
return(do_work(cmdline, con));
}
int
-cl_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con)
+cl_cmd::do_work(class cl_cmdline *cmdline, class cl_console_base *con)
{
con->dd_printf("Command \"%s\" does nothing.\n",
- (char*)(names->at(0)));
+ (char*)(names->at(0)));
return(0);
}
int
cl_cmd::do_work(class cl_app *app,
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
{
con->dd_printf("Command \"%s\" does nothing on application.\n",
- (char*)(names->at(0)));
+ (char*)(names->at(0)));
return(0);
}
int
cl_cmd::do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
{
con->dd_printf("Command \"%s\" does nothing on simulator.\n",
- (char*)(names->at(0)));
+ (char*)(names->at(0)));
return(0);
}
int
cl_cmd::do_work(class cl_uc *uc,
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
{
con->dd_printf("Command \"%s\" does nothing on microcontroller.\n",
- (char*)(names->at(0)));
+ (char*)(names->at(0)));
return(0);
}
{
class cl_cmd *c= (class cl_cmd *)at(i);
if (c->name_match(cmdline, 1))
- return(c);
+ return(c);
}
// not exact match
class cl_cmd *c_matched= 0;
{
class cl_cmd *c= (class cl_cmd *)at(i);
if (c->name_match(cmdline, 0))
- {
- if (!c_matched)
- c_matched= c;
- else
- return(0);
- }
+ {
+ if (!c_matched)
+ c_matched= c;
+ else
+ return(0);
+ }
}
return(c_matched);
//return(0);
{
class cl_cmd *c= (class cl_cmd *)at(i);
if (c->name_match(cmd_name, 1))
- return(c);
+ return(c);
}
return(0);
}
{
class cl_cmd *cmd= (class cl_cmd *)(at(i));
if (cmd->name_match(nam, 1))
- free_at(i);
+ free_at(i);
}
}
{
class cl_cmd *c= (class cl_cmd *)(at(i));
if (c->name_match(nam, 1))
- {
- delete c;
- put_at(i, cmd);
- }
+ {
+ delete c;
+ put_at(i, cmd);
+ }
}
}
*/
cl_super_cmd::cl_super_cmd(char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp,
- class cl_cmdset *acommands):
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp,
+ class cl_cmdset *acommands):
cl_cmd(operate_on_none, aname, can_rep, short_hlp, long_hlp)
{
commands= acommands;
int
cl_super_cmd::work(class cl_app *app,
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
{
class cl_cmd *cmd= 0;
if (!cmdline->shift())
{
if ((cmd= commands->get_cmd("_no_parameters_")) != 0)
- return(cmd->work(app, cmdline, con));
+ return(cmd->work(app, cmdline, con));
int i;
con->dd_printf("\"%s\" must be followed by the name of a subcommand\n"
- "List of subcommands:\n", (char*)(names->at(0)));
+ "List of subcommands:\n", (char*)(names->at(0)));
for (i= 0; i < commands->count; i++)
- {
- cmd= (class cl_cmd *)(commands->at(i));
- con->dd_printf("%s\n", cmd->short_help);
- }
+ {
+ cmd= (class cl_cmd *)(commands->at(i));
+ con->dd_printf("%s\n", cmd->short_help);
+ }
return(0);
}
if ((cmd= commands->get_cmd(cmdline, con->accept_last())) == NULL)
{
con->dd_printf("Undefined subcommand: \"%s\". Try \"help %s\".\n",
- cmdline->get_name(), (char*)(names->at(0)));
+ cmdline->get_name(), (char*)(names->at(0)));
return(0);
}
return(cmd->work(app, cmdline, con));
class cl_list *params;
class cl_ustrings *tokens;
char *matched_syntax;
- class cl_console *con;
+ class cl_console_base *con;
public:
- cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon);
+ cl_cmdline(class cl_app *the_app, char *acmd, class cl_console_base *acon);
virtual ~cl_cmdline(void);
virtual int init(void);
public:
cl_cmd(enum cmd_operate_on opon,
- char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp);
+ char *aname,
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp);
virtual ~cl_cmd(void);
virtual class cl_cmdset *get_subcommands(void) { return(0); }
virtual int name_match(class cl_cmdline *cmdline, int strict);
virtual int syntax_ok(class cl_cmdline *cmdline);
virtual int work(class cl_app *app,
- class cl_cmdline *cmdline, class cl_console *con);
- virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
+ virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_app *app,
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
virtual int do_work(class cl_uc *uc,
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
};
#define COMMAND_HEAD(CLASS_NAME) \
char *short_help,\
char *long_help):\
cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\
- virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
+ virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);
#define COMMAND_METHODS_ON(ON,CLASS_NAME) \
public:\
char *long_help):\
cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\
virtual int do_work(class cl_ ## ON * ON ,\
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
#define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \
public:\
char *short_help,\
char *long_help):\
ANCESTOR (aname, can_rep, short_help, long_help) {}\
- virtual int do_work(class cl_cmdline *cmdline, class cl_console *con);
+ virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con);
#define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \
public:\
char *long_help):\
ANCESTOR (aname, can_rep, short_help, long_help) {}\
virtual int do_work(class cl_ ## ON * ON ,\
- class cl_cmdline *cmdline, class cl_console *con); \
+ class cl_cmdline *cmdline, class cl_console_base *con); \
#define COMMAND_TAIL }
#define COMMAND_DO_WORK(CLASS_NAME) \
int \
-CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con)
+CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console_base *con)
#define COMMAND_DO_WORK_APP(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_app *app,\
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
#define COMMAND_DO_WORK_SIM(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_sim *sim,\
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
#define COMMAND_DO_WORK_UC(CLASS_NAME) \
int \
CLASS_NAME::do_work(class cl_uc *uc,\
- class cl_cmdline *cmdline, class cl_console *con)
+ class cl_cmdline *cmdline, class cl_console_base *con)
// Command set is list of cl_cmd objects
class cl_cmdset: public cl_list
public:
cl_super_cmd(char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp,
- class cl_cmdset *acommands);
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp,
+ class cl_cmdset *acommands);
virtual ~cl_super_cmd(void);
virtual class cl_cmdset *get_subcommands(void) { return(commands); }
virtual int work(class cl_app *app,
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
};
* Simulator of microcontrollers (cmd.src/get.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
//int
//cl_get_sfr_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_get_sfr_cmd)
{
class cl_address_space *mem= uc->address_space(MEM_SFR_ID);
i++, parm= cmdline->param(i))
{
if (!parm->as_address(uc) ||
- !mem->valid_address(parm->value.address))
- con->dd_printf("Warning: Invalid address %s\n",
- (char*)cmdline->tokens->at(i+1));
+ !mem->valid_address(parm->value.address))
+ con->dd_printf("Warning: Invalid address %s\n",
+ (char*)cmdline->tokens->at(i+1));
else
- mem->dump(parm->value.address, parm->value.address, 1, con);
+ mem->dump(parm->value.address, parm->value.address, 1, con);
}
return(DD_FALSE);;
//int
//cl_get_option_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_APP(cl_get_option_cmd)
{
class cl_cmd_arg *parm= cmdline->param(0);
{
class cl_option *o= (class cl_option *)(/*uc*/app->options->at(i));
if ((!s ||
- !strcmp(s, o->get_name())))
- {
- if (!o->hidden)
- {
- con->dd_printf("%2d. %s(by %s): ", i, object_name(o),
- object_name(o->get_creator()));
- o->print(con);
- con->dd_printf(" - %s\n", o->help);
- }
- else
- {
- /*
- con->dd_printf("%2d. %s(by %s) is hidden!\n", i, object_name(o),
- object_name(o->get_creator()));
- */
- }
- }
+ !strcmp(s, o->get_name())))
+ {
+ if (!o->hidden)
+ {
+ con->dd_printf("%2d. %s(by %s): ", i, object_name(o),
+ object_name(o->get_creator()));
+ o->print(con);
+ con->dd_printf(" - %s\n", o->help);
+ }
+ else
+ {
+ /*
+ con->dd_printf("%2d. %s(by %s) is hidden!\n", i, object_name(o),
+ object_name(o->get_creator()));
+ */
+ }
+ }
}
-
+
return(DD_FALSE);;
}
{
public:
cl_get_sfr_cmd(//class cl_sim *asim,
- char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp):
+ char *aname,
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp):
cl_cmd(aname, can_rep, short_hlp, long_hlp) {}
virtual int do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
};*/
COMMAND_ON(uc,cl_get_sfr_cmd);
{
public:
cl_get_option_cmd(//class cl_sim *asim,
- char *aname,
- int can_rep,
- char *short_hlp,
- char *long_hlp):
+ char *aname,
+ int can_rep,
+ char *short_hlp,
+ char *long_hlp):
cl_cmd(aname, can_rep, short_hlp, long_hlp) {}
virtual int do_work(class cl_sim *sim,
- class cl_cmdline *cmdline, class cl_console *con);
+ class cl_cmdline *cmdline, class cl_console_base *con);
};*/
COMMAND_ON(app,cl_get_option_cmd);
//int
//cl_info_bp_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_info_bp_cmd)
{
int i;
class cl_brk *fb= (class cl_brk *)(uc->fbrk->at(i));
s= uc->disass(fb->addr, NULL);
con->dd_printf("%-3d %-10s %s %-5d %-5d 0x%06x %s\n", fb->nr,
- "fetch", (fb->perm==brkFIX)?"keep":"del ",
- fb->hit, fb->cnt,
- fb->addr, s);
+ "fetch", (fb->perm==brkFIX)?"keep":"del ",
+ fb->hit, fb->cnt,
+ fb->addr, s);
free(s);
}
for (i= 0; i < uc->ebrk->count; i++)
{
class cl_ev_brk *eb= (class cl_ev_brk *)(uc->ebrk->at(i));
con->dd_printf("%-3d %-10s %s %-5d %-5d 0x%06x %s\n", eb->nr,
- "event", (eb->perm==brkFIX)?"keep":"del ",
- eb->hit, eb->cnt,
- eb->addr, eb->id);
+ "event", (eb->perm==brkFIX)?"keep":"del ",
+ eb->hit, eb->cnt,
+ eb->addr, eb->id);
}
/*t_addr a;
class cl_rom *r= (class cl_rom *)(sim->uc->mem(MEM_ROM));
for (a= 0; a < sim->uc->get_mem_size(MEM_ROM); a++)
{
if (r->bp_map->get(a))
- con->dd_printf("0x%06x\n", a);
- }*/
+ con->dd_printf("0x%06x\n", a);
+ }*/
return(0);
}
//int
//cl_info_reg_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_info_reg_cmd)
{
uc->print_regs(con);
//int
//cl_info_hw_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_info_hw_cmd)
{
class cl_hw *hw;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, HW)) {
hw= params[0]->value.hw;
//int
//cl_info_stack_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_info_stack_cmd)
{
int i;
{
class cl_memory_chip *m= (class cl_memory_chip *)(uc->memchips->at(i));
if (m)
- con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n",
- m->get_start_address(),
- m->highest_valid_address(),
- m->get_size(),
- m->get_name(),
- m->width, m->data_format, m->addr_format);
+ con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n",
+ m->get_start_address(),
+ m->highest_valid_address(),
+ m->get_size(),
+ m->get_name(),
+ m->width, m->data_format, m->addr_format);
}
con->dd_printf("Address spaces:\n");
for (i= 0; i < uc->address_spaces->count; i++)
{
class cl_address_space *m=
- (class cl_address_space *)(uc->address_spaces->at(i));
+ (class cl_address_space *)(uc->address_spaces->at(i));
if (m)
- con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n",
- m->get_start_address(),
- m->highest_valid_address(),
- m->get_size(),
- m->get_name(),
- m->width, m->data_format, m->addr_format);
+ con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n",
+ m->get_start_address(),
+ m->highest_valid_address(),
+ m->get_size(),
+ m->get_name(),
+ m->width, m->data_format, m->addr_format);
}
con->dd_printf("Address decoders:\n");
for (i= 0; i < uc->address_spaces->count; i++)
{
class cl_address_space *m=
- (class cl_address_space *)(uc->address_spaces->at(i));
+ (class cl_address_space *)(uc->address_spaces->at(i));
int j;
for (j= 0; j < m->decoders->count; j++)
- {
- class cl_address_decoder *d=
- (class cl_address_decoder *)(m->decoders->at(j));
- con->dd_printf("%2d ", j);
- if (d->address_space)
- {
- con->dd_printf("%s ", d->address_space->get_name("unknown"));
- con->dd_printf(d->address_space->addr_format, d->as_begin);
- con->dd_printf(" ");
- con->dd_printf(d->address_space->addr_format, d->as_end);
- }
- else
- con->dd_printf("x");
- con->dd_printf(" -> ");
- if (d->memchip)
- {
- con->dd_printf("%s ", d->memchip->get_name("unknown"));
- con->dd_printf(d->memchip->addr_format, d->chip_begin);
- }
- else
- con->dd_printf("x");
- con->dd_printf(" %s\n", (d->activated)?"activated":"inactive");
- }
+ {
+ class cl_address_decoder *d=
+ (class cl_address_decoder *)(m->decoders->at(j));
+ con->dd_printf("%2d ", j);
+ if (d->address_space)
+ {
+ con->dd_printf("%s ", d->address_space->get_name("unknown"));
+ con->dd_printf(d->address_space->addr_format, d->as_begin);
+ con->dd_printf(" ");
+ con->dd_printf(d->address_space->addr_format, d->as_end);
+ }
+ else
+ con->dd_printf("x");
+ con->dd_printf(" -> ");
+ if (d->memchip)
+ {
+ con->dd_printf("%s ", d->memchip->get_name("unknown"));
+ con->dd_printf(d->memchip->addr_format, d->chip_begin);
+ }
+ else
+ con->dd_printf("x");
+ con->dd_printf(" %s\n", (d->activated)?"activated":"inactive");
+ }
}
return(0);
}
* Simulator of microcontrollers (cmd.src/newcmd.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#ifdef SOCKET_AVAIL
-# include HEADER_SOCKET
-# if defined HAVE_SYS_SOCKET_H
-# include <netinet/in.h>
-# include <arpa/inet.h>
-# include <netdb.h>
-# endif
-#endif
-#if FD_HEADER_OK
-# include HEADER_FD
-#endif
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
#include "i_string.h"
#include "cmdlexcl.h"
* Options of console
*/
-cl_prompt_option::cl_prompt_option(class cl_console *console):
+cl_prompt_option::cl_prompt_option(class cl_console_base *console):
cl_optref(console)
{
con= console;
}
-cl_debug_option::cl_debug_option(class cl_console *console):
+cl_debug_option::cl_debug_option(class cl_console_base *console):
cl_prompt_option(console)
{}
*____________________________________________________________________________
*/
-cl_console::cl_console(char *fin, char *fout, class cl_app *the_app):
- cl_base()
-{
- FILE *f;
-
- app= the_app;
- in= 0;
- if (fin)
- if (f= fopen(fin, "r"), in= f, !f)
- fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));
- out= 0;
- if (fout)
- if (f= fopen(fout, "w"), out= f, !f)
- fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno));
- prompt= 0;
- flags= CONS_NONE;
- if (in &&
- isatty(fileno(in)))
- flags|= CONS_INTERACTIVE;
- else
- ;//fprintf(stderr, "Warning: non-interactive console\n");
- rout= 0;
- id= 0;
- lines_printed= new cl_ustrings(100, 100, "console_cache");
-}
-
-cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app):
- cl_base()
-{
- app= the_app;
- in = fin;
- out= fout;
- prompt= 0;
- flags= CONS_NONE;
- if (in &&
- isatty(fileno(in)))
- flags|= CONS_INTERACTIVE;
- else
- ;//fprintf(stderr, "Warning: non-interactive console\n");
- rout= 0;
- id= 0;
- lines_printed= new cl_ustrings(100, 100, "console_cache");
-}
-
-/*
- * use the port number supplied to connect to localhost for
- * (by Sandeep)
- */
-
-#ifdef SOCKET_AVAIL
-static int
-connect_to_port(int portnum)
-{
- int sock= socket(AF_INET,SOCK_STREAM,0);
- struct sockaddr_in sin;
-
- sin.sin_family = AF_INET;
- sin.sin_port = htons(portnum);
- sin.sin_addr.s_addr = inet_addr("127.0.0.1");
-
- if (connect(sock, (struct sockaddr *)&sin, sizeof(sin))) {
- fprintf(stderr, "Connect to port %d: %s\n", portnum, strerror(errno));
- return -1;
- }
- return sock;
-}
-
-cl_console::cl_console(int portnumber, class cl_app *the_app)
-{
- int sock= connect_to_port(portnumber);
-
- app= the_app;
- if (!(in= fdopen(sock, "r")))
- fprintf(stderr, "cannot open port for input\n");
- if (!(out= fdopen(sock, "w")))
- fprintf(stderr, "cannot open port for output\n");
- //fprintf(stderr, "init socket done\n");
- id= 0;
- lines_printed= new cl_ustrings(1, 1, "console_cache");
-}
-#endif
-
-class cl_console *
-cl_console::clone_for_exec(char *fin)
-{
- FILE *fi= 0, *fo= 0;
-
- if (!fin)
- return(0);
- if (fi= fopen(fin, "r"), !fi)
- {
- fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));
- return(0);
- }
- if ((fo= fdopen(dup(fileno(out)), "a")) == 0)
- {
- fclose(fi);
- fprintf(stderr, "Can't re-open output file: %s\n", strerror(errno));
- return(0);
- }
- class cl_console *con= new cl_sub_console(this, fi, fo, app);
- return(con);
-}
-
int
-cl_console::init(void)
+cl_console_base::init(void)
{
cl_base::init();
prompt_option= new cl_prompt_option(this);
return(0);
}
-cl_console::~cl_console(void)
-{
- if (in)
- fclose(in);
- un_redirect();
- if (out)
- {
- if (flags & CONS_PROMPT)
- fprintf(out, "\n");
- fflush(out);
- fclose(out);
- }
- delete prompt_option;
- delete null_prompt_option;
- delete debug_option;
-#ifdef SOCKET_AVAIL
- /* if (sock)
- {
- shutdown(sock, 2);
- close(sock);
- }*/
-#endif
-}
-
-
-bool
-cl_console::accept_last(void)
-{
- if (!in)
- return(DD_FALSE);
- if (isatty(fileno(in)))
- return(DD_TRUE);
- return(DD_FALSE);
-}
-
-
-/*
- * Output functions
- */
-
void
-cl_console::welcome(void)
+cl_console_base::welcome(void)
{
if (!(flags & CONS_NOWELCOME))
{
}
void
-cl_console::redirect(char *fname, char *mode)
-{
- if ((rout= fopen(fname, mode)) == NULL)
- dd_printf("Unable to open file '%s' for %s: %s\n",
- fname, (mode[0]=='w')?"write":"append", strerror(errno));
-}
-
-void
-cl_console::un_redirect(void)
+cl_console_base::print_prompt(void)
{
- if (!rout)
+ if (flags & (CONS_PROMPT | CONS_FROZEN | CONS_INACTIVE))
return;
- fclose(rout);
- rout= NULL;
-}
-
-
-int
-cl_console::cmd_do_print(char *format, va_list ap)
-{
- int ret;
- FILE *f = get_out();
-
- if (f)
- {
- ret= vfprintf(f, format, ap);
- fflush(f);
- }
- else
- ret= 0;
-
- return(ret);
-}
-void
-cl_console::print_prompt(void)
-{
- if (flags & (CONS_PROMPT|CONS_FROZEN|CONS_INACTIVE))
- return;
- flags|= CONS_PROMPT;
+ flags |= CONS_PROMPT;
if (/*app->args->arg_avail('P')*/null_prompt_option->get_value(bool(0)))
{
- FILE *Out = get_out();
- if (Out)
- {
- putc('\0', Out);
- fflush(Out);
- }
+ dd_printf("%c", 0);
}
else
{
- dd_printf("%d%s", id, (prompt && prompt[0])?prompt:"> ");
+ dd_printf("%d%s", id, (prompt && prompt[0]) ? prompt : "> ");
// ((p= app->args->get_sarg(0, "prompt"))?p:"> "));
}
}
int
-cl_console::dd_printf(char *format, ...)
+cl_console_base::dd_printf(char *format, ...)
{
va_list ap;
int ret= 0;
}
int
-cl_console::debug(char *format, ...)
+cl_console_base::debug(char *format, ...)
{
if ((flags & CONS_DEBUG) == 0)
return(0);
return(ret);
}
+/*
+ * Printing out an integer in binary format
+ */
+
void
-cl_console::print_bin(long data, int bits)
+cl_console_base::print_bin(long data, int bits)
{
long mask= 1;
}
void
-cl_console::print_char_octal(char c)
-{
- FILE *Out= get_out();
-
- if (Out)
- ::print_char_octal(c, Out);
+cl_console_base::print_char_octal(char c)
+{
+ if (strchr("\a\b\f\n\r\t\v\"", c))
+ switch (c)
+ {
+ case '\a': dd_printf("\a"); break;
+ case '\b': dd_printf("\b"); break;
+ case '\f': dd_printf("\f"); break;
+ case '\n': dd_printf("\n"); break;
+ case '\r': dd_printf("\r"); break;
+ case '\t': dd_printf("\t"); break;
+ case '\v': dd_printf("\v"); break;
+ case '\"': dd_printf("\""); break;
+ }
+ else if (isprint(c))
+ dd_printf("%c", c);
+ else
+ dd_printf("\\%03hho", c);
}
-
-/*
- * Input functions
- */
-
int
-cl_console::get_in_fd(void)
+cl_console_base::interpret(char *cmd)
{
- if (flags & CONS_INACTIVE)
- return(-2);
- return(in?fileno(in):-1);
+ dd_printf("Unknown command\n");
+ return(0);
}
-int
-cl_console::input_avail(void)
+void
+cl_console_base::set_id(int new_id)
{
- struct timeval tv;
- UCSOCKET_T i;
-
- if ((i= get_in_fd()) < 0)
- return(0);
- fd_set s;
- FD_ZERO(&s);
- FD_SET(i, &s);
- tv.tv_sec= tv.tv_usec= 0;
- i= select(i+1, &s, NULL, NULL, &tv);
- return(i);
+ char *s;
+
+ id= new_id;
+ set_name(s= format_string("console%d", id));
+ free(s);
}
-char *
-cl_console::read_line(void)
+void
+cl_console_base::set_prompt(char *p)
{
- char *s= NULL;
+ if (prompt)
+ free(prompt);
+ if (p && *p)
+ prompt= strdup(p);
+ else
+ prompt= 0;
+}
-#ifdef HAVE_GETLINE
- if (getline(&s, 0, in) < 0)
- return(0);
-#elif defined HAVE_GETDELIM
- size_t n= 30;
- s= (char *)malloc(n);
- if (getdelim(&s, &n, '\n', in) < 0)
- {
- free(s);
- return(0);
- }
-#elif defined HAVE_FGETS
- s= (char *)malloc(300);
- if (fgets(s, 300, in) == NULL)
+bool
+cl_console_base::input_active(void) const
+{
+ if (((flags & CONS_FROZEN) == 0 ||
+ (flags & CONS_INTERACTIVE) != 0) &&
+ (flags & CONS_INACTIVE) == 0)
{
- free(s);
- return(0);
+ return true;
}
-#endif
- s[strlen(s)-1]= '\0';
- if (s[strlen(s)-1] == '\r')
- s[strlen(s)-1]= '\0';
- flags&= ~CONS_PROMPT;
- return(s);
+ else
+ return false;
}
int
-cl_console::proc_input(class cl_cmdset *cmdset)
+cl_console_base::proc_input(class cl_cmdset *cmdset)
{
- int retval= 0;
+ int retval = 0;
un_redirect();
- if (feof(in))
+ if (is_eof())
{
- fprintf(out, "End\n");
- return(1);
+ dd_printf("End\n");
+ return 1;
}
- char *cmdstr= read_line();
+ char *cmdstr = read_line();
if (!cmdstr)
- return(1);
+ return 1;
if (flags & CONS_FROZEN)
{
app->get_sim()->stop(resUSER);
flags&= ~CONS_FROZEN;
- retval= 0;
+ retval = 0;
}
else
{
- if (cmdstr &&
- *cmdstr == '\004')
- retval= 1;
+ if (cmdstr && *cmdstr == '\004')
+ retval = 1;
else
{
class cl_cmdline *cmdline= 0;
- class cl_cmd *cm= 0;
+ class cl_cmd *cm = 0;
if (flags & CONS_ECHO)
dd_printf("%s\n", cmdstr);
cmdline= new cl_cmdline(app, cmdstr, this);
accept_last() &&
last_command)
{
- cm= last_command;
+ cm = last_command;
delete cmdline;
- cmdline= last_cmdline;
+ cmdline = last_cmdline;
}
else
{
if (last_cmdline)
{
delete last_cmdline;
- last_cmdline= 0;
+ last_cmdline = 0;
}
- last_command= 0;
+ last_command = 0;
}
if (cm)
{
retval= cm->work(app, cmdline, this);
if (cm->can_repeat)
{
- last_command= cm;
- last_cmdline= cmdline;
+ last_command = cm;
+ last_cmdline = cmdline;
}
else
delete cmdline;
{
class YY_cl_ucsim_parser_CLASS *pars;
class cl_ucsim_lexer *lexer;
- lexer= new cl_ucsim_lexer(cmdstr);
- pars= new YY_cl_ucsim_parser_CLASS(lexer);
+ lexer = new cl_ucsim_lexer(cmdstr);
+ pars = new YY_cl_ucsim_parser_CLASS(lexer);
pars->yyparse();
delete cmdline;
delete pars;
return(retval);
}
-/*
- * Old version, sim->do_cmd() falls into this if it doesn't find a new
- * command object which can handle entered command
- */
-
-int
-cl_console::interpret(char *cmd)
-{
- dd_printf("Unknown command\n");
- return(0);
-}
-
-void
-cl_console::set_id(int new_id)
-{
- char *s;
-
- id= new_id;
- set_name(s= format_string("console%d", id));
- free(s);
-}
-
-void
-cl_console::set_prompt(char *p)
-{
- if (prompt)
- free(prompt);
- if (p &&
- *p)
- prompt= strdup(p);
- else
- prompt= 0;
-}
-
-
-/*
- * This console listen on a socket and can accept connection requests
- */
-#ifdef SOCKET_AVAIL
-
-cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app)
-{
- app= the_app;
- if ((sock= make_server_socket(serverport)) >= 0)
- {
- if (listen(sock, 10) < 0)
- fprintf(stderr, "Listen on port %d: %s\n",
- serverport, strerror(errno));
- }
- in= out= 0;
-}
-
-int
-cl_listen_console::get_in_fd(void)
-{
- return(sock);
-}
-
-int
-cl_listen_console::proc_input(class cl_cmdset *cmdset)
-{
- int newsock;
- ACCEPT_SOCKLEN_T size;
- struct sockaddr_in sock_addr;
- class cl_commander *cmd;
-
- cmd= app->get_commander();
- size= sizeof(struct sockaddr);
- newsock= accept(sock, (struct sockaddr*)&sock_addr, &size);
- if (newsock < 0)
- {
- perror("accept");
- return(0);
- }
- if (!(in= fdopen(newsock, "r+")))
- fprintf(stderr, "cannot open port for input\n");
- if (!(out= fdopen(newsock, "w+")))
- fprintf(stderr, "cannot open port for output\n");
- class cl_console *c= cmd->mk_console(in, out);
- c->flags|= CONS_INTERACTIVE;
- cmd->add_console(c);
- in= out= 0;
- return(0);
-}
-
-#endif /* SOCKET_AVAIL */
-
-
-/*
- * Sub-console
- */
-
-cl_sub_console::cl_sub_console(class cl_console *the_parent,
- FILE *fin, FILE *fout, class cl_app *the_app):
- cl_console(fin, fout, the_app)
-{
- parent= the_parent;
-}
-
-cl_sub_console::~cl_sub_console(void)
-{
- class cl_commander *c= app->get_commander();
-
- if (parent && c)
- {
- c->activate_console(parent);
- }
-}
-
-int
-cl_sub_console::init(void)
-{
- class cl_commander *c= app->get_commander();
-
- if (parent && c)
- {
- c->deactivate_console(parent);
- }
- cl_console::init();
- flags|= CONS_ECHO;
- return(0);
-}
-
/*
* Command interpreter
*____________________________________________________________________________
*/
-cl_commander::cl_commander(class cl_app *the_app, class cl_cmdset *acmdset
- /*, class cl_sim *asim*/):
+cl_commander_base::cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset):
cl_base()
{
app= the_app;
- cons= new cl_list(1, 1, "consoles");
+ cons= new cl_list(1, 1, "consoles");
actual_console= frozen_console= 0;
cmdset= acmdset;
}
-int
-cl_commander::init(void)
-{
- class cl_optref console_on_option(this);
- class cl_optref config_file_option(this);
- class cl_optref port_number_option(this);
- class cl_console *con;
-
- console_on_option.init();
- console_on_option.use("console_on");
- config_file_option.init();
- config_file_option.use("config_file");
- port_number_option.init();
-
- cl_base::init();
- set_name("Commander");
-
- bool need_config= DD_TRUE;
-
-#ifdef SOCKET_AVAIL
- if (port_number_option.use("port_number"))
- add_console(mk_console(port_number_option.get_value((long)0)));
-#endif
-
- /* The following code is commented out because it produces gcc warnings
- * newcmd.cc: In member function `virtual int cl_commander::init()':
- * newcmd.cc:785: warning: 'Config' might be used uninitialized in this function
- * newcmd.cc:786: warning: 'cn' might be used uninitialized in this function
- */
- /*
- char *Config= config_file_option.get_value(Config);
- char *cn= console_on_option.get_value(cn);
- */
- /* Here shoud probably be something else, but is still better then the former code... */
- char *Config= config_file_option.get_value("");
- char *cn= console_on_option.get_value("");
-
- if (cn)
- {
- add_console(con= mk_console(cn, cn));
- exec_on(con, Config);
- need_config= DD_FALSE;
- }
- if (cons->get_count() == 0)
- {
- add_console(con= mk_console(stdin, stdout));
- exec_on(con, Config);
- need_config= DD_FALSE;
- }
- if (need_config &&
- Config &&
- *Config)
- {
- FILE *fc= fopen(Config, "r");
- if (!fc)
- fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno));
- else
- {
- con= mk_console(fc, stderr);
- con->flags|= CONS_NOWELCOME|CONS_ECHO;
- add_console(con);
- }
- }
- return(0);
-}
-
-cl_commander::~cl_commander(void)
+cl_commander_base::~cl_commander_base(void)
{
delete cons;
delete cmdset;
}
-class cl_console *
-cl_commander::mk_console(char *fin, char *fout)
-{
- return(new cl_console(fin, fout, app));
-}
-
-class cl_console *
-cl_commander::mk_console(FILE *fin, FILE *fout)
-{
- return(new cl_console(fin, fout, app));
-}
-
-#ifdef SOCKET_AVAIL
-class cl_console *
-cl_commander::mk_console(int portnumber)
-{
- return(new cl_listen_console(portnumber, app));
-}
-#endif
-
void
-cl_commander::add_console(class cl_console *console)
+cl_commander_base::add_console(class cl_console_base *console)
{
if (!console)
return;
}
void
-cl_commander::del_console(class cl_console *console)
+cl_commander_base::del_console(class cl_console_base *console)
{
cons->disconn(console);
set_fd_set();
}
void
-cl_commander::activate_console(class cl_console *console)
+cl_commander_base::activate_console(class cl_console_base *console)
{
console->flags&= ~CONS_INACTIVE;
//console->print_prompt();
}
void
-cl_commander::deactivate_console(class cl_console *console)
+cl_commander_base::deactivate_console(class cl_console_base *console)
{
console->flags|= CONS_INACTIVE;
set_fd_set();
}
-void
-cl_commander::set_fd_set(void)
-{
- int i;
-
- //fprintf(stderr, "** Setting fd set\n");
- FD_ZERO(&read_set);
- fd_num= 0;
- for (i= 0; i < cons->count; i++)
- {
- UCSOCKET_T fd;
- class cl_console *c= (class cl_console*)(cons->at(i));
- if ((fd= c->get_in_fd()) >= 0)
- {
- if ((c->flags & CONS_FROZEN) == 0 ||
- (c->flags & CONS_INTERACTIVE) != 0)
- {
- FD_SET(fd, &read_set);
- if (fd > fd_num)
- fd_num= fd;
- }
- }
- else
- ;//fprintf(stderr, "** Skipping console %p\n",c);
- }
- fd_num++;
-}
-
-
/*
* Printing to all consoles
*/
int
-cl_commander::all_printf(char *format, ...)
+cl_commander_base::all_printf(char *format, ...)
{
va_list ap;
int i, ret= 0;
-
+
for (i= 0; i < cons->count; i++)
{
- class cl_console *c= (class cl_console*)(cons->at(i));
+ class cl_console_base *c= (class cl_console_base*)(cons->at(i));
va_start(ap, format);
ret= c->cmd_do_print(format, ap);
}
void
-cl_commander::prompt(void)
+cl_commander_base::prompt(void)
{
int i;
-
+
for (i= 0; i < cons->count; i++)
{
- class cl_console *c= (class cl_console*)(cons->at(i));
+ class cl_console_base *c= (class cl_console_base*)(cons->at(i));
c->print_prompt();
}
}
*/
int
-cl_commander::dd_printf(char *format, va_list ap)
+cl_commander_base::dd_printf(char *format, va_list ap)
{
int ret= 0;
- class cl_console *con;
+ class cl_console_base *con;
if (actual_console)
{
}
int
-cl_commander::dd_printf(char *format, ...)
+cl_commander_base::dd_printf(char *format, ...)
{
va_list ap;
int ret= 0;
*/
int
-cl_commander::debug(char *format, ...)
+cl_commander_base::debug(char *format, ...)
{
va_list ap;
int i, ret= 0;
for (i= 0; i < cons->count; i++)
{
- class cl_console *c= (class cl_console*)(cons->at(i));
+ class cl_console_base *c= (class cl_console_base*)(cons->at(i));
if (c->flags & CONS_DEBUG)
{
va_start(ap, format);
}
int
-cl_commander::debug(char *format, va_list ap)
+cl_commander_base::debug(char *format, va_list ap)
{
int i, ret= 0;
for (i= 0; i < cons->count; i++)
{
- class cl_console *c= (class cl_console*)(cons->at(i));
+ class cl_console_base *c= (class cl_console_base*)(cons->at(i));
if (c->flags & CONS_DEBUG)
{
ret= c->cmd_do_print(format, ap);
}
int
-cl_commander::flag_printf(int iflags, char *format, ...)
+cl_commander_base::flag_printf(int iflags, char *format, ...)
{
va_list ap;
int i, ret= 0;
for (i= 0; i < cons->count; i++)
{
- class cl_console *c= (class cl_console*)(cons->at(i));
+ class cl_console_base *c= (class cl_console_base*)(cons->at(i));
if ((c->flags & iflags) == iflags)
{
va_start(ap, format);
}
int
-cl_commander::input_avail(void)
+cl_commander_base::input_avail_on_frozen(void)
{
- struct timeval tv;
- int i;
-
- tv.tv_sec= tv.tv_usec= 0;
- active_set= read_set;
- i= select(fd_num, &active_set, NULL, NULL, &tv);
- return(i);
-}
-
-int
-cl_commander::input_avail_on_frozen(void)
-{
- int fd;
-
- if (!frozen_console)
- return(0);
- if ((fd= frozen_console->get_in_fd()) >= 0 &&
- !isatty(fd))
+ if (!frozen_console || frozen_console->is_tty())
return(0);
return(frozen_console->input_avail());
}
-int
-cl_commander::wait_input(void)
-{
- int i;
-
- active_set= read_set;
- prompt();
- i= select(fd_num, &active_set, NULL, NULL, NULL);
- return(i);
-}
-
-int
-cl_commander::proc_input(void)
-{
- for (int j = 0; j < cons->count; j++)
- {
- class cl_console *c = (class cl_console*)(cons->at(j));
-
- int fd = c->get_in_fd();
- if (fd >= 0 && FD_ISSET(fd, &active_set))
- {
- actual_console = c;
- int retval = c->proc_input(cmdset);
- if (retval)
- {
- del_console(c);
- delete c;
- }
- actual_console = 0;
- return(0 == cons->count);
- }
- }
- return 0;
-}
-
void
-cl_commander::exec_on(class cl_console *cons, char *file_name)
+cl_commander_base::exec_on(class cl_console_base *cons, char *file_name)
{
- FILE *fi= fopen(file_name, "r");
-
- if (!cons ||
- !fi)
+ if (!cons || !file_name || !fopen(file_name, "r"))
return;
- class cl_console *subcon= cons->clone_for_exec(file_name);
- subcon->flags|= CONS_NOWELCOME;
+
+ class cl_console_base *subcon = cons->clone_for_exec(file_name);
+ subcon->flags |= CONS_NOWELCOME;
add_console(subcon);
}
/*
- * Simulator of microcontrollers (cmd.src/cmdcl.h)
+ * Simulator of microcontrollers (cmd.src/newcmdcl.h)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
*
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
-#if FD_HEADER_OK
-# include HEADER_FD
-#endif
// prj
#include "pobjcl.h"
class cl_prompt_option: public cl_optref
{
protected:
- class cl_console *con;
+ class cl_console_base *con;
public:
- cl_prompt_option(class cl_console *console);
+ cl_prompt_option(class cl_console_base *console);
virtual int init(void);
virtual void option_changed(void);
};
class cl_debug_option: public cl_prompt_option
{
public:
- cl_debug_option(class cl_console *console);
+ cl_debug_option(class cl_console_base *console);
virtual int init(void);
virtual void option_changed(void);
};
* Command console
*/
-class cl_console: public cl_base
+class cl_console_base: public cl_base
{
- friend class cl_commander;
protected:
- FILE *in, *out, *rout/*redirected output*/;
- int id;
class cl_prompt_option *prompt_option;
class cl_optref *null_prompt_option;
class cl_debug_option *debug_option;
class cl_ustrings *lines_printed;
class cl_cmd *last_command;
class cl_cmdline *last_cmdline;
-public:
- class cl_app *app;
- int flags; // See CONS_XXXX
- char *prompt;
public:
- cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
- cl_console(char *fin, char *fout, class cl_app *the_app);
- cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
- cl_console(char *fin, FILE *fout);
-#ifdef SOCKET_AVAIL
- cl_console(int portnumber, class cl_app *the_app);
-#endif
- virtual ~cl_console(void);
- virtual class cl_console *clone_for_exec(char *fin);
- virtual int init(void);
+ cl_console_base(void): cl_base() { app = 0; flags = 0; prompt = 0; }
- virtual bool accept_last(void);
+ virtual class cl_console_base *clone_for_exec(char *fin) = 0;
- virtual void welcome(void);
- virtual void redirect(char *fname, char *mode);
- virtual void un_redirect(void);
- int cmd_do_print(char *format, va_list ap);
- virtual void print_prompt(void);
- virtual int dd_printf(char *format, ...);
- virtual int debug(char *format, ...);
- virtual void print_bin(long data, int bits);
- virtual void print_char_octal(char c);
- virtual int get_in_fd(void);
- virtual int input_avail(void);
- virtual char *read_line(void);
- virtual int proc_input(class cl_cmdset *cmdset);
- virtual bool interpret(char *cmd);
- virtual void set_id(int new_id);
- virtual int get_id(void) { return(id); }
- virtual void set_prompt(char *p);
-private:
- FILE *get_out(void) { return(rout?rout:out); }
-};
-
-#ifdef SOCKET_AVAIL
-class cl_listen_console: public cl_console
-{
-public:
- int sock;
-public:
- cl_listen_console(int serverport, class cl_app *the_app);
+ virtual void redirect(char *fname, char *mode) = 0;
+ virtual void un_redirect(void) = 0;
+ virtual int cmd_do_print(char *format, va_list ap) = 0;
+ virtual bool is_tty(void) const = 0;
+ virtual bool is_eof(void) const = 0;
+ virtual int input_avail(void) = 0;
+ virtual char *read_line(void) = 0;
- virtual void welcome(void) {}
-
- virtual int get_in_fd(void);
+ virtual int init(void);
+ virtual void welcome(void);
virtual int proc_input(class cl_cmdset *cmdset);
-};
-#endif
+ void print_prompt(void);
+ int dd_printf(char *format, ...);
+ int debug(char *format, ...);
+ void print_bin(long data, int bits);
+ void print_char_octal(char c);
+
+ bool interpret(char *cmd);
+ int get_id(void) const { return(id); }
+ void set_id(int new_id);
+ void set_prompt(char *p);
+
+ bool input_active(void) const;
+ bool accept_last(void) { return is_tty() ? DD_TRUE : DD_FALSE; }
-class cl_sub_console: public cl_console
-{
- class cl_console *parent;
public:
- cl_sub_console(class cl_console *the_parent,
- FILE *fin, FILE *fout, class cl_app *the_app);
- virtual ~cl_sub_console(void);
- virtual int init(void);
-};
+ int flags; // See CONS_XXXX
+protected:
+ class cl_app *app;
+ char *prompt;
+ int id;
+};
/*
* Command interpreter
*/
-class cl_commander: public cl_base
+class cl_commander_base: public cl_base
{
public:
class cl_app *app;
class cl_list *cons;
- fd_set read_set, active_set;
- UCSOCKET_T fd_num;
- class cl_console *actual_console, *frozen_console;
+ class cl_console_base *actual_console, *frozen_console;
class cl_cmdset *cmdset;
public:
- cl_commander(class cl_app *the_app,
- class cl_cmdset *acmdset/*, class cl_sim *asim*/);
- virtual ~cl_commander(void);
- virtual int init(void);
+ cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset);
+ virtual ~cl_commander_base(void);
- virtual class cl_console *mk_console(char *fin, char *fout);
- virtual class cl_console *mk_console(FILE *fin, FILE *fout);
-#ifdef SOCKET_AVAIL
- virtual class cl_console *mk_console(int portnumber);
-#endif
- void add_console(class cl_console *console);
- void del_console(class cl_console *console);
- void activate_console(class cl_console *console);
- void deactivate_console(class cl_console *console);
- void set_fd_set(void);
+ void add_console(class cl_console_base *console);
+ void del_console(class cl_console_base *console);
+ void activate_console(class cl_console_base *console);
+ void deactivate_console(class cl_console_base *console);
void prompt(void);
int all_printf(char *format, ...); // print to all consoles
int debug(char *format, ...); // print consoles with debug flag set
int debug(char *format, va_list ap); // print consoles with debug flag set
int flag_printf(int iflags, char *format, ...);
- int input_avail(void);
int input_avail_on_frozen(void);
- int wait_input(void);
- int proc_input(void);
- void exec_on(class cl_console *cons, char *file_name);
+ void exec_on(class cl_console_base *cons, char *file_name);
+
+ virtual int init(void) = 0;
+ virtual void set_fd_set(void) = 0;
+ virtual int proc_input(void) = 0;
+ virtual int input_avail(void) = 0;
+ virtual int wait_input(void) = 0;
};
#endif
-/* End of cmd.src/cmdcl.h */
+/* End of cmd.src/newcmdcl.h */
--- /dev/null
+/*\r
+ * Simulator of microcontrollers (cmd.src/newcmdposix.cc)\r
+ *\r
+ * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.\r
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net\r
+ *\r
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu\r
+ *\r
+ */\r
+\r
+/* This file is part of microcontroller simulator: ucsim.\r
+\r
+UCSIM is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+UCSIM is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with UCSIM; see the file COPYING. If not, write to the Free\r
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA\r
+02111-1307, USA. */\r
+/*@1@*/\r
+\r
+#include "ddconfig.h"\r
+\r
+#include <stdio.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdlib.h>\r
+#include <sys/types.h>\r
+#include <sys/time.h>\r
+#ifdef SOCKET_AVAIL\r
+# include HEADER_SOCKET\r
+# if defined HAVE_SYS_SOCKET_H\r
+# include <netinet/in.h>\r
+# include <arpa/inet.h>\r
+# include <netdb.h>\r
+# endif\r
+#endif\r
+#if FD_HEADER_OK\r
+# include HEADER_FD\r
+#endif\r
+#ifdef HAVE_UNISTD_H\r
+# include <unistd.h>\r
+#endif\r
+#include "i_string.h"\r
+\r
+#include "cmdlexcl.h"\r
+#include "cmdpars.h"\r
+\r
+// prj\r
+#include "globals.h"\r
+#include "utils.h"\r
+\r
+// sim\r
+#include "simcl.h"\r
+#include "argcl.h"\r
+#include "appcl.h"\r
+\r
+// local\r
+#include "newcmdposixcl.h"\r
+\r
+\r
+/*\r
+ * Command console\r
+ *____________________________________________________________________________\r
+ */\r
+\r
+cl_console::cl_console(char *fin, char *fout, class cl_app *the_app)\r
+{\r
+ FILE *f;\r
+\r
+ app= the_app;\r
+ in= 0;\r
+ if (fin)\r
+ if (f= fopen(fin, "r"), in= f, !f)\r
+ fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));\r
+ out= 0;\r
+ if (fout)\r
+ if (f= fopen(fout, "w"), out= f, !f)\r
+ fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno));\r
+ prompt= 0;\r
+ flags= CONS_NONE;\r
+ if (is_tty())\r
+ flags|= CONS_INTERACTIVE;\r
+ else\r
+ ;//fprintf(stderr, "Warning: non-interactive console\n");\r
+ rout= 0;\r
+ id= 0;\r
+ lines_printed= new cl_ustrings(100, 100, "console_cache");\r
+}\r
+\r
+cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app)\r
+{\r
+ app= the_app;\r
+ in = fin;\r
+ out= fout;\r
+ prompt= 0;\r
+ flags= CONS_NONE;\r
+ if (is_tty())\r
+ flags|= CONS_INTERACTIVE;\r
+ else\r
+ ;//fprintf(stderr, "Warning: non-interactive console\n");\r
+ rout= 0;\r
+ id= 0;\r
+ lines_printed= new cl_ustrings(100, 100, "console_cache");\r
+}\r
+\r
+class cl_console *\r
+cl_console::clone_for_exec(char *fin)\r
+{\r
+ FILE *fi= 0, *fo= 0;\r
+\r
+ if (!fin)\r
+ return(0);\r
+ if (fi= fopen(fin, "r"), !fi)\r
+ {\r
+ fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));\r
+ return(0);\r
+ }\r
+ if ((fo= fdopen(dup(fileno(out)), "a")) == 0)\r
+ {\r
+ fclose(fi);\r
+ fprintf(stderr, "Can't re-open output file: %s\n", strerror(errno));\r
+ return(0);\r
+ }\r
+ class cl_console *con= new cl_sub_console(this, fi, fo, app);\r
+ return(con);\r
+}\r
+\r
+cl_console::~cl_console(void)\r
+{\r
+ if (in)\r
+ fclose(in);\r
+ un_redirect();\r
+ if (out)\r
+ {\r
+ if (flags & CONS_PROMPT)\r
+ fprintf(out, "\n");\r
+ fflush(out);\r
+ fclose(out);\r
+ }\r
+ delete prompt_option;\r
+ delete null_prompt_option;\r
+ delete debug_option;\r
+#ifdef SOCKET_AVAIL\r
+ /* if (sock)\r
+ {\r
+ shutdown(sock, 2);\r
+ close(sock);\r
+ }*/\r
+#endif\r
+}\r
+\r
+\r
+/*\r
+ * Output functions\r
+ */\r
+\r
+void\r
+cl_console::redirect(char *fname, char *mode)\r
+{\r
+ if ((rout= fopen(fname, mode)) == NULL)\r
+ dd_printf("Unable to open file '%s' for %s: %s\n",\r
+ fname, (mode[0]=='w')?"write":"append", strerror(errno));\r
+}\r
+\r
+void\r
+cl_console::un_redirect(void)\r
+{\r
+ if (!rout)\r
+ return;\r
+ fclose(rout);\r
+ rout = NULL;\r
+}\r
+\r
+int\r
+cl_console::cmd_do_print(char *format, va_list ap)\r
+{\r
+ int ret;\r
+ FILE *f = get_out();\r
+\r
+ if (f)\r
+ {\r
+ ret= vfprintf(f, format, ap);\r
+ fflush(f);\r
+ }\r
+ else\r
+ ret = 0;\r
+\r
+ return ret;\r
+}\r
+\r
+/*\r
+ * Input functions\r
+ */\r
+\r
+char *\r
+cl_console::read_line(void)\r
+{\r
+ char *s= NULL;\r
+\r
+#ifdef HAVE_GETLINE\r
+ if (getline(&s, 0, in) < 0)\r
+ return(0);\r
+#elif defined HAVE_GETDELIM\r
+ size_t n= 30;\r
+ s= (char *)malloc(n);\r
+ if (getdelim(&s, &n, '\n', in) < 0)\r
+ {\r
+ free(s);\r
+ return(0);\r
+ }\r
+#elif defined HAVE_FGETS\r
+ s= (char *)malloc(300);\r
+ if (fgets(s, 300, in) == NULL)\r
+ {\r
+ free(s);\r
+ return(0);\r
+ }\r
+#endif\r
+ s[strlen(s)-1]= '\0';\r
+ if (s[strlen(s)-1] == '\r')\r
+ s[strlen(s)-1]= '\0';\r
+ flags&= ~CONS_PROMPT;\r
+ return(s);\r
+}\r
+\r
+\r
+/*\r
+ * This console listen on a socket and can accept connection requests\r
+ */\r
+#ifdef SOCKET_AVAIL\r
+\r
+cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app)\r
+{\r
+ app= the_app;\r
+ if ((sock= make_server_socket(serverport)) >= 0)\r
+ {\r
+ if (listen(sock, 10) < 0)\r
+ fprintf(stderr, "Listen on port %d: %s\n",\r
+ serverport, strerror(errno));\r
+ }\r
+ in= out= rout= 0;\r
+}\r
+\r
+int\r
+cl_listen_console::proc_input(class cl_cmdset *cmdset)\r
+{\r
+ int newsock;\r
+ ACCEPT_SOCKLEN_T size;\r
+ struct sockaddr_in sock_addr;\r
+ class cl_commander_base *cmd;\r
+ FILE *in, *out;\r
+\r
+ cmd= app->get_commander();\r
+ size= sizeof(struct sockaddr);\r
+ newsock= accept(sock, (struct sockaddr*)&sock_addr, &size);\r
+ if (newsock < 0)\r
+ {\r
+ perror("accept");\r
+ return(0);\r
+ }\r
+ if (!(in= fdopen(newsock, "r")))\r
+ fprintf(stderr, "cannot open port for input\n");\r
+ if (!(out= fdopen(newsock, "w")))\r
+ fprintf(stderr, "cannot open port for output\n");\r
+ class cl_console_base *c= new cl_console(in, out, app);\r
+ c->flags|= CONS_INTERACTIVE;\r
+ cmd->add_console(c);\r
+ return(0);\r
+}\r
+\r
+#endif /* SOCKET_AVAIL */\r
+\r
+\r
+/*\r
+ * Sub-console\r
+ */\r
+\r
+cl_sub_console::cl_sub_console(class cl_console_base *the_parent,\r
+ FILE *fin, FILE *fout, class cl_app *the_app):\r
+ cl_console(fin, fout, the_app)\r
+{\r
+ parent= the_parent;\r
+}\r
+\r
+cl_sub_console::~cl_sub_console(void)\r
+{\r
+ class cl_commander_base *c= app->get_commander();\r
+\r
+ if (parent && c)\r
+ {\r
+ c->activate_console(parent);\r
+ }\r
+}\r
+\r
+int\r
+cl_sub_console::init(void)\r
+{\r
+ class cl_commander_base *c= app->get_commander();\r
+\r
+ if (parent && c)\r
+ {\r
+ c->deactivate_console(parent);\r
+ }\r
+ cl_console::init();\r
+ flags|= CONS_ECHO;\r
+ return(0);\r
+}\r
+\r
+\r
+/*\r
+ * Command interpreter\r
+ *____________________________________________________________________________\r
+ */\r
+\r
+int\r
+cl_commander::init(void)\r
+{\r
+ class cl_optref console_on_option(this);\r
+ class cl_optref config_file_option(this);\r
+ class cl_optref port_number_option(this);\r
+ class cl_console_base *con;\r
+\r
+ console_on_option.init();\r
+ console_on_option.use("console_on");\r
+ config_file_option.init();\r
+ config_file_option.use("config_file");\r
+ port_number_option.init();\r
+\r
+ cl_base::init();\r
+ set_name("Commander");\r
+\r
+ bool need_config= DD_TRUE;\r
+\r
+#ifdef SOCKET_AVAIL\r
+ if (port_number_option.use("port_number"))\r
+ add_console(new cl_listen_console(port_number_option.get_value((long)0), app));\r
+#endif\r
+\r
+ /* The following code is commented out because it produces gcc warnings\r
+ * newcmd.cc: In member function `virtual int cl_commander::init()':\r
+ * newcmd.cc:785: warning: 'Config' might be used uninitialized in this function\r
+ * newcmd.cc:786: warning: 'cn' might be used uninitialized in this function\r
+ */\r
+ /*\r
+ char *Config= config_file_option.get_value(Config);\r
+ char *cn= console_on_option.get_value(cn);\r
+ */\r
+ /* Here shoud probably be something else, but is still better then the former code... */\r
+ char *Config= config_file_option.get_value("");\r
+ char *cn= console_on_option.get_value("");\r
+\r
+ if (cn)\r
+ {\r
+ add_console(con= new cl_console(cn, cn, app));\r
+ exec_on(con, Config);\r
+ need_config= DD_FALSE;\r
+ }\r
+ if (cons->get_count() == 0)\r
+ {\r
+ add_console(con= new cl_console(stdin, stdout, app));\r
+ exec_on(con, Config);\r
+ need_config= DD_FALSE;\r
+ }\r
+ if (need_config &&\r
+ Config &&\r
+ *Config)\r
+ {\r
+ FILE *fc= fopen(Config, "r");\r
+ if (!fc)\r
+ fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno));\r
+ else\r
+ {\r
+ con= new cl_console(fc, stderr, app);\r
+ con->flags|= CONS_NOWELCOME|CONS_ECHO;\r
+ add_console(con);\r
+ }\r
+ }\r
+ return(0);\r
+}\r
+\r
+void\r
+cl_commander::set_fd_set(void)\r
+{\r
+ int i;\r
+\r
+ FD_ZERO(&read_set);\r
+ fd_num = 0;\r
+ for (i = 0; i < cons->count; i++)\r
+ {\r
+ class cl_console *c= dynamic_cast<class cl_console*>((class cl_console_base*)(cons->at(i)));\r
+\r
+ if (c->input_active())\r
+ {\r
+ UCSOCKET_T fd = c->get_in_fd();\r
+ assert(0 <= fd);\r
+\r
+ FD_SET(fd, &read_set);\r
+ if (fd > fd_num)\r
+ fd_num = fd;\r
+ }\r
+ }\r
+ fd_num++;\r
+}\r
+\r
+int\r
+cl_commander::input_avail(void)\r
+{\r
+ struct timeval tv = {0, 0};\r
+ active_set = read_set;\r
+\r
+ int i = select(fd_num, &active_set, NULL, NULL, &tv);\r
+ if (i < 0)\r
+ perror("select");\r
+\r
+ return i;\r
+}\r
+\r
+int\r
+cl_commander::wait_input(void)\r
+{\r
+ prompt();\r
+ active_set = read_set;\r
+ int i = select(fd_num, &active_set, NULL, NULL, NULL);\r
+ return i;\r
+}\r
+\r
+int\r
+cl_commander::proc_input(void)\r
+{\r
+ for (int j = 0; j < cons->count; j++)\r
+ {\r
+ class cl_console *c = dynamic_cast<class cl_console*>((class cl_console_base*)(cons->at(j)));\r
+\r
+ if (c->input_active())\r
+ {\r
+ UCSOCKET_T fd = c->get_in_fd();\r
+ assert(0 <= fd);\r
+\r
+ if (FD_ISSET(fd, &active_set))\r
+ {\r
+ actual_console = c;\r
+ int retval = c->proc_input(cmdset);\r
+ if (retval)\r
+ {\r
+ del_console(c);\r
+ delete c;\r
+ }\r
+ actual_console = 0;\r
+ return(0 == cons->count);\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
+/* End of cmd.src/newcmdposix.cc */\r
--- /dev/null
+/*
+ * Simulator of microcontrollers (cmd.src/newcmdposixcl.h)
+ *
+ * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
+ *
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
+ *
+ */
+
+/* This file is part of microcontroller simulator: ucsim.
+
+UCSIM is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+UCSIM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with UCSIM; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
+/*@1@*/
+
+#ifndef CMD_NEWCMDFDCL_HEADER
+#define CMD_NEWCMDFDCL_HEADER
+
+#include "newcmdcl.h"
+#include "cmdutil.h"
+
+
+/*
+ * Command fd console
+ */
+
+class cl_console: public cl_console_base
+{
+protected:
+ FILE *in, *out, *rout/*redirected output*/;
+
+public:
+ cl_console(void) { in = out = rout = 0; }
+ cl_console(char *fin, char *fout, class cl_app *the_app);
+ cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
+ int cmd_do_print(char *format, va_list ap);
+
+ virtual ~cl_console(void);
+ virtual class cl_console *clone_for_exec(char *fin);
+
+ virtual void redirect(char *fname, char *mode);
+ virtual void un_redirect(void);
+ virtual UCSOCKET_T get_in_fd(void) { return(in ? fileno(in) : -1); }
+ virtual bool is_tty(void) const { return in && isatty(fileno(in)); }
+ virtual bool is_eof(void) const { return in ? feof(in) : true; }
+ virtual bool input_avail(void) { return input_active() ? ::input_avail(fileno(in)) : false; };
+ virtual char *read_line(void);
+
+private:
+ FILE *get_out(void) { return rout ? rout : out; }
+};
+
+#ifdef SOCKET_AVAIL
+class cl_listen_console: public cl_console
+{
+private:
+ int sock;
+
+public:
+ cl_listen_console(int serverport, class cl_app *the_app);
+
+ virtual void welcome(void) {}
+
+ virtual UCSOCKET_T get_in_fd(void) { return(sock); }
+ virtual int proc_input(class cl_cmdset *cmdset);
+};
+#endif
+
+
+class cl_sub_console: public cl_console
+{
+private:
+ class cl_console_base *parent;
+
+public:
+ cl_sub_console(class cl_console_base *the_parent,
+ FILE *fin, FILE *fout, class cl_app *the_app);
+ virtual ~cl_sub_console(void);
+ virtual int init(void);
+};
+
+
+/*
+ * Command interpreter
+ */
+
+class cl_commander: public cl_commander_base
+{
+private:
+ fd_set read_set, active_set;
+ UCSOCKET_T fd_num;
+
+public:
+ cl_commander(class cl_app *the_app, class cl_cmdset *acmdset)
+ : cl_commander_base(the_app, acmdset)
+ {
+ }
+
+ virtual int init(void);
+ virtual void set_fd_set(void);
+ virtual int input_avail(void);
+ virtual int wait_input(void);
+ virtual int proc_input(void);
+};
+
+#endif
+
+/* End of cmd.src/newcmdposixcl.h */
--- /dev/null
+/*\r
+ * Simulator of microcontrollers (cmd.src/newcmdwin32.cc)\r
+ *\r
+ * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.\r
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net\r
+ *\r
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu\r
+ *\r
+ */\r
+\r
+/* This file is part of microcontroller simulator: ucsim.\r
+\r
+UCSIM is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+UCSIM is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with UCSIM; see the file COPYING. If not, write to the Free\r
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA\r
+02111-1307, USA. */\r
+/*@1@*/\r
+\r
+#include "ddconfig.h"\r
+\r
+#include <stdio.h>\r
+#include <errno.h>\r
+#include <stdarg.h>\r
+#include <stdlib.h>\r
+#include <sys/types.h>\r
+#include <sys/time.h>\r
+#include <assert.h>\r
+#include <fcntl.h>\r
+#include <windows.h>\r
+\r
+#include "i_string.h"\r
+\r
+#include "cmdlexcl.h"\r
+#include "cmdpars.h"\r
+\r
+// prj\r
+#include "globals.h"\r
+#include "utils.h"\r
+\r
+// sim\r
+#include "simcl.h"\r
+#include "argcl.h"\r
+#include "appcl.h"\r
+\r
+// local\r
+#include "newcmdwin32cl.h"\r
+\r
+\r
+/*\r
+ * Channel\r
+ *____________________________________________________________________________\r
+ */\r
+\r
+inline void\r
+cl_channel::set(void)\r
+{\r
+ fp = 0;\r
+ handle = INVALID_HANDLE_VALUE;\r
+ type = CH_UNDEF;\r
+}\r
+\r
+inline void\r
+cl_channel::set(HANDLE _handle, e_handle_type _type)\r
+{\r
+ assert(INVALID_HANDLE_VALUE != _handle);\r
+\r
+ fp = 0;\r
+ handle = _handle;\r
+ type = (_type == CH_UNDEF) ? guess_type() : _type;\r
+}\r
+\r
+inline void\r
+cl_channel::set(FILE *_fp, e_handle_type _type)\r
+{\r
+ assert(_fp);\r
+ fp = _fp;\r
+ handle = (HANDLE)_get_osfhandle(fileno(fp));\r
+ assert(INVALID_HANDLE_VALUE != handle);\r
+ type = (_type == CH_UNDEF) ? guess_type() : _type;\r
+}\r
+\r
+void\r
+cl_channel::close(void)\r
+{\r
+ assert(INVALID_HANDLE_VALUE != handle);\r
+\r
+ if (CH_SOCKET == type)\r
+ {\r
+ shutdown((SOCKET)handle, SD_BOTH);\r
+ closesocket((SOCKET)handle);\r
+ }\r
+ if (fp)\r
+ fclose(fp);\r
+ else if (CH_SOCKET != type)\r
+ CloseHandle(handle);\r
+\r
+ fp = 0;\r
+ handle = INVALID_HANDLE_VALUE;\r
+ type = CH_UNDEF;\r
+}\r
+\r
+/*\r
+ * Command console\r
+ *____________________________________________________________________________\r
+ */\r
+\r
+cl_console::cl_console(char *fin, char *fout, class cl_app *the_app)\r
+{\r
+ FILE *f;\r
+\r
+ app = the_app;\r
+ if (fin)\r
+ {\r
+ if (!(f = fopen(fin, "r")))\r
+ fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));\r
+ in.set(f, CH_FILE);\r
+ }\r
+\r
+ if (fout)\r
+ {\r
+ if (!(f = fopen(fout, "w")))\r
+ fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno));\r
+ out.set(f, CH_FILE);\r
+ }\r
+\r
+ prompt = 0;\r
+ flags = CONS_NONE;\r
+ if (in.is_tty())\r
+ flags |= CONS_INTERACTIVE;\r
+ else\r
+ ;//fprintf(stderr, "Warning: non-interactive console\n");\r
+ id = 0;\r
+ lines_printed = new cl_ustrings(100, 100, "console_cache");\r
+}\r
+\r
+cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app)\r
+{\r
+ app = the_app;\r
+ in.set(fin);\r
+ out.set(fout);\r
+\r
+ prompt = 0;\r
+ flags = CONS_NONE;\r
+ if (in.is_tty())\r
+ flags |= CONS_INTERACTIVE;\r
+ else\r
+ ;//fprintf(stderr, "Warning: non-interactive console\n");\r
+ id = 0;\r
+ lines_printed = new cl_ustrings(100, 100, "console_cache");\r
+}\r
+\r
+cl_console::cl_console(cl_channel _in, cl_channel _out, class cl_app *the_app)\r
+{\r
+ app = the_app;\r
+ in = _in;\r
+ out = _out;\r
+\r
+ prompt = 0;\r
+ flags = CONS_NONE;\r
+ if (in.is_tty())\r
+ flags |= CONS_INTERACTIVE;\r
+ else\r
+ ;//fprintf(stderr, "Warning: non-interactive console\n");\r
+ id = 0;\r
+ lines_printed= new cl_ustrings(100, 100, "console_cache");\r
+}\r
+\r
+class cl_console *\r
+cl_console::clone_for_exec(char *fin)\r
+{\r
+ FILE *fi;\r
+ if (!fin)\r
+ return 0;\r
+\r
+ if (!(fi = fopen(fin, "r")))\r
+ {\r
+ fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno));\r
+ return 0;\r
+ }\r
+ cl_channel ch_in = cl_channel(fi, CH_FILE);\r
+ class cl_console *con= new cl_sub_console(this, ch_in, out, app);\r
+ return con;\r
+}\r
+\r
+cl_console::~cl_console(void)\r
+{\r
+ if (CH_UNDEF != in.get_type())\r
+ in.close();\r
+ un_redirect();\r
+ if (CH_UNDEF != out.get_type())\r
+ {\r
+ if (flags & CONS_PROMPT)\r
+ dd_printf("\n");\r
+ out.close();\r
+ }\r
+ delete prompt_option;\r
+ delete null_prompt_option;\r
+ delete debug_option;\r
+}\r
+\r
+\r
+/*\r
+ * Output functions\r
+ */\r
+\r
+void\r
+cl_console::redirect(char *fname, char *mode)\r
+{\r
+ FILE *fp = fopen(fname, mode);\r
+ if (!fp)\r
+ dd_printf("Unable to open file '%s' for %s: %s\n",\r
+ fname, (mode[0]=='w') ? "write" : "append", strerror(errno));\r
+ out.set(fp, CH_FILE);\r
+}\r
+\r
+void\r
+cl_console::un_redirect(void)\r
+{\r
+ if (CH_UNDEF != rout.get_type())\r
+ out.close();\r
+}\r
+\r
+int\r
+cl_console::cmd_do_print(char *format, va_list ap)\r
+{\r
+ FILE *f = get_out()->get_fp();\r
+\r
+ if (f)\r
+ {\r
+ int ret = vfprintf(f, format, ap);\r
+ fflush(f);\r
+ return ret;\r
+ }\r
+ else\r
+ return 0;\r
+}\r
+\r
+/*\r
+ * Input functions\r
+ */\r
+\r
+char *\r
+cl_console::read_line(void)\r
+{\r
+#define BUF_LEN 1024\r
+\r
+ TRACE("%d-%s\n", get_id(), __PRETTY_FUNCTION__);\r
+\r
+ char *s = NULL;\r
+ FILE *fp = in.get_fp();\r
+ assert(fp);\r
+\r
+#ifdef HAVE_GETLINE\r
+ if (getline(&s, 0, fp) < 0)\r
+ return(0);\r
+#elif defined HAVE_GETDELIM\r
+ size_t n = BUF_LEN;\r
+ s = (char *)malloc(n);\r
+ if (getdelim(&s, &n, '\n', fp) < 0)\r
+ {\r
+ free(s);\r
+ return(0);\r
+ }\r
+#elif defined HAVE_FGETS\r
+ s = (char *)malloc(BUF_LEN);\r
+ if (fgets(s, BUF_LEN, fp) == NULL)\r
+ {\r
+ free(s);\r
+ return(0);\r
+ }\r
+#endif\r
+ s[strlen(s)-1]= '\0';\r
+ if (s[strlen(s)-1] == '\r')\r
+ s[strlen(s)-1]= '\0';\r
+ flags&= ~CONS_PROMPT;\r
+ return(s);\r
+}\r
+\r
+\r
+/*\r
+ * This console cl_listen_console on a socket and can accept connection requests\r
+ */\r
+\r
+cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app)\r
+{\r
+ SOCKET sock;\r
+ app = the_app;\r
+\r
+ if (INVALID_SOCKET != (sock = make_server_socket(serverport)))\r
+ {\r
+ if (SOCKET_ERROR == listen(sock, 10))\r
+ fprintf(stderr, "Can't listen on port %d: %d\n", serverport, WSAGetLastError());\r
+ }\r
+ in.set((HANDLE)sock, CH_SOCKET);\r
+}\r
+\r
+int\r
+cl_listen_console::proc_input(class cl_cmdset *cmdset)\r
+{\r
+ class cl_commander_base *cmd = app->get_commander();\r
+\r
+ struct sockaddr_in sock_addr;\r
+ ACCEPT_SOCKLEN_T size = sizeof(struct sockaddr);\r
+ SOCKET newsock = accept((SOCKET)get_in_fd(), (struct sockaddr*)&sock_addr, &size);\r
+\r
+ if (INVALID_SOCKET == newsock)\r
+ {\r
+ fprintf(stderr, "Can't accept: %d\n", WSAGetLastError());\r
+ return(0);\r
+ }\r
+\r
+ int fh = _open_osfhandle((intptr_t)newsock, _O_TEXT);\r
+ if (-1 == fh)\r
+ {\r
+ fprintf(stderr, "Can't _open_osfhandle\n");\r
+ }\r
+ FILE *fp = fdopen(fh, "r");\r
+ if (!fp)\r
+ fprintf(stderr, "Can't open port for input\n");\r
+ cl_channel ch_in = cl_channel(fp, CH_SOCKET);\r
+\r
+ fh = _open_osfhandle((intptr_t)newsock, _O_TEXT);\r
+ if (-1 == fh)\r
+ {\r
+ fprintf(stderr, "Can't _open_osfhandle\n");\r
+ }\r
+ fp = fdopen(fh, "w");\r
+ if (!fp)\r
+ fprintf(stderr, "Can't open port for output\n");\r
+ cl_channel ch_out = cl_channel(fp, CH_SOCKET);\r
+\r
+ class cl_console_base *c = new cl_console(ch_in, ch_out, app);\r
+ c->flags |= CONS_INTERACTIVE;\r
+ cmd->add_console(c);\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+/*\r
+ * Sub-console\r
+ */\r
+\r
+cl_sub_console::cl_sub_console(class cl_console_base *the_parent,\r
+ cl_channel _in, cl_channel _out, class cl_app *the_app):\r
+ cl_console(_in, _out, the_app)\r
+{\r
+ parent = the_parent;\r
+}\r
+\r
+cl_sub_console::~cl_sub_console(void)\r
+{\r
+ class cl_commander_base *c = app->get_commander();\r
+\r
+ if (parent && c)\r
+ {\r
+ c->activate_console(parent);\r
+ }\r
+}\r
+\r
+int\r
+cl_sub_console::init(void)\r
+{\r
+ class cl_commander_base *c = app->get_commander();\r
+\r
+ if (parent && c)\r
+ {\r
+ c->deactivate_console(parent);\r
+ }\r
+ cl_console::init();\r
+ flags |= CONS_ECHO;\r
+ return 0;\r
+}\r
+\r
+\r
+/*\r
+ * Command interpreter\r
+ *____________________________________________________________________________\r
+ */\r
+\r
+int\r
+cl_commander::init(void)\r
+{\r
+ TRACE("%s\n", __PRETTY_FUNCTION__);\r
+\r
+ class cl_optref console_on_option(this);\r
+ class cl_optref config_file_option(this);\r
+ class cl_optref port_number_option(this);\r
+ class cl_console_base *con;\r
+\r
+ console_on_option.init();\r
+ console_on_option.use("console_on");\r
+ config_file_option.init();\r
+ config_file_option.use("config_file");\r
+ port_number_option.init();\r
+\r
+ cl_base::init();\r
+ set_name("Commander");\r
+\r
+ bool need_config = DD_TRUE;\r
+\r
+ if (port_number_option.use("port_number"))\r
+ add_console(new cl_listen_console(port_number_option.get_value((long)0), app));\r
+\r
+ /* The following code is commented out because it produces gcc warnings\r
+ * newcmd.cc: In member function `virtual int cl_commander::init()':\r
+ * newcmd.cc:785: warning: 'Config' might be used uninitialized in this function\r
+ * newcmd.cc:786: warning: 'cn' might be used uninitialized in this function\r
+ */\r
+ /*\r
+ char *Config= config_file_option.get_value(Config);\r
+ char *cn= console_on_option.get_value(cn);\r
+ */\r
+ /* Here shoud probably be something else, but is still better then the former code... */\r
+ char *Config = config_file_option.get_value("");\r
+ char *cn = console_on_option.get_value("");\r
+\r
+ if (cn)\r
+ {\r
+ add_console(con = new cl_console(cn, cn, app));\r
+ exec_on(con, Config);\r
+ need_config = DD_FALSE;\r
+ }\r
+ if (cons->get_count() == 0)\r
+ {\r
+ add_console(con = new cl_console(stdin, stdout, app));\r
+ exec_on(con, Config);\r
+ need_config = DD_FALSE;\r
+ }\r
+ if (need_config && Config && *Config)\r
+ {\r
+ FILE *fc = fopen(Config, "r");\r
+ if (!fc)\r
+ fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno));\r
+ else\r
+ {\r
+ con = new cl_console(fc, stderr, app);\r
+ con->flags |= CONS_NOWELCOME | CONS_ECHO;\r
+ add_console(con);\r
+ }\r
+ }\r
+ return(0);\r
+}\r
+\r
+void\r
+cl_commander::set_fd_set(void)\r
+{\r
+ TRACE("%s\n", __PRETTY_FUNCTION__);\r
+\r
+ int i;\r
+\r
+ FD_ZERO(&read_set);\r
+\r
+ for (i = 0; i < cons->count; i++)\r
+ {\r
+ class cl_console *c= dynamic_cast<class cl_console*>((class cl_console_base*)(cons->at(i)));\r
+\r
+ if (c->input_active() && CH_SOCKET == c->in.get_type())\r
+ {\r
+ HANDLE fd = c->get_in_fd();\r
+ assert(INVALID_HANDLE_VALUE != fd);\r
+\r
+ FD_SET((SOCKET)fd, &read_set);\r
+ }\r
+ }\r
+}\r
+\r
+int\r
+cl_commander::console_count(void)\r
+{\r
+ int i = 0;\r
+\r
+ for (int j = 0; j < cons->count; j++)\r
+ {\r
+ class cl_console *c = dynamic_cast<class cl_console*>((class cl_console_base*)(cons->at(j)));\r
+\r
+ if (c->input_active())\r
+ {\r
+ switch (c->in.get_type())\r
+ {\r
+ case CH_CONSOLE:\r
+ case CH_FILE:\r
+ case CH_SERIAL:\r
+ ++i;\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return i;\r
+}\r
+\r
+int\r
+cl_commander::console_input_avail(void)\r
+{\r
+ int i = 0;\r
+\r
+ FD_ZERO(&console_active_set);\r
+ for (int j = 0; j < cons->count; j++)\r
+ {\r
+ class cl_console *c = dynamic_cast<class cl_console*>((class cl_console_base*)(cons->at(j)));\r
+\r
+ if (c->input_avail())\r
+ {\r
+ HANDLE fd = c->get_in_fd();\r
+ assert(INVALID_HANDLE_VALUE != fd);\r
+\r
+ switch (c->in.get_type())\r
+ {\r
+ case CH_CONSOLE:\r
+ case CH_FILE:\r
+ case CH_SERIAL:\r
+ FD_SET((SOCKET)fd, &console_active_set);\r
+ ++i;\r
+ break;\r
+\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ return i;\r
+}\r
+\r
+int\r
+cl_commander::socket_input_avail(long timeout, bool sleep)\r
+{\r
+ active_set = read_set;\r
+\r
+ if (active_set.fd_count)\r
+ {\r
+ struct timeval tv = {0, 0};\r
+\r
+ struct timeval *tvp = sleep ? NULL : &tv;\r
+\r
+ int i = select(0, &active_set, NULL, NULL, tvp);\r
+ if (SOCKET_ERROR == i)\r
+ {\r
+ fprintf(stderr, "Can't select: %d\n", WSAGetLastError());\r
+ return 0;\r
+ }\r
+\r
+ return i;\r
+ }\r
+ else\r
+ {\r
+ Sleep(timeout / 1000);\r
+ return 0;\r
+ }\r
+}\r
+\r
+int\r
+cl_commander::input_avail_timeout(long timeout)\r
+{\r
+ TRACE("%s\n", __PRETTY_FUNCTION__);\r
+\r
+ int n;\r
+ if (0 != (n = console_input_avail()))\r
+ FD_ZERO(&active_set);\r
+ else\r
+ n = socket_input_avail(timeout, false);\r
+\r
+ return n;\r
+}\r
+\r
+#define CONSOLE_TIMEOUT 300000\r
+\r
+int\r
+cl_commander::wait_input(void)\r
+{\r
+ TRACE("%s\n", __PRETTY_FUNCTION__);\r
+\r
+ prompt();\r
+\r
+ if (0 < console_count())\r
+ {\r
+ int n;\r
+\r
+ while (0 == (n = input_avail_timeout(CONSOLE_TIMEOUT)))\r
+ ;\r
+\r
+ return n;\r
+ }\r
+ else\r
+ {\r
+ FD_ZERO(&console_active_set);\r
+ return socket_input_avail(0, true);\r
+ }\r
+}\r
+\r
+int\r
+cl_commander::proc_input(void)\r
+{\r
+ TRACE("%s\n", __PRETTY_FUNCTION__);\r
+\r
+ for (int j = 0; j < cons->count; j++)\r
+ {\r
+ class cl_console *c = dynamic_cast<class cl_console*>((class cl_console_base*)(cons->at(j)));\r
+\r
+ if (c->input_active())\r
+ {\r
+ HANDLE fd = c->get_in_fd();\r
+ assert(INVALID_HANDLE_VALUE != fd);\r
+\r
+ if (FD_ISSET(fd, &active_set) || FD_ISSET(fd, &console_active_set))\r
+ {\r
+ actual_console = c;\r
+ if (c->proc_input(cmdset))\r
+ {\r
+ del_console(c);\r
+ delete c;\r
+ }\r
+ actual_console = 0;\r
+ return 0 == cons->count;\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
+/* End of cmd.src/newcmdwin32.cc */\r
--- /dev/null
+/*
+ * Simulator of microcontrollers (cmd.src/newcmdwin32cl.h)
+ *
+ * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
+ * Copyright (C) 2006, Borut Razem - borut.razem@siol.net
+ *
+ * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
+ *
+ */
+
+/* This file is part of microcontroller simulator: ucsim.
+
+UCSIM is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+UCSIM is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with UCSIM; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
+/*@1@*/
+
+#ifndef CMD_NEWCMDFDCL_HEADER
+#define CMD_NEWCMDFDCL_HEADER
+
+#include "newcmdcl.h"
+#include "cmdutil.h"
+
+
+class cl_channel
+{
+public:
+ cl_channel(void) { set(); }
+ cl_channel(HANDLE _handle, e_handle_type _type = CH_UNDEF) { set(_handle, _type); }
+ cl_channel(FILE *_fp, e_handle_type _type = CH_UNDEF) { set(_fp, _type); }
+
+ void set(void);
+ void set(HANDLE _handle, e_handle_type _type = CH_UNDEF);
+ void set(FILE *_fp, e_handle_type _type = CH_UNDEF);
+
+ void close(void);
+ bool input_avail(void) const { return ::input_avail(handle, type); }
+ enum e_handle_type get_type(void) const { return type; }
+ HANDLE get_handle(void) const { return handle; }
+ FILE *get_fp(void) const { return fp; }
+ bool is_tty(void) const { return CH_FILE != type; }
+ bool is_eof(void) const { return get_fp() ? feof(get_fp()) : true; }
+
+private:
+ e_handle_type guess_type(void) { return get_handle_type(handle); }
+
+ e_handle_type type;
+ HANDLE handle;
+ FILE *fp;
+};
+
+
+/*
+ * Command socket console
+ */
+
+class cl_console: public cl_console_base
+{
+ friend class cl_commander;
+
+protected:
+ cl_channel in, out, rout/*redirected output*/;
+
+public:
+ cl_console(void) { in = cl_channel(); out = cl_channel(); rout = cl_channel(); }
+ cl_console(char *fin, char *fout, class cl_app *the_app);
+ cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
+ cl_console(cl_channel _in, cl_channel _out, class cl_app *the_app);
+
+ int cmd_do_print(char *format, va_list ap);
+
+ virtual ~cl_console(void);
+ virtual class cl_console *clone_for_exec(char *fin);
+
+ virtual void redirect(char *fname, char *mode);
+ virtual void un_redirect(void);
+ virtual bool is_tty(void) const { return CH_FILE != in.get_type(); }
+ virtual bool is_eof(void) const { return in.is_eof(); }
+ virtual HANDLE get_in_fd(void) { return in.get_handle(); }
+ virtual bool input_avail(void) { return input_active() ? in.input_avail() : false; }
+ virtual char *read_line(void);
+
+private:
+ class cl_channel *get_out(void) { return (CH_UNDEF != rout.get_type()) ? &rout : &out; }
+};
+
+class cl_listen_console: public cl_console
+{
+public:
+ cl_listen_console(int serverport, class cl_app *the_app);
+
+ virtual void welcome(void) {}
+ virtual int proc_input(class cl_cmdset *cmdset);
+};
+
+class cl_sub_console: public cl_console
+{
+private:
+ class cl_console_base *parent;
+
+public:
+ cl_sub_console(class cl_console_base *the_parent,
+ cl_channel _in, cl_channel _out, class cl_app *the_app);
+ virtual ~cl_sub_console(void);
+ virtual int init(void);
+};
+
+
+/*
+ * Command interpreter
+ */
+
+class cl_commander: public cl_commander_base
+{
+private:
+ fd_set read_set, active_set, console_active_set;
+
+public:
+ cl_commander(class cl_app *the_app, class cl_cmdset *acmdset)
+ : cl_commander_base(the_app, acmdset)
+ {
+ }
+
+ virtual int init(void);
+ virtual void set_fd_set(void);
+ virtual int input_avail(void) { return input_avail_timeout(0); }
+ virtual int wait_input(void);
+ virtual int proc_input(void);
+
+private:
+ int console_count(void);
+ int console_input_avail(void);
+ int socket_input_avail(long timeout, bool sleep);
+ int input_avail_timeout(long timeout);
+};
+
+#endif
+
+/* End of cmd.src/newcmdwin32cl.h */
//int
//cl_set_mem_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_set_mem_cmd)
{
class cl_memory *mem= 0;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, MEMORY ADDRESS DATALIST)) {
mem= params[0]->value.memory.memory;
con->dd_printf("Error: no data\n");
else if (start < mem->get_start_address())
con->dd_printf("Start address less then 0x%"_A_"x\n",
- mem->get_start_address());
+ mem->get_start_address());
else
{
- int i;
- t_addr addr;
- for (i= 0, addr= start;
- i < len && mem->valid_address(addr);
- i++, addr++)
- mem->write(addr, array[i]);
- uc->check_errors();
- mem->dump(start, start+len-1, 8, con);
+ int i;
+ t_addr addr;
+ for (i= 0, addr= start;
+ i < len && mem->valid_address(addr);
+ i++, addr++)
+ mem->write(addr, array[i]);
+ uc->check_errors();
+ mem->dump(start, start+len-1, 8, con);
}
}
else
//int
//cl_set_bit_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_set_bit_cmd)
{
class cl_memory *mem;
t_addr mem_addr= 0;
t_mem bit_mask= 0;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cmdline->syntax_match(uc, BIT NUMBER)) {
mem= params[0]->value.bit.mem;
{
class cl_hw *hw= 0;
class cl_cmd_arg *params[1]= { cmdline->param(0)/*,
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3)*/ };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3)*/ };
if (params[0] && /*cmdline->syntax_match(uc, HW)*/params[0]->as_hw(uc)) {
hw= params[0]->value.hw;
else*/
{
if (hw)
- {
- cmdline->shift();
- hw->set_cmd(cmdline, con);
- }
+ {
+ cmdline->shift();
+ hw->set_cmd(cmdline, con);
+ }
else
- con->dd_printf("Error: no hw\n");
+ con->dd_printf("Error: no hw\n");
}
return(DD_FALSE);;
}
//int
//cl_set_option_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_APP(cl_set_option_cmd)
{
char *id= 0, *s= 0;
int idx;
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
class cl_option *option= 0;
if (cmdline->syntax_match(0/*app->get_uc()*/, NUMBER STRING)) {
int n= app->options->nuof_options(id, cr);
if (n > 1)
{
- con->dd_printf("Ambiguous option name, use number instead\n");
- return(DD_FALSE);
+ con->dd_printf("Ambiguous option name, use number instead\n");
+ return(DD_FALSE);
}
else if (n == 0)
;//con->dd_printf("Named option does not exist\n");
else
{
- if ((option= app->options->get_option(id, cr)) == 0)
- option= app->options->get_option(cr, id);
+ if ((option= app->options->get_option(id, cr)) == 0)
+ option= app->options->get_option(cr, id);
}
}
else if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) {
int n= app->options->nuof_options(id);
if (n > 1)
{
- con->dd_printf("Ambiguous option name, use number instead\n");
- return(DD_FALSE);
+ con->dd_printf("Ambiguous option name, use number instead\n");
+ return(DD_FALSE);
}
else if (n == 0)
;//con->dd_printf("Named option does not exist\n");
//int
//cl_set_option_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_APP(cl_set_error_cmd)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
char *error_name= NIL, *value= NIL;
if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) {
{
int i;
for (i= 0; i < registered_errors->count; i++)
- {
- class cl_error_class *e=
- dynamic_cast<class cl_error_class *>(registered_errors->object_at(i));
- if (e->is_inamed(error_name))
- {
- if (strchr("uU-?", *value) != NULL)
- e->set_on(ERROR_PARENT);
- else if (strchr("1tTyY", *value) != NULL ||
- (strlen(value) > 1 &&
- strchr("nN", value[2]) != NULL))
- e->set_on(ERROR_ON);
- else if (strchr("0fFnN", *value) != NULL ||
- (strlen(value) > 1 &&
- strchr("fF", value[2]) != NULL))
- e->set_on(ERROR_OFF);
- else
- con->dd_printf("Bad value (%s)\n", value);
- return(DD_FALSE);
- }
- }
+ {
+ class cl_error_class *e=
+ dynamic_cast<class cl_error_class *>(registered_errors->object_at(i));
+ if (e->is_inamed(error_name))
+ {
+ if (strchr("uU-?", *value) != NULL)
+ e->set_on(ERROR_PARENT);
+ else if (strchr("1tTyY", *value) != NULL ||
+ (strlen(value) > 1 &&
+ strchr("nN", value[2]) != NULL))
+ e->set_on(ERROR_ON);
+ else if (strchr("0fFnN", *value) != NULL ||
+ (strlen(value) > 1 &&
+ strchr("fF", value[2]) != NULL))
+ e->set_on(ERROR_OFF);
+ else
+ con->dd_printf("Bad value (%s)\n", value);
+ return(DD_FALSE);
+ }
+ }
}
con->dd_printf("Error %s not found\n", error_name);
//int
//cl_show_copying_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK(cl_show_copying_cmd)
{
con->dd_printf("%s\n", copying);
//int
//cl_show_warranty_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK(cl_show_warranty_cmd)
{
con->dd_printf("%s\n", warranty);
{
class cl_option *o= (class cl_option *)(/*uc*/app->options->at(i));
if (!s ||
- !strcmp(s, o->get_name()))
- {
- int j;
- con->dd_printf("%d. %s: ", i, object_name(o));
- o->print(con);
- con->dd_printf(" - %s\n", o->help);
- con->dd_printf(" Type: %s\n", o->get_type_name());
- /*union option_value *val= o->get_value();
- con->dd_printf(" Value: \"");
- unsigned int uj;
- TYPE_UBYTE *d= (TYPE_UBYTE*)val;
- for (uj= 0; uj < sizeof(*val); uj++)
- con->print_char_octal(d[uj]);
- con->dd_printf("\"\n");*/
- con->dd_printf(" Hidden: %s\n", (o->hidden)?"True":"False");
- con->dd_printf(" Creator: \"%s\"\n %d Users:\n",
- object_name(o->get_creator()),
- o->users->count);
- for (j= 0; j < o->users->count; j++)
- {
- class cl_optref *r= (class cl_optref *)(o->users->at(j));
- con->dd_printf(" %2d. owner(s)=\"%s\"\n", j,
- object_name(r->get_owner()));
- }
- if (i >= 0 &&
- i < app->options->count-1)
- con->dd_printf("\n");
- }
+ !strcmp(s, o->get_name()))
+ {
+ int j;
+ con->dd_printf("%d. %s: ", i, object_name(o));
+ o->print(con);
+ con->dd_printf(" - %s\n", o->help);
+ con->dd_printf(" Type: %s\n", o->get_type_name());
+ /*union option_value *val= o->get_value();
+ con->dd_printf(" Value: \"");
+ unsigned int uj;
+ TYPE_UBYTE *d= (TYPE_UBYTE*)val;
+ for (uj= 0; uj < sizeof(*val); uj++)
+ con->print_char_octal(d[uj]);
+ con->dd_printf("\"\n");*/
+ con->dd_printf(" Hidden: %s\n", (o->hidden)?"True":"False");
+ con->dd_printf(" Creator: \"%s\"\n %d Users:\n",
+ object_name(o->get_creator()),
+ o->users->count);
+ for (j= 0; j < o->users->count; j++)
+ {
+ class cl_optref *r= (class cl_optref *)(o->users->at(j));
+ con->dd_printf(" %2d. owner(s)=\"%s\"\n", j,
+ object_name(r->get_owner()));
+ }
+ if (i >= 0 &&
+ i < app->options->count-1)
+ con->dd_printf("\n");
+ }
}
return(DD_FALSE);
#include "errorcl.h"
static void
-show_error_cmd_print_node(class cl_console *con,
- int indent, class cl_base *node)
+show_error_cmd_print_node(class cl_console_base *con,
+ int indent, class cl_base *node)
{
if (!node)
return;
class cl_error_class *ec= dynamic_cast<class cl_error_class *>(node);
char *str;
con->dd_printf("%s: %s [%s/%s]\n",
- str= case_string(case_case, ec->get_type_name()),
- name, get_id_string(error_on_off_names,
- ec->get_on()),
- (ec->is_on())?"ON":"OFF");
+ str= case_string(case_case, ec->get_type_name()),
+ name, get_id_string(error_on_off_names,
+ ec->get_on()),
+ (ec->is_on())?"ON":"OFF");
free(str);
class cl_base *c= node->first_child();
while (c)
class cl_error_class *ec;
ec= dynamic_cast<class cl_error_class*>(registered_errors->object_at(i));
if (!ec->get_parent())
- show_error_cmd_print_node(con, 0, ec);
+ show_error_cmd_print_node(con, 0, ec);
}
return(DD_FALSE);
}
//int
//cl_timer_cmd::do_work(class cl_sim *sim,
-// class cl_cmdline *cmdline, class cl_console *con)
+// class cl_cmdline *cmdline, class cl_console_base *con)
COMMAND_DO_WORK_UC(cl_timer_cmd)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (!params[0])
{
as_nr= DD_TRUE;
id_nr= params[0]->value.number;
if (id_nr <= 0)
- {
- con->dd_printf("Error: "
- "Timer id must be greater than zero or a string\n");
- return(DD_TRUE);
- }
+ {
+ con->dd_printf("Error: "
+ "Timer id must be greater than zero or a string\n");
+ return(DD_TRUE);
+ }
ticker= uc->get_counter(id_nr);
}
else
*/
COMMAND_DO_WORK_UC(cl_timer_add_cmd)
- //add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
+ //add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
long dir= +1, in_isr= 0;
if (cl_timer_cmd::do_work(uc, cmdline, con))
if (ticker)
{
if (!as_nr)
- con->dd_printf("Error: Timer \"%s\" already exists\n", id_str);
+ con->dd_printf("Error: Timer \"%s\" already exists\n", id_str);
else
- con->dd_printf("Error: Timer %d already exists\n", id_nr);
+ con->dd_printf("Error: Timer %d already exists\n", id_nr);
return(DD_FALSE);
}
if (cmdline->nuof_params() > 0)
{
if (cmdline->syntax_match(uc, NUMBER))
- dir= params[0]->value.number;
+ dir= params[0]->value.number;
else if (cmdline->syntax_match(uc, NUMBER NUMBER))
- {
- dir= params[0]->value.number;
- in_isr= params[1]->value.number;
- }
+ {
+ dir= params[0]->value.number;
+ in_isr= params[1]->value.number;
+ }
}
if (!as_nr)
*/
COMMAND_DO_WORK_UC(cl_timer_delete_cmd)
- //del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
+ //del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con)
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(DD_FALSE);
if (!ticker)
{
if (!as_nr)
- con->dd_printf("Timer \"%s\" does not exist\n", id_str);
+ con->dd_printf("Timer \"%s\" does not exist\n", id_str);
else
- con->dd_printf("Timer %d does not exist\n", id_nr);
+ con->dd_printf("Timer %d does not exist\n", id_nr);
return(DD_FALSE);
}
if (!as_nr)
*/
COMMAND_DO_WORK_UC(cl_timer_get_cmd)
- //get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
+ //get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con)
{
if (cmdline->nuof_params())
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
- return(DD_FALSE);
+ return(DD_FALSE);
}
else
ticker= 0;
uc->isr_ticks->dump(0, uc->xtal, con);
uc->idle_ticks->dump(0, uc->xtal, con);
for (id_nr= 0; id_nr < uc->counters->count; id_nr++)
- {
- ticker= uc->get_counter(id_nr);
- if (ticker)
- ticker->dump(id_nr, uc->xtal, con);
- }
+ {
+ ticker= uc->get_counter(id_nr);
+ if (ticker)
+ ticker->dump(id_nr, uc->xtal, con);
+ }
}
return(DD_FALSE);
*/
COMMAND_DO_WORK_UC(cl_timer_run_cmd)
- //run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
+ //run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con)
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(DD_FALSE);
if (!ticker)
{
if (!as_nr)
- con->dd_printf("Timer %d does not exist\n", id_str);
+ con->dd_printf("Timer %d does not exist\n", id_str);
else
- con->dd_printf("Timer %d does not exist\n", id_nr);
+ con->dd_printf("Timer %d does not exist\n", id_nr);
return(0);
}
ticker->options|= TICK_RUN;
*/
COMMAND_DO_WORK_UC(cl_timer_stop_cmd)
- //stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
+ //stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con)
{
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(DD_FALSE);
if (!ticker)
{
if (!as_nr)
- con->dd_printf("Timer %d does not exist\n", id_str);
+ con->dd_printf("Timer %d does not exist\n", id_str);
else
- con->dd_printf("Timer %d does not exist\n", id_nr);
+ con->dd_printf("Timer %d does not exist\n", id_nr);
return(DD_FALSE);
}
ticker->options&= ~TICK_RUN;
*/
COMMAND_DO_WORK_UC(cl_timer_value_cmd)
- //val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con)
+ //val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con)
{
class cl_cmd_arg *params[4]= { cmdline->param(0),
- cmdline->param(1),
- cmdline->param(2),
- cmdline->param(3) };
+ cmdline->param(1),
+ cmdline->param(2),
+ cmdline->param(3) };
if (cl_timer_cmd::do_work(uc, cmdline, con))
return(DD_FALSE);
if (!ticker)
{
if (!as_nr)
- con->dd_printf("Error: Timer %d does not exist\n", id_str);
+ con->dd_printf("Error: Timer %d does not exist\n", id_str);
else
- con->dd_printf("Error: Timer %d does not exist\n", id_nr);
+ con->dd_printf("Error: Timer %d does not exist\n", id_nr);
return(DD_FALSE);
}
if (params[2])
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK VERSION VERSIONHI VERSIONLO VERSIONP docdir enable_ucsim enable_dlso enable_51 enable_avr enable_z80 enable_hc08 enable_xa enable_serio CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT CXXCPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA RANLIB ac_ct_RANLIB STRIP build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS ac_ct_CC LN_S ECHO ac_ct_STRIP CPP EGREP LIBTOOL LIBTOOL_DEPS LEX LEXLIB LEX_OUTPUT_ROOT YACC BISON_PLUS_PLUS SERIAL_AVAIL dl_ok DL panel_ok curses_ok CURSES_LIBS M_OR_MM SHAREDLIB PICOPT dlso_ok LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK VERSION VERSIONHI VERSIONLO VERSIONP docdir enable_ucsim enable_dlso enable_51 enable_avr enable_z80 enable_hc08 enable_xa enable_serio CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT CXXCPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA RANLIB ac_ct_RANLIB STRIP build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS ac_ct_CC LN_S ECHO ac_ct_STRIP CPP EGREP LIBTOOL LIBTOOL_DEPS LEX LEXLIB LEX_OUTPUT_ROOT YACC BISON_PLUS_PLUS WINSOCK_AVAIL dl_ok DL panel_ok curses_ok CURSES_LIBS M_OR_MM SHAREDLIB PICOPT dlso_ok LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
fi
if test ${LEX} = "flex"; then
- cat >>confdefs.h <<\_ACEOF
+ cat >>confdefs.h <<\_ACEOF
#define HAVE_FLEX 1
_ACEOF
fi
-for ac_header in getopt.h
-do
-as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking $ac_header usability" >&5
-echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <$ac_header>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_cxx_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-# Is the header present?
-echo "$as_me:$LINENO: checking $ac_header presence" >&5
-echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <$ac_header>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_cxx_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
-echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for $ac_header" >&5
-echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
-if eval "test \"\${$as_ac_Header+set}\" = set"; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- eval "$as_ac_Header=\$ac_header_preproc"
-fi
-echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
-echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
-
-fi
-if test `eval echo '${'$as_ac_Header'}'` = yes; then
- cat >>confdefs.h <<_ACEOF
-#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
-_ACEOF
-
-fi
-
-done
-
-
-for ac_header in unistd.h
+for ac_header in getopt.h unistd.h termios.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
done
-if test "${ac_cv_header_termios_h+set}" = set; then
- echo "$as_me:$LINENO: checking for termios.h" >&5
-echo $ECHO_N "checking for termios.h... $ECHO_C" >&6
-if test "${ac_cv_header_termios_h+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-fi
-echo "$as_me:$LINENO: result: $ac_cv_header_termios_h" >&5
-echo "${ECHO_T}$ac_cv_header_termios_h" >&6
-else
- # Is the header compilable?
-echo "$as_me:$LINENO: checking termios.h usability" >&5
-echo $ECHO_N "checking termios.h usability... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-$ac_includes_default
-#include <termios.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
- (eval $ac_compile) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } &&
- { ac_try='test -z "$ac_cxx_werror_flag"
- || test ! -s conftest.err'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; } &&
- { ac_try='test -s conftest.$ac_objext'
- { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
- (eval $ac_try) 2>&5
- ac_status=$?
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); }; }; then
- ac_header_compiler=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_header_compiler=no
-fi
-rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
-echo "${ECHO_T}$ac_header_compiler" >&6
-
-# Is the header present?
-echo "$as_me:$LINENO: checking termios.h presence" >&5
-echo $ECHO_N "checking termios.h presence... $ECHO_C" >&6
-cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h. */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h. */
-#include <termios.h>
-_ACEOF
-if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
- (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
- ac_status=$?
- grep -v '^ *+' conftest.er1 >conftest.err
- rm -f conftest.er1
- cat conftest.err >&5
- echo "$as_me:$LINENO: \$? = $ac_status" >&5
- (exit $ac_status); } >/dev/null; then
- if test -s conftest.err; then
- ac_cpp_err=$ac_cxx_preproc_warn_flag
- ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag
- else
- ac_cpp_err=
- fi
-else
- ac_cpp_err=yes
-fi
-if test -z "$ac_cpp_err"; then
- ac_header_preproc=yes
-else
- echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
- ac_header_preproc=no
-fi
-rm -f conftest.err conftest.$ac_ext
-echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
-echo "${ECHO_T}$ac_header_preproc" >&6
-
-# So? What about this header?
-case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in
- yes:no: )
- { echo "$as_me:$LINENO: WARNING: termios.h: accepted by the compiler, rejected by the preprocessor!" >&5
-echo "$as_me: WARNING: termios.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
- { echo "$as_me:$LINENO: WARNING: termios.h: proceeding with the compiler's result" >&5
-echo "$as_me: WARNING: termios.h: proceeding with the compiler's result" >&2;}
- ac_header_preproc=yes
- ;;
- no:yes:* )
- { echo "$as_me:$LINENO: WARNING: termios.h: present but cannot be compiled" >&5
-echo "$as_me: WARNING: termios.h: present but cannot be compiled" >&2;}
- { echo "$as_me:$LINENO: WARNING: termios.h: check for missing prerequisite headers?" >&5
-echo "$as_me: WARNING: termios.h: check for missing prerequisite headers?" >&2;}
- { echo "$as_me:$LINENO: WARNING: termios.h: see the Autoconf documentation" >&5
-echo "$as_me: WARNING: termios.h: see the Autoconf documentation" >&2;}
- { echo "$as_me:$LINENO: WARNING: termios.h: section \"Present But Cannot Be Compiled\"" >&5
-echo "$as_me: WARNING: termios.h: section \"Present But Cannot Be Compiled\"" >&2;}
- { echo "$as_me:$LINENO: WARNING: termios.h: proceeding with the preprocessor's result" >&5
-echo "$as_me: WARNING: termios.h: proceeding with the preprocessor's result" >&2;}
- { echo "$as_me:$LINENO: WARNING: termios.h: in the future, the compiler will take precedence" >&5
-echo "$as_me: WARNING: termios.h: in the future, the compiler will take precedence" >&2;}
- (
- cat <<\_ASBOX
-## ------------------------------------------ ##
-## Report this to the AC_PACKAGE_NAME lists. ##
-## ------------------------------------------ ##
-_ASBOX
- ) |
- sed "s/^/$as_me: WARNING: /" >&2
- ;;
-esac
-echo "$as_me:$LINENO: checking for termios.h" >&5
-echo $ECHO_N "checking for termios.h... $ECHO_C" >&6
-if test "${ac_cv_header_termios_h+set}" = set; then
- echo $ECHO_N "(cached) $ECHO_C" >&6
-else
- ac_cv_header_termios_h=$ac_header_preproc
-fi
-echo "$as_me:$LINENO: result: $ac_cv_header_termios_h" >&5
-echo "${ECHO_T}$ac_cv_header_termios_h" >&6
-
-fi
-if test $ac_cv_header_termios_h = yes; then
- cat >>confdefs.h <<\_ACEOF
-#define HAVE_TERMIOS_H 1
-_ACEOF
-
- SERIAL_AVAIL=1
-else
- SERIAL_AVAIL=0
-
-fi
-
-
-
-
if test "${ac_cv_header_curses_h+set}" = set; then
echo "$as_me:$LINENO: checking for curses.h" >&5
echo $ECHO_N "checking for curses.h... $ECHO_C" >&6
+WINSOCK_AVAIL=0
if test $ucsim_cv_socket = unknown; then
if test "${ac_cv_header_winsock2_h+set}" = set; then
echo "$as_me:$LINENO: checking for winsock2.h" >&5
_ACEOF
ucsim_cv_socket="<winsock2.h>"
+ WINSOCK_AVAIL=1
fi
fi
+
if test $ucsim_cv_socket != unknown; then
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
# Checking for functions/libs
# ===========================================================================
if echo $ucsim_cv_socket|grep winsock2 >/dev/null 2>&1; then
- LIBS="-lwsock32 $LIBS"
+ LIBS="-lws2_32 $LIBS"
else
echo "$as_me:$LINENO: checking for socket in -lsocket" >&5
done
+for ac_func in _vsnprintf
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+ For example, HP-UX 11i <limits.h> declares gettimeofday. */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $ac_func (); below.
+ Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ <limits.h> exists even on freestanding compilers. */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_cxx_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ eval "$as_ac_var=yes"
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
for ac_func in vasprintf
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
else
#echo "CROSS ENDIAN"
if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
- ac_cv_c_bigendian=no
+ ac_cv_c_bigendian=no
else
- : # FIXME
+ : # FIXME
fi
#echo "CROSS ENDIAN DONE"
fi
gopt="-g"
fi
if test "$CXXFLAGS"x = x ;then
- CXXFLAGS="$gopt"
+ CXXFLAGS="$gopt"
else
- CXXFLAGS="$CXXFLAGS $gopt"
+ CXXFLAGS="$CXXFLAGS $gopt"
fi
echo "${ECHO_T}$ucsim_cv_CXXfpic" >&6
if test "$ucsim_cv_CXXfpic" = "yes"; then
- PICOPT="-fpic"
+ PICOPT="-fpic"
fi
fi
if test "$PICOPT"x != "x"; then
else
if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
- ac_cv_sizeof_char=1
- ac_cv_sizeof_short=2
- ac_cv_sizeof_int=4
- ac_cv_sizeof_long=4
- ac_cv_sizeof_long_long=4
+ ac_cv_sizeof_char=1
+ ac_cv_sizeof_short=2
+ ac_cv_sizeof_int=4
+ ac_cv_sizeof_long=4
+ ac_cv_sizeof_long_long=4
else
- : # FIXME
+ : # FIXME
fi
#echo
fi
type_name()
{
if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then
- echo "char"
- exit
+ echo "char"
+ exit
fi
if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then
- echo "short"
- exit
+ echo "short"
+ exit
fi
if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then
- echo "int"
- exit
+ echo "int"
+ exit
fi
if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then
- echo "long"
- exit
+ echo "long"
+ exit
fi
if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then
- echo "long long"
- exit
+ echo "long long"
+ exit
fi
echo "long long"
}
s,@LEX_OUTPUT_ROOT@,$LEX_OUTPUT_ROOT,;t t
s,@YACC@,$YACC,;t t
s,@BISON_PLUS_PLUS@,$BISON_PLUS_PLUS,;t t
-s,@SERIAL_AVAIL@,$SERIAL_AVAIL,;t t
+s,@WINSOCK_AVAIL@,$WINSOCK_AVAIL,;t t
s,@dl_ok@,$dl_ok,;t t
s,@DL@,$DL,;t t
s,@panel_ok@,$panel_ok,;t t
AC_PROG_LEX
if test ${LEX} = "flex"; then
- AC_DEFINE(HAVE_FLEX)
+ AC_DEFINE(HAVE_FLEX)
fi
AC_PROG_YACC
AC_CHECK_PROG(BISON_PLUS_PLUS, bison++, bison++, :)
fi
AC_HEADER_STDC
-AC_CHECK_HEADERS(getopt.h)
-AC_CHECK_HEADERS(unistd.h)
-
-AC_CHECK_HEADER(termios.h,
- AC_DEFINE(HAVE_TERMIOS_H)
- SERIAL_AVAIL=1,
- SERIAL_AVAIL=0
-)
-AC_SUBST(SERIAL_AVAIL)
+AC_CHECK_HEADERS(getopt.h unistd.h termios.h)
AC_CHECK_HEADER(curses.h,
AC_DEFINE(HAVE_CURSES_H)
ucsim_cv_socket="<sys/socket.h>"
)
+WINSOCK_AVAIL=0
if test $ucsim_cv_socket = unknown; then
AC_CHECK_HEADER(winsock2.h,
AC_DEFINE(HAVE_WINSOCK2_H)
AC_DEFINE(SOCKET_AVAIL)
AC_DEFINE_UNQUOTED(UCSOCKET_T, SOCKET)
ucsim_cv_socket="<winsock2.h>"
+ WINSOCK_AVAIL=1
)
fi
+AC_SUBST(WINSOCK_AVAIL)
if test $ucsim_cv_socket != unknown; then
AC_EGREP_HEADER(socklen_t,
# Checking for functions/libs
# ===========================================================================
if echo $ucsim_cv_socket|grep winsock2 >/dev/null 2>&1; then
- LIBS="-lwsock32 $LIBS"
+ LIBS="-lws2_32 $LIBS"
else
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(nsl,xdr_short)
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(vsnprintf)
+AC_CHECK_FUNCS(_vsnprintf)
AC_CHECK_FUNCS(vasprintf)
AC_CHECK_FUNCS(strlen strcpy strcat strstr strcmp strerror strtok strdup)
AC_CHECK_FUNCS(strchr memcpy)
ac_cv_c_bigendian=no
ac_cv_sizeof_char=1
ac_cv_sizeof_short=2
- ac_cv_sizeof_int=4
+ ac_cv_sizeof_int=4
ac_cv_sizeof_long=4
ac_cv_sizeof_long_long=4
fi
else
#echo "CROSS ENDIAN"
if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
- ac_cv_c_bigendian=no
+ ac_cv_c_bigendian=no
else
- : # FIXME
+ : # FIXME
fi
#echo "CROSS ENDIAN DONE"
fi
gopt="-gstabs+ -g3"
elif test "$ucsim_cv_CXXggdb" = "yes"; then
gopt="-ggdb -g3"
-else
+else
gopt="-g"
fi
if test "$CXXFLAGS"x = x ;then
- CXXFLAGS="$gopt"
+ CXXFLAGS="$gopt"
else
- CXXFLAGS="$CXXFLAGS $gopt"
+ CXXFLAGS="$CXXFLAGS $gopt"
fi
DD_COPT(CXX, pipe)
else
DD_COPT(CXX, fpic)
if test "$ucsim_cv_CXXfpic" = "yes"; then
- PICOPT="-fpic"
+ PICOPT="-fpic"
fi
fi
if test "$PICOPT"x != "x"; then
AC_CHECK_SIZEOF(long long)
else
if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then
- ac_cv_sizeof_char=1
- ac_cv_sizeof_short=2
- ac_cv_sizeof_int=4
- ac_cv_sizeof_long=4
- ac_cv_sizeof_long_long=4
+ ac_cv_sizeof_char=1
+ ac_cv_sizeof_short=2
+ ac_cv_sizeof_int=4
+ ac_cv_sizeof_long=4
+ ac_cv_sizeof_long_long=4
else
- : # FIXME
+ : # FIXME
fi
#echo
fi
type_name()
{
if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then
- echo "char"
- exit
+ echo "char"
+ exit
fi
if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then
- echo "short"
- exit
+ echo "short"
+ exit
fi
if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then
- echo "int"
- exit
+ echo "int"
+ exit
fi
if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then
- echo "long"
- exit
+ echo "long"
+ exit
fi
if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then
- echo "long long"
- exit
+ echo "long long"
+ exit
fi
echo "long long"
}
* Simulator of microcontrollers (ddconfig.h)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#define DD_TRUE 1
#define DD_FALSE 0
-#define NIL 0
+#define NIL 0
#undef STDC_HEADERS
#undef HAVE_GETOPT_H
#undef HAVE_VPRINTF
#undef HAVE_DOPRNT
#undef HAVE_VSNPRINTF
+#undef HAVE__VSNPRINTF
#undef HAVE_VASPRINTF
#undef HAVE_GETLINE
struct id_element error_on_off_names[]= {
{ ERROR_PARENT, "unset" },
- { ERROR_ON , "on" },
- { ERROR_OFF , "off" },
- { 0 , 0 }
+ { ERROR_ON , "on" },
+ { ERROR_OFF , "off" },
+ { 0 , 0 }
};
static class cl_error_registry error_registry;
*/
cl_error_class::cl_error_class(enum error_type typ, char *aname,
- enum error_on_off be_on/* = ERROR_PARENT*/):
+ enum error_on_off be_on/* = ERROR_PARENT*/):
cl_base()
{
type= typ;
}
cl_error_class::cl_error_class(enum error_type typ, char *aname,
- class cl_error_class *parent,
- enum error_on_off be_on/* = ERROR_PARENT*/):
+ class cl_error_class *parent,
+ enum error_on_off be_on/* = ERROR_PARENT*/):
cl_base()
{
type= typ;
if (on == ERROR_PARENT)
{
if (!get_parent())
- return(DD_TRUE);
+ return(DD_TRUE);
class cl_error_class *p=
- dynamic_cast<class cl_error_class *>(get_parent());
+ dynamic_cast<class cl_error_class *>(get_parent());
return(p->is_on());
}
else
}
void
-cl_error::print(class cl_commander *c)
+cl_error::print(class cl_commander_base *c)
{
c->dd_printf("%s\n", get_type_name());
}
enum error_on_off on;
public:
cl_error_class(enum error_type typ, char *aname,
- enum error_on_off be_on= ERROR_PARENT);
+ enum error_on_off be_on= ERROR_PARENT);
cl_error_class(enum error_type typ, char *aname,
- class cl_error_class *parent,
- enum error_on_off be_on= ERROR_PARENT);
+ class cl_error_class *parent,
+ enum error_on_off be_on= ERROR_PARENT);
enum error_on_off get_on(void) { return(on); }
void set_on(enum error_on_off val);
}
};
-class cl_commander; //forward
+class cl_commander_base; //forward
class cl_error: public cl_base
{
protected:
class cl_error_class *classification;
public:
- bool inst; // Occured during instruction execution
- t_addr PC; // Address of the instruction
+ bool inst; // Occured during instruction execution
+ t_addr PC; // Address of the instruction
public:
cl_error(void);
virtual ~cl_error(void);
virtual bool is_on(void);
virtual class cl_error_class *get_class(void) { return(classification); }
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
virtual char *get_type_name();
};
while (*b)
{
if (*b == '%')
- {
- b++;
- switch (*(b++))
- {
- case 's': // s signed byte immediate
- sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- case 'w': // w word immediate operand
- sprintf(temp, "#0x%04x",
- (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) |
- (get_mem(MEM_ROM_ID, addr+immed_offset+1))) );
- ++immed_offset;
- ++immed_offset;
- break;
- case 'b': // b byte immediate operand
- sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- case 'x': // x extended addressing
- sprintf(temp, "0x%04x",
- (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) |
- (get_mem(MEM_ROM_ID, addr+immed_offset+1))) );
- ++immed_offset;
- ++immed_offset;
- break;
- case 'd': // d direct addressing
- sprintf(temp, "*0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- case '2': // 2 word index offset
- sprintf(temp, "0x%04x",
- (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) |
- (get_mem(MEM_ROM_ID, addr+immed_offset+1))) );
- ++immed_offset;
- ++immed_offset;
- break;
- case '1': // b byte index offset
+ {
+ b++;
+ switch (*(b++))
+ {
+ case 's': // s signed byte immediate
+ sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset));
+ ++immed_offset;
+ break;
+ case 'w': // w word immediate operand
+ sprintf(temp, "#0x%04x",
+ (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) |
+ (get_mem(MEM_ROM_ID, addr+immed_offset+1))) );
+ ++immed_offset;
+ ++immed_offset;
+ break;
+ case 'b': // b byte immediate operand
+ sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
+ ++immed_offset;
+ break;
+ case 'x': // x extended addressing
+ sprintf(temp, "0x%04x",
+ (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) |
+ (get_mem(MEM_ROM_ID, addr+immed_offset+1))) );
+ ++immed_offset;
+ ++immed_offset;
+ break;
+ case 'd': // d direct addressing
+ sprintf(temp, "*0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
+ ++immed_offset;
+ break;
+ case '2': // 2 word index offset
+ sprintf(temp, "0x%04x",
+ (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) |
+ (get_mem(MEM_ROM_ID, addr+immed_offset+1))) );
+ ++immed_offset;
+ ++immed_offset;
+ break;
+ case '1': // b byte index offset
sprintf(temp, "0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- case 'p': // b byte index offset
+ ++immed_offset;
+ break;
+ case 'p': // b byte index offset
sprintf(temp, "0x%04x",
addr+immed_offset+1
+(char)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- default:
- strcpy(temp, "?");
- break;
- }
- t= temp;
- while (*t)
- *(p++)= *(t++);
- }
+ ++immed_offset;
+ break;
+ default:
+ strcpy(temp, "?");
+ break;
+ }
+ t= temp;
+ while (*t)
+ *(p++)= *(t++);
+ }
else
- *(p++)= *(b++);
+ *(p++)= *(b++);
}
*p= '\0';
if (sep == NULL)
{
while (strlen(buf) < 6)
- strcat(buf, " ");
+ strcat(buf, " ");
}
else
strcat(buf, sep);
void
-cl_hc08::print_regs(class cl_console *con)
+cl_hc08::print_regs(class cl_console_base *con)
{
con->dd_printf("V--HINZC Flags= 0x%02x %3d %c ",
- regs.P, regs.P, isprint(regs.P)?regs.P:'.');
+ regs.P, regs.P, isprint(regs.P)?regs.P:'.');
con->dd_printf("A= 0x%02x %3d %c\n",
- regs.A, regs.A, isprint(regs.A)?regs.A:'.');
+ regs.A, regs.A, isprint(regs.A)?regs.A:'.');
con->dd_printf("%c--%c%c%c%c%c ",
- (regs.P&BIT_V)?'1':'0',
- (regs.P&BIT_H)?'1':'0',
- (regs.P&BIT_I)?'1':'0',
- (regs.P&BIT_N)?'1':'0',
- (regs.P&BIT_Z)?'1':'0',
- (regs.P&BIT_C)?'1':'0');
+ (regs.P&BIT_V)?'1':'0',
+ (regs.P&BIT_H)?'1':'0',
+ (regs.P&BIT_I)?'1':'0',
+ (regs.P&BIT_N)?'1':'0',
+ (regs.P&BIT_Z)?'1':'0',
+ (regs.P&BIT_C)?'1':'0');
con->dd_printf(" H= 0x%02x %3d %c ",
- regs.H, regs.H, isprint(regs.H)?regs.H:'.');
+ regs.H, regs.H, isprint(regs.H)?regs.H:'.');
con->dd_printf("X= 0x%02x %3d %c\n",
- regs.X, regs.X, isprint(regs.X)?regs.X:'.');
+ regs.X, regs.X, isprint(regs.X)?regs.X:'.');
con->dd_printf("SP= 0x%04x [SP+1]= %02x %3d %c\n",
- regs.SP, ram->get(regs.SP+1), ram->get(regs.SP+1),
- isprint(ram->get(regs.SP+1))?ram->get(regs.SP+1):'.');
+ regs.SP, ram->get(regs.SP+1), ram->get(regs.SP+1),
+ isprint(ram->get(regs.SP+1))?ram->get(regs.SP+1):'.');
print_disass(PC, con);
}
virtual int inst_branch(t_addr addr);
virtual int longest_inst(void);
virtual char *disass(t_addr addr, char *sep);
- virtual void print_regs(class cl_console *con);
+ virtual void print_regs(class cl_console_base *con);
virtual int exec_inst(void);
/*struct id_element option_type_names[]= {
- { non_opt , "non" },
- { integer_opt , "integer" },
- { float_opt , "float" },
- { bool_opt , "boolean" },
- { string_opt , "string" },
- { pointer_opt , "pointer" },
+ { non_opt , "non" },
+ { integer_opt , "integer" },
+ { float_opt , "float" },
+ { bool_opt , "boolean" },
+ { string_opt , "string" },
+ { pointer_opt , "pointer" },
{ 0, 0 }
};*/
idx--;
o= (class cl_option *)(at(idx));
while (compare(the_name, key_of(o)) == 0 &&
- idx > 0)
- {
- idx--;
- o= (class cl_option *)(at(idx));
- }
+ idx > 0)
+ {
+ idx--;
+ o= (class cl_option *)(at(idx));
+ }
if (compare(the_name, key_of(o)) != 0)
- idx++;
+ idx++;
}
o= (class cl_option *)(at(idx));
while (compare(the_name, key_of(o)) == 0 &&
- o->get_creator() != creator &&
- idx < count)
+ o->get_creator() != creator &&
+ idx < count)
{
idx++;
o= (class cl_option *)(at(idx));
if (compare(the_name, key_of(o)) == 0 &&
- o->get_creator() == creator)
- return(o);
+ o->get_creator() == creator)
+ return(o);
}
if (compare(the_name, key_of(o)) == 0 &&
o->get_creator() == creator)
idx--;
o= (class cl_option *)(at(idx));
while (compare(the_name, key_of(o)) == 0 &&
- idx > 0)
- {
- idx--;
- o= (class cl_option *)(at(idx));
- }
+ idx > 0)
+ {
+ idx--;
+ o= (class cl_option *)(at(idx));
+ }
if (compare(the_name, key_of(o)) != 0)
- idx++;
+ idx++;
}
o= (class cl_option *)(at(idx));
while (compare(the_name, key_of(o)) == 0 &&
- strcmp(object_name(o->get_creator()), creator) != 0 &&
- idx < count)
+ strcmp(object_name(o->get_creator()), creator) != 0 &&
+ idx < count)
{
idx++;
o= (class cl_option *)(at(idx));
if (compare(the_name, key_of(o)) == 0 &&
- strcmp(object_name(o->get_creator()), creator) == 0)
- return(o);
+ strcmp(object_name(o->get_creator()), creator) == 0)
+ return(o);
}
if (compare(the_name, key_of(o)) == 0 &&
strcmp(object_name(o->get_creator()), creator) == 0)
{
class cl_option *o= (class cl_option *)(at(i));
if (strcmp(the_name, o->get_name()) == 0)
- n++;
+ n++;
}
return(n);
}
{
class cl_option *o= (class cl_option *)(at(i));
if (strcmp(the_name, o->get_name()) == 0 &&
- strcmp(creator, object_name(o->get_creator())) == 0)
- n++;
+ strcmp(creator, object_name(o->get_creator())) == 0)
+ n++;
}
return(n);
}
{
option->del_reference(this);
if (option->get_creator() == owner)
- application->options->del_option(option);
+ application->options->del_option(option);
}
}
class cl_option *
cl_optref::create(class cl_base *creator,
- enum option_type type,
- char *the_name, char *help)
+ enum option_type type,
+ char *the_name, char *help)
{
if (option)
option->del_reference(this);
if (!option)
{
fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
- "bool option: %s\n", object_name(owner), get_name());
+ "bool option: %s\n", object_name(owner), get_name());
return(DD_FALSE);
}
else
if (!option)
{
fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
- "string option: %s\n", object_name(owner), get_name());
+ "string option: %s\n", object_name(owner), get_name());
return(0);
}
else
if (!option)
{
fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
- "pointer option: %s\n", object_name(owner), get_name());
+ "pointer option: %s\n", object_name(owner), get_name());
return(NIL);
}
else
if (!option)
{
fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
- "number option: %s\n", object_name(owner), get_name());
+ "number option: %s\n", object_name(owner), get_name());
return(0);
}
else
if (!option)
{
fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent "
- "float option: %s\n", object_name(owner), get_name());
+ "float option: %s\n", object_name(owner), get_name());
return(0);
}
else
*/
cl_bool_option::cl_bool_option(class cl_base *the_creator,
- char *aname, char *Ihelp):
+ char *aname, char *Ihelp):
cl_option(the_creator, aname, Ihelp)
{}
void
-cl_bool_option::print(class cl_console *con)
+cl_bool_option::print(class cl_console_base *con)
{
if (/**(bool *)option*/value.bval)
con->dd_printf("TRUE");
{
c= toupper(*s);
if (c == '1' ||
- c == 'T' ||
- c == 'Y')
- /**(bool *)option=*/ value.bval= DD_TRUE;
+ c == 'T' ||
+ c == 'Y')
+ /**(bool *)option=*/ value.bval= DD_TRUE;
else
- /**(bool *)option=*/ value.bval= DD_FALSE;
+ /**(bool *)option=*/ value.bval= DD_FALSE;
}
inform_users();
}
*/
cl_string_option::cl_string_option(class cl_base *the_creator,
- char *aname, char *Ihelp):
+ char *aname, char *Ihelp):
cl_option(the_creator, aname, Ihelp)
{}
}
void
-cl_string_option::print(class cl_console *con)
+cl_string_option::print(class cl_console_base *con)
{
if (/**(bool *)option*/value.sval)
con->dd_printf("\"%s\"", value.sval);
*/
cl_pointer_option::cl_pointer_option(class cl_base *the_creator,
- char *aname, char *Ihelp):
+ char *aname, char *Ihelp):
cl_option(the_creator, aname, Ihelp)
{}
}
void
-cl_pointer_option::print(class cl_console *con)
+cl_pointer_option::print(class cl_console_base *con)
{
if (value.pval)
con->dd_printf("\"%p\"", value.pval);
*/
/*
cl_cons_debug_opt::cl_cons_debug_opt(class cl_app *the_app,
- char *Iid,
- char *Ihelp):
+ char *Iid,
+ char *Ihelp):
cl_option(0, Iid, Ihelp)
{
app= the_app;
}
void
-cl_cons_debug_opt::print(class cl_console *con)
+cl_cons_debug_opt::print(class cl_console_base *con)
{
if (con->flags & CONS_DEBUG)
con->dd_printf("TRUE");
if (app->get_commander()->actual_console)
{
if (opt)
- app->get_commander()->actual_console->flags|= CONS_DEBUG;
+ app->get_commander()->actual_console->flags|= CONS_DEBUG;
else
- app->get_commander()->actual_console->flags&= ~CONS_DEBUG;
+ app->get_commander()->actual_console->flags&= ~CONS_DEBUG;
}
inform_users();
}
{
c= toupper(*s);
if (c == '1' ||
- c == 'T' ||
- c == 'Y')
- set_value(1);
+ c == 'T' ||
+ c == 'Y')
+ set_value(1);
else
- set_value(0);
+ set_value(0);
}
}
*/
*/
cl_number_option::cl_number_option(class cl_base *the_creator,
- char *aname, char *Ihelp):
+ char *aname, char *Ihelp):
cl_option(the_creator, aname, Ihelp)
{}
void
-cl_number_option::print(class cl_console *con)
+cl_number_option::print(class cl_console_base *con)
{
con->dd_printf("%ld", value.ival);
}
*/
cl_float_option::cl_float_option(class cl_base *the_creator,
- char *aname, char *Ihelp):
+ char *aname, char *Ihelp):
cl_option(the_creator, aname, Ihelp)
{}
void
-cl_float_option::print(class cl_console *con)
+cl_float_option::print(class cl_console_base *con)
{
con->dd_printf("%.3f", value.fval);
}
virtual void hide(void) { hidden= DD_TRUE; }
virtual void show(void) { hidden= DD_FALSE; }
- virtual void print(class cl_console *con) {}
+ virtual void print(class cl_console_base *con) {}
virtual char *get_type_name(void) { return("non"); }
virtual union option_value *get_value(void) { return(&value); }
virtual int nuof_options(char *the_name, char *creator);
virtual class cl_option *set_value(char *the_name, cl_base *creator,
- bool value);
+ bool value);
virtual class cl_option *set_value(char *the_name, cl_base *creator,
- char *value);
+ char *value);
virtual class cl_option *set_value(char *the_name, cl_base *creator,
- void *value);
+ void *value);
virtual class cl_option *set_value(char *the_name, cl_base *creator,
- long value);
+ long value);
virtual class cl_option *set_value(char *the_name, cl_base *creator,
- double value);
+ double value);
};
virtual ~cl_optref(void);
virtual class cl_option *create(class cl_base *creator,
- enum option_type type,
- char *the_name, char *help);
+ enum option_type type,
+ char *the_name, char *help);
virtual void default_option(char *the_name);
virtual class cl_option *use(void);
virtual class cl_option *use(char *the_name);
{
public:
cl_bool_option(class cl_base *the_creator, char *aname, char *Ihelp);
- virtual void print(class cl_console *con);
+ virtual void print(class cl_console_base *con);
virtual char *get_type_name(void) { return("boolean"); }
virtual void set_value(char *s);
};
public:
cl_string_option(class cl_base *the_creator, char *aname, char *Ihelp);
virtual class cl_option &operator=(class cl_option &o);
- virtual void print(class cl_console *con);
+ virtual void print(class cl_console_base *con);
virtual char *get_type_name(void) { return("string"); }
};
public:
cl_pointer_option(class cl_base *the_creator, char *aname, char *Ihelp);
virtual class cl_option &operator=(class cl_option &o);
- virtual void print(class cl_console *con);
+ virtual void print(class cl_console_base *con);
virtual char *get_type_name(void) { return("pointer"); }
};
{
public:
cl_number_option(class cl_base *the_creator, char *aname, char *Ihelp);
- virtual void print(class cl_console *con);
+ virtual void print(class cl_console_base *con);
virtual char *get_type_name(void) { return("integer"); }
virtual void set_value(char *s);
};
{
public:
cl_float_option(class cl_base *the_creator, char *aname, char *Ihelp);
- virtual void print(class cl_console *con);
+ virtual void print(class cl_console_base *con);
virtual char *get_type_name(void) { return("float"); }
virtual void set_value(char *s);
};
public:
cl_cons_debug_opt(class cl_app *the_app, char *Iid, char *Ihelp);
- virtual void print(class cl_console *con);
+ virtual void print(class cl_console_base *con);
virtual void get_value(bool *val);
M_OR_MM = @M_OR_MM@
PICOPT = @PICOPT@
SHAREDLIB = @SHAREDLIB@
-SERIAL_AVAIL = @SERIAL_AVAIL@
SDCC = sdcc
SDCFLAGS = --debug --stack-after-data --model-small
OBJECTS_SHARED = glob.o sim51.o \
inc.o jmp.o mov.o logic.o arith.o bit.o \
- timer0.o timer1.o timer2.o port.o interrupt.o \
+ timer0.o timer1.o timer2.o serial.o port.o interrupt.o \
wdt.o pca.o \
uc51.o uc52.o uc51r.o uc89c51r.o uc251.o \
uc390.o uc390hw.o
-
-ifeq ($(SERIAL_AVAIL), 1)
-OBJECTS_SHARED += serial.o
-endif
-
OBJECTS_EXE = s51.o
OBJECTS = $(OBJECTS_SHARED) $(OBJECTS_EXE)
cl_interrupt::added_to_uc(void)
{
uc->it_sources->add(new cl_it_src(bmEX0, TCON, bmIE0, 0x0003, true,
- "external #0", 1));
+ "external #0", 1));
uc->it_sources->add(new cl_it_src(bmEX1, TCON, bmIE1, 0x0013, true,
- "external #1", 3));
+ "external #1", 3));
}
void
t_mem p3n= ep->new_pins & ep->new_value;
t_mem p3o= ep->pins & ep->prev_value;
if (bit_IT0 &&
- !(p3n & bm_INT0) &&
- (p3o & bm_INT0))
- cell_tcon->set_bit1(bmIE0);
+ !(p3n & bm_INT0) &&
+ (p3o & bm_INT0))
+ cell_tcon->set_bit1(bmIE0);
if (bit_IT1 &&
- !(p3n & bm_INT1) &&
- (p3o & bm_INT1))
- cell_tcon->set_bit1(bmIE1);
+ !(p3n & bm_INT1) &&
+ (p3o & bm_INT1))
+ cell_tcon->set_bit1(bmIE1);
bit_INT0= p3n & bm_INT0;
bit_INT1= p3n & bm_INT1;
}
void
-cl_interrupt::print_info(class cl_console *con)
+cl_interrupt::print_info(class cl_console_base *con)
{
int ie= sfr->get(IE);
int i;
con->dd_printf("Interrupts are %s. Interrupt sources:\n",
- (ie&bmEA)?"enabled":"disabled");
+ (ie&bmEA)?"enabled":"disabled");
con->dd_printf(" Handler En Pr Req Act Name\n");
for (i= 0; i < uc->it_sources->count; i++)
{
con->dd_printf(" %-3s", (ie&(is->ie_mask))?"en":"dis");
con->dd_printf(" %2d", uc->it_priority(is->ie_mask));
con->dd_printf(" %-3s",
- (sfr->get(is->src_reg)&(is->src_mask))?
- "YES":"no");
+ (sfr->get(is->src_reg)&(is->src_mask))?
+ "YES":"no");
con->dd_printf(" %-3s", (is->active)?"act":"no");
con->dd_printf(" %s", object_name(is));
con->dd_printf("\n");
{
class it_level *il= (class it_level *)(uc->it_levels->at(i));
if (il->level >= 0)
- {
- con->dd_printf(" %2d", il->level);
- con->dd_printf(" 0x%06x", il->addr);
- con->dd_printf(" 0x%06x", il->PC);
- con->dd_printf(" %s", (il->source)?(object_name(il->source)):
- "nothing");
- con->dd_printf("\n");
- }
+ {
+ con->dd_printf(" %2d", il->level);
+ con->dd_printf(" 0x%06x", il->addr);
+ con->dd_printf(" 0x%06x", il->PC);
+ con->dd_printf(" %s", (il->source)?(object_name(il->source)):
+ "nothing");
+ con->dd_printf("\n");
+ }
}
}
virtual void reset(void);
virtual void happen(class cl_hw *where, enum hw_event he, void *params);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
cl_pca::added_to_uc(void)
{
uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF4, 0x0033, false,
- "PCA module #4", 5));
+ "PCA module #4", 5));
uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF3, 0x0033, false,
- "PCA module #3", 5));
+ "PCA module #3", 5));
uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF2, 0x0033, false,
- "PCA module #2", 5));
+ "PCA module #2", 5));
uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF1, 0x0033, false,
- "PCA module #1", 5));
+ "PCA module #1", 5));
uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF0, 0x0033, false,
- "PCA module #0", 5));
+ "PCA module #0", 5));
uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCF, 0x0033, false,
- "PCA counter", 5));
+ "PCA counter", 5));
}
void
bit_ECF = *val & bmECF;
t_mem o= clk_source;
if ((clk_source= *val & (bmCPS1|bmCPS0)) != o)
- t0_overflows= ECI_edge= 0;
+ t0_overflows= ECI_edge= 0;
}
else if (cell == cell_ccon)
{
{
int i;
for (i= 0; i < 5; i++)
- {
- if (cell == cell_ccapm[i])
- {
- t_mem o= ccapm[i];
- ccapm[i]= *val & 0xff;
- if (o != ccapm[i])
- cex_neg[i]= cex_pos[i]= DD_FALSE;
- }
- else
- {
- if (ccapm[i] & (bmMAT|bmTOG))
- {
- if (cell == cell_ccapl[i])
- {
- cell_ccapm[i]->set_bit0(bmECOM);
- ccapm[i]= cell_ccapm[i]->get();
- }
- else if (cell == cell_ccaph[i])
- {
- cell_ccapm[i]->set_bit1(bmECOM);
- ccapm[i]= cell_ccapm[i]->get();
- }
- }
- }
- }
+ {
+ if (cell == cell_ccapm[i])
+ {
+ t_mem o= ccapm[i];
+ ccapm[i]= *val & 0xff;
+ if (o != ccapm[i])
+ cex_neg[i]= cex_pos[i]= DD_FALSE;
+ }
+ else
+ {
+ if (ccapm[i] & (bmMAT|bmTOG))
+ {
+ if (cell == cell_ccapl[i])
+ {
+ cell_ccapm[i]->set_bit0(bmECOM);
+ ccapm[i]= cell_ccapm[i]->get();
+ }
+ else if (cell == cell_ccaph[i])
+ {
+ cell_ccapm[i]->set_bit1(bmECOM);
+ ccapm[i]= cell_ccapm[i]->get();
+ }
+ }
+ }
+ }
}
}
if (mem && sfr && mem == sfr)
{
if (addr == addr_ccapXl)
- ccapXl= sfr->get_cell(addr_ccapXl);
+ ccapXl= sfr->get_cell(addr_ccapXl);
else if (addr == addr_ccapXh)
- ccapXh= sfr->get_cell(addr_ccapXh);
+ ccapXh= sfr->get_cell(addr_ccapXh);
else if (addr == addr_ccapmX)
- ccapmX= sfr->get_cell(addr_ccapmX);
+ ccapmX= sfr->get_cell(addr_ccapmX);
}
}*/
while (cycles--)
{
if (cell_cl->add(1) == 0)
- {
- int i;
- for (i= 0; i < 5; i++)
- if (ccapm[i] & bmPWM)
- cell_ccapl[i]->set(cell_ccaph[i]->get());
- if (cell_ch->add(1) == 0)
- {
- // CH,CL overflow
- cell_ccon->set_bit1(bmCF);
- do_pca_module(0);
- do_pca_module(1);
- do_pca_module(2);
- do_pca_module(3);
- do_pca_module(4);
- }
- }
+ {
+ int i;
+ for (i= 0; i < 5; i++)
+ if (ccapm[i] & bmPWM)
+ cell_ccapl[i]->set(cell_ccaph[i]->get());
+ if (cell_ch->add(1) == 0)
+ {
+ // CH,CL overflow
+ cell_ccon->set_bit1(bmCF);
+ do_pca_module(0);
+ do_pca_module(1);
+ do_pca_module(2);
+ do_pca_module(3);
+ do_pca_module(4);
+ }
+ }
}
}
{
// Comparator enabled
if (cell_cl->get() == cell_ccapl[nr]->get() &&
- cell_ch->get() == cell_ccaph[nr]->get())
- {
- // Match
- if (nr == 4 &&
- (bit_WDTE))
- {
- reset();
- return;
- }
- cell_ccon->set_bit1(bmCCF[nr]);
- if (ccapm[nr] & bmTOG)
- {
- // Toggle
- sfr->set(P1, sfr->get(P1) ^ bmCEX[nr]);
- }
- }
+ cell_ch->get() == cell_ccaph[nr]->get())
+ {
+ // Match
+ if (nr == 4 &&
+ (bit_WDTE))
+ {
+ reset();
+ return;
+ }
+ cell_ccon->set_bit1(bmCCF[nr]);
+ if (ccapm[nr] & bmTOG)
+ {
+ // Toggle
+ sfr->set(P1, sfr->get(P1) ^ bmCEX[nr]);
+ }
+ }
if (ccapm[nr] & bmPWM)
- {
- // PWM
- /*if (cell_cl->get() == 0)
- cell_ccapl[nr]->set(cell_ccaph[nr]->get());*/
- if (cell_cl->get() < cell_ccapl[nr]->get())
- //sfr->set(P1, sfr->get(P1) & ~(bmCEX[nr]));
- sfr->set_bit1(P1, bmCEX[nr]);
- else
- sfr->set_bit1(P1, bmCEX[nr]);
- }
+ {
+ // PWM
+ /*if (cell_cl->get() == 0)
+ cell_ccapl[nr]->set(cell_ccaph[nr]->get());*/
+ if (cell_cl->get() < cell_ccapl[nr]->get())
+ //sfr->set(P1, sfr->get(P1) & ~(bmCEX[nr]));
+ sfr->set_bit1(P1, bmCEX[nr]);
+ else
+ sfr->set_bit1(P1, bmCEX[nr]);
+ }
}
}
t_mem p1n= ep->new_pins & ep->new_value;
t_mem p1o= ep->pins & ep->prev_value;
if (!(p1n & bmECI) &&
- (p1o & bmECI))
- ECI_edge++;
+ (p1o & bmECI))
+ ECI_edge++;
int i;
for (i= 0; i < 5; i++)
- {
- if (!(p1n & bmCEX[i]) &&
- (p1o & bmCEX[i]))
- cex_neg[i]= DD_TRUE;
- else if ((p1n & bmCEX[i]) &&
- !(p1o & bmCEX[i]))
- cex_pos[i]= DD_TRUE;
- }
+ {
+ if (!(p1n & bmCEX[i]) &&
+ (p1o & bmCEX[i]))
+ cex_neg[i]= DD_TRUE;
+ else if ((p1n & bmCEX[i]) &&
+ !(p1o & bmCEX[i]))
+ cex_pos[i]= DD_TRUE;
+ }
}
else if (where->cathegory == HW_TIMER &&
- he == EV_OVERFLOW &&
- where->id == 0)
+ he == EV_OVERFLOW &&
+ where->id == 0)
{
t0_overflows++;
}
void
-cl_pca::print_info(class cl_console *con)
+cl_pca::print_info(class cl_console_base *con)
{
con->dd_printf("%s[%d] FIXME\n", id_string, id);
}
virtual void reset(void);
virtual void happen(class cl_hw *where, enum hw_event he, void *params);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
case 0: addr_p= P0; break;
case 1:
{
- addr_p= P1;
- /*class cl_hw *hw;
- if ((hw= uc->get_hw(HW_TIMER, 2, 0)))
- hws_to_inform->add(hw);*/
- make_partner(HW_TIMER, 2);
- make_partner(HW_PCA, 0);
- break;
+ addr_p= P1;
+ /*class cl_hw *hw;
+ if ((hw= uc->get_hw(HW_TIMER, 2, 0)))
+ hws_to_inform->add(hw);*/
+ make_partner(HW_TIMER, 2);
+ make_partner(HW_PCA, 0);
+ break;
}
case 2: addr_p= P2; break;
case 3:
{
- addr_p= P3;
- //class cl_hw *hw;
- /*if ((hw= uc->get_hw(HW_TIMER, 0, 0)))
- hws_to_inform->add(hw);
- if ((hw= uc->get_hw(HW_TIMER, 1, 0)))
- hws_to_inform->add(hw);
- if ((hw= uc->get_hw(HW_DUMMY, 0, 0)))
- hws_to_inform->add(hw);*/
- make_partner(HW_TIMER, 0);
- make_partner(HW_TIMER, 1);
- make_partner(HW_INTERRUPT, 0);
- make_partner(HW_DUMMY, 0);
- break;
+ addr_p= P3;
+ //class cl_hw *hw;
+ /*if ((hw= uc->get_hw(HW_TIMER, 0, 0)))
+ hws_to_inform->add(hw);
+ if ((hw= uc->get_hw(HW_TIMER, 1, 0)))
+ hws_to_inform->add(hw);
+ if ((hw= uc->get_hw(HW_DUMMY, 0, 0)))
+ hws_to_inform->add(hw);*/
+ make_partner(HW_TIMER, 0);
+ make_partner(HW_TIMER, 1);
+ make_partner(HW_INTERRUPT, 0);
+ make_partner(HW_DUMMY, 0);
+ break;
}
default: addr_p= P0; return(1);
}
}
void
-cl_port::set_cmd(class cl_cmdline *cmdline, class cl_console *con)
+cl_port::set_cmd(class cl_cmdline *cmdline, class cl_console_base *con)
{
struct ev_port_changed ep;
class cl_cmd_arg *params[1]= { cmdline->param(0) };
ep.new_value= cell_p->get();
ep.new_pins= port_pins;
if (ep.pins != ep.new_pins)
- inform_partners(EV_PORT_CHANGED, &ep);
+ inform_partners(EV_PORT_CHANGED, &ep);
}
else
{
con->dd_printf("set hardware port[%d] pins_value\n Set port pins\n",
- id);
+ id);
value= 0;
}
}
}*/
void
-cl_port::print_info(class cl_console *con)
+cl_port::print_info(class cl_console_base *con)
{
uchar data;
con->dd_printf("P%d ", id);
con->print_bin(data, 8);
con->dd_printf(" 0x%02x %3d %c (Value in SFR register)\n",
- data, data, isprint(data)?data:'.');
+ data, data, isprint(data)?data:'.');
data= /*uc->*/port_pins/*[id]*/;
con->dd_printf("Pin%d ", id);
con->print_bin(data, 8);
con->dd_printf(" 0x%02x %3d %c (Output of outside circuits)\n",
- data, data, isprint(data)?data:'.');
+ data, data, isprint(data)?data:'.');
data= cell_p->read();
con->dd_printf("Port%d ", id);
con->print_bin(data, 8);
con->dd_printf(" 0x%02x %3d %c (Value on the port pins)\n",
- data, data, isprint(data)?data:'.');
+ data, data, isprint(data)?data:'.');
}
virtual t_mem read(class cl_memory_cell *cell);
virtual void write(class cl_memory_cell *cell, t_mem *val);
- virtual void set_cmd(class cl_cmdline *cmdline, class cl_console *con);
+ virtual void set_cmd(class cl_cmdline *cmdline, class cl_console_base *con);
//virtual void mem_cell_changed(class cl_m *mem, t_addr addr);
//virtual int tick(int cycles);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
* Simulator of microcontrollers (serial.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#include <fcntl.h>
#include <sys/time.h>
#include <strings.h>
+#include <assert.h>
// prj
#include "globals.h"
#include "serialcl.h"
#include "regs51.h"
#include "uc51cl.h"
+#include "cmdutil.h"
cl_serial::cl_serial(class cl_uc *auc):
cl_serial::~cl_serial(void)
{
+ if (serial_in != serial_out && serial_in)
+ {
+#ifdef HAVE_TERMIOS_H
+ if (isatty(fileno(serial_in)))
+ tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in);
+#endif
+ fclose(serial_in);
+ }
if (serial_out)
{
+#ifdef HAVE_TERMIOS_H
if (isatty(fileno(serial_out)))
- tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out);
+ tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out);
+#endif
fclose(serial_out);
}
- if (serial_in)
- {
- if (isatty(fileno(serial_in)))
- tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in);
- fclose(serial_in);
- }
delete serial_in_file_option;
delete serial_out_file_option;
}
int
cl_serial::init(void)
{
+#ifdef HAVE_TERMIOS_H
int i;
struct termios tattr;
+#endif
set_name("mcs51_uart");
sfr= uc->address_space(MEM_SFR_ID);
serial_in= fopen(fni, "r");
if ((fno= serial_out_file_option->get_value((char*)0)))
serial_out= fopen(fno, "w");*/
-
+
//serial_in = (FILE*)application->args->get_parg(0, "Ser_in");
//serial_out= (FILE*)application->args->get_parg(0, "Ser_out");
serial_in = (FILE*)serial_in_file_option->get_value((void*)0);
serial_out= (FILE*)serial_out_file_option->get_value((void*)0);
- if (serial_in)
+
+ if (serial_in != serial_out && serial_in)
{
// making `serial' unbuffered
if (setvbuf(serial_in, NULL, _IONBF, 0))
- perror("Unbuffer serial input channel");
+ perror("Unbuffer serial input channel");
+#ifdef _WIN32
+ if (CH_SERIAL != get_handle_type((HANDLE)_get_osfhandle(fileno(serial_in))))
+#elif defined HAVE_TERMIOS_H
// setting O_NONBLOCK
if ((i= fcntl(fileno(serial_in), F_GETFL, 0)) < 0)
- perror("Get flags of serial input");
+ perror("Get flags of serial input");
i|= O_NONBLOCK;
if (fcntl(fileno(serial_in), F_SETFL, i) < 0)
- perror("Set flags of serial input");
+ perror("Set flags of serial input");
// switching terminal to noncanonical mode
if (isatty(fileno(serial_in)))
- {
- tcgetattr(fileno(serial_in), &saved_attributes_in);
- tcgetattr(fileno(serial_in), &tattr);
- tattr.c_lflag&= ~(ICANON|ECHO);
- tattr.c_cc[VMIN] = 1;
- tattr.c_cc[VTIME]= 0;
- tcsetattr(fileno(serial_in), TCSAFLUSH, &tattr);
- }
+ {
+ tcgetattr(fileno(serial_in), &saved_attributes_in);
+ tcgetattr(fileno(serial_in), &tattr);
+ tattr.c_lflag&= ~(ICANON|ECHO);
+ tattr.c_cc[VMIN] = 1;
+ tattr.c_cc[VTIME]= 0;
+ tcsetattr(fileno(serial_in), TCSAFLUSH, &tattr);
+ }
else
- fprintf(stderr, "Warning: serial input interface connected to a "
- "non-terminal file.\n");
+#endif
+ fprintf(stderr, "Warning: serial input interface connected to a "
+ "non-terminal file.\n");
}
if (serial_out)
{
// making `serial' unbuffered
if (setvbuf(serial_out, NULL, _IONBF, 0))
- perror("Unbuffer serial output channel");
+ perror("Unbuffer serial output channel");
+#ifdef _WIN32
+ if (CH_SERIAL != get_handle_type((HANDLE)_get_osfhandle(fileno(serial_out))))
+#elif defined HAVE_TERMIOS_H
// setting O_NONBLOCK
if ((i= fcntl(fileno(serial_out), F_GETFL, 0)) < 0)
- perror("Get flags of serial output");
+ perror("Get flags of serial output");
i|= O_NONBLOCK;
if (fcntl(fileno(serial_out), F_SETFL, i) < 0)
- perror("Set flags of serial output");
+ perror("Set flags of serial output");
// switching terminal to noncanonical mode
if (isatty(fileno(serial_out)))
- {
- tcgetattr(fileno(serial_out), &saved_attributes_out);
- tcgetattr(fileno(serial_out), &tattr);
- tattr.c_lflag&= ~(ICANON|ECHO);
- tattr.c_cc[VMIN] = 1;
- tattr.c_cc[VTIME]= 0;
- tcsetattr(fileno(serial_out), TCSAFLUSH, &tattr);
- }
+ {
+ tcgetattr(fileno(serial_out), &saved_attributes_out);
+ tcgetattr(fileno(serial_out), &tattr);
+ tattr.c_lflag&= ~(ICANON|ECHO);
+ tattr.c_cc[VMIN] = 1;
+ tattr.c_cc[VTIME]= 0;
+ tcsetattr(fileno(serial_out), TCSAFLUSH, &tattr);
+ }
else
- fprintf(stderr, "Warning: serial output interface connected to a "
- "non-terminal file.\n");
+#endif
+ fprintf(stderr, "Warning: serial output interface connected to a "
+ "non-terminal file.\n");
}
class cl_hw *t2= uc->get_hw(HW_TIMER, 2, 0);
cl_serial::added_to_uc(void)
{
uc->it_sources->add(new cl_it_src(bmES , SCON, bmTI , 0x0023, false,
- "serial transmit", 6));
+ "serial transmit", 6));
uc->it_sources->add(new cl_it_src(bmES , SCON, bmRI , 0x0023, false,
- "serial receive", 6));
+ "serial receive", 6));
}
t_mem
_bmREN= *val & bmREN;
_bits= 8;
switch (_mode)
- {
- case 0:
- _bits= 8;
- _divby= 12;
- break;
- case 1:
- _bits= 10;
- _divby= _bmSMOD?16:32;
- break;
- case 2:
- _bits= 11;
- _divby= _bmSMOD?16:32;
- break;
- case 3:
- _bits= 11;
- _divby= _bmSMOD?16:32;
- break;
- }
+ {
+ case 0:
+ _bits= 8;
+ _divby= 12;
+ break;
+ case 1:
+ _bits= 10;
+ _divby= _bmSMOD?16:32;
+ break;
+ case 2:
+ _bits= 11;
+ _divby= _bmSMOD?16:32;
+ break;
+ case 3:
+ _bits= 11;
+ _divby= _bmSMOD?16:32;
+ break;
+ }
}
else if (cell == pcon)
{
_bmSMOD= *val & bmSMOD;
/*switch (_mode)
- {
- case 1:
- _divby= _bmSMOD?16:32;
- break;
- case 2:
- _divby= _bmSMOD?16:32;
- break;
- case 3:
- _divby= _bmSMOD?16:32;
- break;
- }*/
+ {
+ case 1:
+ _divby= _bmSMOD?16:32;
+ break;
+ case 2:
+ _divby= _bmSMOD?16:32;
+ break;
+ case 3:
+ _divby= _bmSMOD?16:32;
+ break;
+ }*/
if (_mode)
- _divby= _bmSMOD?16:32;
+ _divby= _bmSMOD?16:32;
}
}
if (s_sending)
{
while (*tr_src >= _divby)
- {
- (*tr_src)-= _divby;
- s_tr_bit++;
- //printf("serial bit sent %d\n",uc->ticks->ticks);
- }
+ {
+ (*tr_src)-= _divby;
+ s_tr_bit++;
+ //printf("serial bit sent %d\n",uc->ticks->ticks);
+ }
}
if (s_receiving)
{
while (*rec_src >= _divby)
- {
- (*rec_src)-= _divby;
- s_rec_bit++;
- }
+ {
+ (*rec_src)-= _divby;
+ s_rec_bit++;
+ }
}
return(0);
}
s_sending= DD_FALSE;
scon->set_bit1(bmTI);
if (serial_out)
- {
- putc(s_out, serial_out);
- fflush(serial_out);
- }
+ {
+ putc(s_out, serial_out);
+ fflush(serial_out);
+ }
s_tr_bit-= _bits;
//printf("serial out %d bit rems %d\n",s_tr_bit,uc->ticks->ticks);
}
serial_in &&
!s_receiving)
{
- fd_set set; static struct timeval timeout= {0,0};
- FD_ZERO(&set);
- FD_SET(fileno(serial_in), &set);
- int i= select(fileno(serial_in)+1, &set, NULL, NULL, &timeout);
- if (i > 0 &&
- FD_ISSET(fileno(serial_in), &set))
- {
- s_receiving= DD_TRUE;
- s_rec_bit= 0;
- s_rec_tick= /*uc51->*/s_rec_t1= 0;
- }
+#ifdef _WIN32
+ HANDLE handle = (HANDLE)_get_osfhandle(fileno(serial_in));
+ assert(INVALID_HANDLE_VALUE != handle);
+
+ if (input_avail(handle))
+#else
+ if (input_avail(fileno(serial_in)))
+#endif
+ {
+ s_receiving= DD_TRUE;
+ s_rec_bit= 0;
+ s_rec_tick= /*uc51->*/s_rec_t1= 0;
+ }
}
if (s_receiving &&
(s_rec_bit >= _bits))
{
if (::read(fileno(serial_in), &c, 1) == 1)
- {
- s_in= c;
- sbuf->set(s_in);
- received(c);
- }
+ {
+ s_in= c;
+ sbuf->set(s_in);
+ received(c);
+ }
s_receiving= DD_FALSE;
s_rec_bit-= _bits;
}
-
+
int l;
s_tr_tick+= (l= cycles * uc->clock_per_cycle());
s_rec_tick+= l;
if (where->cathegory == HW_TIMER)
{
if (where->id == 1)
- {
- //printf("serial: timer overflowed %ld\n", uc->ticks->ticks);
- s_rec_t1++;
- s_tr_t1++;
- }
+ {
+ //printf("serial: timer overflowed %ld\n", uc->ticks->ticks);
+ s_rec_t1++;
+ s_tr_t1++;
+ }
if (where->id == 2 /*&& there_is_t2*/)
- {
- switch (he)
- {
- case EV_T2_MODE_CHANGED:
- {
- if (!t2_baud)
- s_rec_t1= s_tr_t1= 0;
- t_mem *d= (t_mem *)params;
- t2_baud= *d & (bmRCLK | bmTCLK);
- break;
- }
- case EV_OVERFLOW:
- //printf("T2 \abaud ov r%d t%d\n",s_rec_t1,s_tr_t1);
- s_rec_t1++;
- s_tr_t1++;
- break;
- default: break;
- }
- }
+ {
+ switch (he)
+ {
+ case EV_T2_MODE_CHANGED:
+ {
+ if (!t2_baud)
+ s_rec_t1= s_tr_t1= 0;
+ t_mem *d= (t_mem *)params;
+ t2_baud= *d & (bmRCLK | bmTCLK);
+ break;
+ }
+ case EV_OVERFLOW:
+ //printf("T2 \abaud ov r%d t%d\n",s_rec_t1,s_tr_t1);
+ s_rec_t1++;
+ s_tr_t1++;
+ break;
+ default: break;
+ }
+ }
}
}
void
-cl_serial::print_info(class cl_console *con)
+cl_serial::print_info(class cl_console_base *con)
{
char *modes[]= { "Shift, fixed clock",
- "8 bit UART timer clocked",
- "9 bit UART fixed clock",
- "9 bit UART timer clocked" };
+ "8 bit UART timer clocked",
+ "9 bit UART fixed clock",
+ "9 bit UART timer clocked" };
int sc= scon->get();
con->dd_printf("%s[%d]", id_string, id);
if (mode == 1 || mode == 2)
con->dd_printf(" (timer%d)", (t2_baud)?2:1);
con->dd_printf(" MultiProc=%s",
- (mode&2)?((sc&bmSM2)?"ON":"OFF"):"none");
+ (mode&2)?((sc&bmSM2)?"ON":"OFF"):"none");
con->dd_printf(" irq=%s", (sfr->get(IE)&bmES)?"en":"dis");
con->dd_printf(" prio=%d", uc->it_priority(bmPS));
con->dd_printf("\n");
con->dd_printf(" irq=%c", (sc&bmTI)?'1':'0');
con->dd_printf("\n");
/*con->dd_printf("s_rec_t1=%d s_rec_bit=%d s_rec_tick=%d\n",
- s_rec_t1, s_rec_bit, s_rec_tick);
+ s_rec_t1, s_rec_bit, s_rec_tick);
con->dd_printf("s_tr_t1=%d s_tr_bit=%d s_tr_tick=%d\n",
- s_tr_t1, s_tr_bit, s_tr_tick);
- con->dd_printf("divby=%d bits=%d\n", _divby, _bits);*/
+ s_tr_t1, s_tr_bit, s_tr_tick);
+ con->dd_printf("divby=%d bits=%d\n", _divby, _bits);*/
}
#endif
class cl_optref *serial_in_file_option;
class cl_optref *serial_out_file_option;
- FILE *serial_in; // Serial line input
- FILE *serial_out; // Serial line output
- uchar s_in; // Serial channel input reg
- uchar s_out; // Serial channel output reg
- bool s_sending; // Transmitter is working
- bool s_receiving; // Receiver is working
- int s_rec_bit; // Bit counter of receiver
- int s_tr_bit; // Bit counter of transmitter
- int s_rec_t1; // T1 overflows for receiving
- int s_tr_t1; // T1 overflows for sending
- int s_rec_tick; // Machine cycles for receiving
- int s_tr_tick; // Machine cycles for sending
+ FILE *serial_in; // Serial line input
+ FILE *serial_out; // Serial line output
+ uchar s_in; // Serial channel input reg
+ uchar s_out; // Serial channel output reg
+ bool s_sending; // Transmitter is working
+ bool s_receiving; // Receiver is working
+ int s_rec_bit; // Bit counter of receiver
+ int s_tr_bit; // Bit counter of transmitter
+ int s_rec_t1; // T1 overflows for receiving
+ int s_tr_t1; // T1 overflows for sending
+ int s_rec_tick; // Machine cycles for receiving
+ int s_tr_tick; // Machine cycles for sending
uchar _mode;
uchar _bmREN;
uchar _bmSMOD;
virtual void reset(void);
virtual void happen(class cl_hw *where, enum hw_event he, void *params);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
{
//t_mem d;
if (id == 0 || id == 1)
- {
- //cell_tmod= sfr->register_hw(TMOD, this, 0);
- register_cell(sfr, TMOD, &cell_tmod, wtd_restore_write);
- //d= cell_tmod->get(); write(cell_tmod, &d);
- //cell_tcon= sfr->register_hw(TCON, this, 0);
- register_cell(sfr, TCON, &cell_tcon, wtd_restore_write);
- //d= cell_tcon->get(); write(cell_tcon, &d);
- INT= sfr->read(P3) & mask_INT;
- }
+ {
+ //cell_tmod= sfr->register_hw(TMOD, this, 0);
+ register_cell(sfr, TMOD, &cell_tmod, wtd_restore_write);
+ //d= cell_tmod->get(); write(cell_tmod, &d);
+ //cell_tcon= sfr->register_hw(TCON, this, 0);
+ register_cell(sfr, TCON, &cell_tcon, wtd_restore_write);
+ //d= cell_tcon->get(); write(cell_tcon, &d);
+ INT= sfr->read(P3) & mask_INT;
+ }
else if (id == 2)
- {
- cell_tmod= 0;
- //cell_tcon= sfr->register_hw(T2CON, this, 0);
- register_cell(sfr, T2CON, &cell_tcon, wtd_restore_write);
- //d= cell_tcon->get(); write(cell_tcon, &d);
- }
+ {
+ cell_tmod= 0;
+ //cell_tcon= sfr->register_hw(T2CON, this, 0);
+ register_cell(sfr, T2CON, &cell_tcon, wtd_restore_write);
+ //d= cell_tcon->get(); write(cell_tcon, &d);
+ }
//cell_tl= sfr->get_cell(addr_tl);
//cell_th= sfr->get_cell(addr_th);
use_cell(sfr, addr_tl, &cell_tl, wtd_restore);
{
if (id == 0)
uc->it_sources->add(new cl_it_src(bmET0, TCON, bmTF0, 0x000b, true,
- "timer #0", 2));
+ "timer #0", 2));
else if (id == 1)
uc->it_sources->add(new cl_it_src(bmET1, TCON, bmTF1, 0x001b, true,
- "timer #1", 4));
+ "timer #1", 4));
}
/*t_mem
{
t_mem md= *val & (mask_M0|mask_M1);
if (md == mask_M0)
- mode= 1;
+ mode= 1;
else if (md == mask_M1)
- mode= 2;
+ mode= 2;
else if (md == (mask_M0|mask_M1))
- mode= 3;
+ mode= 3;
else
- mode= 0;
+ mode= 0;
GATE= *val & mask_GATE;
C_T = *val & mask_C_T;
T_edge= 0;
if (GATE)
{
if ((/*p3 & mask_*/INT) == 0)
- return(0);
+ return(0);
}
if (C_T)
{
/*cycles= 0;
if ((uc51->prev_p3 & mask_T) &&
- !(p3 & uc51->port_pins[3] & mask_T))
- cycles= 1;*/
+ !(p3 & uc51->port_pins[3] & mask_T))
+ cycles= 1;*/
cycles= T_edge;
T_edge= 0;
}
// mod 0, TH= 8 bit t/c, TL= 5 bit precounter
t_mem tl= cell_tl->add(1);
if ((tl & 0x1f) == 0)
- {
- cell_tl->set(0);
- if (!cell_th->add(1))
- {
- cell_tcon->set_bit1(mask_TF);
- overflow();
- }
- }
+ {
+ cell_tl->set(0);
+ if (!cell_th->add(1))
+ {
+ cell_tcon->set_bit1(mask_TF);
+ overflow();
+ }
+ }
}
return(0);
if (GATE)
{
if ((/*p3 & mask_*/INT) == 0)
- return(0);
+ return(0);
}
if (C_T)
{
/*cycles= 0;
if ((uc51->prev_p3 & mask_T) &&
- !(p3 & uc51->port_pins[3] & mask_T))
- cycles= 1;*/
+ !(p3 & uc51->port_pins[3] & mask_T))
+ cycles= 1;*/
cycles= T_edge;
T_edge= 0;
}
{
// mod 1 TH+TL= 16 bit t/c
if (!cell_tl->add(1))
- {
- if (!cell_th->add(1))
- {
- cell_tcon->set_bit1(mask_TF);
- overflow();
- }
- }
+ {
+ if (!cell_th->add(1))
+ {
+ cell_tcon->set_bit1(mask_TF);
+ overflow();
+ }
+ }
}
return(0);
if (GATE)
{
if ((/*p3 & mask_*/INT) == 0)
- return(0);
+ return(0);
}
if (C_T)
{
/*cycles= 0;
if ((uc51->prev_p3 & mask_T) &&
- !(p3 & uc51->port_pins[3] & mask_T))
- cycles= 1;*/
+ !(p3 & uc51->port_pins[3] & mask_T))
+ cycles= 1;*/
cycles= T_edge;
T_edge= 0;
}
{
// mod 2 TL= 8 bit t/c auto reload from TH
if (!cell_tl->add(1))
- {
- cell_tl->set(cell_th->get());
- cell_tcon->set_bit1(mask_TF);
- //printf("timer%d overflow %d (%d) %d\n",id,uc->ticks->ticks,i,startt+(i*12));
- overflow();
- }
+ {
+ cell_tl->set(cell_th->get());
+ cell_tcon->set_bit1(mask_TF);
+ //printf("timer%d overflow %d (%d) %d\n",id,uc->ticks->ticks,i,startt+(i*12));
+ overflow();
+ }
//i++;
}
return(0);
if (GATE)
{
if ((/*p3 & mask_*/INT) == 0)
- goto do_th;
+ goto do_th;
}
if (C_T)
{
/*cycles= 0;
if ((uc51->prev_p3 & mask_T) &&
- !(p3 & uc51->port_pins[3] & mask_T))
- cycles= 1;*/
+ !(p3 & uc51->port_pins[3] & mask_T))
+ cycles= 1;*/
cycles= T_edge;
T_edge= 0;
}
while (cycles--)
{
if (!cell_tl->add(1))
- {
- cell_tcon->set_bit1(mask_TF);
- overflow();
- }
+ {
+ cell_tcon->set_bit1(mask_TF);
+ overflow();
+ }
}
do_th:
if ((cell_tcon->get() & bmTR1) != 0)
while (cyc--)
{
- if (!cell_th->add(1))
- cell_tcon->set_bit1(bmTF1);
+ if (!cell_th->add(1))
+ cell_tcon->set_bit1(bmTF1);
}
return(0);
}
t_mem p3n= ep->new_pins & ep->new_value;
t_mem p3o= ep->pins & ep->prev_value;
if ((p3n & mask_T) &&
- !(p3o & mask_T))
- T_edge++;
+ !(p3o & mask_T))
+ T_edge++;
INT= p3n & mask_INT;
//printf("timer%d p%dchanged (%02x,%02x->%02x,%02x) INT=%d(%02x) edge=%d(%02x)\n",id,where->id,ep->prev_value,ep->pins,ep->new_value,ep->new_pins,INT,mask_INT,T_edge,mask_T);
}
}
void
-cl_timer0::print_info(class cl_console *con)
+cl_timer0::print_info(class cl_console_base *con)
{
char *modes[]= { "13 bit", "16 bit", "8 bit autoreload", "2x8 bit" };
//t_mem tmod= cell_tmod->get();
class cl_address_space *sfr= uc->address_space(MEM_SFR_ID);
con->dd_printf("%s[%d] 0x%04x", id_string, id,
- 256*cell_th->get()+cell_tl->get());
+ 256*cell_th->get()+cell_tl->get());
//int mode= tmod & (bmM00|bmM10);
con->dd_printf(" %s", modes[mode]);
con->dd_printf(" %s", (/*tmod&bm*/C_T/*0*/)?"counter":"timer");
virtual void overflow(void);
virtual void happen(class cl_hw *where, enum hw_event he, void *params);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
}*/
void
-cl_timer1::print_info(class cl_console *con)
+cl_timer1::print_info(class cl_console_base *con)
{
char *modes[]= { "13 bit", "16 bit", "8 bit autoreload", "stop" };
//int tmod= cell_tmod->get();
class cl_address_space *sfr= uc->address_space(MEM_SFR_ID);
con->dd_printf("%s[%d] 0x%04x", id_string, id,
- 256*cell_th->get()+cell_tl->get());
+ 256*cell_th->get()+cell_tl->get());
//int mode= (tmod & (bmM11|bmM01)) >> 4;
con->dd_printf(" %s", modes[mode]);
con->dd_printf(" %s", (/*tmod&bm*/C_T/*1*/)?"counter":"timer");
virtual int do_mode3(int cycles);
//virtual void overflow(void);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
cl_timer2::cl_timer2(class cl_uc *auc, int aid, char *aid_string,
- int afeatures):
+ int afeatures):
cl_timer0(auc, /*2*/aid, /*"timer2"*/aid_string)
{
features= afeatures;
if (features & (t2_down|t2_clock_out))
{
register_cell(sfr, T2MOD, &cell_t2mod,
- wtd_restore_write);
+ wtd_restore_write);
}
}
cl_timer2::added_to_uc(void)
{
uc->it_sources->add(new cl_it_src(bmET2, T2CON, bmTF2, 0x002b, false,
- "timer #2 TF2", 7));
+ "timer #2 TF2", 7));
exf2it= new cl_it_src(bmET2, T2CON, bmEXF2, 0x002b, false,
- "timer #2 EXF2", 7);
+ "timer #2 EXF2", 7);
uc->it_sources->add(exf2it);
}
if (mem && sfr && mem == sfr)
{
switch (addr)
- {
- case T2CON:
- c= cell_tcon= sfr->get_cell(T2CON);
- break;
- }
+ {
+ case T2CON:
+ c= cell_tcon= sfr->get_cell(T2CON);
+ break;
+ }
if (c)
- {
- t_mem d= c->get();
- write(c, &d);
- }
+ {
+ t_mem d= c->get();
+ write(c, &d);
+ }
if (addr == addr_tl)
- cell_tl= sfr->get_cell(addr_tl);
+ cell_tl= sfr->get_cell(addr_tl);
if (addr == addr_th)
- cell_th= sfr->get_cell(addr_th);
+ cell_th= sfr->get_cell(addr_th);
cell_rcap2l= sfr->get_cell(RCAP2L);
cell_rcap2h= sfr->get_cell(RCAP2H);
}
CP_RL2= *val & mask_CP_RL2;
EXEN2 = *val & bmEXEN2;
if (!(RCLK || TCLK) &&
- !CP_RL2)
- mode= T2MODE_RELOAD;
+ !CP_RL2)
+ mode= T2MODE_RELOAD;
else if (!(RCLK || TCLK) &&
- CP_RL2)
- mode= T2MODE_CAPTURE;
+ CP_RL2)
+ mode= T2MODE_CAPTURE;
else if (RCLK || TCLK)
- mode= T2MODE_BAUDRATE;
+ mode= T2MODE_BAUDRATE;
else
- mode= T2MODE_OFF;
+ mode= T2MODE_OFF;
if (mode != oldmode)
- inform_partners(EV_T2_MODE_CHANGED, val);
+ inform_partners(EV_T2_MODE_CHANGED, val);
}
else if (cell == cell_t2mod)
{
bit_dcen= (*val & bmDCEN) != 0;
bit_t2oe= (*val & bmT2OE) != 0;
if ((features & t2_down) &&
- bit_dcen &&
- mode == T2MODE_RELOAD)
- {
- mode= T2MODE_DOWN;
- if (exf2it)
- exf2it->deactivate();
- }
+ bit_dcen &&
+ mode == T2MODE_RELOAD)
+ {
+ mode= T2MODE_DOWN;
+ if (exf2it)
+ exf2it->deactivate();
+ }
if ((features & t2_clock_out) &&
- bit_t2oe)
- mode= T2MODE_CLKOUT;
+ bit_t2oe)
+ mode= T2MODE_CLKOUT;
}
if (mode != oldmode ||
TR && !oldtr ||
while (cycles--)
{
if (!cell_tl->add(1))
- if (!cell_th->add(1))
- {
- cell_th->set(cell_rcap2h->get());
- cell_tl->set(cell_rcap2l->get());
- inform_partners(EV_OVERFLOW, 0);
- }
+ if (!cell_th->add(1))
+ {
+ cell_th->set(cell_rcap2h->get());
+ cell_tl->set(cell_rcap2l->get());
+ inform_partners(EV_OVERFLOW, 0);
+ }
}
return(resGO);
}
if (!cell_tl->add(1))
{
if (!cell_th->add(1))
- cell_tcon->set_bit1(bmTF2);
+ cell_tcon->set_bit1(bmTF2);
}
}
if (!cell_tl->add(1))
{
if (!cell_th->add(1))
- {
- cell_tcon->set_bit1(mask_TF);
- cell_th->set(cell_rcap2h->get());
- cell_tl->set(cell_rcap2l->get());
- }
+ {
+ cell_tcon->set_bit1(mask_TF);
+ cell_th->set(cell_rcap2h->get());
+ cell_tl->set(cell_rcap2l->get());
+ }
}
}
// UP
while (cycles--)
if (!cell_tl->add(1))
- {
- if (!cell_th->add(1))
- {
- cell_tcon->set_bit1(mask_TF);
- cell_th->set(cell_rcap2h->get());
- cell_tl->set(cell_rcap2l->get());
- toggle= DD_TRUE;
- }
- }
+ {
+ if (!cell_th->add(1))
+ {
+ cell_tcon->set_bit1(mask_TF);
+ cell_th->set(cell_rcap2h->get());
+ cell_tl->set(cell_rcap2l->get());
+ toggle= DD_TRUE;
+ }
+ }
else
// DOWN
while (cycles--)
{
- t_mem l, h;
- if ((l= cell_tl->add(-1)) == 0xff)
- h= cell_th->add(-1);
- else
- h= cell_th->get();
- if ((TYPE_UWORD)(h*256+l) <
- (TYPE_UWORD)(cell_rcap2h->get()*256+cell_rcap2l->get()))
- {
- cell_tcon->set_bit1(mask_TF);
- cell_th->set(0xff);
- cell_tl->set(0xff);
- toggle= DD_TRUE;
- }
+ t_mem l, h;
+ if ((l= cell_tl->add(-1)) == 0xff)
+ h= cell_th->add(-1);
+ else
+ h= cell_th->get();
+ if ((TYPE_UWORD)(h*256+l) <
+ (TYPE_UWORD)(cell_rcap2h->get()*256+cell_rcap2l->get()))
+ {
+ cell_tcon->set_bit1(mask_TF);
+ cell_th->set(0xff);
+ cell_tl->set(0xff);
+ toggle= DD_TRUE;
+ }
}
if (toggle &&
sfr)
{
class cl_memory_cell *p1= sfr->get_cell(P1);
if (p1)
- p1->set(p1->get() ^ bmEXF2);
+ p1->set(p1->get() ^ bmEXF2);
}
}
while (cycles--)
{
if (!cell_tl->add(1))
- if (!cell_th->add(1))
- {
- cell_th->set(cell_rcap2h->get());
- cell_tl->set(cell_rcap2l->get());
- inform_partners(EV_OVERFLOW, 0);
- if (!C_T &&
- sfr)
- {
- // toggle T2 on P1
- class cl_memory_cell *p1= sfr->get_cell(P1);
- if (p1)
- p1->set(p1->get() ^ bmT2);
- }
- }
+ if (!cell_th->add(1))
+ {
+ cell_th->set(cell_rcap2h->get());
+ cell_tl->set(cell_rcap2l->get());
+ inform_partners(EV_OVERFLOW, 0);
+ if (!C_T &&
+ sfr)
+ {
+ // toggle T2 on P1
+ class cl_memory_cell *p1= sfr->get_cell(P1);
+ if (p1)
+ p1->set(p1->get() ^ bmT2);
+ }
+ }
}
}
t_mem p1n= ep->new_pins & ep->new_value;
t_mem p1o= ep->pins & ep->prev_value;
if (!(p1n & mask_T) &&
- (p1o & mask_T))
- T_edge++;
+ (p1o & mask_T))
+ T_edge++;
if (!(p1n & bmT2EX) &&
- (p1o & bmT2EX))
- t2ex_edge++;
+ (p1o & bmT2EX))
+ t2ex_edge++;
bit_t2ex= p1n & bmT2EX;
}
}
void
-cl_timer2::print_info(class cl_console *con)
+cl_timer2::print_info(class cl_console_base *con)
{
int t2con= cell_tcon->get();
con->dd_printf("%s[%d] 0x%04x", id_string, id,
- 256*cell_th->get()+cell_tl->get());
+ 256*cell_th->get()+cell_tl->get());
if (RCLK || TCLK)
{
con->dd_printf(" baud");
if (RCLK)
- con->dd_printf(" RCLK");
+ con->dd_printf(" RCLK");
if (TCLK)
- con->dd_printf(" TCLK");
+ con->dd_printf(" TCLK");
}
else
con->dd_printf(" %s", (CP_RL2)?"capture":"reload");
con->dd_printf(" 0x%04x",
- 256*cell_rcap2h->get()+cell_rcap2l->get());
+ 256*cell_rcap2h->get()+cell_rcap2l->get());
con->dd_printf(" %s", (C_T)?"counter":"timer");
con->dd_printf(" %s", (TR)?"ON":"OFF");
con->dd_printf(" irq=%c", (t2con&bmTF2)?'1':'0');
#include "timer0cl.h"
-#define T2MODE_RELOAD 0
-#define T2MODE_CAPTURE 1
-#define T2MODE_BAUDRATE 2
-#define T2MODE_OFF 3
-#define T2MODE_DOWN 4
-#define T2MODE_CLKOUT 5
+#define T2MODE_RELOAD 0
+#define T2MODE_CAPTURE 1
+#define T2MODE_BAUDRATE 2
+#define T2MODE_OFF 3
+#define T2MODE_DOWN 4
+#define T2MODE_CLKOUT 5
enum t2_features {
- t2_default = 0x01,
- t2_down = 0x02,
- t2_clock_out = 0x04
+ t2_default = 0x01,
+ t2_down = 0x02,
+ t2_clock_out = 0x04
};
virtual void do_t2_clock_out(int cycles);
virtual void happen(class cl_hw *where, enum hw_event he, void *params);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= address_space(MEM_IXRAM_ID),
- chip, 0, 0xfff, 0);
+ chip, 0, 0xfff, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
cl_uc390::clear_sfr(void)
{
cl_uc52::clear_sfr();
- /* SFR value */
+ /* SFR value */
sfr->write(0x80, 0xff); /* P4 */
sfr->write(0x81, 0x07); /* SP */
sfr->write(0x86, 0x04); /* DPS */
}
PC = rom->validate_address(sfr->read (ph) * 256 + sfr->read (pl) +
- acc->read());
+ acc->read());
if (sfr->get (ACON) & 0x02) /* AM1 set: 24-bit flat? */
PC += sfr->read (px) * 256*256;
if (sfr->get (ACON) & 0x02) /* AM1 set: 24-bit flat? */
acc->write (rom->read ((sfr->read (px) * 256*256 +
- sfr->read (ph) * 256 + sfr->read (pl) +
+ sfr->read (ph) * 256 + sfr->read (pl) +
acc->read())));
else
acc->write (rom->read ((sfr->read (ph) * 256 + sfr->read (pl) +
- acc->read())));
+ acc->read())));
if (dps & 0x20) /* auto-switch dptr */
sfr->write (DPS, dps ^ 1); /* toggle dual-dptr switch */
class cl_stack_op *so;
if (addr)
{
- PC = addr;
- so= new cl_stack_intr(instPC, PC, pushed, sp_before, sfr->get(SP));
- }
+ PC = addr;
+ so= new cl_stack_intr(instPC, PC, pushed, sp_before, sfr->get(SP));
+ }
else
{
- PC = h * 256 + l;
- so= new cl_stack_call(instPC, PC, pushed, sp_before, sfr->get(SP));
- }
+ PC = h * 256 + l;
+ so= new cl_stack_call(instPC, PC, pushed, sp_before, sfr->get(SP));
+ }
so->init();
stack_write(so);
}
sprintf (temp, "%02"_M_"x", rom->get (addr + 2));
break;
case 'b': // bitaddr at 2nd byte
- {
- t_addr ba = rom->get (addr+1);
- if (get_name (ba, bit_tbl(), temp))
- break;
- if (get_name ((ba<128) ? ((ba/8)+32) : (ba&0xf8), sfr_tbl(), temp))
- {
- strcat (temp, ".");
- sprintf (c, "%1"_M_"d", ba & 0x07);
- strcat (temp, c);
- break;
- }
- sprintf (temp, "%02x.%"_M_"d", (ba<128) ? ((ba/8)+32) : (ba&0xf8),
- ba & 0x07);
- break;
- }
+ {
+ t_addr ba = rom->get (addr+1);
+ if (get_name (ba, bit_tbl(), temp))
+ break;
+ if (get_name ((ba<128) ? ((ba/8)+32) : (ba&0xf8), sfr_tbl(), temp))
+ {
+ strcat (temp, ".");
+ sprintf (c, "%1"_M_"d", ba & 0x07);
+ strcat (temp, c);
+ break;
+ }
+ sprintf (temp, "%02x.%"_M_"d", (ba<128) ? ((ba/8)+32) : (ba&0xf8),
+ ba & 0x07);
+ break;
+ }
case 'r': // rel8 address at 2nd byte
sprintf (temp, "%04"_A_"x",
t_addr (addr + 2 + (signed char) (rom->get (addr + 1))));
}
void
-cl_uc390::print_regs (class cl_console *con)
+cl_uc390::print_regs (class cl_console_base *con)
{
t_addr start;
t_mem data;
start = sfr->get (PSW) & 0x18;
data = iram->get (iram->get (start));
con->dd_printf("%06x %02x %c",
- iram->get (start), data, isprint (data) ? data : '.');
+ iram->get (start), data, isprint (data) ? data : '.');
con->dd_printf(" ACC= 0x%02x %3d %c B= 0x%02x",
- sfr->get (ACC), sfr->get (ACC),
- isprint (sfr->get (ACC)) ?
- (sfr->get (ACC)) : '.', sfr->get (B));
+ sfr->get (ACC), sfr->get (ACC),
+ isprint (sfr->get (ACC)) ?
+ (sfr->get (ACC)) : '.', sfr->get (B));
eram2xram ();
data = get_mem (MEM_XRAM_ID,
sfr->get (DPX) * 256*256 + sfr->get (DPH) * 256 + sfr->get (DPL));
con->dd_printf (" DPTR= 0x%02x%02x%02x @DPTR= 0x%02x %3d %c\n",
- sfr->get (DPX), sfr->get (DPH), sfr->get (DPL),
- data, data, isprint (data) ? data : '.');
+ sfr->get (DPX), sfr->get (DPH), sfr->get (DPL),
+ data, data, isprint (data) ? data : '.');
data = iram->get (iram->get (start + 1));
con->dd_printf ("%06x %02x %c", iram->get (start + 1), data,
- isprint (data) ? data : '.');
+ isprint (data) ? data : '.');
data= sfr->get (PSW);
con->dd_printf (" PSW= 0x%02x CY=%c AC=%c OV=%c P=%c ",
- data,
- (data & bmCY) ? '1' : '0', (data & bmAC) ? '1' : '0',
- (data & bmOV) ? '1' : '0', (data & bmP ) ? '1' : '0'
- );
+ data,
+ (data & bmCY) ? '1' : '0', (data & bmAC) ? '1' : '0',
+ (data & bmOV) ? '1' : '0', (data & bmP ) ? '1' : '0'
+ );
/* show stack pointer */
if (sfr->get (ACON) & 0x04)
/* SA: 10 bit stack */
con->dd_printf ("SP10 0x%03x %3d\n",
- (sfr->get (ESP) & 3) * 256 + sfr->get (SP),
- get_mem (MEM_IXRAM_ID, (sfr->get (ESP) & 3) * 256 + sfr->get (SP))
- );
+ (sfr->get (ESP) & 3) * 256 + sfr->get (SP),
+ get_mem (MEM_IXRAM_ID, (sfr->get (ESP) & 3) * 256 + sfr->get (SP))
+ );
else
con->dd_printf ("SP 0x%02x %3d\n",
- sfr->get (SP),
- iram->get (sfr->get (SP))
- );
+ sfr->get (SP),
+ iram->get (sfr->get (SP))
+ );
print_disass (PC, con);
}
/* mods for disassembly of flat24 */
virtual struct dis_entry *dis_tbl(void);
virtual char * disass(t_addr addr, char *sep);
- virtual void print_regs(class cl_console *con);
+ virtual void print_regs(class cl_console_base *con);
protected:
int flat24_flag; /* true if processor == ds390f */
{
if (ctm_ticks &&
uc390->ticks->ticks >= ctm_ticks + 65535)
- {
- ctm_ticks = 0;
- cell->set (cell->get() | 0x08); /* set CKRDY */
- }
+ {
+ ctm_ticks = 0;
+ cell->set (cell->get() | 0x08); /* set CKRDY */
+ }
}
return cell->get();
}
/* Bit 0 (BGS) is TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = (*val & ~0x01) | (cell_exif->get() & 0x01);
+ *val = (*val & ~0x01) | (cell_exif->get() & 0x01);
/* CKRDY and RGMD are read-only */
*val = (*val & 0x0c) | (*val & ~0x0c);
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
*val = cell_acon->get();
else
- {
+ {
- /* lockout: IDM1:IDM0 and SA can't be set at the same time */
- if ((cell_mcon->get() & 0xc0) == 0xc0) /* IDM1 and IDM0 set? */
- *val &= ~0x04; /* lockout SA */
- }
+ /* lockout: IDM1:IDM0 and SA can't be set at the same time */
+ if ((cell_mcon->get() & 0xc0) == 0xc0) /* IDM1 and IDM0 set? */
+ *val &= ~0x04; /* lockout SA */
+ }
*val |= 0xf8; /* always 1 */
}
else if (cell == cell_p5cnt)
/* Bits 0...2 are TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = (*val & ~0x07) | (cell_p5cnt->get() & 0x07);
+ *val = (*val & ~0x07) | (cell_p5cnt->get() & 0x07);
}
else if (cell == cell_c0c)
{
/* Bit 3 (CRST) is TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = (*val & ~0x08) | (cell_c0c->get() & 0x08);
+ *val = (*val & ~0x08) | (cell_c0c->get() & 0x08);
}
else if (cell == cell_pmr)
{
/* fixme: check previous state */
if ((*val & 0xd0) == 0x90) /* CD1:CD0 set to 10, CTM set */
{
- ctm_ticks = uc390->ticks->ticks;
- cell_exif->set (cell_exif->get() & ~0x08); /* clear CKRDY */
+ ctm_ticks = uc390->ticks->ticks;
+ cell_exif->set (cell_exif->get() & ~0x08); /* clear CKRDY */
}
else
ctm_ticks = 0;
/* MCON is TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = cell_mcon->get();
+ *val = cell_mcon->get();
else
/* lockout: IDM1:IDM0 and SA can't be set at the same time */
if ((cell_acon->get() & 0x04) == 0x04) /* SA set? */
/* COR is TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = cell_cor->get();
+ *val = cell_cor->get();
}
else if (cell == cell_mcnt0)
{
/* Bits 0, 1, 3 and 6 are TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = (*val & ~0x4b) | (cell_wdcon->get() & 0x4b);
+ *val = (*val & ~0x4b) | (cell_wdcon->get() & 0x4b);
}
else if (cell == cell_c1c)
{
/* Bit 3 (CRST) is TA-protected */
if (timed_access_state != 2 ||
timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles
- *val = (*val & ~0x08) | (cell_c1c->get() & 0x08);
+ *val = (*val & ~0x08) | (cell_c1c->get() & 0x08);
}
}
if (mem && sfr && mem == sfr)
switch (addr)
{
- case DPS: cell_dps = sfr->get_cell (DPS); break;
- case P4CNT: cell_p4cnt = sfr->get_cell (P4CNT); break;
- case EXIF: cell_exif = sfr->get_cell (EXIF); break;
- case ACON: cell_acon = sfr->get_cell (ACON); break;
- case P5CNT: cell_p5cnt = sfr->get_cell (P5CNT); break;
- case C0C: cell_c0c = sfr->get_cell (C0C); break;
- case PMR: cell_pmr = sfr->get_cell (PMR); break;
- case MCON: cell_mcon = sfr->get_cell (MCON); break;
- case TA: cell_ta = sfr->get_cell (TA); break;
- case COR: cell_cor = sfr->get_cell (COR); break;
- case MCNT0: cell_mcnt0 = sfr->get_cell (MCNT0); break;
- case MCNT1: cell_mcnt1 = sfr->get_cell (MCNT1); break;
- case MA: cell_ma = sfr->get_cell (MA); break;
- case MB: cell_mb = sfr->get_cell (MB); break;
- case MC: cell_mc = sfr->get_cell (MC); break;
- case WDCON: cell_wdcon = sfr->get_cell (WDCON); break;
- case C1C: cell_c1c = sfr->get_cell (C1C); break;
+ case DPS: cell_dps = sfr->get_cell (DPS); break;
+ case P4CNT: cell_p4cnt = sfr->get_cell (P4CNT); break;
+ case EXIF: cell_exif = sfr->get_cell (EXIF); break;
+ case ACON: cell_acon = sfr->get_cell (ACON); break;
+ case P5CNT: cell_p5cnt = sfr->get_cell (P5CNT); break;
+ case C0C: cell_c0c = sfr->get_cell (C0C); break;
+ case PMR: cell_pmr = sfr->get_cell (PMR); break;
+ case MCON: cell_mcon = sfr->get_cell (MCON); break;
+ case TA: cell_ta = sfr->get_cell (TA); break;
+ case COR: cell_cor = sfr->get_cell (COR); break;
+ case MCNT0: cell_mcnt0 = sfr->get_cell (MCNT0); break;
+ case MCNT1: cell_mcnt1 = sfr->get_cell (MCNT1); break;
+ case MA: cell_ma = sfr->get_cell (MA); break;
+ case MB: cell_mb = sfr->get_cell (MB); break;
+ case MC: cell_mc = sfr->get_cell (MC); break;
+ case WDCON: cell_wdcon = sfr->get_cell (WDCON); break;
+ case C1C: cell_c1c = sfr->get_cell (C1C); break;
}
}*/
}
void
-cl_uc390_hw::print_info(class cl_console *con)
+cl_uc390_hw::print_info(class cl_console_base *con)
{
int i;
long l;
con->dd_printf ("%s"
" EXIF 0x%02x: IE5 %c IE4 %c IE3 %c IE2 %c CKRDY %c RGMD %c RGSL %c BGS %c\n",
id_string,
- i,
+ i,
(i & 0x80) ? '1' : '0',
(i & 0x40) ? '1' : '0',
(i & 0x20) ? '1' : '0',
(i & 0x01) ? '1' : '0');
i = sfr->get (DPS);
con->dd_printf ("\tDPS 0x%02x: ID1 %c ID0 %c TSL %c SEL %c\n",
- i,
+ i,
(i & 0x80) ? '1' : '0',
(i & 0x40) ? '1' : '0',
(i & 0x20) ? '1' : '0',
//virtual void mem_cell_changed (class cl_mem *mem, t_addr addr);
virtual void reset (void);
- virtual void print_info (class cl_console *con);
+ virtual void print_info (class cl_console_base *con);
};
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
for (i= 0; cpus_51[i].type_str != NULL && cpus_51[i].type != type; i++) ;
sprintf(id_string_51, "%s %s",
- cpus_51[i].type_str?cpus_51[i].type_str:"51",
- (technology==CPU_HMOS)?"HMOS":"CMOS");
+ cpus_51[i].type_str?cpus_51[i].type_str:"51",
+ (technology==CPU_HMOS)?"HMOS":"CMOS");
return(id_string_51);
}
h->init();
hws->add(h= new cl_timer1(this, 1, "timer1"));
h->init();
-#ifdef HAVE_TERMIOS_H
hws->add(h= new cl_serial(this));
h->init();
-#endif
hws->add(h= new cl_port(this, 0));
h->init();
hws->add(h= new cl_port(this, 1));
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= rom/*address_space(MEM_ROM_ID)*/,
- chip, 0, 0xffff, 0);
+ chip, 0, 0xffff, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= iram/*address_space(MEM_IRAM_ID)*/,
- chip, 0, 0x7f, 0);
+ chip, 0, 0x7f, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= xram/*address_space(MEM_XRAM_ID)*/,
- chip, 0, 0xffff, 0);
+ chip, 0, 0xffff, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
chip->init();
memchips->add(chip);
ad= new cl_address_decoder(as= sfr/*address_space(MEM_SFR_ID)*/,
- chip, 0x80, 0xff, 0);
+ chip, 0x80, 0xff, 0);
ad->init();
as->decoders->add(ad);
ad->activate(0);
if (serial_out)
{
if (isatty(fileno(serial_out)))
- tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out);
+ tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out);
fclose(serial_out);
}
if (serial_in)
{
if (isatty(fileno(serial_in)))
- tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in);
+ tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in);
fclose(serial_in);
}
*/
while (*b)
{
if (*b == '%')
- {
- b++;
- switch (*(b++))
- {
- case 'A': // absolute address
- sprintf(temp, "%04"_A_"x",
- t_addr((addr&0xf800)|
- (((code>>5)&0x07)*256 +
- rom->get(addr+1))));
- break;
- case 'l': // long address
- sprintf(temp, "%04"_A_"x",
- t_addr(rom->get(addr+1)*256 +
- rom->get(addr+2)));
- break;
- case 'a': // addr8 (direct address) at 2nd byte
- if (!get_name(rom->get(addr+1), sfr_tbl(), temp))
- sprintf(temp, "%02"_M_"x", rom->get(addr+1));
- break;
- case '8': // addr8 (direct address) at 3rd byte
- if (!get_name(rom->get(addr+2), sfr_tbl(), temp))
- sprintf(temp, "%02"_M_"x", rom->get(addr+2));
- //sprintf(temp, "%02"_M_"x", rom->get(addr+2));
- break;
- case 'b': // bitaddr at 2nd byte
- {
- t_addr ba= rom->get(addr+1);
- if (get_name(ba, bit_tbl(), temp))
- break;
- if (get_name((ba<128)?((ba/8)+32):(ba&0xf8), sfr_tbl(), temp))
- {
- strcat(temp, ".");
- sprintf(c, "%1"_M_"d", ba & 0x07);
- strcat(temp, c);
- break;
- }
- sprintf(temp, "%02x.%"_M_"d", (ba<128)?((ba/8)+32):(ba&0xf8),
- ba & 0x07);
- break;
- }
- case 'r': // rel8 address at 2nd byte
- sprintf(temp, "%04"_A_"x",
- t_addr(addr+2+(signed char)(rom->get(addr+1))));
- break;
- case 'R': // rel8 address at 3rd byte
- sprintf(temp, "%04"_A_"x",
- t_addr(addr+3+(signed char)(rom->get(addr+2))));
- break;
- case 'd': // data8 at 2nd byte
- sprintf(temp, "%02"_M_"x", rom->get(addr+1));
- break;
- case 'D': // data8 at 3rd byte
- sprintf(temp, "%02"_M_"x", rom->get(addr+2));
- break;
- case '6': // data16 at 2nd(H)-3rd(L) byte
- sprintf(temp, "%04"_A_"x",
- t_addr(rom->get(addr+1)*256 +
- rom->get(addr+2)));
- break;
- default:
- strcpy(temp, "?");
- break;
- }
- t= temp;
- while (*t)
- *(p++)= *(t++);
- }
+ {
+ b++;
+ switch (*(b++))
+ {
+ case 'A': // absolute address
+ sprintf(temp, "%04"_A_"x",
+ t_addr((addr&0xf800)|
+ (((code>>5)&0x07)*256 +
+ rom->get(addr+1))));
+ break;
+ case 'l': // long address
+ sprintf(temp, "%04"_A_"x",
+ t_addr(rom->get(addr+1)*256 +
+ rom->get(addr+2)));
+ break;
+ case 'a': // addr8 (direct address) at 2nd byte
+ if (!get_name(rom->get(addr+1), sfr_tbl(), temp))
+ sprintf(temp, "%02"_M_"x", rom->get(addr+1));
+ break;
+ case '8': // addr8 (direct address) at 3rd byte
+ if (!get_name(rom->get(addr+2), sfr_tbl(), temp))
+ sprintf(temp, "%02"_M_"x", rom->get(addr+2));
+ //sprintf(temp, "%02"_M_"x", rom->get(addr+2));
+ break;
+ case 'b': // bitaddr at 2nd byte
+ {
+ t_addr ba= rom->get(addr+1);
+ if (get_name(ba, bit_tbl(), temp))
+ break;
+ if (get_name((ba<128)?((ba/8)+32):(ba&0xf8), sfr_tbl(), temp))
+ {
+ strcat(temp, ".");
+ sprintf(c, "%1"_M_"d", ba & 0x07);
+ strcat(temp, c);
+ break;
+ }
+ sprintf(temp, "%02x.%"_M_"d", (ba<128)?((ba/8)+32):(ba&0xf8),
+ ba & 0x07);
+ break;
+ }
+ case 'r': // rel8 address at 2nd byte
+ sprintf(temp, "%04"_A_"x",
+ t_addr(addr+2+(signed char)(rom->get(addr+1))));
+ break;
+ case 'R': // rel8 address at 3rd byte
+ sprintf(temp, "%04"_A_"x",
+ t_addr(addr+3+(signed char)(rom->get(addr+2))));
+ break;
+ case 'd': // data8 at 2nd byte
+ sprintf(temp, "%02"_M_"x", rom->get(addr+1));
+ break;
+ case 'D': // data8 at 3rd byte
+ sprintf(temp, "%02"_M_"x", rom->get(addr+2));
+ break;
+ case '6': // data16 at 2nd(H)-3rd(L) byte
+ sprintf(temp, "%04"_A_"x",
+ t_addr(rom->get(addr+1)*256 +
+ rom->get(addr+2)));
+ break;
+ default:
+ strcpy(temp, "?");
+ break;
+ }
+ t= temp;
+ while (*t)
+ *(p++)= *(t++);
+ }
else
- *(p++)= *(b++);
+ *(p++)= *(b++);
}
*p= '\0';
if (sep == NULL)
{
while (strlen(buf) < 6)
- strcat(buf, " ");
+ strcat(buf, " ");
}
else
strcat(buf, sep);
void
-cl_51core::print_regs(class cl_console *con)
+cl_51core::print_regs(class cl_console_base *con)
{
t_addr start;
uchar data;
start= psw->get() & 0x18;
data= iram->get(iram->get(start));
con->dd_printf("%06x %02x %c",
- iram->get(start), data, isprint(data)?data:'.');
+ iram->get(start), data, isprint(data)?data:'.');
con->dd_printf(" ACC= 0x%02x %3d %c B= 0x%02x", sfr->get(ACC), sfr->get(ACC),
- isprint(sfr->get(ACC))?(sfr->get(ACC)):'.', sfr->get(B));
+ isprint(sfr->get(ACC))?(sfr->get(ACC)):'.', sfr->get(B));
//eram2xram();
data= xram->get(sfr->get(DPH)*256+sfr->get(DPL));
con->dd_printf(" DPTR= 0x%02x%02x @DPTR= 0x%02x %3d %c\n", sfr->get(DPH),
- sfr->get(DPL), data, data, isprint(data)?data:'.');
+ sfr->get(DPL), data, data, isprint(data)?data:'.');
data= iram->get(iram->get(start+1));
con->dd_printf("%06x %02x %c", iram->get(start+1), data,
- isprint(data)?data:'.');
+ isprint(data)?data:'.');
data= psw->get();
con->dd_printf(" PSW= 0x%02x CY=%c AC=%c OV=%c P=%c\n", data,
- (data&bmCY)?'1':'0', (data&bmAC)?'1':'0',
- (data&bmOV)?'1':'0', (data&bmP)?'1':'0');
+ (data&bmCY)?'1':'0', (data&bmAC)?'1':'0',
+ (data&bmOV)?'1':'0', (data&bmP)?'1':'0');
print_disass(PC, con);
}
t_addr
cl_51core::bit_address(class cl_memory *mem,
- t_addr mem_address, int bit_number)
+ t_addr mem_address, int bit_number)
{
if (bit_number < 0 ||
bit_number > 7 ||
if (mem == sfr)
{
if (mem_address < 128 ||
- mem_address % 8 != 0 ||
- mem_address > 255)
- return(-1);
+ mem_address % 8 != 0 ||
+ mem_address > 255)
+ return(-1);
return(128 + (mem_address-128) + bit_number);
}
if (mem == iram)
{
if (mem_address < 0x20 ||
- mem_address >= 0x20+32)
- return(-1);
+ mem_address >= 0x20+32)
+ return(-1);
return((mem_address-0x20)*8 + bit_number);
}
return(-1);
code= rom->get(addr);
tabl= &(dis_tbl()[code]);
while (!inst_at(addr) &&
- code != 0xa5 /* break point */)
+ code != 0xa5 /* break point */)
{
set_inst_at(addr);
switch (tabl->branch)
- {
- case 'a': // acall
- analyze((addr & 0xf800)|
- ((rom->get(addr+1)&0x07)*256+
- rom->get(addr+2)));
- analyze(addr+tabl->length);
- break;
- case 'A': // ajmp
- addr= (addr & 0xf800)|
- ((rom->get(addr+1) & 0x07)*256 + rom->get(addr+2));
- break;
- case 'l': // lcall
- analyze(rom->get(addr+1)*256 + rom->get(addr+2));
- analyze(addr+tabl->length);
- break;
- case 'L': // ljmp
- addr= rom->get(addr+1)*256 + rom->get(addr+2);
- break;
- case 'r': // reljmp (2nd byte)
- analyze(rom->validate_address(addr+(signed char)(rom->get(addr+1))));
- analyze(addr+tabl->length);
- break;
- case 'R': // reljmp (3rd byte)
- analyze(rom->validate_address(addr+(signed char)(rom->get(addr+2))));
- analyze(addr+tabl->length);
- break;
- case 's': // sjmp
- {
- signed char target;
- target= rom->get(addr+1);
- addr+= 2;
- addr= rom->validate_address(addr+target);
- break;
- }
- case '_':
- return;
- default:
- addr= rom->validate_address(addr+tabl->length);
- break;
- }
+ {
+ case 'a': // acall
+ analyze((addr & 0xf800)|
+ ((rom->get(addr+1)&0x07)*256+
+ rom->get(addr+2)));
+ analyze(addr+tabl->length);
+ break;
+ case 'A': // ajmp
+ addr= (addr & 0xf800)|
+ ((rom->get(addr+1) & 0x07)*256 + rom->get(addr+2));
+ break;
+ case 'l': // lcall
+ analyze(rom->get(addr+1)*256 + rom->get(addr+2));
+ analyze(addr+tabl->length);
+ break;
+ case 'L': // ljmp
+ addr= rom->get(addr+1)*256 + rom->get(addr+2);
+ break;
+ case 'r': // reljmp (2nd byte)
+ analyze(rom->validate_address(addr+(signed char)(rom->get(addr+1))));
+ analyze(addr+tabl->length);
+ break;
+ case 'R': // reljmp (3rd byte)
+ analyze(rom->validate_address(addr+(signed char)(rom->get(addr+2))));
+ analyze(addr+tabl->length);
+ break;
+ case 's': // sjmp
+ {
+ signed char target;
+ target= rom->get(addr+1);
+ addr+= 2;
+ addr= rom->validate_address(addr+target);
+ break;
+ }
+ case '_':
+ return;
+ default:
+ addr= rom->validate_address(addr+tabl->length);
+ break;
+ }
code= rom->get(addr);
tabl= &(dis_tbl()[code]);
}
* (inp_avail will be TRUE if ENTER is pressed) and it can confuse
* command interepter.
*/
-//static class cl_console *c= NULL;
+//static class cl_console_base *c= NULL;
int
cl_51core::do_inst(int step)
{
result= resGO;
while ((result == resGO) &&
- (state != stPD) &&
- (step != 0))
+ (state != stPD) &&
+ (step != 0))
{
if (step > 0)
- step--;
+ step--;
if (state == stGO)
- {
- interrupt->was_reti= DD_FALSE;
- pre_inst();
- result= exec_inst();
- post_inst();
- /*
- {
- if (c)
- print_regs(c);
- else
- {
- if (sim->app->get_commander()==NULL)
- printf("no commander PC=0x%x\n",PC);
- else
- if (sim->app->get_commander()->frozen_console==NULL)
- printf("no frozen console PC=0x%x\n",PC);
- else
- c= sim->app->get_commander()->frozen_console;
- if (c)
- print_regs(c);
- else
- printf("no console PC=0x%x\n",PC);
- }
- }
- */
- /*if (result == resGO)
- result= check_events();*/
- }
+ {
+ interrupt->was_reti= DD_FALSE;
+ pre_inst();
+ result= exec_inst();
+ post_inst();
+ /*
+ {
+ if (c)
+ print_regs(c);
+ else
+ {
+ if (sim->app->get_commander()==NULL)
+ printf("no commander PC=0x%x\n",PC);
+ else
+ if (sim->app->get_commander()->frozen_console==NULL)
+ printf("no frozen console PC=0x%x\n",PC);
+ else
+ c= sim->app->get_commander()->frozen_console;
+ if (c)
+ print_regs(c);
+ else
+ printf("no console PC=0x%x\n",PC);
+ }
+ }
+ */
+ /*if (result == resGO)
+ result= check_events();*/
+ }
else
- {
- // tick hw in idle state
- inst_ticks= 1;
- post_inst();
- tick(1);
- }
+ {
+ // tick hw in idle state
+ inst_ticks= 1;
+ post_inst();
+ tick(1);
+ }
if (result == resGO)
- {
- int res;
- if ((res= do_interrupt()) != resGO)
- result= res;
- else
- result= idle_pd();
- }
+ {
+ int res;
+ if ((res= do_interrupt()) != resGO)
+ result= res;
+ else
+ result= idle_pd();
+ }
if ((step < 0) &&
- ((ticks->ticks % 100000) < 50))
- {
- if (sim->app->get_commander()->input_avail_on_frozen())
- {
- result= resUSER;
- }
- else
- if (sim->app->get_commander()->input_avail())
- break;
- }
+ ((ticks->ticks % 100000) < 50))
+ {
+ if (sim->app->get_commander()->input_avail_on_frozen())
+ {
+ result= resUSER;
+ }
+ else
+ if (sim->app->get_commander()->input_avail())
+ break;
+ }
if (((result == resINTERRUPT) &&
- stop_at_it) ||
- result >= resSTOP)
- {
- sim->stop(result);
- break;
- }
+ stop_at_it) ||
+ result >= resSTOP)
+ {
+ sim->stop(result);
+ break;
+ }
}
if (state == stPD)
{
//FIXME: tick outsiders eg. watchdog
if (sim->app->get_commander()->input_avail_on_frozen())
- {
- //fprintf(stderr,"uc: inp avail in PD mode, user stop\n");
+ {
+ //fprintf(stderr,"uc: inp avail in PD mode, user stop\n");
result= resUSER;
sim->stop(result);
- }
+ }
}
return(result);
}
{
// IE0 edge triggered
if (p3_int0_edge)
- {
- // falling edge on INT0
- sim->app->get_commander()->
- debug("%g sec (%d clks): Falling edge detected on INT0 (P3.2)\n",
- get_rtime(), ticks->ticks);
- sfr->set_bit1(TCON, bmIE0);
- p3_int0_edge= 0;
- }
+ {
+ // falling edge on INT0
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): Falling edge detected on INT0 (P3.2)\n",
+ get_rtime(), ticks->ticks);
+ sfr->set_bit1(TCON, bmIE0);
+ p3_int0_edge= 0;
+ }
}
else
{
// IE0 level triggered
if (p3 & bm_INT0)
- sfr->set_bit0(TCON, bmIE0);
+ sfr->set_bit0(TCON, bmIE0);
else
- sfr->set_bit1(TCON, bmIE0);
+ sfr->set_bit1(TCON, bmIE0);
}
if ((tcon & bmIT1))
{
// IE1 edge triggered
if (p3_int1_edge)
- {
- // falling edge on INT1
- sfr->set_bit1(TCON, bmIE1);
- p3_int1_edge= 0;
- }
+ {
+ // falling edge on INT1
+ sfr->set_bit1(TCON, bmIE1);
+ p3_int1_edge= 0;
+ }
}
else
{
// IE1 level triggered
if (p3 & bm_INT1)
- sfr->set_bit0(TCON, bmIE1);
+ sfr->set_bit0(TCON, bmIE1);
else
- sfr->set_bit1(TCON, bmIE1);
- }*/
+ sfr->set_bit1(TCON, bmIE1);
+ }*/
//prev_p3= p3 & port_pins[3];
//prev_p1= p3 & port_pins[1];
//}
{
class cl_it_src *is= (class cl_it_src *)(it_sources->at(i));
if (is->is_active() &&
- (ie & is->ie_mask) &&
- (sfr->get(is->src_reg) & is->src_mask))
- {
- int pr= it_priority(is->ie_mask);
- if (il->level >= 0 &&
- pr <= il->level)
- continue;
- if (state == stIDLE)
- {
- state= stGO;
- sfr->set_bit0(PCON, bmIDL);
- interrupt->was_reti= DD_TRUE;
- return(resGO);
- }
- if (is->clr_bit)
- sfr->set_bit0(is->src_reg, is->src_mask);
- sim->app->get_commander()->
- debug("%g sec (%d clks): Accepting interrupt `%s' PC= 0x%06x\n",
- get_rtime(), ticks->ticks, object_name(is), PC);
- IL= new it_level(pr, is->addr, PC, is);
- return(accept_it(IL));
- }
+ (ie & is->ie_mask) &&
+ (sfr->get(is->src_reg) & is->src_mask))
+ {
+ int pr= it_priority(is->ie_mask);
+ if (il->level >= 0 &&
+ pr <= il->level)
+ continue;
+ if (state == stIDLE)
+ {
+ state= stGO;
+ sfr->set_bit0(PCON, bmIDL);
+ interrupt->was_reti= DD_TRUE;
+ return(resGO);
+ }
+ if (is->clr_bit)
+ sfr->set_bit0(is->src_reg, is->src_mask);
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): Accepting interrupt `%s' PC= 0x%06x\n",
+ get_rtime(), ticks->ticks, object_name(is), PC);
+ IL= new it_level(pr, is->addr, PC, is);
+ return(accept_it(IL));
+ }
}
return(resGO);
}
if (pcon & bmIDL)
{
if (state != stIDLE)
- sim->app->get_commander()->
- debug("%g sec (%d clks): CPU in Idle mode (PC=0x%x, PCON=0x%x)\n",
- get_rtime(), ticks->ticks, PC, pcon);
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): CPU in Idle mode (PC=0x%x, PCON=0x%x)\n",
+ get_rtime(), ticks->ticks, PC, pcon);
state= stIDLE;
//was_reti= 1;
}
if (pcon & bmPD)
{
if (state != stPD)
- sim->app->get_commander()->
- debug("%g sec (%d clks): CPU in PowerDown mode\n",
- get_rtime(), ticks->ticks);
+ sim->app->get_commander()->
+ debug("%g sec (%d clks): CPU in PowerDown mode\n",
+ get_rtime(), ticks->ticks);
state= stPD;
}
return(resGO);
{
eb= (class cl_ev_brk *)(ebrk->at(i));
if (eb->match(&event_at))
- return(resBREAKPOINT);
+ return(resBREAKPOINT);
}
return(resGO);
}*/
p = DD_FALSE;
uc= *val;
for (i= 0; i < 8; i++)
- {
- if (uc & 1)
- p= !p;
- uc>>= 1;
- }
+ {
+ if (uc & 1)
+ p= !p;
+ uc>>= 1;
+ }
if (p)
- cell_psw->set_bit1(bmP);
+ cell_psw->set_bit1(bmP);
else
- cell_psw->set_bit0(bmP);
+ cell_psw->set_bit0(bmP);
}
else if (cell == cell_sp)
{
if (*val > uc->sp_max)
- uc->sp_max= *val;
+ uc->sp_max= *val;
uc->sp_avg= (uc->sp_avg+(*val))/2;
}
/*else if (cell == cell_pcon)
t_mem p3o= ep->pins & ep->prev_value;
t_mem p3n= ep->new_pins & ep->new_value;
if ((p3o & bm_INT0) &&
- !(p3n & bm_INT0))
- uc51->p3_int0_edge++;
+ !(p3n & bm_INT0))
+ uc51->p3_int0_edge++;
if ((p3o & bm_INT1) &&
- !(p3n & bm_INT1))
- uc51->p3_int1_edge++;
+ !(p3n & bm_INT1))
+ uc51->p3_int1_edge++;
}
}*/
public:
// Help to detect external it requests (falling edge)
- uchar prev_p1; // Prev state of P1
- uchar prev_p3; // Prev state of P3
+ uchar prev_p1; // Prev state of P1
+ uchar prev_p3; // Prev state of P3
int p3_int0_edge, p3_int1_edge;
public:
// Simulation of interrupt system
class cl_interrupt *interrupt;
- //bool was_reti; // Instruction had an effect on IE
+ //bool was_reti; // Instruction had an effect on IE
public:
- int result; // result of instruction execution
+ int result; // result of instruction execution
cl_51core(int Itype, int Itech, class cl_sim *asim);
virtual ~cl_51core(void);
virtual struct name_entry *sfr_tbl(void);
virtual struct name_entry *bit_tbl(void);
virtual char *disass(t_addr addr, char *sep);
- virtual void print_regs(class cl_console *con);
+ virtual void print_regs(class cl_console_base *con);
virtual class cl_address_space *bit2mem(t_addr bitaddr,
- t_addr *memaddr, t_mem *bitmask);
+ t_addr *memaddr, t_mem *bitmask);
virtual t_addr bit_address(class cl_memory *mem,
- t_addr mem_address,
- int bit_number);
+ t_addr mem_address,
+ int bit_number);
virtual void reset(void);
virtual void clear_sfr(void);
virtual void analyze(t_addr addr);
//virtual void post_inst(void);
virtual int inst_unknown(void);
- virtual int inst_nop(uchar code); /* 00 */
- virtual int inst_ajmp_addr(uchar code); /* [02468ace]1 */
- virtual int inst_ljmp(uchar code); /* 02 */
- virtual int inst_rr(uchar code); /* 03 */
- virtual int inst_inc_a(uchar code); /* 04 */
- virtual int inst_inc_addr(uchar code); /* 05 */
- virtual int inst_inc_Sri(uchar code); /* 06,07 */
- virtual int inst_inc_rn(uchar code); /* 08-0f */
- virtual int inst_jbc_bit_addr(uchar code); /* 10 */
- virtual int inst_acall_addr(uchar code); /* [13579bdf]1 */
+ virtual int inst_nop(uchar code); /* 00 */
+ virtual int inst_ajmp_addr(uchar code); /* [02468ace]1 */
+ virtual int inst_ljmp(uchar code); /* 02 */
+ virtual int inst_rr(uchar code); /* 03 */
+ virtual int inst_inc_a(uchar code); /* 04 */
+ virtual int inst_inc_addr(uchar code); /* 05 */
+ virtual int inst_inc_Sri(uchar code); /* 06,07 */
+ virtual int inst_inc_rn(uchar code); /* 08-0f */
+ virtual int inst_jbc_bit_addr(uchar code); /* 10 */
+ virtual int inst_acall_addr(uchar code); /* [13579bdf]1 */
virtual int inst_lcall(uchar code, uint addr, bool intr);/* 12 */
- virtual int inst_rrc(uchar code); /* 13 */
- virtual int inst_dec_a(uchar code); /* 14 */
- virtual int inst_dec_addr(uchar code); /* 15 */
- virtual int inst_dec_Sri(uchar code); /* 16,17 */
- virtual int inst_dec_rn(uchar code); /* 18-1f */
- virtual int inst_jb_bit_addr(uchar code); /* 20 */
- virtual int inst_ret(uchar code); /* 22 */
- virtual int inst_rl(uchar code); /* 23 */
- virtual int inst_add_a_Sdata(uchar code); /* 24 */
- virtual int inst_add_a_addr(uchar code); /* 25 */
- virtual int inst_add_a_Sri(uchar code); /* 26,27 */
- virtual int inst_add_a_rn(uchar code); /* 28-2f */
- virtual int inst_jnb_bit_addr(uchar code); /* 30 */
- virtual int inst_reti(uchar code); /* 32 */
- virtual int inst_rlc(uchar code); /* 33 */
- virtual int inst_addc_a_Sdata(uchar code); /* 34 */
- virtual int inst_addc_a_addr(uchar code); /* 35 */
- virtual int inst_addc_a_Sri(uchar code); /* 36,37 */
- virtual int inst_addc_a_rn(uchar code); /* 38-3f */
- virtual int inst_jc_addr(uchar code); /* 40 */
- virtual int inst_orl_addr_a(uchar code); /* 42 */
- virtual int inst_orl_addr_Sdata(uchar code); /* 43 */
- virtual int inst_orl_a_Sdata(uchar code); /* 44 */
- virtual int inst_orl_a_addr(uchar code); /* 45 */
- virtual int inst_orl_a_Sri(uchar code); /* 46,47 */
- virtual int inst_orl_a_rn(uchar code); /* 48-4f */
- virtual int inst_jnc_addr(uchar code); /* 50 */
- virtual int inst_anl_addr_a(uchar code); /* 52 */
- virtual int inst_anl_addr_Sdata(uchar code); /* 53 */
- virtual int inst_anl_a_Sdata(uchar code); /* 54 */
- virtual int inst_anl_a_addr(uchar code); /* 55 */
- virtual int inst_anl_a_Sri(uchar code); /* 56,57 */
- virtual int inst_anl_a_rn(uchar code); /* 58-5f */
- virtual int inst_jz_addr(uchar code); /* 60 */
- virtual int inst_xrl_addr_a(uchar code); /* 62 */
- virtual int inst_xrl_addr_Sdata(uchar code); /* 63 */
- virtual int inst_xrl_a_Sdata(uchar code); /* 64 */
- virtual int inst_xrl_a_addr(uchar code); /* 65 */
- virtual int inst_xrl_a_Sri(uchar code); /* 66,67 */
- virtual int inst_xrl_a_rn(uchar code); /* 68-6f */
- virtual int inst_jnz_addr(uchar code); /* 70 */
- virtual int inst_orl_c_bit(uchar code); /* 72 */
- virtual int inst_jmp_Sa_dptr(uchar code); /* 73 */
- virtual int inst_mov_a_Sdata(uchar code); /* 74 */
- virtual int inst_mov_addr_Sdata(uchar code); /* 75 */
- virtual int inst_mov_Sri_Sdata(uchar code); /* 76,77 */
- virtual int inst_mov_rn_Sdata(uchar code); /* 78-7f */
- virtual int inst_sjmp(uchar code); /* 80 */
- virtual int inst_anl_c_bit(uchar code); /* 82 */
- virtual int inst_movc_a_Sa_pc(uchar code); /* 83 */
- virtual int inst_div_ab(uchar code); /* 84 */
- virtual int inst_mov_addr_addr(uchar code); /* 85 */
- virtual int inst_mov_addr_Sri(uchar code); /* 86,87 */
- virtual int inst_mov_addr_rn(uchar code); /* 88-8f */
- virtual int inst_mov_dptr_Sdata(uchar code); /* 90 */
- virtual int inst_mov_bit_c(uchar code); /* 92 */
- virtual int inst_movc_a_Sa_dptr(uchar code); /* 93 */
- virtual int inst_subb_a_Sdata(uchar code); /* 94 */
- virtual int inst_subb_a_addr(uchar code); /* 95 */
- virtual int inst_subb_a_Sri(uchar code); /* 96,97 */
- virtual int inst_subb_a_rn(uchar code); /* 98-9f */
- virtual int inst_orl_c_Sbit(uchar code); /* a0 */
- virtual int inst_mov_c_bit(uchar code); /* a2 */
- virtual int inst_inc_dptr(uchar code); /* a3 */
- virtual int inst_mul_ab(uchar code); /* a4 */
- virtual int inst_mov_Sri_addr(uchar code); /* a6,a7 */
- virtual int inst_mov_rn_addr(uchar code); /* a8-af */
- virtual int inst_anl_c_Sbit(uchar code); /* b0 */
- virtual int inst_cpl_bit(uchar code); /* b2 */
- virtual int inst_cpl_c(uchar code); /* b3 */
- virtual int inst_cjne_a_Sdata_addr(uchar code); /* b4 */
- virtual int inst_cjne_a_addr_addr(uchar code); /* b5 */
- virtual int inst_cjne_Sri_Sdata_addr(uchar code); /* b6,b7 */
- virtual int inst_cjne_rn_Sdata_addr(uchar code); /* b8-bf */
- virtual int inst_push(uchar code); /* c0 */
- virtual int inst_clr_bit(uchar code); /* c2 */
- virtual int inst_clr_c(uchar code); /* c3*/
- virtual int inst_swap(uchar code); /* c4 */
- virtual int inst_xch_a_addr(uchar code); /* c5 */
- virtual int inst_xch_a_Sri(uchar code); /* c6,c7 */
- virtual int inst_xch_a_rn(uchar code); /* c8-cf */
- virtual int inst_pop(uchar code); /* d0 */
- virtual int inst_setb_bit(uchar code); /* d2 */
- virtual int inst_setb_c(uchar code); /* d3 */
- virtual int inst_da_a(uchar code); /* d4 */
- virtual int inst_djnz_addr_addr(uchar code); /* d5 */
- virtual int inst_xchd_a_Sri(uchar code); /* d6,d7 */
- virtual int inst_djnz_rn_addr(uchar code); /* d8-df */
- virtual int inst_movx_a_Sdptr(uchar code); /* e0 */
- virtual int inst_movx_a_Sri(uchar code); /* e2,e3 */
- virtual int inst_clr_a(uchar code); /* e4 */
- virtual int inst_mov_a_addr(uchar code); /* e5 */
- virtual int inst_mov_a_Sri(uchar code); /* e6,e7 */
- virtual int inst_mov_a_rn(uchar code); /* e8-ef */
- virtual int inst_movx_Sdptr_a(uchar code); /* f0 */
- virtual int inst_movx_Sri_a(uchar code); /* f2,f3 */
- virtual int inst_cpl_a(uchar code); /* f4 */
- virtual int inst_mov_addr_a(uchar code); /* f5 */
- virtual int inst_mov_Sri_a(uchar code); /* f6,f7 */
- virtual int inst_mov_rn_a(uchar code); /* f8-ff */
+ virtual int inst_rrc(uchar code); /* 13 */
+ virtual int inst_dec_a(uchar code); /* 14 */
+ virtual int inst_dec_addr(uchar code); /* 15 */
+ virtual int inst_dec_Sri(uchar code); /* 16,17 */
+ virtual int inst_dec_rn(uchar code); /* 18-1f */
+ virtual int inst_jb_bit_addr(uchar code); /* 20 */
+ virtual int inst_ret(uchar code); /* 22 */
+ virtual int inst_rl(uchar code); /* 23 */
+ virtual int inst_add_a_Sdata(uchar code); /* 24 */
+ virtual int inst_add_a_addr(uchar code); /* 25 */
+ virtual int inst_add_a_Sri(uchar code); /* 26,27 */
+ virtual int inst_add_a_rn(uchar code); /* 28-2f */
+ virtual int inst_jnb_bit_addr(uchar code); /* 30 */
+ virtual int inst_reti(uchar code); /* 32 */
+ virtual int inst_rlc(uchar code); /* 33 */
+ virtual int inst_addc_a_Sdata(uchar code); /* 34 */
+ virtual int inst_addc_a_addr(uchar code); /* 35 */
+ virtual int inst_addc_a_Sri(uchar code); /* 36,37 */
+ virtual int inst_addc_a_rn(uchar code); /* 38-3f */
+ virtual int inst_jc_addr(uchar code); /* 40 */
+ virtual int inst_orl_addr_a(uchar code); /* 42 */
+ virtual int inst_orl_addr_Sdata(uchar code); /* 43 */
+ virtual int inst_orl_a_Sdata(uchar code); /* 44 */
+ virtual int inst_orl_a_addr(uchar code); /* 45 */
+ virtual int inst_orl_a_Sri(uchar code); /* 46,47 */
+ virtual int inst_orl_a_rn(uchar code); /* 48-4f */
+ virtual int inst_jnc_addr(uchar code); /* 50 */
+ virtual int inst_anl_addr_a(uchar code); /* 52 */
+ virtual int inst_anl_addr_Sdata(uchar code); /* 53 */
+ virtual int inst_anl_a_Sdata(uchar code); /* 54 */
+ virtual int inst_anl_a_addr(uchar code); /* 55 */
+ virtual int inst_anl_a_Sri(uchar code); /* 56,57 */
+ virtual int inst_anl_a_rn(uchar code); /* 58-5f */
+ virtual int inst_jz_addr(uchar code); /* 60 */
+ virtual int inst_xrl_addr_a(uchar code); /* 62 */
+ virtual int inst_xrl_addr_Sdata(uchar code); /* 63 */
+ virtual int inst_xrl_a_Sdata(uchar code); /* 64 */
+ virtual int inst_xrl_a_addr(uchar code); /* 65 */
+ virtual int inst_xrl_a_Sri(uchar code); /* 66,67 */
+ virtual int inst_xrl_a_rn(uchar code); /* 68-6f */
+ virtual int inst_jnz_addr(uchar code); /* 70 */
+ virtual int inst_orl_c_bit(uchar code); /* 72 */
+ virtual int inst_jmp_Sa_dptr(uchar code); /* 73 */
+ virtual int inst_mov_a_Sdata(uchar code); /* 74 */
+ virtual int inst_mov_addr_Sdata(uchar code); /* 75 */
+ virtual int inst_mov_Sri_Sdata(uchar code); /* 76,77 */
+ virtual int inst_mov_rn_Sdata(uchar code); /* 78-7f */
+ virtual int inst_sjmp(uchar code); /* 80 */
+ virtual int inst_anl_c_bit(uchar code); /* 82 */
+ virtual int inst_movc_a_Sa_pc(uchar code); /* 83 */
+ virtual int inst_div_ab(uchar code); /* 84 */
+ virtual int inst_mov_addr_addr(uchar code); /* 85 */
+ virtual int inst_mov_addr_Sri(uchar code); /* 86,87 */
+ virtual int inst_mov_addr_rn(uchar code); /* 88-8f */
+ virtual int inst_mov_dptr_Sdata(uchar code); /* 90 */
+ virtual int inst_mov_bit_c(uchar code); /* 92 */
+ virtual int inst_movc_a_Sa_dptr(uchar code); /* 93 */
+ virtual int inst_subb_a_Sdata(uchar code); /* 94 */
+ virtual int inst_subb_a_addr(uchar code); /* 95 */
+ virtual int inst_subb_a_Sri(uchar code); /* 96,97 */
+ virtual int inst_subb_a_rn(uchar code); /* 98-9f */
+ virtual int inst_orl_c_Sbit(uchar code); /* a0 */
+ virtual int inst_mov_c_bit(uchar code); /* a2 */
+ virtual int inst_inc_dptr(uchar code); /* a3 */
+ virtual int inst_mul_ab(uchar code); /* a4 */
+ virtual int inst_mov_Sri_addr(uchar code); /* a6,a7 */
+ virtual int inst_mov_rn_addr(uchar code); /* a8-af */
+ virtual int inst_anl_c_Sbit(uchar code); /* b0 */
+ virtual int inst_cpl_bit(uchar code); /* b2 */
+ virtual int inst_cpl_c(uchar code); /* b3 */
+ virtual int inst_cjne_a_Sdata_addr(uchar code); /* b4 */
+ virtual int inst_cjne_a_addr_addr(uchar code); /* b5 */
+ virtual int inst_cjne_Sri_Sdata_addr(uchar code); /* b6,b7 */
+ virtual int inst_cjne_rn_Sdata_addr(uchar code); /* b8-bf */
+ virtual int inst_push(uchar code); /* c0 */
+ virtual int inst_clr_bit(uchar code); /* c2 */
+ virtual int inst_clr_c(uchar code); /* c3*/
+ virtual int inst_swap(uchar code); /* c4 */
+ virtual int inst_xch_a_addr(uchar code); /* c5 */
+ virtual int inst_xch_a_Sri(uchar code); /* c6,c7 */
+ virtual int inst_xch_a_rn(uchar code); /* c8-cf */
+ virtual int inst_pop(uchar code); /* d0 */
+ virtual int inst_setb_bit(uchar code); /* d2 */
+ virtual int inst_setb_c(uchar code); /* d3 */
+ virtual int inst_da_a(uchar code); /* d4 */
+ virtual int inst_djnz_addr_addr(uchar code); /* d5 */
+ virtual int inst_xchd_a_Sri(uchar code); /* d6,d7 */
+ virtual int inst_djnz_rn_addr(uchar code); /* d8-df */
+ virtual int inst_movx_a_Sdptr(uchar code); /* e0 */
+ virtual int inst_movx_a_Sri(uchar code); /* e2,e3 */
+ virtual int inst_clr_a(uchar code); /* e4 */
+ virtual int inst_mov_a_addr(uchar code); /* e5 */
+ virtual int inst_mov_a_Sri(uchar code); /* e6,e7 */
+ virtual int inst_mov_a_rn(uchar code); /* e8-ef */
+ virtual int inst_movx_Sdptr_a(uchar code); /* f0 */
+ virtual int inst_movx_Sri_a(uchar code); /* f2,f3 */
+ virtual int inst_cpl_a(uchar code); /* f4 */
+ virtual int inst_mov_addr_a(uchar code); /* f5 */
+ virtual int inst_mov_Sri_a(uchar code); /* f6,f7 */
+ virtual int inst_mov_rn_a(uchar code); /* f8-ff */
};
{
wdt= 0;
/*uc->sim->app->get_commander()->
- debug("%g sec (%d tick): Watchdog timer enabled/reset PC= 0x%06x"
- "\n", uc->get_rtime(), uc->ticks->ticks, uc51r->PC);*/
+ debug("%g sec (%d tick): Watchdog timer enabled/reset PC= 0x%06x"
+ "\n", uc->get_rtime(), uc->ticks->ticks, uc51r->PC);*/
}
written_since_reset= DD_TRUE;
}
{
wdt+= cycles;
if (wdt > reset_value)
- {
- /*sim->app->get_commander()->
- debug("%g sec (%d ticks): Watchdog timer resets the CPU, "
- "PC= 0x%06x\n", get_rtime(), ticks->ticks, PC);*/
- uc->reset();
- //return(resWDTRESET);
- }
+ {
+ /*sim->app->get_commander()->
+ debug("%g sec (%d ticks): Watchdog timer resets the CPU, "
+ "PC= 0x%06x\n", get_rtime(), ticks->ticks, PC);*/
+ uc->reset();
+ //return(resWDTRESET);
+ }
}
return(0);
}
}
void
-cl_wdt::print_info(class cl_console *con)
+cl_wdt::print_info(class cl_console_base *con)
{
con->dd_printf("%s[%d] %s counter=%d (remains=%d)\n", id_string, id,
- (wdt>=0)?"ON":"OFF", wdt, (wdt>=0)?(reset_value-wdt):0);
+ (wdt>=0)?"ON":"OFF", wdt, (wdt>=0)?(reset_value-wdt):0);
}
virtual int tick(int cycles);
virtual void reset(void);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
*/
cl_watched_cell::cl_watched_cell(class cl_address_space *amem, t_addr aaddr,
- class cl_memory_cell **astore,
- enum what_to_do_on_cell_change awtd)
+ class cl_memory_cell **astore,
+ enum what_to_do_on_cell_change awtd)
{
mem= amem;
addr= aaddr;
{
cell= mem->get_cell(addr);
if (store)
- *store= cell;
+ *store= cell;
}
}
void
cl_watched_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
- class cl_hw *hw)
+ class cl_hw *hw)
{
if (mem &&
mem == amem &&
{
cell= mem->get_cell(addr);
if (store &&
- (wtd & WTD_RESTORE))
- *store= cell;
+ (wtd & WTD_RESTORE))
+ *store= cell;
if (wtd & WTD_WRITE)
- {
- t_mem d= cell->get();
- hw->write(cell, &d);
- }
+ {
+ t_mem d= cell->get();
+ hw->write(cell, &d);
+ }
}
}
void
cl_watched_cell::address_space_added(class cl_address_space *amem,
- class cl_hw *hw)
+ class cl_hw *hw)
{
}
{
cell= mem->get_cell(addr);
if (store &&
- (wtd & WTD_RESTORE))
- *store= cell;
+ (wtd & WTD_RESTORE))
+ *store= cell;
if (wtd & WTD_WRITE)
- {
- t_mem d= cell->get();
- hw->write(cell, &d);
- }
+ {
+ t_mem d= cell->get();
+ hw->write(cell, &d);
+ }
}
}
void
cl_used_cell::address_space_added(class cl_address_space *amem,
- class cl_hw *hw)
+ class cl_hw *hw)
{
}
}*/
void
-cl_hw::set_cmd(class cl_cmdline *cmdline, class cl_console *con)
+cl_hw::set_cmd(class cl_cmdline *cmdline, class cl_console_base *con)
{
con->dd_printf("Nothing to do\n");
}
class cl_memory_cell *
cl_hw::register_cell(class cl_address_space *mem, t_addr addr,
- class cl_memory_cell **store,
- enum what_to_do_on_cell_change awtd)
+ class cl_memory_cell **store,
+ enum what_to_do_on_cell_change awtd)
{
class cl_watched_cell *wc;
class cl_memory_cell *cell;
class cl_memory_cell *
cl_hw::use_cell(class cl_address_space *mem, t_addr addr,
- class cl_memory_cell **store,
- enum what_to_do_on_cell_change awtd)
+ class cl_memory_cell **store,
+ enum what_to_do_on_cell_change awtd)
{
class cl_watched_cell *wc;
class cl_memory_cell *cell;
for (i= 0; i < watched_cells->count; i++)
{
class cl_watched_cell *wc=
- (class cl_watched_cell *)(watched_cells->at(i));
+ (class cl_watched_cell *)(watched_cells->at(i));
wc->mem_cell_changed(mem, addr, this);
}
}
for (i= 0; i < watched_cells->count; i++)
{
class cl_watched_cell *wc=
- dynamic_cast<class cl_watched_cell *>(watched_cells->object_at(i));
+ dynamic_cast<class cl_watched_cell *>(watched_cells->object_at(i));
wc->address_space_added(as, this);
}
}
void
-cl_hw::print_info(class cl_console *con)
+cl_hw::print_info(class cl_console_base *con)
{
con->dd_printf("%s[%d]\n", id_string, id);
}
{
// partner is already set
if (partner != hw)
- {
- // partner changed?
- partner= hw;
- }
+ {
+ // partner changed?
+ partner= hw;
+ }
else
- partner= hw;
+ partner= hw;
}
partner= hw;
}
id == new_hw->id)
{
if (partner)
- {
- // partner changed?
- partner= new_hw;
- }
+ {
+ // partner changed?
+ partner= new_hw;
+ }
else
- partner= new_hw;
+ partner= new_hw;
}
}
enum what_to_do_on_cell_change {
- wtd_none = 0x01,
- wtd_write = 0x02,
- wtd_restore = 0x04,
- wtd_restore_write = 0x08
+ wtd_none = 0x01,
+ wtd_write = 0x02,
+ wtd_restore = 0x04,
+ wtd_restore_write = 0x08
};
-#define WTD_WRITE (wtd_write|wtd_restore_write)
-#define WTD_RESTORE (wtd_restore|wtd_restore_write)
+#define WTD_WRITE (wtd_write|wtd_restore_write)
+#define WTD_RESTORE (wtd_restore|wtd_restore_write)
class cl_hw; // forward
enum what_to_do_on_cell_change wtd;
public:
cl_watched_cell(class cl_address_space *amem, t_addr aaddr,
- class cl_memory_cell **astore,
- enum what_to_do_on_cell_change awtd);
+ class cl_memory_cell **astore,
+ enum what_to_do_on_cell_change awtd);
virtual void mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
- class cl_hw *hw);
+ class cl_hw *hw);
virtual void address_space_added(class cl_address_space *amem,
- class cl_hw *hw);
+ class cl_hw *hw);
};
class cl_used_cell: public cl_watched_cell
{
public:
cl_used_cell(class cl_address_space *amem, t_addr aaddr,
- class cl_memory_cell **astore,
- enum what_to_do_on_cell_change awtd):
+ class cl_memory_cell **astore,
+ enum what_to_do_on_cell_change awtd):
cl_watched_cell(amem, aaddr, astore, awtd) {}
virtual void mem_cell_changed(class cl_address_space *amem, t_addr aaddr,
- class cl_hw *hw);
+ class cl_hw *hw);
virtual void address_space_added(class cl_address_space *amem,
- class cl_hw *hw);
+ class cl_hw *hw);
};
class cl_hw: public cl_guiobj
virtual t_mem read(class cl_memory_cell *cell) { return(cell->get()); }
virtual void write(class cl_memory_cell */*cell*/, t_mem */*val*/) {}
- virtual void set_cmd(class cl_cmdline *cmdline, class cl_console *con);
+ virtual void set_cmd(class cl_cmdline *cmdline, class cl_console_base *con);
virtual class cl_memory_cell *register_cell(class cl_address_space *mem,
- t_addr addr,
- class cl_memory_cell **store,
- enum what_to_do_on_cell_change
- awtd);
+ t_addr addr,
+ class cl_memory_cell **store,
+ enum what_to_do_on_cell_change
+ awtd);
virtual class cl_memory_cell *use_cell(class cl_address_space *mem,
- t_addr addr,
- class cl_memory_cell **store,
- enum what_to_do_on_cell_change awtd);
+ t_addr addr,
+ class cl_memory_cell **store,
+ enum what_to_do_on_cell_change awtd);
virtual void mem_cell_changed(class cl_address_space *mem, t_addr addr);
virtual void address_space_added(class cl_address_space *as);
virtual int tick(int cycles);
virtual void reset(void) {}
virtual void happen(class cl_hw */*where*/, enum hw_event /*he*/,
- void */*params*/) {}
+ void */*params*/) {}
virtual void inform_partners(enum hw_event he, void *params);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
};
class cl_hws: public cl_list
t_addr
-cl_memory::dump(t_addr start, t_addr stop, int bpl, class cl_console *con)
+cl_memory::dump(t_addr start, t_addr stop, int bpl, class cl_console_base *con)
{
int i;
t_addr lva= lowest_valid_address();
}
t_addr
-cl_memory::dump(class cl_console *con)
+cl_memory::dump(class cl_console_base *con)
{
return(dump(dump_finished, dump_finished+10*8-1, 8, con));
}
void
cl_address_space::undecode_area(class cl_address_decoder *skip,
- t_addr begin, t_addr end,class cl_console *con)
+ t_addr begin, t_addr end,class cl_console_base *con)
{
#define D if (con) con->debug
D("Undecoding area 0x%x-0x%x of %s\n", begin, end, get_name());
bool
-cl_address_decoder::activate(class cl_console *con)
+cl_address_decoder::activate(class cl_console_base *con)
{
#define D if (con) con->debug
D("Activation of an address decoder\n");
}
void
-cl_error_mem_invalid_address::print(class cl_commander *c)
+cl_error_mem_invalid_address::print(class cl_commander_base *c)
{
c->dd_printf("%s: invalid address ", get_type_name());
c->dd_printf(mem->addr_format, addr);
}
void
-cl_error_mem_non_decoded::print(class cl_commander *c)
+cl_error_mem_non_decoded::print(class cl_commander_base *c)
{
c->dd_printf("%s: access of non-decoded address ", get_type_name());
c->dd_printf(mem->addr_format, addr);
// Cell types
-#define CELL_NORMAL 0x00 /* Nothing special */
-#define CELL_HW_READ 0x01 /* Hw handles read */
-#define CELL_HW_WRITE 0x02 /* Hw catches write */
-//#define CELL_INST 0x04 /* Marked as instruction */
-//#define CELL_FETCH_BRK 0x08 /* Fetch breakpoint */
-#define CELL_READ_BRK 0x10 /* Read event breakpoint */
-#define CELL_WRITE_BRK 0x20 /* Write event breakpoint */
+#define CELL_NORMAL 0x00 /* Nothing special */
+#define CELL_HW_READ 0x01 /* Hw handles read */
+#define CELL_HW_WRITE 0x02 /* Hw catches write */
+//#define CELL_INST 0x04 /* Marked as instruction */
+//#define CELL_FETCH_BRK 0x08 /* Fetch breakpoint */
+#define CELL_READ_BRK 0x10 /* Read event breakpoint */
+#define CELL_WRITE_BRK 0x20 /* Write event breakpoint */
// Cell flags
enum cell_flag {
- CELL_NONE = 0x00,
- CELL_INST = 0x04, /* Marked as instruction */
- CELL_FETCH_BRK = 0x08, /* Fetch breakpoint */
- CELL_NON_DECODED = 0x40 /* Cell is not decoded (yet) */
+ CELL_NONE = 0x00,
+ CELL_INST = 0x04, /* Marked as instruction */
+ CELL_FETCH_BRK = 0x08, /* Fetch breakpoint */
+ CELL_NON_DECODED = 0x40 /* Cell is not decoded (yet) */
};
-#define CELL_GENERAL (CELL_NORMAL|CELL_INST|CELL_FETCH_BRK)
+#define CELL_GENERAL (CELL_NORMAL|CELL_INST|CELL_FETCH_BRK)
/*
virtual void err_non_decoded(t_addr addr);
virtual t_addr dump(t_addr start, t_addr stop, int bpl,
- class cl_console *con);
- virtual t_addr dump(class cl_console *con);
+ class cl_console_base *con);
+ virtual t_addr dump(class cl_console_base *con);
virtual bool search_next(bool case_sensitive,
- t_mem *array, int len, t_addr *addr);
+ t_mem *array, int len, t_addr *addr);
virtual t_addr lowest_valid_address(void) { return(start_address); }
public:
cl_memory_operator(class cl_memory_cell *acell, t_addr addr);
cl_memory_operator(class cl_memory_cell *acell, t_addr addr,
- t_mem *data_place, t_mem the_mask);
+ t_mem *data_place, t_mem the_mask);
virtual void set_data(t_mem *data_place, t_mem the_mask);
virtual class cl_memory_operator *get_next(void) { return(next_operator); }
class cl_hw *hw;
public:
cl_hw_operator(class cl_memory_cell *acell, t_addr addr,
- t_mem *data_place, t_mem the_mask, class cl_hw *ahw);
+ t_mem *data_place, t_mem the_mask, class cl_hw *ahw);
virtual bool match(class cl_hw *the_hw) { return(hw == the_hw); }
class cl_brk *bp;
public:
cl_event_break_operator(class cl_memory_cell *acell, t_addr addr,
- t_mem *data_place, t_mem the_mask,
- class cl_uc *auc, class cl_brk *the_bp):
+ t_mem *data_place, t_mem the_mask,
+ class cl_uc *auc, class cl_brk *the_bp):
cl_memory_operator(acell, addr, data_place, the_mask)
{
uc= auc;
{
public:
cl_write_operator(class cl_memory_cell *acell, t_addr addr,
- t_mem *data_place, t_mem the_mask,
- class cl_uc *auc, class cl_brk *the_bp);
+ t_mem *data_place, t_mem the_mask,
+ class cl_uc *auc, class cl_brk *the_bp);
virtual t_mem write(t_mem val);
};
{
public:
cl_read_operator(class cl_memory_cell *acell, t_addr addr,
- t_mem *data_place, t_mem the_mask,
- class cl_uc *auc, class cl_brk *the_bp);
+ t_mem *data_place, t_mem the_mask,
+ class cl_uc *auc, class cl_brk *the_bp);
virtual t_mem read(void);
};
virtual void set_cell_flag(t_addr addr, bool set_to, enum cell_flag flag);
virtual bool decode_cell(t_addr addr,
- class cl_memory_chip *chip, t_addr chipaddr);
+ class cl_memory_chip *chip, t_addr chipaddr);
virtual void undecode_cell(t_addr addr);
virtual void undecode_area(class cl_address_decoder *skip,
- t_addr begin, t_addr end, class cl_console *con);
+ t_addr begin, t_addr end, class cl_console_base *con);
virtual class cl_memory_cell *register_hw(t_addr addr, class cl_hw *hw,
- int *ith,
- bool announce);
+ int *ith,
+ bool announce);
virtual void set_brk(t_addr addr, class cl_brk *brk);
virtual void del_brk(t_addr addr, class cl_brk *brk);
bool activated;
public:
cl_address_decoder(class cl_memory *as, class cl_memory *chip,
- t_addr asb, t_addr ase, t_addr cb);
+ t_addr asb, t_addr ase, t_addr cb);
virtual ~cl_address_decoder(void);
virtual int init(void);
- virtual bool activate(class cl_console *con);
+ virtual bool activate(class cl_console_base *con);
virtual bool fully_covered_by(t_addr begin, t_addr end);
virtual bool is_in(t_addr begin, t_addr end);
public:
cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_error_mem_non_decoded: public cl_error_mem
public:
cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_mem_error_registry: public cl_error_registry
cl_mem::cl_mem(enum mem_class atype, char *aclass_name,
- t_addr asize, int awidth, class cl_uc *auc):
+ t_addr asize, int awidth, class cl_uc *auc):
cl_guiobj()
{
int i;
addr_format= (char *)malloc(10);
sprintf(addr_format, "0x%%0%dx",
- size-1<=0xf?1:
- (size-1<=0xff?2:
- (size-1<=0xfff?3:
- (size-1<=0xffff?4:
- (size-1<=0xfffff?5:
- (size-1<=0xffffff?6:12))))));
+ size-1<=0xf?1:
+ (size-1<=0xff?2:
+ (size-1<=0xfff?3:
+ (size-1<=0xffff?4:
+ (size-1<=0xfffff?5:
+ (size-1<=0xffffff?6:12))))));
data_format= (char *)malloc(10);
sprintf(data_format, "%%0%dx", width/4+((width%4)?1:0));
else
((TYPE_UDWORD*)mem)[addr]= (*val)&mask;*/
fprintf(stderr, "FIXME cl_mem::write(0x%06"_A_"x, 0x%04"_M_"x)\n",
- addr, val);
+ addr, val);
return(0);
}
}
t_addr
-cl_mem::dump(t_addr start, t_addr stop, int bpl, class cl_console *con)
+cl_mem::dump(t_addr start, t_addr stop, int bpl, class cl_console_base *con)
{
int i;
while ((start <= stop) &&
- (start < size))
+ (start < size))
{
con->dd_printf(addr_format, start); con->dd_printf(" ");
for (i= 0;
- (i < bpl) &&
- (start+i < size) &&
- (start+i <= stop);
- i++)
- {
- con->dd_printf(data_format, /*read*/get(start+i)); con->dd_printf(" ");
- }
+ (i < bpl) &&
+ (start+i < size) &&
+ (start+i <= stop);
+ i++)
+ {
+ con->dd_printf(data_format, /*read*/get(start+i)); con->dd_printf(" ");
+ }
while (i < bpl)
- {
- int j;
- j= width/4 + ((width%4)?1:0) + 1;
- while (j)
- {
- con->dd_printf(" ");
- j--;
- }
- i++;
- }
+ {
+ int j;
+ j= width/4 + ((width%4)?1:0) + 1;
+ while (j)
+ {
+ con->dd_printf(" ");
+ j--;
+ }
+ i++;
+ }
for (i= 0; (i < bpl) &&
- (start+i < size) &&
- (start+i <= stop);
- i++)
- {
- long c= get(start+i);
- con->dd_printf("%c", isprint(255&c)?(255&c):'.');
- if (width > 8)
- con->dd_printf("%c", isprint(255&(c>>8))?(255&(c>>8)):'.');
- if (width > 16)
- con->dd_printf("%c", isprint(255&(c>>16))?(255&(c>>16)):'.');
- if (width > 24)
- con->dd_printf("%c", isprint(255&(c>>24))?(255&(c>>24)):'.');
- }
+ (start+i < size) &&
+ (start+i <= stop);
+ i++)
+ {
+ long c= get(start+i);
+ con->dd_printf("%c", isprint(255&c)?(255&c):'.');
+ if (width > 8)
+ con->dd_printf("%c", isprint(255&(c>>8))?(255&(c>>8)):'.');
+ if (width > 16)
+ con->dd_printf("%c", isprint(255&(c>>16))?(255&(c>>16)):'.');
+ if (width > 24)
+ con->dd_printf("%c", isprint(255&(c>>24))?(255&(c>>24)):'.');
+ }
con->dd_printf("\n");
dump_finished= start+i;
start+= bpl;
}
t_addr
-cl_mem::dump(class cl_console *con)
+cl_mem::dump(class cl_console_base *con)
{
return(dump(dump_finished, dump_finished+10*8-1, 8, con));
}
*/
cl_m::cl_m(enum mem_class atype, char *aclass_name, t_addr asize, int awidth,
- class cl_uc *auc):
+ class cl_uc *auc):
cl_memory(aclass_name, asize, awidth)
//cl_mem(atype, aclass_name, 0, awidth, auc)
{
found= DD_FALSE;
while (!found &&
- a+len <= size)
+ a+len <= size)
{
bool match= DD_TRUE;
for (i= 0; i < len && match; i++)
- {
- t_mem d1, d2;
- d1= get(a+i);
- d2= array[i];
- if (!case_sensitive)
- {
- if (/*d1 < 128*/isalpha(d1))
- d1= toupper(d1);
- if (/*d2 < 128*/isalpha(d2))
- d2= toupper(d2);
- }
- match= d1 == d2;
- }
+ {
+ t_mem d1, d2;
+ d1= get(a+i);
+ d2= array[i];
+ if (!case_sensitive)
+ {
+ if (/*d1 < 128*/isalpha(d1))
+ d1= toupper(d1);
+ if (/*d2 < 128*/isalpha(d2))
+ d2= toupper(d2);
+ }
+ match= d1 == d2;
+ }
found= match;
if (!found)
- a++;
+ a++;
}
if (addr)
nc= new cl_ev_reg_cell(width, uc);
nc->set(cell->get());
nc->set_type(nc->get_type() &
- ~(CELL_GENERAL|CELL_READ_BRK|CELL_WRITE_BRK));
+ ~(CELL_GENERAL|CELL_READ_BRK|CELL_WRITE_BRK));
nc->set_type(nc->get_type() | (cell->get_type() & CELL_GENERAL));
class cl_event_handler *eh= nc->get_event_handler();
if (eh)
- nc->set_type(nc->get_type() | eh->copy_from(cell->get_event_handler()));
+ nc->set_type(nc->get_type() | eh->copy_from(cell->get_event_handler()));
nc->add_hw(hw, ith);
}
else
set_cell_flag(addr, DD_TRUE, CELL_FETCH_BRK);
return;
break;
- default: e= '.'; break;
+ default: e= '.'; break;
}
if (cell->get_type() & (CELL_HW_READ | CELL_HW_WRITE))
int i= 0;
class cl_hw *hw;
while ((hw= cell->get_hw(i)) != 0)
- {
- nc->add_hw(hw, 0);
- i++;
- }
+ {
+ nc->add_hw(hw, 0);
+ i++;
+ }
if (((class cl_registered_cell *)cell)->hardwares)
- {
- free(((class cl_registered_cell *)cell)->hardwares);
- ((class cl_registered_cell *)cell)->hardwares= 0;
- }
+ {
+ free(((class cl_registered_cell *)cell)->hardwares);
+ ((class cl_registered_cell *)cell)->hardwares= 0;
+ }
class cl_event_handler *eh;
if ((eh= nc->get_event_handler()))
- nc->set_type(nc->get_type() | eh->add_bp(brk));
+ nc->set_type(nc->get_type() | eh->add_bp(brk));
}
else if (cell->get_type() & (CELL_READ_BRK | CELL_WRITE_BRK))
{
/* Break is already set on it */
class cl_event_handler *eh;
if ((eh= cell->get_event_handler()))
- cell->set_type(cell->get_type() | eh->add_bp(brk));
+ cell->set_type(cell->get_type() | eh->add_bp(brk));
return;
}
else
nc->set_type(nc->get_type() | (cell->get_type() & CELL_GENERAL));
class cl_event_handler *eh;
if ((eh= nc->get_event_handler()))
- nc->set_type(nc->get_type() | eh->add_bp(brk));
+ nc->set_type(nc->get_type() | eh->add_bp(brk));
}
if (addr >= size)
class cl_event_handler *eh;
int t= CELL_NORMAL;
if ((eh= cell->get_event_handler()))
- t= eh->del_bp(brk);
+ t= eh->del_bp(brk);
if (t & (CELL_READ_BRK|CELL_WRITE_BRK))
- {
- cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK));
- cell->set_type(cell->get_type() | t);
- return;
- }
+ {
+ cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK));
+ cell->set_type(cell->get_type() | t);
+ return;
+ }
nc= new cl_registered_cell(width);
nc->set(cell->get());
nc->set_type(cell->get_type() & ~CELL_GENERAL);
int i= 0;
class cl_hw *hw;
while ((hw= cell->get_hw(i)) != 0)
- {
- nc->add_hw(hw, 0);
- i++;
- }
+ {
+ nc->add_hw(hw, 0);
+ i++;
+ }
if (((class cl_registered_cell *)cell)->hardwares)
- free(((class cl_registered_cell *)cell)->hardwares);
+ free(((class cl_registered_cell *)cell)->hardwares);
}
else if (cell->get_type() & (CELL_READ_BRK | CELL_WRITE_BRK))
{
class cl_event_handler *eh;
int t= CELL_NORMAL;
if ((eh= cell->get_event_handler()))
- t= eh->del_bp(brk);
+ t= eh->del_bp(brk);
if (t & (CELL_READ_BRK|CELL_WRITE_BRK))
- {
- cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK));
- cell->set_type(cell->get_type() | t);
- return;
- }
+ {
+ cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK));
+ cell->set_type(cell->get_type() | t);
+ return;
+ }
nc= new cl_normal_cell(width);
nc->set(cell->get());
nc->set_type(cell->get_type() & ~CELL_GENERAL);
if (nuof_hws)
for (i= 0; i < nuof_hws; i++)
{
- d= hardwares[i]->read(this);
- ;
+ d= hardwares[i]->read(this);
+ ;
}
#ifdef STATISTIC
nuof_reads++;
if (nuof_hws)
for (i= 0; i < nuof_hws; i++)
{
- if ((skip & hardwares[i]->cathegory) == 0)
- d= hardwares[i]->read(this);
- ;
+ if ((skip & hardwares[i]->cathegory) == 0)
+ d= hardwares[i]->read(this);
+ ;
}
#ifdef STATISTIC
nuof_reads++;
if (nuof_hws)
for (i= 0; i < nuof_hws; i++)
{
- hardwares[i]->write(this, &val);
- ;
+ hardwares[i]->write(this, &val);
+ ;
}
#ifdef STATISTIC
nuof_writes++;
hardwares= (class cl_hw **)malloc(sizeof(class cl_hw *));
else
hardwares= (class cl_hw **)realloc(hardwares,
- sizeof(class c_hw *) * (nuof_hws+1));
+ sizeof(class c_hw *) * (nuof_hws+1));
hardwares[nuof_hws]= hw;
nuof_hws++;
if (ith)
public:
cl_mem(enum mem_class atype, char *aclass_name, t_addr asize, int awidth,
- class cl_uc *auc);
+ class cl_uc *auc);
virtual ~cl_mem(void);
virtual int init(void);
virtual char *id_string(void);
virtual int get_cell_flag(t_addr //addr
- ) { return(CELL_NORMAL); }
+ ) { return(CELL_NORMAL); }
virtual bool get_cell_flag(t_addr //addr
- , int //flag
- )
+ , int //flag
+ )
{ return(DD_FALSE); }
virtual void set_cell_flag(t_addr addr, bool set_to, int flag) {}
virtual t_mem read(t_addr addr);
virtual t_mem read(t_addr addr, enum hw_cath //skip
- ) {return(read(addr));}
+ ) {return(read(addr));}
virtual t_mem get(t_addr addr);
virtual t_mem write(t_addr addr, t_mem val);
virtual void set(t_addr addr, t_mem val);
virtual t_mem add(t_addr addr, long what);
virtual t_mem wadd(t_addr addr, long what) { return(add(addr, what)); }
virtual t_addr dump(t_addr start, t_addr stop, int bpl,
- class cl_console *con);
- virtual t_addr dump(class cl_console *con);
+ class cl_console_base *con);
+ virtual t_addr dump(class cl_console_base *con);
virtual bool search_next(bool case_sensitive,
- t_mem *array, int len, t_addr *addr);
+ t_mem *array, int len, t_addr *addr);
virtual class cl_cell *get_cell(t_addr addr) {return(0);}
virtual class cl_cell *register_hw(t_addr addr, class cl_hw *hw, int *ith,
- bool announce)
+ bool announce)
{ return(0); }
virtual void set_brk(t_addr //addr
- , class cl_brk *//brk
- ) {}
+ , class cl_brk *//brk
+ ) {}
virtual void del_brk(t_addr addr, class cl_brk *brk) {}
#ifdef STATISTIC
virtual unsigned long get_nuof_reads(void) {return(0);}
virtual t_mem wadd(t_addr addr, long what);
virtual bool search_next(bool case_sensitive,
- t_mem *array, int len, t_addr *addr);
+ t_mem *array, int len, t_addr *addr);
virtual class cl_cell *register_hw(t_addr addr, class cl_hw *hw, int *ith,
- bool announce);
+ bool announce);
virtual void set_brk(t_addr addr, class cl_brk *brk);
virtual void del_brk(t_addr addr, class cl_brk *brk);
{
public:
t_mem data;
- TYPE_UBYTE type; // See CELL_XXXX
+ TYPE_UBYTE type; // See CELL_XXXX
//protected:
public:
* Simulator of microcontrollers (sim.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
//arguments= new cl_list(2, 2);
//accept_args= more_args?strdup(more_args):0;
gui= new cl_gui(this);
+
+ state = SIM_QUIT;
+ argc = 0;
+ argv = 0;
}
int
int done= 0;
while (!done &&
- (state & SIM_QUIT) == 0)
+ (state & SIM_QUIT) == 0)
{
if (state & SIM_GO)
- {
- uc->do_inst(-1);
- if (app->get_commander()->input_avail())
- {
- done= app->get_commander()->proc_input();
- }
- }
+ {
+ uc->do_inst(-1);
+ if (app->get_commander()->input_avail())
+ {
+ done= app->get_commander()->proc_input();
+ }
+ }
else
- {
- app->get_commander()->wait_input();
- done= app->get_commander()->proc_input();
- }
+ {
+ app->get_commander()->wait_input();
+ done= app->get_commander()->proc_input();
+ }
}
return(0);
}
}
/*int
-cl_sim::do_cmd(char *cmdstr, class cl_console *console)
+cl_sim::do_cmd(char *cmdstr, class cl_console_base *console)
{
class cl_cmdline *cmdline;
class cl_cmd *cm;
}*/
void
-cl_sim::start(class cl_console *con)
+cl_sim::start(class cl_console_base *con)
{
state|= SIM_GO;
con->flags|= CONS_FROZEN;
void
cl_sim::stop(int reason)
{
- class cl_commander *cmd= app->get_commander();
+ class cl_commander_base *cmd= app->get_commander();
state&= ~SIM_GO;
if (cmd->frozen_console)
{
if (reason == resUSER &&
- cmd->frozen_console->input_avail())
- cmd->frozen_console->read_line();
+ cmd->frozen_console->input_avail())
+ cmd->frozen_console->read_line();
cmd->frozen_console->dd_printf("Stop at 0x%06x: (%d) ", uc->PC, reason);
switch (reason)
- {
- case resHALT:
- cmd->frozen_console->dd_printf("Halted\n");
- break;
- case resINV_ADDR:
- cmd->frozen_console->dd_printf("Invalid address\n");
- break;
- case resSTACK_OV:
- cmd->frozen_console->dd_printf("Stack overflow\n");
- break;
- case resBREAKPOINT:
- cmd->frozen_console->dd_printf("Breakpoint\n");
- uc->print_regs(cmd->frozen_console);
- break;
- case resINTERRUPT:
- cmd->frozen_console->dd_printf("Interrupt\n");
- break;
- case resWDTRESET:
- cmd->frozen_console->dd_printf("Watchdog reset\n");
- break;
- case resUSER:
- cmd->frozen_console->dd_printf("User stopped\n");
- break;
- case resINV_INST:
- {
- cmd->frozen_console->dd_printf("Invalid instruction");
- if (uc->rom)
- cmd->frozen_console->dd_printf(" 0x%04x\n",
- uc->rom->get(uc->PC));
- }
+ {
+ case resHALT:
+ cmd->frozen_console->dd_printf("Halted\n");
+ break;
+ case resINV_ADDR:
+ cmd->frozen_console->dd_printf("Invalid address\n");
+ break;
+ case resSTACK_OV:
+ cmd->frozen_console->dd_printf("Stack overflow\n");
+ break;
+ case resBREAKPOINT:
+ cmd->frozen_console->dd_printf("Breakpoint\n");
+ uc->print_regs(cmd->frozen_console);
+ break;
+ case resINTERRUPT:
+ cmd->frozen_console->dd_printf("Interrupt\n");
+ break;
+ case resWDTRESET:
+ cmd->frozen_console->dd_printf("Watchdog reset\n");
+ break;
+ case resUSER:
+ cmd->frozen_console->dd_printf("User stopped\n");
+ break;
+ case resINV_INST:
+ {
+ cmd->frozen_console->dd_printf("Invalid instruction");
+ if (uc->rom)
+ cmd->frozen_console->dd_printf(" 0x%04x\n",
+ uc->rom->get(uc->PC));
+ }
break;
- case resERROR:
- // uc::check_error prints error messages...
- break;
- default:
- cmd->frozen_console->dd_printf("Unknown reason\n");
- break;
- }
+ case resERROR:
+ // uc::check_error prints error messages...
+ break;
+ default:
+ cmd->frozen_console->dd_printf("Unknown reason\n");
+ break;
+ }
cmd->frozen_console->dd_printf("F 0x%06x\n", uc->PC); // for sdcdb
//if (cmd->actual_console != cmd->frozen_console)
cmd->frozen_console->flags&= ~CONS_FROZEN;
void
cl_sim::stop(class cl_ev_brk *brk)
{
- class cl_commander *cmd= app->get_commander();
+ class cl_commander_base *cmd= app->get_commander();
state&= ~SIM_GO;
if (cmd->frozen_console)
{
- class cl_console *con= cmd->frozen_console;
+ class cl_console_base *con= cmd->frozen_console;
/*
if (reason == resUSER &&
- cmd->frozen_console->input_avail())
- cmd->frozen_console->read_line();
+ cmd->frozen_console->input_avail())
+ cmd->frozen_console->read_line();
*/
//con->dd_printf("Stop at 0x%06x\n", uc->PC);
con->dd_printf("Event `%s' at %s[0x%"_A_"x]: 0x%"_A_"x %s\n",
- brk->id, brk->get_mem()->get_name(), brk->addr,
- uc->instPC,
- uc->disass(uc->instPC, " "));
+ brk->id, brk->get_mem()->get_name(), brk->addr,
+ uc->instPC,
+ uc->disass(uc->instPC, " "));
//con->flags&= ~CONS_FROZEN;
//con->print_prompt();
//cmd->frozen_console= 0;
{
cset= new cl_cmdset();
cset->init();
- cset->add(cmd= new cl_gui_start_cmd("start", 0,
+ cset->add(cmd= new cl_gui_start_cmd("start", 0,
"gui start Start interfacing with GUI tool",
"long help of gui start"));
cmd->init();
- cset->add(cmd= new cl_gui_stop_cmd("stop", 0,
+ cset->add(cmd= new cl_gui_stop_cmd("stop", 0,
"gui stop Stop interfacing with GUI tool",
"long help of gui stop"));
cmd->init();
int state; // See SIM_XXXX
int argc; char **argv;
- //class cl_commander *cmd;
+ //class cl_commander_base *cmd;
class cl_uc *uc;
class cl_gui *gui;
//virtual void mem_cell_changed(class cl_address_space *m, t_addr addr);
virtual int main(void);
- virtual void start(class cl_console *con);
+ virtual void start(class cl_console_base *con);
virtual void stop(int reason);
virtual void stop(class cl_ev_brk *brk);
virtual int step(void);
static class cl_stack_error_registry stack_error_registry;
cl_stack_op::cl_stack_op(enum stack_op op,
- t_addr iPC,
- t_addr iSP_before, t_addr iSP_after):
+ t_addr iPC,
+ t_addr iSP_before, t_addr iSP_after):
cl_base()
{
operation= op;
}
void
-cl_stack_op::info_head(class cl_console *con)
+cl_stack_op::info_head(class cl_console_base *con)
{
con->dd_printf("OP SP before-after L DATA/ADDR INSTRUCTION\n");
}
void
-cl_stack_op::info(class cl_console *con, class cl_uc *uc)
+cl_stack_op::info(class cl_console_base *con, class cl_uc *uc)
{
con->dd_printf("%-4s 0x%06"_A_"x-0x%06"_A_"x %d ",
get_op_name(), SP_before, SP_after, abs(SP_before-SP_after));
}
void
-cl_stack_op::print_info(class cl_console *con)
+cl_stack_op::print_info(class cl_console_base *con)
{
con->dd_printf("-");
}
}
void
-cl_stack_call::print_info(class cl_console *con)
+cl_stack_call::print_info(class cl_console_base *con)
{
con->dd_printf("0x%06"_A_"x", called_addr);
}
}
void
-cl_stack_intr::print_info(class cl_console *con)
+cl_stack_intr::print_info(class cl_console_base *con)
{
con->dd_printf("0x%06"_A_"x", called_addr);
}
}
void
-cl_stack_push::print_info(class cl_console *con)
+cl_stack_push::print_info(class cl_console_base *con)
{
t_addr d= data;
con->dd_printf("0x%06"_A_"x", d);
}
void
-cl_error_stack_tracker_wrong_handle::print(class cl_commander *c)
+cl_error_stack_tracker_wrong_handle::print(class cl_commander_base *c)
{
c->dd_printf("%s: wrong stack tracker handle called for %s operation\n",
- get_type_name(), write_operation?"write":"read");
+ get_type_name(), write_operation?"write":"read");
}
/* Stack Tracker: operation on empty stack */
}
void
-cl_error_stack_tracker_empty::print(class cl_commander *c)
+cl_error_stack_tracker_empty::print(class cl_commander_base *c)
{
c->dd_printf("%s(0x%06"_A_"x: %s on empty stack, PC="
- "0x06"_A_"x, SP=0x%06"_A_"x->0x%06"_A_"x\n",
- get_type_name(), operation->get_pc(), operation->get_op_name(),
- operation->get_before(), operation->get_after());
+ "0x06"_A_"x, SP=0x%06"_A_"x->0x%06"_A_"x\n",
+ get_type_name(), operation->get_pc(), operation->get_op_name(),
+ operation->get_before(), operation->get_after());
}
/* Stack Tracker: operation on empty stack */
}
void
-cl_error_stack_tracker_unmatch::print(class cl_commander *c)
+cl_error_stack_tracker_unmatch::print(class cl_commander_base *c)
{
c->dd_printf("%s(0x%06"_A_"x): %s when %s expected, "
- "SP=0x%06"_A_"x->0x%06"_A_"x\n",
- get_type_name(), operation->get_pc(),
- operation->get_op_name(), top->get_matching_name(),
- operation->get_before(), operation->get_after());
+ "SP=0x%06"_A_"x->0x%06"_A_"x\n",
+ get_type_name(), operation->get_pc(),
+ operation->get_op_name(), top->get_matching_name(),
+ operation->get_before(), operation->get_after());
}
/* Stack Tracker: stack is inconsistent */
}
void
-cl_error_stack_tracker_inconsistent::print(class cl_commander *c)
+cl_error_stack_tracker_inconsistent::print(class cl_commander_base *c)
{
c->dd_printf("%s(0x%06"_A_"x): %d byte(s) unread from the stack\n",
- get_type_name(), operation->get_pc(),
- unread_data_size);
+ get_type_name(), operation->get_pc(),
+ unread_data_size);
}
cl_stack_error_registry::cl_stack_error_registry(void)
{
protected:
enum stack_op operation;
- t_addr PC; // of instruction
+ t_addr PC; // of instruction
t_addr SP_before;
t_addr SP_after;
public:
cl_stack_op(enum stack_op op,
- t_addr iPC, t_addr iSP_before, t_addr iSP_after);
+ t_addr iPC, t_addr iSP_before, t_addr iSP_after);
virtual ~cl_stack_op(void);
virtual class cl_stack_op *mk_copy(void);
- static void info_head(class cl_console *con);
- virtual void info(class cl_console *con, class cl_uc *uc);
+ static void info_head(class cl_console_base *con);
+ virtual void info(class cl_console_base *con, class cl_uc *uc);
protected:
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
public:
virtual char *get_op_name(void);
virtual char *get_matching_name(void) { return("unknown"); }
t_addr pushed_addr;
public:
cl_stack_call(t_addr iPC, t_addr called, t_addr pushed,
- t_addr iSP_before, t_addr iSP_after);
+ t_addr iSP_before, t_addr iSP_after);
virtual class cl_stack_op *mk_copy(void);
protected:
virtual char *get_op_name(void);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
public:
virtual char *get_matching_name(void);
virtual enum stack_op get_matching_op(void);
{
public:
cl_stack_intr(t_addr iPC, t_addr called, t_addr pushed,
- t_addr iSP_before, t_addr iSP_after);
+ t_addr iSP_before, t_addr iSP_after);
virtual class cl_stack_op *mk_copy(void);
protected:
virtual char *get_op_name(void);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
public:
virtual char *get_matching_name(void);
virtual enum stack_op get_matching_op(void);
virtual class cl_stack_op *mk_copy(void);
protected:
virtual char *get_op_name(void);
- virtual void print_info(class cl_console *con);
+ virtual void print_info(class cl_console_base *con);
public:
virtual char *get_matching_name(void);
virtual enum stack_op get_matching_op(void);
public:
cl_error_stack_tracker_wrong_handle(bool write_op);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_error_stack_tracker_empty: public cl_error_stack_tracker
cl_error_stack_tracker_empty(class cl_stack_op *op);
virtual ~cl_error_stack_tracker_empty(void);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker
class cl_stack_op *op);
virtual ~cl_error_stack_tracker_unmatch(void);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker
int unread_data_size;
public:
cl_error_stack_tracker_inconsistent(class cl_stack_op *op,
- int the_unread_data_size);
+ int the_unread_data_size);
virtual ~cl_error_stack_tracker_inconsistent(void);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_stack_error_registry: public cl_error_registry
while (go)
for (a= 0; go && a < mem->size; a++)
{
- t_mem d2;
- for (d2= 0; go && d2 <= 255; d2++)
- {
- d2= mem->write(a, d2);
- d= mem->read(a);
- if (d != d2)
- printf("%"_M_"d written to mem and %"_M_"d read back!\n", d2, d);
- counter+= 1;
- }
+ t_mem d2;
+ for (d2= 0; go && d2 <= 255; d2++)
+ {
+ d2= mem->write(a, d2);
+ d= mem->read(a);
+ if (d != d2)
+ printf("%"_M_"d written to mem and %"_M_"d read back!\n", d2, d);
+ counter+= 1;
+ }
}
return(counter);
}
int i;
class cl_mem *mem;
class cl_m *m2;
- class cl_console *con;
+ class cl_console_base *con;
signal(SIGALRM, alarmed);
- con= new cl_console(stdin, stdout, 0);
+ con= new cl_console_base(stdin, stdout, 0);
mem= new cl_mem(MEM_SFR, "egy", 0x10000, 8, 0);
mem->init();
printf("%g operations on classic memory within 5 sec\n",
- do_rw_test(mem, 5));
+ do_rw_test(mem, 5));
//mem->dump(con);
m2= new cl_m(MEM_TYPES, "test", 0x10000, 8, 0);
m2->init();
printf("%g operations on new memory within 5 sec\n",
- do_rw_test(m2, 5));
+ do_rw_test(m2, 5));
class cl_hw_test *hw= new cl_hw_test();
for (i= 0; i < 0x10000; i++)
class cl_cell *c= m2->get_cell(i);
int dummy;
if (c)
- c->add_hw(hw, &dummy);
+ c->add_hw(hw, &dummy);
}
printf("%g operations on new memory within 5 sec with hw read\n",
- do_rw_test(m2, 5));
+ do_rw_test(m2, 5));
//m2->dump(con);
return(0);
}
void
-cl_ticker::dump(int nr, double xtal, class cl_console *con)
+cl_ticker::dump(int nr, double xtal, class cl_console_base *con)
{
con->dd_printf("timer #%d(\"%s\") %s%s: %g sec (%lu clks)\n",
nr, get_name("unnamed"),
}
void
-cl_uc::print_disass(t_addr addr, class cl_console *con)
+cl_uc::print_disass(t_addr addr, class cl_console_base *con)
{
char *dis;
class cl_brk *b;
}
void
-cl_uc::print_regs(class cl_console *con)
+cl_uc::print_regs(class cl_console_base *con)
{
con->dd_printf("No registers\n");
}
cl_uc::check_errors(void)
{
int i;
- class cl_commander *c= sim->app->get_commander();
+ class cl_commander_base *c= sim->app->get_commander();
bool must_stop= DD_FALSE;
if (c)
must_stop= must_stop || (error->get_type() & err_stop);
if (error->inst)
{
- class cl_console *con;
+ class cl_console_base *con;
con= c->actual_console;
if (!con)
con= c->frozen_console;
}
void
-cl_error_unknown_code::print(class cl_commander *c)
+cl_error_unknown_code::print(class cl_commander_base *c)
{
c->dd_printf("%s: unknown instruction code at ", get_type_name());
if (uc->rom)
/* Counter to count clock ticks */
-#define TICK_RUN 0x01
-#define TICK_INISR 0x02
-#define TICK_IDLE 0x03
+#define TICK_RUN 0x01
+#define TICK_INISR 0x02
+#define TICK_IDLE 0x03
class cl_ticker: public cl_base
{
virtual int tick(int nr);
virtual double get_rtime(double xtal);
- virtual void dump(int nr, double xtal, class cl_console *con);
+ virtual void dump(int nr, double xtal, class cl_console_base *con);
};
class cl_uc: public cl_base
{
public:
- int type; // CPU family
- int technology; // CMOS, HMOS
- int state; // GO, IDLE, PD
+ int type; // CPU family
+ int technology; // CMOS, HMOS
+ int state; // GO, IDLE, PD
//class cl_list *options;
class cl_xtal_option *xtal_option;
- t_addr PC, instPC; // Program Counter
- bool inst_exec; // Instruction is executed
- class cl_ticker *ticks; // Nr of XTAL clocks
- class cl_ticker *isr_ticks; // Time in ISRs
- class cl_ticker *idle_ticks; // Time in idle mode
- class cl_list *counters; // User definable timers (tickers)
- int inst_ticks; // ticks of an instruction
- double xtal; // Clock speed
-
- int brk_counter; // Number of breakpoints
- class brk_coll *fbrk; // Collection of FETCH break-points
- class brk_coll *ebrk; // Collection of EVENT breakpoints
+ t_addr PC, instPC; // Program Counter
+ bool inst_exec; // Instruction is executed
+ class cl_ticker *ticks; // Nr of XTAL clocks
+ class cl_ticker *isr_ticks; // Time in ISRs
+ class cl_ticker *idle_ticks; // Time in idle mode
+ class cl_list *counters; // User definable timers (tickers)
+ int inst_ticks; // ticks of an instruction
+ double xtal; // Clock speed
+
+ int brk_counter; // Number of breakpoints
+ class brk_coll *fbrk; // Collection of FETCH break-points
+ class brk_coll *ebrk; // Collection of EVENT breakpoints
class cl_sim *sim;
//class cl_list *mems;
class cl_hws *hws;
- class cl_list *memchips; // v3
+ class cl_list *memchips; // v3
class cl_address_space_list *address_spaces;
- class cl_address_space *rom; // Required for almost every uc
+ class cl_address_space *rom; // Required for almost every uc
//class cl_list *address_decoders;
- class cl_irqs *it_sources; // Sources of interrupts
- class cl_list *it_levels; // Follow interrupt services
- class cl_list *stack_ops; // Track stack operations
+ class cl_irqs *it_sources; // Sources of interrupts
+ class cl_list *it_levels; // Follow interrupt services
+ class cl_list *stack_ops; // Track stack operations
- class cl_list *errors; // Errors of instruction execution
- class cl_list *events; // Events happened during inst exec
+ class cl_list *errors; // Errors of instruction execution
+ class cl_list *events; // Events happened during inst exec
t_addr sp_max;
t_addr sp_avg;
virtual void remove_all_breaks(void);
virtual int make_new_brknr(void);
virtual class cl_ev_brk *mk_ebrk(enum brk_perm perm,
- class cl_address_space *mem,
- char op, t_addr addr, int hit);
+ class cl_address_space *mem,
+ char op, t_addr addr, int hit);
virtual void check_events(void);
// disassembling and symbol recognition
virtual struct dis_entry *dis_tbl(void);
virtual struct name_entry *sfr_tbl(void);
virtual struct name_entry *bit_tbl(void);
- virtual void print_disass(t_addr addr, class cl_console *con);
- virtual void print_regs(class cl_console *con);
+ virtual void print_disass(t_addr addr, class cl_console_base *con);
+ virtual void print_regs(class cl_console_base *con);
virtual int inst_length(t_addr addr);
virtual int inst_branch(t_addr addr);
virtual int longest_inst(void);
virtual bool get_name(t_addr addr, struct name_entry tab[], char *buf);
virtual bool symbol2address(char *sym, struct name_entry tab[],
- t_addr *addr);
+ t_addr *addr);
virtual char *symbolic_bit_name(t_addr bit_address,
- class cl_memory *mem,
- t_addr mem_addr,
- t_mem bit_mask);
+ class cl_memory *mem,
+ t_addr mem_addr,
+ t_mem bit_mask);
/* Converting abstract address spaces into real ones */
virtual class cl_address_space *bit2mem(t_addr bitaddr,
- t_addr *memaddr,
- t_mem *bitmask);
+ t_addr *memaddr,
+ t_mem *bitmask);
virtual t_addr bit_address(class cl_memory *mem,
- t_addr mem_address,
- int bit_number) { return(-1); }
+ t_addr mem_address,
+ int bit_number) { return(-1); }
// messages from app to handle and broadcast
virtual bool handle_event(class cl_event &event);
public:
cl_error_unknown_code(class cl_uc *the_uc);
- virtual void print(class cl_commander *c);
+ virtual void print(class cl_commander_base *c);
};
class cl_uc_error_registry: public cl_error_registry
* Simulator of microcontrollers (utils.cc)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
*valuep= 0;
i= 0;
while (tokens[i] &&
- strcmp(*option, tokens[i]))
+ strcmp(*option, tokens[i]))
i++;
if (!tokens[i])
*valuep= *option;
{
int i= 0;
- while (ids[i].id_string &&
- id != ids[i].id)
+ while (ids[i].id_string && id != ids[i].id)
i++;
return(ids[i].id_string);
}
{
int i= 0;
- while (ids[i].id_string &&
- strcmp(ids[i].id_string, str) != 0)
+ while (ids[i].id_string && strcmp(ids[i].id_string, str) != 0)
i++;
return(ids[i].id);
}
{
int i= 0;
- while (ids[i].id_string &&
- strcmp(ids[i].id_string, str) != 0)
+ while (ids[i].id_string && strcmp(ids[i].id_string, str) != 0)
i++;
return(ids[i].id_string?ids[i].id:def);
}
extern "C" int vasprintf(char **strp, const char *format, va_list ap);
extern "C" int vsnprintf(char *str, size_t size,const char *format,va_list ap);
-static char *
-vformat_string(char *format, va_list ap)
+char *
+format_string(char *format, ...)
{
+ va_list ap;
+
+ va_start(ap, format);
#ifdef HAVE_VASPRINTF
char *msg= NULL;
vasprintf(&msg, format, ap);
return(msg);
-#else
-# ifdef HAVE_VSNPRINTF
+#elif defined HAVE_VSNPRINTF
char *msg= (char*)malloc(80*25);
vsnprintf(msg, 80*25, format, ap);
return(msg);
-# else
-# ifdef HAVE_VPRINTF
+#elif defined HAVE__VSNPRINTF
char *msg= (char*)malloc(80*25);
- vsprintf(msg, format, ap); /* Dangerous */
+ _vsnprintf(msg, 80*25, format, ap);
return(msg);
-# endif
-# endif
+#else
+#error No vasprintf or vsnprintf
#endif
-}
-
-char *
-format_string(char *format, ...)
-{
- va_list ap;
-
- va_start(ap, format);
- char *s= vformat_string(format, ap);
va_end(ap);
- return(s);
-}
-
-
-void
-print_char_octal(char c, FILE *f)
-{
- if (strchr("\a\b\f\n\r\t\v\"", c))
- switch (c)
- {
- case '\a': fprintf(f, "\a"); break;
- case '\b': fprintf(f, "\b"); break;
- case '\f': fprintf(f, "\f"); break;
- case '\n': fprintf(f, "\n"); break;
- case '\r': fprintf(f, "\r"); break;
- case '\t': fprintf(f, "\t"); break;
- case '\v': fprintf(f, "\v"); break;
- case '\"': fprintf(f, "\""); break;
- }
- else if (isprint(c))
- fprintf(f, "%c", c);
- else
- fprintf(f, "\\%03hho", c);
+ return(msg);
}
if (o)
name= o->get_name();
- if (name &&
- *name)
+ if (name && *name)
return(name);
return("(unkown)");
}
switch (lcase)
{
case case_upper:
- while (p && *p) {
- *p= toupper(*p);
- p++;
- }
+ while (p && *p)
+ {
+ *p= toupper(*p);
+ p++;
+ }
break;
case case_lower:
- while (p && *p) {
- *p= tolower(*p);
- p++;
- }
+ while (p && *p)
+ {
+ *p= tolower(*p);
+ p++;
+ }
break;
case case_case:
if (!p || *p == '\0')
- break;
- while (isspace(*p)) p++;
+ break;
+ while (isspace(*p))
+ p++;
if (*p)
- *p= toupper(*p);
+ *p= toupper(*p);
break;
}
return(s);
* Simulator of microcontrollers (utils.h)
*
* Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
- *
+ *
* To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
*
*/
#include "stypes.h"
-extern int get_sub_opt(char **option,
- const char * const *tokens,
- char **valuep);
+//#define TRACE printf
+#define TRACE 1 ? (void)0 : (*(void (*)(const char *, ...))0)
+
+
+extern int get_sub_opt(char **option, const char * const *tokens, char **valuep);
extern char *get_id_string(struct id_element *ids, int id);
extern char *get_id_string(struct id_element *ids, int id, char *def);
extern int get_string_id(struct id_element *ids, char *str);
extern int get_string_id(struct id_element *ids, char *str, int def);
extern char *format_string(char *format, ...);
-extern void print_char_octal(char c, FILE *f);
extern char *object_name(class cl_base *o);
extern char *case_string(enum letter_case lcase, char *str);
case DIRECT_REG :
sprintf(parm_str, "%s,%s",
get_dir_name(((code & 0x7) << 8) |
- get_mem(MEM_ROM_ID, addr+immed_offset)),
+ get_mem(MEM_ROM_ID, addr+immed_offset)),
reg_strs[((code >> 4) & 0xf)] );
++immed_offset;
break;
case REG_DIRECT :
sprintf(parm_str, "%s,%s",
- reg_strs[((code >> 4) & 0xf)],
+ reg_strs[((code >> 4) & 0xf)],
get_dir_name(((code & 0x7) << 8) |
- get_mem(MEM_ROM_ID, addr+immed_offset)));
+ get_mem(MEM_ROM_ID, addr+immed_offset)));
++immed_offset;
break;
case REG_DATA8 :
case DIRECT_DATA8 :
sprintf(parm_str, "%s,#0x%02x",
get_dir_name(((code & 0x0070) << 4) |
- get_mem(MEM_ROM_ID, addr+immed_offset)),
+ get_mem(MEM_ROM_ID, addr+immed_offset)),
get_mem(MEM_ROM_ID, addr+immed_offset+1));
immed_offset += 3;
break;
case DIRECT_DATA16 :
sprintf(parm_str, "%s,#0x%04x",
get_dir_name(((code & 0x0070) << 4) |
- get_mem(MEM_ROM_ID, addr+immed_offset)),
+ get_mem(MEM_ROM_ID, addr+immed_offset)),
get_mem(MEM_ROM_ID, addr+immed_offset+2) +
- (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8));
+ (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8));
immed_offset += 3;
break;
break;
case CY_BIT :
sprintf(parm_str, "C,%s",
- get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2)));
+ get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2)));
break;
case BIT_CY :
sprintf(parm_str, "%s,C",
- get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2)));
+ get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2)));
break;
case REG_DATA4 :
strcpy(parm_str, "REG_DATA4");
break;
case DIRECT_DATA4 :
sprintf(parm_str, "%s,#0x%x",
- get_dir_name(((code & 0x70)<<4) |
- get_mem(MEM_ROM_ID, addr+2)),
- code&0x0f);
+ get_dir_name(((code & 0x70)<<4) |
+ get_mem(MEM_ROM_ID, addr+2)),
+ code&0x0f);
break;
case DIRECT :
sprintf(parm_str, "%s",
- get_dir_name(((code & 0x007) << 4) +
- get_mem(MEM_ROM_ID, addr+2)));
+ get_dir_name(((code & 0x007) << 4) +
+ get_mem(MEM_ROM_ID, addr+2)));
break;
case REG :
sprintf(parm_str, "%s",
break;
case BIT_ALONE :
sprintf(parm_str, "%s",
- get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2)));
+ get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2)));
break;
case BIT_REL8 :
sprintf(parm_str, "%s,0x%04x",
- get_bit_name((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2),
- ((signed char)get_mem(MEM_ROM_ID, addr+3)*2+addr+len)&0xfffe);
+ get_bit_name((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2),
+ ((signed char)get_mem(MEM_ROM_ID, addr+3)*2+addr+len)&0xfffe);
break;
case DATA4:
sprintf(parm_str, "#0x%02x", code&0x0f);
break;
case ADDR24 :
sprintf(parm_str, "0x%06x",
- (get_mem(MEM_ROM_ID, addr+3)<<16) +
- (get_mem(MEM_ROM_ID, addr+1)<<8) +
- get_mem(MEM_ROM_ID, addr+2));
+ (get_mem(MEM_ROM_ID, addr+3)<<16) +
+ (get_mem(MEM_ROM_ID, addr+1)<<8) +
+ get_mem(MEM_ROM_ID, addr+2));
break;
break;
case REG_REL8 :
sprintf(parm_str, "%s,0x%04x",
- reg_strs[(code>>4) & 0xf],
- ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe);
+ reg_strs[(code>>4) & 0xf],
+ ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe);
break;
case DIRECT_REL8 :
sprintf(parm_str, "%s,0x%04x",
- get_dir_name(((code&0x07)<<8) +
- get_mem(MEM_ROM_ID, addr+2)),
- ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe);
+ get_dir_name(((code&0x07)<<8) +
+ get_mem(MEM_ROM_ID, addr+2)),
+ ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe);
break;
case REG_USP:
sprintf(parm_str, "REG_USP");
break;
case REL8 :
sprintf(parm_str, "0x%04x",
- ((signed char)get_mem(MEM_ROM_ID, addr+1)*2+addr+len)&0xfffe);
+ ((signed char)get_mem(MEM_ROM_ID, addr+1)*2+addr+len)&0xfffe);
break;
case REL16 :
sprintf(parm_str, "0x%04x",
- ((signed short)((get_mem(MEM_ROM_ID, addr+1)<<8) + get_mem(MEM_ROM_ID, addr+2))*2+addr+len)&0xfffe);
+ ((signed short)((get_mem(MEM_ROM_ID, addr+1)<<8) + get_mem(MEM_ROM_ID, addr+2))*2+addr+len)&0xfffe);
break;
case RLIST : {
/* TODO: the list should be comma reperated
- and maybe for POP the list should be reversed */
+ and maybe for POP the list should be reversed */
unsigned char rlist=code&0xff;
parm_str[0]='\0';
if (code&0x0800) { // word list
- if (code&0x4000) { // R8-R15
- if (rlist&0x80) strcat (parm_str, "R15 ");
- if (rlist&0x40) strcat (parm_str, "R14");
- if (rlist&0x20) strcat (parm_str, "R13 ");
- if (rlist&0x10) strcat (parm_str, "R12 ");
- if (rlist&0x08) strcat (parm_str, "R11 ");
- if (rlist&0x04) strcat (parm_str, "R10 ");
- if (rlist&0x02) strcat (parm_str, "R9 ");
- if (rlist&0x01) strcat (parm_str, "R8 ");
- } else { // R7-R0
- if (rlist&0x80) strcat (parm_str, "R7 ");
- if (rlist&0x40) strcat (parm_str, "R6 ");
- if (rlist&0x20) strcat (parm_str, "R5 ");
- if (rlist&0x10) strcat (parm_str, "R4 ");
- if (rlist&0x08) strcat (parm_str, "R3 ");
- if (rlist&0x04) strcat (parm_str, "R2 ");
- if (rlist&0x02) strcat (parm_str, "R1 ");
- if (rlist&0x01) strcat (parm_str, "R0 ");
- }
+ if (code&0x4000) { // R8-R15
+ if (rlist&0x80) strcat (parm_str, "R15 ");
+ if (rlist&0x40) strcat (parm_str, "R14");
+ if (rlist&0x20) strcat (parm_str, "R13 ");
+ if (rlist&0x10) strcat (parm_str, "R12 ");
+ if (rlist&0x08) strcat (parm_str, "R11 ");
+ if (rlist&0x04) strcat (parm_str, "R10 ");
+ if (rlist&0x02) strcat (parm_str, "R9 ");
+ if (rlist&0x01) strcat (parm_str, "R8 ");
+ } else { // R7-R0
+ if (rlist&0x80) strcat (parm_str, "R7 ");
+ if (rlist&0x40) strcat (parm_str, "R6 ");
+ if (rlist&0x20) strcat (parm_str, "R5 ");
+ if (rlist&0x10) strcat (parm_str, "R4 ");
+ if (rlist&0x08) strcat (parm_str, "R3 ");
+ if (rlist&0x04) strcat (parm_str, "R2 ");
+ if (rlist&0x02) strcat (parm_str, "R1 ");
+ if (rlist&0x01) strcat (parm_str, "R0 ");
+ }
} else { // byte list
- if (code&0x4000) { //R7h-R4l
- if (rlist&0x80) strcat (parm_str, "R7h ");
- if (rlist&0x40) strcat (parm_str, "R7l ");
- if (rlist&0x20) strcat (parm_str, "R6h ");
- if (rlist&0x10) strcat (parm_str, "R6l ");
- if (rlist&0x08) strcat (parm_str, "R5h ");
- if (rlist&0x04) strcat (parm_str, "R5l ");
- if (rlist&0x02) strcat (parm_str, "R4h ");
- if (rlist&0x01) strcat (parm_str, "R4l ");
- } else { // R3h-R0l
- if (rlist&0x80) strcat (parm_str, "R3h ");
- if (rlist&0x40) strcat (parm_str, "R3l ");
- if (rlist&0x20) strcat (parm_str, "R2h ");
- if (rlist&0x10) strcat (parm_str, "R2l ");
- if (rlist&0x08) strcat (parm_str, "R1h ");
- if (rlist&0x04) strcat (parm_str, "R1l ");
- if (rlist&0x02) strcat (parm_str, "R0h ");
- if (rlist&0x01) strcat (parm_str, "R0l ");
- }
+ if (code&0x4000) { //R7h-R4l
+ if (rlist&0x80) strcat (parm_str, "R7h ");
+ if (rlist&0x40) strcat (parm_str, "R7l ");
+ if (rlist&0x20) strcat (parm_str, "R6h ");
+ if (rlist&0x10) strcat (parm_str, "R6l ");
+ if (rlist&0x08) strcat (parm_str, "R5h ");
+ if (rlist&0x04) strcat (parm_str, "R5l ");
+ if (rlist&0x02) strcat (parm_str, "R4h ");
+ if (rlist&0x01) strcat (parm_str, "R4l ");
+ } else { // R3h-R0l
+ if (rlist&0x80) strcat (parm_str, "R3h ");
+ if (rlist&0x40) strcat (parm_str, "R3l ");
+ if (rlist&0x20) strcat (parm_str, "R2h ");
+ if (rlist&0x10) strcat (parm_str, "R2l ");
+ if (rlist&0x08) strcat (parm_str, "R1h ");
+ if (rlist&0x04) strcat (parm_str, "R1l ");
+ if (rlist&0x02) strcat (parm_str, "R0h ");
+ if (rlist&0x01) strcat (parm_str, "R0l ");
+ }
}
}
break;
sprintf(parm_str, "%s,%s,0x%02x",
reg_strs[((code >> 4) & 0xf)],
get_dir_name(((code & 0x7) << 8) +
- get_mem(MEM_ROM_ID, addr+immed_offset)),
+ get_mem(MEM_ROM_ID, addr+immed_offset)),
((signed char) get_mem(MEM_ROM_ID, addr+immed_offset+1) * 2) & 0xfffe );
break;
case REG_DATA8_REL8 :
sprintf(parm_str, "[%s],#0x%04x,0x%02x",
w_reg_strs[(code >> 4) & 0x7],
get_mem(MEM_ROM_ID, addr+immed_offset+2) +
- (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8),
+ (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8),
((signed char)get_mem(MEM_ROM_ID, addr+immed_offset) * 2) & 0xfffe );
break;
case REG_REGOFF8 :
sprintf(parm_str, "%s,%s+0x%02x",
- w_reg_strs[(code >> 4) & 0x7],
- w_reg_strs[code & 0x7],
- get_mem(MEM_ROM_ID, addr+immed_offset));
+ w_reg_strs[(code >> 4) & 0x7],
+ w_reg_strs[code & 0x7],
+ get_mem(MEM_ROM_ID, addr+immed_offset));
break;
case REG_REGOFF16 :
sprintf(parm_str, "%s,%s+0x%02x",
- w_reg_strs[(code >> 4) & 0x7],
- w_reg_strs[code & 0x7],
- get_mem(MEM_ROM_ID, addr+immed_offset+1) +
- (get_mem(MEM_ROM_ID, addr+immed_offset+0)<<8));
+ w_reg_strs[(code >> 4) & 0x7],
+ w_reg_strs[code & 0x7],
+ get_mem(MEM_ROM_ID, addr+immed_offset+1) +
+ (get_mem(MEM_ROM_ID, addr+immed_offset+0)<<8));
break;
case A_PLUSDPTR :
Used to print a status line while stepping through the code.
|--------------------------------------------------------------------*/
void
-cl_xa::print_regs(class cl_console *con)
+cl_xa::print_regs(class cl_console_base *con)
{
unsigned char flags;
int *mnemonic);
virtual char *disass(t_addr addr, char *sep);
- virtual void print_regs(class cl_console *con);
+ virtual void print_regs(class cl_console_base *con);
virtual int exec_inst(void);
virtual int get_reg(int word_flag, unsigned int index);
while (*b)
{
if (*b == '%')
- {
- b++;
- switch (*(b++))
- {
- case 'd': // d jump relative target, signed? byte immediate operand
- sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- case 'w': // w word immediate operand
- sprintf(temp, "#0x%04x",
- (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)) |
- (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8)) );
- ++immed_offset;
- ++immed_offset;
- break;
- case 'b': // b byte immediate operand
- sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
- ++immed_offset;
- break;
- default:
- strcpy(temp, "?");
- break;
- }
- t= temp;
- while (*t)
- *(p++)= *(t++);
- }
+ {
+ b++;
+ switch (*(b++))
+ {
+ case 'd': // d jump relative target, signed? byte immediate operand
+ sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset));
+ ++immed_offset;
+ break;
+ case 'w': // w word immediate operand
+ sprintf(temp, "#0x%04x",
+ (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)) |
+ (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8)) );
+ ++immed_offset;
+ ++immed_offset;
+ break;
+ case 'b': // b byte immediate operand
+ sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset));
+ ++immed_offset;
+ break;
+ default:
+ strcpy(temp, "?");
+ break;
+ }
+ t= temp;
+ while (*t)
+ *(p++)= *(t++);
+ }
else
- *(p++)= *(b++);
+ *(p++)= *(b++);
}
*p= '\0';
if (sep == NULL)
{
while (strlen(buf) < 6)
- strcat(buf, " ");
+ strcat(buf, " ");
}
else
strcat(buf, sep);
void
-cl_z80::print_regs(class cl_console *con)
+cl_z80::print_regs(class cl_console_base *con)
{
con->dd_printf("SZ-A--P-C Flags= 0x%02x %3d %c ",
- regs.F, regs.F, isprint(regs.F)?regs.F:'.');
+ regs.F, regs.F, isprint(regs.F)?regs.F:'.');
con->dd_printf("A= 0x%02x %3d %c\n",
- regs.A, regs.A, isprint(regs.A)?regs.A:'.');
+ regs.A, regs.A, isprint(regs.A)?regs.A:'.');
con->dd_printf("%c%c-%c--%c-%c\n",
- (regs.F&BIT_S)?'1':'0',
- (regs.F&BIT_Z)?'1':'0',
- (regs.F&BIT_A)?'1':'0',
- (regs.F&BIT_P)?'1':'0',
- (regs.F&BIT_C)?'1':'0');
+ (regs.F&BIT_S)?'1':'0',
+ (regs.F&BIT_Z)?'1':'0',
+ (regs.F&BIT_A)?'1':'0',
+ (regs.F&BIT_P)?'1':'0',
+ (regs.F&BIT_C)?'1':'0');
con->dd_printf("BC= 0x%04x [BC]= %02x %3d %c ",
- regs.BC, ram->get(regs.BC), ram->get(regs.BC),
- isprint(ram->get(regs.BC))?ram->get(regs.BC):'.');
+ regs.BC, ram->get(regs.BC), ram->get(regs.BC),
+ isprint(ram->get(regs.BC))?ram->get(regs.BC):'.');
con->dd_printf("DE= 0x%04x [DE]= %02x %3d %c ",
- regs.DE, ram->get(regs.DE), ram->get(regs.DE),
- isprint(ram->get(regs.DE))?ram->get(regs.DE):'.');
+ regs.DE, ram->get(regs.DE), ram->get(regs.DE),
+ isprint(ram->get(regs.DE))?ram->get(regs.DE):'.');
con->dd_printf("HL= 0x%04x [HL]= %02x %3d %c\n",
- regs.HL, ram->get(regs.HL), ram->get(regs.HL),
- isprint(ram->get(regs.HL))?ram->get(regs.HL):'.');
+ regs.HL, ram->get(regs.HL), ram->get(regs.HL),
+ isprint(ram->get(regs.HL))?ram->get(regs.HL):'.');
con->dd_printf("IX= 0x%04x [IX]= %02x %3d %c ",
- regs.IX, ram->get(regs.IX), ram->get(regs.IX),
- isprint(ram->get(regs.IX))?ram->get(regs.IX):'.');
+ regs.IX, ram->get(regs.IX), ram->get(regs.IX),
+ isprint(ram->get(regs.IX))?ram->get(regs.IX):'.');
con->dd_printf("IY= 0x%04x [IY]= %02x %3d %c ",
- regs.IY, ram->get(regs.IY), ram->get(regs.IY),
- isprint(ram->get(regs.IY))?ram->get(regs.IY):'.');
+ regs.IY, ram->get(regs.IY), ram->get(regs.IY),
+ isprint(ram->get(regs.IY))?ram->get(regs.IY):'.');
con->dd_printf("SP= 0x%04x [SP]= %02x %3d %c\n",
- regs.SP, ram->get(regs.SP), ram->get(regs.SP),
- isprint(ram->get(regs.SP))?ram->get(regs.SP):'.');
+ regs.SP, ram->get(regs.SP), ram->get(regs.SP),
+ isprint(ram->get(regs.SP))?ram->get(regs.SP):'.');
print_disass(PC, con);
}
virtual int inst_branch(t_addr addr);
virtual int longest_inst(void);
virtual char *disass(t_addr addr, char *sep);
- virtual void print_regs(class cl_console *con);
+ virtual void print_regs(class cl_console_base *con);
virtual int exec_inst(void);