[ucsim] Intro -U, -u options and configurable NL in UART display
[sdcc.git] / sdcc / sim / ucsim / src / apps / ucsim.src / ucsim.cc
blobda85e698e06645c780e78e1a06d93b1b06da5126
1 /*
2 * Simulator of microcontrollers (ucsim.cc)
4 * Copyright (C) 1997 Drotos Daniel
5 *
6 * To contact author send email to dr.dkdb@gmail.com
8 */
10 /* This file is part of microcontroller simulator: ucsim.
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING. If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
28 // prj
29 #include "globals.h"
30 #include "appcl.h"
32 #include "charscl.h"
34 class cl_general_uc: public cl_uc
36 public:
37 u8_t r;
38 public:
39 cl_general_uc(cl_sim *s): cl_uc(s) {}
40 virtual void make_memories(void);
41 virtual int exec_inst()
43 t_mem code;
44 if (fetch(&code))
45 return resBREAKPOINT;
46 tick(1);
47 r= rom->read(PC);
48 vc.rd++;
49 rom->write(PC, r+1);
50 vc.wr++;
51 r= 34;
52 return resGO;
56 void
57 cl_general_uc::make_memories(void)
59 class cl_address_space *as;
60 class cl_memory_chip *ch;
61 class cl_address_decoder *ad;
63 rom= as= new cl_address_space("nas", 0, 0x100000, 8);
64 as->init();
65 address_spaces->add(as);
67 ch= new cl_chip8("chip", 0x100000, 8/*, 0*/);
68 ch->init();
69 memchips->add(ch);
71 ad= new cl_address_decoder(as, ch, 0, 0x100000-1, 0);
72 ad->init();
73 as->decoders->add(ad);
74 ad->activate(0);
77 class cl_general_sim: public cl_sim
79 public:
80 cl_general_sim(cl_app *a): cl_sim(a) {}
81 virtual class cl_uc *mk_controller(void)
83 class cl_uc *uc= new cl_general_uc(this);
84 return uc;
88 int
89 main(int argc, char *argv[])
91 int ret;
92 class cl_sim *sim;
93 volatile double fd, id;
94 unsigned int i= 0;
96 app_start_at= dnow();
98 fd= 0;
99 while (++i < 100000000) fd+= 1.0;
100 fd= dnow()-app_start_at;
101 fd= 100.0/fd;
103 application= new cl_app();
104 application->set_name("ucsim");
105 application->init(argc, argv);
106 sim= new cl_general_sim(application);
107 if (sim->init())
108 sim->state|= SIM_QUIT;
109 application->set_simulator(sim);
112 id= dnow();
113 i= 0;
114 while (++i < 1000000) sim->step();
115 id= dnow() - id;
116 id= (1.0*1000)/id;
117 fprintf(stderr, "\n%f MFlop ", fd);
118 fprintf(stderr, "%f kips\n", id);
121 ret= application->run();
122 application->done();
123 return(ret);
126 /* End of sim.src/ucsim.cc */